From 967801dc322c8edbc5335e4e23d70a2442b5280c Mon Sep 17 00:00:00 2001 From: Jake Stanger Date: Sun, 31 Dec 2023 00:43:36 +0000 Subject: [PATCH] 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 f0f1ccf..74f0d85 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 484d360..c703ff5 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 40f1b24..7906ab1 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 b6d745b..47d32b8 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") }; }); }