[gnome-remote-desktop] clipboard: Add APIs for client-side clipboard handling



commit beb3d2738c3e691f129c8bb1582ba0e985ec9996
Author: Pascal Nowack <Pascal Nowack gmx de>
Date:   Sun Sep 27 10:45:05 2020 +0200

    clipboard: Add APIs for client-side clipboard handling
    
    Add APIs to submit a mime type lists to mutter, request the clipboard
    content for a mime type from mutter, and to enable or disable the
    clipboard.
    These APIs make use of the previously implemented APIs in grd-session.

 src/grd-clipboard.c | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/grd-clipboard.h | 14 +++++++++
 2 files changed, 98 insertions(+)
---
diff --git a/src/grd-clipboard.c b/src/grd-clipboard.c
index a8f87f8..8f2b55f 100644
--- a/src/grd-clipboard.c
+++ b/src/grd-clipboard.c
@@ -21,15 +21,99 @@
 
 #include "grd-clipboard.h"
 
+#include "grd-session.h"
+
 typedef struct _GrdClipboardPrivate
 {
   GrdSession *session;
 
+  gboolean enabled;
+
   GHashTable *client_mime_type_tables;
 } GrdClipboardPrivate;
 
 G_DEFINE_TYPE_WITH_PRIVATE (GrdClipboard, grd_clipboard, G_TYPE_OBJECT);
 
+void
+grd_clipboard_update_server_mime_type_list (GrdClipboard *clipboard,
+                                            GList        *mime_type_tables)
+{
+  GrdClipboardPrivate *priv = grd_clipboard_get_instance_private (clipboard);
+  GList *l;
+
+  for (l = mime_type_tables; l; l = l->next)
+    {
+      GrdMimeTypeTable *mime_type_table = l->data;
+      GrdMimeType mime_type;
+
+      mime_type = mime_type_table->mime_type;
+      g_hash_table_insert (priv->client_mime_type_tables,
+                           GUINT_TO_POINTER (mime_type), mime_type_table);
+    }
+
+  if (!priv->enabled)
+    {
+      priv->enabled = grd_session_enable_clipboard (priv->session,
+                                                    clipboard, mime_type_tables);
+    }
+  else
+    {
+      if (mime_type_tables)
+        grd_session_set_selection (priv->session, mime_type_tables);
+    }
+
+  g_list_free (mime_type_tables);
+}
+
+uint8_t *
+grd_clipboard_request_server_content_for_mime_type (GrdClipboard *clipboard,
+                                                    GrdMimeType   mime_type,
+                                                    uint32_t     *size)
+{
+  GrdClipboardPrivate *priv = grd_clipboard_get_instance_private (clipboard);
+  uint8_t *data;
+
+  *size = 0;
+  if (!priv->enabled)
+    return NULL;
+
+  data = grd_session_selection_read (priv->session, mime_type, size);
+
+  return data;
+}
+
+void
+grd_clipboard_initialize (GrdClipboard *clipboard,
+                          GrdSession   *session)
+{
+  GrdClipboardPrivate *priv = grd_clipboard_get_instance_private (clipboard);
+
+  priv->session = session;
+}
+
+void
+grd_clipboard_maybe_enable_clipboard (GrdClipboard *clipboard)
+{
+  GrdClipboardPrivate *priv = grd_clipboard_get_instance_private (clipboard);
+
+  if (priv->enabled)
+    return;
+
+  priv->enabled = grd_session_enable_clipboard (priv->session, clipboard, NULL);
+}
+
+void
+grd_clipboard_disable_clipboard (GrdClipboard *clipboard)
+{
+  GrdClipboardPrivate *priv = grd_clipboard_get_instance_private (clipboard);
+
+  if (!priv->enabled)
+    return;
+
+  grd_session_disable_clipboard (priv->session);
+  priv->enabled = FALSE;
+}
+
 void
 grd_clipboard_update_client_mime_type_list (GrdClipboard *clipboard,
                                             GList        *mime_type_list)
diff --git a/src/grd-clipboard.h b/src/grd-clipboard.h
index c77746e..2e38d24 100644
--- a/src/grd-clipboard.h
+++ b/src/grd-clipboard.h
@@ -40,6 +40,20 @@ struct _GrdClipboardClass
                                                     uint32_t         *size);
 };
 
+void grd_clipboard_update_server_mime_type_list (GrdClipboard *clipboard,
+                                                 GList        *mime_type_tables);
+
+uint8_t *grd_clipboard_request_server_content_for_mime_type (GrdClipboard *clipboard,
+                                                             GrdMimeType   mime_type,
+                                                             uint32_t     *size);
+
+void grd_clipboard_initialize (GrdClipboard *clipboard,
+                               GrdSession   *session);
+
+void grd_clipboard_maybe_enable_clipboard (GrdClipboard *clipboard);
+
+void grd_clipboard_disable_clipboard (GrdClipboard *clipboard);
+
 void grd_clipboard_update_client_mime_type_list (GrdClipboard *clipboard,
                                                  GList        *mime_type_list);
 


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