Add debounce-ms recent-windows setting
Browse files at this commitd74debda132dd4b44c045d6d3333d7b586316808Parent: 642277f4 changed files +39 -12
- docs/wiki/Configuration:-Recent-Windows.md +26 -0
- niri-config/src/lib.rs +2 -3
- niri-config/src/recent_windows.rs +5 -5
- src/niri.rs +6 -4
docs/wiki/Configuration:-Recent-Windows.mdmodified+26 -0
| @@ -9,6 +9,8 @@ Here is an outline of the available settings and their default values: | |||
| 9 | ```kdl | 9 | ```kdl |
| 10 | recent-windows { | 10 | recent-windows { |
| 11 | // off | 11 | // off |
| 12 | + debounce-ms 750 | ||
| 13 | + | ||
| 12 | open-delay-ms 150 | 14 | open-delay-ms 150 |
| 13 | 15 | ||
| 14 | highlight { | 16 | highlight { |
| @@ -39,6 +41,30 @@ recent-windows { | |||
| 39 | 41 | ||
| 40 | `off` disables the recent windows switcher altogether. | 42 | `off` disables the recent windows switcher altogether. |
| 41 | 43 | ||
| 44 | +### `debounce-ms` | ||
| 45 | + | ||
| 46 | +Delay, in milliseconds, between the window receiving focus and getting "committed" to the recent windows list. | ||
| 47 | + | ||
| 48 | +When you want to focus some window, you might end up focusing some unrelated windows on the way: | ||
| 49 | + | ||
| 50 | +- with keyboard navigation, the windows between your current one and the target one; | ||
| 51 | +- with [`focus-follows-mouse`](./Configuration:-Input.md#focus-follows-mouse), the windows you happen to cross with the mouse pointer on the way to the target window. | ||
| 52 | + | ||
| 53 | +The debounce delay prevents those intermediate windows from polluting the recent windows list. | ||
| 54 | + | ||
| 55 | +Note that some actions, like keyboard input into the target window, will skip this delay and commit the window to the list immediately. | ||
| 56 | +This way, the recent windows list stays responsive while not getting polluted too much with unintended windows. | ||
| 57 | + | ||
| 58 | +If you want windows to appear in recent windows right away, including intermediate windows, you can reduce the delay or set it to zero: | ||
| 59 | + | ||
| 60 | +```kdl | ||
| 61 | +recent-windows { | ||
| 62 | + // Commit windows to the recent windows list as soon as they're focused, | ||
| 63 | + // with no debounce delay. | ||
| 64 | + debounce-ms 0 | ||
| 65 | +} | ||
| 66 | +``` | ||
| 67 | + | ||
| 42 | ### `open-delay-ms` | 68 | ### `open-delay-ms` |
| 43 | 69 | ||
| 44 | Delay, in milliseconds, between pressing the Alt-Tab bind and the recent windows switcher visually appearing on screen. | 70 | Delay, in milliseconds, between pressing the Alt-Tab bind and the recent windows switcher visually appearing on screen. |
niri-config/src/lib.rsmodified+2 -3
| @@ -56,9 +56,7 @@ pub use crate::layout::*; | |||
| 56 | pub use crate::misc::*; | 56 | pub use crate::misc::*; |
| 57 | pub use crate::output::{Output, OutputName, Outputs, Position, Vrr}; | 57 | pub use crate::output::{Output, OutputName, Outputs, Position, Vrr}; |
| 58 | use crate::recent_windows::RecentWindowsPart; | 58 | use crate::recent_windows::RecentWindowsPart; |
| 59 | -pub use crate::recent_windows::{ | 59 | +pub use crate::recent_windows::{MruDirection, MruFilter, MruPreviews, MruScope, RecentWindows}; |
| 60 | - MruDirection, MruFilter, MruPreviews, MruScope, RecentWindows, DEFAULT_MRU_COMMIT_MS, | ||
| 61 | -}; | ||
| 62 | pub use crate::utils::FloatOrInt; | 60 | pub use crate::utils::FloatOrInt; |
| 63 | use crate::utils::{Flag, MergeWith as _}; | 61 | use crate::utils::{Flag, MergeWith as _}; |
| 64 | pub use crate::window_rule::{FloatingPosition, RelativeTo, WindowRule}; | 62 | pub use crate::window_rule::{FloatingPosition, RelativeTo, WindowRule}; |
| @@ -2181,6 +2179,7 @@ mod tests { | |||
| 2181 | ], | 2179 | ], |
| 2182 | recent_windows: RecentWindows { | 2180 | recent_windows: RecentWindows { |
| 2183 | on: false, | 2181 | on: false, |
| 2182 | + debounce_ms: 750, | ||
| 2184 | open_delay_ms: 150, | 2183 | open_delay_ms: 150, |
| 2185 | highlight: MruHighlight { | 2184 | highlight: MruHighlight { |
| 2186 | active_color: Color { | 2185 | active_color: Color { |
niri-config/src/recent_windows.rsmodified+5 -5
| @@ -6,13 +6,10 @@ use smithay::input::keyboard::Keysym; | |||
| 6 | use crate::utils::{expect_only_children, MergeWith}; | 6 | use crate::utils::{expect_only_children, MergeWith}; |
| 7 | use crate::{Action, Bind, Color, FloatOrInt, Key, Modifiers, Trigger}; | 7 | use crate::{Action, Bind, Color, FloatOrInt, Key, Modifiers, Trigger}; |
| 8 | 8 | ||
| 9 | -/// Delay before the window focus is considered to be locked-in for Window | ||
| 10 | -/// MRU ordering. For now the delay is not configurable. | ||
| 11 | -pub const DEFAULT_MRU_COMMIT_MS: u64 = 750; | ||
| 12 | - | ||
| 13 | #[derive(Debug, PartialEq)] | 9 | #[derive(Debug, PartialEq)] |
| 14 | pub struct RecentWindows { | 10 | pub struct RecentWindows { |
| 15 | pub on: bool, | 11 | pub on: bool, |
| 12 | + pub debounce_ms: u16, | ||
| 16 | pub open_delay_ms: u16, | 13 | pub open_delay_ms: u16, |
| 17 | pub highlight: MruHighlight, | 14 | pub highlight: MruHighlight, |
| 18 | pub previews: MruPreviews, | 15 | pub previews: MruPreviews, |
| @@ -23,6 +20,7 @@ impl Default for RecentWindows { | |||
| 23 | fn default() -> Self { | 20 | fn default() -> Self { |
| 24 | RecentWindows { | 21 | RecentWindows { |
| 25 | on: true, | 22 | on: true, |
| 23 | + debounce_ms: 750, | ||
| 26 | open_delay_ms: 150, | 24 | open_delay_ms: 150, |
| 27 | highlight: MruHighlight::default(), | 25 | highlight: MruHighlight::default(), |
| 28 | previews: MruPreviews::default(), | 26 | previews: MruPreviews::default(), |
| @@ -38,6 +36,8 @@ pub struct RecentWindowsPart { | |||
| 38 | #[knuffel(child)] | 36 | #[knuffel(child)] |
| 39 | pub off: bool, | 37 | pub off: bool, |
| 40 | #[knuffel(child, unwrap(argument))] | 38 | #[knuffel(child, unwrap(argument))] |
| 39 | + pub debounce_ms: Option<u16>, | ||
| 40 | + #[knuffel(child, unwrap(argument))] | ||
| 41 | pub open_delay_ms: Option<u16>, | 41 | pub open_delay_ms: Option<u16>, |
| 42 | #[knuffel(child)] | 42 | #[knuffel(child)] |
| 43 | pub highlight: Option<MruHighlightPart>, | 43 | pub highlight: Option<MruHighlightPart>, |
| @@ -54,7 +54,7 @@ impl MergeWith<RecentWindowsPart> for RecentWindows { | |||
| 54 | self.on = false; | 54 | self.on = false; |
| 55 | } | 55 | } |
| 56 | 56 | ||
| 57 | - merge_clone!((self, part), open_delay_ms); | 57 | + merge_clone!((self, part), debounce_ms, open_delay_ms); |
| 58 | merge!((self, part), highlight, previews); | 58 | merge!((self, part), highlight, previews); |
| 59 | 59 | ||
| 60 | if let Some(part) = &part.binds { | 60 | if let Some(part) = &part.binds { |
src/niri.rsmodified+6 -4
| @@ -16,7 +16,7 @@ use calloop::futures::Scheduler; | |||
| 16 | use niri_config::debug::PreviewRender; | 16 | use niri_config::debug::PreviewRender; |
| 17 | use niri_config::{ | 17 | use niri_config::{ |
| 18 | Config, FloatOrInt, Key, Modifiers, OutputName, TrackLayout, WarpMouseToFocusMode, | 18 | Config, FloatOrInt, Key, Modifiers, OutputName, TrackLayout, WarpMouseToFocusMode, |
| 19 | - WorkspaceReference, Xkb, DEFAULT_MRU_COMMIT_MS, | 19 | + WorkspaceReference, Xkb, |
| 20 | }; | 20 | }; |
| 21 | use smithay::backend::allocator::Fourcc; | 21 | use smithay::backend::allocator::Fourcc; |
| 22 | use smithay::backend::input::Keycode; | 22 | use smithay::backend::input::Keycode; |
| @@ -1255,11 +1255,13 @@ impl State { | |||
| 1255 | // period has gone by without the focus having elsewhere. | 1255 | // period has gone by without the focus having elsewhere. |
| 1256 | let stamp = get_monotonic_time(); | 1256 | let stamp = get_monotonic_time(); |
| 1257 | 1257 | ||
| 1258 | - if mapped.get_focus_timestamp().is_none() { | 1258 | + let debounce = self.niri.config.borrow().recent_windows.debounce_ms; |
| 1259 | + let debounce = Duration::from_millis(u64::from(debounce)); | ||
| 1260 | + | ||
| 1261 | + if mapped.get_focus_timestamp().is_none() || debounce.is_zero() { | ||
| 1259 | mapped.set_focus_timestamp(stamp); | 1262 | mapped.set_focus_timestamp(stamp); |
| 1260 | } else { | 1263 | } else { |
| 1261 | - let timer = | 1264 | + let timer = Timer::from_duration(debounce); |
| 1262 | - Timer::from_duration(Duration::from_millis(DEFAULT_MRU_COMMIT_MS)); | ||
| 1263 | 1265 | ||
| 1264 | let focus_token = self | 1266 | let focus_token = self |
| 1265 | .niri | 1267 | .niri |