dwm-meillo
diff util.c @ 11:ea9c08ec4b48
added gridsel to gridwm
author | Anselm R. Garbe <garbeam@wmii.de> |
---|---|
date | Tue, 11 Jul 2006 13:21:57 +0200 |
parents | d567f430a81d |
children | 5c078b66347b |
line diff
1.1 --- a/util.c Tue Jul 11 13:02:22 2006 +0200 1.2 +++ b/util.c Tue Jul 11 13:21:57 2006 +0200 1.3 @@ -10,6 +10,7 @@ 1.4 #include <sys/types.h> 1.5 #include <sys/wait.h> 1.6 #include <unistd.h> 1.7 +#include <X11/Xatom.h> 1.8 1.9 #include "util.h" 1.10 1.11 @@ -147,3 +148,40 @@ 1.12 } 1.13 wait(0); 1.14 } 1.15 + 1.16 + 1.17 +unsigned char * 1.18 +getselection(unsigned long offset, unsigned long *len, unsigned long *remain) 1.19 +{ 1.20 + Display *dpy; 1.21 + Atom xa_clip_string; 1.22 + Window w; 1.23 + XEvent ev; 1.24 + Atom typeret; 1.25 + int format; 1.26 + unsigned char *data; 1.27 + unsigned char *result = NULL; 1.28 + 1.29 + dpy = XOpenDisplay(0); 1.30 + if(!dpy) 1.31 + return NULL; 1.32 + xa_clip_string = XInternAtom(dpy, "_SEL_STRING", False); 1.33 + w = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 10, 10, 200, 200, 1.34 + 1, CopyFromParent, CopyFromParent); 1.35 + XConvertSelection(dpy, XA_PRIMARY, XA_STRING, xa_clip_string, 1.36 + w, CurrentTime); 1.37 + XFlush(dpy); 1.38 + XNextEvent(dpy, &ev); 1.39 + if(ev.type == SelectionNotify && ev.xselection.property != None) { 1.40 + XGetWindowProperty(dpy, w, ev.xselection.property, offset, 4096L, False, 1.41 + AnyPropertyType, &typeret, &format, len, remain, &data); 1.42 + if(*len) { 1.43 + result = emalloc(sizeof(unsigned char) * *len); 1.44 + memcpy(result, data, *len); 1.45 + } 1.46 + XDeleteProperty(dpy, w, ev.xselection.property); 1.47 + } 1.48 + XDestroyWindow(dpy, w); 1.49 + XCloseDisplay(dpy); 1.50 + return result; 1.51 +}