[gtk+] gdk/dnd: Don't use default display when getting cursor



commit 1a4f000f3b2a3289c6bcd30b7ce259c1686ef169
Author: Jonas Ådahl <jadahl gmail com>
Date:   Tue Apr 26 15:31:33 2016 +0800

    gdk/dnd: Don't use default display when getting cursor
    
    Always associate a drag context with a GdkDisplay and use that when
    getting a cursor for a given action.
    
    If we don't do this, dragging on a window that doesn't use the default
    display will make us use cursors from the wrong display.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=765565

 gdk/broadway/gdkdnd-broadway.c   |    1 +
 gdk/gdkdnd.c                     |    5 +++--
 gdk/gdkdndprivate.h              |    5 ++++-
 gdk/quartz/GdkQuartzNSWindow.c   |    2 ++
 gdk/quartz/gdkdnd-quartz.c       |    1 +
 gdk/wayland/gdkdevice-wayland.c  |    3 ++-
 gdk/wayland/gdkdnd-wayland.c     |    7 +++++--
 gdk/wayland/gdkprivate-wayland.h |    3 ++-
 gdk/win32/gdkdnd-win32.c         |    1 +
 gdk/x11/gdkdnd-x11.c             |    4 +++-
 10 files changed, 24 insertions(+), 8 deletions(-)
---
diff --git a/gdk/broadway/gdkdnd-broadway.c b/gdk/broadway/gdkdnd-broadway.c
index 042a0cd..7c5fffe 100644
--- a/gdk/broadway/gdkdnd-broadway.c
+++ b/gdk/broadway/gdkdnd-broadway.c
@@ -98,6 +98,7 @@ _gdk_broadway_window_drag_begin (GdkWindow *window,
 
   new_context = g_object_new (GDK_TYPE_BROADWAY_DRAG_CONTEXT,
                              NULL);
+  new_context->display = gdk_window_get_display (window);
 
   return new_context;
 }
diff --git a/gdk/gdkdnd.c b/gdk/gdkdnd.c
index a1e52c2..163a705 100644
--- a/gdk/gdkdnd.c
+++ b/gdk/gdkdnd.c
@@ -753,7 +753,8 @@ gdk_drag_context_handle_source_event (GdkEvent *event)
 }
 
 GdkCursor *
-gdk_drag_get_cursor (GdkDragAction action)
+gdk_drag_get_cursor (GdkDragContext *context,
+                     GdkDragAction   action)
 {
   gint i;
 
@@ -762,7 +763,7 @@ gdk_drag_get_cursor (GdkDragAction action)
       break;
 
   if (drag_cursors[i].cursor == NULL)
-    drag_cursors[i].cursor = gdk_cursor_new_from_name (gdk_display_get_default (),
+    drag_cursors[i].cursor = gdk_cursor_new_from_name (context->display,
                                                        drag_cursors[i].name);
   return drag_cursors[i].cursor;
 }
diff --git a/gdk/gdkdndprivate.h b/gdk/gdkdndprivate.h
index 283dba2..d37ec67 100644
--- a/gdk/gdkdndprivate.h
+++ b/gdk/gdkdndprivate.h
@@ -94,6 +94,8 @@ struct _GdkDragContext {
   /*< private >*/
   GdkDragProtocol protocol;
 
+  GdkDisplay *display;
+
   gboolean is_source;
   GdkWindow *source_window;
   GdkWindow *dest_window;
@@ -119,7 +121,8 @@ void     gdk_drag_context_cancel              (GdkDragContext      *context,
                                                GdkDragCancelReason  reason);
 gboolean gdk_drag_context_handle_source_event (GdkEvent *event);
 gboolean gdk_drag_context_handle_dest_event   (GdkEvent *event);
-GdkCursor * gdk_drag_get_cursor (GdkDragAction action);
+GdkCursor * gdk_drag_get_cursor               (GdkDragContext *context,
+                                               GdkDragAction   action);
 
 G_END_DECLS
 
diff --git a/gdk/quartz/GdkQuartzNSWindow.c b/gdk/quartz/GdkQuartzNSWindow.c
index e45c632..5a99411 100644
--- a/gdk/quartz/GdkQuartzNSWindow.c
+++ b/gdk/quartz/GdkQuartzNSWindow.c
@@ -587,6 +587,8 @@ update_context_from_dragging_info (id <NSDraggingInfo> sender)
 
   window = [[self contentView] gdkWindow];
 
+  current_context->display = gdk_window_get_display (window);
+
   device_manager = gdk_display_get_device_manager (gdk_display_get_default ());
   gdk_drag_context_set_device (current_context,
                                gdk_device_manager_get_client_pointer (device_manager));
diff --git a/gdk/quartz/gdkdnd-quartz.c b/gdk/quartz/gdkdnd-quartz.c
index 0a38cd8..15b6fed 100644
--- a/gdk/quartz/gdkdnd-quartz.c
+++ b/gdk/quartz/gdkdnd-quartz.c
@@ -44,6 +44,7 @@ _gdk_quartz_window_drag_begin (GdkWindow *window,
   /* Create fake context */
   _gdk_quartz_drag_source_context = g_object_new (GDK_TYPE_QUARTZ_DRAG_CONTEXT,
                                                   NULL);
+  _gdk_quartz_drag_source_context->display = gdk_window_get_display (window);
   _gdk_quartz_drag_source_context->is_source = TRUE;
 
   _gdk_quartz_drag_source_context->source_window = window;
diff --git a/gdk/wayland/gdkdevice-wayland.c b/gdk/wayland/gdkdevice-wayland.c
index c220d2b..e3f7fac 100644
--- a/gdk/wayland/gdkdevice-wayland.c
+++ b/gdk/wayland/gdkdevice-wayland.c
@@ -3988,7 +3988,8 @@ _gdk_wayland_device_manager_add_seat (GdkDeviceManager *device_manager,
   seat->data_device =
     wl_data_device_manager_get_data_device (display_wayland->data_device_manager,
                                             seat->wl_seat);
-  seat->drop_context = _gdk_wayland_drop_context_new (seat->data_device);
+  seat->drop_context = _gdk_wayland_drop_context_new (display,
+                                                      seat->data_device);
   wl_data_device_add_listener (seat->data_device,
                                &data_device_listener, seat);
 
diff --git a/gdk/wayland/gdkdnd-wayland.c b/gdk/wayland/gdkdnd-wayland.c
index 7bb0c61..adc33a4 100644
--- a/gdk/wayland/gdkdnd-wayland.c
+++ b/gdk/wayland/gdkdnd-wayland.c
@@ -427,7 +427,7 @@ gdk_wayland_drag_context_action_changed (GdkDragContext *context,
 {
   GdkCursor *cursor;
 
-  cursor = gdk_drag_get_cursor (action);
+  cursor = gdk_drag_get_cursor (context, action);
   gdk_drag_context_set_cursor (context, cursor);
 }
 
@@ -528,6 +528,7 @@ _gdk_wayland_window_drag_begin (GdkWindow *window,
 
   context_wayland = g_object_new (GDK_TYPE_WAYLAND_DRAG_CONTEXT, NULL);
   context = GDK_DRAG_CONTEXT (context_wayland);
+  context->display = gdk_window_get_display (window);
   context->source_window = g_object_ref (window);
   context->is_source = TRUE;
   context->targets = g_list_copy (targets);
@@ -552,13 +553,15 @@ _gdk_wayland_window_drag_begin (GdkWindow *window,
 }
 
 GdkDragContext *
-_gdk_wayland_drop_context_new (struct wl_data_device *data_device)
+_gdk_wayland_drop_context_new (GdkDisplay            *display,
+                               struct wl_data_device *data_device)
 {
   GdkWaylandDragContext *context_wayland;
   GdkDragContext *context;
 
   context_wayland = g_object_new (GDK_TYPE_WAYLAND_DRAG_CONTEXT, NULL);
   context = GDK_DRAG_CONTEXT (context_wayland);
+  context->display = display;
   context->is_source = FALSE;
 
   return context;
diff --git a/gdk/wayland/gdkprivate-wayland.h b/gdk/wayland/gdkprivate-wayland.h
index eb93047..81770f6 100644
--- a/gdk/wayland/gdkprivate-wayland.h
+++ b/gdk/wayland/gdkprivate-wayland.h
@@ -109,7 +109,8 @@ GdkDragContext *_gdk_wayland_window_drag_begin (GdkWindow *window,
 void            _gdk_wayland_window_offset_next_wl_buffer (GdkWindow *window,
                                                            int        x,
                                                            int        y);
-GdkDragContext * _gdk_wayland_drop_context_new (struct wl_data_device *data_device);
+GdkDragContext * _gdk_wayland_drop_context_new (GdkDisplay            *display,
+                                                struct wl_data_device *data_device);
 void _gdk_wayland_drag_context_set_source_window (GdkDragContext *context,
                                                   GdkWindow      *window);
 void _gdk_wayland_drag_context_set_dest_window (GdkDragContext *context,
diff --git a/gdk/win32/gdkdnd-win32.c b/gdk/win32/gdkdnd-win32.c
index d012463..cec3dcc 100644
--- a/gdk/win32/gdkdnd-win32.c
+++ b/gdk/win32/gdkdnd-win32.c
@@ -182,6 +182,7 @@ gdk_drag_context_new (GdkDisplay *display)
 
   context_win32 = g_object_new (GDK_TYPE_WIN32_DRAG_CONTEXT, NULL);
   context = GDK_DRAG_CONTEXT(context_win32);
+  context->display = display;
 
   gdk_drag_context_set_device (context, gdk_seat_get_pointer (gdk_display_get_default_seat (display)));
 
diff --git a/gdk/x11/gdkdnd-x11.c b/gdk/x11/gdkdnd-x11.c
index c2a6919..3d25ea2 100644
--- a/gdk/x11/gdkdnd-x11.c
+++ b/gdk/x11/gdkdnd-x11.c
@@ -1705,6 +1705,7 @@ xdnd_enter_filter (GdkXEvent *xev,
   context_x11 = (GdkX11DragContext *)g_object_new (GDK_TYPE_X11_DRAG_CONTEXT, NULL);
   context = (GdkDragContext *)context_x11;
 
+  context->display = display;
   context->protocol = GDK_DRAG_PROTO_XDND;
   context_x11->version = version;
 
@@ -2020,6 +2021,7 @@ _gdk_x11_window_drag_begin (GdkWindow *window,
 
   context = (GdkDragContext *) g_object_new (GDK_TYPE_X11_DRAG_CONTEXT, NULL);
 
+  context->display = gdk_window_get_display (window);
   context->is_source = TRUE;
   context->source_window = window;
   g_object_ref (window);
@@ -3132,6 +3134,6 @@ gdk_x11_drag_context_action_changed (GdkDragContext *context,
 {
   GdkCursor *cursor;
 
-  cursor = gdk_drag_get_cursor (action);
+  cursor = gdk_drag_get_cursor (context, action);
   gdk_drag_context_set_cursor (context, cursor);
 }


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