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: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3420>
This commit is contained in:
Carlos Garnacho 2023-11-02 17:13:40 +01:00
parent a37fd34bbb
commit 7a2411ce50
3 changed files with 53 additions and 22 deletions

View File

@ -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;

View File

@ -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;
}

View File

@ -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);