From f057235a1f48e39e16b515ff261167b36119bb8b Mon Sep 17 00:00:00 2001 From: Consolatis <35009135+Consolatis@users.noreply.github.com> Date: Thu, 8 Sep 2022 01:07:55 +0200 Subject: [PATCH] cursor: Make cursor_rebase() private Also allow to re-use node, surface, sx and sy. --- include/labwc.h | 10 +--------- src/cursor.c | 48 ++++++++++++++++++++++++++++++------------------ 2 files changed, 31 insertions(+), 27 deletions(-) diff --git a/include/labwc.h b/include/labwc.h index 20fe882b..4d1d7c3b 100644 --- a/include/labwc.h +++ b/include/labwc.h @@ -521,14 +521,6 @@ struct view *desktop_node_and_view_at(struct server *server, double lx, struct view *desktop_view_at_cursor(struct server *server); -/** - * cursor_rebase - set cursor icon for and send motion-event to surface below it - * @seat - current seat - * @time_msec - time now - * @force - disable check for skipping already focused surface - */ -void cursor_rebase(struct seat *seat, uint32_t time_msec, bool force); - /** * cursor_set - set cursor icon * @seat - current seat @@ -537,7 +529,7 @@ void cursor_rebase(struct seat *seat, uint32_t time_msec, bool force); void cursor_set(struct seat *seat, const char *cursor_name); /** - * cursor_update_focus - update cursor focus + * 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. diff --git a/src/cursor.c b/src/cursor.c index 894fd9bd..72e3c74b 100644 --- a/src/cursor.c +++ b/src/cursor.c @@ -24,21 +24,15 @@ is_surface(enum ssd_part_type view_area) ; } -void -cursor_rebase(struct seat *seat, uint32_t time_msec, bool force) +/* + * cursor_rebase() for internal use: reuses node, surface, sx and sy + * For a public variant use cursor_update_focus() + */ +static void +cursor_rebase(struct seat *seat, struct wlr_scene_node *node, + struct wlr_surface *surface, double sx, double sy, uint32_t time_msec, + bool force) { - double sx, sy; - struct wlr_scene_node *node; - enum ssd_part_type view_area = LAB_SSD_NONE; - struct wlr_surface *surface = NULL; - - desktop_node_and_view_at(seat->server, seat->cursor->x, - seat->cursor->y, &node, &sx, &sy, &view_area); - if (is_surface(view_area)) { - surface = lab_wlr_surface_from_node(node); - } - - ssd_update_button_hover(node, &seat->server->ssd_hover_state); if (seat->pressed.surface && surface != seat->pressed.surface) { /* Don't leave surface when a button was pressed over another surface */ return; @@ -373,10 +367,26 @@ msec(const struct timespec *t) void cursor_update_focus(struct server *server) { + double sx, sy; + struct wlr_scene_node *node = NULL; + struct wlr_surface *surface = NULL; + enum ssd_part_type view_area = LAB_SSD_NONE; + struct timespec now; clock_gettime(CLOCK_MONOTONIC, &now); + + struct seat *seat = &server->seat; + desktop_node_and_view_at(seat->server, seat->cursor->x, + seat->cursor->y, &node, &sx, &sy, &view_area); + + if (is_surface(view_area)) { + surface = lab_wlr_surface_from_node(node); + } + + ssd_update_button_hover(node, &seat->server->ssd_hover_state); + /* Focus surface under cursor if it isn't already focused */ - cursor_rebase(&server->seat, msec(&now), false); + cursor_rebase(seat, node, surface, sx, sy, msec(&now), false); } void @@ -701,7 +711,7 @@ cursor_button(struct wl_listener *listener, void *data) wlr_idle_notify_activity(seat->wlr_idle, seat->seat); double sx, sy; - struct wlr_scene_node *node; + struct wlr_scene_node *node = NULL; enum ssd_part_type view_area = LAB_SSD_NONE; uint32_t resize_edges = 0; @@ -745,7 +755,8 @@ cursor_button(struct wl_listener *listener, void *data) if (server->input_mode == LAB_INPUT_STATE_MENU) { if (close_menu) { menu_close_root(server); - cursor_rebase(&server->seat, event->time_msec, false); + cursor_rebase(&server->seat, node, surface, sx, sy, + event->time_msec, false); close_menu = false; } return; @@ -763,7 +774,8 @@ cursor_button(struct wl_listener *listener, void *data) * Focus surface under cursor and force updating the * cursor icon */ - cursor_rebase(&server->seat, event->time_msec, true); + cursor_rebase(&server->seat, node, surface, sx, sy, + event->time_msec, true); return; } goto mousebindings;