add window urgency through xdg-activation-v1
Browse files at this commit86f57c2ec775d4aa08bf310c94b22ea266eaa9e9Parent: 3cc67896 changed files +52 -7
- niri-visual-tests/src/test_window.rs +4 -0
- src/handlers/mod.rs +13 -7
- src/layout/mod.rs +2 -0
- src/layout/tests.rs +4 -0
- src/window/mapped.rs +22 -0
- src/window/mod.rs +7 -0
niri-visual-tests/src/test_window.rsmodified+4 -0
| @@ -272,4 +272,8 @@ impl LayoutElement for TestWindow { | ||
| 272 | 272 | fn interactive_resize_data(&self) -> Option<InteractiveResizeData> { |
| 273 | 273 | 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 | 708 | delegate_gamma_control!(State); |
| 709 | 709 | |
| 710 | +struct UrgentOnlyMarker; | |
| 711 | + | |
| 710 | 712 | impl XdgActivationHandler for State { |
| 711 | 713 | fn activation_state(&mut self) -> &mut XdgActivationState { |
| 712 | 714 | &mut self.niri.activation_state |
| @@ -716,11 +718,10 @@ impl XdgActivationHandler for State { | ||
| 716 | 718 | // Tokens without a serial are urgency-only. This is not specified, but it seems to be the |
| 717 | 719 | // common client behavior. |
| 718 | 720 | // |
| 719 | - // We don't have urgency yet, so just ignore such tokens. | |
| 720 | - // | |
| 721 | 721 | // See also: https://gitlab.freedesktop.org/wayland/wayland-protocols/-/issues/150 |
| 722 | 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 | 726 | let Some(seat) = Seat::<State>::from_resource(&seat) else { |
| 726 | 727 | return false; |
| @@ -760,11 +761,16 @@ impl XdgActivationHandler for State { | ||
| 760 | 761 | surface: WlSurface, |
| 761 | 762 | ) { |
| 762 | 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 | 765 | 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 | + } | |
| 768 | 774 | } else if let Some(unmapped) = self.niri.unmapped_windows.get_mut(&surface) { |
| 769 | 775 | unmapped.activation_token_data = Some(token_data); |
| 770 | 776 | } |
src/layout/mod.rsmodified+2 -0
| @@ -210,6 +210,8 @@ pub trait LayoutElement { | ||
| 210 | 210 | fn set_bounds(&self, bounds: Size<i32, Logical>); |
| 211 | 211 | fn is_ignoring_opacity_window_rule(&self) -> bool; |
| 212 | 212 | |
| 213 | + fn is_urgent(&self) -> bool; | |
| 214 | + | |
| 213 | 215 | fn configure_intent(&self) -> ConfigureIntent; |
| 214 | 216 | fn send_pending_configure(&mut self); |
| 215 | 217 |
src/layout/tests.rsmodified+4 -0
| @@ -261,6 +261,10 @@ impl LayoutElement for TestWindow { | ||
| 261 | 261 | fn interactive_resize_data(&self) -> Option<InteractiveResizeData> { |
| 262 | 262 | None |
| 263 | 263 | } |
| 264 | + | |
| 265 | + fn is_urgent(&self) -> bool { | |
| 266 | + false | |
| 267 | + } | |
| 264 | 268 | } |
| 265 | 269 | |
| 266 | 270 | fn arbitrary_bbox() -> impl Strategy<Value = Rectangle<i32, Logical>> { |
src/window/mapped.rsmodified+22 -0
| @@ -77,6 +77,9 @@ pub struct Mapped { | ||
| 77 | 77 | /// If `None`, then the window is not offscreened. |
| 78 | 78 | offscreen_data: RefCell<Option<OffscreenData>>, |
| 79 | 79 | |
| 80 | + /// Whether this has an urgent indicator. | |
| 81 | + is_urgent: bool, | |
| 82 | + | |
| 80 | 83 | /// Whether this window has the keyboard focus. |
| 81 | 84 | is_focused: bool, |
| 82 | 85 | |
| @@ -231,6 +234,7 @@ impl Mapped { | ||
| 231 | 234 | needs_configure: false, |
| 232 | 235 | needs_frame_callback: false, |
| 233 | 236 | offscreen_data: RefCell::new(None), |
| 237 | + is_urgent: false, | |
| 234 | 238 | is_focused: false, |
| 235 | 239 | is_active_in_column: true, |
| 236 | 240 | is_floating: false, |
| @@ -328,6 +332,7 @@ impl Mapped { | ||
| 328 | 332 | } |
| 329 | 333 | |
| 330 | 334 | self.is_focused = is_focused; |
| 335 | + self.is_urgent = false; | |
| 331 | 336 | self.need_to_recompute_rules = true; |
| 332 | 337 | } |
| 333 | 338 | |
| @@ -510,6 +515,19 @@ impl Mapped { | ||
| 510 | 515 | pub fn is_windowed_fullscreen(&self) -> bool { |
| 511 | 516 | 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 | 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 | 855 | fn set_activated(&mut self, active: bool) { |
| 834 | 856 | let changed = self.toplevel().with_pending_state(|state| { |
| 835 | 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 | 141 | pub fn is_active_in_column(self) -> bool { |
| 135 | 142 | match self { |
| 136 | 143 | WindowRef::Unmapped(_) => true, |