From e4004a7c4feb777ee565fd49214dc13bb2bfd27b Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Tue, 20 Aug 2024 12:38:52 +1000 Subject: [PATCH] wayland: Use the tool's current_tablet device instead of caching it The tablet tool is initialized with a device but if that device is later removed we never update tool->device. This eventually causes a crash when we're passing that device into meta_wayland_input_invalidate_focus(). The tool keeps track of the current tablet anyway so instead of caching this pointer in the tool, use the current tablet's device. Closes: https://gitlab.gnome.org/GNOME/mutter/-/issues/3642 Part-of: --- src/wayland/meta-wayland-tablet-seat.c | 5 ++--- src/wayland/meta-wayland-tablet-tool.c | 8 +++----- src/wayland/meta-wayland-tablet-tool.h | 1 - 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/wayland/meta-wayland-tablet-seat.c b/src/wayland/meta-wayland-tablet-seat.c index 71e47f8da..58f62a838 100644 --- a/src/wayland/meta-wayland-tablet-seat.c +++ b/src/wayland/meta-wayland-tablet-seat.c @@ -362,7 +362,6 @@ meta_wayland_tablet_seat_lookup_pad (MetaWaylandTabletSeat *tablet_seat, static MetaWaylandTabletTool * meta_wayland_tablet_seat_ensure_tool (MetaWaylandTabletSeat *tablet_seat, - ClutterInputDevice *device, ClutterInputDeviceTool *device_tool) { MetaWaylandTabletTool *tool; @@ -371,7 +370,7 @@ meta_wayland_tablet_seat_ensure_tool (MetaWaylandTabletSeat *tablet_seat, if (!tool) { - tool = meta_wayland_tablet_tool_new (tablet_seat, device, device_tool); + tool = meta_wayland_tablet_tool_new (tablet_seat, device_tool); g_hash_table_insert (tablet_seat->tools, device_tool, tool); } @@ -399,7 +398,7 @@ meta_wayland_tablet_seat_update (MetaWaylandTabletSeat *tablet_seat, device_tool = clutter_event_get_device_tool (event); if (device && device_tool) - tool = meta_wayland_tablet_seat_ensure_tool (tablet_seat, device, device_tool); + tool = meta_wayland_tablet_seat_ensure_tool (tablet_seat, device_tool); if (!tool) return; diff --git a/src/wayland/meta-wayland-tablet-tool.c b/src/wayland/meta-wayland-tablet-tool.c index dbafff724..ca0cd59b9 100644 --- a/src/wayland/meta-wayland-tablet-tool.c +++ b/src/wayland/meta-wayland-tablet-tool.c @@ -41,7 +41,6 @@ struct _MetaWaylandTabletTool { MetaWaylandTabletSeat *seat; - ClutterInputDevice *device; ClutterInputDeviceTool *device_tool; struct wl_list resource_list; struct wl_list focus_resource_list; @@ -423,7 +422,6 @@ tool_cursor_prepare_at (MetaCursorSpriteXcursor *sprite_xcursor, MetaWaylandTabletTool * meta_wayland_tablet_tool_new (MetaWaylandTabletSeat *seat, - ClutterInputDevice *device, ClutterInputDeviceTool *device_tool) { MetaWaylandCompositor *compositor = @@ -435,7 +433,6 @@ meta_wayland_tablet_tool_new (MetaWaylandTabletSeat *seat, tool = g_new0 (MetaWaylandTabletTool, 1); tool->seat = seat; - tool->device = device; tool->device_tool = device_tool; wl_list_init (&tool->resource_list); wl_list_init (&tool->focus_resource_list); @@ -634,7 +631,8 @@ meta_wayland_tablet_tool_set_current_surface (MetaWaylandTabletTool *tool, tablet_seat = tool->seat; input = meta_wayland_seat_get_input (tablet_seat->seat); - meta_wayland_input_invalidate_focus (input, tool->device, NULL); + if (tool->current_tablet) + meta_wayland_input_invalidate_focus (input, tool->current_tablet->device, NULL); } static void @@ -1002,7 +1000,7 @@ meta_wayland_tablet_tool_get_grab_info (MetaWaylandTabletTool *tool, meta_wayland_tablet_tool_can_grab_surface (tool, surface, serial)) { if (device_out) - *device_out = tool->device; + *device_out = tool->current_tablet ? NULL : tool->current_tablet->device; if (x) *x = tool->grab_x; diff --git a/src/wayland/meta-wayland-tablet-tool.h b/src/wayland/meta-wayland-tablet-tool.h index d7c0cb6b8..660002fe9 100644 --- a/src/wayland/meta-wayland-tablet-tool.h +++ b/src/wayland/meta-wayland-tablet-tool.h @@ -29,7 +29,6 @@ #include "wayland/meta-wayland-types.h" MetaWaylandTabletTool * meta_wayland_tablet_tool_new (MetaWaylandTabletSeat *seat, - ClutterInputDevice *device, ClutterInputDeviceTool *device_tool); void meta_wayland_tablet_tool_free (MetaWaylandTabletTool *tool);