From b4d75450acacc36a71e0ed8365f82bd88d2a55e8 Mon Sep 17 00:00:00 2001 From: Jake Stanger Date: Sun, 31 Dec 2023 00:50:03 +0000 Subject: [PATCH] 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 711a92a..31e149a 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 7654f97..ea2eb39 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 defefb6..a23debf 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 26c76b3..9bf7379 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 deb8975..e71a593 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 cdc72fb..c7ef2bf 100644 --- a/src/modules/clipboard.rs +++ b/src/modules/clipboard.rs @@ -145,7 +145,7 @@ impl Module