[gtk/wip/carlosg/translate-string-selections] wayland: Translate STRING/UTF8_STRING selection atoms to mimetypes




commit 0c1ea9221976b838101d2593754b658808fdc542
Author: Carlos Garnacho <carlosg gnome org>
Date:   Mon Oct 3 10:35:48 2022 +0200

    wayland: Translate STRING/UTF8_STRING selection atoms to mimetypes
    
    Since the GDK API layer in 3.x is considerably tied to X11 details,
    it makes sense to provide this bit of translation in case the app
    uses these exclusively and does not use actual mimetype strings.
    Provide this bit of translation of X11 selection atoms to mimetypes.
    
    While at it, use the right zwp_primary_selection_source_v1 API with
    primary selection data sources. From the looks of it, this just
    happened to work.
    
    Closes: https://gitlab.gnome.org/GNOME/gtk/-/issues/5217

 gdk/wayland/gdkselection-wayland.c | 23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)
---
diff --git a/gdk/wayland/gdkselection-wayland.c b/gdk/wayland/gdkselection-wayland.c
index d7f3332fa2..6fbdb5e50d 100644
--- a/gdk/wayland/gdkselection-wayland.c
+++ b/gdk/wayland/gdkselection-wayland.c
@@ -34,6 +34,9 @@
 
 #include <string.h>
 
+#define STRING_MIMETYPE "text/plain"
+#define UTF8_STRING_MIMETYPE "text/plain;charset=utf-8"
+
 typedef struct _SelectionBuffer SelectionBuffer;
 typedef struct _SelectionData SelectionData;
 typedef struct _StoredSelection StoredSelection;
@@ -1783,7 +1786,25 @@ gdk_wayland_selection_add_targets (GdkWindow *window,
     {
       gchar *mimetype = gdk_atom_name (targets[i]);
 
-      wl_data_source_offer (data_source, mimetype);
+      if (selection == atoms[ATOM_PRIMARY])
+        {
+          if (g_strcmp0 (mimetype, "STRING") == 0)
+            zwp_primary_selection_source_v1_offer (data_source, STRING_MIMETYPE);
+          else if (g_strcmp0 (mimetype, "UTF8_STRING") == 0)
+            zwp_primary_selection_source_v1_offer (data_source, UTF8_STRING_MIMETYPE);
+
+          zwp_primary_selection_source_v1_offer (data_source, mimetype);
+        }
+      else
+        {
+          if (g_strcmp0 (mimetype, "STRING") == 0)
+            wl_data_source_offer (data_source, STRING_MIMETYPE);
+          else if (g_strcmp0 (mimetype, "UTF8_STRING") == 0)
+            wl_data_source_offer (data_source, UTF8_STRING_MIMETYPE);
+
+          wl_data_source_offer (data_source, mimetype);
+        }
+
       g_free (mimetype);
     }
 


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