[gtk/wip/otte/dnd: 67/70] gdk: Make DRAG_ENTER event take x/y coordinates



commit e7db0a6187e5670b80e08444ad0614964538f063
Author: Benjamin Otte <otte redhat com>
Date:   Wed Feb 19 03:37:23 2020 +0100

    gdk: Make DRAG_ENTER event take x/y coordinates
    
    Make it mirror the behavior of ENTER/LEAVE events.

 gdk/gdkdrop.c                   |  2 ++
 gdk/gdkdropprivate.h            |  2 ++
 gdk/wayland/gdkdevice-wayland.c |  5 +++++
 gdk/win32/gdkdrop-win32.c       |  3 +--
 gdk/x11/gdkdrop-x11.c           | 16 ++++++++++++----
 gtk/gtkdragdest.c               |  4 +---
 gtk/gtkmain.c                   |  2 +-
 7 files changed, 24 insertions(+), 10 deletions(-)
---
diff --git a/gdk/gdkdrop.c b/gdk/gdkdrop.c
index 6d40b79d93..b491eebfdb 100644
--- a/gdk/gdkdrop.c
+++ b/gdk/gdkdrop.c
@@ -962,6 +962,8 @@ gdk_drop_do_emit_event (GdkEvent *event,
 void
 gdk_drop_emit_enter_event (GdkDrop  *self,
                            gboolean  dont_queue,
+                           double    x,
+                           double    y,
                            guint32   time)
 {
   GdkDropPrivate *priv = gdk_drop_get_instance_private (self);
diff --git a/gdk/gdkdropprivate.h b/gdk/gdkdropprivate.h
index 5836c89b78..82b5e41945 100644
--- a/gdk/gdkdropprivate.h
+++ b/gdk/gdkdropprivate.h
@@ -61,6 +61,8 @@ void                    gdk_drop_set_actions                    (GdkDrop
 
 void                    gdk_drop_emit_enter_event               (GdkDrop                *self,
                                                                  gboolean                dont_queue,
+                                                                 double                  x,
+                                                                 double                  y,
                                                                  guint32                 time);
 void                    gdk_drop_emit_motion_event              (GdkDrop                *self,
                                                                  gboolean                dont_queue,
diff --git a/gdk/wayland/gdkdevice-wayland.c b/gdk/wayland/gdkdevice-wayland.c
index 72fc22d75e..b948b895c7 100644
--- a/gdk/wayland/gdkdevice-wayland.c
+++ b/gdk/wayland/gdkdevice-wayland.c
@@ -1201,6 +1201,7 @@ data_device_enter (void                  *data,
   GdkWaylandSeat *seat = data;
   GdkSurface *dest_surface;
   GdkContentFormats *formats;
+  int origin_x, origin_y;
   GdkDevice *device;
 
   dest_surface = wl_surface_get_user_data (surface);
@@ -1245,8 +1246,12 @@ data_device_enter (void                  *data,
 
   gdk_wayland_seat_discard_pending_offer (seat);
 
+  gdk_surface_get_origin (gdk_drop_get_surface (seat->drop), &origin_x, &origin_y);
+
   gdk_drop_emit_enter_event (seat->drop,
                              FALSE,
+                             origin_x + seat->pointer_info.surface_x,
+                             origin_y + seat->pointer_info.surface_y,
                              GDK_CURRENT_TIME);
 }
 
diff --git a/gdk/win32/gdkdrop-win32.c b/gdk/win32/gdkdrop-win32.c
index 6ad6615442..8dbe3b1072 100644
--- a/gdk/win32/gdkdrop-win32.c
+++ b/gdk/win32/gdkdrop-win32.c
@@ -487,8 +487,7 @@ _gdk_win32_local_drop_target_dragenter (GdkDrag        *drag,
 
   source_actions = set_source_actions_helper (drop, *actions, grfKeyState);
 
-  gdk_drop_emit_enter_event (drop, TRUE, time_);
-  gdk_drop_emit_motion_event (drop, TRUE, x_root, y_root, time_);
+  gdk_drop_emit_enter_event (drop, TRUE, x_root, y_root, time_);
   drop_win32->last_key_state = grfKeyState;
   drop_win32->last_x = x_root;
   drop_win32->last_y = y_root;
diff --git a/gdk/x11/gdkdrop-x11.c b/gdk/x11/gdkdrop-x11.c
index 4eb24d154f..767adac7ab 100644
--- a/gdk/x11/gdkdrop-x11.c
+++ b/gdk/x11/gdkdrop-x11.c
@@ -70,6 +70,7 @@ struct _GdkX11Drop
 
   guint xdnd_targets_set  : 1; /* Whether we've already set XdndTypeList */
   guint xdnd_have_actions : 1; /* Whether an XdndActionList was provided */
+  guint enter_emitted     : 1; /* Set after gdk_drop_emit_enter() */
 };
 
 struct _GdkX11DropClass
@@ -582,8 +583,6 @@ xdnd_enter_filter (GdkSurface   *surface,
 
   display_x11->current_drop = drop;
 
-  gdk_drop_emit_enter_event (drop, FALSE, GDK_CURRENT_TIME);
-
   gdk_content_formats_unref (content_formats);
 
   return TRUE;
@@ -609,7 +608,8 @@ xdnd_leave_filter (GdkSurface   *surface,
   if ((display_x11->current_drop != NULL) &&
       (GDK_X11_DROP (display_x11->current_drop)->source_window == source_window))
     {
-      gdk_drop_emit_leave_event (display_x11->current_drop, FALSE, GDK_CURRENT_TIME);
+      if (GDK_X11_DROP (display_x11->current_drop)->enter_emitted)
+        gdk_drop_emit_leave_event (display_x11->current_drop, FALSE, GDK_CURRENT_TIME);
 
       g_clear_object (&display_x11->current_drop);
     }
@@ -656,7 +656,15 @@ xdnd_position_filter (GdkSurface   *surface,
       drop_x11->last_x = x_root / impl->surface_scale;
       drop_x11->last_y = y_root / impl->surface_scale;
 
-      gdk_drop_emit_motion_event (drop, FALSE, drop_x11->last_x - surface->x, drop_x11->last_y - surface->y, 
time);
+      if (drop_x11->enter_emitted)
+        {
+          gdk_drop_emit_motion_event (drop, FALSE, drop_x11->last_x - surface->x, drop_x11->last_y - 
surface->y, time);
+        }
+      else
+        {
+          gdk_drop_emit_enter_event (drop, FALSE, drop_x11->last_x - surface->x, drop_x11->last_y - 
surface->y, time);
+          drop_x11->enter_emitted = TRUE;
+        }
     }
 
   return TRUE;
diff --git a/gtk/gtkdragdest.c b/gtk/gtkdragdest.c
index 51dcf37c96..8742dc6e8a 100644
--- a/gtk/gtkdragdest.c
+++ b/gtk/gtkdragdest.c
@@ -822,13 +822,11 @@ gtk_drag_dest_handle_event (GtkWidget *toplevel,
 
   switch ((guint) event_type)
     {
-    case GDK_DRAG_ENTER:
-      break;
-
     case GDK_DRAG_LEAVE:
       gtk_drop_set_current_dest (drop, NULL);
       break;
 
+    case GDK_DRAG_ENTER:
     case GDK_DRAG_MOTION:
     case GDK_DROP_START:
       gtk_drop_set_current_dest (drop, NULL);
diff --git a/gtk/gtkmain.c b/gtk/gtkmain.c
index 21ea620b7e..c31ae27796 100644
--- a/gtk/gtkmain.c
+++ b/gtk/gtkmain.c
@@ -1760,13 +1760,13 @@ gtk_main_do_event (GdkEvent *event)
       /* Crossing event propagation happens during picking */
       break;
 
+    case GDK_DRAG_ENTER:
     case GDK_DRAG_MOTION:
     case GDK_DROP_START:
       if (gtk_propagate_event (target_widget, event))
         break;
       G_GNUC_FALLTHROUGH;
 
-    case GDK_DRAG_ENTER:
     case GDK_DRAG_LEAVE:
       gtk_drag_dest_handle_event (target_widget, event);
       break;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]