commit 5b91425d2b716a4aaf86d8f80b806faaedd54a65
parent 09da2b8809865f0c4e4fa26f40206fb2945602b4
Author: Anselm R. Garbe <garbeam@wmii.de>
Date: Thu, 6 Jul 2006 16:40:33 +0200
added offset handling to blitz_getselection and wmiipsel (works like a charm)
Diffstat:
3 files changed, 28 insertions(+), 23 deletions(-)
diff --git a/cmd/wmiipsel.c b/cmd/wmiipsel.c
@@ -7,8 +7,7 @@
#include <stdio.h>
#include <string.h>
-#include <X11/Xlib.h>
-#include <X11/Xatom.h>
+#include <blitz.h>
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
@@ -3,14 +3,15 @@
* See LICENSE file for license details.
*/
+#include <string.h>
#include <cext.h>
#include <X11/Xlib.h>
#include <X11/Xatom.h>
#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
@@ -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);