From a05af1f0f3fcd18ed7feac92f2ce5397d4cf8751 Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Mon, 14 May 2018 04:16:25 +0200 Subject: [PATCH] dnd: Move the gdk_drag_status() function It's now gdk_drop_status(). Also clarify the intended semantics. --- gdk/broadway/gdkdnd-broadway.c | 9 --------- gdk/gdkdnd.c | 4 +--- gdk/gdkdndprivate.h | 3 --- gdk/gdkdrop.c | 34 ++++++++++++++++++++++++++++++++++ gdk/gdkdrop.h | 4 ++++ gdk/gdkdropprivate.h | 2 ++ gdk/quartz/gdkdnd-quartz.c | 9 --------- gdk/wayland/gdkdnd-wayland.c | 9 ++++----- gdk/win32/gdkdrop-win32.c | 8 ++++---- gdk/x11/gdkdnd-x11.c | 21 +++++++++++---------- 10 files changed, 60 insertions(+), 43 deletions(-) diff --git a/gdk/broadway/gdkdnd-broadway.c b/gdk/broadway/gdkdnd-broadway.c index b5ad024e21..170b692451 100644 --- a/gdk/broadway/gdkdnd-broadway.c +++ b/gdk/broadway/gdkdnd-broadway.c @@ -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; diff --git a/gdk/gdkdnd.c b/gdk/gdkdnd.c index 2ddc075c54..ddc155f553 100644 --- a/gdk/gdkdnd.c +++ b/gdk/gdkdnd.c @@ -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); } /* diff --git a/gdk/gdkdndprivate.h b/gdk/gdkdndprivate.h index c8f396deaf..3e0055344e 100644 --- a/gdk/gdkdndprivate.h +++ b/gdk/gdkdndprivate.h @@ -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, diff --git a/gdk/gdkdrop.c b/gdk/gdkdrop.c index 0908a065c5..925357e2a7 100644 --- a/gdk/gdkdrop.c +++ b/gdk/gdkdrop.c @@ -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 diff --git a/gdk/gdkdrop.h b/gdk/gdkdrop.h index 5df8872b78..b044a28075 100644 --- a/gdk/gdkdrop.h +++ b/gdk/gdkdrop.h @@ -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, diff --git a/gdk/gdkdropprivate.h b/gdk/gdkdropprivate.h index b5759fb2b6..40a47ba53f 100644 --- a/gdk/gdkdropprivate.h +++ b/gdk/gdkdropprivate.h @@ -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, diff --git a/gdk/quartz/gdkdnd-quartz.c b/gdk/quartz/gdkdnd-quartz.c index b9b2656ba5..f78a88284e 100644 --- a/gdk/quartz/gdkdnd-quartz.c +++ b/gdk/quartz/gdkdnd-quartz.c @@ -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; diff --git a/gdk/wayland/gdkdnd-wayland.c b/gdk/wayland/gdkdnd-wayland.c index 815080746a..d03af430e8 100644 --- a/gdk/wayland/gdkdnd-wayland.c +++ b/gdk/wayland/gdkdnd-wayland.c @@ -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; diff --git a/gdk/win32/gdkdrop-win32.c b/gdk/win32/gdkdrop-win32.c index b8150e597b..bbf8a9b4af 100644 --- a/gdk/win32/gdkdrop-win32.c +++ b/gdk/win32/gdkdrop-win32.c @@ -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; } diff --git a/gdk/x11/gdkdnd-x11.c b/gdk/x11/gdkdnd-x11.c index 42761dc6e5..6c061d5064 100644 --- a/gdk/x11/gdkdnd-x11.c +++ b/gdk/x11/gdkdnd-x11.c @@ -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, -- 2.30.2