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).
This commit is contained in:
Carlos Garnacho
2023-11-24 23:30:36 +01:00
parent 822425072b
commit 0c19ef6c2c
4 changed files with 34 additions and 27 deletions

View File

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

View File

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

View File

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

View File

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