29 |
|
|
30 |
// static Time selection_timestamp; |
// static Time selection_timestamp; |
31 |
static Atom clipboard_atom, primary_atom, targets_atom, timestamp_atom; |
static Atom clipboard_atom, primary_atom, targets_atom, timestamp_atom; |
32 |
static Atom rdesktop_clipboard_target_atom; |
static Atom rdesktop_clipboard_target_atom, incr_atom; |
33 |
static cliprdr_dataformat *server_formats = NULL; |
static cliprdr_dataformat *server_formats = NULL; |
34 |
static uint16 num_server_formats = 0; |
static uint16 num_server_formats = 0; |
35 |
static XSelectionEvent selection_event; |
static XSelectionEvent selection_event; |
36 |
static uint16 clipboard_channelno; |
static uint16 clipboard_channelno; |
37 |
|
static Atom targets[NUM_TARGETS]; |
38 |
|
|
39 |
static void |
static void |
40 |
cliprdr_print_server_formats(void) |
cliprdr_print_server_formats(void) |
126 |
cliprdr_handle_SelectionNotify(XSelectionEvent *event) |
cliprdr_handle_SelectionNotify(XSelectionEvent *event) |
127 |
{ |
{ |
128 |
|
|
129 |
unsigned char *data; |
unsigned char *data, *datap; |
130 |
unsigned long nitems, bytes_left; |
unsigned long nitems, bytes_left; |
131 |
int res; |
|
132 |
|
unsigned long bytes_left_to_transfer; |
133 |
|
int res, i; |
134 |
|
|
135 |
int format; |
int format; |
136 |
Atom type_return; |
Atom type_return; |
137 |
Atom best_target; |
Atom best_target; |
138 |
|
Atom *supported_targets; |
139 |
|
|
140 |
STREAM out; |
STREAM out; |
141 |
|
|
175 |
{ |
{ |
176 |
/* FIXME: We should choose format here based |
/* FIXME: We should choose format here based |
177 |
on what the server wanted */ |
on what the server wanted */ |
178 |
|
supported_targets = (Atom *)data; |
179 |
|
for (i=0;i<nitems;i++) |
180 |
|
{ |
181 |
|
DEBUG_CLIPBOARD(("Target %d: %s\n", |
182 |
|
i, XGetAtomName(display, |
183 |
|
supported_targets[i]))); |
184 |
|
} |
185 |
best_target = XInternAtom(display, "TEXT", False); |
best_target = XInternAtom(display, "TEXT", False); |
186 |
|
|
187 |
|
|
198 |
|
|
199 |
res = XGetWindowProperty(display, wnd, |
res = XGetWindowProperty(display, wnd, |
200 |
rdesktop_clipboard_target_atom, |
rdesktop_clipboard_target_atom, |
201 |
0L, 4096L, False, AnyPropertyType, |
0L, 0x1FFFFFF, |
202 |
|
True, AnyPropertyType, |
203 |
&type_return, |
&type_return, |
204 |
&format, &nitems, &bytes_left, &data); |
&format, &nitems, &bytes_left, &data); |
205 |
|
|
206 |
|
|
207 |
|
/* FIXME: We need to handle INCR as well, |
208 |
|
this is a temporary solution. */ |
209 |
|
|
210 |
|
if (incr_atom == type_return) |
211 |
|
{ |
212 |
|
warning("We don't support INCR transfers at this time. Try cutting less data\n"); |
213 |
|
cliprdr_send_empty_datapacket(); |
214 |
|
} |
215 |
|
|
216 |
|
|
217 |
if (Success != res) |
if (Success != res) |
218 |
{ |
{ |
219 |
DEBUG_CLIPBOARD(("XGetWindowProperty failed!\n")); |
DEBUG_CLIPBOARD(("XGetWindowProperty failed!\n")); |
221 |
return; |
return; |
222 |
} |
} |
223 |
|
|
224 |
/* We need to handle INCR as well */ |
DEBUG_CLIPBOARD(("Received %d bytes of clipboard data from X, there is %d remaining\n", |
225 |
|
nitems, bytes_left)); |
226 |
|
DEBUG_CLIPBOARD(("type_return is %s\n", |
227 |
|
XGetAtomName(display, type_return))); |
228 |
|
|
229 |
out = sec_init(encryption ? SEC_ENCRYPT : 0, |
datap = data; |
230 |
20+nitems+1); |
|
231 |
out_uint32_le(out, 12+nitems+1); |
if (nitems+1 <= MAX_CLIPRDR_STANDALONE_DATASIZE) |
232 |
out_uint32_le(out, 0x13); |
{ |
233 |
out_uint16_le(out, 5); |
out = sec_init(encryption ? SEC_ENCRYPT : 0, |
234 |
out_uint16_le(out, 1); |
20+nitems+1); |
235 |
out_uint32_le(out, nitems+1); |
out_uint32_le(out, 12+nitems+1); |
236 |
out_uint8p(out, data, nitems+1); |
out_uint32_le(out, 0x13); |
237 |
/* Insert null string here? */ |
out_uint16_le(out, 5); |
238 |
out_uint32_le(out, 0); |
out_uint16_le(out, 1); |
239 |
s_mark_end(out); |
out_uint32_le(out, nitems+1); |
240 |
|
out_uint8p(out, datap, nitems+1); |
241 |
|
out_uint32_le(out, 0); |
242 |
|
s_mark_end(out); |
243 |
|
|
244 |
sec_send_to_channel(out, encryption ? SEC_ENCRYPT : 0, |
sec_send_to_channel(out, encryption ? SEC_ENCRYPT : 0, |
245 |
clipboard_channelno); |
clipboard_channelno); |
246 |
|
|
247 |
|
} |
248 |
|
else |
249 |
|
{ |
250 |
|
DEBUG_CLIPBOARD(("Sending %d bytes of data\n", |
251 |
|
16+MAX_CLIPRDR_STANDALONE_DATASIZE)); |
252 |
|
out = sec_init(encryption ? SEC_ENCRYPT : 0, |
253 |
|
16+MAX_CLIPRDR_STANDALONE_DATASIZE); |
254 |
|
out_uint32_le(out, nitems+12); |
255 |
|
out_uint32_le(out, 0x11); |
256 |
|
out_uint16_le(out, 5); |
257 |
|
out_uint16_le(out, 1); |
258 |
|
out_uint32_le(out, nitems); |
259 |
|
out_uint8p(out, datap, |
260 |
|
MAX_CLIPRDR_STANDALONE_DATASIZE); |
261 |
|
s_mark_end(out); |
262 |
|
|
263 |
|
sec_send_to_channel(out, encryption ? SEC_ENCRYPT : 0, |
264 |
|
clipboard_channelno); |
265 |
|
|
266 |
|
bytes_left_to_transfer = nitems - MAX_CLIPRDR_STANDALONE_DATASIZE; |
267 |
|
datap+=MAX_CLIPRDR_STANDALONE_DATASIZE; |
268 |
|
|
269 |
|
while (bytes_left_to_transfer > MAX_CLIPRDR_STANDALONE_DATASIZE) |
270 |
|
{ |
271 |
|
DEBUG_CLIPBOARD(("Sending %d bytes of data\n", |
272 |
|
16+MAX_CLIPRDR_CONTINUATION_DATASIZE)); |
273 |
|
out = sec_init(encryption ? SEC_ENCRYPT : 0, |
274 |
|
8+MAX_CLIPRDR_CONTINUATION_DATASIZE); |
275 |
|
out_uint32_le(out, nitems); |
276 |
|
out_uint32_le(out, 0x10); |
277 |
|
out_uint8p(out, datap, |
278 |
|
MAX_CLIPRDR_CONTINUATION_DATASIZE); |
279 |
|
s_mark_end(out); |
280 |
|
|
281 |
|
sec_send_to_channel(out, |
282 |
|
encryption ? SEC_ENCRYPT : 0, |
283 |
|
clipboard_channelno); |
284 |
|
bytes_left_to_transfer-= MAX_CLIPRDR_CONTINUATION_DATASIZE; |
285 |
|
datap+=MAX_CLIPRDR_CONTINUATION_DATASIZE; |
286 |
|
|
287 |
|
} |
288 |
|
DEBUG_CLIPBOARD(("Sending %d bytes of data\n", |
289 |
|
12+bytes_left_to_transfer)); |
290 |
|
out = sec_init(encryption ? SEC_ENCRYPT : 0, |
291 |
|
12+bytes_left_to_transfer); |
292 |
|
out_uint32_le(out, nitems); |
293 |
|
out_uint32_le(out, 0x12); |
294 |
|
out_uint8p(out, datap, |
295 |
|
bytes_left_to_transfer); |
296 |
|
out_uint32_le(out, 0x0); |
297 |
|
s_mark_end(out); |
298 |
|
|
299 |
|
sec_send_to_channel(out, encryption ? SEC_ENCRYPT : 0, |
300 |
|
clipboard_channelno); |
301 |
|
|
302 |
|
} |
303 |
|
|
304 |
|
|
305 |
|
XFree(data); |
306 |
cliprdr_send_format_announce(); |
cliprdr_send_format_announce(); |
307 |
|
|
308 |
} |
} |
342 |
cliprdr_handle_SelectionRequest(XSelectionRequestEvent *xevent) |
cliprdr_handle_SelectionRequest(XSelectionRequestEvent *xevent) |
343 |
{ |
{ |
344 |
|
|
|
Atom *targets; |
|
|
int res; |
|
|
|
|
345 |
XSelectionEvent xev; |
XSelectionEvent xev; |
346 |
DEBUG_CLIPBOARD(("cliprdr_handle_SelectionRequest\n")); |
DEBUG_CLIPBOARD(("cliprdr_handle_SelectionRequest\n")); |
347 |
DEBUG_CLIPBOARD(("Requestor window id 0x%x ", |
DEBUG_CLIPBOARD(("Requestor window id 0x%x ", |
370 |
if (targets_atom == xevent->target) |
if (targets_atom == xevent->target) |
371 |
{ |
{ |
372 |
DEBUG_CLIPBOARD(("TARGETS requested, sending list..\n")); |
DEBUG_CLIPBOARD(("TARGETS requested, sending list..\n")); |
373 |
targets = xmalloc(4*sizeof(Atom)); |
XChangeProperty(display, |
374 |
targets[0] = xevent->target; |
xevent->requestor, |
375 |
targets[1] = XInternAtom(display, "TEXT", True); |
xevent->property, |
376 |
targets[2] = XInternAtom(display, "UTF8_STRING", True); |
XA_ATOM, |
377 |
targets[3] = XInternAtom(display, "TIMESTAMP", True); |
32, |
378 |
res = XChangeProperty(display, |
PropModeAppend, |
379 |
xevent->requestor, |
(unsigned char *)&targets, |
380 |
xevent->property, |
NUM_TARGETS); |
381 |
XA_ATOM, |
|
382 |
32, |
XSendEvent(display, |
383 |
PropModeAppend, |
xevent->requestor, |
384 |
(unsigned char *)targets, |
False, |
385 |
3); |
NoEventMask, |
386 |
|
(XEvent *)&xev); |
|
res = XSendEvent(display, |
|
|
xevent->requestor, |
|
|
False, |
|
|
NoEventMask, |
|
|
(XEvent *)&xev); |
|
387 |
return; |
return; |
388 |
} else if (timestamp_atom == xevent->target) |
} else if (timestamp_atom == xevent->target) |
389 |
{ |
{ |
390 |
DEBUG_CLIPBOARD(("TIMESTAMP requested... sending 0x%x\n", |
XChangeProperty(display, |
391 |
(unsigned)last_gesturetime)); |
xevent->requestor, |
392 |
res = XChangeProperty(display, |
xevent->property, |
393 |
xevent->requestor, |
XA_INTEGER, |
394 |
xevent->property, |
32, |
395 |
XA_INTEGER, |
PropModeAppend, |
396 |
32, |
(unsigned char *)&last_gesturetime, |
397 |
PropModeAppend, |
1); |
398 |
(unsigned char *)&last_gesturetime, |
XSendEvent(display, |
399 |
1); |
xevent->requestor, |
400 |
res = XSendEvent(display, |
False, |
401 |
xevent->requestor, |
NoEventMask, |
402 |
False, |
(XEvent *)&xev); |
|
NoEventMask, |
|
|
(XEvent *)&xev); |
|
403 |
} else /* Some other target */ |
} else /* Some other target */ |
404 |
{ |
{ |
405 |
cliprdr_request_clipboard_data(CF_TEXT); |
cliprdr_request_clipboard_data(CF_TEXT); |
649 |
targets_atom = XInternAtom(display, "TARGETS", False); |
targets_atom = XInternAtom(display, "TARGETS", False); |
650 |
timestamp_atom = XInternAtom(display, "TIMESTAMP", False); |
timestamp_atom = XInternAtom(display, "TIMESTAMP", False); |
651 |
rdesktop_clipboard_target_atom = XInternAtom(display, "_RDESKTOP_CLIPBOARD_TARGET", False); |
rdesktop_clipboard_target_atom = XInternAtom(display, "_RDESKTOP_CLIPBOARD_TARGET", False); |
652 |
|
incr_atom = XInternAtom(display, "INCR", False); |
653 |
|
targets[0] = targets_atom; |
654 |
|
targets[1] = XInternAtom(display, "TEXT", False); |
655 |
|
targets[2] = XInternAtom(display, "UTF8_STRING", False); |
656 |
|
targets[3] = XInternAtom(display, "text/unicode", False); |
657 |
|
targets[4] = XInternAtom(display, "TIMESTAMP", False); |
658 |
|
targets[5] = XInternAtom(display, "STRING", False); |
659 |
|
|
660 |
} |
} |