Skip to content

Commit 269fcfd

Browse files
committed
Fix focus_follows_mouse switching active window on desktop return
When returning to a desktop/space, enter_event fires and detects the window under the cursor, triggering focus_follows_mouse to switch focus even though the mouse didn't cross a window boundary. Add a focus_follows parameter to set_currently_hovered_window so enter_event can update hover state without triggering focus switching. Normal mouse motion still switches focus on boundary crossings as before.
1 parent fc162e8 commit 269fcfd

2 files changed

Lines changed: 9 additions & 7 deletions

File tree

docs/changelog.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,8 @@ Detailed list of changes
187187

188188
- Change :opt:`focus_follows_mouse` to switch the active window only when the mouse crosses into a different window, instead of on every mouse motion event. Prevents accidental mouse bumps from undoing a keyboard-driven window switch.
189189

190+
- Fix :opt:`focus_follows_mouse` switching the active window when returning from another desktop/space, instead of preserving the previously active window.
191+
190192
- Wayland: Use hold gestures to cancel momentum scrolling when fingers are placed on the trackpad, for a more natural kinetic scrolling experience (:iss:`9863`)
191193

192194
- Fix thickness of diagonal lines in box drawing characters not the same as horizontal/vertical lines (:iss:`9719`)

kitty/mouse.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ update_scrollbar_hover_state(Window *w, bool hovering) {
181181
}
182182

183183
static void
184-
set_currently_hovered_window(id_type window_id, int modifiers) {
184+
set_currently_hovered_window(id_type window_id, int modifiers, bool focus_follows) {
185185
if (global_state.mouse_hover_in_window != window_id) {
186186
Window *left_window = window_for_id(global_state.mouse_hover_in_window);
187187
global_state.mouse_hover_in_window = window_id;
@@ -196,7 +196,7 @@ set_currently_hovered_window(id_type window_id, int modifiers) {
196196
debug("Sent mouse leave event to window: %llu\n", left_window->id);
197197
}
198198
}
199-
if (window_id && OPT(focus_follows_mouse) && global_state.callback_os_window && global_state.callback_os_window->num_tabs) {
199+
if (focus_follows && window_id && OPT(focus_follows_mouse) && global_state.callback_os_window && global_state.callback_os_window->num_tabs) {
200200
Tab *t = global_state.callback_os_window->tabs + global_state.callback_os_window->active_tab;
201201
for (unsigned i = 0; i < t->num_windows; i++) {
202202
if (t->windows[i].id == window_id) {
@@ -927,7 +927,7 @@ currently_pressed_button(void) {
927927
HANDLER(handle_event) {
928928
modifiers &= ~GLFW_LOCK_MASK;
929929
set_mouse_cursor_for_screen(w->render_data.screen);
930-
set_currently_hovered_window(w->id, modifiers);
930+
set_currently_hovered_window(w->id, modifiers, true);
931931
if (button == -1) {
932932
button = currently_pressed_button();
933933
handle_move_event(w, button, modifiers, window_idx);
@@ -948,7 +948,7 @@ handle_window_title_bar_mouse(Window *w, int button, int modifiers, int action)
948948

949949
static void
950950
handle_tab_bar_mouse(int button, int modifiers, int action) {
951-
set_currently_hovered_window(0, modifiers);
951+
set_currently_hovered_window(0, modifiers, false);
952952
OSWindow *w = global_state.callback_os_window;
953953
// dont report motion events, as they are expensive and useless
954954
if (w && (button > -1 || global_state.tab_being_dragged.id)) {
@@ -1139,7 +1139,7 @@ update_mouse_pointer_shape(void) {
11391139
void
11401140
leave_event(int modifiers) {
11411141
if (global_state.redirect_mouse_handling || global_state.active_drag_in_window || global_state.tracked_drag_in_window) return;
1142-
set_currently_hovered_window(0, modifiers);
1142+
set_currently_hovered_window(0, modifiers, false);
11431143
}
11441144

11451145
void
@@ -1161,7 +1161,7 @@ enter_event(int modifiers) {
11611161
if (global_state.redirect_mouse_handling || global_state.active_drag_in_window || global_state.tracked_drag_in_window) return;
11621162
MouseRegion r = mouse_region(false, false);
11631163
Window *w = r.window;
1164-
set_currently_hovered_window(w ? w->id : 0, modifiers);
1164+
set_currently_hovered_window(w ? w->id : 0, modifiers, false);
11651165
if (!w || r.in_tab_bar || r.in_title_bar) return;
11661166

11671167
if (handle_scrollbar_mouse(w, -1, MOVE, modifiers)) return;
@@ -1347,7 +1347,7 @@ mouse_event(const int button, int modifiers, int action) {
13471347
}
13481348
MouseRegion r = mouse_region(true, true);
13491349
w = r.window; window_idx = r.window_idx;
1350-
set_currently_hovered_window(w && !r.window_border && !r.in_title_bar ? w->id : 0, modifiers);
1350+
set_currently_hovered_window(w && !r.window_border && !r.in_title_bar ? w->id : 0, modifiers, true);
13511351

13521352
if (r.in_tab_bar || global_state.tab_being_dragged.id) {
13531353
mouse_cursor_shape = POINTER_POINTER;

0 commit comments

Comments
 (0)