forge
Explore
Log in

Don't you dare go Hollow

Add deactivate-unfocused-windows debug flag (#1706)

Browse files at this commit

8d7b22d1a8968a46286fdd13ca9d8d2c88e10e48Unverifiedsashomasho and Ivan MolodetskikhParent: 0407ac5
* force xdg deactivation on invisable workspaces

This debug option provides a workaround for many Chromium-based chat
applications that fail to show notifications when they're active in
a workspace that's not currently visible and don't have keyboard focus

Signed-off-by: Alex Yosifov <sashomasho@gmail.com>

* fixes

---------

Signed-off-by: Alex Yosifov <sashomasho@gmail.com>
niri-config/src/lib.rsmodified+3 -0
@@ -2351,6 +2351,8 @@ pub struct DebugConfig {
2351 #[knuffel(child)]2351 #[knuffel(child)]
2352 pub honor_xdg_activation_with_invalid_serial: bool,2352 pub honor_xdg_activation_with_invalid_serial: bool,
2353 #[knuffel(child)]2353 #[knuffel(child)]
2354+ pub deactivate_unfocused_windows: bool,
2355+ #[knuffel(child)]
2354 pub skip_cursor_only_updates_during_vrr: bool,2356 pub skip_cursor_only_updates_during_vrr: bool,
2355 }2357 }
2356 2358
@@ -5324,6 +5326,7 @@ mod tests {
5324 disable_monitor_names: false,5326 disable_monitor_names: false,
5325 strict_new_window_focus_policy: false,5327 strict_new_window_focus_policy: false,
5326 honor_xdg_activation_with_invalid_serial: false,5328 honor_xdg_activation_with_invalid_serial: false,
5329+ deactivate_unfocused_windows: false,
5327 skip_cursor_only_updates_during_vrr: false,5330 skip_cursor_only_updates_during_vrr: false,
5328 },5331 },
5329 workspaces: [5332 workspaces: [
src/layout/floating.rsmodified+5 -2
@@ -1090,7 +1090,7 @@ impl<W: LayoutElement> FloatingSpace<W> {
1090 self.interactive_resize = None;1090 self.interactive_resize = None;
1091 }1091 }
1092 1092
1093- pub fn refresh(&mut self, is_active: bool) {1093+ pub fn refresh(&mut self, is_active: bool, is_focused: bool) {
1094 let active = self.active_window_id.clone();1094 let active = self.active_window_id.clone();
1095 for tile in &mut self.tiles {1095 for tile in &mut self.tiles {
1096 let win = tile.window_mut();1096 let win = tile.window_mut();
@@ -1098,7 +1098,10 @@ impl<W: LayoutElement> FloatingSpace<W> {
1098 win.set_active_in_column(true);1098 win.set_active_in_column(true);
1099 win.set_floating(true);1099 win.set_floating(true);
1100 1100
1101- let is_active = is_active && Some(win.id()) == active.as_ref();1101+ let mut is_active = is_active && Some(win.id()) == active.as_ref();
1102+ if self.options.deactivate_unfocused_windows {
1103+ is_active &= is_focused;
1104+ }
1102 win.set_activated(is_active);1105 win.set_activated(is_active);
1103 1106
1104 let resize_data = self1107 let resize_data = self
src/layout/mod.rsmodified+6 -2
@@ -361,6 +361,7 @@ pub struct Options {
361 // Debug flags.361 // Debug flags.
362 pub disable_resize_throttling: bool,362 pub disable_resize_throttling: bool,
363 pub disable_transactions: bool,363 pub disable_transactions: bool,
364+ pub deactivate_unfocused_windows: bool,
364 }365 }
365 366
366 impl Default for Options {367 impl Default for Options {
@@ -393,6 +394,7 @@ impl Default for Options {
393 PresetSize::Proportion(0.5),394 PresetSize::Proportion(0.5),
394 PresetSize::Proportion(2. / 3.),395 PresetSize::Proportion(2. / 3.),
395 ],396 ],
397+ deactivate_unfocused_windows: false,
396 }398 }
397 }399 }
398 }400 }
@@ -658,6 +660,7 @@ impl Options {
658 overview: config.overview,660 overview: config.overview,
659 disable_resize_throttling: config.debug.disable_resize_throttling,661 disable_resize_throttling: config.debug.disable_resize_throttling,
660 disable_transactions: config.debug.disable_transactions,662 disable_transactions: config.debug.disable_transactions,
663+ deactivate_unfocused_windows: config.debug.deactivate_unfocused_windows,
661 preset_window_heights,664 preset_window_heights,
662 }665 }
663 }666 }
@@ -5124,7 +5127,8 @@ impl<W: LayoutElement> Layout<W> {
5124 }5127 }
5125 5128
5126 for (ws_idx, ws) in mon.workspaces.iter_mut().enumerate() {5129 for (ws_idx, ws) in mon.workspaces.iter_mut().enumerate() {
5127- ws.refresh(is_active);5130+ let is_focused = is_active && ws_idx == mon.active_workspace_idx;
5131+ ws.refresh(is_active, is_focused);
5128 5132
5129 if let Some(is_scrolling) = ongoing_scrolling_dnd {5133 if let Some(is_scrolling) = ongoing_scrolling_dnd {
5130 // Lock or unlock the view for scrolling interactive move.5134 // Lock or unlock the view for scrolling interactive move.
@@ -5144,7 +5148,7 @@ impl<W: LayoutElement> Layout<W> {
5144 }5148 }
5145 MonitorSet::NoOutputs { workspaces, .. } => {5149 MonitorSet::NoOutputs { workspaces, .. } => {
5146 for ws in workspaces {5150 for ws in workspaces {
5147- ws.refresh(false);5151+ ws.refresh(false, false);
5148 ws.view_offset_gesture_end(None);5152 ws.view_offset_gesture_end(None);
5149 }5153 }
5150 }5154 }
src/layout/scrolling.rsmodified+7 -4
@@ -3458,7 +3458,7 @@ impl<W: LayoutElement> ScrollingSpace<W> {
3458 self.interactive_resize = None;3458 self.interactive_resize = None;
3459 }3459 }
3460 3460
3461- pub fn refresh(&mut self, is_active: bool) {3461+ pub fn refresh(&mut self, is_active: bool, is_focused: bool) {
3462 for (col_idx, col) in self.columns.iter_mut().enumerate() {3462 for (col_idx, col) in self.columns.iter_mut().enumerate() {
3463 let mut col_resize_data = None;3463 let mut col_resize_data = None;
3464 if let Some(resize) = &self.interactive_resize {3464 if let Some(resize) = &self.interactive_resize {
@@ -3503,11 +3503,14 @@ impl<W: LayoutElement> ScrollingSpace<W> {
3503 win.set_active_in_column(active_in_column);3503 win.set_active_in_column(active_in_column);
3504 win.set_floating(false);3504 win.set_floating(false);
3505 3505
3506- let active = is_active3506+ let mut active = is_active && self.active_column_idx == col_idx;
3507- && self.active_column_idx == col_idx3507+ if self.options.deactivate_unfocused_windows {
3508+ active &= active_in_column && is_focused;
3509+ } else {
3508 // In tabbed mode, all tabs have activated state to reduce unnecessary3510 // In tabbed mode, all tabs have activated state to reduce unnecessary
3509 // animations when switching tabs.3511 // animations when switching tabs.
3510- && (active_in_column || is_tabbed);3512+ active &= active_in_column || is_tabbed;
3513+ }
3511 win.set_activated(active);3514 win.set_activated(active);
3512 3515
3513 win.set_interactive_resize(col_resize_data);3516 win.set_interactive_resize(col_resize_data);
src/layout/workspace.rsmodified+3 -3
@@ -1600,11 +1600,11 @@ impl<W: LayoutElement> Workspace<W> {
1600 }1600 }
1601 }1601 }
1602 1602
1603- pub fn refresh(&mut self, is_active: bool) {1603+ pub fn refresh(&mut self, is_active: bool, is_focused: bool) {
1604 self.scrolling1604 self.scrolling
1605- .refresh(is_active && !self.floating_is_active.get());1605+ .refresh(is_active && !self.floating_is_active.get(), is_focused);
1606 self.floating1606 self.floating
1607- .refresh(is_active && self.floating_is_active.get());1607+ .refresh(is_active && self.floating_is_active.get(), is_focused);
1608 }1608 }
1609 1609
1610 pub fn scroll_amount_to_activate(&self, window: &W::Id) -> f64 {1610 pub fn scroll_amount_to_activate(&self, window: &W::Id) -> f64 {
wiki/Configuration:-Debug-Options.mdmodified+18 -1
@@ -28,8 +28,9 @@ debug {
28 keep-laptop-panel-on-when-lid-is-closed28 keep-laptop-panel-on-when-lid-is-closed
29 disable-monitor-names29 disable-monitor-names
30 strict-new-window-focus-policy30 strict-new-window-focus-policy
31- honor-xdg-activation-with-invalid-serial 31+ honor-xdg-activation-with-invalid-serial
32 skip-cursor-only-updates-during-vrr32 skip-cursor-only-updates-during-vrr
33+ deactivate-unfocused-windows
33 }34 }
34 35
35 binds {36 binds {
@@ -292,6 +293,22 @@ debug {
292 }293 }
293 ```294 ```
294 295
296+### `deactivate-unfocused-windows`
297+
298+<sup>Since: next release</sup>
299+
300+Some clients (notably, Chromium- and Electron-based, like Teams or Slack) erroneously use the Activated xdg window state instead of keyboard focus for things like deciding whether to send notifications for new messages, or for picking where to show an IME popup.
301+Niri keeps the Activated state on unfocused workspaces and invisible tabbed windows (to reduce unwanted animations), surfacing bugs in these applications.
302+
303+Set this debug flag to work around these problems.
304+It will cause niri to drop the Activated state for all unfocused windows.
305+
306+```kdl
307+debug {
308+ deactivate-unfocused-windows
309+}
310+```
311+
295 ### Key Bindings312 ### Key Bindings
296 313
297 These are not debug options, but rather key bindings.314 These are not debug options, but rather key bindings.