emacs-diffs
[Top][All Lists]
Advanced

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

feature/pgtk ef76e64: Support getting a image from clipboard


From: Yuuki Harano
Subject: feature/pgtk ef76e64: Support getting a image from clipboard
Date: Thu, 11 Feb 2021 05:33:42 -0500 (EST)

branch: feature/pgtk
commit ef76e64427bb980cca23c338df2526766431ea52
Author: Yuuki Harano <masm+github@masm11.me>
Commit: Yuuki Harano <masm+github@masm11.me>

    Support getting a image from clipboard
    
    * src/pgtkselect.c (Fpgtk_get_selection_internal): Reimplement
    referring selection_data_to_lisp_data in xselect.c
    (syms_of_pgtkselect): Add symbols.
---
 src/pgtkselect.c | 43 ++++++++++++++++++++++++++++++++++++-------
 1 file changed, 36 insertions(+), 7 deletions(-)

diff --git a/src/pgtkselect.c b/src/pgtkselect.c
index 3e57fc7..2d81d12 100644
--- a/src/pgtkselect.c
+++ b/src/pgtkselect.c
@@ -546,14 +546,41 @@ On PGTK, TIME-STAMP is unused.  */)
 
   cb = symbol_to_gtk_clipboard (FRAME_GTK_WIDGET (f), selection_symbol);
 
-  gchar *s = gtk_clipboard_wait_for_text (cb);
-  if (s == NULL)
+  GdkAtom target_atom = gdk_atom_intern (SSDATA (SYMBOL_NAME (target_type)), 
false);
+  GtkSelectionData *seldata = gtk_clipboard_wait_for_contents (cb, 
target_atom);
+
+  if (seldata == NULL)
     return Qnil;
-  int size = strlen (s);
-  Lisp_Object str = make_unibyte_string (s, size);
-  Fput_text_property (make_fixnum (0), make_fixnum (size),
-                     Qforeign_selection, QUTF8_STRING, str);
-  return str;
+
+  const guchar *sd_data = gtk_selection_data_get_data (seldata);
+  int sd_len = gtk_selection_data_get_length (seldata);
+  int sd_format = gtk_selection_data_get_format (seldata);
+  GdkAtom sd_type = gtk_selection_data_get_data_type (seldata);
+
+  if (sd_format == 8)
+    {
+      Lisp_Object str, lispy_type;
+
+      str = make_unibyte_string ((char *) sd_data, sd_len);
+      /* Indicate that this string is from foreign selection by a text
+        property `foreign-selection' so that the caller of
+        x-get-selection-internal (usually x-get-selection) can know
+        that the string must be decode.  */
+      if (sd_type == gdk_atom_intern("COMPOUND_TEXT", false))
+       lispy_type = QCOMPOUND_TEXT;
+      else if (sd_type == gdk_atom_intern("UTF8_STRING", false))
+       lispy_type = QUTF8_STRING;
+      else
+       lispy_type = QSTRING;
+      Fput_text_property (make_fixnum (0), make_fixnum (sd_len),
+                         Qforeign_selection, lispy_type, str);
+
+      gtk_selection_data_free (seldata);
+      return str;
+    }
+
+  gtk_selection_data_free (seldata);
+  return Qnil;
 }
 
 
@@ -576,6 +603,8 @@ syms_of_pgtkselect (void)
 
   DEFSYM (Qforeign_selection, "foreign-selection");
   DEFSYM (QUTF8_STRING, "UTF8_STRING");
+  DEFSYM (QSTRING, "STRING");
+  DEFSYM (QCOMPOUND_TEXT, "COMPOUND_TEXT");
 
   defsubr (&Spgtk_disown_selection_internal);
   defsubr (&Spgtk_get_selection_internal);



reply via email to

[Prev in Thread] Current Thread [Next in Thread]