diff --git a/include/labwc.h b/include/labwc.h index 999db395..62863def 100644 --- a/include/labwc.h +++ b/include/labwc.h @@ -78,6 +78,9 @@ struct seat { */ struct cursor_context_saved pressed; + /* Cursor context of the last cursor motion */ + struct cursor_context_saved last_cursor_ctx; + struct lab_set bound_buttons; struct { diff --git a/src/input/cursor.c b/src/input/cursor.c index d3221513..2a681a6e 100644 --- a/src/input/cursor.c +++ b/src/input/cursor.c @@ -664,9 +664,6 @@ cursor_process_motion(struct server *server, uint32_t time, double *sx, double * } } - struct wlr_surface *old_focused_surface = - seat->seat->pointer_state.focused_surface; - /* * Cursor context that is actually interacting with cursor and should * be notified to the client. E.g. it is cleared when menu is open, @@ -675,19 +672,28 @@ cursor_process_motion(struct server *server, uint32_t time, double *sx, double * struct cursor_context notified_ctx = {0}; cursor_update_common(server, &ctx, ¬ified_ctx); - 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 (rc.focus_follow_mouse) { /* - * If followMouse=yes, update the keyboard focus when the - * cursor enters a surface + * If followMouse=yes, entering a surface or view updates + * keyboard focus. Note that moving the cursor between a + * surface and a SSD within the same view doesn't update + * keyboard focus, and that entering a surface/view doesn't + * update keyboard focus if implicit grab is active. */ - desktop_focus_view_or_surface(seat, - view_from_wlr_surface(new_focused_surface), - new_focused_surface, rc.raise_on_focus); + bool entering = false; + if (notified_ctx.view) { + entering = notified_ctx.view + != seat->last_cursor_ctx.ctx.view; + } else if (notified_ctx.surface) { + entering = notified_ctx.surface + != seat->last_cursor_ctx.ctx.surface; + } + if (entering) { + desktop_focus_view_or_surface(seat, notified_ctx.view, + notified_ctx.surface, rc.raise_on_focus); + } } + cursor_context_save(&seat->last_cursor_ctx, ¬ified_ctx); *sx = notified_ctx.sx; *sy = notified_ctx.sy;