add workspace urgency ipc event
Browse files at this commitcaa6189448cbf338c18fe6afe313f577c8378b31Parent: 86f57c25 changed files +30 -0
- niri-ipc/src/lib.rs +9 -0
- niri-ipc/src/state.rs +7 -0
- src/ipc/client.rs +3 -0
- src/ipc/server.rs +7 -0
- src/layout/workspace.rs +4 -0
niri-ipc/src/lib.rsmodified+9 -0
| @@ -1150,6 +1150,8 @@ pub struct Workspace { | |||
| 1150 | /// | 1150 | /// |
| 1151 | /// Can be `None` if no outputs are currently connected. | 1151 | /// Can be `None` if no outputs are currently connected. |
| 1152 | pub output: Option<String>, | 1152 | pub output: Option<String>, |
| 1153 | + /// Whether the workspace currently has an urgent window in its output. | ||
| 1154 | + pub is_urgent: bool, | ||
| 1153 | /// Whether the workspace is currently active on its output. | 1155 | /// Whether the workspace is currently active on its output. |
| 1154 | /// | 1156 | /// |
| 1155 | /// Every output has one active workspace, the one that is currently visible on that output. | 1157 | /// Every output has one active workspace, the one that is currently visible on that output. |
| @@ -1224,6 +1226,13 @@ pub enum Event { | |||
| 1224 | /// workspaces are missing from here, then they were deleted. | 1226 | /// workspaces are missing from here, then they were deleted. |
| 1225 | workspaces: Vec<Workspace>, | 1227 | workspaces: Vec<Workspace>, |
| 1226 | }, | 1228 | }, |
| 1229 | + /// The workspace urgency changed. | ||
| 1230 | + WorkspaceUrgencyChanged { | ||
| 1231 | + /// Id of the workspace. | ||
| 1232 | + id: u64, | ||
| 1233 | + /// Whether this workspace has an urgent window. | ||
| 1234 | + urgent: bool, | ||
| 1235 | + }, | ||
| 1227 | /// A workspace was activated on an output. | 1236 | /// A workspace was activated on an output. |
| 1228 | /// | 1237 | /// |
| 1229 | /// This doesn't always mean the workspace became focused, just that it's now the active | 1238 | /// This doesn't always mean the workspace became focused, just that it's now the active |
niri-ipc/src/state.rsmodified+7 -0
| @@ -103,6 +103,13 @@ impl EventStreamStatePart for WorkspacesState { | |||
| 103 | Event::WorkspacesChanged { workspaces } => { | 103 | Event::WorkspacesChanged { workspaces } => { |
| 104 | self.workspaces = workspaces.into_iter().map(|ws| (ws.id, ws)).collect(); | 104 | self.workspaces = workspaces.into_iter().map(|ws| (ws.id, ws)).collect(); |
| 105 | } | 105 | } |
| 106 | + Event::WorkspaceUrgencyChanged { id, urgent } => { | ||
| 107 | + for ws in self.workspaces.values_mut() { | ||
| 108 | + if ws.id == id { | ||
| 109 | + ws.is_urgent = urgent; | ||
| 110 | + } | ||
| 111 | + } | ||
| 112 | + } | ||
| 106 | Event::WorkspaceActivated { id, focused } => { | 113 | Event::WorkspaceActivated { id, focused } => { |
| 107 | let ws = self.workspaces.get(&id); | 114 | let ws = self.workspaces.get(&id); |
| 108 | let ws = ws.expect("activated workspace was missing from the map"); | 115 | let ws = ws.expect("activated workspace was missing from the map"); |
src/ipc/client.rsmodified+3 -0
| @@ -405,6 +405,9 @@ pub fn handle_msg(msg: Msg, json: bool) -> anyhow::Result<()> { | |||
| 405 | Event::WorkspacesChanged { workspaces } => { | 405 | Event::WorkspacesChanged { workspaces } => { |
| 406 | println!("Workspaces changed: {workspaces:?}"); | 406 | println!("Workspaces changed: {workspaces:?}"); |
| 407 | } | 407 | } |
| 408 | + Event::WorkspaceUrgencyChanged { id, urgent } => { | ||
| 409 | + println!("Workspace {id}: urgency changed to {urgent}"); | ||
| 410 | + } | ||
| 408 | Event::WorkspaceActivated { id, focused } => { | 411 | Event::WorkspaceActivated { id, focused } => { |
| 409 | let word = if focused { "focused" } else { "activated" }; | 412 | let word = if focused { "focused" } else { "activated" }; |
| 410 | println!("Workspace {word}: {id}"); | 413 | println!("Workspace {word}: {id}"); |
src/ipc/server.rsmodified+7 -0
| @@ -579,6 +579,12 @@ impl State { | |||
| 579 | }); | 579 | }); |
| 580 | } | 580 | } |
| 581 | 581 | ||
| 582 | + // Check if this workspace urgent state changed. | ||
| 583 | + let urgent = ws.is_urgent(); | ||
| 584 | + if urgent != ipc_ws.is_urgent { | ||
| 585 | + events.push(Event::WorkspaceUrgencyChanged { id, urgent }); | ||
| 586 | + } | ||
| 587 | + | ||
| 582 | // Check if this workspace became focused. | 588 | // Check if this workspace became focused. |
| 583 | let is_focused = Some(id) == focused_ws_id; | 589 | let is_focused = Some(id) == focused_ws_id; |
| 584 | if is_focused && !ipc_ws.is_focused { | 590 | if is_focused && !ipc_ws.is_focused { |
| @@ -610,6 +616,7 @@ impl State { | |||
| 610 | idx: u8::try_from(ws_idx + 1).unwrap_or(u8::MAX), | 616 | idx: u8::try_from(ws_idx + 1).unwrap_or(u8::MAX), |
| 611 | name: ws.name().cloned(), | 617 | name: ws.name().cloned(), |
| 612 | output: mon.map(|mon| mon.output_name().clone()), | 618 | output: mon.map(|mon| mon.output_name().clone()), |
| 619 | + is_urgent: ws.is_urgent(), | ||
| 613 | is_active: mon.is_some_and(|mon| mon.active_workspace_idx() == ws_idx), | 620 | is_active: mon.is_some_and(|mon| mon.active_workspace_idx() == ws_idx), |
| 614 | is_focused: Some(id) == focused_ws_id, | 621 | is_focused: Some(id) == focused_ws_id, |
| 615 | active_window_id: ws.active_window().map(|win| win.id().get()), | 622 | active_window_id: ws.active_window().map(|win| win.id().get()), |
src/layout/workspace.rsmodified+4 -0
| @@ -1608,6 +1608,10 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 1608 | self.scrolling.scroll_amount_to_activate(window) | 1608 | self.scrolling.scroll_amount_to_activate(window) |
| 1609 | } | 1609 | } |
| 1610 | 1610 | ||
| 1611 | + pub fn is_urgent(&self) -> bool { | ||
| 1612 | + self.windows().any(|win| win.is_urgent()) | ||
| 1613 | + } | ||
| 1614 | + | ||
| 1611 | pub fn activate_window(&mut self, window: &W::Id) -> bool { | 1615 | pub fn activate_window(&mut self, window: &W::Id) -> bool { |
| 1612 | if self.floating.activate_window(window) { | 1616 | if self.floating.activate_window(window) { |
| 1613 | self.floating_is_active = FloatingActive::Yes; | 1617 | self.floating_is_active = FloatingActive::Yes; |