From a8259b4ceae521311f5152980287ff88d0b984e7 Mon Sep 17 00:00:00 2001 From: Duncan Overbruck Date: Sat, 10 May 2025 20:18:49 +0200 Subject: add WindowUrgencyChanged ipc event --- niri-ipc/src/lib.rs | 9 +++++++++ niri-ipc/src/state.rs | 8 ++++++++ src/ipc/client.rs | 3 +++ src/ipc/server.rs | 6 ++++++ 4 files changed, 26 insertions(+) diff --git a/niri-ipc/src/lib.rs b/niri-ipc/src/lib.rs index 86388f16..6d7ea92d 100644 --- a/niri-ipc/src/lib.rs +++ b/niri-ipc/src/lib.rs @@ -1129,6 +1129,8 @@ pub struct Window { /// /// If the window isn't floating then it is in the tiling layout. pub is_floating: bool, + /// Whether this window requests your attention. + pub is_urgent: bool, } /// Output configuration change result. @@ -1298,6 +1300,13 @@ pub enum Event { /// Id of the newly focused window, or `None` if no window is now focused. id: Option, }, + /// Window urgency changed. + WindowUrgencyChanged { + /// Id of the window. + id: u64, + /// The new urgency state of the window. + urgent: bool, + }, /// The configured keyboard layouts have changed. KeyboardLayoutsChanged { /// The new keyboard layout configuration. diff --git a/niri-ipc/src/state.rs b/niri-ipc/src/state.rs index 9edeeabf..ef03321f 100644 --- a/niri-ipc/src/state.rs +++ b/niri-ipc/src/state.rs @@ -181,6 +181,14 @@ impl EventStreamStatePart for WindowsState { win.is_focused = Some(win.id) == id; } } + Event::WindowUrgencyChanged { id, urgent } => { + for win in self.windows.values_mut() { + if win.id == id { + win.is_urgent = urgent; + break; + } + } + } event => return Some(event), } None diff --git a/src/ipc/client.rs b/src/ipc/client.rs index 654890ab..55034ce0 100644 --- a/src/ipc/client.rs +++ b/src/ipc/client.rs @@ -433,6 +433,9 @@ pub fn handle_msg(msg: Msg, json: bool) -> anyhow::Result<()> { Event::WindowFocusChanged { id } => { println!("Window focus changed: {id:?}"); } + Event::WindowUrgencyChanged { id, urgent } => { + println!("Window {id}: urgency changed to {urgent}"); + } Event::KeyboardLayoutsChanged { keyboard_layouts } => { println!("Keyboard layouts changed: {keyboard_layouts:?}"); } diff --git a/src/ipc/server.rs b/src/ipc/server.rs index b3901998..ef9d9c87 100644 --- a/src/ipc/server.rs +++ b/src/ipc/server.rs @@ -476,6 +476,7 @@ fn make_ipc_window(mapped: &Mapped, workspace_id: Option) -> niri_i workspace_id: workspace_id.map(|id| id.get()), is_focused: mapped.is_focused(), is_floating: mapped.is_floating(), + is_urgent: mapped.is_urgent(), }) } @@ -680,6 +681,11 @@ impl State { if mapped.is_focused() && !ipc_win.is_focused { events.push(Event::WindowFocusChanged { id: Some(id) }); } + + let urgent = mapped.is_urgent(); + if urgent != ipc_win.is_urgent { + events.push(Event::WindowUrgencyChanged { id, urgent }) + } }); // Check for closed windows. -- cgit