From aecbd679e39a321495964995fa1e37d84bd91ddf Mon Sep 17 00:00:00 2001 From: Ivan Molodetskikh Date: Sat, 15 Nov 2025 10:52:04 +0300 Subject: Reimplement focus-previous-window with MRU focus timestamps Makes it consistent with the MRU and improves the behavior: - considers MRU's debounce - fixes problematic cases where focus changes to non-Layout and back --- src/input/mod.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'src/input') diff --git a/src/input/mod.rs b/src/input/mod.rs index a6fc549f..a952a23a 100644 --- a/src/input/mod.rs +++ b/src/input/mod.rs @@ -779,7 +779,19 @@ impl State { self.niri.queue_redraw_all(); } Action::FocusWindowPrevious => { - if let Some(window) = self.niri.previously_focused_window.clone() { + let current = self.niri.layout.focus().map(|win| win.id()); + if let Some(window) = self + .niri + .layout + .windows() + .map(|(_, win)| win) + .filter(|win| Some(win.id()) != current) + .max_by_key(|win| win.get_focus_timestamp()) + .map(|win| win.window.clone()) + { + // Commit current focus so repeated focus-window-previous works as expected. + self.niri.mru_apply_keyboard_commit(); + self.focus_window(&window); } } -- cgit