1
0
Fork 0
mirror of https://github.com/Zedfrigg/ironbar.git synced 2025-08-16 14:21:03 +02:00

feat(sway): support workspace rename events (#799)

And reorder based on label with fallback to widget name
This commit is contained in:
quietvoid 2024-12-05 07:04:22 -05:00 committed by GitHub
parent 13c2f8fa8b
commit 9f7c3918c4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 23 additions and 1 deletions

View file

@ -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 {

View file

@ -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)| {
@ -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) {