[gtk+] wayland: Add some dumb support for the TARGETS selection



commit f4b212abd47435d97c464afa001fa812d4897015
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Thu Jul 3 13:20:38 2014 -0400

    wayland: Add some dumb support for the TARGETS selection
    
    The way that GtkTextView et al pop up their context menu is to first
    query to see if the clipboard has some text, and if so, enable the Paste
    menu item. But since the Wayland backend hasn't had the greatest
    selection and clipboard code, the callback for the clipboard got dropped
    on the floor.
    
    Add some simple code to respond to the TARGETS selection.
    
    This makes right-clicking on a GtkTextView work fine.

 gdk/wayland/gdkdevice-wayland.c |   17 ++++++++++-------
 gtk/gtkclipboard-wayland.c      |   18 ++++++++++++++++++
 2 files changed, 28 insertions(+), 7 deletions(-)
---
diff --git a/gdk/wayland/gdkdevice-wayland.c b/gdk/wayland/gdkdevice-wayland.c
index 9471d31..0da19a6 100644
--- a/gdk/wayland/gdkdevice-wayland.c
+++ b/gdk/wayland/gdkdevice-wayland.c
@@ -1770,6 +1770,15 @@ _gdk_wayland_device_get_button_press_serial (GdkWaylandDeviceData *device)
   return device->button_press_serial;
 }
 
+static GdkAtom
+mime_type_to_gdk_atom (char *mime_type)
+{
+  if (strcmp (mime_type, "text/plain;charset=utf8"))
+    return gdk_atom_intern_static_string ("UTF8_STRING");
+
+  return GDK_NONE;
+}
+
 gint
 gdk_wayland_device_get_selection_type_atoms (GdkDevice  *gdk_device,
                                              GdkAtom   **atoms_out)
@@ -1793,13 +1802,7 @@ gdk_wayland_device_get_selection_type_atoms (GdkDevice  *gdk_device,
 
   /* Convert list of targets to atoms */
   for (i = 0; i < device->selection_offer->types->len; i++)
-    {
-      atoms[i] = gdk_atom_intern (device->selection_offer->types->pdata[i],
-                                  FALSE);
-      GDK_NOTE (MISC,
-                g_message (G_STRLOC ": Adding atom for %s",
-                           (char *)device->selection_offer->types->pdata[i]));
-    }
+    atoms[i] = mime_type_to_gdk_atom (device->selection_offer->types->pdata[i]);
 
   *atoms_out = atoms;
   return device->selection_offer->types->len;
diff --git a/gtk/gtkclipboard-wayland.c b/gtk/gtkclipboard-wayland.c
index 328ba4d..9e72802 100644
--- a/gtk/gtkclipboard-wayland.c
+++ b/gtk/gtkclipboard-wayland.c
@@ -283,6 +283,24 @@ gtk_clipboard_wayland_request_contents (GtkClipboard            *gtkclipboard,
   device_manager = gdk_display_get_device_manager (gdk_display_get_default ());
   device = gdk_device_manager_get_client_pointer (device_manager);
 
+  if (target == gdk_atom_intern_static_string ("TARGETS"))
+    {
+      GtkSelectionData selection_data;
+      int n_atoms;
+      GdkAtom *atoms;
+
+      selection_data.selection = GDK_NONE;
+      selection_data.format = 32;
+      selection_data.type = GDK_SELECTION_TYPE_ATOM;
+
+      n_atoms = gdk_wayland_device_get_selection_type_atoms (device, &atoms);
+      selection_data.length = n_atoms;
+      selection_data.data = atoms;
+
+      callback (gtkclipboard, &selection_data, user_data);
+      return;
+    }
+
   /* When GTK+ requests text, it tries UTF8_STRING first and then
    * falls back to COMPOUND_TEXT and then STRING.  We rewrite
    * UTF8_STRING to text/plain;charset=utf-8, and if that doesn't


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