drop: Add GdkDrop:surface property
authorBenjamin Otte <otte@redhat.com>
Wed, 23 May 2018 16:30:14 +0000 (18:30 +0200)
committerBenjamin Otte <otte@redhat.com>
Mon, 18 Jun 2018 21:49:52 +0000 (23:49 +0200)
This replaces gdk_drag_context_get_dest_surface().

gdk/gdkdrop.c
gdk/gdkdrop.h
gdk/wayland/gdkdevice-wayland.c
gdk/wayland/gdkdnd-wayland.c
gdk/wayland/gdkprivate-wayland.h
gdk/win32/gdkdrop-win32.c
gdk/x11/gdkdnd-x11.c

index 46ff8bc19600125e02268ae4560500328324f050..ad3da7a5f370148b8fdc35ad1582b5667ada0b44 100644 (file)
@@ -36,6 +36,7 @@ struct _GdkDropPrivate {
   GdkDevice *device;
   GdkDragContext *drag;
   GdkContentFormats *formats;
+  GdkSurface *surface;
   GdkDragAction actions;
 };
 
@@ -46,6 +47,7 @@ enum {
   PROP_DISPLAY,
   PROP_DRAG,
   PROP_FORMATS,
+  PROP_SURFACE,
   N_PROPERTIES
 };
 
@@ -118,6 +120,8 @@ gdk_drop_set_property (GObject      *gobject,
     case PROP_DEVICE:
       priv->device = g_value_dup_object (value);
       g_assert (priv->device != NULL);
+      if (priv->surface)
+        g_assert (gdk_surface_get_display (priv->surface) == gdk_device_get_display (priv->device));
       break;
 
     case PROP_DRAG:
@@ -131,6 +135,15 @@ gdk_drop_set_property (GObject      *gobject,
 #endif
       break;
 
+    case PROP_SURFACE:
+      priv->surface = g_value_dup_object (value);
+#ifdef DROP_SUBCLASS
+      g_assert (priv->surface != NULL);
+      if (priv->device)
+        g_assert (gdk_surface_get_display (priv->surface) == gdk_device_get_display (priv->device));
+#endif
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
       break;
@@ -168,6 +181,10 @@ gdk_drop_get_property (GObject    *gobject,
       g_value_set_boxed (value, priv->formats);
       break;
 
+    case PROP_SURFACE:
+      g_value_set_object (value, priv->surface);
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
       break;
@@ -271,6 +288,22 @@ gdk_drop_class_init (GdkDropClass *klass)
                         G_PARAM_CONSTRUCT_ONLY |
                         G_PARAM_STATIC_STRINGS |
                         G_PARAM_EXPLICIT_NOTIFY);
+
+  /**
+   * GdkDrop:surface:
+   *
+   * The #GdkSurface the drop happens on
+   */
+  properties[PROP_SURFACE] =
+    g_param_spec_object ("surface",
+                         "Surface",
+                         "The surface the drop is happening on",
+                         GDK_TYPE_SURFACE,
+                         G_PARAM_READWRITE |
+                         G_PARAM_CONSTRUCT_ONLY |
+                         G_PARAM_STATIC_STRINGS |
+                         G_PARAM_EXPLICIT_NOTIFY);
+
   g_object_class_install_properties (object_class, N_PROPERTIES, properties);
 }
 
@@ -334,6 +367,24 @@ gdk_drop_get_formats (GdkDrop *self)
   return priv->formats;
 }
 
+/**
+ * gdk_drop_get_surface:
+ * @self: a #GdkDrop
+ *
+ * Returns the #GdkSurface performing the drop.
+ *
+ * Returns: (transfer none): The #GdkSurface performing the drop.
+ **/
+GdkSurface *
+gdk_drop_get_surface (GdkDrop *self)
+{
+  GdkDropPrivate *priv = gdk_drop_get_instance_private (self);
+
+  g_return_val_if_fail (GDK_IS_DROP (self), NULL);
+
+  return priv->surface;
+}
+
 /**
  * gdk_drop_get_actions:
  * @self: a #GdkDrop
index 6ae088932e72dbd28e52514d23517cc6844f8de0..b25323cb77b2d619255ea18f3e0ca1a394686308 100644 (file)
@@ -44,6 +44,8 @@ GdkDisplay *            gdk_drop_get_display            (GdkDrop
 GDK_AVAILABLE_IN_ALL
 GdkDevice *             gdk_drop_get_device             (GdkDrop                *self);
 GDK_AVAILABLE_IN_ALL
+GdkSurface *            gdk_drop_get_surface            (GdkDrop                *self);
+GDK_AVAILABLE_IN_ALL
 GdkContentFormats *     gdk_drop_get_formats            (GdkDrop                *self);
 GDK_AVAILABLE_IN_ALL
 GdkDragAction           gdk_drop_get_actions            (GdkDrop                *self);
index f2c623347b9086c2ea2382420b929fe21c7ea0f0..08a936e73984b5bd5b7ed994e44d963423c7328d 100644 (file)
@@ -1269,14 +1269,12 @@ data_device_enter (void                  *data,
   seat->pending_builder = NULL;
   seat->pending_offer = NULL;
 
-  seat->drop_context = _gdk_wayland_drop_context_new (device, formats, offer);
+  seat->drop_context = _gdk_wayland_drop_context_new (device, formats, dest_surface, offer, serial);
 
   dnd_owner = seat->foreign_dnd_surface;
 
   _gdk_wayland_drag_context_set_source_surface (seat->drop_context, dnd_owner);
 
-  _gdk_wayland_drag_context_set_dest_surface (seat->drop_context,
-                                             dest_surface, serial);
   _gdk_wayland_drag_context_set_coords (seat->drop_context,
                                         wl_fixed_to_double (x),
                                         wl_fixed_to_double (y));
@@ -1305,7 +1303,6 @@ data_device_leave (void                  *data,
   _gdk_wayland_drag_context_set_coords (seat->drop_context, -1, -1);
   _gdk_wayland_drag_context_emit_event (seat->drop_context, GDK_DRAG_LEAVE,
                                         GDK_CURRENT_TIME);
-  _gdk_wayland_drag_context_set_dest_surface (seat->drop_context, NULL, 0);
 
   g_clear_object (&seat->drop_context);
 }
index ea3159f64a315da09e43e56fd694a8030af0334f..52ad3e3142dfaf6c0d02dbd27d88559c89980b13 100644 (file)
@@ -117,7 +117,7 @@ _gdk_wayland_drag_context_emit_event (GdkDragContext *context,
   if (context->is_source)
     surface = gdk_drag_context_get_source_surface (context);
   else
-    surface = gdk_drag_context_get_dest_surface (context);
+    surface = gdk_drop_get_surface (GDK_DROP (context));
 
   event = gdk_event_new (type);
   event->any.surface = g_object_ref (surface);
@@ -494,7 +494,10 @@ _gdk_wayland_surface_drag_begin (GdkSurface          *surface,
 GdkDragContext *
 _gdk_wayland_drop_context_new (GdkDevice            *device,
                                GdkContentFormats    *formats,
-                               struct wl_data_offer *offer)
+                               GdkSurface           *surface,
+                               struct wl_data_offer *offer,
+                               uint32_t              serial)
+
 {
   GdkWaylandDragContext *context_wayland;
   GdkDragContext *context;
@@ -502,10 +505,12 @@ _gdk_wayland_drop_context_new (GdkDevice            *device,
   context_wayland = g_object_new (GDK_TYPE_WAYLAND_DRAG_CONTEXT,
                                   "device", device,
                                   "formats", formats,
+                                  "surface", surface,
                                   NULL);
   context = GDK_DRAG_CONTEXT (context_wayland);
   context->is_source = FALSE;
   context_wayland->offer = offer;
+  context_wayland->serial = serial;
 
   return context;
 }
@@ -532,18 +537,6 @@ _gdk_wayland_drag_context_set_source_surface (GdkDragContext *context,
   context->source_surface = surface ? g_object_ref (surface) : NULL;
 }
 
-void
-_gdk_wayland_drag_context_set_dest_surface (GdkDragContext *context,
-                                           GdkSurface      *dest_surface,
-                                           uint32_t        serial)
-{
-  if (context->dest_surface)
-    g_object_unref (context->dest_surface);
-
-  context->dest_surface = dest_surface ? g_object_ref (dest_surface) : NULL;
-  GDK_WAYLAND_DRAG_CONTEXT (context)->serial = serial;
-}
-
 GdkDragContext *
 gdk_wayland_drag_context_lookup_by_data_source (struct wl_data_source *source)
 {
index e9e547a8fffe8ba5282399e724d1b6d2e2b771e5..dfeca6dce4e702b924d1bc8a564a5edca1756f49 100644 (file)
@@ -106,12 +106,11 @@ void            _gdk_wayland_surface_offset_next_wl_buffer (GdkSurface *surface,
                                                             int        y);
 GdkDragContext * _gdk_wayland_drop_context_new (GdkDevice             *device,
                                                 GdkContentFormats     *formats,
-                                                struct wl_data_offer  *offer);
+                                                GdkSurface            *surface,
+                                                struct wl_data_offer  *offer,
+                                                uint32_t               serial);
 void _gdk_wayland_drag_context_set_source_surface (GdkDragContext *context,
                                                   GdkSurface      *surface);
-void _gdk_wayland_drag_context_set_dest_surface (GdkDragContext *context,
-                                                 GdkSurface      *dest_surface,
-                                                 uint32_t        serial);
 void _gdk_wayland_drag_context_emit_event (GdkDragContext *context,
                                            GdkEventType    type,
                                            guint32         time_);
index e385a37ffa1cd6b409ac55262342758c17c90028..391ddae94cd6965022f18d8a177dc41b74923025 100644 (file)
@@ -144,6 +144,7 @@ gdk_drop_context_new (GdkDisplay        *display,
   context_win32 = g_object_new (GDK_TYPE_WIN32_DROP_CONTEXT,
                                 "device", gdk_seat_get_pointer (gdk_display_get_default_seat (display)),
                                 "formats", formats,
+                                "surface", dest_surface,
                                 NULL);
 
   context = GDK_DRAG_CONTEXT (context_win32);
index 936c218e50ee86317d3125c90a8f2fa7cd16455e..601de5cc6a15fccbd3d561d0fbcb0be9e939e842 100644 (file)
@@ -1815,6 +1815,7 @@ xdnd_enter_filter (const XEvent *xevent,
   context_x11 = g_object_new (GDK_TYPE_X11_DRAG_CONTEXT,
                               "device", gdk_seat_get_pointer (seat),
                               "formats", content_formats,
+                              "surface", event->any.surface,
                               NULL);
   context = (GdkDragContext *)context_x11;