From 03b504fc38d20dd15664238a74a8375b316e38f2 Mon Sep 17 00:00:00 2001 From: Carlos Garnacho Date: Tue, 27 Feb 2024 13:06:24 +0100 Subject: [PATCH] wayland: Refactor pointer grab checks Move the bulk of the implementation inside MetaWaylandPointer files, like it happens in other places (e.g. MetaWaylandTabletSeat). This avoids MetaWaylandPointer struct peeking from outside. Part-of: --- src/wayland/meta-wayland-pointer.c | 28 +++++++++++++++++++++++++++- src/wayland/meta-wayland-pointer.h | 10 +++++++--- src/wayland/meta-wayland-seat.c | 26 ++++++++++---------------- 3 files changed, 44 insertions(+), 20 deletions(-) diff --git a/src/wayland/meta-wayland-pointer.c b/src/wayland/meta-wayland-pointer.c index 6db9d33f8..afa2c90b6 100644 --- a/src/wayland/meta-wayland-pointer.c +++ b/src/wayland/meta-wayland-pointer.c @@ -1259,7 +1259,7 @@ pointer_can_grab_surface (MetaWaylandPointer *pointer, return FALSE; } -gboolean +static gboolean meta_wayland_pointer_can_grab_surface (MetaWaylandPointer *pointer, MetaWaylandSurface *surface, uint32_t serial) @@ -1268,6 +1268,32 @@ meta_wayland_pointer_can_grab_surface (MetaWaylandPointer *pointer, pointer_can_grab_surface (pointer, surface)); } +gboolean +meta_wayland_pointer_get_grab_info (MetaWaylandPointer *pointer, + MetaWaylandSurface *surface, + uint32_t serial, + gboolean require_pressed, + ClutterInputDevice **device_out, + float *x, + float *y) +{ + if ((!require_pressed || pointer->button_count > 0) && + meta_wayland_pointer_can_grab_surface (pointer, surface, serial)) + { + if (device_out) + *device_out = pointer->device; + + if (x) + *x = pointer->grab_x; + if (y) + *y = pointer->grab_y; + + return TRUE; + } + + return FALSE; +} + gboolean meta_wayland_pointer_can_popup (MetaWaylandPointer *pointer, uint32_t serial) { diff --git a/src/wayland/meta-wayland-pointer.h b/src/wayland/meta-wayland-pointer.h index 7b7578c92..7c4e38110 100644 --- a/src/wayland/meta-wayland-pointer.h +++ b/src/wayland/meta-wayland-pointer.h @@ -100,9 +100,13 @@ void meta_wayland_pointer_create_new_resource (MetaWaylandPointer *pointer, struct wl_resource *seat_resource, uint32_t id); -gboolean meta_wayland_pointer_can_grab_surface (MetaWaylandPointer *pointer, - MetaWaylandSurface *surface, - uint32_t serial); +gboolean meta_wayland_pointer_get_grab_info (MetaWaylandPointer *pointer, + MetaWaylandSurface *surface, + uint32_t serial, + gboolean require_pressed, + ClutterInputDevice **device_out, + float *x, + float *y); gboolean meta_wayland_pointer_can_popup (MetaWaylandPointer *pointer, uint32_t serial); diff --git a/src/wayland/meta-wayland-seat.c b/src/wayland/meta-wayland-seat.c index 924573d7b..ebbe533c3 100644 --- a/src/wayland/meta-wayland-seat.c +++ b/src/wayland/meta-wayland-seat.c @@ -601,23 +601,17 @@ meta_wayland_seat_get_grab_info (MetaWaylandSeat *seat, } } - if (meta_wayland_seat_has_pointer (seat)) + if (meta_wayland_seat_has_pointer (seat) && + meta_wayland_pointer_get_grab_info (seat->pointer, + surface, + serial, + require_pressed, + device_out, + x, y)) { - if ((!require_pressed || seat->pointer->button_count > 0) && - meta_wayland_pointer_can_grab_surface (seat->pointer, surface, serial)) - { - if (device_out) - *device_out = seat->pointer->device; - if (sequence_out) - *sequence_out = NULL; - - if (x) - *x = seat->pointer->grab_x; - if (y) - *y = seat->pointer->grab_y; - - return TRUE; - } + if (sequence_out) + *sequence_out = NULL; + return TRUE; } if (meta_wayland_tablet_seat_get_grab_info (seat->tablet_seat,