Debian Bug report logs - #380392
xclip doesn't support unicode clipboards

version graph

Package: xclip; Maintainer for xclip is Alessandro Ghedini <ghedo@debian.org>; Source for xclip is src:xclip.

Reported by: Baruch Even <baruch@debian.org>

Date: Sat, 29 Jul 2006 20:48:11 UTC

Severity: normal

Tags: patch

Merged with 384983

Found in versions 0.07-1, xclip/0.08-5.1

Fixed in version xclip/0.11-1

Done: Maximilian Gass <mxey@cloudconnected.org>

Bug is archived. No further changes may be made.

Toggle useless messages

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to debian-bugs-dist@lists.debian.org:
Bug#380392; Package xclip. Full text and rfc822 format available.

Acknowledgement sent to Baruch Even <baruch@debian.org>:
New Bug report received and forwarded. Full text and rfc822 format available.

Message #5 received at submit@bugs.debian.org (full text, mbox):

From: Baruch Even <baruch@debian.org>
To: submit@bugs.debian.org
Subject: xclip doesn't support unicode clipboards
Date: Sat, 29 Jul 2006 21:14:52 +0100
Package: xclip
Version: 0.07-1
Severity: normal

I received the following bug report in email.

-------- Original Message --------
Subject: Re: xclip
Date: Mon, 12 Jun 2006 16:21:46 +0200 (MEST)
From: Thomas Wolff <towo@towo.net>
To: Baruch Even <baruch@debian.org>
CC: towo@towo.net

Hi
thanks for your quick response.

> I never got a bug report that it fails on unicode to know about it. If
> you can please file a bug report in the Debian BTS, If you use debian
> you can use reportbug to ease the submission process. If you are not a
> Debian user a detailed bug report to me would help.
OK, these are my test cases, all inside a UTF-8 mode xterm with
LC_CTYPE=de_DE.UTF-8:

$ echo bäh | xclip -i ; xclip -o
bäh
# works fine; bytes are probably handled transparently
# xclip -o in a Latin-1 terminal would not work now, effect same as below

$ echo bäh | xclip -i
# now inserting the selection with the middle mouse button:
bäh
# UTF-8 bytes are being interpreted as separate characters

$ # bäh # selecting this with the mouse
$ xclip -o
b�
# instead of 'ä' the Unicode replacement character gets pasted


> Ofcourse, if you can find the issue and fix it I'll happily consider the
> patch for inclusion.
Unfortunately, I am not familiar with X programming.
But I have seen in discussions about xterm that UTF-8 mode has to
be handled explicitly with the X clipboard.

Kind regards,
Thomas



Merged 380392 384983. Request was from Robert Millan <rmh@aybabtu.com> to control@bugs.debian.org. Full text and rfc822 format available.

Information forwarded to debian-bugs-dist@lists.debian.org, Baruch Even <baruch@debian.org>:
Bug#380392; Package xclip. Full text and rfc822 format available.

Acknowledgement sent to Morita Sho <morita-pub-en-debian@inz.sakura.ne.jp>:
Extra info received and forwarded to list. Copy sent to Baruch Even <baruch@debian.org>. Full text and rfc822 format available.

Message #12 received at 380392@bugs.debian.org (full text, mbox):

From: Morita Sho <morita-pub-en-debian@inz.sakura.ne.jp>
To: 380392@bugs.debian.org
Subject: xclip: A patch to implement UTF8_STRING support
Date: Sun, 25 Nov 2007 17:36:03 +0900
[Message part 1 (text/plain, inline)]
Hi,

I have made a patch to implement UTF8_STRING support for xclip.

Currently, xclip uses XA_STRING when read from clipboard and write to clipboard.
Because of XA_STRING means ISO-8859-1,
every text read from clipboard is treated as ISO-8859-1, and
every text write to clipboard is treated as ISO-8859-1.
It breaks UTF-8 text.
It is the reason why xclip cannot work in UTF-8 environment.

To handle UTF-8 text, it should use UTF8_STRING instead of XA_STRING.

But I think behaviour of original xclip should be keeped.

To resolve this, my patch add -utf8 option.
Without -utf8 option, xclip works same as original version.
With -utf8 option, xclip uses UTF8_STRING to communicate with clipboard.
I mean,
every text read from clipboard is treated as UTF-8, and
every text write to clipboard is treated as UTF-8.
And if reading/writing as UTF-8 is failed, fallback to XA_STRING.


I have referenced following resources to make this patch:
 * The source code of GTK+-2.0 and GDK
 * The source code of xterm
 * Inter-Client Communication Conventions Manual(ICCCM)
 * UTF8_STRING draft
   http://www.pps.jussieu.fr/~jch/software/UTF8_STRING/

I have tested whether xclip -utf8 work with other applications by following 
procedures:
 * Copy a text with `xclip -utf8` and paste it in other application.
 * Copy a text in other application and paste it with `xclip -o -utf8`.

Note: xclip uses the selection PRIMARY by default.
      PRIMARY is a selection for "Currently selected text."
      You can change to the selection CLIPBOARD by "-selection CLIPBOARD" option.

And here is applications that I have confirmed to work with `xclip -utf8`:
  GTK+ apps (gedit, GNOME Terminal)
  Iceweasel
  xterm
  GVim
  xpdf (Note: because of xpdf doesn't support UTF8_STRING,
        xclip fallbacks to use XA_STRING to retrieve a text from xpdf)

Everything works fine in my test.

Thanks,
-- 
Morita Sho <morita-pub-en-debian@inz.sakura.ne.jp>
[xclip-0.08_utf8-support.patch (text/x-patch, inline)]
diff -u xclip-0.08.orig/xclib.c xclip-0.08/xclib.c
--- xclip-0.08.orig/xclib.c	2007-11-22 09:34:07.000000000 +0900
+++ xclip-0.08/xclib.c	2007-11-24 18:01:00.000000000 +0900
@@ -80,6 +80,8 @@
  * 
  * The selection to return
  * 
+ * The target(UTF8_STRING or XA_STRING) to return
+ *
  * A pointer to a char array to put the selection into.
  * 
  * A pointer to a long to record the length of the char array
@@ -94,13 +96,14 @@
 	Window win,
 	XEvent evt,
 	Atom sel,
+	Atom target,
 	unsigned char **txt,
 	unsigned long *len,
 	unsigned int *context
 )
 {
 	/* a property for other windows to put their selection into */
-	Atom pty, inc, pty_type, targets;
+	Atom pty, inc, pty_type, targets, atomUTF8String;
 	int pty_format;
 		
 	/* buffer for XGetWindowProperty to dump data into */
@@ -128,7 +131,7 @@
 			XConvertSelection(
 				dpy,
 				sel,
-				XA_STRING,
+				target,
 				pty,
 				win,
 				CurrentTime
@@ -138,10 +141,17 @@
 		
 		case XCLIB_XCOUT_SENTCONVSEL:
 			inc = XInternAtom(dpy, "INCR", False);
+			atomUTF8String = XInternAtom(dpy, "UTF8_STRING", False);
 
 			if (evt.type != SelectionNotify)
 				return(0);
 
+			/* fallback to XA_STRING when UTF8_STRING failed */
+			if (target == atomUTF8String && evt.xselection.property == None) {
+				*context = XCLIB_XCOUT_FALLBACK;
+				return(0);
+			}
+
 			/* find the size and format of the data in property */
 			XGetWindowProperty(
 				dpy,
@@ -333,6 +343,8 @@
  * app in it's SelectionRequest. Things are likely to break if you change the
  * value of this yourself.
  * 
+ * The target(UTF8_STRING or XA_STRING) to respond to
+ *
  * A pointer to an array of chars to read selection data from.
  * 
  * The length of the array of chars.
@@ -347,6 +359,7 @@
 	Window *win,
 	XEvent evt,
 	Atom *pty,
+	Atom target,
 	unsigned char *txt,
 	unsigned long len,
 	unsigned long *pos,
@@ -377,18 +390,18 @@
 			/* put the data into an property */
 			if (evt.xselectionrequest.target == targets)
 			{
-				Atom types[2] = { targets, XA_STRING };
+				Atom types[2] = { targets, target };
 			
 				/* send data all at once (not using INCR) */
 				XChangeProperty(
 					dpy,
 					*win,
 					*pty,
-					targets,
-					8,
+					XA_ATOM,
+					32,
 					PropModeReplace,
 					(unsigned char*) types,
-					(int)sizeof(types)
+					(int)(sizeof(types) / sizeof(Atom))
 			       );
 			} else if (len > XC_CHUNK)
 			{
@@ -425,7 +438,7 @@
 					dpy,
 					*win,
 					*pty,
-					XA_STRING,
+					target,
 					8,
 					PropModeReplace,
 					(unsigned char*) txt,
@@ -506,7 +519,7 @@
 					dpy,
 					*win,
 					*pty,
-					XA_STRING,
+					target,
 					8,
 					PropModeReplace,
 					&txt[*pos],
@@ -521,7 +534,7 @@
 					dpy,
 					*win,
 					*pty,
-					XA_STRING,
+					target,
 					8,
 					PropModeReplace,
 					0,
diff -u xclip-0.08.orig/xclib.h xclip-0.08/xclib.h
--- xclip-0.08.orig/xclib.h	2001-11-12 08:56:33.000000000 +0900
+++ xclip-0.08/xclib.h	2007-11-24 17:56:25.000000000 +0900
@@ -24,6 +24,7 @@
 #define XCLIB_XCOUT_NONE	0	/* no context */
 #define XCLIB_XCOUT_SENTCONVSEL	1	/* sent a request */
 #define XCLIB_XCOUT_INCR	2	/* in an incr loop */
+#define XCLIB_XCOUT_FALLBACK	3	/* UTF8_STRING failed, need fallback to XA_STRING */
 
 /* xcin() contexts */
 #define XCLIB_XCIN_NONE		0
@@ -36,6 +37,7 @@
 	Window,
 	XEvent,
 	Atom,
+	Atom,
 	unsigned char**,
 	unsigned long*,
 	unsigned int*
@@ -45,6 +47,7 @@
 	Window*,
 	XEvent,
 	Atom*,
+	Atom,
 	unsigned char*,
 	unsigned long,
 	unsigned long*,
diff -u xclip-0.08.orig/xclip.c xclip-0.08/xclip.c
--- xclip-0.08.orig/xclip.c	2007-11-22 09:34:07.000000000 +0900
+++ xclip-0.08/xclip.c	2007-11-24 18:02:00.000000000 +0900
@@ -30,12 +30,13 @@
 #include "xclib.h"
 
 /* command line option table for XrmParseCommand() */
-XrmOptionDescRec opt_tab[11];
+XrmOptionDescRec opt_tab[12];
 
 /* Options that get set on the command line */
 int             sloop = 0;			/* number of loops */
 char           *sdisp = NULL;			/* X display to connect to */
 Atom            sseln = XA_PRIMARY;		/* X selection to work with */
+Atom            target = XA_STRING;
 
 /* Flags for command line options */
 static int      fverb = OSILENT;		/* output level */
@@ -238,6 +239,26 @@
 	}
 }
 
+/* process utf8 command line option */
+static void doOptUtf8 (void)
+{
+	/* check for -utf8 */
+	if (
+		XrmGetResource(
+			opt_db,
+			"xclip.utf8",
+			"Xclip.utf8",
+			&rec_typ,
+			&rec_val
+		)
+	)
+	{
+		target = XA_UTF8_STRING(dpy);
+		if (fverb == OVERBOSE)	/* print in verbose mode only */
+			fprintf(stderr, "Using UTF8_STRING.\n", sloop);
+	}
+}
+
 static void doIn(Window win, const char *progname)
 {
 	unsigned char *sel_buf;		/* buffer for selection data */
@@ -422,6 +443,7 @@
 					&cwin,
 					evt,
 					&pty,
+					target,
 					sel_buf,
 					sel_len,
 					&sel_pos,
@@ -465,11 +487,20 @@
 					win,
 					evt,
 					sseln,
+					target,
 					&sel_buf,
 					&sel_len,
 					&context
 				 );
 
+			/* fallback is needed. set XA_STRING to target and restart the loop. */
+			if (context == XCLIB_XCOUT_FALLBACK)
+			{
+				context = XCLIB_XCOUT_NONE;
+				target = XA_STRING;
+				continue;
+			}
+
 			/* only continue if xcout() is doing something */
 			if (context == XCLIB_XCOUT_NONE)
 				break;
@@ -568,6 +599,12 @@
 	opt_tab[10].argKind	=	XrmoptionNoArg;
 	opt_tab[10].value	=	(XPointer) xcstrdup("V");
 
+	/* utf8 option entry */
+	opt_tab[11].option	=	xcstrdup("-utf8");
+	opt_tab[11].specifier	=	xcstrdup(".utf8");
+	opt_tab[11].argKind	=	XrmoptionNoArg;
+	opt_tab[11].value	=	(XPointer) xcstrdup("U");
+
 	/* parse command line options */
 	doOptMain(argc, argv);
    
@@ -585,6 +622,8 @@
 
 	/* parse selection command line option */
 	doOptSel();
+	/* parse utf8 command line option */
+	doOptUtf8();
   
 	/* Create a window to trap events */
 	win = XCreateSimpleWindow(
diff -u xclip-0.08.orig/xcprint.c xclip-0.08/xcprint.c
--- xclip-0.08.orig/xcprint.c	2007-11-22 09:34:07.000000000 +0900
+++ xclip-0.08/xcprint.c	2007-11-25 17:24:04.000000000 +0900
@@ -45,6 +45,7 @@
 		"  -h, -help        usage information\n"\
 		"      -selection   selection to access (\"primary\", "\
 		"\"secondary\", \"clipboard\" or \"buffer-cut\")\n"\
+		"      -utf8        treat all text are utf-8\n"\
 		"      -version     version information\n"\
 		"      -silent      errors only, run in background (default)\n"\
 		"      -quiet       run in foreground, show what's happening\n"\

Information forwarded to debian-bugs-dist@lists.debian.org, Baruch Even <baruch@debian.org>:
Bug#380392; Package xclip. (Wed, 07 Jan 2009 12:00:06 GMT) Full text and rfc822 format available.

Acknowledgement sent to Håkon Stordahl <hakon@stordahl.org>:
Extra info received and forwarded to list. Copy sent to Baruch Even <baruch@debian.org>. (Wed, 07 Jan 2009 12:00:06 GMT) Full text and rfc822 format available.

Message #17 received at 380392@bugs.debian.org (full text, mbox):

From: Håkon Stordahl <hakon@stordahl.org>
To: 380392@bugs.debian.org
Cc: control@bugs.debian.org
Subject: New upstream maintainer for xclip
Date: Wed, 07 Jan 2009 12:59:19 +0100
tags 380392 patch
thanks

Hello. Apparently this package has got a new upstream maintainer and
homepage:

http://sourceforge.net/projects/xclip/

And it seems that the patch posted by Morita Sho above was included by
upstream in version 0.11.




Tags added: patch Request was from Håkon Stordahl <hakon@stordahl.org> to control@bugs.debian.org. (Wed, 07 Jan 2009 12:00:09 GMT) Full text and rfc822 format available.

Reply sent to Maximilian Gass <mxey@cloudconnected.org>:
You have taken responsibility. (Mon, 27 Jul 2009 15:48:03 GMT) Full text and rfc822 format available.

Notification sent to Baruch Even <baruch@debian.org>:
Bug acknowledged by developer. (Mon, 27 Jul 2009 15:48:03 GMT) Full text and rfc822 format available.

Message #24 received at 380392-close@bugs.debian.org (full text, mbox):

From: Maximilian Gass <mxey@cloudconnected.org>
To: 380392-close@bugs.debian.org
Subject: Bug#380392: fixed in xclip 0.11-1
Date: Mon, 27 Jul 2009 15:21:34 +0000
Source: xclip
Source-Version: 0.11-1

We believe that the bug you reported is fixed in the latest version of
xclip, which is due to be installed in the Debian FTP archive:

xclip_0.11-1.diff.gz
  to pool/main/x/xclip/xclip_0.11-1.diff.gz
xclip_0.11-1.dsc
  to pool/main/x/xclip/xclip_0.11-1.dsc
xclip_0.11-1_amd64.deb
  to pool/main/x/xclip/xclip_0.11-1_amd64.deb
xclip_0.11.orig.tar.gz
  to pool/main/x/xclip/xclip_0.11.orig.tar.gz



A summary of the changes between this version and the previous one is
attached.

Thank you for reporting the bug, which will now be closed.  If you
have further comments please address them to 380392@bugs.debian.org,
and the maintainer will reopen the bug report if appropriate.

Debian distribution maintenance software
pp.
Maximilian Gass <mxey@cloudconnected.org> (supplier of updated xclip package)

(This message was generated automatically at their request; if you
believe that there is a problem with it please contact the archive
administrators by mailing ftpmaster@debian.org)


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Format: 1.8
Date: Sat, 25 Jul 2009 20:55:38 +0200
Source: xclip
Binary: xclip
Architecture: source amd64
Version: 0.11-1
Distribution: unstable
Urgency: low
Maintainer: Maximilian Gass <mxey@cloudconnected.org>
Changed-By: Maximilian Gass <mxey@cloudconnected.org>
Description: 
 xclip      - command line interface to X selections
Closes: 380392 471962 515299
Changes: 
 xclip (0.11-1) unstable; urgency=low
 .
   * New upstream release (closes: #380392, #471962)
   * Taking over maintainership, suggested by old maintainer Baruch Even via
     private email. Thanks to Baruch for his previous work on this package.
   * Fixed homepage (closes: #515299)
   * Removed old patches, because upstream applied them in 0.10
   * Added Quilt patch system
   * Added patch to fix manpage section
   * Added patch to use minus signs instead of hyphens in manpage
   * Bumped Standards-Version to 3.8.2, no changes necessary.
   * Switched to machine-readable copyright file
   * Added a watch file
Checksums-Sha1: 
 45d12f64c75c2901555068780aea84817db31411 1123 xclip_0.11-1.dsc
 e65e287e48567d661d125c1a78e43d5d9f572cae 60067 xclip_0.11.orig.tar.gz
 eca070d631ee24db620d4e3e437ef1875fead03b 4327 xclip_0.11-1.diff.gz
 a016e1de3524c58779bc7359a513c7b36010fc3e 20184 xclip_0.11-1_amd64.deb
Checksums-Sha256: 
 a0fff25523adeb15386c0aadd1c15fc8ba64f1b588de7d0d0800e99e0daef53f 1123 xclip_0.11-1.dsc
 8f29fd6b7e635d63ff84451afcf15c264fd1b4213b584aa5f9ce988fddecfc46 60067 xclip_0.11.orig.tar.gz
 a1aed4752b493a67f193599f191a37442b9eb1d311ae6deef196321dcd91aa41 4327 xclip_0.11-1.diff.gz
 75054bdd448b50ae18e8d937cc6479333561e5495680b0d9b2891ad80342eed4 20184 xclip_0.11-1_amd64.deb
Files: 
 3428c54509a37d46f768b89e7306da3d 1123 x11 optional xclip_0.11-1.dsc
 4caf3a2b03c36981f9af36a8e8582951 60067 x11 optional xclip_0.11.orig.tar.gz
 0dc54bdc1ed5425671c8055a5b7ac98a 4327 x11 optional xclip_0.11-1.diff.gz
 cd6ea88b0c0c70c2842806fd8a38f2ed 20184 x11 optional xclip_0.11-1_amd64.deb

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)

iEYEARECAAYFAkptvv8ACgkQBnqtBMk7/3k/zgCgvu65JjqCEk+TY22NwxV0tnmk
6/oAmQH9djnM8BqXw/pCLGSh+Fmg+fIT
=H7kT
-----END PGP SIGNATURE-----





Reply sent to Maximilian Gass <mxey@cloudconnected.org>:
You have taken responsibility. (Mon, 27 Jul 2009 15:48:04 GMT) Full text and rfc822 format available.

Notification sent to Dan Jacobson <jidanni@jidanni.org>:
Bug acknowledged by developer. (Mon, 27 Jul 2009 15:48:04 GMT) Full text and rfc822 format available.

Bug archived. Request was from Debbugs Internal Request <owner@bugs.debian.org> to internal_control@bugs.debian.org. (Fri, 04 Sep 2009 07:42:59 GMT) Full text and rfc822 format available.

Send a report that this bug log contains spam.


Debian bug tracking system administrator <owner@bugs.debian.org>. Last modified: Thu Apr 17 04:28:31 2014; Machine Name: beach.debian.org

Debian Bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.