summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Otte <otte@redhat.com>2018-05-13 17:03:57 +0200
committerBenjamin Otte <otte@redhat.com>2018-06-18 23:49:19 +0200
commit2e27967814276fb94d2c4d1982bc504a26282188 (patch)
treecd7d4cab45ac51fa5e0871d7a168cd1ac8ceaebf
parent18c3b725b4b2e477ca4d6d8380203ef9ba04b8d6 (diff)
downloadgtk+-2e27967814276fb94d2c4d1982bc504a26282188.tar.gz
dnd: Make actions a private member variable
Use a setter in the backends.
-rw-r--r--gdk/gdkdnd.c22
-rw-r--r--gdk/gdkdndprivate.h6
-rw-r--r--gdk/quartz/GdkQuartzNSWindow.c6
-rw-r--r--gdk/wayland/gdkdevice-wayland.c8
-rw-r--r--gdk/wayland/gdkdnd-wayland.c9
-rw-r--r--gdk/wayland/gdkprivate-wayland.h3
-rw-r--r--gdk/win32/gdkdrag-win32.c26
-rw-r--r--gdk/win32/gdkdrop-win32.c25
-rw-r--r--gdk/x11/gdkdnd-x11.c46
9 files changed, 85 insertions, 66 deletions
diff --git a/gdk/gdkdnd.c b/gdk/gdkdnd.c
index 98801fcde3..4f2b5830dd 100644
--- a/gdk/gdkdnd.c
+++ b/gdk/gdkdnd.c
@@ -46,6 +46,8 @@ struct _GdkDragContextPrivate
GdkDevice *device;
#endif
GdkContentFormats *formats;
+ GdkDragAction actions;
+ GdkDragAction suggested_action;
};
static struct {
@@ -166,9 +168,11 @@ gdk_drag_context_get_formats (GdkDragContext *context)
GdkDragAction
gdk_drag_context_get_actions (GdkDragContext *context)
{
+ GdkDragContextPrivate *priv = gdk_drag_context_get_instance_private (context);
+
g_return_val_if_fail (GDK_IS_DRAG_CONTEXT (context), 0);
- return context->actions;
+ return priv->actions;
}
/**
@@ -182,9 +186,11 @@ gdk_drag_context_get_actions (GdkDragContext *context)
GdkDragAction
gdk_drag_context_get_suggested_action (GdkDragContext *context)
{
+ GdkDragContextPrivate *priv = gdk_drag_context_get_instance_private (context);
+
g_return_val_if_fail (GDK_IS_DRAG_CONTEXT (context), 0);
- return context->suggested_action;
+ return priv->suggested_action;
}
/**
@@ -707,6 +713,17 @@ gdk_drag_context_write_finish (GdkDragContext *context,
return g_task_propagate_boolean (G_TASK (result), error);
}
+void
+gdk_drag_context_set_actions (GdkDragContext *context,
+ GdkDragAction actions,
+ GdkDragAction suggested_action)
+{
+ GdkDragContextPrivate *priv = gdk_drag_context_get_instance_private (context);
+
+ priv->actions = actions;
+ priv->suggested_action = suggested_action;
+}
+
/**
* gdk_drag_context_get_drag_surface:
* @context: a #GdkDragContext
@@ -894,4 +911,3 @@ gdk_drag_action_is_unique (GdkDragAction action)
{
return (action & (action - 1)) == 0;
}
-
diff --git a/gdk/gdkdndprivate.h b/gdk/gdkdndprivate.h
index 4018632d3c..c8f396deaf 100644
--- a/gdk/gdkdndprivate.h
+++ b/gdk/gdkdndprivate.h
@@ -78,8 +78,6 @@ struct _GdkDragContext {
GdkSurface *drag_surface;
GdkContentProvider *content;
- GdkDragAction actions;
- GdkDragAction suggested_action;
GdkDragAction action;
guint drop_done : 1; /* Whether gdk_drag_drop_done() was performed */
@@ -87,6 +85,10 @@ struct _GdkDragContext {
void gdk_drag_context_set_cursor (GdkDragContext *context,
GdkCursor *cursor);
+void gdk_drag_context_set_actions (GdkDragContext *context,
+ GdkDragAction actions,
+ GdkDragAction suggested_action);
+
void gdk_drag_context_cancel (GdkDragContext *context,
GdkDragCancelReason reason);
gboolean gdk_drag_context_handle_source_event (GdkEvent *event);
diff --git a/gdk/quartz/GdkQuartzNSWindow.c b/gdk/quartz/GdkQuartzNSWindow.c
index edf2095b6d..503fbf690c 100644
--- a/gdk/quartz/GdkQuartzNSWindow.c
+++ b/gdk/quartz/GdkQuartzNSWindow.c
@@ -559,11 +559,13 @@ drag_action_to_drag_operation (GdkDragAction action)
static void
update_context_from_dragging_info (id <NSDraggingInfo> sender)
{
+ GdkDragAction action;
+
g_assert (current_context != NULL);
GDK_QUARTZ_DRAG_CONTEXT (current_context)->dragging_info = sender;
- current_context->suggested_action = drag_operation_to_drag_action ([sender draggingSourceOperationMask]);
- current_context->actions = current_context->suggested_action;
+ action = drag_operation_to_drag_action ([sender draggingSourceOperationMask]);
+ gdk_drag_context_set_actions (current_context, action, action);
}
- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
diff --git a/gdk/wayland/gdkdevice-wayland.c b/gdk/wayland/gdkdevice-wayland.c
index 0cc50c77fa..f2c623347b 100644
--- a/gdk/wayland/gdkdevice-wayland.c
+++ b/gdk/wayland/gdkdevice-wayland.c
@@ -1154,7 +1154,9 @@ data_offer_source_actions (void *data,
if (drop_context == NULL)
return;
- drop_context->actions = gdk_wayland_actions_to_gdk_actions (source_actions);
+ gdk_drag_context_set_actions (drop_context,
+ gdk_wayland_actions_to_gdk_actions (source_actions),
+ gdk_drag_context_get_suggested_action (drop_context));
_gdk_wayland_drag_context_emit_event (drop_context, GDK_DRAG_MOTION,
GDK_CURRENT_TIME);
@@ -1180,7 +1182,9 @@ data_offer_action (void *data,
if (drop_context == NULL)
return;
- drop_context->suggested_action = gdk_wayland_actions_to_gdk_actions (action);
+ gdk_drag_context_set_actions (drop_context,
+ gdk_drag_context_get_actions (drop_context),
+ gdk_wayland_actions_to_gdk_actions (action));
_gdk_wayland_drag_context_emit_event (drop_context, GDK_DRAG_MOTION,
GDK_CURRENT_TIME);
diff --git a/gdk/wayland/gdkdnd-wayland.c b/gdk/wayland/gdkdnd-wayland.c
index 98e85d6a38..815080746a 100644
--- a/gdk/wayland/gdkdnd-wayland.c
+++ b/gdk/wayland/gdkdnd-wayland.c
@@ -146,13 +146,6 @@ gdk_to_wl_actions (GdkDragAction action)
return dnd_actions;
}
-void
-gdk_wayland_drag_context_set_action (GdkDragContext *context,
- GdkDragAction action)
-{
- context->suggested_action = context->action = action;
-}
-
static void
gdk_wayland_drag_context_drag_abort (GdkDragContext *context,
guint32 time)
@@ -326,8 +319,6 @@ gdk_wayland_drag_context_init (GdkWaylandDragContext *context_wayland)
contexts = g_list_prepend (contexts, context);
context->action = GDK_ACTION_COPY;
- context->suggested_action = GDK_ACTION_COPY;
- context->actions = GDK_ACTION_COPY | GDK_ACTION_MOVE;
}
static GdkSurface *
diff --git a/gdk/wayland/gdkprivate-wayland.h b/gdk/wayland/gdkprivate-wayland.h
index 0795a0fe35..e9e547a8ff 100644
--- a/gdk/wayland/gdkprivate-wayland.h
+++ b/gdk/wayland/gdkprivate-wayland.h
@@ -119,9 +119,6 @@ void _gdk_wayland_drag_context_set_coords (GdkDragContext *context,
gdouble x,
gdouble y);
-void gdk_wayland_drag_context_set_action (GdkDragContext *context,
- GdkDragAction action);
-
GdkDragContext * gdk_wayland_drag_context_lookup_by_data_source (struct wl_data_source *source);
GdkDragContext * gdk_wayland_drag_context_lookup_by_source_surface (GdkSurface *surface);
struct wl_data_source * gdk_wayland_drag_context_get_data_source (GdkDragContext *context);
diff --git a/gdk/win32/gdkdrag-win32.c b/gdk/win32/gdkdrag-win32.c
index 069e3c1e4f..b1f5c29649 100644
--- a/gdk/win32/gdkdrag-win32.c
+++ b/gdk/win32/gdkdrag-win32.c
@@ -825,7 +825,7 @@ gdk_drag_context_new (GdkDisplay *display,
context->is_source = TRUE;
g_set_object (&context->source_surface, source_surface);
- context->actions = actions;
+ gdk_drag_context_set_actions (context, actions, actions);
context_win32->protocol = protocol;
gdk_content_formats_unref (formats);
@@ -1806,7 +1806,7 @@ local_send_motion (GdkDragContext *context,
tmp_event->dnd.time = time;
gdk_event_set_device (tmp_event, gdk_drag_context_get_device (current_dest_drag));
- current_dest_drag->suggested_action = action;
+ gdk_drag_context_set_actions (current_dest_drag, action, action);
tmp_event->dnd.x_root = x_root;
tmp_event->dnd.y_root = y_root;
@@ -2092,8 +2092,6 @@ gdk_win32_drag_context_drag_motion (GdkDragContext *context,
g_return_val_if_fail (context != NULL, FALSE);
- context->actions = possible_actions;
-
GDK_NOTE (DND, g_print ("gdk_win32_drag_context_drag_motion: @ %+d:%+d %s suggested=%s, possible=%s\n"
" context=%p:{actions=%s,suggested=%s,action=%s}\n",
x_root, y_root,
@@ -2101,8 +2099,8 @@ gdk_win32_drag_context_drag_motion (GdkDragContext *context,
_gdk_win32_drag_action_to_string (suggested_action),
_gdk_win32_drag_action_to_string (possible_actions),
context,
- _gdk_win32_drag_action_to_string (context->actions),
- _gdk_win32_drag_action_to_string (context->suggested_action),
+ _gdk_win32_drag_action_to_string (gdk_drag_context_get_actions (context)),
+ _gdk_win32_drag_action_to_string (gdk_drag_context_get_suggested_action (context)),
_gdk_win32_drag_action_to_string (context->action)));
context_win32 = GDK_WIN32_DRAG_CONTEXT (context);
@@ -2120,9 +2118,9 @@ gdk_win32_drag_context_drag_motion (GdkDragContext *context,
dest_surface);
if (dest_context)
- dest_context->actions = context->actions;
+ gdk_drag_context_set_actions (dest_context, possible_actions, suggested_action);
- context->suggested_action = suggested_action;
+ gdk_drag_context_set_actions (context, possible_actions, suggested_action);
}
else
{
@@ -2146,12 +2144,12 @@ gdk_win32_drag_context_drag_motion (GdkDragContext *context,
default:
break;
}
- context->suggested_action = suggested_action;
+ gdk_drag_context_set_actions (context, possible_actions, suggested_action);
}
else
{
context->dest_surface = NULL;
- context->action = 0;
+ gdk_drag_context_set_actions (context, 0, 0);
}
GDK_NOTE (DND, g_print ("gdk_dnd_handle_drag_status: 0x%p\n",
@@ -2192,8 +2190,8 @@ gdk_win32_drag_context_drag_motion (GdkDragContext *context,
GDK_NOTE (DND, g_print (" returning TRUE\n"
" context=%p:{actions=%s,suggested=%s,action=%s}\n",
context,
- _gdk_win32_drag_action_to_string (context->actions),
- _gdk_win32_drag_action_to_string (context->suggested_action),
+ _gdk_win32_drag_action_to_string (gdk_drag_context_get_actions (context)),
+ _gdk_win32_drag_action_to_string (gdk_drag_context_get_suggested_action (context)),
_gdk_win32_drag_action_to_string (context->action)));
return TRUE;
}
@@ -2203,8 +2201,8 @@ gdk_win32_drag_context_drag_motion (GdkDragContext *context,
GDK_NOTE (DND, g_print (" returning FALSE\n"
" context=%p:{actions=%s,suggested=%s,action=%s}\n",
context,
- _gdk_win32_drag_action_to_string (context->actions),
- _gdk_win32_drag_action_to_string (context->suggested_action),
+ _gdk_win32_drag_action_to_string (gdk_drag_context_get_actions (context)),
+ _gdk_win32_drag_action_to_string (gdk_drag_context_get_suggested_action (context)),
_gdk_win32_drag_action_to_string (context->action)));
return FALSE;
}
diff --git a/gdk/win32/gdkdrop-win32.c b/gdk/win32/gdkdrop-win32.c
index f8b21e182c..b8150e597b 100644
--- a/gdk/win32/gdkdrop-win32.c
+++ b/gdk/win32/gdkdrop-win32.c
@@ -158,7 +158,7 @@ gdk_drop_context_new (GdkDisplay *display,
context->is_source = FALSE;
g_set_object (&context->source_surface, source_surface);
g_set_object (&context->dest_surface, dest_surface);
- context->actions = actions;
+ gdk_drag_context_set_actions (context, actions, actions);
context_win32->protocol = protocol;
gdk_content_formats_unref (formats);
@@ -445,7 +445,9 @@ idroptarget_dragenter (LPDROPTARGET This,
ctx->context = context;
context->action = GDK_ACTION_MOVE;
- context->suggested_action = get_suggested_action (context_win32, grfKeyState);
+ gdk_drag_context_set_actions (context,
+ GDK_ACTION_COPY | GDK_ACTION_MOVE,
+ get_suggested_action (context_win32, grfKeyState));
set_data_object (&ctx->data_object, pDataObj);
pt_x = pt.x / context_win32->scale + _gdk_offset_x;
pt_y = pt.y / context_win32->scale + _gdk_offset_y;
@@ -482,9 +484,11 @@ idroptarget_dragover (LPDROPTARGET This,
gint pt_x = pt.x / context_win32->scale + _gdk_offset_x;
gint pt_y = pt.y / context_win32->scale + _gdk_offset_y;
- ctx->context->suggested_action = get_suggested_action (context_win32, grfKeyState);
+ gdk_drag_context_set_actions (ctx->context,
+ gdk_drag_context_get_actions (ctx->context),
+ get_suggested_action (context_win32, grfKeyState));
- GDK_NOTE (DND, g_print ("idroptarget_dragover %p @ %d : %d (raw %ld : %ld), suggests %d action S_OK\n", This, pt_x, pt_y, pt.x, pt.y, ctx->context->suggested_action));
+ GDK_NOTE (DND, g_print ("idroptarget_dragover %p @ %d : %d (raw %ld : %ld), suggests %d action S_OK\n", This, pt_x, pt_y, pt.x, pt.y, gdk_drag_context_get_suggested_action (ctx->context)));
if (pt_x != context_win32->last_x ||
pt_y != context_win32->last_y ||
@@ -541,7 +545,9 @@ idroptarget_drop (LPDROPTARGET This,
return E_POINTER;
}
- ctx->context->suggested_action = get_suggested_action (context_win32, grfKeyState);
+ gdk_drag_context_set_actions (ctx->context,
+ gdk_drag_context_get_actions (ctx->context),
+ get_suggested_action (context_win32, grfKeyState));
dnd_event_emit (GDK_DROP_START, ctx->context, pt_x, pt_y, ctx->context->dest_surface);
@@ -734,8 +740,7 @@ gdk_dropfiles_filter (GdkWin32Display *display,
context_win32 = GDK_WIN32_DROP_CONTEXT (context);
/* WM_DROPFILES drops are always file names */
-
- context->suggested_action = GDK_ACTION_COPY;
+ gdk_drag_context_set_actions (context, GDK_ACTION_COPY, GDK_ACTION_COPY);
current_dest_drag = context;
hdrop = (HANDLE) msg->wParam;
@@ -860,8 +865,8 @@ gdk_win32_drop_context_drag_status (GdkDragContext *context,
" context=%p:{actions=%s,suggested=%s,action=%s}\n",
_gdk_win32_drag_action_to_string (action),
context,
- _gdk_win32_drag_action_to_string (context->actions),
- _gdk_win32_drag_action_to_string (context->suggested_action),
+ _gdk_win32_drag_action_to_string (gdk_drag_context_get_actions (context)),
+ _gdk_win32_drag_action_to_string (gdk_drag_context_get_suggested_action (context)),
_gdk_win32_drag_action_to_string (context->action)));
context->action = action;
@@ -1227,7 +1232,7 @@ _gdk_win32_local_send_enter (GdkDragContext *context,
context->source_surface,
context->dest_surface,
gdk_content_formats_ref (gdk_drag_context_get_formats (context)),
- context->actions,
+ gdk_drag_context_get_actions (context),
GDK_DRAG_PROTO_LOCAL);
gdk_surface_set_events (new_context->source_surface,
diff --git a/gdk/x11/gdkdnd-x11.c b/gdk/x11/gdkdnd-x11.c
index 5542dc6ada..42761dc6e5 100644
--- a/gdk/x11/gdkdnd-x11.c
+++ b/gdk/x11/gdkdnd-x11.c
@@ -1527,6 +1527,7 @@ xdnd_read_actions (GdkX11DragContext *context_x11)
{
GdkDragContext *context = GDK_DRAG_CONTEXT (context_x11);
GdkDisplay *display = gdk_drag_context_get_display (context);
+ GdkDragAction actions = GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK | GDK_ACTION_ASK;
Atom type;
int format;
gulong nitems, after;
@@ -1549,12 +1550,12 @@ xdnd_read_actions (GdkX11DragContext *context_x11)
&after, &data) == Success &&
type == XA_ATOM)
{
- atoms = (Atom *)data;
+ actions = 0;
- context->actions = 0;
+ atoms = (Atom *)data;
for (i = 0; i < nitems; i++)
- context->actions |= xdnd_action_from_atom (display, atoms[i]);
+ actions |= xdnd_action_from_atom (display, atoms[i]);
context_x11->xdnd_have_actions = TRUE;
@@ -1562,20 +1563,20 @@ xdnd_read_actions (GdkX11DragContext *context_x11)
if (GDK_DISPLAY_DEBUG_CHECK (display, DND))
{
GString *action_str = g_string_new (NULL);
- if (context->actions & GDK_ACTION_MOVE)
+ GdkDragAction actions = gdk_drag_context_get_actions (context);
+ if (actions & GDK_ACTION_MOVE)
g_string_append(action_str, "MOVE ");
- if (context->actions & GDK_ACTION_COPY)
+ if (actions & GDK_ACTION_COPY)
g_string_append(action_str, "COPY ");
- if (context->actions & GDK_ACTION_LINK)
+ if (actions & GDK_ACTION_LINK)
g_string_append(action_str, "LINK ");
- if (context->actions & GDK_ACTION_ASK)
+ if (actions & GDK_ACTION_ASK)
g_string_append(action_str, "ASK ");
g_message("Xdnd actions = %s", action_str->str);
g_string_free (action_str, TRUE);
}
#endif /* G_ENABLE_DEBUG */
-
}
if (data)
@@ -1595,10 +1596,12 @@ xdnd_read_actions (GdkX11DragContext *context_x11)
if (source_context)
{
- context->actions = source_context->actions;
+ actions = gdk_drag_context_get_actions (source_context);
context_x11->xdnd_have_actions = TRUE;
}
}
+
+ gdk_drag_context_set_actions (context, actions, gdk_drag_context_get_suggested_action (context));
}
/* We have to make sure that the XdndActionList we keep internally
@@ -1899,6 +1902,7 @@ xdnd_position_filter (const XEvent *xevent,
GdkX11Display *display_x11;
GdkDragContext *context;
GdkX11DragContext *context_x11;
+ GdkDragAction suggested_action;
if (!event->any.surface ||
gdk_surface_get_surface_type (event->any.surface) == GDK_SURFACE_FOREIGN)
@@ -1930,10 +1934,15 @@ xdnd_position_filter (const XEvent *xevent,
event->dnd.time = time;
- context->suggested_action = xdnd_action_from_atom (display, action);
-
- if (!context_x11->xdnd_have_actions)
- context->actions = context->suggested_action;
+ suggested_action = xdnd_action_from_atom (display, action);
+ if (context_x11->xdnd_have_actions)
+ gdk_drag_context_set_actions (context,
+ gdk_drag_context_get_actions (context),
+ suggested_action);
+ else
+ gdk_drag_context_set_actions (context,
+ suggested_action,
+ suggested_action);
event->dnd.x_root = x_root / impl->surface_scale;
event->dnd.y_root = y_root / impl->surface_scale;
@@ -2219,7 +2228,7 @@ gdk_x11_drag_context_drag_motion (GdkDragContext *context,
if (context_x11->drag_surface)
move_drag_surface (context, x_root, y_root);
- context->actions = possible_actions;
+ gdk_drag_context_set_actions (context, possible_actions, suggested_action);
if (protocol == GDK_DRAG_PROTO_XDND && context_x11->version == 0)
{
@@ -2261,7 +2270,7 @@ gdk_x11_drag_context_drag_motion (GdkDragContext *context,
if (dest_context)
{
- dest_context->actions = context->actions;
+ gdk_drag_context_set_actions (dest_context, possible_actions, suggested_action);
GDK_X11_DRAG_CONTEXT (dest_context)->xdnd_have_actions = TRUE;
}
}
@@ -2294,7 +2303,6 @@ gdk_x11_drag_context_drag_motion (GdkDragContext *context,
default:
break;
}
- context->suggested_action = suggested_action;
}
else
{
@@ -2312,10 +2320,6 @@ gdk_x11_drag_context_drag_motion (GdkDragContext *context,
g_signal_emit_by_name (context, "action-changed", context->action);
}
}
- else
- {
- context->suggested_action = suggested_action;
- }
/* Send a drag-motion event */
@@ -2342,7 +2346,7 @@ gdk_x11_drag_context_drag_motion (GdkDragContext *context,
*/
if (gdk_content_formats_contain_mime_type (formats, "application/x-rootwindow-drop") ||
gdk_content_formats_contain_mime_type (formats, "application/x-rootwin-drop"))
- context->action = context->suggested_action;
+ context->action = gdk_drag_context_get_suggested_action (context);
else
context->action = 0;