From 1e387199962b81caeb40ffbd99a956f24abdf4e3 Mon Sep 17 00:00:00 2001 From: Jake Stanger Date: Thu, 25 Aug 2022 21:53:57 +0100 Subject: [PATCH] feat: introduce logging in some areas --- src/bar.rs | 4 ++++ src/main.rs | 4 ++++ src/modules/workspaces.rs | 6 ++++++ src/sway/mod.rs | 1 + 4 files changed, 15 insertions(+) diff --git a/src/bar.rs b/src/bar.rs index ad366ab..c800b7d 100644 --- a/src/bar.rs +++ b/src/bar.rs @@ -5,6 +5,7 @@ use color_eyre::Result; use gtk::gdk::Monitor; use gtk::prelude::*; use gtk::{Application, ApplicationWindow, Orientation}; +use tracing::{debug, info}; pub fn create_bar( app: &Application, @@ -41,10 +42,12 @@ pub fn create_bar( win.add(&content); win.connect_destroy_event(|_, _| { + info!("Shutting down"); gtk::main_quit(); Inhibit(false) }); + debug!("Showing bar"); win.show_all(); Ok(()) @@ -104,6 +107,7 @@ fn add_modules(content: >k::Box, modules: Vec, info: &ModuleInfo let widget = $module.into_widget(&info)?; widget.set_widget_name($name); content.add(&widget); + debug!("Added module of type {}", $name); }}; } diff --git a/src/main.rs b/src/main.rs index 2f85ff3..477ff8f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -110,12 +110,16 @@ fn create_bars(app: &Application, display: &Display, config: &Config) -> Result< let outputs = serde_json::from_slice::>(&outputs)?; + debug!("Received {} outputs from Sway IPC", outputs.len()); + let num_monitors = display.n_monitors(); for i in 0..num_monitors { let monitor = display.monitor(i).ok_or_else(|| Report::msg("GTK and Sway are reporting a different number of outputs - this is a severe bug and should never happen"))?; let monitor_name = &outputs.get(i as usize).ok_or_else(|| Report::msg("GTK and Sway are reporting a different set of outputs - this is a severe bug and should never happen"))?.name; + info!("Creating bar on '{}'", monitor_name); + config.monitors.as_ref().map_or_else( || create_bar(app, &monitor, monitor_name, config.clone()), |config| { diff --git a/src/modules/workspaces.rs b/src/modules/workspaces.rs index ec76332..f5f6319 100644 --- a/src/modules/workspaces.rs +++ b/src/modules/workspaces.rs @@ -59,6 +59,7 @@ impl Module for WorkspacesModule { if self.all_monitors { workspaces } else { + trace!("Filtering workspaces to current monitor only"); workspaces .into_iter() .filter(|workspace| workspace.output == info.output_name) @@ -72,6 +73,7 @@ impl Module for WorkspacesModule { let (ui_tx, mut ui_rx) = mpsc::channel(32); + trace!("Creating workspace buttons"); for workspace in workspaces { let item = workspace.as_button(&name_map, &ui_tx); container.add(&item); @@ -95,9 +97,11 @@ impl Module for WorkspacesModule { }); { + trace!("Setting up sway event handler"); let menubar = container.clone(); let output_name = info.output_name.to_string(); rx.attach(None, move |event| { + debug!("Received workspace event {:?}", event); match event.change.as_str() { "focus" => { let old = event.old.and_then(|old| button_map.get(&old.name)); @@ -109,6 +113,8 @@ impl Module for WorkspacesModule { if let Some(new) = new { new.style_context().add_class("focused"); } + + trace!("{:?} {:?}", old, new); } "init" => { if let Some(workspace) = event.current { diff --git a/src/sway/mod.rs b/src/sway/mod.rs index 1e19d9d..d38e45c 100644 --- a/src/sway/mod.rs +++ b/src/sway/mod.rs @@ -133,6 +133,7 @@ impl SwayClient { } pub fn ipc(&mut self, command: IpcCommand) -> Result> { + debug!("Sending command: {:?}", command); match self.client.ipc(command) { Ok(res) => Ok(res), Err(err) => Err(get_client_error(err)),