From 885919fc5fce2df9bf178204b1c72d4c2d6f8b45 Mon Sep 17 00:00:00 2001 From: tokyo4j Date: Tue, 1 Apr 2025 21:32:31 +0900 Subject: [PATCH] cursor: let followMouse update focus only when cursor enters a surface Before this patch, when followMouse and followMouseRequiresMovement are both yes, we set the keyboard focus when the cursor moves within an unfocused surface. However, kwin, xfwm4 and openbox all set keyboard focus only when the cursor enters a surface. --- src/input/cursor.c | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/src/input/cursor.c b/src/input/cursor.c index ce0a6799..2963ceff 100644 --- a/src/input/cursor.c +++ b/src/input/cursor.c @@ -599,11 +599,6 @@ cursor_process_motion(struct server *server, uint32_t time, double *sx, double * dnd_icons_move(seat, seat->cursor->x, seat->cursor->y); } - if ((ctx.view || ctx.surface) && rc.focus_follow_mouse) { - desktop_focus_view_or_surface(seat, ctx.view, ctx.surface, - rc.raise_on_focus); - } - struct mousebind *mousebind; wl_list_for_each(mousebind, &rc.mousebinds, link) { if (mousebind->mouse_event == MOUSE_ACTION_DRAG @@ -619,8 +614,27 @@ cursor_process_motion(struct server *server, uint32_t time, double *sx, double * } } - return cursor_update_common(server, &ctx, time, + struct wlr_surface *old_focused_surface = + seat->seat->pointer_state.focused_surface; + + bool notify = cursor_update_common(server, &ctx, time, /* cursor_has_moved */ true, sx, sy); + + struct wlr_surface *new_focused_surface = + seat->seat->pointer_state.focused_surface; + + if (rc.focus_follow_mouse && new_focused_surface + && old_focused_surface != new_focused_surface) { + /* + * If followMouse=yes, update the keyboard focus when the + * cursor enters a surface + */ + desktop_focus_view_or_surface(seat, + view_from_wlr_surface(new_focused_surface), + new_focused_surface, rc.raise_on_focus); + } + + return notify; } static uint32_t -- 2.52.0