[dev] [st] Support UTF8 clipboard

From: Petr Sabata <psabata_AT_redhat.com>
Date: Sat, 2 Apr 2011 18:11:24 +0200

This patch adds UTF8 clipboard support via UTF8_STRING, if it's available. This
is needed to correctly exchange UTF8 data with other applications.

-- Petr

---
 st.c |   10 +++++++---
 1 files changed, 7 insertions(+), 3 deletions(-)
diff --git a/st.c b/st.c
index 561d5b0..366f681 100644
--- a/st.c
+++ b/st.c
@@ -248,6 +248,7 @@ static CSIEscape escseq;
 static int cmdfd;
 static pid_t pid;
 static Selection sel;
+static Atom seltarget;
 static char **opt_cmd  = NULL;
 static char *opt_title = NULL;
 static char *opt_class = NULL;
@@ -370,6 +371,9 @@ selinit(void) {
 	sel.mode = 0;
 	sel.bx = -1;
 	sel.clip = NULL;
+	seltarget = XInternAtom(xw.dpy, "UTF8_STRING", 0);
+	if (seltarget == None)
+		seltarget = XA_STRING;
 }
 
 static inline int 
@@ -453,7 +457,7 @@ selnotify(XEvent *e) {
 
 void
 selpaste() {
-	XConvertSelection(xw.dpy, XA_PRIMARY, XA_STRING, XA_PRIMARY, xw.win, CurrentTime);
+	XConvertSelection(xw.dpy, XA_PRIMARY, seltarget, XA_PRIMARY, xw.win, CurrentTime);
 }
 
 void
@@ -474,12 +478,12 @@ selrequest(XEvent *e) {
 	xa_targets = XInternAtom(xw.dpy, "TARGETS", 0);
 	if(xsre->target == xa_targets) {
 		/* respond with the supported type */
-		Atom string = XA_STRING;
+		Atom string = seltarget;
 		XChangeProperty(xsre->display, xsre->requestor, xsre->property,
 				XA_ATOM, 32, PropModeReplace,
 				(unsigned char *) &string, 1);
 		xev.property = xsre->property;
-	} else if(xsre->target == XA_STRING) {
+	} else if(xsre->target == seltarget || xsre->target == XA_STRING) {
 		XChangeProperty(xsre->display, xsre->requestor, xsre->property,
 				xsre->target, 8, PropModeReplace,
 				(unsigned char *) sel.clip, strlen(sel.clip));
-- 
1.7.4
Received on Sat Apr 02 2011 - 18:11:24 CEST

This archive was generated by hypermail 2.2.0 : Sat Apr 02 2011 - 18:24:01 CEST