1
0
Fork 0
mirror of https://github.com/Zedfrigg/ironbar.git synced 2025-04-19 19:34:24 +02:00

Merge pull request #578 from JakeStanger/fix/sway-workspaces

fix(workspaces): regression due to #572
This commit is contained in:
Jake Stanger 2024-05-09 17:38:43 +01:00 committed by GitHub
commit 386955c1ea
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 38 additions and 31 deletions

View file

@ -158,7 +158,7 @@ impl Client {
send!( send!(
tx, tx,
WorkspaceUpdate::Rename { WorkspaceUpdate::Rename {
id: data.workspace_id.to_string(), id: data.workspace_id as i64,
name: data.workspace_name name: data.workspace_name
} }
); );
@ -169,7 +169,7 @@ impl Client {
event_listener.add_workspace_destroy_handler(move |data| { event_listener.add_workspace_destroy_handler(move |data| {
let _lock = lock!(lock); let _lock = lock!(lock);
debug!("Received workspace destroy: {data:?}"); 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 { impl From<(Visibility, HWorkspace)> for Workspace {
fn from((visibility, workspace): (Visibility, HWorkspace)) -> Self { fn from((visibility, workspace): (Visibility, HWorkspace)) -> Self {
Self { Self {
id: workspace.id.to_string(), id: workspace.id as i64,
name: workspace.name, name: workspace.name,
monitor: workspace.monitor, monitor: workspace.monitor,
visibility, visibility,

View file

@ -74,7 +74,7 @@ impl Compositor {
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct Workspace { pub struct Workspace {
/// Unique identifier /// Unique identifier
pub id: String, pub id: i64,
/// Workspace friendly name /// Workspace friendly name
pub name: String, pub name: String,
/// Name of the monitor (output) the workspace is located on /// 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. /// This is re-sent to all subscribers when a new subscription is created.
Init(Vec<Workspace>), Init(Vec<Workspace>),
Add(Workspace), Add(Workspace),
Remove(String), Remove(i64),
Move(Workspace), Move(Workspace),
/// Declares focus moved from the old workspace to the new. /// Declares focus moved from the old workspace to the new.
Focus { Focus {
@ -128,7 +128,7 @@ pub enum WorkspaceUpdate {
}, },
Rename { Rename {
id: String, id: i64,
name: String, name: String,
}, },

View file

@ -90,7 +90,7 @@ impl From<Node> for Workspace {
let visibility = Visibility::from(&node); let visibility = Visibility::from(&node);
Self { Self {
id: node.id.to_string(), id: node.id,
name: node.name.unwrap_or_default(), name: node.name.unwrap_or_default(),
monitor: node.output.unwrap_or_default(), monitor: node.output.unwrap_or_default(),
visibility, visibility,
@ -103,7 +103,7 @@ impl From<swayipc_async::Workspace> for Workspace {
let visibility = Visibility::from(&workspace); let visibility = Visibility::from(&workspace);
Self { Self {
id: workspace.id.to_string(), id: workspace.id,
name: workspace.name, name: workspace.name,
monitor: workspace.output, monitor: workspace.output,
visibility, visibility,
@ -141,13 +141,9 @@ impl From<WorkspaceEvent> for WorkspaceUpdate {
WorkspaceChange::Init => { WorkspaceChange::Init => {
Self::Add(event.current.expect("Missing current workspace").into()) Self::Add(event.current.expect("Missing current workspace").into())
} }
WorkspaceChange::Empty => Self::Remove( WorkspaceChange::Empty => {
event Self::Remove(event.current.expect("Missing current workspace").id)
.current }
.expect("Missing current workspace")
.name
.unwrap_or_default(),
),
WorkspaceChange::Focus => Self::Focus { WorkspaceChange::Focus => Self::Focus {
old: event.old.map(Workspace::from), old: event.old.map(Workspace::from),
new: Workspace::from(event.current.expect("Missing current workspace")), new: Workspace::from(event.current.expect("Missing current workspace")),

View file

@ -1,8 +1,9 @@
use crate::clients::compositor::{Visibility, Workspace, WorkspaceClient, WorkspaceUpdate}; use crate::clients::compositor::{Visibility, Workspace, WorkspaceClient, WorkspaceUpdate};
use crate::config::CommonConfig; use crate::config::CommonConfig;
use crate::gtk_helpers::IronbarGtkExt;
use crate::image::new_icon_button; use crate::image::new_icon_button;
use crate::modules::{Module, ModuleInfo, ModuleParts, ModuleUpdateEvent, WidgetContext}; 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 color_eyre::{Report, Result};
use gtk::prelude::*; use gtk::prelude::*;
use gtk::{Button, IconTheme}; use gtk::{Button, IconTheme};
@ -133,9 +134,18 @@ fn reorder_workspaces(container: &gtk::Box) {
} }
} }
fn find_btn(map: &HashMap<i64, Button>, workspace: &Workspace) -> Option<Button> {
map.get(&workspace.id)
.or_else(|| {
map.values()
.find(|btn| btn.label().unwrap_or_default() == workspace.name)
})
.cloned()
}
impl WorkspacesModule { impl WorkspacesModule {
fn show_workspace_check(&self, output: &String, work: &Workspace) -> bool { fn show_workspace_check(&self, output: &String, work: &Workspace) -> bool {
(work.visibility.is_focused() || !self.hidden.contains(&work.id)) (work.visibility.is_focused() || !self.hidden.contains(&work.name))
&& (self.all_monitors || output == &work.monitor) && (self.all_monitors || output == &work.monitor)
} }
} }
@ -193,7 +203,7 @@ impl Module<gtk::Box> for WorkspacesModule {
let favs = self.favorites.clone(); let favs = self.favorites.clone();
let mut fav_names: Vec<String> = vec![]; let mut fav_names: Vec<String> = vec![];
let mut button_map: HashMap<String, Button> = HashMap::new(); let mut button_map: HashMap<i64, Button> = HashMap::new();
{ {
let container = container.clone(); let container = container.clone();
@ -213,7 +223,7 @@ impl Module<gtk::Box> for WorkspacesModule {
let mut added = HashSet::new(); let mut added = HashSet::new();
let mut add_workspace = |id: &str, name: &str, visibility: Visibility| { let mut add_workspace = |id: i64, name: &str, visibility: Visibility| {
let item = create_button( let item = create_button(
name, name,
visibility, visibility,
@ -224,13 +234,13 @@ impl Module<gtk::Box> for WorkspacesModule {
); );
container.add(&item); container.add(&item);
button_map.insert(id.to_string(), item); button_map.insert(id, item);
}; };
// add workspaces from client // add workspaces from client
for workspace in &workspaces { for workspace in &workspaces {
if self.show_workspace_check(&output_name, workspace) { if self.show_workspace_check(&output_name, workspace) {
add_workspace(&workspace.id, &workspace.name, workspace.visibility); add_workspace(workspace.id, &workspace.name, workspace.visibility);
added.insert(workspace.name.to_string()); added.insert(workspace.name.to_string());
} }
} }
@ -244,7 +254,7 @@ impl Module<gtk::Box> for WorkspacesModule {
// as Hyprland will initialize them this way. // as Hyprland will initialize them this way.
// Since existing workspaces are added above, // Since existing workspaces are added above,
// this means there shouldn't be any issues with renaming. // this means there shouldn't be any issues with renaming.
add_workspace(name, name, Visibility::Hidden); add_workspace(-(Ironbar::unique_id() as i64), name, Visibility::Hidden);
added.insert(name.to_string()); added.insert(name.to_string());
} }
} }
@ -269,20 +279,17 @@ impl Module<gtk::Box> for WorkspacesModule {
} }
} }
WorkspaceUpdate::Focus { old, new } => { WorkspaceUpdate::Focus { old, new } => {
if let Some(btn) = old.as_ref().and_then(|w| button_map.get(&w.id)) { if let Some(btn) = old.as_ref().and_then(|w| find_btn(&button_map, w)) {
if Some(new.monitor) == old.map(|w| w.monitor) { if Some(new.monitor.as_str()) == old.as_ref().map(|w| w.monitor.as_str()) {
btn.style_context().remove_class("visible"); btn.style_context().remove_class("visible");
} }
btn.style_context().remove_class("focused"); btn.style_context().remove_class("focused");
} }
let new = button_map.get(&new.id); if let Some(btn) = find_btn(&button_map, &new) {
if let Some(btn) = new { btn.add_class("visible");
let style = btn.style_context(); btn.add_class("focused");
style.add_class("visible");
style.add_class("focused");
} }
} }
WorkspaceUpdate::Rename { id, name } => { WorkspaceUpdate::Rename { id, name } => {
@ -352,7 +359,8 @@ impl Module<gtk::Box> for WorkspacesModule {
WorkspaceUpdate::Remove(workspace) => { WorkspaceUpdate::Remove(workspace) => {
let button = button_map.get(&workspace); let button = button_map.get(&workspace);
if let Some(item) = button { if let Some(item) = button {
if fav_names.contains(&workspace) { if workspace < 0 {
// if fav_names.contains(&workspace) {
item.style_context().add_class("inactive"); item.style_context().add_class("inactive");
} else { } else {
container.remove(item); container.remove(item);

View file

@ -0,0 +1,3 @@
{
start = [ { type = "workspaces" }]
}