From 6b39f7635c69970c0dbb8f8c9320c6a8ef01e862 Mon Sep 17 00:00:00 2001 From: Tom Callaway Date: Jan 14 2008 20:44:05 +0000 Subject: Enable utf8 support by default (-noutf8 as a fallback option), bz 428192 --- diff --git a/xclip-0.10-utf8.patch b/xclip-0.10-utf8.patch new file mode 100644 index 0000000..7202fb5 --- /dev/null +++ b/xclip-0.10-utf8.patch @@ -0,0 +1,246 @@ +diff -up xclip-0.10/xcprint.c.utf8 xclip-0.10/xcprint.c +--- xclip-0.10/xcprint.c.utf8 2007-08-26 11:06:30.000000000 -0400 ++++ xclip-0.10/xcprint.c 2008-01-14 15:31:03.000000000 -0500 +@@ -45,6 +45,7 @@ prhelp(char *name) + " -h, -help usage information\n" + " -selection selection to access (\"primary\", " + "\"secondary\", \"clipboard\" or \"buffer-cut\")\n" ++ " -noutf8 don't treat text as utf-8, use old unicode\n" + " -version version information\n" + " -silent errors only, run in background (default)\n" + " -quiet run in foreground, show what's happening\n" +diff -up xclip-0.10/xclib.c.utf8 xclip-0.10/xclib.c +--- xclip-0.10/xclib.c.utf8 2007-08-12 09:44:09.000000000 -0400 ++++ xclip-0.10/xclib.c 2008-01-14 15:31:03.000000000 -0500 +@@ -84,6 +84,8 @@ xcstrdup(const char *string) + * + * 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 +@@ -96,12 +98,13 @@ xcstrdup(const char *string) + int + xcout(Display * dpy, + Window win, +- XEvent evt, Atom sel, unsigned char **txt, unsigned long *len, unsigned int *context) ++ 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 */ + static Atom pty; + static Atom inc; + Atom pty_type; ++ Atom atomUTF8String; + int pty_format; + + /* buffer for XGetWindowProperty to dump data into */ +@@ -129,14 +132,21 @@ xcout(Display * dpy, + } + + /* send a selection request */ +- XConvertSelection(dpy, sel, XA_STRING, pty, win, CurrentTime); ++ XConvertSelection(dpy, sel, target, pty, win, CurrentTime); + *context = XCLIB_XCOUT_SENTCONVSEL; + return (0); + + case XCLIB_XCOUT_SENTCONVSEL: ++ 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, + win, +@@ -295,6 +305,8 @@ xcout(Display * dpy, + * 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. +@@ -308,7 +320,7 @@ int + xcin(Display * dpy, + Window * win, + XEvent evt, +- Atom * pty, unsigned char *txt, unsigned long len, unsigned long *pos, unsigned int *context) ++ Atom * pty, Atom target, unsigned char *txt, unsigned long len, unsigned long *pos, unsigned int *context) + { + unsigned long chunk_len; /* length of current chunk (for incr + * transfers only) +@@ -349,14 +361,14 @@ xcin(Display * dpy, + + /* 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, PropModeReplace, (unsigned char *) types, (int) sizeof(types) ++ XA_ATOM, ++ 32, PropModeReplace, (unsigned char *) types, (int)(sizeof(types) / sizeof(Atom)) + ); + } + else if (len > chunk_size) { +@@ -375,7 +387,7 @@ xcin(Display * dpy, + /* send data all at once (not using INCR) */ + XChangeProperty(dpy, + *win, +- *pty, XA_STRING, 8, PropModeReplace, (unsigned char *) txt, (int) len); ++ *pty, target, 8, PropModeReplace, (unsigned char *) txt, (int) len); + } + + /* Perhaps FIXME: According to ICCCM section 2.5, we should +@@ -440,13 +452,13 @@ xcin(Display * dpy, + if (chunk_len) { + /* put the chunk into the property */ + XChangeProperty(dpy, +- *win, *pty, XA_STRING, 8, PropModeReplace, &txt[*pos], (int) chunk_len); ++ *win, *pty, target, 8, PropModeReplace, &txt[*pos], (int) chunk_len); + } + else { + /* make an empty property to show we've + * finished the transfer + */ +- XChangeProperty(dpy, *win, *pty, XA_STRING, 8, PropModeReplace, 0, 0); ++ XChangeProperty(dpy, *win, *pty, target, 8, PropModeReplace, 0, 0); + } + XFlush(dpy); + +diff -up xclip-0.10/xclip.c.utf8 xclip-0.10/xclip.c +--- xclip-0.10/xclip.c.utf8 2007-08-12 09:44:09.000000000 -0400 ++++ xclip-0.10/xclip.c 2008-01-14 15:37:32.000000000 -0500 +@@ -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 */ +@@ -171,6 +172,29 @@ doOptSel(void) + } + } + ++/* process noutf8 command line option */ ++static void doOptNoUtf8 (void) ++{ ++ /* check for -noutf8 */ ++ if ( ++ XrmGetResource( ++ opt_db, ++ "xclip.noutf8", ++ "Xclip.noutf8", ++ &rec_typ, ++ &rec_val ++ ) ++ ) ++ { ++ if (fverb == OVERBOSE) /* print in verbose mode only */ ++ fprintf(stderr, "Using old UNICODE instead of UTF8.\n", sloop); ++ } else { ++ 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) + { +@@ -300,7 +324,7 @@ doIn(Window win, const char *progname) + + XNextEvent(dpy, &evt); + +- finished = xcin(dpy, &cwin, evt, &pty, sel_buf, sel_len, &sel_pos, &context); ++ finished = xcin(dpy, &cwin, evt, &pty, target, sel_buf, sel_len, &sel_pos, &context); + + if (evt.type == SelectionClear) + clear = 1; +@@ -333,7 +357,15 @@ doOut(Window win) + XNextEvent(dpy, &evt); + + /* fetch the selection, or part of it */ +- xcout(dpy, win, evt, sseln, &sel_buf, &sel_len, &context); ++ xcout(dpy, 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) +@@ -433,6 +465,12 @@ main(int argc, char *argv[]) + opt_tab[10].argKind = XrmoptionNoArg; + opt_tab[10].value = (XPointer) xcstrdup("V"); + ++ /* utf8 option entry */ ++ opt_tab[11].option = xcstrdup("-noutf8"); ++ opt_tab[11].specifier = xcstrdup(".noutf8"); ++ opt_tab[11].argKind = XrmoptionNoArg; ++ opt_tab[11].value = (XPointer) xcstrdup("N"); ++ + /* parse command line options */ + doOptMain(argc, argv); + +@@ -450,6 +488,9 @@ main(int argc, char *argv[]) + /* parse selection command line option */ + doOptSel(); + ++ /* parse noutf8 command line option */ ++ doOptNoUtf8(); ++ + /* Create a window to trap events */ + win = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 0, 0, 1, 1, 0, 0, 0); + +diff -up xclip-0.10/xclib.h.utf8 xclip-0.10/xclib.h +--- xclip-0.10/xclib.h.utf8 2007-08-12 05:47:26.000000000 -0400 ++++ xclip-0.10/xclib.h 2008-01-14 15:31:03.000000000 -0500 +@@ -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 @@ extern int xcout( + Window, + XEvent, + Atom, ++ Atom, + unsigned char**, + unsigned long*, + unsigned int* +@@ -45,6 +47,7 @@ extern int xcin( + Window*, + XEvent, + Atom*, ++ Atom, + unsigned char*, + unsigned long, + unsigned long*, diff --git a/xclip.spec b/xclip.spec index c2f4a28..2ffc141 100644 --- a/xclip.spec +++ b/xclip.spec @@ -1,13 +1,14 @@ Name: xclip Version: 0.10 -Release: 1%{?dist}.1 +Release: 2%{?dist} License: GPLv2+ Group: Applications/System Summary: Command line clipboard grabber URL: http://sourceforge.net/projects/xclip Source0: http://downloads.sourceforge.net/xclip/%{name}-%{version}.tar.gz +Patch0: xclip-0.10-utf8.patch BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) -BuildRequires: xorg-x11-devel +BuildRequires: xorg-x11-devel %description xclip is a command line utility that is designed to run on any system with an @@ -19,6 +20,7 @@ another program. %prep %setup -q +%patch0 -p1 -b .utf8 %build %configure @@ -42,8 +44,8 @@ rm -rf $RPM_BUILD_ROOT %{_mandir}/man1/xclip.1* %changelog -* Tue Oct 16 2007 Tom "spot" Callaway 0.10-1.1 -- no need for X11R6 workaround anymore +* Mon Jan 14 2008 Tom "spot" Callaway 0.10-2 +- enable utf8 support by default * Tue Oct 16 2007 Tom "spot" Callaway 0.10-1 - bump to 0.10