26 |
extern Display *display; |
extern Display *display; |
27 |
extern Window wnd; |
extern Window wnd; |
28 |
extern Time last_gesturetime; |
extern Time last_gesturetime; |
29 |
|
extern Atom ipc_atom; |
30 |
|
|
31 |
// static Time selection_timestamp; |
// static Time selection_timestamp; |
32 |
static Atom clipboard_atom, primary_atom, targets_atom, timestamp_atom; |
static Atom clipboard_atom, primary_atom, targets_atom, timestamp_atom; |
33 |
static Atom rdesktop_clipboard_target_atom; |
static Atom rdesktop_clipboard_target_atom, incr_atom; |
34 |
static cliprdr_dataformat *server_formats = NULL; |
static cliprdr_dataformat *server_formats = NULL; |
35 |
static uint16 num_server_formats = 0; |
static uint16 num_server_formats = 0; |
36 |
static XSelectionEvent selection_event; |
static XSelectionEvent selection_event; |
37 |
|
static uint16 clipboard_channelno; |
38 |
|
static Atom targets[NUM_TARGETS]; |
39 |
|
static int have_primary = 0; |
40 |
|
static int rdesktop_is_selection_owner = 0; |
41 |
|
|
42 |
static void |
static void |
43 |
cliprdr_print_server_formats(void) |
cliprdr_print_server_formats(void) |
78 |
static void |
static void |
79 |
cliprdr_send_format_announce(void) |
cliprdr_send_format_announce(void) |
80 |
{ |
{ |
81 |
DEBUG_CLIPBOARD(("Sending format announce\n")); |
DEBUG_CLIPBOARD(("Sending (empty) format announce\n")); |
82 |
|
|
83 |
STREAM s; |
STREAM s; |
84 |
int number_of_formats = 1; |
int number_of_formats = 1; |
100 |
out_uint32_le(s, 0); |
out_uint32_le(s, 0); |
101 |
|
|
102 |
s_mark_end(s); |
s_mark_end(s); |
103 |
sec_send_to_channel(s, encryption ? SEC_ENCRYPT : 0, 1005); // FIXME: Don't hardcode channel! |
sec_send_to_channel(s, encryption ? SEC_ENCRYPT : 0, |
104 |
|
clipboard_channelno); |
105 |
|
} |
106 |
|
|
107 |
|
void cliprdr_ipc_format_announce(unsigned char *data, uint16 length) |
108 |
|
{ |
109 |
|
STREAM s; |
110 |
|
rdesktop_is_selection_owner = 1; |
111 |
|
DEBUG_CLIPBOARD(("cliprdr_ipc_format_announce called, length is %d, data is %s, sending native format announce\n", length, data)); |
112 |
|
|
113 |
|
s = sec_init(encryption ? SEC_ENCRYPT : 0, length+12+4+4); |
114 |
|
out_uint32_le(s, length+12); |
115 |
|
out_uint32_le(s, 0x13); |
116 |
|
out_uint16_le(s, 2); |
117 |
|
out_uint16_le(s, 0); |
118 |
|
out_uint32_le(s, length); |
119 |
|
out_uint8p(s, data, length); |
120 |
|
out_uint32_le(s, 0); // Pad |
121 |
|
s_mark_end(s); |
122 |
|
|
123 |
|
sec_send_to_channel(s, encryption ? SEC_ENCRYPT : 0, |
124 |
|
clipboard_channelno); |
125 |
} |
} |
126 |
|
|
127 |
|
|
128 |
|
|
129 |
|
|
130 |
static void |
static void |
131 |
cliprdr_send_empty_datapacket(void) |
cliprdr_send_empty_datapacket(void) |
132 |
{ |
{ |
142 |
out_uint32_le(out, 0); |
out_uint32_le(out, 0); |
143 |
s_mark_end(out); |
s_mark_end(out); |
144 |
|
|
145 |
sec_send_to_channel(out, encryption ? SEC_ENCRYPT : 0, 1005); // FIXME: Don't hardcode channel! |
sec_send_to_channel(out, encryption ? SEC_ENCRYPT : 0, |
146 |
|
clipboard_channelno); |
147 |
} |
} |
148 |
|
|
149 |
|
|
151 |
cliprdr_handle_SelectionNotify(XSelectionEvent *event) |
cliprdr_handle_SelectionNotify(XSelectionEvent *event) |
152 |
{ |
{ |
153 |
|
|
154 |
unsigned char *data; |
unsigned char *data, *datap; |
155 |
unsigned long nitems, bytes_left; |
unsigned long nitems, bytes_left; |
156 |
int res; |
|
157 |
|
unsigned long bytes_left_to_transfer; |
158 |
|
int res, i; |
159 |
|
|
160 |
int format; |
int format; |
161 |
Atom type_return; |
Atom type_return; |
162 |
Atom best_target; |
Atom best_target; |
163 |
|
Atom *supported_targets; |
164 |
|
|
165 |
STREAM out; |
STREAM out; |
166 |
|
|
200 |
{ |
{ |
201 |
/* FIXME: We should choose format here based |
/* FIXME: We should choose format here based |
202 |
on what the server wanted */ |
on what the server wanted */ |
203 |
|
supported_targets = (Atom *)data; |
204 |
|
for (i=0;i<nitems;i++) |
205 |
|
{ |
206 |
|
DEBUG_CLIPBOARD(("Target %d: %s\n", |
207 |
|
i, XGetAtomName(display, |
208 |
|
supported_targets[i]))); |
209 |
|
} |
210 |
best_target = XInternAtom(display, "TEXT", False); |
best_target = XInternAtom(display, "TEXT", False); |
211 |
|
|
212 |
|
|
218 |
wnd, event->time); |
wnd, event->time); |
219 |
|
|
220 |
} |
} |
221 |
|
|
222 |
else /* Other clipboard data */ |
else /* Other clipboard data */ |
223 |
{ |
{ |
224 |
|
|
225 |
res = XGetWindowProperty(display, wnd, |
res = XGetWindowProperty(display, wnd, |
226 |
rdesktop_clipboard_target_atom, |
rdesktop_clipboard_target_atom, |
227 |
0L, 4096L, False, AnyPropertyType, |
0L, 0x1FFFFFF, |
228 |
|
True, AnyPropertyType, |
229 |
&type_return, |
&type_return, |
230 |
&format, &nitems, &bytes_left, &data); |
&format, &nitems, &bytes_left, &data); |
231 |
|
|
232 |
|
|
233 |
|
/* FIXME: We need to handle INCR as well, |
234 |
|
this is a temporary solution. */ |
235 |
|
|
236 |
|
if (incr_atom == type_return) |
237 |
|
{ |
238 |
|
warning("We don't support INCR transfers at this time. Try cutting less data\n"); |
239 |
|
cliprdr_send_empty_datapacket(); |
240 |
|
} |
241 |
|
|
242 |
|
|
243 |
if (Success != res) |
if (Success != res) |
244 |
{ |
{ |
245 |
DEBUG_CLIPBOARD(("XGetWindowProperty failed!\n")); |
DEBUG_CLIPBOARD(("XGetWindowProperty failed!\n")); |
247 |
return; |
return; |
248 |
} |
} |
249 |
|
|
250 |
/* We need to handle INCR as well */ |
DEBUG_CLIPBOARD(("Received %d bytes of clipboard data from X, there is %d remaining\n", |
251 |
|
nitems, bytes_left)); |
252 |
|
DEBUG_CLIPBOARD(("type_return is %s\n", |
253 |
|
XGetAtomName(display, type_return))); |
254 |
|
|
255 |
|
datap = data; |
256 |
|
|
257 |
|
if (nitems+1 <= MAX_CLIPRDR_STANDALONE_DATASIZE) |
258 |
|
{ |
259 |
|
out = sec_init(encryption ? SEC_ENCRYPT : 0, |
260 |
|
20+nitems+1); |
261 |
|
out_uint32_le(out, 12+nitems+1); |
262 |
|
out_uint32_le(out, 0x13); |
263 |
|
out_uint16_le(out, 5); |
264 |
|
out_uint16_le(out, 1); |
265 |
|
out_uint32_le(out, nitems+1); |
266 |
|
out_uint8p(out, datap, nitems+1); |
267 |
|
out_uint32_le(out, 0); |
268 |
|
s_mark_end(out); |
269 |
|
|
270 |
|
sec_send_to_channel(out, encryption ? SEC_ENCRYPT : 0, |
271 |
|
clipboard_channelno); |
272 |
|
|
273 |
out = sec_init(encryption ? SEC_ENCRYPT : 0, |
} |
274 |
20+nitems); |
else |
275 |
out_uint32_le(out, 12+nitems); |
{ |
276 |
out_uint32_le(out, 0x13); |
DEBUG_CLIPBOARD(("Sending %d bytes of data\n", |
277 |
out_uint16_le(out, 5); |
16+MAX_CLIPRDR_STANDALONE_DATASIZE)); |
278 |
out_uint16_le(out, 1); |
out = sec_init(encryption ? SEC_ENCRYPT : 0, |
279 |
out_uint32_le(out, nitems); |
16+MAX_CLIPRDR_STANDALONE_DATASIZE); |
280 |
out_uint8p(out, data, nitems); |
out_uint32_le(out, nitems+12); |
281 |
/* Insert null string here? */ |
out_uint32_le(out, 0x11); |
282 |
out_uint32_le(out, 0); |
out_uint16_le(out, 5); |
283 |
s_mark_end(out); |
out_uint16_le(out, 1); |
284 |
|
out_uint32_le(out, nitems); |
285 |
|
out_uint8p(out, datap, |
286 |
|
MAX_CLIPRDR_STANDALONE_DATASIZE); |
287 |
|
s_mark_end(out); |
288 |
|
|
289 |
|
sec_send_to_channel(out, encryption ? SEC_ENCRYPT : 0, |
290 |
|
clipboard_channelno); |
291 |
|
|
292 |
|
bytes_left_to_transfer = nitems - MAX_CLIPRDR_STANDALONE_DATASIZE; |
293 |
|
datap+=MAX_CLIPRDR_STANDALONE_DATASIZE; |
294 |
|
|
295 |
|
while (bytes_left_to_transfer > MAX_CLIPRDR_STANDALONE_DATASIZE) |
296 |
|
{ |
297 |
|
DEBUG_CLIPBOARD(("Sending %d bytes of data\n", |
298 |
|
16+MAX_CLIPRDR_CONTINUATION_DATASIZE)); |
299 |
|
out = sec_init(encryption ? SEC_ENCRYPT : 0, |
300 |
|
8+MAX_CLIPRDR_CONTINUATION_DATASIZE); |
301 |
|
out_uint32_le(out, nitems); |
302 |
|
out_uint32_le(out, 0x10); |
303 |
|
out_uint8p(out, datap, |
304 |
|
MAX_CLIPRDR_CONTINUATION_DATASIZE); |
305 |
|
s_mark_end(out); |
306 |
|
|
307 |
|
sec_send_to_channel(out, |
308 |
|
encryption ? SEC_ENCRYPT : 0, |
309 |
|
clipboard_channelno); |
310 |
|
bytes_left_to_transfer-= MAX_CLIPRDR_CONTINUATION_DATASIZE; |
311 |
|
datap+=MAX_CLIPRDR_CONTINUATION_DATASIZE; |
312 |
|
|
313 |
|
} |
314 |
|
DEBUG_CLIPBOARD(("Sending %d bytes of data\n", |
315 |
|
12+bytes_left_to_transfer)); |
316 |
|
out = sec_init(encryption ? SEC_ENCRYPT : 0, |
317 |
|
12+bytes_left_to_transfer); |
318 |
|
out_uint32_le(out, nitems); |
319 |
|
out_uint32_le(out, 0x12); |
320 |
|
out_uint8p(out, datap, |
321 |
|
bytes_left_to_transfer); |
322 |
|
out_uint32_le(out, 0x0); |
323 |
|
s_mark_end(out); |
324 |
|
|
325 |
sec_send_to_channel(out, encryption ? SEC_ENCRYPT : 0, 1005); // FIXME: Don't hardcode channel! |
sec_send_to_channel(out, encryption ? SEC_ENCRYPT : 0, |
326 |
|
clipboard_channelno); |
327 |
|
|
328 |
cliprdr_send_format_announce(); |
} |
329 |
|
|
330 |
|
|
331 |
|
XFree(data); |
332 |
|
if (!rdesktop_clipboard_target_atom) |
333 |
|
cliprdr_send_format_announce(); |
334 |
|
|
335 |
} |
} |
336 |
|
|
341 |
cliprdr_handle_SelectionClear(void) |
cliprdr_handle_SelectionClear(void) |
342 |
{ |
{ |
343 |
DEBUG_CLIPBOARD(("cliprdr_handle_SelectionClear\n")); |
DEBUG_CLIPBOARD(("cliprdr_handle_SelectionClear\n")); |
344 |
|
have_primary = 0; |
345 |
|
ipc_send_message(RDESKTOP_IPC_CLIPRDR_PRIMARY_LOST, |
346 |
|
"", 0); |
347 |
cliprdr_send_format_announce(); |
cliprdr_send_format_announce(); |
348 |
} |
} |
349 |
|
|
363 |
|
|
364 |
s_mark_end(s); |
s_mark_end(s); |
365 |
|
|
366 |
sec_send_to_channel(s, encryption ? SEC_ENCRYPT : 0, 1005); // FIXME: Don't hardcode channel! |
sec_send_to_channel(s, encryption ? SEC_ENCRYPT : 0, |
367 |
|
clipboard_channelno); |
368 |
} |
} |
369 |
|
|
370 |
|
|
372 |
cliprdr_handle_SelectionRequest(XSelectionRequestEvent *xevent) |
cliprdr_handle_SelectionRequest(XSelectionRequestEvent *xevent) |
373 |
{ |
{ |
374 |
|
|
|
Atom *targets; |
|
|
int res; |
|
|
|
|
375 |
XSelectionEvent xev; |
XSelectionEvent xev; |
376 |
|
unsigned char *data; |
377 |
|
unsigned long nitems, bytes_left; |
378 |
|
Atom type_return; |
379 |
|
uint32 *wanted_formatcode; |
380 |
|
int format; |
381 |
|
|
382 |
DEBUG_CLIPBOARD(("cliprdr_handle_SelectionRequest\n")); |
DEBUG_CLIPBOARD(("cliprdr_handle_SelectionRequest\n")); |
383 |
DEBUG_CLIPBOARD(("Requestor window id 0x%x ", |
DEBUG_CLIPBOARD(("Requestor window id 0x%x ", |
384 |
(unsigned)xevent->requestor)); |
(unsigned)xevent->requestor)); |
403 |
xev.property = xevent->property; |
xev.property = xevent->property; |
404 |
xev.time = xevent->time; |
xev.time = xevent->time; |
405 |
|
|
406 |
if (targets_atom == xevent->target) |
memcpy(&selection_event, &xev, sizeof(xev)); |
407 |
|
|
408 |
|
if (ipc_atom == xevent->target) |
409 |
|
{ |
410 |
|
DEBUG_CLIPBOARD(("Target atom is ipc_atom, getting INTEGER from requestor\n")); |
411 |
|
XGetWindowProperty(display, xevent->requestor, |
412 |
|
rdesktop_clipboard_target_atom, |
413 |
|
0, |
414 |
|
1, |
415 |
|
True, XA_INTEGER, |
416 |
|
&type_return, |
417 |
|
&format, |
418 |
|
&nitems, |
419 |
|
&bytes_left, |
420 |
|
&wanted_formatcode); |
421 |
|
DEBUG_CLIPBOARD(("Got wanted formatcode %d, format is %d\n", *wanted_formatcode, format)); |
422 |
|
cliprdr_request_clipboard_data(*wanted_formatcode); |
423 |
|
} |
424 |
|
|
425 |
|
else if (targets_atom == xevent->target) |
426 |
{ |
{ |
427 |
DEBUG_CLIPBOARD(("TARGETS requested, sending list..\n")); |
DEBUG_CLIPBOARD(("TARGETS requested, sending list..\n")); |
428 |
targets = xmalloc(4*sizeof(Atom)); |
XChangeProperty(display, |
429 |
targets[0] = xevent->target; |
xevent->requestor, |
430 |
targets[1] = XInternAtom(display, "TEXT", True); |
xevent->property, |
431 |
targets[2] = XInternAtom(display, "UTF8_STRING", True); |
XA_ATOM, |
432 |
targets[3] = XInternAtom(display, "TIMESTAMP", True); |
32, |
433 |
res = XChangeProperty(display, |
PropModeAppend, |
434 |
xevent->requestor, |
(unsigned char *)&targets, |
435 |
xevent->property, |
NUM_TARGETS); |
436 |
XA_ATOM, |
|
437 |
32, |
XSendEvent(display, |
438 |
PropModeAppend, |
xevent->requestor, |
439 |
(unsigned char *)targets, |
False, |
440 |
3); |
NoEventMask, |
441 |
|
(XEvent *)&xev); |
|
res = XSendEvent(display, |
|
|
xevent->requestor, |
|
|
False, |
|
|
NoEventMask, |
|
|
(XEvent *)&xev); |
|
442 |
return; |
return; |
443 |
} else if (timestamp_atom == xevent->target) |
} else if (timestamp_atom == xevent->target) |
444 |
{ |
{ |
445 |
DEBUG_CLIPBOARD(("TIMESTAMP requested... sending 0x%x\n", |
XChangeProperty(display, |
446 |
(unsigned)last_gesturetime)); |
xevent->requestor, |
447 |
res = XChangeProperty(display, |
xevent->property, |
448 |
xevent->requestor, |
XA_INTEGER, |
449 |
xevent->property, |
32, |
450 |
XA_INTEGER, |
PropModeAppend, |
451 |
32, |
(unsigned char *)&last_gesturetime, |
452 |
PropModeAppend, |
1); |
453 |
(unsigned char *)&last_gesturetime, |
XSendEvent(display, |
454 |
1); |
xevent->requestor, |
455 |
res = XSendEvent(display, |
False, |
456 |
xevent->requestor, |
NoEventMask, |
457 |
False, |
(XEvent *)&xev); |
|
NoEventMask, |
|
|
(XEvent *)&xev); |
|
458 |
} else /* Some other target */ |
} else /* Some other target */ |
459 |
{ |
{ |
460 |
cliprdr_request_clipboard_data(CF_TEXT); |
cliprdr_request_clipboard_data(CF_TEXT); |
|
memcpy(&selection_event, &xev, sizeof(xev)); |
|
461 |
/* Return and wait for data, handled by |
/* Return and wait for data, handled by |
462 |
cliprdr_handle_server_data */ |
cliprdr_handle_server_data */ |
463 |
} |
} |
478 |
|
|
479 |
s_mark_end(s); |
s_mark_end(s); |
480 |
|
|
481 |
sec_send_to_channel(s, encryption ? SEC_ENCRYPT : 0, 1005); // FIXME: Don't hardcode channel! |
sec_send_to_channel(s, encryption ? SEC_ENCRYPT : 0, |
482 |
|
clipboard_channelno); |
483 |
} |
} |
484 |
|
|
485 |
|
|
493 |
uint16 num_formats; |
uint16 num_formats; |
494 |
cliprdr_dataformat *this, *next; |
cliprdr_dataformat *this, *next; |
495 |
|
|
|
DEBUG_CLIPBOARD(("cliprdr_register_server_formats\n")); |
|
496 |
in_uint32_le(s, remaining_length); |
in_uint32_le(s, remaining_length); |
497 |
|
DEBUG_CLIPBOARD(("cliprdr_register_server_formats, remaining_length is %d\n", remaining_length)); |
498 |
|
|
499 |
|
|
500 |
num_formats = remaining_length / 36; |
num_formats = remaining_length / 36; |
501 |
|
|
502 |
|
ipc_send_message(RDESKTOP_IPC_CLIPRDR_FORMAT_ANNOUNCE, |
503 |
|
s->p, remaining_length); |
504 |
if (NULL != server_formats) { |
if (NULL != server_formats) { |
505 |
this = server_formats; |
this = server_formats; |
506 |
next = this->next; |
next = this->next; |
539 |
if (wnd != XGetSelectionOwner(display, primary_atom)) |
if (wnd != XGetSelectionOwner(display, primary_atom)) |
540 |
{ |
{ |
541 |
warning("Failed to aquire ownership of PRIMARY clipboard\n"); |
warning("Failed to aquire ownership of PRIMARY clipboard\n"); |
542 |
|
} |
543 |
|
else |
544 |
|
{ |
545 |
|
have_primary = 1; |
546 |
} |
} |
547 |
XSetSelectionOwner(display, clipboard_atom, wnd, last_gesturetime); |
XSetSelectionOwner(display, clipboard_atom, wnd, last_gesturetime); |
548 |
if (wnd != XGetSelectionOwner(display, clipboard_atom)) |
if (wnd != XGetSelectionOwner(display, clipboard_atom)) |
552 |
|
|
553 |
} |
} |
554 |
|
|
|
|
|
|
|
|
555 |
|
|
556 |
|
|
557 |
static void |
static void |
565 |
cliprdr_send_format_announce(); |
cliprdr_send_format_announce(); |
566 |
} |
} |
567 |
|
|
568 |
void cliprdr_handle_server_data(uint32 length, STREAM s) |
void cliprdr_handle_server_data(uint32 length, uint32 flags, STREAM s) |
569 |
{ |
{ |
570 |
uint32 remaining_length; |
static uint32 remaining_length; |
571 |
char *data; |
static char *data, *datap; |
572 |
in_uint32_le(s, remaining_length); |
static uint32 bytes_left_to_read; |
573 |
data = s->p; |
DEBUG_CLIPBOARD(("In cliprdr_handle_server_data, flags is %d\n", |
574 |
|
flags)); |
575 |
|
if (3 == flags) /* One-op write, no packets follows */ |
576 |
|
{ |
577 |
|
in_uint32_le(s, remaining_length); |
578 |
|
data = s->p; |
579 |
|
} else if (1 == flags) /* First of several packets */ |
580 |
|
{ |
581 |
|
in_uint32_le(s, remaining_length); |
582 |
|
DEBUG_CLIPBOARD(("Remaining length is %d\n", |
583 |
|
remaining_length)); |
584 |
|
data = xmalloc(remaining_length); |
585 |
|
datap = data; |
586 |
|
DEBUG_CLIPBOARD(("Copying first %d bytes\n", |
587 |
|
MAX_CLIPRDR_STANDALONE_DATASIZE)); |
588 |
|
memcpy(datap, s->p, MAX_CLIPRDR_STANDALONE_DATASIZE); |
589 |
|
|
590 |
|
datap+=MAX_CLIPRDR_STANDALONE_DATASIZE; |
591 |
|
bytes_left_to_read = remaining_length-MAX_CLIPRDR_STANDALONE_DATASIZE; |
592 |
|
return; |
593 |
|
} else if (0 == flags) |
594 |
|
{ |
595 |
|
DEBUG_CLIPBOARD(("Copying %d middle bytes", |
596 |
|
MAX_CLIPRDR_CONTINUATION_DATASIZE)); |
597 |
|
memcpy(datap, s->p, MAX_CLIPRDR_CONTINUATION_DATASIZE); |
598 |
|
|
599 |
|
datap+=MAX_CLIPRDR_CONTINUATION_DATASIZE; |
600 |
|
bytes_left_to_read-=MAX_CLIPRDR_CONTINUATION_DATASIZE; |
601 |
|
return; |
602 |
|
} else if (2 == flags) |
603 |
|
{ |
604 |
|
DEBUG_CLIPBOARD(("Copying last %d bytes\n", |
605 |
|
bytes_left_to_read)); |
606 |
|
memcpy(datap, s->p, bytes_left_to_read); |
607 |
|
} |
608 |
XChangeProperty(display, |
XChangeProperty(display, |
609 |
selection_event.requestor, |
selection_event.requestor, |
610 |
selection_event.property, |
selection_event.property, |
612 |
8, |
8, |
613 |
PropModeAppend, |
PropModeAppend, |
614 |
data, |
data, |
615 |
remaining_length); |
remaining_length-1); |
616 |
|
|
617 |
XSendEvent(display, |
XSendEvent(display, |
618 |
selection_event.requestor, |
selection_event.requestor, |
619 |
False, |
False, |
620 |
NoEventMask, |
NoEventMask, |
621 |
(XEvent *)&selection_event); |
(XEvent *)&selection_event); |
622 |
|
|
623 |
|
if (2 == flags) |
624 |
|
xfree(data); |
625 |
|
|
626 |
} |
} |
627 |
|
|
642 |
|
|
643 |
selectionowner = XGetSelectionOwner(display, primary_atom); |
selectionowner = XGetSelectionOwner(display, primary_atom); |
644 |
|
|
645 |
|
if (rdesktop_is_selection_owner) |
646 |
|
{ |
647 |
|
XChangeProperty(display, wnd, rdesktop_clipboard_target_atom, |
648 |
|
XA_INTEGER, 32, PropModeReplace, |
649 |
|
(unsigned char *)&wanted_formatcode, 1); |
650 |
|
|
651 |
|
XConvertSelection(display, primary_atom, |
652 |
|
ipc_atom, |
653 |
|
rdesktop_clipboard_target_atom, |
654 |
|
wnd, CurrentTime); |
655 |
|
return; |
656 |
|
} |
657 |
|
|
658 |
|
|
659 |
if (None != selectionowner) |
if (None != selectionowner) |
660 |
{ |
{ |
661 |
|
|
680 |
} |
} |
681 |
|
|
682 |
|
|
683 |
void cliprdr_callback(STREAM s) |
void cliprdr_callback(STREAM s, uint16 channelno) |
684 |
{ |
{ |
685 |
|
static int failed_clipboard_acks = 0; |
686 |
|
struct timeval timeval; |
687 |
uint32 length, flags; |
uint32 length, flags; |
688 |
uint16 ptype0, ptype1; |
uint16 ptype0, ptype1; |
689 |
DEBUG_CLIPBOARD(("cliprdr_callback called, clipboard data:\n")); |
clipboard_channelno = channelno; |
690 |
|
DEBUG_CLIPBOARD(("cliprdr_callback called with channelno %d, clipboard data:\n", channelno)); |
691 |
#ifdef WITH_DEBUG_CLIPBOARD |
#ifdef WITH_DEBUG_CLIPBOARD |
692 |
hexdump(s->p, s->end - s->p); |
// hexdump(s->p, s->end - s->p); |
693 |
#endif |
#endif |
694 |
in_uint32_le(s, length); |
in_uint32_le(s, length); |
695 |
in_uint32_le(s, flags); |
in_uint32_le(s, flags); |
696 |
|
|
697 |
DEBUG_CLIPBOARD(("length is %d, flags are %d\n", length, flags)); |
DEBUG_CLIPBOARD(("length is %d, flags are %d\n", length, flags)); |
698 |
|
|
699 |
if (flags & 0x03 || flags & 0x01) /* Single-write op or first-packet-of-several op */ |
if (3 == flags || 1 == flags) /* Single-write op or first-packet-of-several op */ |
700 |
{ |
{ |
701 |
in_uint16_le(s, ptype0); |
in_uint16_le(s, ptype0); |
702 |
in_uint16_le(s, ptype1); |
in_uint16_le(s, ptype1); |
710 |
// There is a strange pad in this packet that we might need some time, |
// There is a strange pad in this packet that we might need some time, |
711 |
// but probably not. |
// but probably not. |
712 |
DEBUG_CLIPBOARD(("Received format announce ACK\n")); |
DEBUG_CLIPBOARD(("Received format announce ACK\n")); |
713 |
|
failed_clipboard_acks = 0; |
714 |
return; |
return; |
715 |
|
|
716 |
|
} else if (3 == ptype0 && 2 == ptype1) |
717 |
|
{ |
718 |
|
DEBUG_CLIPBOARD(("Received failed clipboard format announce ACK, retrying\n")); |
719 |
|
|
720 |
|
/* This is a fairly portable way to sleep 1/10 of |
721 |
|
a second.. */ |
722 |
|
timeval.tv_sec = 0; |
723 |
|
timeval.tv_usec = 100; |
724 |
|
select(0, NULL, NULL, NULL, &timeval); |
725 |
|
if (failed_clipboard_acks < 3) |
726 |
|
{ |
727 |
|
|
728 |
|
cliprdr_send_format_announce(); |
729 |
|
/* Make sure we don't get stuck in this loop */ |
730 |
|
failed_clipboard_acks++; |
731 |
|
} |
732 |
|
else |
733 |
|
{ |
734 |
|
warning("Reached maximum number of clipboard format announce attempts. Pasting in Windows probably won't work well now.\n"); |
735 |
|
} |
736 |
} else if (2 == ptype0 && 0 == ptype1) |
} else if (2 == ptype0 && 0 == ptype1) |
737 |
{ |
{ |
738 |
cliprdr_register_server_formats(s); |
cliprdr_register_server_formats(s); |
741 |
return; |
return; |
742 |
} else if (5 == ptype0 && 1 == ptype1) |
} else if (5 == ptype0 && 1 == ptype1) |
743 |
{ |
{ |
744 |
cliprdr_handle_server_data(length, s); |
cliprdr_handle_server_data(length, flags, s); |
745 |
} else if (4 == ptype0 && 0 == ptype1) |
} else if (4 == ptype0 && 0 == ptype1) |
746 |
{ |
{ |
747 |
cliprdr_handle_server_data_request(s); |
cliprdr_handle_server_data_request(s); |
748 |
} |
} |
749 |
|
|
750 |
|
|
751 |
|
} |
752 |
|
else |
753 |
|
{ |
754 |
|
DEBUG_CLIPBOARD(("Handling middle or last packet\n")); |
755 |
|
cliprdr_handle_server_data(length, flags, s); |
756 |
} |
} |
757 |
} |
} |
758 |
|
|
759 |
|
void cliprdr_ipc_primary_lost(unsigned char *data, uint16 length) |
760 |
|
{ |
761 |
|
DEBUG_CLIPBOARD(("cliprdr_ipc_primary_lost called\n")); |
762 |
|
if (!have_primary) |
763 |
|
cliprdr_send_format_announce(); |
764 |
|
rdesktop_is_selection_owner = 0; |
765 |
|
} |
766 |
|
|
767 |
|
|
768 |
void cliprdr_init(void) |
void cliprdr_init(void) |
769 |
{ |
{ |
772 |
targets_atom = XInternAtom(display, "TARGETS", False); |
targets_atom = XInternAtom(display, "TARGETS", False); |
773 |
timestamp_atom = XInternAtom(display, "TIMESTAMP", False); |
timestamp_atom = XInternAtom(display, "TIMESTAMP", False); |
774 |
rdesktop_clipboard_target_atom = XInternAtom(display, "_RDESKTOP_CLIPBOARD_TARGET", False); |
rdesktop_clipboard_target_atom = XInternAtom(display, "_RDESKTOP_CLIPBOARD_TARGET", False); |
775 |
|
incr_atom = XInternAtom(display, "INCR", False); |
776 |
|
targets[0] = targets_atom; |
777 |
|
targets[1] = XInternAtom(display, "TEXT", False); |
778 |
|
targets[2] = XInternAtom(display, "UTF8_STRING", False); |
779 |
|
targets[3] = XInternAtom(display, "text/unicode", False); |
780 |
|
targets[4] = XInternAtom(display, "TIMESTAMP", False); |
781 |
|
targets[5] = XInternAtom(display, "STRING", False); |
782 |
|
ipc_register_ipcnotify(RDESKTOP_IPC_CLIPRDR_FORMAT_ANNOUNCE, |
783 |
|
cliprdr_ipc_format_announce); |
784 |
|
ipc_register_ipcnotify(RDESKTOP_IPC_CLIPRDR_FORMAT_ANNOUNCE, |
785 |
|
cliprdr_ipc_primary_lost); |
786 |
|
|
787 |
|
|
788 |
} |
} |