From 677c4b140ce6ad22726c6e3c39b56f27674989dd Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Mon, 30 Dec 2019 11:56:49 -0500 Subject: [PATCH 1/3] gdk: Fix coordinates in dnd events Don't store coordinates as shorts. Use doubles, as everywhere else. Also add x, y in addition to x_root, y_root, and actually return those in gdk_event_get_coords. --- gdk/gdkevents.c | 7 +++++++ gdk/gdkeventsprivate.h | 4 +++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/gdk/gdkevents.c b/gdk/gdkevents.c index bf978e2980..27c7501bd3 100644 --- a/gdk/gdkevents.c +++ b/gdk/gdkevents.c @@ -947,6 +947,13 @@ gdk_event_get_coords (const GdkEvent *event, x = event->touchpad_pinch.x; y = event->touchpad_pinch.y; break; + case GDK_DRAG_ENTER: + case GDK_DRAG_LEAVE: + case GDK_DRAG_MOTION: + case GDK_DROP_START: + x = event->dnd.x; + y = event->dnd.y; + break; default: fetched = FALSE; break; diff --git a/gdk/gdkeventsprivate.h b/gdk/gdkeventsprivate.h index eefc1f4622..fe9b80a7f8 100644 --- a/gdk/gdkeventsprivate.h +++ b/gdk/gdkeventsprivate.h @@ -418,7 +418,9 @@ struct _GdkEventDND { GdkDrop *drop; guint32 time; - gshort x_root, y_root; + double x_root, y_root; + double x; + double y; }; /* From 94a0bc01f9ed6775436317ac42ca95a6d60b097c Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Mon, 30 Dec 2019 11:58:11 -0500 Subject: [PATCH 2/3] gdk: Populate dnd event coords The GdkDrop emit... apis take root coordinates. That should be changed to surface coordinates, eventually. For now, make the functions fill the x, y fields. --- gdk/gdkdrop.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/gdk/gdkdrop.c b/gdk/gdkdrop.c index ea85862a4c..ae606cb73c 100644 --- a/gdk/gdkdrop.c +++ b/gdk/gdkdrop.c @@ -938,6 +938,9 @@ gdk_drop_emit_motion_event (GdkDrop *self, { GdkDropPrivate *priv = gdk_drop_get_instance_private (self); GdkEvent *event; + int x, y; + + gdk_surface_get_origin (priv->surface, &x, &y); event = gdk_event_new (GDK_DRAG_MOTION); event->any.surface = g_object_ref (priv->surface); @@ -945,6 +948,8 @@ gdk_drop_emit_motion_event (GdkDrop *self, event->dnd.time = time; event->dnd.x_root = x_root; event->dnd.y_root = y_root; + event->dnd.x = x_root - x; + event->dnd.y = y_root - y; gdk_event_set_device (event, priv->device); gdk_drop_do_emit_event (event, dont_queue); @@ -976,6 +981,9 @@ gdk_drop_emit_drop_event (GdkDrop *self, { GdkDropPrivate *priv = gdk_drop_get_instance_private (self); GdkEvent *event; + int x, y; + + gdk_surface_get_origin (priv->surface, &x, &y); event = gdk_event_new (GDK_DROP_START); event->any.surface = g_object_ref (priv->surface); @@ -983,6 +991,8 @@ gdk_drop_emit_drop_event (GdkDrop *self, event->dnd.time = time; event->dnd.x_root = x_root; event->dnd.y_root = y_root; + event->dnd.x = x_root - x; + event->dnd.y = y_root - y; gdk_event_set_device (event, priv->device); gdk_drop_do_emit_event (event, dont_queue); From 15242d66e114b9121cb41cdd9961c9735934fedc Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Mon, 30 Dec 2019 12:00:53 -0500 Subject: [PATCH 3/3] wayland: Pass root coordinates for dnd events That is what the api currently requires, so provide it. This fixes DND to work again, for the most part. --- gdk/wayland/gdkdevice-wayland.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/gdk/wayland/gdkdevice-wayland.c b/gdk/wayland/gdkdevice-wayland.c index 3e3d4748b2..232948a2ba 100644 --- a/gdk/wayland/gdkdevice-wayland.c +++ b/gdk/wayland/gdkdevice-wayland.c @@ -1296,6 +1296,7 @@ data_device_motion (void *data, wl_fixed_t y) { GdkWaylandSeat *seat = data; + int origin_x, origin_y; GDK_DISPLAY_NOTE (seat->display, EVENTS, g_message ("data device motion, data_device = %p, time = %d, x = %f, y = %f", @@ -1308,10 +1309,12 @@ data_device_motion (void *data, seat->pointer_info.surface_x = wl_fixed_to_double (x); seat->pointer_info.surface_y = wl_fixed_to_double (y); + gdk_surface_get_origin (gdk_drop_get_surface (seat->drop), &origin_x, &origin_y); + gdk_drop_emit_motion_event (seat->drop, FALSE, - seat->pointer_info.surface_x, - seat->pointer_info.surface_y, + origin_x + seat->pointer_info.surface_x, + origin_y + seat->pointer_info.surface_y, time); } @@ -1320,14 +1323,17 @@ data_device_drop (void *data, struct wl_data_device *data_device) { GdkWaylandSeat *seat = data; + int origin_x, origin_y; GDK_DISPLAY_NOTE (seat->display, EVENTS, g_message ("data device drop, data device %p", data_device)); + gdk_surface_get_origin (gdk_drop_get_surface (seat->drop), &origin_x, &origin_y); + gdk_drop_emit_drop_event (seat->drop, FALSE, - seat->pointer_info.surface_x, - seat->pointer_info.surface_y, + origin_x + seat->pointer_info.surface_x, + origin_y + seat->pointer_info.surface_y, GDK_CURRENT_TIME); }