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 |
{ |
{ |
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; |
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 |
|
|
329 |
|
|
330 |
|
|
331 |
XFree(data); |
XFree(data); |
332 |
cliprdr_send_format_announce(); |
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 |
|
|
373 |
{ |
{ |
374 |
|
|
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 |
XChangeProperty(display, |
XChangeProperty(display, |
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 |
} |
} |
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 |
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 |
|
|
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 |
{ |
{ |
779 |
targets[3] = XInternAtom(display, "text/unicode", False); |
targets[3] = XInternAtom(display, "text/unicode", False); |
780 |
targets[4] = XInternAtom(display, "TIMESTAMP", False); |
targets[4] = XInternAtom(display, "TIMESTAMP", False); |
781 |
targets[5] = XInternAtom(display, "STRING", False); |
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 |
} |
} |