From 7a2411ce50fc9c3e8b48787d7c19ed533537dd88 Mon Sep 17 00:00:00 2001 From: Carlos Garnacho Date: Thu, 2 Nov 2023 17:13:40 +0100 Subject: [PATCH] wayland: Refactor grab checks for tablets Do not jump at MetaWaylandSeat across the MetaWaylandTabletSeat to poke at the tablet tools, and chain up the checks through a MetaWaylandTabletSeat method instead. While at it, use g_autoptr to manage the tool list, and fix a leak. Part-of: --- src/wayland/meta-wayland-seat.c | 31 +++++++--------------- src/wayland/meta-wayland-tablet-seat.c | 36 ++++++++++++++++++++++++++ src/wayland/meta-wayland-tablet-seat.h | 8 ++++++ 3 files changed, 53 insertions(+), 22 deletions(-) diff --git a/src/wayland/meta-wayland-seat.c b/src/wayland/meta-wayland-seat.c index 24e3fa840..35a389324 100644 --- a/src/wayland/meta-wayland-seat.c +++ b/src/wayland/meta-wayland-seat.c @@ -489,10 +489,6 @@ meta_wayland_seat_get_grab_info (MetaWaylandSeat *seat, float *x, float *y) { - GList *tools, *l; - - tools = g_hash_table_get_values (seat->tablet_seat->tools); - if (meta_wayland_seat_has_touch (seat)) { ClutterEventSequence *sequence; @@ -534,25 +530,16 @@ meta_wayland_seat_get_grab_info (MetaWaylandSeat *seat, } } - for (l = tools; l; l = l->next) + if (meta_wayland_tablet_seat_get_grab_info (seat->tablet_seat, + surface, + serial, + require_pressed, + device_out, + x, y)) { - MetaWaylandTabletTool *tool = l->data; - - if ((!require_pressed || tool->button_count > 0) && - meta_wayland_tablet_tool_can_grab_surface (tool, surface, serial)) - { - if (device_out) - *device_out = tool->device; - if (sequence_out) - *sequence_out = NULL; - - if (x) - *x = tool->grab_x; - if (y) - *y = tool->grab_y; - - return TRUE; - } + if (sequence_out) + *sequence_out = NULL; + return TRUE; } return FALSE; diff --git a/src/wayland/meta-wayland-tablet-seat.c b/src/wayland/meta-wayland-tablet-seat.c index 633dbbb04..861252cbe 100644 --- a/src/wayland/meta-wayland-tablet-seat.c +++ b/src/wayland/meta-wayland-tablet-seat.c @@ -567,3 +567,39 @@ meta_wayland_tablet_seat_can_popup (MetaWaylandTabletSeat *tablet_seat, return FALSE; } + +gboolean +meta_wayland_tablet_seat_get_grab_info (MetaWaylandTabletSeat *tablet_seat, + MetaWaylandSurface *surface, + uint32_t serial, + gboolean require_pressed, + ClutterInputDevice **device_out, + float *x, + float *y) +{ + g_autoptr (GList) tools = NULL; + GList *l; + + tools = g_hash_table_get_values (tablet_seat->tools); + + for (l = tools; l; l = l->next) + { + MetaWaylandTabletTool *tool = l->data; + + if ((!require_pressed || tool->button_count > 0) && + meta_wayland_tablet_tool_can_grab_surface (tool, surface, serial)) + { + if (device_out) + *device_out = tool->device; + + if (x) + *x = tool->grab_x; + if (y) + *y = tool->grab_y; + + return TRUE; + } + } + + return FALSE; +} diff --git a/src/wayland/meta-wayland-tablet-seat.h b/src/wayland/meta-wayland-tablet-seat.h index b0028190b..beee347af 100644 --- a/src/wayland/meta-wayland-tablet-seat.h +++ b/src/wayland/meta-wayland-tablet-seat.h @@ -76,3 +76,11 @@ GList *meta_wayland_tablet_seat_lookup_paired_pads (MetaWaylan MetaWaylandTablet *tablet); gboolean meta_wayland_tablet_seat_can_popup (MetaWaylandTabletSeat *tablet_seat, uint32_t serial); + +gboolean meta_wayland_tablet_seat_get_grab_info (MetaWaylandTabletSeat *tablet_seat, + MetaWaylandSurface *surface, + uint32_t serial, + gboolean require_pressed, + ClutterInputDevice **device_out, + float *x, + float *y);