From c40ba85ace2869f770d1b48552c9f134065f4e03 Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Mon, 27 Oct 2014 21:44:48 -0700 Subject: [PATCH] wayland: Don't use the default display Pass a display in so that multi-display technology works. --- gdk/wayland/gdkdevice-wayland.c | 13 +++++++----- gdk/wayland/gdkdnd-wayland.c | 25 ++++++++++++---------- gdk/wayland/gdkprivate-wayland.h | 9 ++++---- gdk/wayland/gdkselection-wayland.c | 34 ++++++++++++++---------------- gdk/wayland/gdkwaylandselection.h | 2 +- gtk/gtkselection.c | 2 +- 6 files changed, 45 insertions(+), 40 deletions(-) diff --git a/gdk/wayland/gdkdevice-wayland.c b/gdk/wayland/gdkdevice-wayland.c index bc52fb127b..6716c01b69 100644 --- a/gdk/wayland/gdkdevice-wayland.c +++ b/gdk/wayland/gdkdevice-wayland.c @@ -543,7 +543,8 @@ data_device_data_offer (void *data, struct wl_data_device *data_device, struct wl_data_offer *_offer) { - gdk_wayland_selection_set_offer (_offer); + GdkWaylandDeviceData *device = (GdkWaylandDeviceData *)data; + gdk_wayland_selection_set_offer (device->display, _offer); } static void @@ -573,7 +574,7 @@ data_device_enter (void *data, gdk_wayland_drop_context_update_targets (device->drop_context); - dnd_owner = gdk_selection_owner_get (gdk_drag_get_selection (device->drop_context)); + dnd_owner = gdk_selection_owner_get_for_display (device->display, gdk_drag_get_selection (device->drop_context)); if (dnd_owner) _gdk_wayland_drag_context_set_source_window (device->drop_context, dnd_owner); @@ -585,7 +586,7 @@ data_device_enter (void *data, wl_fixed_to_double (y)); _gdk_wayland_drag_context_emit_event (device->drop_context, GDK_DRAG_ENTER, GDK_CURRENT_TIME); - gdk_wayland_selection_set_offer (offer); + gdk_wayland_selection_set_offer (device->display, offer); } static void @@ -645,7 +646,7 @@ data_device_drop (void *data, g_debug (G_STRLOC ": %s data_device = %p", G_STRFUNC, data_device); - local_dnd_owner = gdk_selection_owner_get (gdk_drag_get_selection (device->drop_context)); + local_dnd_owner = gdk_selection_owner_get_for_display (device->display, gdk_drag_get_selection (device->drop_context)); if (local_dnd_owner) { @@ -664,10 +665,12 @@ data_device_selection (void *data, struct wl_data_device *wl_data_device, struct wl_data_offer *offer) { + GdkWaylandDeviceData *device = (GdkWaylandDeviceData *) data; + g_debug (G_STRLOC ": %s wl_data_device = %p wl_data_offer = %p", G_STRFUNC, wl_data_device, offer); - gdk_wayland_selection_set_offer (offer); + gdk_wayland_selection_set_offer (device->display, offer); } static const struct wl_data_device_listener data_device_listener = { diff --git a/gdk/wayland/gdkdnd-wayland.c b/gdk/wayland/gdkdnd-wayland.c index e04e1ce24a..141434d6e7 100644 --- a/gdk/wayland/gdkdnd-wayland.c +++ b/gdk/wayland/gdkdnd-wayland.c @@ -65,12 +65,13 @@ gdk_wayland_drag_context_finalize (GObject *object) { GdkWaylandDragContext *wayland_context = GDK_WAYLAND_DRAG_CONTEXT (object); GdkDragContext *context = GDK_DRAG_CONTEXT (object); + GdkDisplay *display = gdk_window_get_display (context->source_window); contexts = g_list_remove (contexts, context); if (context->is_source && - gdk_selection_owner_get (gdk_drag_get_selection (context)) == context->source_window) - gdk_wayland_selection_unset_data_source (gdk_drag_get_selection (context)); + gdk_selection_owner_get_for_display (display, gdk_drag_get_selection (context)) == context->source_window) + gdk_wayland_selection_unset_data_source (display, gdk_drag_get_selection (context)); if (wayland_context->data_source) wl_data_source_destroy (wayland_context->data_source); @@ -191,10 +192,12 @@ gdk_wayland_drop_context_set_status (GdkDragContext *context, gboolean accepted) { GdkWaylandDragContext *context_wayland; + GdkDisplay *display; struct wl_data_offer *wl_offer; context_wayland = GDK_WAYLAND_DRAG_CONTEXT (context); - wl_offer = gdk_wayland_selection_get_offer (); + display = gdk_window_get_display (context->source_window); + wl_offer = gdk_wayland_selection_get_offer (display); if (!wl_offer) return; @@ -241,8 +244,10 @@ gdk_wayland_drag_context_drop_finish (GdkDragContext *context, gboolean success, guint32 time) { - if (gdk_selection_owner_get (gdk_drag_get_selection (context))) - gdk_wayland_selection_unset_data_source (gdk_drag_get_selection (context)); + GdkDisplay *display = gdk_window_get_display (context->source_window); + + if (gdk_selection_owner_get_for_display (display, gdk_drag_get_selection (context))) + gdk_wayland_selection_unset_data_source (display, gdk_drag_get_selection (context)); } static gboolean @@ -301,14 +306,11 @@ _gdk_wayland_window_register_dnd (GdkWindow *window) } static GdkWindow * -create_dnd_window (void) +create_dnd_window (GdkScreen *screen) { GdkWindowAttr attrs; - GdkScreen *screen; guint mask; - screen = gdk_display_get_default_screen (gdk_display_get_default ()); - attrs.x = attrs.y = 0; attrs.width = attrs.height = 100; attrs.wclass = GDK_INPUT_OUTPUT; @@ -343,7 +345,7 @@ _gdk_wayland_window_drag_begin (GdkWindow *window, gdk_drag_context_set_device (context, device); display_wayland = GDK_WAYLAND_DISPLAY (gdk_device_get_display (device)); - context_wayland->dnd_window = create_dnd_window (); + context_wayland->dnd_window = create_dnd_window (gdk_window_get_screen (window)); context_wayland->dnd_surface = gdk_wayland_window_get_wl_surface (context_wayland->dnd_window); context_wayland->data_source = gdk_wayland_selection_get_data_source (window, @@ -380,8 +382,9 @@ _gdk_wayland_drop_context_new (GdkDevice *device, void gdk_wayland_drop_context_update_targets (GdkDragContext *context) { + GdkDisplay *display = gdk_window_get_display (context->source_window); g_list_free (context->targets); - context->targets = g_list_copy (gdk_wayland_selection_get_targets ()); + context->targets = g_list_copy (gdk_wayland_selection_get_targets (display)); } void diff --git a/gdk/wayland/gdkprivate-wayland.h b/gdk/wayland/gdkprivate-wayland.h index 4f6f15b378..adfff19fab 100644 --- a/gdk/wayland/gdkprivate-wayland.h +++ b/gdk/wayland/gdkprivate-wayland.h @@ -224,9 +224,10 @@ GdkWaylandSelection * gdk_wayland_display_get_selection (GdkDisplay *display); GdkWaylandSelection * gdk_wayland_selection_new (void); void gdk_wayland_selection_free (GdkWaylandSelection *selection); -void gdk_wayland_selection_set_offer (struct wl_data_offer *offer); -struct wl_data_offer * gdk_wayland_selection_get_offer (void); -GList * gdk_wayland_selection_get_targets (void); +void gdk_wayland_selection_set_offer (GdkDisplay *display, + struct wl_data_offer *wl_offer); +struct wl_data_offer * gdk_wayland_selection_get_offer (GdkDisplay *display); +GList * gdk_wayland_selection_get_targets (GdkDisplay *display); void gdk_wayland_selection_store (GdkWindow *window, GdkAtom type, @@ -235,7 +236,7 @@ void gdk_wayland_selection_store (GdkWindow *window, gint len); struct wl_data_source * gdk_wayland_selection_get_data_source (GdkWindow *owner, GdkAtom selection); -void gdk_wayland_selection_unset_data_source (GdkAtom selection); +void gdk_wayland_selection_unset_data_source (GdkDisplay *display, GdkAtom selection); EGLSurface gdk_wayland_window_get_egl_surface (GdkWindow *window, EGLConfig config); diff --git a/gdk/wayland/gdkselection-wayland.c b/gdk/wayland/gdkselection-wayland.c index 52d85352b0..6fdec8f7a6 100644 --- a/gdk/wayland/gdkselection-wayland.c +++ b/gdk/wayland/gdkselection-wayland.c @@ -26,6 +26,7 @@ #include "gdkwayland.h" #include "gdkprivate-wayland.h" #include "gdkdisplay-wayland.h" +#include "gdkdndprivate.h" #include "gdkselection.h" #include "gdkproperty.h" #include "gdkprivate.h" @@ -320,9 +321,9 @@ static const struct wl_data_offer_listener data_offer_listener = { }; void -gdk_wayland_selection_set_offer (struct wl_data_offer *wl_offer) +gdk_wayland_selection_set_offer (GdkDisplay *display, + struct wl_data_offer *wl_offer) { - GdkDisplay *display = gdk_display_get_default (); GdkWaylandSelection *selection = gdk_wayland_display_get_selection (display); if (selection->offer == wl_offer) @@ -345,18 +346,16 @@ gdk_wayland_selection_set_offer (struct wl_data_offer *wl_offer) } struct wl_data_offer * -gdk_wayland_selection_get_offer (void) +gdk_wayland_selection_get_offer (GdkDisplay *display) { - GdkDisplay *display = gdk_display_get_default (); GdkWaylandSelection *selection = gdk_wayland_display_get_selection (display); return selection->offer; } GList * -gdk_wayland_selection_get_targets (void) +gdk_wayland_selection_get_targets (GdkDisplay *display) { - GdkDisplay *display = gdk_display_get_default (); GdkWaylandSelection *selection = gdk_wayland_display_get_selection (display); return selection->targets; @@ -476,7 +475,7 @@ gdk_wayland_selection_store (GdkWindow *window, const guchar *data, gint len) { - GdkDisplay *display = gdk_display_get_default (); + GdkDisplay *display = gdk_window_get_display (window); GdkWaylandSelection *selection = gdk_wayland_display_get_selection (display); GArray *array; @@ -526,7 +525,7 @@ gdk_wayland_selection_store (GdkWindow *window, static SelectionBuffer * gdk_wayland_selection_lookup_requestor_buffer (GdkWindow *requestor) { - GdkDisplay *display = gdk_display_get_default (); + GdkDisplay *display = gdk_window_get_display (requestor); GdkWaylandSelection *selection = gdk_wayland_display_get_selection (display); SelectionBuffer *buffer_data; GHashTableIter iter; @@ -662,16 +661,18 @@ data_source_cancelled (void *data, { GdkWaylandSelection *wayland_selection = data; GdkDragContext *context; + GdkDisplay *display; g_debug (G_STRLOC ": %s source = %p", G_STRFUNC, source); context = gdk_wayland_drag_context_lookup_by_data_source (source); + display = gdk_window_get_display (context->source_window); if (source == wayland_selection->dnd_source) - gdk_wayland_selection_unset_data_source (atoms[ATOM_DND]); + gdk_wayland_selection_unset_data_source (display, atoms[ATOM_DND]); else if (source == wayland_selection->clipboard_source) - gdk_wayland_selection_unset_data_source (atoms[ATOM_CLIPBOARD]); + gdk_wayland_selection_unset_data_source (display, atoms[ATOM_CLIPBOARD]); if (context) gdk_wayland_drag_context_undo_grab (context); @@ -687,7 +688,7 @@ struct wl_data_source * gdk_wayland_selection_get_data_source (GdkWindow *owner, GdkAtom selection) { - GdkDisplay *display = gdk_display_get_default (); + GdkDisplay *display = gdk_window_get_display (owner); GdkWaylandSelection *wayland_selection = gdk_wayland_display_get_selection (display); struct wl_data_source *source = NULL; GdkWaylandDisplay *display_wayland; @@ -741,18 +742,15 @@ gdk_wayland_selection_get_data_source (GdkWindow *owner, } void -gdk_wayland_selection_unset_data_source (GdkAtom selection) +gdk_wayland_selection_unset_data_source (GdkDisplay *display, GdkAtom selection) { - GdkDisplay *display = gdk_display_get_default (); GdkWaylandSelection *wayland_selection = gdk_wayland_display_get_selection (display); if (selection == atoms[ATOM_CLIPBOARD]) { GdkDeviceManager *device_manager; - GdkDisplay *display; GdkDevice *device; - display = gdk_display_get_default (); device_manager = gdk_display_get_device_manager (display); device = gdk_device_manager_get_client_pointer (device_manager); @@ -1023,7 +1021,7 @@ gdk_wayland_selection_add_targets (GdkWindow *window, GdkDisplay *display; GdkDevice *device; - display = gdk_display_get_default (); + display = gdk_window_get_display (window); device_manager = gdk_display_get_device_manager (display); device = gdk_device_manager_get_client_pointer (device_manager); gdk_wayland_device_set_selection (device, data_source); @@ -1031,7 +1029,7 @@ gdk_wayland_selection_add_targets (GdkWindow *window, } void -gdk_wayland_selection_clear_targets (GdkAtom selection) +gdk_wayland_selection_clear_targets (GdkDisplay *display, GdkAtom selection) { - gdk_wayland_selection_unset_data_source (selection); + gdk_wayland_selection_unset_data_source (display, selection); } diff --git a/gdk/wayland/gdkwaylandselection.h b/gdk/wayland/gdkwaylandselection.h index a9d42cc6c8..bc58102b3e 100644 --- a/gdk/wayland/gdkwaylandselection.h +++ b/gdk/wayland/gdkwaylandselection.h @@ -45,7 +45,7 @@ gdk_wayland_selection_add_targets (GdkWindow *window, #define gdk_wayland_selection_clear_targets gdk_wayland_selection_clear_targets_libgtk_only GDK_AVAILABLE_IN_ALL void -gdk_wayland_selection_clear_targets (GdkAtom selection); +gdk_wayland_selection_clear_targets (GdkDisplay *display, GdkAtom selection); #define gdk_wayland_drag_context_get_dnd_window gdk_wayland_drag_context_get_dnd_window_libgtk_only GDK_AVAILABLE_IN_ALL diff --git a/gtk/gtkselection.c b/gtk/gtkselection.c index 2adba2e892..9ad905bdbc 100644 --- a/gtk/gtkselection.c +++ b/gtk/gtkselection.c @@ -885,7 +885,7 @@ gtk_selection_clear_targets (GtkWidget *widget, #ifdef GDK_WINDOWING_WAYLAND if (GDK_IS_WAYLAND_DISPLAY (gtk_widget_get_display (widget))) - gdk_wayland_selection_clear_targets (selection); + gdk_wayland_selection_clear_targets (gtk_widget_get_display (widget), selection); #endif lists = g_object_get_data (G_OBJECT (widget), gtk_selection_handler_key);