|
|
6b39f76 |
diff -up xclip-0.10/xcprint.c.utf8 xclip-0.10/xcprint.c
|
|
|
6b39f76 |
--- xclip-0.10/xcprint.c.utf8 2007-08-26 11:06:30.000000000 -0400
|
|
|
6b39f76 |
+++ xclip-0.10/xcprint.c 2008-01-14 15:31:03.000000000 -0500
|
|
|
6b39f76 |
@@ -45,6 +45,7 @@ prhelp(char *name)
|
|
|
6b39f76 |
" -h, -help usage information\n"
|
|
|
6b39f76 |
" -selection selection to access (\"primary\", "
|
|
|
6b39f76 |
"\"secondary\", \"clipboard\" or \"buffer-cut\")\n"
|
|
|
6b39f76 |
+ " -noutf8 don't treat text as utf-8, use old unicode\n"
|
|
|
6b39f76 |
" -version version information\n"
|
|
|
6b39f76 |
" -silent errors only, run in background (default)\n"
|
|
|
6b39f76 |
" -quiet run in foreground, show what's happening\n"
|
|
|
6b39f76 |
diff -up xclip-0.10/xclib.c.utf8 xclip-0.10/xclib.c
|
|
|
6b39f76 |
--- xclip-0.10/xclib.c.utf8 2007-08-12 09:44:09.000000000 -0400
|
|
|
6b39f76 |
+++ xclip-0.10/xclib.c 2008-01-14 15:31:03.000000000 -0500
|
|
|
6b39f76 |
@@ -84,6 +84,8 @@ xcstrdup(const char *string)
|
|
|
6b39f76 |
*
|
|
|
6b39f76 |
* The selection to return
|
|
|
6b39f76 |
*
|
|
|
6b39f76 |
+ * The target(UTF8_STRING or XA_STRING) to return
|
|
|
6b39f76 |
+ *
|
|
|
6b39f76 |
* A pointer to a char array to put the selection into.
|
|
|
6b39f76 |
*
|
|
|
6b39f76 |
* A pointer to a long to record the length of the char array
|
|
|
6b39f76 |
@@ -96,12 +98,13 @@ xcstrdup(const char *string)
|
|
|
6b39f76 |
int
|
|
|
6b39f76 |
xcout(Display * dpy,
|
|
|
6b39f76 |
Window win,
|
|
|
6b39f76 |
- XEvent evt, Atom sel, unsigned char **txt, unsigned long *len, unsigned int *context)
|
|
|
6b39f76 |
+ XEvent evt, Atom sel, Atom target, unsigned char **txt, unsigned long *len, unsigned int *context)
|
|
|
6b39f76 |
{
|
|
|
6b39f76 |
/* a property for other windows to put their selection into */
|
|
|
6b39f76 |
static Atom pty;
|
|
|
6b39f76 |
static Atom inc;
|
|
|
6b39f76 |
Atom pty_type;
|
|
|
6b39f76 |
+ Atom atomUTF8String;
|
|
|
6b39f76 |
int pty_format;
|
|
|
6b39f76 |
|
|
|
6b39f76 |
/* buffer for XGetWindowProperty to dump data into */
|
|
|
6b39f76 |
@@ -129,14 +132,21 @@ xcout(Display * dpy,
|
|
|
6b39f76 |
}
|
|
|
6b39f76 |
|
|
|
6b39f76 |
/* send a selection request */
|
|
|
6b39f76 |
- XConvertSelection(dpy, sel, XA_STRING, pty, win, CurrentTime);
|
|
|
6b39f76 |
+ XConvertSelection(dpy, sel, target, pty, win, CurrentTime);
|
|
|
6b39f76 |
*context = XCLIB_XCOUT_SENTCONVSEL;
|
|
|
6b39f76 |
return (0);
|
|
|
6b39f76 |
|
|
|
6b39f76 |
case XCLIB_XCOUT_SENTCONVSEL:
|
|
|
6b39f76 |
+ atomUTF8String = XInternAtom(dpy, "UTF8_STRING", False);
|
|
|
6b39f76 |
if (evt.type != SelectionNotify)
|
|
|
6b39f76 |
return (0);
|
|
|
6b39f76 |
|
|
|
6b39f76 |
+ /* fallback to XA_STRING when UTF8_STRING failed */
|
|
|
6b39f76 |
+ if (target == atomUTF8String && evt.xselection.property == None) {
|
|
|
6b39f76 |
+ *context = XCLIB_XCOUT_FALLBACK;
|
|
|
6b39f76 |
+ return(0);
|
|
|
6b39f76 |
+ }
|
|
|
6b39f76 |
+
|
|
|
6b39f76 |
/* find the size and format of the data in property */
|
|
|
6b39f76 |
XGetWindowProperty(dpy,
|
|
|
6b39f76 |
win,
|
|
|
6b39f76 |
@@ -295,6 +305,8 @@ xcout(Display * dpy,
|
|
|
6b39f76 |
* app in it's SelectionRequest. Things are likely to break if you change the
|
|
|
6b39f76 |
* value of this yourself.
|
|
|
6b39f76 |
*
|
|
|
6b39f76 |
+ * The target(UTF8_STRING or XA_STRING) to respond to
|
|
|
6b39f76 |
+ *
|
|
|
6b39f76 |
* A pointer to an array of chars to read selection data from.
|
|
|
6b39f76 |
*
|
|
|
6b39f76 |
* The length of the array of chars.
|
|
|
6b39f76 |
@@ -308,7 +320,7 @@ int
|
|
|
6b39f76 |
xcin(Display * dpy,
|
|
|
6b39f76 |
Window * win,
|
|
|
6b39f76 |
XEvent evt,
|
|
|
6b39f76 |
- Atom * pty, unsigned char *txt, unsigned long len, unsigned long *pos, unsigned int *context)
|
|
|
6b39f76 |
+ Atom * pty, Atom target, unsigned char *txt, unsigned long len, unsigned long *pos, unsigned int *context)
|
|
|
6b39f76 |
{
|
|
|
6b39f76 |
unsigned long chunk_len; /* length of current chunk (for incr
|
|
|
6b39f76 |
* transfers only)
|
|
|
6b39f76 |
@@ -349,14 +361,14 @@ xcin(Display * dpy,
|
|
|
6b39f76 |
|
|
|
6b39f76 |
/* put the data into an property */
|
|
|
6b39f76 |
if (evt.xselectionrequest.target == targets) {
|
|
|
6b39f76 |
- Atom types[2] = { targets, XA_STRING };
|
|
|
6b39f76 |
+ Atom types[2] = { targets, target };
|
|
|
6b39f76 |
|
|
|
6b39f76 |
/* send data all at once (not using INCR) */
|
|
|
6b39f76 |
XChangeProperty(dpy,
|
|
|
6b39f76 |
*win,
|
|
|
6b39f76 |
*pty,
|
|
|
6b39f76 |
- targets,
|
|
|
6b39f76 |
- 8, PropModeReplace, (unsigned char *) types, (int) sizeof(types)
|
|
|
6b39f76 |
+ XA_ATOM,
|
|
|
6b39f76 |
+ 32, PropModeReplace, (unsigned char *) types, (int)(sizeof(types) / sizeof(Atom))
|
|
|
6b39f76 |
);
|
|
|
6b39f76 |
}
|
|
|
6b39f76 |
else if (len > chunk_size) {
|
|
|
6b39f76 |
@@ -375,7 +387,7 @@ xcin(Display * dpy,
|
|
|
6b39f76 |
/* send data all at once (not using INCR) */
|
|
|
6b39f76 |
XChangeProperty(dpy,
|
|
|
6b39f76 |
*win,
|
|
|
6b39f76 |
- *pty, XA_STRING, 8, PropModeReplace, (unsigned char *) txt, (int) len);
|
|
|
6b39f76 |
+ *pty, target, 8, PropModeReplace, (unsigned char *) txt, (int) len);
|
|
|
6b39f76 |
}
|
|
|
6b39f76 |
|
|
|
6b39f76 |
/* Perhaps FIXME: According to ICCCM section 2.5, we should
|
|
|
6b39f76 |
@@ -440,13 +452,13 @@ xcin(Display * dpy,
|
|
|
6b39f76 |
if (chunk_len) {
|
|
|
6b39f76 |
/* put the chunk into the property */
|
|
|
6b39f76 |
XChangeProperty(dpy,
|
|
|
6b39f76 |
- *win, *pty, XA_STRING, 8, PropModeReplace, &txt[*pos], (int) chunk_len);
|
|
|
6b39f76 |
+ *win, *pty, target, 8, PropModeReplace, &txt[*pos], (int) chunk_len);
|
|
|
6b39f76 |
}
|
|
|
6b39f76 |
else {
|
|
|
6b39f76 |
/* make an empty property to show we've
|
|
|
6b39f76 |
* finished the transfer
|
|
|
6b39f76 |
*/
|
|
|
6b39f76 |
- XChangeProperty(dpy, *win, *pty, XA_STRING, 8, PropModeReplace, 0, 0);
|
|
|
6b39f76 |
+ XChangeProperty(dpy, *win, *pty, target, 8, PropModeReplace, 0, 0);
|
|
|
6b39f76 |
}
|
|
|
6b39f76 |
XFlush(dpy);
|
|
|
6b39f76 |
|
|
|
6b39f76 |
diff -up xclip-0.10/xclip.c.utf8 xclip-0.10/xclip.c
|
|
|
6b39f76 |
--- xclip-0.10/xclip.c.utf8 2007-08-12 09:44:09.000000000 -0400
|
|
|
6b39f76 |
+++ xclip-0.10/xclip.c 2008-01-14 15:37:32.000000000 -0500
|
|
|
6b39f76 |
@@ -30,12 +30,13 @@
|
|
|
6b39f76 |
#include "xclib.h"
|
|
|
6b39f76 |
|
|
|
6b39f76 |
/* command line option table for XrmParseCommand() */
|
|
|
6b39f76 |
-XrmOptionDescRec opt_tab[11];
|
|
|
6b39f76 |
+XrmOptionDescRec opt_tab[12];
|
|
|
6b39f76 |
|
|
|
6b39f76 |
/* Options that get set on the command line */
|
|
|
6b39f76 |
int sloop = 0; /* number of loops */
|
|
|
6b39f76 |
char *sdisp = NULL; /* X display to connect to */
|
|
|
6b39f76 |
Atom sseln = XA_PRIMARY; /* X selection to work with */
|
|
|
6b39f76 |
+Atom target = XA_STRING;
|
|
|
6b39f76 |
|
|
|
6b39f76 |
/* Flags for command line options */
|
|
|
6b39f76 |
static int fverb = OSILENT; /* output level */
|
|
|
6b39f76 |
@@ -171,6 +172,29 @@ doOptSel(void)
|
|
|
6b39f76 |
}
|
|
|
6b39f76 |
}
|
|
|
6b39f76 |
|
|
|
6b39f76 |
+/* process noutf8 command line option */
|
|
|
6b39f76 |
+static void doOptNoUtf8 (void)
|
|
|
6b39f76 |
+{
|
|
|
6b39f76 |
+ /* check for -noutf8 */
|
|
|
6b39f76 |
+ if (
|
|
|
6b39f76 |
+ XrmGetResource(
|
|
|
6b39f76 |
+ opt_db,
|
|
|
6b39f76 |
+ "xclip.noutf8",
|
|
|
6b39f76 |
+ "Xclip.noutf8",
|
|
|
6b39f76 |
+ &rec_typ,
|
|
|
6b39f76 |
+ &rec_val
|
|
|
6b39f76 |
+ )
|
|
|
6b39f76 |
+ )
|
|
|
6b39f76 |
+ {
|
|
|
6b39f76 |
+ if (fverb == OVERBOSE) /* print in verbose mode only */
|
|
|
6b39f76 |
+ fprintf(stderr, "Using old UNICODE instead of UTF8.\n", sloop);
|
|
|
6b39f76 |
+ } else {
|
|
|
6b39f76 |
+ target = XA_UTF8_STRING(dpy);
|
|
|
6b39f76 |
+ if (fverb == OVERBOSE) /* print in verbose mode only */
|
|
|
6b39f76 |
+ fprintf(stderr, "Using UTF8_STRING.\n", sloop);
|
|
|
6b39f76 |
+ }
|
|
|
6b39f76 |
+}
|
|
|
6b39f76 |
+
|
|
|
6b39f76 |
static void
|
|
|
6b39f76 |
doIn(Window win, const char *progname)
|
|
|
6b39f76 |
{
|
|
|
6b39f76 |
@@ -300,7 +324,7 @@ doIn(Window win, const char *progname)
|
|
|
6b39f76 |
|
|
|
6b39f76 |
XNextEvent(dpy, &evt);
|
|
|
6b39f76 |
|
|
|
6b39f76 |
- finished = xcin(dpy, &cwin, evt, &pty, sel_buf, sel_len, &sel_pos, &context);
|
|
|
6b39f76 |
+ finished = xcin(dpy, &cwin, evt, &pty, target, sel_buf, sel_len, &sel_pos, &context);
|
|
|
6b39f76 |
|
|
|
6b39f76 |
if (evt.type == SelectionClear)
|
|
|
6b39f76 |
clear = 1;
|
|
|
6b39f76 |
@@ -333,7 +357,15 @@ doOut(Window win)
|
|
|
6b39f76 |
XNextEvent(dpy, &evt);
|
|
|
6b39f76 |
|
|
|
6b39f76 |
/* fetch the selection, or part of it */
|
|
|
6b39f76 |
- xcout(dpy, win, evt, sseln, &sel_buf, &sel_len, &context);
|
|
|
6b39f76 |
+ xcout(dpy, win, evt, sseln, target, &sel_buf, &sel_len, &context);
|
|
|
6b39f76 |
+
|
|
|
6b39f76 |
+ /* fallback is needed. set XA_STRING to target and restart the loop. */
|
|
|
6b39f76 |
+ if (context == XCLIB_XCOUT_FALLBACK)
|
|
|
6b39f76 |
+ {
|
|
|
6b39f76 |
+ context = XCLIB_XCOUT_NONE;
|
|
|
6b39f76 |
+ target = XA_STRING;
|
|
|
6b39f76 |
+ continue;
|
|
|
6b39f76 |
+ }
|
|
|
6b39f76 |
|
|
|
6b39f76 |
/* only continue if xcout() is doing something */
|
|
|
6b39f76 |
if (context == XCLIB_XCOUT_NONE)
|
|
|
6b39f76 |
@@ -433,6 +465,12 @@ main(int argc, char *argv[])
|
|
|
6b39f76 |
opt_tab[10].argKind = XrmoptionNoArg;
|
|
|
6b39f76 |
opt_tab[10].value = (XPointer) xcstrdup("V");
|
|
|
6b39f76 |
|
|
|
6b39f76 |
+ /* utf8 option entry */
|
|
|
6b39f76 |
+ opt_tab[11].option = xcstrdup("-noutf8");
|
|
|
6b39f76 |
+ opt_tab[11].specifier = xcstrdup(".noutf8");
|
|
|
6b39f76 |
+ opt_tab[11].argKind = XrmoptionNoArg;
|
|
|
6b39f76 |
+ opt_tab[11].value = (XPointer) xcstrdup("N");
|
|
|
6b39f76 |
+
|
|
|
6b39f76 |
/* parse command line options */
|
|
|
6b39f76 |
doOptMain(argc, argv);
|
|
|
6b39f76 |
|
|
|
6b39f76 |
@@ -450,6 +488,9 @@ main(int argc, char *argv[])
|
|
|
6b39f76 |
/* parse selection command line option */
|
|
|
6b39f76 |
doOptSel();
|
|
|
6b39f76 |
|
|
|
6b39f76 |
+ /* parse noutf8 command line option */
|
|
|
6b39f76 |
+ doOptNoUtf8();
|
|
|
6b39f76 |
+
|
|
|
6b39f76 |
/* Create a window to trap events */
|
|
|
6b39f76 |
win = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 0, 0, 1, 1, 0, 0, 0);
|
|
|
6b39f76 |
|
|
|
6b39f76 |
diff -up xclip-0.10/xclib.h.utf8 xclip-0.10/xclib.h
|
|
|
6b39f76 |
--- xclip-0.10/xclib.h.utf8 2007-08-12 05:47:26.000000000 -0400
|
|
|
6b39f76 |
+++ xclip-0.10/xclib.h 2008-01-14 15:31:03.000000000 -0500
|
|
|
6b39f76 |
@@ -24,6 +24,7 @@
|
|
|
6b39f76 |
#define XCLIB_XCOUT_NONE 0 /* no context */
|
|
|
6b39f76 |
#define XCLIB_XCOUT_SENTCONVSEL 1 /* sent a request */
|
|
|
6b39f76 |
#define XCLIB_XCOUT_INCR 2 /* in an incr loop */
|
|
|
6b39f76 |
+#define XCLIB_XCOUT_FALLBACK 3 /* UTF8_STRING failed, need fallback to XA_STRING */
|
|
|
6b39f76 |
|
|
|
6b39f76 |
/* xcin() contexts */
|
|
|
6b39f76 |
#define XCLIB_XCIN_NONE 0
|
|
|
6b39f76 |
@@ -36,6 +37,7 @@ extern int xcout(
|
|
|
6b39f76 |
Window,
|
|
|
6b39f76 |
XEvent,
|
|
|
6b39f76 |
Atom,
|
|
|
6b39f76 |
+ Atom,
|
|
|
6b39f76 |
unsigned char**,
|
|
|
6b39f76 |
unsigned long*,
|
|
|
6b39f76 |
unsigned int*
|
|
|
6b39f76 |
@@ -45,6 +47,7 @@ extern int xcin(
|
|
|
6b39f76 |
Window*,
|
|
|
6b39f76 |
XEvent,
|
|
|
6b39f76 |
Atom*,
|
|
|
6b39f76 |
+ Atom,
|
|
|
6b39f76 |
unsigned char*,
|
|
|
6b39f76 |
unsigned long,
|
|
|
6b39f76 |
unsigned long*,
|