forge
Explore
Log in

Don't you dare go Hollow

Add focus-on-xdg-activate window rule

Browse files at this commit

d89a3ebb640fcb204b4ca41f841a818cc6b9db08Artem TimofeevParent: 720c388
  • feat
    • add focus-on-xdg-activate window rule
Show full message
feat: add focus-on-xdg-activate window rule
docs/wiki/Configuration:-Debug-Options.mdmodified+2 -0
@@ -284,6 +284,8 @@ Most of the time, these fresh tokens will have invalid serials, because the app
284 By default, niri ignores xdg-activation tokens with invalid serials, to prevent windows from randomly stealing focus.284 By default, niri ignores xdg-activation tokens with invalid serials, to prevent windows from randomly stealing focus.
285 This debug flag makes niri honor such tokens, making the aforementioned widely-used apps get focus when clicking on their tray icon or notification.285 This debug flag makes niri honor such tokens, making the aforementioned widely-used apps get focus when clicking on their tray icon or notification.
286 286
287+Use the [`focus-on-xdg-activate` window rule](./Configuration:-Window-Rules.md#focus-on-xdg-activate) to control whether individual windows receive focus for accepted xdg-activation requests.
288+
287 Amusingly, clicking on a notification sends the app a perfectly valid activation token from the notification daemon, but these apps seem to simply ignore it.289 Amusingly, clicking on a notification sends the app a perfectly valid activation token from the notification daemon, but these apps seem to simply ignore it.
288 Maybe in the future these apps/toolkits (Electron, Qt) are fixed, making this debug flag unnecessary.290 Maybe in the future these apps/toolkits (Electron, Qt) are fixed, making this debug flag unnecessary.
289 291
docs/wiki/Configuration:-Window-Rules.mdmodified+20 -0
@@ -58,6 +58,7 @@ window-rule {
58 default-column-display "tabbed"58 default-column-display "tabbed"
59 default-floating-position x=100 y=200 relative-to="bottom-left"59 default-floating-position x=100 y=200 relative-to="bottom-left"
60 scroll-factor 0.7560 scroll-factor 0.75
61+ focus-on-xdg-activate true
61 62
62 focus-ring {63 focus-ring {
63 // off64 // off
@@ -594,6 +595,25 @@ window-rule {
594 > This is because window title (and app ID) are not double-buffered in the Wayland protocol, so they are not tied to specific window contents.595 > This is because window title (and app ID) are not double-buffered in the Wayland protocol, so they are not tied to specific window contents.
595 > There's no robust way for Firefox to synchronize visibly showing a different tab and changing the window title.596 > There's no robust way for Firefox to synchronize visibly showing a different tab and changing the window title.
596 597
598+#### `focus-on-xdg-activate`
599+
600+<sup>Since: next release</sup>
601+
602+Set this to `false` to prevent the window from receiving focus when it requests activation.
603+This is useful for apps that steal focus on incoming messages or when opening popup windows like Picture-in-Picture.
604+
605+When set to `false`, the window will instead be marked as urgent.
606+
607+```kdl
608+// Don't let Firefox PiP steal focus.
609+window-rule {
610+ match title="^Picture-in-Picture$"
611+
612+ open-floating true
613+ focus-on-xdg-activate false
614+}
615+```
616+
597 #### `opacity`617 #### `opacity`
598 618
599 Set the opacity of the window.619 Set the opacity of the window.
niri-config/src/lib.rsmodified+1 -0
@@ -1800,6 +1800,7 @@ mod tests {
1800 open_focused: Some(1800 open_focused: Some(
1801 true,1801 true,
1802 ),1802 ),
1803+ focus_on_xdg_activate: None,
1803 min_width: None,1804 min_width: None,
1804 min_height: None,1805 min_height: None,
1805 max_width: None,1806 max_width: None,
niri-config/src/window_rule.rsmodified+2 -0
@@ -34,6 +34,8 @@ pub struct WindowRule {
34 pub open_floating: Option<bool>,34 pub open_floating: Option<bool>,
35 #[knuffel(child, unwrap(argument))]35 #[knuffel(child, unwrap(argument))]
36 pub open_focused: Option<bool>,36 pub open_focused: Option<bool>,
37+ #[knuffel(child, unwrap(argument))]
38+ pub focus_on_xdg_activate: Option<bool>,
37 39
38 // Rules applied dynamically.40 // Rules applied dynamically.
39 #[knuffel(child, unwrap(argument))]41 #[knuffel(child, unwrap(argument))]
src/handlers/mod.rsmodified+4 -2
@@ -67,7 +67,7 @@ use smithay::wayland::xdg_activation::{
67 pub use crate::handlers::xdg_shell::KdeDecorationsModeState;67 pub use crate::handlers::xdg_shell::KdeDecorationsModeState;
68 use crate::input::click_grab::ClickGrab;68 use crate::input::click_grab::ClickGrab;
69 use crate::layout::workspace::WorkspaceId;69 use crate::layout::workspace::WorkspaceId;
70-use crate::layout::ActivateWindow;70+use crate::layout::{ActivateWindow, LayoutElement};
71 use crate::niri::{DndIcon, NewClient, State};71 use crate::niri::{DndIcon, NewClient, State};
72 use crate::protocols::ext_workspace::{self, ExtWorkspaceHandler, ExtWorkspaceManagerState};72 use crate::protocols::ext_workspace::{self, ExtWorkspaceHandler, ExtWorkspaceManagerState};
73 use crate::protocols::foreign_toplevel::{73 use crate::protocols::foreign_toplevel::{
@@ -815,7 +815,9 @@ impl XdgActivationHandler for State {
815 if token_data.timestamp.elapsed() < XDG_ACTIVATION_TOKEN_TIMEOUT {815 if token_data.timestamp.elapsed() < XDG_ACTIVATION_TOKEN_TIMEOUT {
816 if let Some((mapped, _)) = self.niri.layout.find_window_and_output_mut(&surface) {816 if let Some((mapped, _)) = self.niri.layout.find_window_and_output_mut(&surface) {
817 let window = mapped.window.clone();817 let window = mapped.window.clone();
818- if token_data.user_data.get::<UrgentOnlyMarker>().is_some() {818+ if token_data.user_data.get::<UrgentOnlyMarker>().is_some()
819+ || mapped.rules().focus_on_xdg_activate == Some(false)
820+ {
819 mapped.set_urgent(true);821 mapped.set_urgent(true);
820 self.niri.queue_redraw_all();822 self.niri.queue_redraw_all();
821 } else {823 } else {
src/window/mod.rsmodified+7 -0
@@ -73,6 +73,9 @@ pub struct ResolvedWindowRules {
73 /// Whether the window should open focused.73 /// Whether the window should open focused.
74 pub open_focused: Option<bool>,74 pub open_focused: Option<bool>,
75 75
76+ /// Whether the window should receive focus on xdg-activation requests.
77+ pub focus_on_xdg_activate: Option<bool>,
78+
76 /// Extra bound on the minimum window width.79 /// Extra bound on the minimum window width.
77 pub min_width: Option<u16>,80 pub min_width: Option<u16>,
78 /// Extra bound on the minimum window height.81 /// Extra bound on the minimum window height.
@@ -257,6 +260,10 @@ impl ResolvedWindowRules {
257 resolved.open_focused = Some(x);260 resolved.open_focused = Some(x);
258 }261 }
259 262
263+ if let Some(x) = rule.focus_on_xdg_activate {
264+ resolved.focus_on_xdg_activate = Some(x);
265+ }
266+
260 if let Some(x) = rule.min_width {267 if let Some(x) = rule.min_width {
261 resolved.min_width = Some(x);268 resolved.min_width = Some(x);
262 }269 }