forge
Explore
Log in

Don't you dare go Hollow

add window urgency through xdg-activation-v1

Browse files at this commit

86f57c2ec775d4aa08bf310c94b22ea266eaa9e9Duncan OverbruckParent: 3cc6789
urgency is done through activation requests without a serial from a
previous interaction.

https://gitlab.freedesktop.org/wayland/wayland-protocols/-/issues/150
niri-visual-tests/src/test_window.rsmodified+4 -0
@@ -272,4 +272,8 @@ impl LayoutElement for TestWindow {
272272 fn interactive_resize_data(&self) -> Option<InteractiveResizeData> {
273273 None
274274 }
275+
276+ fn is_urgent(&self) -> bool {
277+ false
278+ }
275279 }
src/handlers/mod.rsmodified+13 -7
@@ -707,6 +707,8 @@ impl GammaControlHandler for State {
707707 }
708708 delegate_gamma_control!(State);
709709
710+struct UrgentOnlyMarker;
711+
710712 impl XdgActivationHandler for State {
711713 fn activation_state(&mut self) -> &mut XdgActivationState {
712714 &mut self.niri.activation_state
@@ -716,11 +718,10 @@ impl XdgActivationHandler for State {
716718 // Tokens without a serial are urgency-only. This is not specified, but it seems to be the
717719 // common client behavior.
718720 //
719- // We don't have urgency yet, so just ignore such tokens.
720- //
721721 // See also: https://gitlab.freedesktop.org/wayland/wayland-protocols/-/issues/150
722722 let Some((serial, seat)) = data.serial else {
723- return false;
723+ data.user_data.insert_if_missing(|| UrgentOnlyMarker);
724+ return true;
724725 };
725726 let Some(seat) = Seat::<State>::from_resource(&seat) else {
726727 return false;
@@ -760,11 +761,16 @@ impl XdgActivationHandler for State {
760761 surface: WlSurface,
761762 ) {
762763 if token_data.timestamp.elapsed() < XDG_ACTIVATION_TOKEN_TIMEOUT {
763- if let Some((mapped, _)) = self.niri.layout.find_window_and_output(&surface) {
764+ if let Some((mapped, _)) = self.niri.layout.find_window_and_output_mut(&surface) {
764765 let window = mapped.window.clone();
765- self.niri.layout.activate_window(&window);
766- self.niri.layer_shell_on_demand_focus = None;
767- self.niri.queue_redraw_all();
766+ if token_data.user_data.get::<UrgentOnlyMarker>().is_some() {
767+ mapped.set_urgent(true);
768+ self.niri.queue_redraw_all();
769+ } else {
770+ self.niri.layout.activate_window(&window);
771+ self.niri.layer_shell_on_demand_focus = None;
772+ self.niri.queue_redraw_all();
773+ }
768774 } else if let Some(unmapped) = self.niri.unmapped_windows.get_mut(&surface) {
769775 unmapped.activation_token_data = Some(token_data);
770776 }
src/layout/mod.rsmodified+2 -0
@@ -210,6 +210,8 @@ pub trait LayoutElement {
210210 fn set_bounds(&self, bounds: Size<i32, Logical>);
211211 fn is_ignoring_opacity_window_rule(&self) -> bool;
212212
213+ fn is_urgent(&self) -> bool;
214+
213215 fn configure_intent(&self) -> ConfigureIntent;
214216 fn send_pending_configure(&mut self);
215217
src/layout/tests.rsmodified+4 -0
@@ -261,6 +261,10 @@ impl LayoutElement for TestWindow {
261261 fn interactive_resize_data(&self) -> Option<InteractiveResizeData> {
262262 None
263263 }
264+
265+ fn is_urgent(&self) -> bool {
266+ false
267+ }
264268 }
265269
266270 fn arbitrary_bbox() -> impl Strategy<Value = Rectangle<i32, Logical>> {
src/window/mapped.rsmodified+22 -0
@@ -77,6 +77,9 @@ pub struct Mapped {
7777 /// If `None`, then the window is not offscreened.
7878 offscreen_data: RefCell<Option<OffscreenData>>,
7979
80+ /// Whether this has an urgent indicator.
81+ is_urgent: bool,
82+
8083 /// Whether this window has the keyboard focus.
8184 is_focused: bool,
8285
@@ -231,6 +234,7 @@ impl Mapped {
231234 needs_configure: false,
232235 needs_frame_callback: false,
233236 offscreen_data: RefCell::new(None),
237+ is_urgent: false,
234238 is_focused: false,
235239 is_active_in_column: true,
236240 is_floating: false,
@@ -328,6 +332,7 @@ impl Mapped {
328332 }
329333
330334 self.is_focused = is_focused;
335+ self.is_urgent = false;
331336 self.need_to_recompute_rules = true;
332337 }
333338
@@ -510,6 +515,19 @@ impl Mapped {
510515 pub fn is_windowed_fullscreen(&self) -> bool {
511516 self.is_windowed_fullscreen
512517 }
518+
519+ pub fn set_urgent(&mut self, urgent: bool) {
520+ if self.is_focused && urgent {
521+ return;
522+ }
523+ let changed = self.is_urgent != urgent;
524+ self.is_urgent = urgent;
525+ self.need_to_recompute_rules |= changed;
526+ }
527+
528+ pub fn is_urgent(&self) -> bool {
529+ self.is_urgent
530+ }
513531 }
514532
515533 impl Drop for Mapped {
@@ -830,6 +848,10 @@ impl LayoutElement for Mapped {
830848 }
831849 }
832850
851+ fn is_urgent(&self) -> bool {
852+ self.is_urgent
853+ }
854+
833855 fn set_activated(&mut self, active: bool) {
834856 let changed = self.toplevel().with_pending_state(|state| {
835857 if active {
src/window/mod.rsmodified+7 -0
@@ -131,6 +131,13 @@ impl<'a> WindowRef<'a> {
131131 }
132132 }
133133
134+ pub fn is_urgent(self) -> bool {
135+ match self {
136+ WindowRef::Unmapped(_) => false,
137+ WindowRef::Mapped(mapped) => mapped.is_urgent(),
138+ }
139+ }
140+
134141 pub fn is_active_in_column(self) -> bool {
135142 match self {
136143 WindowRef::Unmapped(_) => true,