commit 09da2b8809865f0c4e4fa26f40206fb2945602b4
parent c14d2644758b1a9111db1629e11915f4bebccbda
Author: Anselm R. Garbe <garbeam@wmii.de>
Date: Thu, 6 Jul 2006 16:03:28 +0200
implemented blitz_getselection function which is called by wmiipsel now and will be used for paste, blitz_setselection is on todo for snarfing
Diffstat:
4 files changed, 59 insertions(+), 53 deletions(-)
diff --git a/cmd/Makefile b/cmd/Makefile
@@ -5,7 +5,7 @@ include ../config.mk
CFLAGS += -I../liblitz -I../libixp -I../libcext
LDFLAGS += -L../libixp -lixp -L../libcext -lcext
-X11LDFLAGS += -L../liblitz -llitz
+X11LDFLAGS += -L../liblitz -llitz -L../libcext -lcext
X11SRC = wmiimenu.c wmiipsel.c wmiiwarp.c
SRC = wmiir.c wmiisetsid.c
diff --git a/cmd/wmiipsel.c b/cmd/wmiipsel.c
@@ -19,34 +19,11 @@ usage()
exit(1);
}
-static void
-print_sel(Display *dpy, Window w, XSelectionEvent * e)
-{
- Atom typeret;
- int format;
- unsigned long nitems, bytesleft;
- unsigned char *data;
-
- XGetWindowProperty(dpy, w, e->property, 0L, 4096L, False,
- AnyPropertyType, &typeret, &format,
- &nitems, &bytesleft, &data);
- if(format == 8) {
- int i;
- for(i = 0; i < nitems; i++)
- putchar(data[i]);
- putchar('\n');
- }
- XDeleteProperty(dpy, w, e->property);
-}
-
int
main(int argc, char **argv)
{
- Display *dpy;
- Atom xa_clip_string;
- Window w;
- XEvent ev;
- int pdone = 0;
+ char buf[4096];
+ unsigned int i, len;
/* command line args */
if(argc > 1) {
@@ -56,32 +33,10 @@ main(int argc, char **argv)
} else
usage();
}
- dpy = XOpenDisplay(0);
- if(!dpy) {
- fprintf(stderr, "%s", "wmiipsel: cannot open display\n");
- exit(1);
- }
- xa_clip_string = XInternAtom(dpy, "WMII_PSEL_STRING", False);
- w = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 10, 10, 200, 200,
- 1, CopyFromParent, CopyFromParent);
- while(!pdone) {
- XConvertSelection(dpy, XA_PRIMARY, XA_STRING, xa_clip_string,
- w, CurrentTime);
- XFlush(dpy);
- XNextEvent(dpy, &ev);
- switch (ev.type) {
- case SelectionNotify:
- if(ev.xselection.property != None)
- print_sel(dpy, w, &ev.xselection);
- else
- putchar('\n');
- XDestroyWindow(dpy, w);
- XCloseDisplay(dpy);
- pdone = 1;
- break;
- default:
- break;
- }
+ if((len = blitz_getselection(buf, sizeof(buf)))) {
+ for(i = 0; i < len; i++)
+ putchar(buf[i]);
+ putchar('\n');
}
return 0;
}
diff --git a/liblitz/Makefile b/liblitz/Makefile
@@ -6,7 +6,7 @@ include ../config.mk
CFLAGS += -I../libixp -I../libcext
LDFLAGS += -L../libixp -lixp -L../libcext -lcext
-SRC = brush.c color.c draw.c font.c input.c
+SRC = blitz.c brush.c color.c draw.c font.c input.c
OBJ = ${SRC:.c=.o}
all: liblitz.a
diff --git a/liblitz/blitz.c b/liblitz/blitz.c
@@ -0,0 +1,51 @@
+/*
+ * (C)opyright MMIV-MMVI Anselm R. Garbe <garbeam at gmail dot com>
+ * See LICENSE file for license details.
+ */
+
+#include <cext.h>
+#include <X11/Xlib.h>
+#include <X11/Xatom.h>
+
+#include "blitz.h"
+
+unsigned int
+blitz_getselection(char *buf, unsigned int len)
+{
+ Display *dpy;
+ Atom xa_clip_string;
+ Window w;
+ XEvent ev;
+ Atom typeret;
+ int format;
+ unsigned long nitems, bytesleft;
+ unsigned char *data;
+ unsigned int ret;
+
+ ret = 0;
+ if(!buf || !len)
+ return ret;
+ buf[0] = 0;
+ dpy = XOpenDisplay(nil);
+ if(!dpy)
+ return ret;
+ xa_clip_string = XInternAtom(dpy, "BLITZ_SEL_STRING", False);
+ w = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 10, 10, 200, 200,
+ 1, CopyFromParent, CopyFromParent);
+ XConvertSelection(dpy, XA_PRIMARY, XA_STRING, xa_clip_string,
+ w, CurrentTime);
+ 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;
+ XDeleteProperty(dpy, w, ev.xselection.property);
+ }
+ XDestroyWindow(dpy, w);
+ XCloseDisplay(dpy);
+ return ret;
+}