From 0c19ef6c2caa0686d924ab9e8377da4a787fccd5 Mon Sep 17 00:00:00 2001 From: Carlos Garnacho Date: Fri, 24 Nov 2023 23:30:36 +0100 Subject: [PATCH] gdk/wayland: Improve recent serial lookup This function takes an event, so the place(s) that do not have one readily available can only pass NULL, so the serial lookup will only work for the pointer. Pass a device (plus optional sequence) to this function, as these places do at least have the corresponding GdkDevice at hand. Fixes serial lookups for DnD, for other devices than pointers (e.g. tablets, or touch). --- gdk/wayland/gdkdrag-wayland.c | 2 +- gdk/wayland/gdkprivate-wayland.h | 5 ++-- gdk/wayland/gdkseat-wayland.c | 50 +++++++++++++++++-------------- gdk/wayland/gdktoplevel-wayland.c | 4 ++- 4 files changed, 34 insertions(+), 27 deletions(-) diff --git a/gdk/wayland/gdkdrag-wayland.c b/gdk/wayland/gdkdrag-wayland.c index d323ba6e38..a637b3abe5 100644 --- a/gdk/wayland/gdkdrag-wayland.c +++ b/gdk/wayland/gdkdrag-wayland.c @@ -397,7 +397,7 @@ _gdk_wayland_surface_drag_begin (GdkSurface *surface, drag_wayland->data_source, gdk_wayland_surface_get_wl_surface (surface), gdk_wayland_surface_get_wl_surface (drag_wayland->dnd_surface), - _gdk_wayland_seat_get_implicit_grab_serial (seat, NULL)); + _gdk_wayland_seat_get_implicit_grab_serial (seat, device, NULL)); cursor = gdk_drag_get_cursor (drag, gdk_drag_get_selected_action (drag)); gdk_drag_set_cursor (drag, cursor); diff --git a/gdk/wayland/gdkprivate-wayland.h b/gdk/wayland/gdkprivate-wayland.h index 0860f118b4..d1da4dbf71 100644 --- a/gdk/wayland/gdkprivate-wayland.h +++ b/gdk/wayland/gdkprivate-wayland.h @@ -164,8 +164,9 @@ void _gdk_wayland_display_remove_seat (GdkWaylandDisplay *displa guint32 id); GdkKeymap *_gdk_wayland_device_get_keymap (GdkDevice *device); -uint32_t _gdk_wayland_seat_get_implicit_grab_serial(GdkSeat *seat, - GdkEvent *event); +uint32_t _gdk_wayland_seat_get_implicit_grab_serial (GdkSeat *seat, + GdkDevice *event, + GdkEventSequence *sequence); uint32_t _gdk_wayland_seat_get_last_implicit_grab_serial (GdkWaylandSeat *seat, GdkEventSequence **sequence); GdkSurface * gdk_wayland_device_get_focus (GdkDevice *device); diff --git a/gdk/wayland/gdkseat-wayland.c b/gdk/wayland/gdkseat-wayland.c index b284388f62..f44258a05b 100644 --- a/gdk/wayland/gdkseat-wayland.c +++ b/gdk/wayland/gdkseat-wayland.c @@ -4344,35 +4344,39 @@ _gdk_wayland_display_remove_seat (GdkWaylandDisplay *display_wayland, } uint32_t -_gdk_wayland_seat_get_implicit_grab_serial (GdkSeat *seat, - GdkEvent *event) +_gdk_wayland_seat_get_implicit_grab_serial (GdkSeat *seat, + GdkDevice *device, + GdkEventSequence *sequence) { - GdkEventSequence *sequence = NULL; - GdkWaylandTouchData *touch = NULL; - - if (event) - sequence = gdk_event_get_event_sequence (event); + GdkWaylandSeat *wayland_seat = GDK_WAYLAND_SEAT (seat); + GList *l; if (sequence) - touch = gdk_wayland_seat_get_touch (GDK_WAYLAND_SEAT (seat), - GDK_EVENT_SEQUENCE_TO_SLOT (sequence)); - - if (touch) - return touch->touch_down_serial; - - if (event) { - GdkDevice *source = gdk_event_get_device (event); - GdkWaylandSeat *wayland_seat = GDK_WAYLAND_SEAT (seat); - GList *l; + GdkWaylandTouchData *touch = NULL; - for (l = wayland_seat->tablets; l; l = l->next) - { - GdkWaylandTabletData *tablet = l->data; + touch = gdk_wayland_seat_get_touch (GDK_WAYLAND_SEAT (seat), + GDK_EVENT_SEQUENCE_TO_SLOT (sequence)); + if (touch) + return touch->touch_down_serial; + } + else if (device == wayland_seat->logical_touch) + { + GdkWaylandTouchData *touch; + GHashTableIter iter; - if (tablet->stylus_device == source) - return tablet->pointer_info.press_serial; - } + /* Pick the first sequence */ + g_hash_table_iter_init (&iter, wayland_seat->touches); + g_hash_table_iter_next (&iter, NULL, (gpointer *) &touch); + return touch->touch_down_serial; + } + + for (l = wayland_seat->tablets; l; l = l->next) + { + GdkWaylandTabletData *tablet = l->data; + + if (tablet->logical_device == device) + return tablet->pointer_info.press_serial; } return GDK_WAYLAND_SEAT (seat)->pointer_info.press_serial; diff --git a/gdk/wayland/gdktoplevel-wayland.c b/gdk/wayland/gdktoplevel-wayland.c index abbd01ece8..c3a0749d55 100644 --- a/gdk/wayland/gdktoplevel-wayland.c +++ b/gdk/wayland/gdktoplevel-wayland.c @@ -1904,7 +1904,9 @@ gdk_wayland_toplevel_show_window_menu (GdkToplevel *toplevel, wl_seat = gdk_wayland_seat_get_wl_seat (seat); gdk_event_get_position (event, &x, &y); - serial = _gdk_wayland_seat_get_implicit_grab_serial (seat, event); + serial = _gdk_wayland_seat_get_implicit_grab_serial (seat, + gdk_event_get_device (event), + gdk_event_get_event_sequence (event)); switch (display_wayland->shell_variant) {