[gtk+/wip/otte/clipboard: 84/117] clipboard: Add gdk_clipboard_claim_remote()



commit ae4d948af32abb78b457e4a93444650e2166840d
Author: Benjamin Otte <otte redhat com>
Date:   Sun Nov 19 19:18:22 2017 +0100

    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(+), 0 deletions(-)
---
diff --git a/gdk/gdkclipboard.c b/gdk/gdkclipboard.c
index caa7354..77862dd 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 ac3f0b8..adc6c0a 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 4a90d8a..eb2f6d1 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,


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