Merge pull request #572 from JakeStanger/fix/workspace-rename

fix(workspaces): add support for hyprland rename event
This commit is contained in:
Jake Stanger 2024-05-07 09:54:37 +01:00 committed by GitHub
commit 4695279d69
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 52 additions and 21 deletions

8
Cargo.lock generated
View File

@ -1444,9 +1444,9 @@ dependencies = [
[[package]]
name = "hyprland"
version = "0.4.0-alpha.1"
version = "0.4.0-alpha.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "54fdc60390459bd6da28ec708ee7a672b8f6680efb8f8f33cbe970da16f40a48"
checksum = "d627cd06fb3389f2554b7a4bb21db8c0bfca8863e6e653702cc4c6dbf20d8276"
dependencies = [
"ahash",
"derive_more",
@ -2007,9 +2007,9 @@ dependencies = [
[[package]]
name = "num-traits"
version = "0.2.18"
version = "0.2.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "da0df0e5185db44f69b44f26786fe401b6c293d1907744beaa7fa62b2e5a517a"
checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841"
dependencies = [
"autocfg",
]

View File

@ -148,7 +148,7 @@ libpulse-binding = { version = "2.28.1", optional = true }
# workspaces
swayipc-async = { version = "2.0.1", optional = true }
hyprland = { version = "0.4.0-alpha.1", features = ["silent"], optional = true }
hyprland = { version = "0.4.0-alpha.2", features = ["silent"], optional = true }
futures-util = { version = "0.3.30", optional = true }
# shared

View File

@ -149,12 +149,27 @@ impl Client {
}
{
event_listener.add_workspace_destroy_handler(move |workspace_type| {
let _lock = lock!(lock);
debug!("Received workspace destroy: {workspace_type:?}");
let tx = tx.clone();
let lock = lock.clone();
let name = get_workspace_name(workspace_type);
send!(tx, WorkspaceUpdate::Remove(name));
event_listener.add_workspace_rename_handler(move |data| {
let _lock = lock!(lock);
send!(
tx,
WorkspaceUpdate::Rename {
id: data.workspace_id.to_string(),
name: data.workspace_name
}
);
});
}
{
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()));
});
}

View File

@ -126,6 +126,12 @@ pub enum WorkspaceUpdate {
old: Option<Workspace>,
new: Workspace,
},
Rename {
id: String,
name: String,
},
/// An update was triggered by the compositor but this was not mapped by Ironbar.
///
/// This is purely used for ergonomics within the compositor clients

View File

@ -135,7 +135,7 @@ fn reorder_workspaces(container: &gtk::Box) {
impl WorkspacesModule {
fn show_workspace_check(&self, output: &String, work: &Workspace) -> bool {
(work.visibility.is_focused() || !self.hidden.contains(&work.name))
(work.visibility.is_focused() || !self.hidden.contains(&work.id))
&& (self.all_monitors || output == &work.monitor)
}
}
@ -213,7 +213,7 @@ impl Module<gtk::Box> for WorkspacesModule {
let mut added = HashSet::new();
let mut add_workspace = |name: &str, visibility: Visibility| {
let mut add_workspace = |id: &str, name: &str, visibility: Visibility| {
let item = create_button(
name,
visibility,
@ -224,13 +224,13 @@ impl Module<gtk::Box> for WorkspacesModule {
);
container.add(&item);
button_map.insert(name.to_string(), item);
button_map.insert(id.to_string(), item);
};
// add workspaces from client
for workspace in &workspaces {
if self.show_workspace_check(&output_name, workspace) {
add_workspace(&workspace.name, workspace.visibility);
add_workspace(&workspace.id, &workspace.name, workspace.visibility);
added.insert(workspace.name.to_string());
}
}
@ -240,7 +240,11 @@ impl Module<gtk::Box> for WorkspacesModule {
fav_names.push(name.to_string());
if !added.contains(name) {
add_workspace(name, Visibility::Hidden);
// Favourites are added with the same name and ID
// as Hyprland will initialize them this way.
// Since existing workspaces are added above,
// this means there shouldn't be any issues with renaming.
add_workspace(name, name, Visibility::Hidden);
added.insert(name.to_string());
}
}
@ -265,7 +269,7 @@ impl Module<gtk::Box> for WorkspacesModule {
}
}
WorkspaceUpdate::Focus { old, new } => {
if let Some(btn) = old.as_ref().and_then(|w| button_map.get(&w.name)) {
if let Some(btn) = old.as_ref().and_then(|w| button_map.get(&w.id)) {
if Some(new.monitor) == old.map(|w| w.monitor) {
btn.style_context().remove_class("visible");
}
@ -273,7 +277,7 @@ impl Module<gtk::Box> for WorkspacesModule {
btn.style_context().remove_class("focused");
}
let new = button_map.get(&new.name);
let new = button_map.get(&new.id);
if let Some(btn) = new {
let style = btn.style_context();
@ -281,9 +285,15 @@ impl Module<gtk::Box> for WorkspacesModule {
style.add_class("focused");
}
}
WorkspaceUpdate::Rename { id, name } => {
if let Some(btn) = button_map.get(&id) {
let name = name_map.get(&name).unwrap_or(&name);
btn.set_label(name);
}
}
WorkspaceUpdate::Add(workspace) => {
if fav_names.contains(&workspace.name) {
let btn = button_map.get(&workspace.name);
let btn = button_map.get(&workspace.id);
if let Some(btn) = btn {
btn.style_context().remove_class("inactive");
}
@ -306,7 +316,7 @@ impl Module<gtk::Box> for WorkspacesModule {
item.show();
if !name.is_empty() {
button_map.insert(name, item);
button_map.insert(workspace.id, item);
}
}
}
@ -332,9 +342,9 @@ impl Module<gtk::Box> for WorkspacesModule {
item.show();
if !name.is_empty() {
button_map.insert(name, item);
button_map.insert(workspace.id, item);
}
} else if let Some(item) = button_map.get(&workspace.name) {
} else if let Some(item) = button_map.get(&workspace.id) {
container.remove(item);
}
}