diff options
Diffstat (limited to 'util.c')
| -rw-r--r-- | util.c | 38 |
1 files changed, 0 insertions, 38 deletions
| @@ -10,7 +10,6 @@ | |||
| 10 | #include <sys/types.h> | 10 | #include <sys/types.h> |
| 11 | #include <sys/wait.h> | 11 | #include <sys/wait.h> |
| 12 | #include <unistd.h> | 12 | #include <unistd.h> |
| 13 | #include <X11/Xatom.h> | ||
| 14 | 13 | ||
| 15 | #include "util.h" | 14 | #include "util.h" |
| 16 | 15 | ||
| @@ -139,40 +138,3 @@ pipe_spawn(char *buf, unsigned int len, Display *dpy, char *argv[]) | |||
| 139 | } | 138 | } |
| 140 | wait(0); | 139 | wait(0); |
| 141 | } | 140 | } |
| 142 | |||
| 143 | |||
| 144 | unsigned char * | ||
| 145 | getselection(unsigned long offset, unsigned long *len, unsigned long *remain) | ||
| 146 | { | ||
| 147 | Display *dpy; | ||
| 148 | Atom xa_clip_string; | ||
| 149 | Window w; | ||
| 150 | XEvent ev; | ||
| 151 | Atom typeret; | ||
| 152 | int format; | ||
| 153 | unsigned char *data; | ||
| 154 | unsigned char *result = NULL; | ||
| 155 | |||
| 156 | dpy = XOpenDisplay(0); | ||
| 157 | if(!dpy) | ||
| 158 | return NULL; | ||
| 159 | xa_clip_string = XInternAtom(dpy, "_SEL_STRING", False); | ||
| 160 | w = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 10, 10, 200, 200, | ||
| 161 | 1, CopyFromParent, CopyFromParent); | ||
| 162 | XConvertSelection(dpy, XA_PRIMARY, XA_STRING, xa_clip_string, | ||
| 163 | w, CurrentTime); | ||
| 164 | XFlush(dpy); | ||
| 165 | XNextEvent(dpy, &ev); | ||
| 166 | if(ev.type == SelectionNotify && ev.xselection.property != None) { | ||
| 167 | XGetWindowProperty(dpy, w, ev.xselection.property, offset, 4096L, False, | ||
| 168 | AnyPropertyType, &typeret, &format, len, remain, &data); | ||
| 169 | if(*len) { | ||
| 170 | result = emalloc(sizeof(unsigned char) * *len); | ||
| 171 | memcpy(result, data, *len); | ||
| 172 | } | ||
| 173 | XDeleteProperty(dpy, w, ev.xselection.property); | ||
| 174 | } | ||
| 175 | XDestroyWindow(dpy, w); | ||
| 176 | XCloseDisplay(dpy); | ||
| 177 | return result; | ||
| 178 | } | ||
