forge
Explore
Log in

Don't you dare go Hollow

Prevent unintended focus-follows-mouse during workspace switch

Browse files at this commit

55a798bd8b44465a354c1bd7723d4ece855c362cIvan MolodetskikhParent: cdcd5a2
src/layout/mod.rsmodified+29 -0
@@ -1031,6 +1031,35 @@ impl<W: LayoutElement> Layout<W> {
10311031 0.
10321032 }
10331033
1034+ pub fn should_trigger_focus_follows_mouse_on(&self, window: &W::Id) -> bool {
1035+ // During an animation, it's easy to trigger focus-follows-mouse on the previous workspace,
1036+ // especially when clicking to switch workspace on a bar of some kind. This cancels the
1037+ // workspace switch, which is annoying and not intended.
1038+ //
1039+ // This function allows focus-follows-mouse to trigger only on the animation target
1040+ // workspace.
1041+ let MonitorSet::Normal { monitors, .. } = &self.monitor_set else {
1042+ return true;
1043+ };
1044+
1045+ let (mon, ws_idx) = monitors
1046+ .iter()
1047+ .find_map(|mon| {
1048+ mon.workspaces
1049+ .iter()
1050+ .position(|ws| ws.has_window(window))
1051+ .map(|ws_idx| (mon, ws_idx))
1052+ })
1053+ .unwrap();
1054+
1055+ // During a gesture, focus-follows-mouse does not cause any unintended workspace switches.
1056+ if let Some(WorkspaceSwitch::Gesture(_)) = mon.workspace_switch {
1057+ return true;
1058+ }
1059+
1060+ ws_idx == mon.active_workspace_idx
1061+ }
1062+
10341063 pub fn activate_window(&mut self, window: &W::Id) {
10351064 let MonitorSet::Normal {
10361065 monitors,
src/niri.rsmodified+4 -0
@@ -4570,6 +4570,10 @@ impl Niri {
45704570
45714571 if let Some(window) = &new_focus.window {
45724572 if current_focus.window.as_ref() != Some(window) {
4573+ if !self.layout.should_trigger_focus_follows_mouse_on(window) {
4574+ return;
4575+ }
4576+
45734577 if let Some(threshold) = ffm.max_scroll_amount {
45744578 if self.layout.scroll_amount_to_activate(window) > threshold.0 {
45754579 return;