Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion src/focus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,19 @@ fn resolve_focus_target(core: &CoreCtx, win: Option<WindowId>) -> Option<FocusTa
});

if target.is_none() {
target = mon.first_visible_client(core.globals().clients.map());
// Try focus history first
if let Some(&hist_win) = mon.tag_focus_history.get(&selected.bits()) {
if core.globals().clients.get(&hist_win).map_or(false, |c| {
c.is_visible_on_tags(selected.bits()) && !c.is_hidden
}) {
target = Some(hist_win);
}
}

// Fallback to top of stack
if target.is_none() {
target = mon.first_visible_client(core.globals().clients.map());
}
}

Some(FocusTargetResult {
Expand All @@ -66,6 +78,9 @@ fn update_focus_state(core: &mut CoreCtx, result: FocusTargetResult) -> (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)
Expand Down
3 changes: 3 additions & 0 deletions src/types/monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ pub struct Monitor {
pub clients: Vec<WindowId>,
/// Currently selected client.
pub sel: Option<WindowId>,
/// Focus history per tag mask.
pub tag_focus_history: HashMap<u32, WindowId>,
/// Overlay window.
pub overlay: Option<WindowId>,
/// Stack list (stacking order).
Expand Down Expand Up @@ -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,
Expand Down
Loading