diff --git a/cmd/wmiipsel.c b/cmd/wmiipsel.c index 51117b7d..4a5613cd 100644 --- a/cmd/wmiipsel.c +++ b/cmd/wmiipsel.c @@ -7,8 +7,7 @@ #include #include -#include -#include +#include static char version[] = "wmiipsel - " VERSION ", (C)opyright MMIV-MMVI Anselm R. Garbe\n"; @@ -22,8 +21,8 @@ usage() int main(int argc, char **argv) { - char buf[4096]; - unsigned int i, len; + unsigned char *data; + unsigned long i, offset, len, remain; /* command line args */ if(argc > 1) { @@ -33,10 +32,15 @@ main(int argc, char **argv) } else usage(); } - if((len = blitz_getselection(buf, sizeof(buf)))) { + len = offset = 0; + do { + data = blitz_getselection(offset, &len, &remain); for(i = 0; i < len; i++) - putchar(buf[i]); - putchar('\n'); + putchar(data[i]); + offset += len; + free(data); } + while(remain); + putchar('\n'); return 0; } diff --git a/liblitz/blitz.c b/liblitz/blitz.c index 2754e862..78af3bff 100644 --- a/liblitz/blitz.c +++ b/liblitz/blitz.c @@ -3,14 +3,15 @@ * See LICENSE file for license details. */ +#include #include #include #include #include "blitz.h" -unsigned int -blitz_getselection(char *buf, unsigned int len) +unsigned char * +blitz_getselection(unsigned long offset, unsigned long *len, unsigned long *remain) { Display *dpy; Atom xa_clip_string; @@ -18,17 +19,12 @@ blitz_getselection(char *buf, unsigned int len) XEvent ev; Atom typeret; int format; - unsigned long nitems, bytesleft; unsigned char *data; - unsigned int ret; + unsigned char *result = nil; - ret = 0; - if(!buf || !len) - return ret; - buf[0] = 0; dpy = XOpenDisplay(nil); if(!dpy) - return ret; + return nil; xa_clip_string = XInternAtom(dpy, "BLITZ_SEL_STRING", False); w = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 10, 10, 200, 200, 1, CopyFromParent, CopyFromParent); @@ -37,15 +33,16 @@ blitz_getselection(char *buf, unsigned int len) XFlush(dpy); XNextEvent(dpy, &ev); if(ev.type == SelectionNotify && ev.xselection.property != None) { - XGetWindowProperty(dpy, w, ev.xselection.property, 0L, len, False, - AnyPropertyType, &typeret, &format, &nitems, &bytesleft, &data); - if(format == 8) - cext_strlcpy(buf, (const char *)data, len); - ret = nitems < len ? nitems : len - 1; - buf[ret] = 0; + XGetWindowProperty(dpy, w, ev.xselection.property, offset, 4096L, False, + AnyPropertyType, &typeret, &format, len, remain, &data); + if(*len) { + result = cext_emallocz(sizeof(unsigned char) * *len); + memcpy(result, data, *len); + result[*len - 1] = 0; + } XDeleteProperty(dpy, w, ev.xselection.property); } XDestroyWindow(dpy, w); XCloseDisplay(dpy); - return ret; + return result; } diff --git a/liblitz/blitz.h b/liblitz/blitz.h index 08ae5faa..272e682b 100644 --- a/liblitz/blitz.h +++ b/liblitz/blitz.h @@ -89,6 +89,10 @@ struct BlitzInput { void (*draw)(void *aux); }; +/* blitz.c */ +unsigned char *blitz_getselection(unsigned long offset, + unsigned long *len, unsigned long *remain); + /* brush.c */ void blitz_draw_label(BlitzBrush *b, char *text); void blitz_draw_tile(BlitzBrush *b);