From 9d3d7cb0e973827e5fcaa5d312a05695564a44c0 Mon Sep 17 00:00:00 2001 From: Duncan Overbruck Date: Thu, 27 Mar 2025 19:38:14 +0100 Subject: add {toggle,set,unset}-urgent cli actions --- niri-config/src/lib.rs | 9 +++++++++ niri-ipc/src/lib.rs | 18 ++++++++++++++++++ src/input/mod.rs | 31 +++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+) diff --git a/niri-config/src/lib.rs b/niri-config/src/lib.rs index 287b630d..b63cdd03 100644 --- a/niri-config/src/lib.rs +++ b/niri-config/src/lib.rs @@ -1874,6 +1874,12 @@ pub enum Action { ToggleOverview, OpenOverview, CloseOverview, + #[knuffel(skip)] + ToggleUrgent(u64), + #[knuffel(skip)] + SetUrgent(u64), + #[knuffel(skip)] + UnsetUrgent(u64), } impl From for Action { @@ -2145,6 +2151,9 @@ impl From for Action { niri_ipc::Action::ToggleOverview {} => Self::ToggleOverview, niri_ipc::Action::OpenOverview {} => Self::OpenOverview, niri_ipc::Action::CloseOverview {} => Self::CloseOverview, + niri_ipc::Action::ToggleUrgent { id } => Self::ToggleUrgent(id), + niri_ipc::Action::SetUrgent { id } => Self::SetUrgent(id), + niri_ipc::Action::UnsetUrgent { id } => Self::UnsetUrgent(id), } } } diff --git a/niri-ipc/src/lib.rs b/niri-ipc/src/lib.rs index fcb2d1ff..86388f16 100644 --- a/niri-ipc/src/lib.rs +++ b/niri-ipc/src/lib.rs @@ -803,6 +803,24 @@ pub enum Action { OpenOverview {}, /// Close the Overview. CloseOverview {}, + /// Toggle urgent status of a window. + ToggleUrgent { + /// Id of the window to toggle urgent. + #[cfg_attr(feature = "clap", arg(long))] + id: u64, + }, + /// Set urgent status of a window. + SetUrgent { + /// Id of the window to set urgent. + #[cfg_attr(feature = "clap", arg(long))] + id: u64, + }, + /// Unset urgent status of a window. + UnsetUrgent { + /// Id of the window to unset urgent. + #[cfg_attr(feature = "clap", arg(long))] + id: u64, + }, } /// Change in window or column size. diff --git a/src/input/mod.rs b/src/input/mod.rs index 1f790f16..1204ff5b 100644 --- a/src/input/mod.rs +++ b/src/input/mod.rs @@ -1971,6 +1971,37 @@ impl State { self.niri.queue_redraw_all(); } } + Action::ToggleUrgent(id) => { + let window = self + .niri + .layout + .workspaces_mut() + .find_map(|ws| ws.windows_mut().find(|w| w.id().get() == id)); + if let Some(window) = window { + let urgent = window.is_urgent(); + window.set_urgent(!urgent); + } + } + Action::SetUrgent(id) => { + let window = self + .niri + .layout + .workspaces_mut() + .find_map(|ws| ws.windows_mut().find(|w| w.id().get() == id)); + if let Some(window) = window { + window.set_urgent(true); + } + } + Action::UnsetUrgent(id) => { + let window = self + .niri + .layout + .workspaces_mut() + .find_map(|ws| ws.windows_mut().find(|w| w.id().get() == id)); + if let Some(window) = window { + window.set_urgent(false); + } + } } } -- cgit