Skip to content

Commit

Permalink
feat: add .urgent workspace css class
Browse files Browse the repository at this point in the history
  • Loading branch information
Rodrigodd committed Sep 26, 2024
1 parent 32e6fc5 commit 11a8f60
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 9 deletions.
19 changes: 10 additions & 9 deletions docs/modules/Workspaces.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,16 @@ end:

## Styling

| Selector | Description |
|--------------------------------|--------------------------------------|
| `.workspaces` | Workspaces widget box |
| `.workspaces .item` | Workspace button |
| `.workspaces .item.focused` | Workspace button (workspace focused) |
| Selector | Description |
| ------------------------------ | ------------------------------------------------------- |
| `.workspaces` | Workspaces widget box |
| `.workspaces .item` | Workspace button |
| `.workspaces .item.focused` | Workspace button (workspace focused) |
| `.workspaces .item.visible` | Workspace button (workspace visible, including focused) |
| `.workspaces .item.inactive` | Workspace button (favourite, not currently open)
| `.workspaces .item .icon` | Workspace button icon (any type) |
| `.workspaces .item .text-icon` | Workspace button icon (textual only) |
| `.workspaces .item .image` | Workspace button icon (image only) |
| `.workspaces .item.urgent` | Workspace button (workspace contain urgent window) |
| `.workspaces .item.inactive` | Workspace button (favourite, not currently open) |
| `.workspaces .item .icon` | Workspace button icon (any type) |
| `.workspaces .item .text-icon` | Workspace button icon (textual only) |
| `.workspaces .item .image` | Workspace button icon (image only) |

For more information on styling, please see the [styling guide](styling-guide).
4 changes: 4 additions & 0 deletions examples/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,10 @@ scale trough {
background-color: @color_bg_dark;
}

.workspaces .item.urgent {
background-color: @color_urgent;
}

.workspaces .item:hover {
box-shadow: inset 0 -3px;
}
Expand Down
40 changes: 40 additions & 0 deletions src/clients/compositor/hyprland.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,45 @@ impl Client {
}

{
let tx = tx.clone();
let lock = lock.clone();

event_listener.add_workspace_destroy_handler(move |data| {
let _lock = lock!(lock);
debug!("Received workspace destroy: {data:?}");
send!(tx, WorkspaceUpdate::Remove(data.workspace_id as i64));
});
}

{
event_listener.add_urgent_state_handler(move |address| {
let _lock = lock!(lock);
debug!("Received urgent state: {address:?}");

let clients = match hyprland::data::Clients::get() {
Ok(clients) => clients,
Err(err) => {
error!("Failed to get clients: {err}");
return;
}
};
clients.iter().find(|c| c.address == address).map_or_else(
|| {
error!("Unable to locate client");
},
|c| {
send!(
tx,
WorkspaceUpdate::Urgent {
id: c.workspace.id as i64,
urgent: true,
}
);
},
);
});
}

event_listener
.start_listener()
.expect("Failed to start listener");
Expand All @@ -194,6 +226,14 @@ impl Client {
}
);

send!(
tx,
WorkspaceUpdate::Urgent {
id: workspace.id,
urgent: false,
}
);

prev_workspace.replace(workspace);
}

Expand Down
6 changes: 6 additions & 0 deletions src/clients/compositor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,12 @@ pub enum WorkspaceUpdate {
name: String,
},

/// The urgent state of a node changed.
Urgent {
id: i64,
urgent: bool,
},

/// An update was triggered by the compositor but this was not mapped by Ironbar.
///
/// This is purely used for ergonomics within the compositor clients
Expand Down
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::Urgent => {
if let Some(node) = event.current {
Self::Urgent {
id: node.id,
urgent: node.urgent,
}
} else {
Self::Unknown
}
}
_ => Self::Unknown,
}
}
Expand Down
10 changes: 10 additions & 0 deletions src/modules/workspaces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,16 @@ impl Module<gtk::Box> for WorkspacesModule {
}
}
}
WorkspaceUpdate::Urgent { id, urgent } => {
let button = button_map.get(&id);
if let Some(item) = button {
if urgent {
item.style_context().add_class("urgent");
} else {
item.style_context().remove_class("urgent");
}
}
}
WorkspaceUpdate::Unknown => warn!("Received unknown type workspace event")
};
});
Expand Down

0 comments on commit 11a8f60

Please sign in to comment.