From c356b22401ad412c9a6a7f0092f2f2214e13f5f0 Mon Sep 17 00:00:00 2001 From: Jake Stanger Date: Sat, 30 Dec 2023 23:30:03 +0000 Subject: [PATCH 1/5] fix(workspaces): favourites missing `inactive` class on startup Fixes #390 --- src/modules/workspaces.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/modules/workspaces.rs b/src/modules/workspaces.rs index 259e338c..b6d745bc 100644 --- a/src/modules/workspaces.rs +++ b/src/modules/workspaces.rs @@ -97,6 +97,10 @@ fn create_button( style_context.add_class("focused"); } + if !visibility.is_visible() { + style_context.add_class("inactive") + } + { let tx = tx.clone(); let name = name.to_string(); From 1b54de98e676d93a8e8ff968b10c9b2d113de016 Mon Sep 17 00:00:00 2001 From: Jake Stanger Date: Sun, 31 Dec 2023 00:42:06 +0000 Subject: [PATCH 2/5] build(deps): update glib --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 68927549..97e1b3e8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1220,9 +1220,9 @@ dependencies = [ [[package]] name = "glib" -version = "0.18.4" +version = "0.18.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "951bbd7fdc5c044ede9f05170f05a3ae9479239c3afdfe2d22d537a3add15c4e" +checksum = "233daaf6e83ae6a12a52055f568f9d7cf4671dabb78ff9560ab6da230ce00ee5" dependencies = [ "bitflags 2.4.0", "futures-channel", diff --git a/Cargo.toml b/Cargo.toml index beaa7cf5..6fb9dca8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -65,7 +65,7 @@ workspaces = ["futures-util"] # core gtk = "0.18.1" gtk-layer-shell = "0.8.0" -glib = "0.18.4" +glib = "0.18.5" tokio = { version = "1.35.1", features = [ "macros", "rt-multi-thread", From 967801dc322c8edbc5335e4e23d70a2442b5280c Mon Sep 17 00:00:00 2001 From: Jake Stanger Date: Sun, 31 Dec 2023 00:43:36 +0000 Subject: [PATCH 3/5] refactor(workspaces): avoid sending unknown update info --- src/clients/compositor/hyprland.rs | 1 - src/clients/compositor/mod.rs | 6 +++++- src/clients/compositor/sway.rs | 9 ++++++--- src/modules/workspaces.rs | 7 ++++--- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/clients/compositor/hyprland.rs b/src/clients/compositor/hyprland.rs index f0f1ccf0..74f0d85e 100644 --- a/src/clients/compositor/hyprland.rs +++ b/src/clients/compositor/hyprland.rs @@ -84,7 +84,6 @@ impl EventClient { }, |workspace| { // there may be another type of update so dispatch that regardless of focus change - send!(tx, WorkspaceUpdate::Update(workspace.clone())); if !workspace.visibility.is_focused() { Self::send_focus_change(&mut prev_workspace, workspace, &tx); } diff --git a/src/clients/compositor/mod.rs b/src/clients/compositor/mod.rs index 484d3602..c703ff50 100644 --- a/src/clients/compositor/mod.rs +++ b/src/clients/compositor/mod.rs @@ -116,13 +116,17 @@ pub enum WorkspaceUpdate { Init(Vec), Add(Workspace), Remove(String), - Update(Workspace), Move(Workspace), /// Declares focus moved from the old workspace to the new. Focus { old: Option, new: Workspace, }, + /// An update was triggered by the compositor but this was not mapped by Ironbar. + /// + /// This is purely used for ergonomics within the compositor clients + /// and should be ignored by consumers. + Unknown, } pub trait WorkspaceClient { diff --git a/src/clients/compositor/sway.rs b/src/clients/compositor/sway.rs index 40f1b24e..7906ab16 100644 --- a/src/clients/compositor/sway.rs +++ b/src/clients/compositor/sway.rs @@ -31,8 +31,11 @@ impl SwayEventClient { while let Some(event) = events.next().await { trace!("event: {:?}", event); - if let Event::Workspace(ev) = event? { - workspace_tx.send(WorkspaceUpdate::from(*ev))?; + if let Event::Workspace(event) = event? { + let event = WorkspaceUpdate::from(*event); + if !matches!(event, WorkspaceUpdate::Unknown) { + workspace_tx.send(event)?; + } }; } @@ -172,7 +175,7 @@ impl From for WorkspaceUpdate { WorkspaceChange::Move => { Self::Move(event.current.expect("Missing current workspace").into()) } - _ => Self::Update(event.current.expect("Missing current workspace").into()), + _ => Self::Unknown, } } } diff --git a/src/modules/workspaces.rs b/src/modules/workspaces.rs index b6d745bc..47d32b8e 100644 --- a/src/modules/workspaces.rs +++ b/src/modules/workspaces.rs @@ -10,7 +10,7 @@ use serde::Deserialize; use std::cmp::Ordering; use std::collections::{HashMap, HashSet}; use tokio::sync::mpsc::{Receiver, Sender}; -use tracing::trace; +use tracing::{debug, trace, warn}; #[derive(Debug, Deserialize, Clone, Copy, Eq, PartialEq)] #[serde(rename_all = "snake_case")] @@ -162,9 +162,10 @@ impl Module for WorkspacesModule { client.subscribe_workspace_change() }; - trace!("Set up Sway workspace subscription"); + trace!("Set up workspace subscription"); while let Ok(payload) = srx.recv().await { + debug!("Received update: {payload:?}"); send_async!(tx, ModuleUpdateEvent::Update(payload)); } }); @@ -351,7 +352,7 @@ impl Module for WorkspacesModule { } } } - WorkspaceUpdate::Update(_) => {} + WorkspaceUpdate::Unknown => warn!("Received unknown type workspace event") }; }); } From b2a37a32b07d46fe56cb7c6b81b9e7da3fe27a15 Mon Sep 17 00:00:00 2001 From: Jake Stanger Date: Sun, 31 Dec 2023 00:43:48 +0000 Subject: [PATCH 4/5] refactor: fix clippy warning --- src/config/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config/mod.rs b/src/config/mod.rs index 357fb2c7..faa5ecaf 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -26,7 +26,7 @@ use serde::Deserialize; use std::collections::HashMap; pub use self::common::{CommonConfig, TransitionType}; -pub use self::truncate::{EllipsizeMode, TruncateMode}; +pub use self::truncate::TruncateMode; #[derive(Debug, Deserialize, Clone)] #[serde(tag = "type", rename_all = "snake_case")] From b4d75450acacc36a71e0ed8365f82bd88d2a55e8 Mon Sep 17 00:00:00 2001 From: Jake Stanger Date: Sun, 31 Dec 2023 00:50:03 +0000 Subject: [PATCH 5/5] fix(regression): GTK refactor causing updates to be missed Regression introduced by recent GTK refactor. The `glib_recv` macros previously using the passed in expression as the receiver, which was causing a new receiver to be created *every* time an event was received. This caused some peculiar behaviours where some events just never got through if sent too close to each other. This was most obvious in the `workspaces` module. Fixes #381 --- src/dynamic_value/dynamic_bool.rs | 2 +- src/dynamic_value/dynamic_string.rs | 2 +- src/image/provider.rs | 2 +- src/ipc/server.rs | 2 +- src/macros.rs | 16 ++++++++++------ src/modules/clipboard.rs | 2 +- src/modules/clock.rs | 4 ++-- src/modules/custom/progress.rs | 2 +- src/modules/custom/slider.rs | 2 +- src/modules/launcher/mod.rs | 4 ++-- src/modules/mod.rs | 2 +- src/modules/music/mod.rs | 4 ++-- src/modules/upower.rs | 4 ++-- src/style.rs | 2 +- 14 files changed, 27 insertions(+), 23 deletions(-) diff --git a/src/dynamic_value/dynamic_bool.rs b/src/dynamic_value/dynamic_bool.rs index 711a92a4..31e149ab 100644 --- a/src/dynamic_value/dynamic_bool.rs +++ b/src/dynamic_value/dynamic_bool.rs @@ -39,7 +39,7 @@ impl DynamicBool { _ => self, }; - let (tx, mut rx) = mpsc::channel(32); + let (tx, rx) = mpsc::channel(32); glib_recv_mpsc!(rx, val => f(val)); diff --git a/src/dynamic_value/dynamic_string.rs b/src/dynamic_value/dynamic_string.rs index 7654f97e..ea2eb39b 100644 --- a/src/dynamic_value/dynamic_string.rs +++ b/src/dynamic_value/dynamic_string.rs @@ -32,7 +32,7 @@ where let tokens = parse_input(input); let label_parts = arc_mut!(vec![]); - let (tx, mut rx) = mpsc::channel(32); + let (tx, rx) = mpsc::channel(32); for (i, segment) in tokens.into_iter().enumerate() { match segment { diff --git a/src/image/provider.rs b/src/image/provider.rs index defefb61..a23debfe 100644 --- a/src/image/provider.rs +++ b/src/image/provider.rs @@ -145,7 +145,7 @@ impl<'a> ImageProvider<'a> { #[cfg(feature = "http")] if let ImageLocation::Remote(url) = &self.location { let url = url.clone(); - let (tx, mut rx) = mpsc::channel(64); + let (tx, rx) = mpsc::channel(64); spawn(async move { let bytes = Self::get_bytes_from_http(url).await; diff --git a/src/ipc/server.rs b/src/ipc/server.rs index 26c76b32..9bf7379b 100644 --- a/src/ipc/server.rs +++ b/src/ipc/server.rs @@ -22,7 +22,7 @@ impl Ipc { /// /// Once started, the server will begin accepting connections. pub fn start(&self, application: &Application, ironbar: Rc) { - let (cmd_tx, mut cmd_rx) = mpsc::channel(32); + let (cmd_tx, cmd_rx) = mpsc::channel(32); let (res_tx, mut res_rx) = mpsc::channel(32); let path = self.path.clone(); diff --git a/src/macros.rs b/src/macros.rs index deb8975f..e71a5934 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -58,13 +58,15 @@ macro_rules! try_send { /// ``` #[macro_export] macro_rules! glib_recv { - ($rx:expr, $val:ident => $expr:expr) => { + ($rx:expr, $val:ident => $expr:expr) => {{ glib::spawn_future_local(async move { - while let Ok($val) = $rx.recv().await { + // re-delcare in case ie `context.subscribe()` is passed directly + let mut rx = $rx; + while let Ok($val) = rx.recv().await { $expr } }); - }; + }}; } /// Spawns a `GLib` future on the local thread, and calls `rx.recv()` @@ -83,13 +85,15 @@ macro_rules! glib_recv { /// ``` #[macro_export] macro_rules! glib_recv_mpsc { - ($rx:expr, $val:ident => $expr:expr) => { + ($rx:expr, $val:ident => $expr:expr) => {{ glib::spawn_future_local(async move { - while let Some($val) = $rx.recv().await { + // re-delcare in case ie `context.subscribe()` is passed directly + let mut rx = $rx; + while let Some($val) = rx.recv().await { $expr } }); - }; + }}; } /// Locks a `Mutex`. diff --git a/src/modules/clipboard.rs b/src/modules/clipboard.rs index cdc72fb8..c7ef2bf4 100644 --- a/src/modules/clipboard.rs +++ b/src/modules/clipboard.rs @@ -145,7 +145,7 @@ impl Module