Package: xsel
Version: 0.9.6-1
Followup-For: Bug #231413

Xsel doesn't support XA_UTF8_STRING selection target when retrieving or
setting selections. Attached is a quick patch to make xsel
UTF8_STRING-enabled. Please note that this patch is not 100% correct.
With this patch applied, xsel will always ask other applications for
XA_UTF8_STRING instead of XA_STRING. Thus it could fail to communicate 
selection with applications not aware of UTF8_STRING selection target.
Hovever, most of today programs (e.g. xterm, mozilla) handle 
UTF8_STRING just fine, so this patch will probably work for you.

-- System Information:
Debian Release: testing/unstable
  APT prefers testing
  APT policy: (500, 'testing')
Architecture: i386 (i686)
Shell:  /bin/sh linked to /bin/bash
Kernel: Linux 2.4.29
Locale: LANG=ru_RU.koi8r, LC_CTYPE=ru_RU.koi8r (charmap=KOI8-R)

Versions of packages xsel depends on:
ii  libc6                         2.3.5-6    GNU C Library: Shared libraries an
ii  xlibs                         4.3.0-5    X Window System client libraries m

xsel recommends no packages.

-- no debconf information
--- xsel.c.old	2005-10-24 16:28:07.000000000 +0700
+++ xsel.c	2005-10-25 09:37:55.000000000 +0700
@@ -56,10 +56,11 @@
 static Atom incr_atom; /* The INCR atom */
 static Atom null_atom; /* The NULL atom */
 static Atom text_atom; /* The TEXT atom */
+static Atom utf8_atom; /* The UTF8 atom */
 
 /* Number of selection targets served by this.
- * (MULTIPLE, INCR, TARGETS, TIMESTAMP, DELETE, TEXT and STRING) */
-#define NUM_TARGETS 7
+ * (MULTIPLE, INCR, TARGETS, TIMESTAMP, DELETE, TEXT, UTF8_STRING and STRING) */
+#define NUM_TARGETS 8
 static Atom supported_targets[NUM_TARGETS];
 
 /* do_follow: Follow mode for output */
@@ -225,6 +226,7 @@
   if (atom == incr_atom) return "INCR";
   if (atom == null_atom) return "NULL";
   if (atom == text_atom) return "TEXT";
+  if (atom == utf8_atom) return "UTF8_STRING";
   if (atom == XInternAtom (display, "XSEL_DATA", True)) return "XSEL_DATA";
 
   return "<unknown atom>";
@@ -595,7 +597,7 @@
           retval = wait_incr_selection (selection, &event.xselection,
                                         *(int *)value);
           keep_waiting = False;
-        } else if (target != XA_STRING && request_target != delete_atom) {
+        } else if (target != utf8_atom && target != XA_STRING && request_target != delete_atom) {
           /* Report non-TEXT atoms */
           print_debug (D_WARN, "Selection (type %s) is not a string.",
                        get_atom_name (target));
@@ -1263,6 +1265,22 @@
 }
 
 /*
+ * handle_utf8_string (display, requestor, property, sel)
+ *
+ * Handle a UTF8_STRING request; setting 'sel' as the data
+ */
+static HandleResult
+handle_utf8_string (Display * display, Window requestor, Atom property,
+               unsigned char * sel, Atom selection, Time time,
+               MultTrack * mparent)
+{
+  return
+    change_property (display, requestor, property, utf8_atom, 8,
+                     PropModeReplace, sel, strlen(sel),
+                     selection, time, mparent);
+}
+
+/*
  * handle_delete (display, requestor, property)
  *
  * Handle a DELETE request.
@@ -1308,6 +1326,9 @@
     } else if (mt->atoms[i] == XA_STRING || mt->atoms[i] == text_atom) {
       retval |= handle_string (mt->display, mt->requestor, mt->atoms[i+1],
                                mt->sel, mt->selection, mt->time, mt);
+    } else if (mt->atoms[i] == utf8_atom) {
+      retval |= handle_utf8_string (mt->display, mt->requestor, mt->atoms[i+1],
+                               mt->sel, mt->selection, mt->time, mt);
     } else if (mt->atoms[i] == delete_atom) {
       retval |= handle_delete (mt->display, mt->requestor, mt->atoms[i+1]);
     } else if (mt->atoms[i] == None) {
@@ -1480,6 +1501,11 @@
     ev.property = xsr->property;
     hr = handle_string (ev.display, ev.requestor, ev.property, sel,
                         ev.selection, ev.time, NULL);
+  } else if (ev.target == utf8_atom) {
+    /* Received UTF8_STRING request */
+    ev.property = xsr->property;
+    hr = handle_utf8_string (ev.display, ev.requestor, ev.property, sel,
+                        ev.selection, ev.time, NULL);
   } else if (ev.target == delete_atom) {
     /* Received DELETE request */
     ev.property = xsr->property;
@@ -1692,8 +1718,8 @@
 {
   unsigned char * text1, * text2;
 
-  text1 = get_selection (XA_PRIMARY, XA_STRING);
-  text2 = get_selection (XA_SECONDARY, XA_STRING);
+  text1 = get_selection (XA_PRIMARY, utf8_atom);
+  text2 = get_selection (XA_SECONDARY, utf8_atom);
 
   set_selection_pair__daemon (text1, text2);
 }
@@ -1710,8 +1736,8 @@
 {
   unsigned char * text1, * text2;
 
-  text1 = get_selection (XA_PRIMARY, XA_STRING);
-  text2 = get_selection (XA_SECONDARY, XA_STRING);
+  text1 = get_selection (XA_PRIMARY, utf8_atom);
+  text2 = get_selection (XA_SECONDARY, utf8_atom);
 
   set_selection_pair__daemon (text2, text1);
 }
@@ -1904,6 +1930,10 @@
   text_atom = XInternAtom (display, "TEXT", False);
   supported_targets[s++] = text_atom;
 
+  /* Get the UTF8_STRING atom */
+  utf8_atom = XInternAtom (display, "UTF8_STRING", False);
+  supported_targets[s++] = utf8_atom;
+
   supported_targets[s++] = XA_STRING;
 
   /* handle selection keeping and exit if so */
@@ -1926,7 +1956,7 @@
   /* handle output modes */
   if (do_output || !dont_output) {
     /* Get the current selection */
-    old_sel = get_selection (selection, XA_STRING);
+    old_sel = get_selection (selection, utf8_atom);
     if (old_sel) printf ("%s", old_sel);
   }
 
@@ -1938,7 +1968,7 @@
   }
   else if (do_input || !dont_input) {
     if (do_append) {
-      if (!old_sel) old_sel = get_selection (selection, XA_STRING);
+      if (!old_sel) old_sel = get_selection (selection, utf8_atom);
       new_sel = copy_sel (old_sel);
     }
     new_sel = initialise_read (new_sel);

Reply via email to