summaryrefslogtreecommitdiff
path: root/gdk
diff options
context:
space:
mode:
authorBenjamin Otte <otte@redhat.com>2017-12-11 01:45:31 +0100
committerBenjamin Otte <otte@redhat.com>2017-12-11 01:46:33 +0100
commit643a6c231176d81e24ea3f3dc05d61848ea570af (patch)
tree0d58e91c7e07607bedd829bb8452e3731a75068a /gdk
parent7e0844d92f10e0ef328fb79e98451e6eef92c606 (diff)
downloadgtk+-643a6c231176d81e24ea3f3dc05d61848ea570af.tar.gz
gdk: Remove gdk_drag_manage_dnd()
Instead, pass the actions as part of gdk_drag_begin() and insist DND is always managed. A new side effect is that gdk_drag_begin() can now return %NULL.
Diffstat (limited to 'gdk')
-rw-r--r--gdk/broadway/gdkdnd-broadway.c1
-rw-r--r--gdk/broadway/gdkprivate-broadway.h5
-rw-r--r--gdk/gdkdnd.c57
-rw-r--r--gdk/gdkdnd.h5
-rw-r--r--gdk/gdkdndprivate.h3
-rw-r--r--gdk/gdkwindow.c11
-rw-r--r--gdk/gdkwindowimpl.h5
-rw-r--r--gdk/wayland/gdkdnd-wayland.c60
-rw-r--r--gdk/wayland/gdkprivate-wayland.h5
-rw-r--r--gdk/x11/gdkdnd-x11.c99
-rw-r--r--gdk/x11/gdkprivate-x11.h1
11 files changed, 83 insertions, 169 deletions
diff --git a/gdk/broadway/gdkdnd-broadway.c b/gdk/broadway/gdkdnd-broadway.c
index ac11be4a2a..c670d8d3d9 100644
--- a/gdk/broadway/gdkdnd-broadway.c
+++ b/gdk/broadway/gdkdnd-broadway.c
@@ -87,6 +87,7 @@ GdkDragContext *
_gdk_broadway_window_drag_begin (GdkWindow *window,
GdkDevice *device,
GdkContentFormats *formats,
+ GdkDragAction actions,
gint dx,
gint dy)
{
diff --git a/gdk/broadway/gdkprivate-broadway.h b/gdk/broadway/gdkprivate-broadway.h
index 250c81c076..bc40ea9c32 100644
--- a/gdk/broadway/gdkprivate-broadway.h
+++ b/gdk/broadway/gdkprivate-broadway.h
@@ -50,8 +50,9 @@ void _gdk_broadway_window_register_dnd (GdkWindow *window);
GdkDragContext * _gdk_broadway_window_drag_begin (GdkWindow *window,
GdkDevice *device,
GdkContentFormats *formats,
- gint x_root,
- gint y_root);
+ GdkDragAction actions,
+ gint dx,
+ gint dy);
void _gdk_broadway_window_translate (GdkWindow *window,
cairo_region_t *area,
gint dx,
diff --git a/gdk/gdkdnd.c b/gdk/gdkdnd.c
index 577ff730ed..8456cd29a7 100644
--- a/gdk/gdkdnd.c
+++ b/gdk/gdkdnd.c
@@ -376,10 +376,6 @@ gdk_drag_context_class_init (GdkDragContextClass *klass)
*
* The drag and drop operation was cancelled.
*
- * This signal will only be emitted if the #GdkDragContext manages
- * the drag and drop operation. See gdk_drag_context_manage_dnd()
- * for more information.
- *
* Since: 3.20
*/
signals[CANCEL] =
@@ -398,10 +394,6 @@ gdk_drag_context_class_init (GdkDragContextClass *klass)
*
* The drag and drop operation was performed on an accepting client.
*
- * This signal will only be emitted if the #GdkDragContext manages
- * the drag and drop operation. See gdk_drag_context_manage_dnd()
- * for more information.
- *
* Since: 3.20
*/
signals[DROP_PERFORMED] =
@@ -421,10 +413,6 @@ gdk_drag_context_class_init (GdkDragContextClass *klass)
* finished reading all data. The drag source can now free all
* miscellaneous data.
*
- * This signal will only be emitted if the #GdkDragContext manages
- * the drag and drop operation. See gdk_drag_context_manage_dnd()
- * for more information.
- *
* Since: 3.20
*/
signals[DND_FINISHED] =
@@ -443,10 +431,6 @@ gdk_drag_context_class_init (GdkDragContextClass *klass)
*
* A new action is being chosen for the drag and drop operation.
*
- * This signal will only be emitted if the #GdkDragContext manages
- * the drag and drop operation. See gdk_drag_context_manage_dnd()
- * for more information.
- *
* Since: 3.20
*/
signals[ACTION_CHANGED] =
@@ -799,47 +783,6 @@ gdk_drag_drop_done (GdkDragContext *context,
GDK_DRAG_CONTEXT_GET_CLASS (context)->drop_done (context, success);
}
-/**
- * gdk_drag_context_manage_dnd:
- * @context: a #GdkDragContext
- * @ipc_window: Window to use for IPC messaging/events
- * @actions: the actions supported by the drag source
- *
- * Requests the drag and drop operation to be managed by @context.
- * When a drag and drop operation becomes managed, the #GdkDragContext
- * will internally handle all input and source-side #GdkEventDND events
- * as required by the windowing system.
- *
- * Once the drag and drop operation is managed, the drag context will
- * emit the following signals:
- * - The #GdkDragContext::action-changed signal whenever the final action
- * to be performed by the drag and drop operation changes.
- * - The #GdkDragContext::drop-performed signal after the user performs
- * the drag and drop gesture (typically by releasing the mouse button).
- * - The #GdkDragContext::dnd-finished signal after the drag and drop
- * operation concludes (after all #GdkSelection transfers happen).
- * - The #GdkDragContext::cancel signal if the drag and drop operation is
- * finished but doesn't happen over an accepting destination, or is
- * cancelled through other means.
- *
- * Returns: #TRUE if the drag and drop operation is managed.
- *
- * Since: 3.20
- **/
-gboolean
-gdk_drag_context_manage_dnd (GdkDragContext *context,
- GdkWindow *ipc_window,
- GdkDragAction actions)
-{
- g_return_val_if_fail (GDK_IS_DRAG_CONTEXT (context), FALSE);
- g_return_val_if_fail (GDK_IS_WINDOW (ipc_window), FALSE);
-
- if (GDK_DRAG_CONTEXT_GET_CLASS (context)->manage_dnd)
- return GDK_DRAG_CONTEXT_GET_CLASS (context)->manage_dnd (context, ipc_window, actions);
-
- return FALSE;
-}
-
void
gdk_drag_context_set_cursor (GdkDragContext *context,
GdkCursor *cursor)
diff --git a/gdk/gdkdnd.h b/gdk/gdkdnd.h
index 6d7d224446..4a3926e589 100644
--- a/gdk/gdkdnd.h
+++ b/gdk/gdkdnd.h
@@ -137,6 +137,7 @@ GDK_AVAILABLE_IN_ALL
GdkDragContext * gdk_drag_begin (GdkWindow *window,
GdkDevice *device,
GdkContentFormats *formats,
+ GdkDragAction actions,
gint dx,
gint dy);
@@ -155,10 +156,6 @@ void gdk_drag_context_set_hotspot (GdkDragContext *context,
gint hot_x,
gint hot_y);
-GDK_AVAILABLE_IN_3_20
-gboolean gdk_drag_context_manage_dnd (GdkDragContext *context,
- GdkWindow *ipc_window,
- GdkDragAction actions);
G_END_DECLS
#endif /* __GDK_DND_H__ */
diff --git a/gdk/gdkdndprivate.h b/gdk/gdkdndprivate.h
index 16ad7332d4..2982bcb83c 100644
--- a/gdk/gdkdndprivate.h
+++ b/gdk/gdkdndprivate.h
@@ -105,9 +105,6 @@ struct _GdkDragContextClass {
void (*drop_done) (GdkDragContext *context,
gboolean success);
- gboolean (*manage_dnd) (GdkDragContext *context,
- GdkWindow *ipc_window,
- GdkDragAction actions);
void (*set_cursor) (GdkDragContext *context,
GdkCursor *cursor);
void (*cancel) (GdkDragContext *context,
diff --git a/gdk/gdkwindow.c b/gdk/gdkwindow.c
index 47ec729f2b..c504bc889b 100644
--- a/gdk/gdkwindow.c
+++ b/gdk/gdkwindow.c
@@ -6928,6 +6928,7 @@ gdk_window_register_dnd (GdkWindow *window)
* @window: the source window for this drag
* @device: the device that controls this drag
* @formats: (transfer none): the offered formats
+ * @actions: the actions supported by this drag
* @dx: the x offset to @device's position where the drag nominally started
* @dy: the y offset to @device's position where the drag nominally started
*
@@ -6935,16 +6936,18 @@ gdk_window_register_dnd (GdkWindow *window)
*
* This function is called by the drag source.
*
- * Returns: (transfer full): a newly created #GdkDragContext
+ * Returns: (transfer full) (nullable): a newly created #GdkDragContext or
+ * %NULL on error.
*/
GdkDragContext *
gdk_drag_begin (GdkWindow *window,
GdkDevice *device,
GdkContentFormats *formats,
- gint x_root,
- gint y_root)
+ GdkDragAction actions,
+ gint dx,
+ gint dy)
{
- return GDK_WINDOW_IMPL_GET_CLASS (window->impl)->drag_begin (window, device, formats, x_root, y_root);
+ return GDK_WINDOW_IMPL_GET_CLASS (window->impl)->drag_begin (window, device, formats, actions, dx, dy);
}
/**
diff --git a/gdk/gdkwindowimpl.h b/gdk/gdkwindowimpl.h
index af063a8f58..f1abe35307 100644
--- a/gdk/gdkwindowimpl.h
+++ b/gdk/gdkwindowimpl.h
@@ -220,8 +220,9 @@ struct _GdkWindowImplClass
GdkDragContext * (*drag_begin) (GdkWindow *window,
GdkDevice *device,
GdkContentFormats *formats,
- gint x_root,
- gint y_root);
+ GdkDragAction actions,
+ gint dx,
+ gint dy);
void (*process_updates_recurse) (GdkWindow *window,
cairo_region_t *region);
diff --git a/gdk/wayland/gdkdnd-wayland.c b/gdk/wayland/gdkdnd-wayland.c
index ea1b6ef3a1..2a2c56c51f 100644
--- a/gdk/wayland/gdkdnd-wayland.c
+++ b/gdk/wayland/gdkdnd-wayland.c
@@ -454,40 +454,6 @@ gdk_wayland_drag_context_set_hotspot (GdkDragContext *context,
gdk_window_invalidate_rect (context_wayland->dnd_window, &damage_rect, FALSE);
}
-static gboolean
-gdk_wayland_drag_context_manage_dnd (GdkDragContext *context,
- GdkWindow *ipc_window,
- GdkDragAction actions)
-{
- GdkWaylandDragContext *context_wayland;
- GdkWaylandDisplay *display_wayland;
- GdkDevice *device;
- GdkWindow *toplevel;
-
- device = gdk_drag_context_get_device (context);
- display_wayland = GDK_WAYLAND_DISPLAY (gdk_device_get_display (device));
- toplevel = _gdk_device_window_at_position (device, NULL, NULL, NULL, TRUE);
-
- context_wayland = GDK_WAYLAND_DRAG_CONTEXT (context);
-
- if (display_wayland->data_device_manager_version >=
- WL_DATA_SOURCE_SET_ACTIONS_SINCE_VERSION)
- {
- wl_data_source_set_actions (context_wayland->data_source,
- gdk_to_wl_actions (actions));
- }
-
- wl_data_device_start_drag (gdk_wayland_device_get_data_device (device),
- context_wayland->data_source,
- gdk_wayland_window_get_wl_surface (toplevel),
- context_wayland->dnd_surface,
- _gdk_wayland_display_get_serial (display_wayland));
-
- gdk_seat_ungrab (gdk_device_get_seat (device));
-
- return TRUE;
-}
-
static void
gdk_wayland_drag_context_set_cursor (GdkDragContext *context,
GdkCursor *cursor)
@@ -557,7 +523,6 @@ gdk_wayland_drag_context_class_init (GdkWaylandDragContextClass *klass)
context_class->get_drag_window = gdk_wayland_drag_context_get_drag_window;
context_class->set_hotspot = gdk_wayland_drag_context_set_hotspot;
context_class->drop_done = gdk_wayland_drag_context_drop_done;
- context_class->manage_dnd = gdk_wayland_drag_context_manage_dnd;
context_class->set_cursor = gdk_wayland_drag_context_set_cursor;
context_class->action_changed = gdk_wayland_drag_context_action_changed;
context_class->drop_performed = gdk_wayland_drag_context_drop_performed;
@@ -586,16 +551,21 @@ GdkDragContext *
_gdk_wayland_window_drag_begin (GdkWindow *window,
GdkDevice *device,
GdkContentFormats *formats,
+ GdkDragAction actions,
gint dx,
gint dy)
{
GdkWaylandDragContext *context_wayland;
GdkDragContext *context;
+ GdkWaylandDisplay *display_wayland;
+ GdkWindow *toplevel;
const char *const *mimetypes;
gsize i, n_mimetypes;
+ display_wayland = GDK_WAYLAND_DISPLAY (gdk_device_get_display (device));
+
context_wayland = g_object_new (GDK_TYPE_WAYLAND_DRAG_CONTEXT,
- "display", gdk_window_get_display (window),
+ "display", display_wayland,
NULL);
context = GDK_DRAG_CONTEXT (context_wayland);
context->source_window = g_object_ref (window);
@@ -616,9 +586,27 @@ _gdk_wayland_window_drag_begin (GdkWindow *window,
wl_data_source_offer (context_wayland->data_source, mimetypes[i]);
}
+ toplevel = _gdk_device_window_at_position (device, NULL, NULL, NULL, TRUE);
+
+ if (display_wayland->data_device_manager_version >=
+ WL_DATA_SOURCE_SET_ACTIONS_SINCE_VERSION)
+ {
+ wl_data_source_set_actions (context_wayland->data_source,
+ gdk_to_wl_actions (actions));
+ }
+
+ wl_data_device_start_drag (gdk_wayland_device_get_data_device (device),
+ context_wayland->data_source,
+ gdk_wayland_window_get_wl_surface (toplevel),
+ context_wayland->dnd_surface,
+ _gdk_wayland_display_get_serial (display_wayland));
+
+ gdk_seat_ungrab (gdk_device_get_seat (device));
+
return context;
}
+
GdkDragContext *
_gdk_wayland_drop_context_new (GdkDisplay *display,
struct wl_data_device *data_device)
diff --git a/gdk/wayland/gdkprivate-wayland.h b/gdk/wayland/gdkprivate-wayland.h
index f650b31d13..6b6e356a11 100644
--- a/gdk/wayland/gdkprivate-wayland.h
+++ b/gdk/wayland/gdkprivate-wayland.h
@@ -94,8 +94,9 @@ void _gdk_wayland_window_register_dnd (GdkWindow *window);
GdkDragContext *_gdk_wayland_window_drag_begin (GdkWindow *window,
GdkDevice *device,
GdkContentFormats *formats,
- gint x_root,
- gint y_root);
+ GdkDragAction actions,
+ gint dx,
+ gint dy);
void _gdk_wayland_window_offset_next_wl_buffer (GdkWindow *window,
int x,
int y);
diff --git a/gdk/x11/gdkdnd-x11.c b/gdk/x11/gdkdnd-x11.c
index 1f9acd257f..a5d35dfaca 100644
--- a/gdk/x11/gdkdnd-x11.c
+++ b/gdk/x11/gdkdnd-x11.c
@@ -235,9 +235,6 @@ static void gdk_x11_drag_context_set_hotspot (GdkDragContext *context,
gint hot_y);
static void gdk_x11_drag_context_drop_done (GdkDragContext *context,
gboolean success);
-static gboolean gdk_x11_drag_context_manage_dnd (GdkDragContext *context,
- GdkWindow *window,
- GdkDragAction actions);
static void gdk_x11_drag_context_set_cursor (GdkDragContext *context,
GdkCursor *cursor);
static void gdk_x11_drag_context_cancel (GdkDragContext *context,
@@ -396,7 +393,6 @@ gdk_x11_drag_context_class_init (GdkX11DragContextClass *klass)
context_class->get_drag_window = gdk_x11_drag_context_get_drag_window;
context_class->set_hotspot = gdk_x11_drag_context_set_hotspot;
context_class->drop_done = gdk_x11_drag_context_drop_done;
- context_class->manage_dnd = gdk_x11_drag_context_manage_dnd;
context_class->set_cursor = gdk_x11_drag_context_set_cursor;
context_class->cancel = gdk_x11_drag_context_cancel;
context_class->drop_performed = gdk_x11_drag_context_drop_performed;
@@ -2097,44 +2093,6 @@ create_drag_window (GdkDisplay *display)
return window;
}
-GdkDragContext *
-_gdk_x11_window_drag_begin (GdkWindow *window,
- GdkDevice *device,
- GdkContentFormats *formats,
- gint dx,
- gint dy)
-{
- GdkDragContext *context;
- int x_root, y_root;
-
- context = (GdkDragContext *) g_object_new (GDK_TYPE_X11_DRAG_CONTEXT,
- "display", gdk_window_get_display (window),
- NULL);
-
- context->is_source = TRUE;
- context->source_window = window;
- g_object_ref (window);
-
- context->formats = gdk_content_formats_ref (formats);
- precache_target_list (context);
-
- context->actions = 0;
-
- gdk_drag_context_set_device (context, device);
- gdk_device_get_position (device, &x_root, &y_root);
- x_root += dx;
- y_root += dy;
-
- GDK_X11_DRAG_CONTEXT (context)->start_x = x_root;
- GDK_X11_DRAG_CONTEXT (context)->start_y = y_root;
- GDK_X11_DRAG_CONTEXT (context)->last_x = x_root;
- GDK_X11_DRAG_CONTEXT (context)->last_y = y_root;
-
- GDK_X11_DRAG_CONTEXT (context)->drag_window = create_drag_window (gdk_window_get_display(window));
-
- return context;
-}
-
Window
_gdk_x11_display_get_drag_protocol (GdkDisplay *display,
Window xid,
@@ -2900,30 +2858,53 @@ drag_context_ungrab (GdkDragContext *context)
}
}
-static gboolean
-gdk_x11_drag_context_manage_dnd (GdkDragContext *context,
- GdkWindow *ipc_window,
- GdkDragAction actions)
+GdkDragContext *
+_gdk_x11_window_drag_begin (GdkWindow *window,
+ GdkDevice *device,
+ GdkContentFormats *formats,
+ GdkDragAction actions,
+ gint dx,
+ gint dy)
{
- GdkX11DragContext *x11_context = GDK_X11_DRAG_CONTEXT (context);
+ GdkDragContext *context;
+ int x_root, y_root;
- if (x11_context->ipc_window)
- return FALSE;
+ context = (GdkDragContext *) g_object_new (GDK_TYPE_X11_DRAG_CONTEXT,
+ "display", gdk_window_get_display (window),
+ NULL);
+
+ context->is_source = TRUE;
+ context->source_window = window;
+ g_object_ref (window);
+
+ context->formats = gdk_content_formats_ref (formats);
+ precache_target_list (context);
+
+ gdk_drag_context_set_device (context, device);
+ gdk_device_get_position (device, &x_root, &y_root);
+ x_root += dx;
+ y_root += dy;
+
+ GDK_X11_DRAG_CONTEXT (context)->start_x = x_root;
+ GDK_X11_DRAG_CONTEXT (context)->start_y = y_root;
+ GDK_X11_DRAG_CONTEXT (context)->last_x = x_root;
+ GDK_X11_DRAG_CONTEXT (context)->last_y = y_root;
context->protocol = GDK_DRAG_PROTO_XDND;
- x11_context->ipc_window = g_object_ref (ipc_window);
+ GDK_X11_DRAG_CONTEXT (context)->actions = actions;
+ GDK_X11_DRAG_CONTEXT (context)->ipc_window = g_object_ref (window);
- if (drag_context_grab (context))
- {
- x11_context->actions = actions;
- move_drag_window (context, x11_context->start_x, x11_context->start_y);
- return TRUE;
- }
- else
+ GDK_X11_DRAG_CONTEXT (context)->drag_window = create_drag_window (gdk_window_get_display(window));
+
+ if (!drag_context_grab (context))
{
- g_clear_object (&x11_context->ipc_window);
- return FALSE;
+ g_object_unref (context);
+ return NULL;
}
+
+ move_drag_window (context, x_root, y_root);
+
+ return context;
}
static void
diff --git a/gdk/x11/gdkprivate-x11.h b/gdk/x11/gdkprivate-x11.h
index f163e9bc6c..990e203175 100644
--- a/gdk/x11/gdkprivate-x11.h
+++ b/gdk/x11/gdkprivate-x11.h
@@ -285,6 +285,7 @@ void _gdk_x11_window_register_dnd (GdkWindow *window);
GdkDragContext * _gdk_x11_window_drag_begin (GdkWindow *window,
GdkDevice *device,
GdkContentFormats *formats,
+ GdkDragAction actions,
gint x_root,
gint y_root);