Skip to content

Commit

Permalink
Prevent unintended focus-follows-mouse during workspace switch
Browse files Browse the repository at this point in the history
  • Loading branch information
YaLTeR committed Sep 12, 2024
1 parent cdcd5a2 commit 55a798b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/layout/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1031,6 +1031,35 @@ impl<W: LayoutElement> Layout<W> {
0.
}

pub fn should_trigger_focus_follows_mouse_on(&self, window: &W::Id) -> bool {
// During an animation, it's easy to trigger focus-follows-mouse on the previous workspace,
// especially when clicking to switch workspace on a bar of some kind. This cancels the
// workspace switch, which is annoying and not intended.
//
// This function allows focus-follows-mouse to trigger only on the animation target
// workspace.
let MonitorSet::Normal { monitors, .. } = &self.monitor_set else {
return true;
};

let (mon, ws_idx) = monitors
.iter()
.find_map(|mon| {
mon.workspaces
.iter()
.position(|ws| ws.has_window(window))
.map(|ws_idx| (mon, ws_idx))
})
.unwrap();

// During a gesture, focus-follows-mouse does not cause any unintended workspace switches.
if let Some(WorkspaceSwitch::Gesture(_)) = mon.workspace_switch {
return true;
}

ws_idx == mon.active_workspace_idx
}

pub fn activate_window(&mut self, window: &W::Id) {
let MonitorSet::Normal {
monitors,
Expand Down
4 changes: 4 additions & 0 deletions src/niri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4570,6 +4570,10 @@ impl Niri {

if let Some(window) = &new_focus.window {
if current_focus.window.as_ref() != Some(window) {
if !self.layout.should_trigger_focus_follows_mouse_on(window) {
return;
}

if let Some(threshold) = ffm.max_scroll_amount {
if self.layout.scroll_amount_to_activate(window) > threshold.0 {
return;
Expand Down

0 comments on commit 55a798b

Please sign in to comment.