145 close(pfd[0]); |
146 close(pfd[0]); |
146 buf[n - 1] = 0; |
147 buf[n - 1] = 0; |
147 } |
148 } |
148 wait(0); |
149 wait(0); |
149 } |
150 } |
|
151 |
|
152 |
|
153 unsigned char * |
|
154 getselection(unsigned long offset, unsigned long *len, unsigned long *remain) |
|
155 { |
|
156 Display *dpy; |
|
157 Atom xa_clip_string; |
|
158 Window w; |
|
159 XEvent ev; |
|
160 Atom typeret; |
|
161 int format; |
|
162 unsigned char *data; |
|
163 unsigned char *result = NULL; |
|
164 |
|
165 dpy = XOpenDisplay(0); |
|
166 if(!dpy) |
|
167 return NULL; |
|
168 xa_clip_string = XInternAtom(dpy, "_SEL_STRING", False); |
|
169 w = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 10, 10, 200, 200, |
|
170 1, CopyFromParent, CopyFromParent); |
|
171 XConvertSelection(dpy, XA_PRIMARY, XA_STRING, xa_clip_string, |
|
172 w, CurrentTime); |
|
173 XFlush(dpy); |
|
174 XNextEvent(dpy, &ev); |
|
175 if(ev.type == SelectionNotify && ev.xselection.property != None) { |
|
176 XGetWindowProperty(dpy, w, ev.xselection.property, offset, 4096L, False, |
|
177 AnyPropertyType, &typeret, &format, len, remain, &data); |
|
178 if(*len) { |
|
179 result = emalloc(sizeof(unsigned char) * *len); |
|
180 memcpy(result, data, *len); |
|
181 } |
|
182 XDeleteProperty(dpy, w, ev.xselection.property); |
|
183 } |
|
184 XDestroyWindow(dpy, w); |
|
185 XCloseDisplay(dpy); |
|
186 return result; |
|
187 } |