Skip to content

Commit

Permalink
feat(sway): support workspace rename events (#799)
Browse files Browse the repository at this point in the history
And reorder based on label with fallback to widget name
  • Loading branch information
quietvoid authored Dec 5, 2024
1 parent 13c2f8f commit 9f7c391
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/clients/compositor/sway.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,16 @@ impl From<WorkspaceEvent> for WorkspaceUpdate {
WorkspaceChange::Move => {
Self::Move(event.current.expect("Missing current workspace").into())
}
WorkspaceChange::Rename => {
if let Some(node) = event.current {
Self::Rename {
id: node.id,
name: node.name.unwrap_or_default(),
}
} else {
Self::Unknown
}
}
WorkspaceChange::Urgent => {
if let Some(node) = event.current {
Self::Urgent {
Expand Down
14 changes: 13 additions & 1 deletion src/modules/workspaces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,15 @@ fn reorder_workspaces(container: &gtk::Box) {
let mut buttons = container
.children()
.into_iter()
.map(|child| (child.widget_name().to_string(), child))
.map(|child| {
let label = child
.downcast_ref::<Button>()
.and_then(|button| button.label())
.unwrap_or_else(|| child.widget_name())
.to_string();

(label, child)
})
.collect::<Vec<_>>();

buttons.sort_by(|(label_a, _), (label_b, _a)| {
Expand Down Expand Up @@ -346,6 +354,10 @@ impl Module<gtk::Box> for WorkspacesModule {
let name = name_map.get(&name).unwrap_or(&name);
btn.set_label(name);
}

if self.sort == SortOrder::Alphanumeric {
reorder_workspaces(&container);
}
}
WorkspaceUpdate::Add(workspace) => {
if fav_names.contains(&workspace.name) {
Expand Down

0 comments on commit 9f7c391

Please sign in to comment.