From 66bd54d14cd5d4dc770bc620741b1cbfc513abc1 Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Thu, 31 May 2018 21:15:59 +0200 Subject: [PATCH] wayland: Store the current drag operation Use it to detect local drags when creating drop objects. --- gdk/wayland/gdkdevice-wayland.c | 13 ++++++++++++- gdk/wayland/gdkdnd-wayland.c | 9 ++++++++- gdk/wayland/gdkdrop-wayland.c | 2 ++ gdk/wayland/gdkprivate-wayland.h | 3 +++ 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/gdk/wayland/gdkdevice-wayland.c b/gdk/wayland/gdkdevice-wayland.c index cbcf86bdda..585887dc07 100644 --- a/gdk/wayland/gdkdevice-wayland.c +++ b/gdk/wayland/gdkdevice-wayland.c @@ -246,6 +246,7 @@ struct _GdkWaylandSeat GdkClipboard *clipboard; GdkClipboard *primary_clipboard; struct wl_data_device *data_device; + GdkDragContext *drag; GdkDrop *drop; /* Source/dest for non-local dnd */ @@ -1263,7 +1264,7 @@ data_device_enter (void *data, seat->pending_builder = NULL; seat->pending_offer = NULL; - seat->drop = gdk_wayland_drop_new (device, formats, dest_surface, offer, serial); + seat->drop = gdk_wayland_drop_new (device, seat->drag, formats, dest_surface, offer, serial); gdk_wayland_seat_discard_pending_offer (seat); @@ -4597,6 +4598,7 @@ gdk_wayland_seat_finalize (GObject *object) gdk_wayland_pointer_data_finalize (&seat->pointer_info); /* FIXME: destroy data_device */ g_clear_object (&seat->keyboard_settings); + g_clear_object (&seat->drag); g_clear_object (&seat->drop); g_clear_object (&seat->clipboard); g_clear_object (&seat->primary_clipboard); @@ -5137,6 +5139,15 @@ gdk_wayland_seat_set_global_cursor (GdkSeat *seat, NULL); } +void +gdk_wayland_seat_set_drag (GdkSeat *seat, + GdkDragContext *context) +{ + GdkWaylandSeat *wayland_seat = GDK_WAYLAND_SEAT (seat); + + g_set_object (&wayland_seat->drag, context); +} + struct wl_data_device * gdk_wayland_device_get_data_device (GdkDevice *gdk_device) { diff --git a/gdk/wayland/gdkdnd-wayland.c b/gdk/wayland/gdkdnd-wayland.c index 3ff57f451d..98c1b7a0c9 100644 --- a/gdk/wayland/gdkdnd-wayland.c +++ b/gdk/wayland/gdkdnd-wayland.c @@ -193,6 +193,9 @@ gdk_wayland_drag_context_drop_done (GdkDragContext *context, gboolean success) { GdkWaylandDragContext *context_wayland = GDK_WAYLAND_DRAG_CONTEXT (context); + GdkDevice *device = gdk_drag_context_get_device (context); + + gdk_wayland_seat_set_drag (gdk_device_get_seat (device), context); if (success) { @@ -387,9 +390,11 @@ _gdk_wayland_surface_drag_begin (GdkSurface *surface, { GdkWaylandDragContext *context_wayland; GdkDragContext *context; + GdkSeat *seat; GdkWaylandDisplay *display_wayland; display_wayland = GDK_WAYLAND_DISPLAY (gdk_device_get_display (device)); + seat = gdk_device_get_seat (device); context_wayland = g_object_new (GDK_TYPE_WAYLAND_DRAG_CONTEXT, "device", device, @@ -411,13 +416,15 @@ _gdk_wayland_surface_drag_begin (GdkSurface *surface, gdk_to_wl_actions (actions)); } + gdk_wayland_seat_set_drag (seat, context); + wl_data_device_start_drag (gdk_wayland_device_get_data_device (device), context_wayland->data_source, gdk_wayland_surface_get_wl_surface (surface), context_wayland->dnd_wl_surface, _gdk_wayland_display_get_serial (display_wayland)); - gdk_seat_ungrab (gdk_device_get_seat (device)); + gdk_seat_ungrab (seat); return context; } diff --git a/gdk/wayland/gdkdrop-wayland.c b/gdk/wayland/gdkdrop-wayland.c index a73fa8be00..09d6de5b48 100644 --- a/gdk/wayland/gdkdrop-wayland.c +++ b/gdk/wayland/gdkdrop-wayland.c @@ -261,6 +261,7 @@ gdk_wayland_drop_init (GdkWaylandDrop *drop) GdkDrop * gdk_wayland_drop_new (GdkDevice *device, + GdkDragContext *drag, GdkContentFormats *formats, GdkSurface *surface, struct wl_data_offer *offer, @@ -271,6 +272,7 @@ gdk_wayland_drop_new (GdkDevice *device, drop = g_object_new (GDK_TYPE_WAYLAND_DROP, "device", device, + "drag", drag, "formats", formats, "surface", surface, NULL); diff --git a/gdk/wayland/gdkprivate-wayland.h b/gdk/wayland/gdkprivate-wayland.h index 14dc4d4e5c..c45d17fc33 100644 --- a/gdk/wayland/gdkprivate-wayland.h +++ b/gdk/wayland/gdkprivate-wayland.h @@ -105,6 +105,7 @@ void _gdk_wayland_surface_offset_next_wl_buffer (GdkSurface *surface, int x, int y); GdkDrop * gdk_wayland_drop_new (GdkDevice *device, + GdkDragContext *drag, GdkContentFormats *formats, GdkSurface *surface, struct wl_data_offer *offer, @@ -192,6 +193,8 @@ struct gtk_surface1 * gdk_wayland_surface_get_gtk_surface (GdkSurface *surface); void gdk_wayland_seat_set_global_cursor (GdkSeat *seat, GdkCursor *cursor); +void gdk_wayland_seat_set_drag (GdkSeat *seat, + GdkDragContext *drag); struct wl_output *gdk_wayland_surface_get_wl_output (GdkSurface *surface); -- 2.30.2