Skip to content

Commit 9c13e53

Browse files
authored
Merge pull request #735 from Rodrigodd/feat/urgent
feat: add `.urgent` workspace css class
2 parents abf1c12 + afe534c commit 9c13e53

File tree

6 files changed

+80
-9
lines changed

6 files changed

+80
-9
lines changed

Diff for: docs/modules/Workspaces.md

+10-9
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,16 @@ end:
9898

9999
## Styling
100100

101-
| Selector | Description |
102-
|--------------------------------|--------------------------------------|
103-
| `.workspaces` | Workspaces widget box |
104-
| `.workspaces .item` | Workspace button |
105-
| `.workspaces .item.focused` | Workspace button (workspace focused) |
101+
| Selector | Description |
102+
| ------------------------------ | ------------------------------------------------------- |
103+
| `.workspaces` | Workspaces widget box |
104+
| `.workspaces .item` | Workspace button |
105+
| `.workspaces .item.focused` | Workspace button (workspace focused) |
106106
| `.workspaces .item.visible` | Workspace button (workspace visible, including focused) |
107-
| `.workspaces .item.inactive` | Workspace button (favourite, not currently open)
108-
| `.workspaces .item .icon` | Workspace button icon (any type) |
109-
| `.workspaces .item .text-icon` | Workspace button icon (textual only) |
110-
| `.workspaces .item .image` | Workspace button icon (image only) |
107+
| `.workspaces .item.urgent` | Workspace button (workspace contains urgent window) |
108+
| `.workspaces .item.inactive` | Workspace button (favourite, not currently open) |
109+
| `.workspaces .item .icon` | Workspace button icon (any type) |
110+
| `.workspaces .item .text-icon` | Workspace button icon (textual only) |
111+
| `.workspaces .item .image` | Workspace button icon (image only) |
111112

112113
For more information on styling, please see the [styling guide](styling-guide).

Diff for: examples/style.css

+4
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,10 @@ scale trough {
201201
background-color: @color_bg_dark;
202202
}
203203

204+
.workspaces .item.urgent {
205+
background-color: @color_urgent;
206+
}
207+
204208
.workspaces .item:hover {
205209
box-shadow: inset 0 -3px;
206210
}

Diff for: src/clients/compositor/hyprland.rs

+40
Original file line numberDiff line numberDiff line change
@@ -166,13 +166,45 @@ impl Client {
166166
}
167167

168168
{
169+
let tx = tx.clone();
170+
let lock = lock.clone();
171+
169172
event_listener.add_workspace_destroy_handler(move |data| {
170173
let _lock = lock!(lock);
171174
debug!("Received workspace destroy: {data:?}");
172175
send!(tx, WorkspaceUpdate::Remove(data.workspace_id as i64));
173176
});
174177
}
175178

179+
{
180+
event_listener.add_urgent_state_handler(move |address| {
181+
let _lock = lock!(lock);
182+
debug!("Received urgent state: {address:?}");
183+
184+
let clients = match hyprland::data::Clients::get() {
185+
Ok(clients) => clients,
186+
Err(err) => {
187+
error!("Failed to get clients: {err}");
188+
return;
189+
}
190+
};
191+
clients.iter().find(|c| c.address == address).map_or_else(
192+
|| {
193+
error!("Unable to locate client");
194+
},
195+
|c| {
196+
send!(
197+
tx,
198+
WorkspaceUpdate::Urgent {
199+
id: c.workspace.id as i64,
200+
urgent: true,
201+
}
202+
);
203+
},
204+
);
205+
});
206+
}
207+
176208
event_listener
177209
.start_listener()
178210
.expect("Failed to start listener");
@@ -194,6 +226,14 @@ impl Client {
194226
}
195227
);
196228

229+
send!(
230+
tx,
231+
WorkspaceUpdate::Urgent {
232+
id: workspace.id,
233+
urgent: false,
234+
}
235+
);
236+
197237
prev_workspace.replace(workspace);
198238
}
199239

Diff for: src/clients/compositor/mod.rs

+6
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,12 @@ pub enum WorkspaceUpdate {
135135
name: String,
136136
},
137137

138+
/// The urgent state of a node changed.
139+
Urgent {
140+
id: i64,
141+
urgent: bool,
142+
},
143+
138144
/// An update was triggered by the compositor but this was not mapped by Ironbar.
139145
///
140146
/// This is purely used for ergonomics within the compositor clients

Diff for: src/clients/compositor/sway.rs

+10
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,16 @@ impl From<WorkspaceEvent> for WorkspaceUpdate {
109109
WorkspaceChange::Move => {
110110
Self::Move(event.current.expect("Missing current workspace").into())
111111
}
112+
WorkspaceChange::Urgent => {
113+
if let Some(node) = event.current {
114+
Self::Urgent {
115+
id: node.id,
116+
urgent: node.urgent,
117+
}
118+
} else {
119+
Self::Unknown
120+
}
121+
}
112122
_ => Self::Unknown,
113123
}
114124
}

Diff for: src/modules/workspaces.rs

+10
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,16 @@ impl Module<gtk::Box> for WorkspacesModule {
416416
}
417417
}
418418
}
419+
WorkspaceUpdate::Urgent { id, urgent } => {
420+
let button = button_map.get(&id);
421+
if let Some(item) = button {
422+
if urgent {
423+
item.add_class("urgent");
424+
} else {
425+
item.style_context().remove_class("urgent");
426+
}
427+
}
428+
}
419429
WorkspaceUpdate::Unknown => warn!("Received unknown type workspace event")
420430
};
421431
});

0 commit comments

Comments
 (0)