]> git.mdlowis.com Git - proto/labwc.git/commitdiff
cursor: let followMouse update focus only when cursor enters a surface
authortokyo4j <hrak1529@gmail.com>
Tue, 1 Apr 2025 12:32:31 +0000 (21:32 +0900)
committerJohan Malm <johanmalm@users.noreply.github.com>
Wed, 2 Apr 2025 19:42:07 +0000 (20:42 +0100)
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

index ce0a67993ea5ae9061dfe4d239b29e4f19d0fba0..2963ceffdcdf8b4b15a64b8b76c9405953585ee1 100644 (file)
@@ -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