From c0f0e0c46e741f854854b4baa882ba92d0f3a696 Mon Sep 17 00:00:00 2001 From: Consolatis <35009135+Consolatis@users.noreply.github.com> Date: Sun, 11 Sep 2022 07:08:28 +0200 Subject: [PATCH] cursor: Allow re-enter for cursor_update_focus() This allows forcing an application to re-set their desired cursor image. --- include/labwc.h | 9 ++++++--- src/cursor.c | 6 +++--- src/desktop.c | 2 +- src/view.c | 2 +- src/xwayland-unmanaged.c | 8 ++++---- 5 files changed, 15 insertions(+), 12 deletions(-) diff --git a/include/labwc.h b/include/labwc.h index 93f1e01c..6032d472 100644 --- a/include/labwc.h +++ b/include/labwc.h @@ -532,10 +532,13 @@ void cursor_set(struct seat *seat, const char *cursor_name); /** * cursor_update_focus - update cursor focus, may update the cursor icon * @server - server - * Use it to force an update of the cursor icon and to send an enter event - * to the surface below the cursor. + * @force_reenter - re-enter a surface if it already owns the cursor focus + * + * This can be used to give the mouse focus to the surface under the cursor + * or to force an update of the cursor icon by sending an exit and enter + * event to an already focused surface when @force_reenter is true. */ -void cursor_update_focus(struct server *server); +void cursor_update_focus(struct server *server, bool force_reenter); void cursor_init(struct seat *seat); void cursor_finish(struct seat *seat); diff --git a/src/cursor.c b/src/cursor.c index fc5a3204..c20dc0a9 100644 --- a/src/cursor.c +++ b/src/cursor.c @@ -365,7 +365,7 @@ msec(const struct timespec *t) } void -cursor_update_focus(struct server *server) +cursor_update_focus(struct server *server, bool force_reenter) { double sx, sy; struct wlr_scene_node *node = NULL; @@ -386,7 +386,7 @@ cursor_update_focus(struct server *server) ssd_update_button_hover(node, &seat->server->ssd_hover_state); /* Focus surface under cursor if it isn't already focused */ - cursor_rebase(seat, node, surface, sx, sy, msec(&now), false); + cursor_rebase(seat, node, surface, sx, sy, msec(&now), force_reenter); } void @@ -848,7 +848,7 @@ cursor_axis(struct wl_listener *listener, void *data) wlr_idle_notify_activity(seat->wlr_idle, seat->seat); /* Make sure we are sending the events to the surface under the cursor */ - cursor_update_focus(seat->server); + cursor_update_focus(seat->server, false); /* Notify the client with pointer focus of the axis event. */ wlr_seat_pointer_notify_axis(seat->seat, event->time_msec, diff --git a/src/desktop.c b/src/desktop.c index e6d09080..20e73ff9 100644 --- a/src/desktop.c +++ b/src/desktop.c @@ -65,7 +65,7 @@ desktop_move_to_front(struct view *view) #if HAVE_XWAYLAND move_xwayland_sub_views_to_front(view); #endif - cursor_update_focus(view->server); + cursor_update_focus(view->server, false); } static void diff --git a/src/view.c b/src/view.c index 0f5a8351..088d3647 100644 --- a/src/view.c +++ b/src/view.c @@ -149,7 +149,7 @@ view_moved(struct view *view) wlr_scene_node_set_position(&view->scene_tree->node, view->x, view->y); view_discover_output(view); ssd_update_geometry(view); - cursor_update_focus(view->server); + cursor_update_focus(view->server, false); } /* N.B. Use view_move() if not resizing. */ diff --git a/src/xwayland-unmanaged.c b/src/xwayland-unmanaged.c index b09b6196..db6022d6 100644 --- a/src/xwayland-unmanaged.c +++ b/src/xwayland-unmanaged.c @@ -11,7 +11,7 @@ unmanaged_handle_request_configure(struct wl_listener *listener, void *data) wlr_xwayland_surface_configure(xsurface, ev->x, ev->y, ev->width, ev->height); if (unmanaged->node) { wlr_scene_node_set_position(unmanaged->node, ev->x, ev->y); - cursor_update_focus(unmanaged->server); + cursor_update_focus(unmanaged->server, false); } } @@ -23,7 +23,7 @@ unmanaged_handle_set_geometry(struct wl_listener *listener, void *data) struct wlr_xwayland_surface *xsurface = unmanaged->xwayland_surface; if (unmanaged->node) { wlr_scene_node_set_position(unmanaged->node, xsurface->x, xsurface->y); - cursor_update_focus(unmanaged->server); + cursor_update_focus(unmanaged->server, false); } } @@ -51,7 +51,7 @@ unmanaged_handle_map(struct wl_listener *listener, void *data) unmanaged->server->unmanaged_tree, xsurface->surface)->buffer->node; wlr_scene_node_set_position(unmanaged->node, xsurface->x, xsurface->y); - cursor_update_focus(unmanaged->server); + cursor_update_focus(unmanaged->server, false); } static void @@ -105,7 +105,7 @@ unmanaged_handle_unmap(struct wl_listener *listener, void *data) seat_reset_pressed(seat); } unmanaged->node = NULL; - cursor_update_focus(unmanaged->server); + cursor_update_focus(unmanaged->server, false); if (seat->seat->keyboard_state.focused_surface == xsurface->surface) { focus_next_surface(unmanaged->server, xsurface);