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; |
36 |
static XSelectionEvent selection_event; |
static XSelectionEvent selection_event; |
37 |
static uint16 clipboard_channelno; |
static uint16 clipboard_channelno; |
38 |
static Atom targets[NUM_TARGETS]; |
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 |
{ |
{ |
|
DEBUG_CLIPBOARD(("Sending format announce\n")); |
|
|
|
|
81 |
STREAM s; |
STREAM s; |
82 |
|
|
83 |
|
DEBUG_CLIPBOARD(("Sending (empty) format announce\n")); |
84 |
int number_of_formats = 1; |
int number_of_formats = 1; |
85 |
s = sec_init(encryption ? SEC_ENCRYPT : 0, number_of_formats*36+12+4+4); |
s = sec_init(encryption ? SEC_ENCRYPT : 0, number_of_formats*36+12+4+4); |
86 |
out_uint32_le(s, number_of_formats*36+12); |
out_uint32_le(s, number_of_formats*36+12); |
104 |
clipboard_channelno); |
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) |
218 |
wnd, event->time); |
wnd, event->time); |
219 |
|
|
220 |
} |
} |
221 |
|
|
222 |
else /* Other clipboard data */ |
else /* Other clipboard data */ |
223 |
{ |
{ |
224 |
|
|
247 |
return; |
return; |
248 |
} |
} |
249 |
|
|
|
DEBUG_CLIPBOARD(("Received %d bytes of clipboard data from X, there is %d remaining\n", |
|
|
nitems, bytes_left)); |
|
|
DEBUG_CLIPBOARD(("type_return is %s\n", |
|
|
XGetAtomName(display, type_return))); |
|
|
|
|
250 |
datap = data; |
datap = data; |
251 |
|
|
252 |
if (nitems+1 <= MAX_CLIPRDR_STANDALONE_DATASIZE) |
if (nitems+1 <= MAX_CLIPRDR_STANDALONE_DATASIZE) |
306 |
datap+=MAX_CLIPRDR_CONTINUATION_DATASIZE; |
datap+=MAX_CLIPRDR_CONTINUATION_DATASIZE; |
307 |
|
|
308 |
} |
} |
309 |
DEBUG_CLIPBOARD(("Sending %d bytes of data\n", |
DEBUG_CLIPBOARD(("Sending %u bytes of data\n", |
310 |
12+bytes_left_to_transfer)); |
12+bytes_left_to_transfer)); |
311 |
out = sec_init(encryption ? SEC_ENCRYPT : 0, |
out = sec_init(encryption ? SEC_ENCRYPT : 0, |
312 |
12+bytes_left_to_transfer); |
12+bytes_left_to_transfer); |
324 |
|
|
325 |
|
|
326 |
XFree(data); |
XFree(data); |
327 |
cliprdr_send_format_announce(); |
if (!rdesktop_clipboard_target_atom) |
328 |
|
cliprdr_send_format_announce(); |
329 |
|
|
330 |
} |
} |
331 |
|
|
336 |
cliprdr_handle_SelectionClear(void) |
cliprdr_handle_SelectionClear(void) |
337 |
{ |
{ |
338 |
DEBUG_CLIPBOARD(("cliprdr_handle_SelectionClear\n")); |
DEBUG_CLIPBOARD(("cliprdr_handle_SelectionClear\n")); |
339 |
|
have_primary = 0; |
340 |
|
ipc_send_message(RDESKTOP_IPC_CLIPRDR_PRIMARY_LOST, |
341 |
|
"", 0); |
342 |
cliprdr_send_format_announce(); |
cliprdr_send_format_announce(); |
343 |
} |
} |
344 |
|
|
368 |
{ |
{ |
369 |
|
|
370 |
XSelectionEvent xev; |
XSelectionEvent xev; |
371 |
|
unsigned long nitems, bytes_left; |
372 |
|
Atom type_return; |
373 |
|
uint32 *wanted_formatcode; |
374 |
|
int format; |
375 |
|
|
376 |
DEBUG_CLIPBOARD(("cliprdr_handle_SelectionRequest\n")); |
DEBUG_CLIPBOARD(("cliprdr_handle_SelectionRequest\n")); |
377 |
DEBUG_CLIPBOARD(("Requestor window id 0x%x ", |
DEBUG_CLIPBOARD(("Requestor window id 0x%x ", |
378 |
(unsigned)xevent->requestor)); |
(unsigned)xevent->requestor)); |
397 |
xev.property = xevent->property; |
xev.property = xevent->property; |
398 |
xev.time = xevent->time; |
xev.time = xevent->time; |
399 |
|
|
400 |
if (targets_atom == xevent->target) |
memcpy(&selection_event, &xev, sizeof(xev)); |
401 |
|
|
402 |
|
if (ipc_atom == xevent->target) |
403 |
|
{ |
404 |
|
DEBUG_CLIPBOARD(("Target atom is ipc_atom, getting INTEGER from requestor\n")); |
405 |
|
XGetWindowProperty(display, xevent->requestor, |
406 |
|
rdesktop_clipboard_target_atom, |
407 |
|
0, |
408 |
|
1, |
409 |
|
True, XA_INTEGER, |
410 |
|
&type_return, |
411 |
|
&format, |
412 |
|
&nitems, |
413 |
|
&bytes_left, |
414 |
|
(unsigned char **)&wanted_formatcode); |
415 |
|
DEBUG_CLIPBOARD(("Got wanted formatcode %d, format is %d\n", *wanted_formatcode, format)); |
416 |
|
cliprdr_request_clipboard_data(*wanted_formatcode); |
417 |
|
} |
418 |
|
|
419 |
|
else if (targets_atom == xevent->target) |
420 |
{ |
{ |
421 |
DEBUG_CLIPBOARD(("TARGETS requested, sending list..\n")); |
DEBUG_CLIPBOARD(("TARGETS requested, sending list..\n")); |
422 |
XChangeProperty(display, |
XChangeProperty(display, |
436 |
return; |
return; |
437 |
} else if (timestamp_atom == xevent->target) |
} else if (timestamp_atom == xevent->target) |
438 |
{ |
{ |
439 |
|
DEBUG_CLIPBOARD(("Sending TIMESTAMP\n")); |
440 |
XChangeProperty(display, |
XChangeProperty(display, |
441 |
xevent->requestor, |
xevent->requestor, |
442 |
xevent->property, |
xevent->property, |
453 |
} else /* Some other target */ |
} else /* Some other target */ |
454 |
{ |
{ |
455 |
cliprdr_request_clipboard_data(CF_TEXT); |
cliprdr_request_clipboard_data(CF_TEXT); |
|
memcpy(&selection_event, &xev, sizeof(xev)); |
|
456 |
/* Return and wait for data, handled by |
/* Return and wait for data, handled by |
457 |
cliprdr_handle_server_data */ |
cliprdr_handle_server_data */ |
458 |
} |
} |
488 |
uint16 num_formats; |
uint16 num_formats; |
489 |
cliprdr_dataformat *this, *next; |
cliprdr_dataformat *this, *next; |
490 |
|
|
|
DEBUG_CLIPBOARD(("cliprdr_register_server_formats\n")); |
|
491 |
in_uint32_le(s, remaining_length); |
in_uint32_le(s, remaining_length); |
492 |
|
DEBUG_CLIPBOARD(("cliprdr_register_server_formats, remaining_length is %d\n", remaining_length)); |
493 |
|
|
494 |
|
|
495 |
num_formats = remaining_length / 36; |
num_formats = remaining_length / 36; |
496 |
|
|
497 |
|
ipc_send_message(RDESKTOP_IPC_CLIPRDR_FORMAT_ANNOUNCE, |
498 |
|
s->p, remaining_length); |
499 |
if (NULL != server_formats) { |
if (NULL != server_formats) { |
500 |
this = server_formats; |
this = server_formats; |
501 |
next = this->next; |
next = this->next; |
534 |
if (wnd != XGetSelectionOwner(display, primary_atom)) |
if (wnd != XGetSelectionOwner(display, primary_atom)) |
535 |
{ |
{ |
536 |
warning("Failed to aquire ownership of PRIMARY clipboard\n"); |
warning("Failed to aquire ownership of PRIMARY clipboard\n"); |
537 |
|
} |
538 |
|
else |
539 |
|
{ |
540 |
|
have_primary = 1; |
541 |
} |
} |
542 |
XSetSelectionOwner(display, clipboard_atom, wnd, last_gesturetime); |
XSetSelectionOwner(display, clipboard_atom, wnd, last_gesturetime); |
543 |
if (wnd != XGetSelectionOwner(display, clipboard_atom)) |
if (wnd != XGetSelectionOwner(display, clipboard_atom)) |
547 |
|
|
548 |
} |
} |
549 |
|
|
|
|
|
|
|
|
550 |
|
|
551 |
|
|
552 |
static void |
static void |
600 |
bytes_left_to_read)); |
bytes_left_to_read)); |
601 |
memcpy(datap, s->p, bytes_left_to_read); |
memcpy(datap, s->p, bytes_left_to_read); |
602 |
} |
} |
603 |
|
DEBUG_CLIPBOARD(("Setting target atom (%s) on %d\n", |
604 |
|
XGetAtomName(display, selection_event.property), |
605 |
|
selection_event.requestor)); |
606 |
XChangeProperty(display, |
XChangeProperty(display, |
607 |
selection_event.requestor, |
selection_event.requestor, |
608 |
selection_event.property, |
selection_event.property, |
618 |
NoEventMask, |
NoEventMask, |
619 |
(XEvent *)&selection_event); |
(XEvent *)&selection_event); |
620 |
|
|
621 |
if (flags & 0x12) |
if (2 == flags) |
622 |
xfree(data); |
xfree(data); |
623 |
|
|
624 |
} |
} |
640 |
|
|
641 |
selectionowner = XGetSelectionOwner(display, primary_atom); |
selectionowner = XGetSelectionOwner(display, primary_atom); |
642 |
|
|
643 |
|
if (rdesktop_is_selection_owner) |
644 |
|
{ |
645 |
|
DEBUG_CLIPBOARD(("XChangeProperty, rdesktop_is_selection_owner\n")); |
646 |
|
XChangeProperty(display, wnd, rdesktop_clipboard_target_atom, |
647 |
|
XA_INTEGER, 32, PropModeReplace, |
648 |
|
(unsigned char *)&wanted_formatcode, 1); |
649 |
|
|
650 |
|
XConvertSelection(display, primary_atom, |
651 |
|
ipc_atom, |
652 |
|
rdesktop_clipboard_target_atom, |
653 |
|
wnd, CurrentTime); |
654 |
|
return; |
655 |
|
} |
656 |
|
|
657 |
|
|
658 |
if (None != selectionowner) |
if (None != selectionowner) |
659 |
{ |
{ |
660 |
|
|
755 |
} |
} |
756 |
} |
} |
757 |
|
|
758 |
|
void cliprdr_ipc_primary_lost(unsigned char *data, uint16 length) |
759 |
|
{ |
760 |
|
DEBUG_CLIPBOARD(("cliprdr_ipc_primary_lost called\n")); |
761 |
|
if (!have_primary) |
762 |
|
cliprdr_send_format_announce(); |
763 |
|
rdesktop_is_selection_owner = 0; |
764 |
|
} |
765 |
|
|
766 |
|
|
767 |
void cliprdr_init(void) |
void cliprdr_init(void) |
768 |
{ |
{ |
778 |
targets[3] = XInternAtom(display, "text/unicode", False); |
targets[3] = XInternAtom(display, "text/unicode", False); |
779 |
targets[4] = XInternAtom(display, "TIMESTAMP", False); |
targets[4] = XInternAtom(display, "TIMESTAMP", False); |
780 |
targets[5] = XInternAtom(display, "STRING", False); |
targets[5] = XInternAtom(display, "STRING", False); |
781 |
|
ipc_register_ipcnotify(RDESKTOP_IPC_CLIPRDR_FORMAT_ANNOUNCE, |
782 |
|
cliprdr_ipc_format_announce); |
783 |
|
ipc_register_ipcnotify(RDESKTOP_IPC_CLIPRDR_FORMAT_ANNOUNCE, |
784 |
|
cliprdr_ipc_primary_lost); |
785 |
|
|
786 |
|
|
787 |
} |
} |