From a5ab9a9671a3ef7b34e88fdaab55736de4d2ee7c Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Sun, 19 Nov 2017 19:18:22 +0100 Subject: [PATCH] clipboard: Add gdk_clipboard_claim_remote() This allows the remote clipboard to take over. The X11 clipboard already does that. --- gdk/gdkclipboard.c | 22 ++++++++++++++++++++++ gdk/gdkclipboardprivate.h | 2 ++ gdk/x11/gdkclipboard-x11.c | 5 +++++ 3 files changed, 29 insertions(+) diff --git a/gdk/gdkclipboard.c b/gdk/gdkclipboard.c index caa73540fb..77862dd55b 100644 --- a/gdk/gdkclipboard.c +++ b/gdk/gdkclipboard.c @@ -188,6 +188,7 @@ gdk_clipboard_init (GdkClipboard *clipboard) GdkClipboardPrivate *priv = gdk_clipboard_get_instance_private (clipboard); priv->formats = gdk_content_formats_new (NULL, 0); + priv->local = TRUE; } /** @@ -233,3 +234,24 @@ gdk_clipboard_new (GdkDisplay *display) "display", display, NULL); } + +void +gdk_clipboard_claim_remote (GdkClipboard *clipboard, + GdkContentFormats *formats) +{ + GdkClipboardPrivate *priv = gdk_clipboard_get_instance_private (clipboard); + + g_return_if_fail (GDK_IS_CLIPBOARD (clipboard)); + g_return_if_fail (formats != NULL); + + gdk_content_formats_unref (priv->formats); + priv->formats = gdk_content_formats_ref (formats); + g_object_notify_by_pspec (G_OBJECT (clipboard), properties[PROP_FORMATS]); + if (priv->local) + { + priv->local = FALSE; + g_object_notify_by_pspec (G_OBJECT (clipboard), properties[PROP_LOCAL]); + } + + g_signal_emit (clipboard, signals[CHANGED], 0); +} diff --git a/gdk/gdkclipboardprivate.h b/gdk/gdkclipboardprivate.h index ac3f0b88c4..adc6c0ac02 100644 --- a/gdk/gdkclipboardprivate.h +++ b/gdk/gdkclipboardprivate.h @@ -45,6 +45,8 @@ struct _GdkClipboardClass GdkClipboard * gdk_clipboard_new (GdkDisplay *display); +void gdk_clipboard_claim_remote (GdkClipboard *clipboard, + GdkContentFormats *formats); G_END_DECLS diff --git a/gdk/x11/gdkclipboard-x11.c b/gdk/x11/gdkclipboard-x11.c index 4a90d8afb0..eb2f6d1645 100644 --- a/gdk/x11/gdkclipboard-x11.c +++ b/gdk/x11/gdkclipboard-x11.c @@ -115,9 +115,14 @@ gdk_x11_clipboard_request_targets_finish (GObject *source_object, { gdk_content_formats_builder_add_mime_type (builder, gdk_x11_get_xatom_name_for_display (display , atoms[i])); } + gdk_content_formats_builder_add_formats (builder, gdk_clipboard_get_formats (GDK_CLIPBOARD (cb))); formats = gdk_content_formats_builder_free (builder); GDK_NOTE(CLIPBOARD, char *s = gdk_content_formats_to_string (formats); g_printerr ("%s: got formats: %s\n", cb->selection, s); g_free (s)); + /* union with previously loaded formats */ + gdk_clipboard_claim_remote (GDK_CLIPBOARD (cb), formats); + gdk_content_formats_unref (formats); + g_input_stream_read_bytes_async (stream, SELECTION_MAX_SIZE (display), G_PRIORITY_DEFAULT,