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 {
272 fn interactive_resize_data(&self) -> Option<InteractiveResizeData> {272 fn interactive_resize_data(&self) -> Option<InteractiveResizeData> {
273 None273 None
274 }274 }
275+
276+ fn is_urgent(&self) -> bool {
277+ false
278+ }
275 }279 }
src/handlers/mod.rsmodified+13 -7
@@ -707,6 +707,8 @@ impl GammaControlHandler for State {
707 }707 }
708 delegate_gamma_control!(State);708 delegate_gamma_control!(State);
709 709
710+struct UrgentOnlyMarker;
711+
710 impl XdgActivationHandler for State {712 impl XdgActivationHandler for State {
711 fn activation_state(&mut self) -> &mut XdgActivationState {713 fn activation_state(&mut self) -> &mut XdgActivationState {
712 &mut self.niri.activation_state714 &mut self.niri.activation_state
@@ -716,11 +718,10 @@ impl XdgActivationHandler for State {
716 // Tokens without a serial are urgency-only. This is not specified, but it seems to be the718 // Tokens without a serial are urgency-only. This is not specified, but it seems to be the
717 // common client behavior.719 // common client behavior.
718 //720 //
719- // We don't have urgency yet, so just ignore such tokens.
720- //
721 // See also: https://gitlab.freedesktop.org/wayland/wayland-protocols/-/issues/150721 // See also: https://gitlab.freedesktop.org/wayland/wayland-protocols/-/issues/150
722 let Some((serial, seat)) = data.serial else {722 let Some((serial, seat)) = data.serial else {
723- return false;723+ data.user_data.insert_if_missing(|| UrgentOnlyMarker);
724+ return true;
724 };725 };
725 let Some(seat) = Seat::<State>::from_resource(&seat) else {726 let Some(seat) = Seat::<State>::from_resource(&seat) else {
726 return false;727 return false;
@@ -760,11 +761,16 @@ impl XdgActivationHandler for State {
760 surface: WlSurface,761 surface: WlSurface,
761 ) {762 ) {
762 if token_data.timestamp.elapsed() < XDG_ACTIVATION_TOKEN_TIMEOUT {763 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) {
764 let window = mapped.window.clone();765 let window = mapped.window.clone();
765- self.niri.layout.activate_window(&window);766+ if token_data.user_data.get::<UrgentOnlyMarker>().is_some() {
766- self.niri.layer_shell_on_demand_focus = None;767+ mapped.set_urgent(true);
767- self.niri.queue_redraw_all();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+ }
768 } else if let Some(unmapped) = self.niri.unmapped_windows.get_mut(&surface) {774 } else if let Some(unmapped) = self.niri.unmapped_windows.get_mut(&surface) {
769 unmapped.activation_token_data = Some(token_data);775 unmapped.activation_token_data = Some(token_data);
770 }776 }
src/layout/mod.rsmodified+2 -0
@@ -210,6 +210,8 @@ pub trait LayoutElement {
210 fn set_bounds(&self, bounds: Size<i32, Logical>);210 fn set_bounds(&self, bounds: Size<i32, Logical>);
211 fn is_ignoring_opacity_window_rule(&self) -> bool;211 fn is_ignoring_opacity_window_rule(&self) -> bool;
212 212
213+ fn is_urgent(&self) -> bool;
214+
213 fn configure_intent(&self) -> ConfigureIntent;215 fn configure_intent(&self) -> ConfigureIntent;
214 fn send_pending_configure(&mut self);216 fn send_pending_configure(&mut self);
215 217
src/layout/tests.rsmodified+4 -0
@@ -261,6 +261,10 @@ impl LayoutElement for TestWindow {
261 fn interactive_resize_data(&self) -> Option<InteractiveResizeData> {261 fn interactive_resize_data(&self) -> Option<InteractiveResizeData> {
262 None262 None
263 }263 }
264+
265+ fn is_urgent(&self) -> bool {
266+ false
267+ }
264 }268 }
265 269
266 fn arbitrary_bbox() -> impl Strategy<Value = Rectangle<i32, Logical>> {270 fn arbitrary_bbox() -> impl Strategy<Value = Rectangle<i32, Logical>> {
src/window/mapped.rsmodified+22 -0
@@ -77,6 +77,9 @@ pub struct Mapped {
77 /// If `None`, then the window is not offscreened.77 /// If `None`, then the window is not offscreened.
78 offscreen_data: RefCell<Option<OffscreenData>>,78 offscreen_data: RefCell<Option<OffscreenData>>,
79 79
80+ /// Whether this has an urgent indicator.
81+ is_urgent: bool,
82+
80 /// Whether this window has the keyboard focus.83 /// Whether this window has the keyboard focus.
81 is_focused: bool,84 is_focused: bool,
82 85
@@ -231,6 +234,7 @@ impl Mapped {
231 needs_configure: false,234 needs_configure: false,
232 needs_frame_callback: false,235 needs_frame_callback: false,
233 offscreen_data: RefCell::new(None),236 offscreen_data: RefCell::new(None),
237+ is_urgent: false,
234 is_focused: false,238 is_focused: false,
235 is_active_in_column: true,239 is_active_in_column: true,
236 is_floating: false,240 is_floating: false,
@@ -328,6 +332,7 @@ impl Mapped {
328 }332 }
329 333
330 self.is_focused = is_focused;334 self.is_focused = is_focused;
335+ self.is_urgent = false;
331 self.need_to_recompute_rules = true;336 self.need_to_recompute_rules = true;
332 }337 }
333 338
@@ -510,6 +515,19 @@ impl Mapped {
510 pub fn is_windowed_fullscreen(&self) -> bool {515 pub fn is_windowed_fullscreen(&self) -> bool {
511 self.is_windowed_fullscreen516 self.is_windowed_fullscreen
512 }517 }
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+ }
513 }531 }
514 532
515 impl Drop for Mapped {533 impl Drop for Mapped {
@@ -830,6 +848,10 @@ impl LayoutElement for Mapped {
830 }848 }
831 }849 }
832 850
851+ fn is_urgent(&self) -> bool {
852+ self.is_urgent
853+ }
854+
833 fn set_activated(&mut self, active: bool) {855 fn set_activated(&mut self, active: bool) {
834 let changed = self.toplevel().with_pending_state(|state| {856 let changed = self.toplevel().with_pending_state(|state| {
835 if active {857 if active {
src/window/mod.rsmodified+7 -0
@@ -131,6 +131,13 @@ impl<'a> WindowRef<'a> {
131 }131 }
132 }132 }
133 133
134+ pub fn is_urgent(self) -> bool {
135+ match self {
136+ WindowRef::Unmapped(_) => false,
137+ WindowRef::Mapped(mapped) => mapped.is_urgent(),
138+ }
139+ }
140+
134 pub fn is_active_in_column(self) -> bool {141 pub fn is_active_in_column(self) -> bool {
135 match self {142 match self {
136 WindowRef::Unmapped(_) => true,143 WindowRef::Unmapped(_) => true,