diff --git a/src/bar.rs b/src/bar.rs index 9d9c7684..f1377833 100644 --- a/src/bar.rs +++ b/src/bar.rs @@ -48,14 +48,14 @@ fn load_modules( right: >k::Box, app: &Application, config: Config, - output_name: &str + output_name: &str, ) { if let Some(modules) = config.left { let info = ModuleInfo { app, location: ModuleLocation::Left, bar_position: &config.position, - output_name + output_name, }; add_modules(left, modules, info); @@ -66,7 +66,7 @@ fn load_modules( app, location: ModuleLocation::Center, bar_position: &config.position, - output_name + output_name, }; add_modules(center, modules, info); @@ -77,7 +77,7 @@ fn load_modules( app, location: ModuleLocation::Right, bar_position: &config.position, - output_name + output_name, }; add_modules(right, modules, info); @@ -122,6 +122,11 @@ fn add_modules(content: >k::Box, modules: Vec, info: ModuleInfo) widget.set_widget_name("script"); content.add(&widget); } + ModuleConfig::Focused(module) => { + let widget = module.into_widget(&info); + widget.set_widget_name("focused"); + content.add(&widget); + } } } } @@ -137,8 +142,16 @@ fn setup_layer_shell(win: &ApplicationWindow, monitor: &Monitor, position: &BarP gtk_layer_shell::set_margin(win, gtk_layer_shell::Edge::Left, 0); gtk_layer_shell::set_margin(win, gtk_layer_shell::Edge::Right, 0); - gtk_layer_shell::set_anchor(win, gtk_layer_shell::Edge::Top, position == &BarPosition::Top); - gtk_layer_shell::set_anchor(win, gtk_layer_shell::Edge::Bottom, position == &BarPosition::Bottom); + gtk_layer_shell::set_anchor( + win, + gtk_layer_shell::Edge::Top, + position == &BarPosition::Top, + ); + gtk_layer_shell::set_anchor( + win, + gtk_layer_shell::Edge::Bottom, + position == &BarPosition::Bottom, + ); gtk_layer_shell::set_anchor(win, gtk_layer_shell::Edge::Left, true); gtk_layer_shell::set_anchor(win, gtk_layer_shell::Edge::Right, true); } diff --git a/src/config.rs b/src/config.rs index 1a8d88d5..598c1c9d 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,4 +1,5 @@ use crate::modules::clock::ClockModule; +use crate::modules::focused::FocusedModule; use crate::modules::launcher::LauncherModule; use crate::modules::mpd::MpdModule; use crate::modules::script::ScriptModule; @@ -19,13 +20,14 @@ pub enum ModuleConfig { SysInfo(SysInfoModule), Launcher(LauncherModule), Script(ScriptModule), + Focused(FocusedModule), } -#[derive(Debug, Deserialize, Clone, PartialEq)] +#[derive(Debug, Deserialize, Clone, PartialEq, Eq)] #[serde(rename_all = "kebab-case")] pub enum BarPosition { Top, - Bottom + Bottom, } impl Default for BarPosition { @@ -83,3 +85,10 @@ impl Config { }) } } + +pub const fn default_false() -> bool { + false +} +pub const fn default_true() -> bool { + true +} diff --git a/src/modules/launcher/icon.rs b/src/icon.rs similarity index 100% rename from src/modules/launcher/icon.rs rename to src/icon.rs diff --git a/src/main.rs b/src/main.rs index 65004de5..e69c33ea 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,24 +1,21 @@ mod bar; mod collection; mod config; +mod icon; mod modules; mod popup; mod style; +mod sway; use crate::bar::create_bar; use crate::config::Config; use crate::style::load_css; +use crate::sway::SwayOutput; use dirs::config_dir; use gtk::prelude::*; use gtk::{gdk, Application}; use ksway::client::Client; use ksway::IpcCommand; -use serde::Deserialize; - -#[derive(Deserialize)] -struct SwayOutput { - name: String, -} #[tokio::main] async fn main() { @@ -27,8 +24,11 @@ async fn main() { .build(); let mut sway_client = Client::connect().expect("Failed to connect to Sway IPC"); - let outputs = sway_client.ipc(IpcCommand::GetOutputs).expect("Failed to get Sway outputs"); - let outputs = serde_json::from_slice::>(&outputs).expect("Failed to deserialize outputs message from Sway IPC"); + let outputs = sway_client + .ipc(IpcCommand::GetOutputs) + .expect("Failed to get Sway outputs"); + let outputs = serde_json::from_slice::>(&outputs) + .expect("Failed to deserialize outputs message from Sway IPC"); app.connect_activate(move |app| { let config = Config::load().unwrap_or_default(); @@ -42,7 +42,10 @@ async fn main() { let num_monitors = display.n_monitors(); for i in 0..num_monitors { let monitor = display.monitor(i).unwrap(); - let monitor_name = &outputs.get(i as usize).expect("GTK monitor output differs from Sway's").name; + let monitor_name = &outputs + .get(i as usize) + .expect("GTK monitor output differs from Sway's") + .name; let config = config.monitors.as_ref().map_or(&config, |monitor_config| { monitor_config.get(i as usize).unwrap_or(&config) diff --git a/src/modules/clock/mod.rs b/src/modules/clock/mod.rs index c1135803..212c9fdd 100644 --- a/src/modules/clock/mod.rs +++ b/src/modules/clock/mod.rs @@ -30,7 +30,12 @@ impl Module