[gtk+] dnd: Pass dx/dy instead of x_root/y_root
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] dnd: Pass dx/dy instead of x_root/y_root
- Date: Mon, 11 Dec 2017 00:08:03 +0000 (UTC)
commit 218efa62ef7e7ee20ca70c8c0735400684561838
Author: Benjamin Otte <otte redhat com>
Date: Mon Dec 11 00:55:56 2017 +0100
dnd: Pass dx/dy instead of x_root/y_root
This way, we don't need root coordinates when computing the dnd start
position.
gdk/broadway/gdkdnd-broadway.c | 4 ++--
gdk/gdkdnd.h | 4 ++--
gdk/gdkwindow.c | 4 ++--
gdk/quartz/gdkdnd-quartz.c | 4 ++--
gdk/wayland/gdkdnd-wayland.c | 4 ++--
gdk/win32/gdkdnd-win32.c | 9 +++++++--
gdk/x11/gdkdnd-x11.c | 8 ++++++--
gtk/gtkdnd.c | 34 +++++++++++++++++++++++++---------
8 files changed, 48 insertions(+), 23 deletions(-)
---
diff --git a/gdk/broadway/gdkdnd-broadway.c b/gdk/broadway/gdkdnd-broadway.c
index cbc1860..ac11be4 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 f830fdc..6d7d224 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 d14558d..47ec729 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 fc9c338..2143848 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 b64f487..ea1b6ef 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 fbf5af6..6952807 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 9b626e2..1f9acd2 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 e613a5c..e969a37 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))
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]