dnd: Move the gdk_drag_status() function
authorBenjamin Otte <otte@redhat.com>
Mon, 14 May 2018 02:16:25 +0000 (04:16 +0200)
committerBenjamin Otte <otte@redhat.com>
Mon, 18 Jun 2018 21:49:19 +0000 (23:49 +0200)
It's now gdk_drop_status().

Also clarify the intended semantics.

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 b5ad024e219c32192612204715efc6fe6e4dd263..170b692451a4632896a34686267ac319538bf13d 100644 (file)
@@ -120,14 +120,6 @@ gdk_broadway_drag_context_drag_abort (GdkDragContext *context,
 
 /* Destination side */
 
-static void
-gdk_broadway_drag_context_drag_status (GdkDragContext   *context,
-                                       GdkDragAction     action,
-                                       guint32           time)
-{
-  g_return_if_fail (context != NULL);
-}
-
 static void
 gdk_broadway_drag_context_drop_finish (GdkDragContext   *context,
                                        gboolean          success,
@@ -154,7 +146,6 @@ gdk_broadway_drag_context_class_init (GdkBroadwayDragContextClass *klass)
 
   object_class->finalize = gdk_broadway_drag_context_finalize;
 
-  context_class->drag_status = gdk_broadway_drag_context_drag_status;
   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 2ddc075c540fe85940e38680287a4ecce473ee45..ddc155f553f30580473bd8cf6ea9de2500807cdd 100644 (file)
@@ -533,9 +533,7 @@ gdk_drag_status (GdkDragContext *context,
                  GdkDragAction   action,
                  guint32         time_)
 {
-  g_return_if_fail (GDK_IS_DRAG_CONTEXT (context));
-
-  GDK_DRAG_CONTEXT_GET_CLASS (context)->drag_status (context, action, time_);
+  gdk_drop_status (GDK_DROP (context), action);
 }
 
 /*
index c8f396deaf76e6a06d04d8b5209720dc729aff34..3e0055344e35aff40dccdea578ba94583641e9c3 100644 (file)
@@ -35,9 +35,6 @@ typedef struct _GdkDragContextClass GdkDragContextClass;
 struct _GdkDragContextClass {
   GdkDropClass parent_class;
 
-  void        (*drag_status)   (GdkDragContext  *context,
-                                GdkDragAction    action,
-                                guint32          time_);
   void        (*drag_abort)    (GdkDragContext  *context,
                                 guint32          time_);
   void        (*drag_drop)     (GdkDragContext  *context,
index 0908a065c5489b872e41f48865bd5915843e7134..925357e2a7759d48cc3238f2970ec8ef7b8bb7bc 100644 (file)
@@ -58,6 +58,12 @@ G_DEFINE_TYPE_WITH_PRIVATE (GdkDrop, gdk_drop, G_TYPE_OBJECT)
  * should not be accessed directly.
  */
 
+static void
+gdk_drop_default_status (GdkDrop       *self,
+                         GdkDragAction  actions)
+{
+}
+
 static void
 gdk_drop_read_local_async (GdkDrop             *self,
                            GdkContentFormats   *formats,
@@ -174,6 +180,8 @@ gdk_drop_class_init (GdkDropClass *klass)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
+  klass->status = gdk_drop_default_status;
+
   object_class->get_property = gdk_drop_get_property;
   object_class->set_property = gdk_drop_set_property;
   object_class->finalize = gdk_drop_finalize;
@@ -343,6 +351,32 @@ gdk_drop_set_actions (GdkDrop       *self,
   g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_ACTIONS]);
 }
 
+/**
+ * gdk_drop_status:
+ * @self: a #GdkDrop
+ * @actions: Supported actions of the destination, or 0 to indicate
+ *    that a drop will not be accepted
+ *
+ * Selects all actions that are potentially supported by the destination.
+ *
+ * When calling this function, do not restrict the passed in actions to
+ * the ones provided by gdk_drop_get_actions(). Those actions may
+ * change in the future, even depending on the actions you provide here.
+ *
+ * This function should be called by drag destinations in response to
+ * %GDK_DRAG_ENTER or %GDK_DRAG_MOTION events. If the destination does
+ * not yet know the exact actions it supports, it should set any possible
+ * actions first and then later call this function again.
+ */
+void
+gdk_drop_status (GdkDrop       *self,
+                 GdkDragAction  actions)
+{
+  g_return_if_fail (GDK_IS_DROP (self));
+
+  GDK_DROP_GET_CLASS (self)->status (self, actions);
+}
+
 /**
  * gdk_drop_read_async:
  * @self: a #GdkDrop
index 5df8872b78e42369b2e12ab410e0f042974517a5..b044a280757d373cd91e9c9584a8f78d514f77de 100644 (file)
@@ -48,6 +48,10 @@ GdkContentFormats *     gdk_drop_get_formats            (GdkDrop
 GDK_AVAILABLE_IN_ALL
 GdkDragAction           gdk_drop_get_actions            (GdkDrop                *self);
 
+GDK_AVAILABLE_IN_ALL
+void                    gdk_drop_status                 (GdkDrop                *self,
+                                                         GdkDragAction           actions);
+
 GDK_AVAILABLE_IN_ALL
 void                    gdk_drop_read_async             (GdkDrop                *self,
                                                          const char            **mime_types,
index b5759fb2b6209fab61ccbd19e8c4df84f01e1144..40a47ba53ff7d83285ccc55d90887d4da92d1bc3 100644 (file)
@@ -39,6 +39,8 @@ struct _GdkDrop {
 struct _GdkDropClass {
   GObjectClass parent_class;
 
+  void                  (* status)                              (GdkDrop                *self,
+                                                                 GdkDragAction           action);
   void                  (* read_async)                          (GdkDrop                *self,
                                                                  GdkContentFormats      *formats,
                                                                  int                     io_priority,
index b9b2656ba53ed853584a514657fa0e831ae5d182..f78a88284e3d152fc2ded9295e453dee8466bdbb 100644 (file)
@@ -70,14 +70,6 @@ gdk_quartz_drag_context_drag_abort (GdkDragContext *context,
   /* FIXME: Implement */
 }
 
-static void
-gdk_quartz_drag_context_drag_status (GdkDragContext *context,
-                                     GdkDragAction   action,
-                                     guint32         time)
-{
-  context->action = action;
-}
-
 static void
 gdk_quartz_drag_context_drop_finish (GdkDragContext *context,
                                      gboolean        success,
@@ -117,7 +109,6 @@ gdk_quartz_drag_context_class_init (GdkQuartzDragContextClass *klass)
 
   object_class->finalize = gdk_quartz_drag_context_finalize;
 
-  context_class->drag_status = gdk_quartz_drag_context_drag_status;
   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 815080746acc9e80f9f84913863b40bdbe05c5de..d03af430e852c12f7b01d4cd72be9632620054d0 100644 (file)
@@ -215,13 +215,12 @@ gdk_wayland_drag_context_commit_status (GdkDragContext *context)
 }
 
 static void
-gdk_wayland_drag_context_drag_status (GdkDragContext *context,
-                                     GdkDragAction   action,
-                                     guint32         time_)
+gdk_wayland_drag_context_status (GdkDrop       *drop,
+                                GdkDragAction  action)
 {
   GdkWaylandDragContext *wayland_context;
 
-  wayland_context = GDK_WAYLAND_DRAG_CONTEXT (context);
+  wayland_context = GDK_WAYLAND_DRAG_CONTEXT (drop);
   wayland_context->selected_action = action;
 }
 
@@ -403,10 +402,10 @@ 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->read_async = gdk_wayland_drag_context_read_async;
   drop_class->read_finish = gdk_wayland_drag_context_read_finish;
 
-  context_class->drag_status = gdk_wayland_drag_context_drag_status;
   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;
index b8150e597bb7a5bde258d0f8ed8f37141630024a..bbf8a9b4af5ba20b4fb8409620eac367710c8731 100644 (file)
@@ -853,10 +853,10 @@ gdk_dropfiles_filter (GdkWin32Display *display,
 /* Destination side */
 
 static void
-gdk_win32_drop_context_drag_status (GdkDragContext *context,
-                 GdkDragAction   action,
-                 guint32         time)
+gdk_win32_drop_context_status (GdkDrop       *drop,
+                               GdkDragAction  action)
 {
+  GdkDragContext *context = GDK_DRAG_CONTEXT (drop);
   GdkDragContext *src_context;
 
   g_return_if_fail (context != NULL);
@@ -1204,10 +1204,10 @@ 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->read_async = gdk_win32_drop_context_read_async;
   drop_class->read_finish = gdk_win32_drop_context_read_finish;
 
-  context_class->drag_status = gdk_win32_drop_context_drag_status;
   context_class->drop_finish = gdk_win32_drop_context_drop_finish;
 }
 
index 42761dc6e5a0cb3dfe9cee1943f3e9384faa36ad..6c061d50647215ff7b4e1d6b927f0f1e5a0eb903 100644 (file)
@@ -233,9 +233,8 @@ static gboolean    gdk_x11_drag_context_drag_motion (GdkDragContext  *context,
                                                      GdkDragAction    suggested_action,
                                                      GdkDragAction    possible_actions,
                                                      guint32          time);
-static void        gdk_x11_drag_context_drag_status (GdkDragContext  *context,
-                                                     GdkDragAction    action,
-                                                     guint32          time_);
+static void        gdk_x11_drag_context_status      (GdkDrop         *drop,
+                                                     GdkDragAction    actions);
 static void        gdk_x11_drag_context_drag_abort  (GdkDragContext  *context,
                                                      guint32          time_);
 static void        gdk_x11_drag_context_drag_drop   (GdkDragContext  *context,
@@ -394,10 +393,10 @@ 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->read_async = gdk_x11_drag_context_read_async;
   drop_class->read_finish = gdk_x11_drag_context_read_finish;
 
-  context_class->drag_status = gdk_x11_drag_context_drag_status;
   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;
@@ -2408,30 +2407,32 @@ gdk_x11_drag_context_drag_drop (GdkDragContext *context,
 /* Destination side */
 
 static void
-gdk_x11_drag_context_drag_status (GdkDragContext *context,
-                                  GdkDragAction   action,
-                                  guint32         time_)
+gdk_x11_drag_context_status (GdkDrop       *drop,
+                             GdkDragAction  actions)
 {
+  GdkDragContext *context = GDK_DRAG_CONTEXT (drop);
   GdkX11DragContext *context_x11 = GDK_X11_DRAG_CONTEXT (context);
   XEvent xev;
   GdkDisplay *display;
 
   display = gdk_drag_context_get_display (context);
 
-  context->action = action;
+  context->action = actions;
 
   if (context_x11->protocol == GDK_DRAG_PROTO_XDND)
     {
+      GdkDragAction possible_actions = actions & gdk_drop_get_actions (drop);
+
       xev.xclient.type = ClientMessage;
       xev.xclient.message_type = gdk_x11_get_xatom_by_name_for_display (display, "XdndStatus");
       xev.xclient.format = 32;
       xev.xclient.window = GDK_SURFACE_XID (context->source_surface);
 
       xev.xclient.data.l[0] = GDK_SURFACE_XID (context->dest_surface);
-      xev.xclient.data.l[1] = (action != 0) ? (2 | 1) : 0;
+      xev.xclient.data.l[1] = (possible_actions != 0) ? (2 | 1) : 0;
       xev.xclient.data.l[2] = 0;
       xev.xclient.data.l[3] = 0;
-      xev.xclient.data.l[4] = xdnd_action_to_atom (display, action);
+      xev.xclient.data.l[4] = xdnd_action_to_atom (display, possible_actions);
       if (!xdnd_send_xevent (context_x11, context->source_surface, FALSE, &xev))
         {
           GDK_DISPLAY_NOTE (display, DND,