137 close(pfd[0]); |
136 close(pfd[0]); |
138 buf[n - 1] = 0; |
137 buf[n - 1] = 0; |
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 } |
|