From c45ea02a7d39b30fece3986044a44a64aebf5e16 Mon Sep 17 00:00:00 2001 From: Jake Stanger Date: Thu, 9 May 2024 17:25:08 +0100 Subject: [PATCH] fix(workspaces): regression due to #572 Fixes #574 --- src/clients/compositor/hyprland.rs | 6 ++--- src/clients/compositor/mod.rs | 6 ++--- src/clients/compositor/sway.rs | 14 ++++------- src/modules/workspaces.rs | 40 ++++++++++++++++++------------ test-configs/workspaces.corn | 3 +++ 5 files changed, 38 insertions(+), 31 deletions(-) create mode 100644 test-configs/workspaces.corn diff --git a/src/clients/compositor/hyprland.rs b/src/clients/compositor/hyprland.rs index 3932578..ee526ea 100644 --- a/src/clients/compositor/hyprland.rs +++ b/src/clients/compositor/hyprland.rs @@ -158,7 +158,7 @@ impl Client { send!( tx, WorkspaceUpdate::Rename { - id: data.workspace_id.to_string(), + id: data.workspace_id as i64, name: data.workspace_name } ); @@ -169,7 +169,7 @@ impl Client { event_listener.add_workspace_destroy_handler(move |data| { let _lock = lock!(lock); debug!("Received workspace destroy: {data:?}"); - send!(tx, WorkspaceUpdate::Remove(data.workspace_id.to_string())); + send!(tx, WorkspaceUpdate::Remove(data.workspace_id as i64)); }); } @@ -279,7 +279,7 @@ fn create_is_visible() -> impl Fn(&HWorkspace) -> bool { impl From<(Visibility, HWorkspace)> for Workspace { fn from((visibility, workspace): (Visibility, HWorkspace)) -> Self { Self { - id: workspace.id.to_string(), + id: workspace.id as i64, name: workspace.name, monitor: workspace.monitor, visibility, diff --git a/src/clients/compositor/mod.rs b/src/clients/compositor/mod.rs index 6dc2398..051a7b8 100644 --- a/src/clients/compositor/mod.rs +++ b/src/clients/compositor/mod.rs @@ -74,7 +74,7 @@ impl Compositor { #[derive(Debug, Clone)] pub struct Workspace { /// Unique identifier - pub id: String, + pub id: i64, /// Workspace friendly name pub name: String, /// Name of the monitor (output) the workspace is located on @@ -119,7 +119,7 @@ pub enum WorkspaceUpdate { /// This is re-sent to all subscribers when a new subscription is created. Init(Vec), Add(Workspace), - Remove(String), + Remove(i64), Move(Workspace), /// Declares focus moved from the old workspace to the new. Focus { @@ -128,7 +128,7 @@ pub enum WorkspaceUpdate { }, Rename { - id: String, + id: i64, name: String, }, diff --git a/src/clients/compositor/sway.rs b/src/clients/compositor/sway.rs index 28e8f7f..b3f4197 100644 --- a/src/clients/compositor/sway.rs +++ b/src/clients/compositor/sway.rs @@ -90,7 +90,7 @@ impl From for Workspace { let visibility = Visibility::from(&node); Self { - id: node.id.to_string(), + id: node.id, name: node.name.unwrap_or_default(), monitor: node.output.unwrap_or_default(), visibility, @@ -103,7 +103,7 @@ impl From for Workspace { let visibility = Visibility::from(&workspace); Self { - id: workspace.id.to_string(), + id: workspace.id, name: workspace.name, monitor: workspace.output, visibility, @@ -141,13 +141,9 @@ impl From for WorkspaceUpdate { WorkspaceChange::Init => { Self::Add(event.current.expect("Missing current workspace").into()) } - WorkspaceChange::Empty => Self::Remove( - event - .current - .expect("Missing current workspace") - .name - .unwrap_or_default(), - ), + WorkspaceChange::Empty => { + Self::Remove(event.current.expect("Missing current workspace").id) + } WorkspaceChange::Focus => Self::Focus { old: event.old.map(Workspace::from), new: Workspace::from(event.current.expect("Missing current workspace")), diff --git a/src/modules/workspaces.rs b/src/modules/workspaces.rs index 45e816e..b1a20de 100644 --- a/src/modules/workspaces.rs +++ b/src/modules/workspaces.rs @@ -1,8 +1,9 @@ use crate::clients::compositor::{Visibility, Workspace, WorkspaceClient, WorkspaceUpdate}; use crate::config::CommonConfig; +use crate::gtk_helpers::IronbarGtkExt; use crate::image::new_icon_button; use crate::modules::{Module, ModuleInfo, ModuleParts, ModuleUpdateEvent, WidgetContext}; -use crate::{glib_recv, module_impl, send_async, spawn, try_send}; +use crate::{glib_recv, module_impl, send_async, spawn, try_send, Ironbar}; use color_eyre::{Report, Result}; use gtk::prelude::*; use gtk::{Button, IconTheme}; @@ -133,9 +134,18 @@ fn reorder_workspaces(container: >k::Box) { } } +fn find_btn(map: &HashMap, workspace: &Workspace) -> Option