28 |
extern Time last_keyrelease; |
extern Time last_keyrelease; |
29 |
|
|
30 |
static Atom clipboard_atom, primary_atom, targets_atom, timestamp_atom; |
static Atom clipboard_atom, primary_atom, targets_atom, timestamp_atom; |
31 |
|
static Atom rdesktop_clipboard_target_atom; |
32 |
static cliprdr_dataformat *server_formats = NULL; |
static cliprdr_dataformat *server_formats = NULL; |
33 |
static uint16 num_server_formats = 0; |
static uint16 num_server_formats = 0; |
34 |
static XSelectionEvent selection_event; |
static XSelectionEvent selection_event; |
51 |
#endif |
#endif |
52 |
} |
} |
53 |
|
|
54 |
|
static void |
55 |
|
cliprdr_send_empty_datapacket(void) |
56 |
|
{ |
57 |
|
STREAM out; |
58 |
|
out = sec_init(encryption ? SEC_ENCRYPT : 0, |
59 |
|
20); |
60 |
|
out_uint32_le(out, 12); |
61 |
|
out_uint32_le(out, 0x13); |
62 |
|
out_uint16_le(out, 5); |
63 |
|
out_uint16_le(out, 1); |
64 |
|
out_uint32_le(out, 0); |
65 |
|
/* Insert null string here? */ |
66 |
|
out_uint32_le(out, 0); |
67 |
|
s_mark_end(out); |
68 |
|
|
69 |
|
sec_send_to_channel(out, encryption ? SEC_ENCRYPT : 0, 1005); // FIXME: Don't hardcode channel! |
70 |
|
} |
71 |
|
|
72 |
|
|
73 |
void |
void |
74 |
cliprdr_handle_SelectionNotify(void) |
cliprdr_handle_SelectionNotify(XSelectionEvent *event) |
75 |
{ |
{ |
76 |
|
|
77 |
|
unsigned char *data; |
78 |
|
unsigned long nitems, bytes_left; |
79 |
|
int res; |
80 |
|
|
81 |
|
int format; |
82 |
|
Atom type_return; |
83 |
|
Atom best_target; |
84 |
|
|
85 |
|
STREAM out; |
86 |
|
|
87 |
DEBUG_CLIPBOARD(("cliprdr_handle_SelectionNotify\n")); |
DEBUG_CLIPBOARD(("cliprdr_handle_SelectionNotify\n")); |
88 |
|
|
89 |
|
if (None == event->property) { |
90 |
|
cliprdr_send_empty_datapacket(); |
91 |
|
return; /* Selection failed */ |
92 |
|
} |
93 |
|
|
94 |
|
DEBUG_CLIPBOARD(("selection: %s, target: %s, property: %s\n", |
95 |
|
XGetAtomName(display, event->selection), |
96 |
|
XGetAtomName(display, event->target), |
97 |
|
XGetAtomName(display, event->property))); |
98 |
|
|
99 |
|
if (targets_atom == event->target) { |
100 |
|
/* Response to TARGETS request. Let's find the target |
101 |
|
we want and request that */ |
102 |
|
res = XGetWindowProperty(display, wnd, |
103 |
|
rdesktop_clipboard_target_atom, |
104 |
|
0L, 4096L, False, AnyPropertyType, |
105 |
|
&type_return, |
106 |
|
&format, &nitems, &bytes_left, &data); |
107 |
|
|
108 |
|
if (Success != res) |
109 |
|
{ |
110 |
|
DEBUG_CLIPBOARD(("XGetWindowProperty failed!\n")); |
111 |
|
cliprdr_send_empty_datapacket(); |
112 |
|
return; |
113 |
|
} |
114 |
|
|
115 |
|
if (None == type_return) |
116 |
|
/* The owner might no support TARGETS. Just try |
117 |
|
STRING */ |
118 |
|
best_target = XA_STRING; |
119 |
|
else |
120 |
|
{ |
121 |
|
/* FIXME: We should choose format here based |
122 |
|
on what the server wanted */ |
123 |
|
best_target = XInternAtom(display, "TEXT", False); |
124 |
|
|
125 |
|
|
126 |
|
} |
127 |
|
|
128 |
|
XConvertSelection(display, primary_atom, |
129 |
|
best_target, |
130 |
|
rdesktop_clipboard_target_atom, |
131 |
|
wnd, event->time); |
132 |
|
|
133 |
|
} |
134 |
|
else /* Other clipboard data */ |
135 |
|
{ |
136 |
|
|
137 |
|
res = XGetWindowProperty(display, wnd, |
138 |
|
rdesktop_clipboard_target_atom, |
139 |
|
0L, 4096L, False, AnyPropertyType, |
140 |
|
&type_return, |
141 |
|
&format, &nitems, &bytes_left, &data); |
142 |
|
|
143 |
|
if (Success != res) |
144 |
|
{ |
145 |
|
DEBUG_CLIPBOARD(("XGetWindowProperty failed!\n")); |
146 |
|
cliprdr_send_empty_datapacket(); |
147 |
|
return; |
148 |
|
} |
149 |
|
|
150 |
|
/* We need to handle INCR as well */ |
151 |
|
|
152 |
|
out = sec_init(encryption ? SEC_ENCRYPT : 0, |
153 |
|
20+nitems); |
154 |
|
out_uint32_le(out, 12+nitems); |
155 |
|
out_uint32_le(out, 0x13); |
156 |
|
out_uint16_le(out, 5); |
157 |
|
out_uint16_le(out, 1); |
158 |
|
out_uint32_le(out, nitems); |
159 |
|
out_uint8p(out, data, nitems); |
160 |
|
/* Insert null string here? */ |
161 |
|
out_uint32_le(out, 0); |
162 |
|
s_mark_end(out); |
163 |
|
|
164 |
|
sec_send_to_channel(out, encryption ? SEC_ENCRYPT : 0, 1005); // FIXME: Don't hardcode channel! |
165 |
|
|
166 |
|
} |
167 |
|
|
168 |
|
|
169 |
} |
} |
170 |
|
|
171 |
void |
void |
406 |
out_uint16_le(s, 0); |
out_uint16_le(s, 0); |
407 |
out_uint32_le(s, number_of_formats*36); |
out_uint32_le(s, number_of_formats*36); |
408 |
|
|
409 |
out_uint32_le(s, 0xd); // FIXME: This is a rather bogus unicode text description.. |
// out_uint32_le(s, 0xd); // FIXME: This is a rather bogus unicode text description.. |
410 |
// rdp_out_unistr(s, "", 16); |
// rdp_out_unistr(s, "", 16); |
411 |
|
// out_uint8s(s, 32); |
412 |
|
|
413 |
|
|
414 |
|
out_uint32_le(s, 1); // FIXME: This is a rather bogus text description.. |
415 |
out_uint8s(s, 32); |
out_uint8s(s, 32); |
416 |
|
|
417 |
out_uint32_le(s, 0); |
out_uint32_le(s, 0); |
462 |
|
|
463 |
} |
} |
464 |
|
|
465 |
|
void cliprdr_handle_server_data_request(STREAM s) |
466 |
|
{ |
467 |
|
Window selectionowner; |
468 |
|
uint32 remaining_length; |
469 |
|
uint32 wanted_formatcode, pad; |
470 |
|
|
471 |
|
in_uint32_le(s, remaining_length); |
472 |
|
in_uint32_le(s, wanted_formatcode); |
473 |
|
in_uint32_le(s, pad); |
474 |
|
|
475 |
|
/* FIXME: Check that we support this formatcode */ |
476 |
|
|
477 |
|
DEBUG_CLIPBOARD(("Request from server for format %d\n", |
478 |
|
wanted_formatcode)); |
479 |
|
|
480 |
|
selectionowner = XGetSelectionOwner(display, primary_atom); |
481 |
|
|
482 |
|
if (None != selectionowner) |
483 |
|
{ |
484 |
|
|
485 |
|
/* FIXME: Perhaps we should check if we are the owner? */ |
486 |
|
|
487 |
|
XConvertSelection(display, primary_atom, |
488 |
|
targets_atom, |
489 |
|
rdesktop_clipboard_target_atom, |
490 |
|
wnd, CurrentTime); |
491 |
|
|
492 |
|
/* The rest of the transfer is handled in |
493 |
|
cliprdr_handle_SelectionNotify */ |
494 |
|
|
495 |
|
} else |
496 |
|
{ |
497 |
|
DEBUG_CLIPBOARD(("There were no owner for PRIMARY, sending empty string\n")); // FIXME: Should we always send an empty string? |
498 |
|
|
499 |
|
cliprdr_send_empty_datapacket(); |
500 |
|
} |
501 |
|
|
502 |
|
|
503 |
|
} |
504 |
|
|
505 |
|
|
506 |
void cliprdr_callback(STREAM s) |
void cliprdr_callback(STREAM s) |
507 |
{ |
{ |
508 |
uint32 length, flags; |
uint32 length, flags; |
541 |
} else if (5 == ptype0 && 1 == ptype1) |
} else if (5 == ptype0 && 1 == ptype1) |
542 |
{ |
{ |
543 |
cliprdr_handle_server_data(length, s); |
cliprdr_handle_server_data(length, s); |
544 |
|
} else if (4 == ptype0 && 0 == ptype1) |
545 |
|
{ |
546 |
|
cliprdr_handle_server_data_request(s); |
547 |
} |
} |
548 |
|
|
549 |
|
|
550 |
} |
} |
551 |
} |
} |
555 |
{ |
{ |
556 |
primary_atom = XInternAtom(display, "PRIMARY", False); |
primary_atom = XInternAtom(display, "PRIMARY", False); |
557 |
clipboard_atom = XInternAtom(display, "CLIPBOARD", False); |
clipboard_atom = XInternAtom(display, "CLIPBOARD", False); |
558 |
targets_atom = XInternAtom(display, "TARGETS", True); |
targets_atom = XInternAtom(display, "TARGETS", False); |
559 |
timestamp_atom = XInternAtom(display, "TIMESTAMP", True); |
timestamp_atom = XInternAtom(display, "TIMESTAMP", False); |
560 |
|
rdesktop_clipboard_target_atom = XInternAtom(display, "_RDESKTOP_CLIPBOARD_TARGET", False); |
561 |
} |
} |