From b2069e639ec81497fd6021be57f159df35e6736f Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sun, 22 Mar 2026 17:50:41 +0000 Subject: [PATCH] Maintain focus history per tag Added `tag_focus_history` to `Monitor` to maintain the last focused window for each tag combination. When switching views, `resolve_focus_target` now checks this history before falling back to the topmost window in the visible stack. This prevents focus from resetting to the top window every time the user switches back to a previously visited tag. Co-authored-by: paperbenni <15818888+paperbenni@users.noreply.github.com> --- src/focus.rs | 17 ++++++++++++++++- src/types/monitor.rs | 3 +++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/focus.rs b/src/focus.rs index d4b5deb7..e033a49c 100644 --- a/src/focus.rs +++ b/src/focus.rs @@ -43,7 +43,19 @@ fn resolve_focus_target(core: &CoreCtx, win: Option) -> Option (Option< if let Some(mon) = core.globals_mut().monitor_mut(sel_mon_id) { mon.sel = target; + if let Some(t) = target { + mon.tag_focus_history.insert(mon.selected_tags(), t); + } } (target, selection_state_changed) diff --git a/src/types/monitor.rs b/src/types/monitor.rs index d06e03ef..06d9667a 100644 --- a/src/types/monitor.rs +++ b/src/types/monitor.rs @@ -74,6 +74,8 @@ pub struct Monitor { pub clients: Vec, /// Currently selected client. pub sel: Option, + /// Focus history per tag mask. + pub tag_focus_history: HashMap, /// Overlay window. pub overlay: Option, /// Stack list (stacking order). @@ -112,6 +114,7 @@ impl Default for Monitor { tags: Vec::new(), clients: Vec::new(), sel: None, + tag_focus_history: HashMap::new(), overlay: None, stack: Vec::new(), fullscreen: None,