dnd: Add gdk_drop_finish()
authorBenjamin Otte <otte@redhat.com>
Tue, 15 May 2018 03:45:06 +0000 (05:45 +0200)
committerBenjamin Otte <otte@redhat.com>
Mon, 18 Jun 2018 21:49:20 +0000 (23:49 +0200)
and move the vfunc into GdkDrop.

gdk/broadway/gdkdnd-broadway.c
gdk/gdkdnd.c
gdk/gdkdndprivate.h
gdk/gdkdrop.c
gdk/gdkdrop.h
gdk/gdkdropprivate.h
gdk/quartz/gdkdnd-quartz.c
gdk/wayland/gdkdnd-wayland.c
gdk/win32/gdkdrop-win32.c
gdk/x11/gdkdnd-x11.c

index 170b692451a4632896a34686267ac319538bf13d..fecf3b9c047cb284201921adc5ca3fe5c7755f5c 100644 (file)
@@ -118,16 +118,6 @@ gdk_broadway_drag_context_drag_abort (GdkDragContext *context,
   g_return_if_fail (context != NULL);
 }
 
-/* Destination side */
-
-static void
-gdk_broadway_drag_context_drop_finish (GdkDragContext   *context,
-                                       gboolean          success,
-                                       guint32           time)
-{
-  g_return_if_fail (context != NULL);
-}
-
 void
 _gdk_broadway_surface_register_dnd (GdkSurface      *surface)
 {
@@ -148,5 +138,4 @@ gdk_broadway_drag_context_class_init (GdkBroadwayDragContextClass *klass)
 
   context_class->drag_abort = gdk_broadway_drag_context_drag_abort;
   context_class->drag_drop = gdk_broadway_drag_context_drag_drop;
-  context_class->drop_finish = gdk_broadway_drag_context_drop_finish;
 }
index 126d8ea356c4586034cb9ffec01cbf0fea241649..13267b7ffdfa3bff0f9397b19d02ba3d546a5dc7 100644 (file)
@@ -589,7 +589,10 @@ gdk_drag_finish (GdkDragContext *context,
 {
   g_return_if_fail (GDK_IS_DRAG_CONTEXT (context));
 
-  GDK_DRAG_CONTEXT_GET_CLASS (context)->drop_finish (context, success, time_);
+  if (success)
+    gdk_drop_finish (GDK_DROP (context), gdk_drag_context_get_selected_action (context));
+  else
+    gdk_drop_finish (GDK_DROP (context), 0);
 }
 
 static void
index 3e0055344e35aff40dccdea578ba94583641e9c3..5bead8248c2a5b8bc151ff4c2ec48e53d50c267c 100644 (file)
@@ -39,9 +39,6 @@ struct _GdkDragContextClass {
                                 guint32          time_);
   void        (*drag_drop)     (GdkDragContext  *context,
                                 guint32          time_);
-  void        (*drop_finish)   (GdkDragContext  *context,
-                                gboolean         success,
-                                guint32          time_);
   GdkSurface*  (*get_drag_surface) (GdkDragContext *context);
   void        (*set_hotspot)   (GdkDragContext  *context,
                                 gint             hot_x,
index 7fa7d029c7b9db7cd38096a6657a5cdb3fcbbb20..b9c21c07763b5ae772a8fac07b03152615771139 100644 (file)
@@ -377,6 +377,27 @@ gdk_drop_status (GdkDrop       *self,
   GDK_DROP_GET_CLASS (self)->status (self, actions);
 }
 
+/**
+ * gdk_drop_finish:
+ * @self: a #GdkDrop
+ * @action: the action performed by the destination or 0 if the drop
+ *     failed
+ *
+ * Ends the drag operation after a drop.
+ * 
+ * The @action must be a single action selected from the actions
+ * available via gdk_drop_get_actions().
+ **/
+void
+gdk_drop_finish (GdkDrop       *self,
+                 GdkDragAction  action)
+{
+  g_return_if_fail (GDK_IS_DROP (self));
+  g_return_if_fail (gdk_drag_action_is_unique (action));
+
+  GDK_DROP_GET_CLASS (self)->finish (self, action);
+}
+
 /**
  * gdk_drop_read_async:
  * @self: a #GdkDrop
index b044a280757d373cd91e9c9584a8f78d514f77de..762c6891bf7159a2427efdb76a3b21d542667ec8 100644 (file)
@@ -51,6 +51,9 @@ GdkDragAction           gdk_drop_get_actions            (GdkDrop
 GDK_AVAILABLE_IN_ALL
 void                    gdk_drop_status                 (GdkDrop                *self,
                                                          GdkDragAction           actions);
+GDK_AVAILABLE_IN_ALL
+void                    gdk_drop_finish                 (GdkDrop                *self,
+                                                         GdkDragAction           action);
 
 GDK_AVAILABLE_IN_ALL
 void                    gdk_drop_read_async             (GdkDrop                *self,
index 40a47ba53ff7d83285ccc55d90887d4da92d1bc3..029e68de33f0044ee5af5479236d89fd97d17bb6 100644 (file)
@@ -40,7 +40,10 @@ struct _GdkDropClass {
   GObjectClass parent_class;
 
   void                  (* status)                              (GdkDrop                *self,
+                                                                 GdkDragAction           actions);
+  void                  (* finish)                              (GdkDrop                *self,
                                                                  GdkDragAction           action);
+
   void                  (* read_async)                          (GdkDrop                *self,
                                                                  GdkContentFormats      *formats,
                                                                  int                     io_priority,
index f78a88284e3d152fc2ded9295e453dee8466bdbb..2b80e8e32ec627b571f388bc4123698475a73bc4 100644 (file)
@@ -70,14 +70,6 @@ gdk_quartz_drag_context_drag_abort (GdkDragContext *context,
   /* FIXME: Implement */
 }
 
-static void
-gdk_quartz_drag_context_drop_finish (GdkDragContext *context,
-                                     gboolean        success,
-                                     guint32         time)
-{
-  /* FIXME: Implement */
-}
-
 void
 _gdk_quartz_surface_register_dnd (GdkSurface *window)
 {
@@ -111,5 +103,4 @@ gdk_quartz_drag_context_class_init (GdkQuartzDragContextClass *klass)
 
   context_class->drag_abort = gdk_quartz_drag_context_drag_abort;
   context_class->drag_drop = gdk_quartz_drag_context_drag_drop;
-  context_class->drop_finish = gdk_quartz_drag_context_drop_finish;
 }
index d03af430e852c12f7b01d4cd72be9632620054d0..0cfebd6557b790d00311f518f50e36bde0399cff 100644 (file)
@@ -225,18 +225,16 @@ gdk_wayland_drag_context_status (GdkDrop       *drop,
 }
 
 static void
-gdk_wayland_drag_context_drop_finish (GdkDragContext *context,
-                                     gboolean        success,
-                                     guint32         time)
+gdk_wayland_drag_context_finish (GdkDrop       *drop,
+                                 GdkDragAction  action)
 {
-  GdkWaylandDragContext *wayland_context = GDK_WAYLAND_DRAG_CONTEXT (context);
-  GdkDisplay *display = gdk_device_get_display (gdk_drag_context_get_device (context));
+  GdkWaylandDragContext *wayland_context = GDK_WAYLAND_DRAG_CONTEXT (drop);
+  GdkDisplay *display = gdk_drop_get_display (drop);
   GdkWaylandDisplay *display_wayland = GDK_WAYLAND_DISPLAY (display);
 
-  if (success && wayland_context->selected_action &&
-      wayland_context->selected_action != GDK_ACTION_ASK)
+  if (action)
     {
-      gdk_wayland_drag_context_commit_status (context);
+      gdk_wayland_drag_context_commit_status (GDK_DRAG_CONTEXT (drop));
 
       if (display_wayland->data_device_manager_version >=
           WL_DATA_OFFER_FINISH_SINCE_VERSION)
@@ -403,13 +401,12 @@ gdk_wayland_drag_context_class_init (GdkWaylandDragContextClass *klass)
   object_class->finalize = gdk_wayland_drag_context_finalize;
 
   drop_class->status = gdk_wayland_drag_context_status;
+  drop_class->finish = gdk_wayland_drag_context_finish;
   drop_class->read_async = gdk_wayland_drag_context_read_async;
   drop_class->read_finish = gdk_wayland_drag_context_read_finish;
 
   context_class->drag_abort = gdk_wayland_drag_context_drag_abort;
   context_class->drag_drop = gdk_wayland_drag_context_drag_drop;
-  context_class->drop_finish = gdk_wayland_drag_context_drop_finish;
-  context_class->drop_finish = gdk_wayland_drag_context_drop_finish;
   context_class->get_drag_surface = gdk_wayland_drag_context_get_drag_surface;
   context_class->set_hotspot = gdk_wayland_drag_context_set_hotspot;
   context_class->drop_done = gdk_wayland_drag_context_drop_done;
index d0b088b000281f7fdf39909d71b5a29c6eefe38a..e385a37ffa1cd6b409ac55262342758c17c90028 100644 (file)
@@ -895,10 +895,10 @@ _gdk_display_put_event (GdkDisplay *display,
 }
 
 static void
-gdk_win32_drop_context_drop_finish (GdkDragContext *context,
-                 gboolean        success,
-                 guint32         time)
+gdk_win32_drop_context_finish (GdkDrop       *drop,
+                               GdkDragAction  action)
 {
+  GdkDragContext *context = GDK_DRAG_CONTEXT (drop);
   GdkDragContext *src_context;
   GdkWin32Clipdrop *clipdrop = _gdk_win32_clipdrop_get ();
 
@@ -906,6 +906,9 @@ gdk_win32_drop_context_drop_finish (GdkDragContext *context,
 
   GDK_NOTE (DND, g_print ("gdk_drag_finish\n"));
 
+  if (context->action != action)
+    gdk_win32_drop_context_status (context, action);
+
   if (!use_ole2_dnd)
     {
       src_context = _gdk_win32_drag_context_find (context->source_surface,
@@ -921,9 +924,9 @@ gdk_win32_drop_context_drop_finish (GdkDragContext *context,
     }
   else
     {
-      _gdk_win32_drag_do_leave (context, time);
+      _gdk_win32_drag_do_leave (context, GDK_CURRENT_TIME);
 
-      if (success)
+      if (action)
         clipdrop->dnd_target_state = GDK_WIN32_DND_DROPPED;
       else
         clipdrop->dnd_target_state = GDK_WIN32_DND_FAILED;
@@ -1205,10 +1208,9 @@ gdk_win32_drop_context_class_init (GdkWin32DropContextClass *klass)
   object_class->finalize = gdk_win32_drop_context_finalize;
 
   drop_class->status = gdk_win32_drop_context_status;
+  drop_class->finish = gdk_win32_drop_context_finish;
   drop_class->read_async = gdk_win32_drop_context_read_async;
   drop_class->read_finish = gdk_win32_drop_context_read_finish;
-
-  context_class->drop_finish = gdk_win32_drop_context_drop_finish;
 }
 
 void
index 6c061d50647215ff7b4e1d6b927f0f1e5a0eb903..936c218e50ee86317d3125c90a8f2fa7cd16455e 100644 (file)
@@ -239,9 +239,8 @@ static void        gdk_x11_drag_context_drag_abort  (GdkDragContext  *context,
                                                      guint32          time_);
 static void        gdk_x11_drag_context_drag_drop   (GdkDragContext  *context,
                                                      guint32          time_);
-static void        gdk_x11_drag_context_drop_finish (GdkDragContext  *context,
-                                                     gboolean         success,
-                                                     guint32          time_);
+static void        gdk_x11_drag_context_finish      (GdkDrop         *drop,
+                                                     GdkDragAction    action);
 static GdkSurface * gdk_x11_drag_context_get_drag_surface (GdkDragContext *context);
 static void        gdk_x11_drag_context_set_hotspot (GdkDragContext  *context,
                                                      gint             hot_x,
@@ -394,12 +393,12 @@ gdk_x11_drag_context_class_init (GdkX11DragContextClass *klass)
   object_class->finalize = gdk_x11_drag_context_finalize;
 
   drop_class->status = gdk_x11_drag_context_status;
+  drop_class->finish = gdk_x11_drag_context_finish;
   drop_class->read_async = gdk_x11_drag_context_read_async;
   drop_class->read_finish = gdk_x11_drag_context_read_finish;
 
   context_class->drag_abort = gdk_x11_drag_context_drag_abort;
   context_class->drag_drop = gdk_x11_drag_context_drag_drop;
-  context_class->drop_finish = gdk_x11_drag_context_drop_finish;
   context_class->get_drag_surface = gdk_x11_drag_context_get_drag_surface;
   context_class->set_hotspot = gdk_x11_drag_context_set_hotspot;
   context_class->drop_done = gdk_x11_drag_context_drop_done;
@@ -2443,23 +2442,23 @@ gdk_x11_drag_context_status (GdkDrop       *drop,
 }
 
 static void
-gdk_x11_drag_context_drop_finish (GdkDragContext *context,
-                                  gboolean        success,
-                                  guint32         time)
+gdk_x11_drag_context_finish (GdkDrop       *drop,
+                             GdkDragAction  action)
 {
-  if (GDK_X11_DRAG_CONTEXT (context)->protocol == GDK_DRAG_PROTO_XDND)
+  if (GDK_X11_DRAG_CONTEXT (drop)->protocol == GDK_DRAG_PROTO_XDND)
     {
-      GdkDisplay *display = gdk_drag_context_get_display (context);
+      GdkDragContext *context = GDK_DRAG_CONTEXT (drop);
+      GdkDisplay *display = gdk_drop_get_display (drop);
       XEvent xev;
 
-      if (success && gdk_drag_context_get_selected_action (context) == GDK_ACTION_MOVE)
+      if (action == GDK_ACTION_MOVE)
         {
           XConvertSelection (GDK_DISPLAY_XDISPLAY (display),
                              gdk_x11_get_xatom_by_name_for_display (display, "XdndSelection"),
                              gdk_x11_get_xatom_by_name_for_display (display, "DELETE"),
                              gdk_x11_get_xatom_by_name_for_display (display, "GDK_SELECTION"),
                              GDK_SURFACE_XID (context->source_surface),
-                             time);
+                             GDK_X11_DRAG_CONTEXT (drop)->timestamp);
           /* XXX: Do we need to wait for a reply here before sending the next message? */
         }
 
@@ -2469,11 +2468,10 @@ gdk_x11_drag_context_drop_finish (GdkDragContext *context,
       xev.xclient.window = GDK_SURFACE_XID (context->source_surface);
 
       xev.xclient.data.l[0] = GDK_SURFACE_XID (context->dest_surface);
-      if (success)
+      if (action != 0)
         {
           xev.xclient.data.l[1] = 1;
-          xev.xclient.data.l[2] = xdnd_action_to_atom (display,
-                                                       context->action);
+          xev.xclient.data.l[2] = xdnd_action_to_atom (display, action);
         }
       else
         {