summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Otte <otte@redhat.com>2017-12-11 00:55:56 +0100
committerBenjamin Otte <otte@redhat.com>2017-12-11 01:02:31 +0100
commit218efa62ef7e7ee20ca70c8c0735400684561838 (patch)
treed9440ef2b2ced1c6c4ef2f187012dc0664f0729b
parenta7c3c794df0fa9eee47fea499f7daef48a05c167 (diff)
downloadgtk+-218efa62ef7e7ee20ca70c8c0735400684561838.tar.gz
dnd: Pass dx/dy instead of x_root/y_root
This way, we don't need root coordinates when computing the dnd start position.
-rw-r--r--gdk/broadway/gdkdnd-broadway.c4
-rw-r--r--gdk/gdkdnd.h4
-rw-r--r--gdk/gdkwindow.c4
-rw-r--r--gdk/quartz/gdkdnd-quartz.c4
-rw-r--r--gdk/wayland/gdkdnd-wayland.c4
-rw-r--r--gdk/win32/gdkdnd-win32.c9
-rw-r--r--gdk/x11/gdkdnd-x11.c8
-rw-r--r--gtk/gtkdnd.c34
8 files changed, 48 insertions, 23 deletions
diff --git a/gdk/broadway/gdkdnd-broadway.c b/gdk/broadway/gdkdnd-broadway.c
index cbc1860181..ac11be4a2a 100644
--- a/gdk/broadway/gdkdnd-broadway.c
+++ b/gdk/broadway/gdkdnd-broadway.c
@@ -87,8 +87,8 @@ GdkDragContext *
_gdk_broadway_window_drag_begin (GdkWindow *window,
GdkDevice *device,
GdkContentFormats *formats,
- gint x_root,
- gint y_root)
+ gint dx,
+ gint dy)
{
GdkDragContext *new_context;
diff --git a/gdk/gdkdnd.h b/gdk/gdkdnd.h
index f830fdc69e..6d7d224446 100644
--- a/gdk/gdkdnd.h
+++ b/gdk/gdkdnd.h
@@ -137,8 +137,8 @@ GDK_AVAILABLE_IN_ALL
GdkDragContext * gdk_drag_begin (GdkWindow *window,
GdkDevice *device,
GdkContentFormats *formats,
- gint x_root,
- gint y_root);
+ gint dx,
+ gint dy);
GDK_AVAILABLE_IN_ALL
gboolean gdk_drag_drop_succeeded (GdkDragContext *context);
diff --git a/gdk/gdkwindow.c b/gdk/gdkwindow.c
index d14558d72a..47ec729f2b 100644
--- a/gdk/gdkwindow.c
+++ b/gdk/gdkwindow.c
@@ -6928,8 +6928,8 @@ 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
- * @x_root: the x coordinate where the drag nominally started
- * @y_root: the y coordinate where the drag nominally started
+ * @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
*
* Starts a drag and creates a new drag context for it.
*
diff --git a/gdk/quartz/gdkdnd-quartz.c b/gdk/quartz/gdkdnd-quartz.c
index fc9c338ca2..21438481b4 100644
--- a/gdk/quartz/gdkdnd-quartz.c
+++ b/gdk/quartz/gdkdnd-quartz.c
@@ -36,8 +36,8 @@ GdkDragContext *
_gdk_quartz_window_drag_begin (GdkWindow *window,
GdkDevice *device,
GList *targets,
- gint x_root,
- gint y_root)
+ gint dx,
+ gint dy)
{
g_assert (_gdk_quartz_drag_source_context == NULL);
diff --git a/gdk/wayland/gdkdnd-wayland.c b/gdk/wayland/gdkdnd-wayland.c
index b64f487738..ea1b6ef3a1 100644
--- a/gdk/wayland/gdkdnd-wayland.c
+++ b/gdk/wayland/gdkdnd-wayland.c
@@ -586,8 +586,8 @@ GdkDragContext *
_gdk_wayland_window_drag_begin (GdkWindow *window,
GdkDevice *device,
GdkContentFormats *formats,
- gint x_root,
- gint y_root)
+ gint dx,
+ gint dy)
{
GdkWaylandDragContext *context_wayland;
GdkDragContext *context;
diff --git a/gdk/win32/gdkdnd-win32.c b/gdk/win32/gdkdnd-win32.c
index fbf5af6922..6952807622 100644
--- a/gdk/win32/gdkdnd-win32.c
+++ b/gdk/win32/gdkdnd-win32.c
@@ -2011,13 +2011,14 @@ GdkDragContext *
_gdk_win32_window_drag_begin (GdkWindow *window,
GdkDevice *device,
GdkContentFormats *formats,
- gint x_root,
- gint y_root)
+ gint dx,
+ gint dy)
{
GdkDragContext *new_context;
GdkWin32DragContext *context_win32;
BYTE kbd_state[256];
GdkWin32Selection *sel_win32 = _gdk_win32_selection_get ();
+ int x_root, y_root;
if (!use_ole2_dnd)
{
@@ -2050,6 +2051,10 @@ _gdk_win32_window_drag_begin (GdkWindow *window,
context_win32 = GDK_WIN32_DRAG_CONTEXT (new_context);
}
+ gdk_device_get_position (device, &x_root, &y_root);
+ x_root += dx;
+ y_root += dy;
+
context_win32->start_x = x_root;
context_win32->start_y = y_root;
context_win32->last_x = context_win32->start_x;
diff --git a/gdk/x11/gdkdnd-x11.c b/gdk/x11/gdkdnd-x11.c
index 9b626e2ad1..1f9acd257f 100644
--- a/gdk/x11/gdkdnd-x11.c
+++ b/gdk/x11/gdkdnd-x11.c
@@ -2101,10 +2101,11 @@ GdkDragContext *
_gdk_x11_window_drag_begin (GdkWindow *window,
GdkDevice *device,
GdkContentFormats *formats,
- gint x_root,
- gint y_root)
+ 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),
@@ -2120,6 +2121,9 @@ _gdk_x11_window_drag_begin (GdkWindow *window,
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;
diff --git a/gtk/gtkdnd.c b/gtk/gtkdnd.c
index e613a5c1dd..e969a3702c 100644
--- a/gtk/gtkdnd.c
+++ b/gtk/gtkdnd.c
@@ -1060,7 +1060,7 @@ gtk_drag_begin_internal (GtkWidget *widget,
GtkWidget *ipc_widget;
GdkDevice *pointer, *keyboard;
GdkWindow *ipc_window;
- int start_x, start_y;
+ int dx, dy;
GdkAtom selection;
pointer = keyboard = NULL;
@@ -1106,21 +1106,37 @@ gtk_drag_begin_internal (GtkWidget *widget,
GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
gtk_widget_translate_coordinates (widget, toplevel,
x, y, &x, &y);
- gdk_window_get_root_coords (gtk_widget_get_window (toplevel),
- x, y, &start_x, &start_y);
+ gdk_window_get_device_position (gtk_widget_get_window (toplevel),
+ pointer,
+ &dx, &dy,
+ NULL);
+ dx -= x;
+ dy -= y;
}
else if (event && gdk_event_get_event_type (event) == GDK_MOTION_NOTIFY)
{
- double x, y;
+ double ex, ey;
+ GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
- gdk_event_get_root_coords (event, &x, &y);
- start_x = (int)x;
- start_y = (int)y;
+ gdk_event_get_coords (event, &ex, &ey);
+ x = ex;
+ y = ey;
+ gtk_widget_translate_coordinates (widget, toplevel,
+ x, y, &x, &y);
+ gdk_window_get_device_position (gtk_widget_get_window (toplevel),
+ pointer,
+ &dx, &dy,
+ NULL);
+ dx -= x;
+ dy -= y;
}
else
- gdk_device_get_position (pointer, &start_x, &start_y);
+ {
+ dx = 0;
+ dy = 0;
+ }
- context = gdk_drag_begin (ipc_window, pointer, target_list, start_x, start_y);
+ context = gdk_drag_begin (ipc_window, pointer, target_list, dx, dy);
if (!gdk_drag_context_manage_dnd (context, ipc_window, actions))
{