From c93c2e7718bcd4c7c728a76f5a34be3a825f0629 Mon Sep 17 00:00:00 2001 From: Olivier Fourdan Date: Wed, 20 Oct 2021 09:32:34 +0200 Subject: [PATCH] xwayland: Add xwl_cursor_clear_frame_cb() The code to clear a cursor pending frame callback was duplicated in multiple places in the code. Introduce a new xwl_cursor_clear_frame_cb() function and remove the duplicated code. No functional change. Signed-off-by: Olivier Fourdan Reviewed-by: Simon Ser Reviewed-by: Carlos Garnacho --- hw/xwayland/xwayland-cursor.c | 30 ++++++++++++++++-------------- hw/xwayland/xwayland-cursor.h | 1 + hw/xwayland/xwayland-input.c | 10 ++-------- 3 files changed, 19 insertions(+), 22 deletions(-) diff --git a/hw/xwayland/xwayland-cursor.c b/hw/xwayland/xwayland-cursor.c index 27b090442..16c13fb64 100644 --- a/hw/xwayland/xwayland-cursor.c +++ b/hw/xwayland/xwayland-cursor.c @@ -111,15 +111,6 @@ xwl_unrealize_cursor(DeviceIntPtr device, ScreenPtr screen, CursorPtr cursor) return xwl_shm_destroy_pixmap(pixmap); } -static void -clear_cursor_frame_callback(struct xwl_cursor *xwl_cursor) -{ - if (xwl_cursor->frame_cb) { - wl_callback_destroy (xwl_cursor->frame_cb); - xwl_cursor->frame_cb = NULL; - } -} - static void frame_callback(void *data, struct wl_callback *callback, @@ -127,7 +118,7 @@ frame_callback(void *data, { struct xwl_cursor *xwl_cursor = data; - clear_cursor_frame_callback(xwl_cursor); + xwl_cursor_clear_frame_cb(xwl_cursor); if (xwl_cursor->needs_update) { xwl_cursor->needs_update = FALSE; xwl_cursor->update_proc(xwl_cursor); @@ -187,6 +178,18 @@ xwl_cursor_attach_pixmap(struct xwl_seat *xwl_seat, wl_surface_commit(xwl_cursor->surface); } +Bool +xwl_cursor_clear_frame_cb(struct xwl_cursor *xwl_cursor) +{ + if (xwl_cursor->frame_cb) { + wl_callback_destroy(xwl_cursor->frame_cb); + xwl_cursor->frame_cb = NULL; + return TRUE; + } + + return FALSE; +} + void xwl_seat_set_cursor(struct xwl_seat *xwl_seat) { @@ -200,7 +203,7 @@ xwl_seat_set_cursor(struct xwl_seat *xwl_seat) if (!xwl_seat->x_cursor) { wl_pointer_set_cursor(xwl_seat->wl_pointer, xwl_seat->pointer_enter_serial, NULL, 0, 0); - clear_cursor_frame_callback(xwl_cursor); + xwl_cursor_clear_frame_cb(xwl_cursor); xwl_cursor->needs_update = FALSE; return; } @@ -238,7 +241,7 @@ xwl_tablet_tool_set_cursor(struct xwl_tablet_tool *xwl_tablet_tool) zwp_tablet_tool_v2_set_cursor(xwl_tablet_tool->tool, xwl_tablet_tool->proximity_in_serial, NULL, 0, 0); - clear_cursor_frame_callback(xwl_cursor); + xwl_cursor_clear_frame_cb(xwl_cursor); xwl_cursor->needs_update = FALSE; return; } @@ -268,8 +271,7 @@ void xwl_cursor_release(struct xwl_cursor *xwl_cursor) { wl_surface_destroy(xwl_cursor->surface); - if (xwl_cursor->frame_cb) - wl_callback_destroy(xwl_cursor->frame_cb); + xwl_cursor_clear_frame_cb(xwl_cursor); } static void diff --git a/hw/xwayland/xwayland-cursor.h b/hw/xwayland/xwayland-cursor.h index a48ef16e4..76b5b49b6 100644 --- a/hw/xwayland/xwayland-cursor.h +++ b/hw/xwayland/xwayland-cursor.h @@ -31,6 +31,7 @@ #include #include +Bool xwl_cursor_clear_frame_cb(struct xwl_cursor *xwl_cursor); void xwl_cursor_release(struct xwl_cursor *xwl_cursor); void xwl_tablet_tool_set_cursor(struct xwl_tablet_tool *tool); void xwl_seat_set_cursor(struct xwl_seat *xwl_seat); diff --git a/hw/xwayland/xwayland-input.c b/hw/xwayland/xwayland-input.c index 3b3378e98..f5c24048f 100644 --- a/hw/xwayland/xwayland-input.c +++ b/hw/xwayland/xwayland-input.c @@ -463,11 +463,8 @@ pointer_handle_enter(void *data, struct wl_pointer *pointer, * of our surfaces might not have been shown. In that case we'll * have a cursor surface frame callback pending which we need to * clear so that we can continue submitting new cursor frames. */ - if (xwl_seat->cursor.frame_cb) { - wl_callback_destroy(xwl_seat->cursor.frame_cb); - xwl_seat->cursor.frame_cb = NULL; + if (xwl_cursor_clear_frame_cb(&xwl_seat->cursor)) xwl_seat_set_cursor(xwl_seat); - } if (xwl_seat->pointer_warp_emulator) { xwl_pointer_warp_emulator_maybe_lock(xwl_seat->pointer_warp_emulator, @@ -1672,10 +1669,7 @@ tablet_tool_proximity_in(void *data, struct zwp_tablet_tool_v2 *tool, /* If there is a cursor surface frame callback pending, we need to clear it * so that we can continue submitting new cursor frames. */ - if (xwl_tablet_tool->cursor.frame_cb) { - wl_callback_destroy(xwl_tablet_tool->cursor.frame_cb); - xwl_tablet_tool->cursor.frame_cb = NULL; - } + xwl_cursor_clear_frame_cb(&xwl_tablet_tool->cursor); xwl_tablet_tool_set_cursor(xwl_tablet_tool); }