Prevent unintended focus-follows-mouse during workspace switch
Browse files at this commit55a798bd8b44465a354c1bd7723d4ece855c362cParent: cdcd5a22 changed files +33 -0
- src/layout/mod.rs +29 -0
- src/niri.rs +4 -0
src/layout/mod.rsmodified+29 -0
| @@ -1031,6 +1031,35 @@ impl<W: LayoutElement> Layout<W> { | |||
| 1031 | 0. | 1031 | 0. |
| 1032 | } | 1032 | } |
| 1033 | 1033 | ||
| 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 | + | ||
| 1034 | pub fn activate_window(&mut self, window: &W::Id) { | 1063 | pub fn activate_window(&mut self, window: &W::Id) { |
| 1035 | let MonitorSet::Normal { | 1064 | let MonitorSet::Normal { |
| 1036 | monitors, | 1065 | monitors, |
src/niri.rsmodified+4 -0
| @@ -4570,6 +4570,10 @@ impl Niri { | |||
| 4570 | 4570 | ||
| 4571 | if let Some(window) = &new_focus.window { | 4571 | if let Some(window) = &new_focus.window { |
| 4572 | if current_focus.window.as_ref() != Some(window) { | 4572 | if current_focus.window.as_ref() != Some(window) { |
| 4573 | + if !self.layout.should_trigger_focus_follows_mouse_on(window) { | ||
| 4574 | + return; | ||
| 4575 | + } | ||
| 4576 | + | ||
| 4573 | if let Some(threshold) = ffm.max_scroll_amount { | 4577 | if let Some(threshold) = ffm.max_scroll_amount { |
| 4574 | if self.layout.scroll_amount_to_activate(window) > threshold.0 { | 4578 | if self.layout.scroll_amount_to_activate(window) > threshold.0 { |
| 4575 | return; | 4579 | return; |