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_format_announce(void) |
56 |
|
{ |
57 |
|
STREAM s; |
58 |
|
int number_of_formats = 1; |
59 |
|
s = sec_init(encryption ? SEC_ENCRYPT : 0, number_of_formats*36+12+4+4); |
60 |
|
out_uint32_le(s, number_of_formats*36+12); |
61 |
|
out_uint32_le(s, 0x13); |
62 |
|
out_uint16_le(s, 2); |
63 |
|
out_uint16_le(s, 0); |
64 |
|
out_uint32_le(s, number_of_formats*36); |
65 |
|
|
66 |
|
// out_uint32_le(s, 0xd); // FIXME: This is a rather bogus unicode text description.. |
67 |
|
// rdp_out_unistr(s, "", 16); |
68 |
|
// out_uint8s(s, 32); |
69 |
|
|
70 |
|
|
71 |
|
out_uint32_le(s, 1); // FIXME: This is a rather bogus text description.. |
72 |
|
out_uint8s(s, 32); |
73 |
|
|
74 |
|
out_uint32_le(s, 0); |
75 |
|
|
76 |
|
s_mark_end(s); |
77 |
|
sec_send_to_channel(s, encryption ? SEC_ENCRYPT : 0, 1005); // FIXME: Don't hardcode channel! |
78 |
|
} |
79 |
|
|
80 |
|
|
81 |
|
static void |
82 |
|
cliprdr_send_empty_datapacket(void) |
83 |
|
{ |
84 |
|
STREAM out; |
85 |
|
out = sec_init(encryption ? SEC_ENCRYPT : 0, |
86 |
|
20); |
87 |
|
out_uint32_le(out, 12); |
88 |
|
out_uint32_le(out, 0x13); |
89 |
|
out_uint16_le(out, 5); |
90 |
|
out_uint16_le(out, 1); |
91 |
|
out_uint32_le(out, 0); |
92 |
|
/* Insert null string here? */ |
93 |
|
out_uint32_le(out, 0); |
94 |
|
s_mark_end(out); |
95 |
|
|
96 |
|
sec_send_to_channel(out, encryption ? SEC_ENCRYPT : 0, 1005); // FIXME: Don't hardcode channel! |
97 |
|
} |
98 |
|
|
99 |
|
|
100 |
void |
void |
101 |
cliprdr_handle_SelectionNotify(void) |
cliprdr_handle_SelectionNotify(XSelectionEvent *event) |
102 |
{ |
{ |
103 |
|
|
104 |
|
unsigned char *data; |
105 |
|
unsigned long nitems, bytes_left; |
106 |
|
int res; |
107 |
|
|
108 |
|
int format; |
109 |
|
Atom type_return; |
110 |
|
Atom best_target; |
111 |
|
|
112 |
|
STREAM out; |
113 |
|
|
114 |
DEBUG_CLIPBOARD(("cliprdr_handle_SelectionNotify\n")); |
DEBUG_CLIPBOARD(("cliprdr_handle_SelectionNotify\n")); |
115 |
|
|
116 |
|
if (None == event->property) { |
117 |
|
cliprdr_send_empty_datapacket(); |
118 |
|
return; /* Selection failed */ |
119 |
|
} |
120 |
|
|
121 |
|
DEBUG_CLIPBOARD(("selection: %s, target: %s, property: %s\n", |
122 |
|
XGetAtomName(display, event->selection), |
123 |
|
XGetAtomName(display, event->target), |
124 |
|
XGetAtomName(display, event->property))); |
125 |
|
|
126 |
|
if (targets_atom == event->target) { |
127 |
|
/* Response to TARGETS request. Let's find the target |
128 |
|
we want and request that */ |
129 |
|
res = XGetWindowProperty(display, wnd, |
130 |
|
rdesktop_clipboard_target_atom, |
131 |
|
0L, 4096L, False, AnyPropertyType, |
132 |
|
&type_return, |
133 |
|
&format, &nitems, &bytes_left, &data); |
134 |
|
|
135 |
|
if (Success != res) |
136 |
|
{ |
137 |
|
DEBUG_CLIPBOARD(("XGetWindowProperty failed!\n")); |
138 |
|
cliprdr_send_empty_datapacket(); |
139 |
|
return; |
140 |
|
} |
141 |
|
|
142 |
|
if (None == type_return) |
143 |
|
/* The owner might no support TARGETS. Just try |
144 |
|
STRING */ |
145 |
|
best_target = XA_STRING; |
146 |
|
else |
147 |
|
{ |
148 |
|
/* FIXME: We should choose format here based |
149 |
|
on what the server wanted */ |
150 |
|
best_target = XInternAtom(display, "TEXT", False); |
151 |
|
|
152 |
|
|
153 |
|
} |
154 |
|
|
155 |
|
XConvertSelection(display, primary_atom, |
156 |
|
best_target, |
157 |
|
rdesktop_clipboard_target_atom, |
158 |
|
wnd, event->time); |
159 |
|
|
160 |
|
} |
161 |
|
else /* Other clipboard data */ |
162 |
|
{ |
163 |
|
|
164 |
|
res = XGetWindowProperty(display, wnd, |
165 |
|
rdesktop_clipboard_target_atom, |
166 |
|
0L, 4096L, False, AnyPropertyType, |
167 |
|
&type_return, |
168 |
|
&format, &nitems, &bytes_left, &data); |
169 |
|
|
170 |
|
if (Success != res) |
171 |
|
{ |
172 |
|
DEBUG_CLIPBOARD(("XGetWindowProperty failed!\n")); |
173 |
|
cliprdr_send_empty_datapacket(); |
174 |
|
return; |
175 |
|
} |
176 |
|
|
177 |
|
/* We need to handle INCR as well */ |
178 |
|
|
179 |
|
out = sec_init(encryption ? SEC_ENCRYPT : 0, |
180 |
|
20+nitems); |
181 |
|
out_uint32_le(out, 12+nitems); |
182 |
|
out_uint32_le(out, 0x13); |
183 |
|
out_uint16_le(out, 5); |
184 |
|
out_uint16_le(out, 1); |
185 |
|
out_uint32_le(out, nitems); |
186 |
|
out_uint8p(out, data, nitems); |
187 |
|
/* Insert null string here? */ |
188 |
|
out_uint32_le(out, 0); |
189 |
|
s_mark_end(out); |
190 |
|
|
191 |
|
sec_send_to_channel(out, encryption ? SEC_ENCRYPT : 0, 1005); // FIXME: Don't hardcode channel! |
192 |
|
|
193 |
|
} |
194 |
|
|
195 |
|
|
196 |
} |
} |
197 |
|
|
198 |
void |
void |
199 |
cliprdr_handle_SelectionClear(void) |
cliprdr_handle_SelectionClear(void) |
200 |
{ |
{ |
201 |
DEBUG_CLIPBOARD(("cliprdr_handle_SelectionClear\n")); |
DEBUG_CLIPBOARD(("cliprdr_handle_SelectionClear\n")); |
202 |
|
cliprdr_send_format_announce(); |
203 |
} |
} |
204 |
|
|
205 |
void print_X_error(int res) |
void print_X_error(int res) |
422 |
|
|
423 |
|
|
424 |
|
|
|
static void |
|
|
cliprdr_send_format_announce(void) |
|
|
{ |
|
|
STREAM s; |
|
|
int number_of_formats = 1; |
|
|
s = sec_init(encryption ? SEC_ENCRYPT : 0, number_of_formats*36+12+4+4); |
|
|
out_uint32_le(s, number_of_formats*36+12); |
|
|
out_uint32_le(s, 0x13); |
|
|
out_uint16_le(s, 2); |
|
|
out_uint16_le(s, 0); |
|
|
out_uint32_le(s, number_of_formats*36); |
|
|
|
|
|
out_uint32_le(s, 0xd); // FIXME: This is a rather bogus unicode text description.. |
|
|
// rdp_out_unistr(s, "", 16); |
|
|
out_uint8s(s, 32); |
|
|
|
|
|
out_uint32_le(s, 0); |
|
|
|
|
|
s_mark_end(s); |
|
|
sec_send_to_channel(s, encryption ? SEC_ENCRYPT : 0, 1005); // FIXME: Don't hardcode channel! |
|
|
} |
|
425 |
|
|
426 |
|
|
427 |
static void |
static void |
465 |
|
|
466 |
} |
} |
467 |
|
|
468 |
|
void cliprdr_handle_server_data_request(STREAM s) |
469 |
|
{ |
470 |
|
Window selectionowner; |
471 |
|
uint32 remaining_length; |
472 |
|
uint32 wanted_formatcode, pad; |
473 |
|
|
474 |
|
in_uint32_le(s, remaining_length); |
475 |
|
in_uint32_le(s, wanted_formatcode); |
476 |
|
in_uint32_le(s, pad); |
477 |
|
|
478 |
|
/* FIXME: Check that we support this formatcode */ |
479 |
|
|
480 |
|
DEBUG_CLIPBOARD(("Request from server for format %d\n", |
481 |
|
wanted_formatcode)); |
482 |
|
|
483 |
|
selectionowner = XGetSelectionOwner(display, primary_atom); |
484 |
|
|
485 |
|
if (None != selectionowner) |
486 |
|
{ |
487 |
|
|
488 |
|
/* FIXME: Perhaps we should check if we are the owner? */ |
489 |
|
|
490 |
|
XConvertSelection(display, primary_atom, |
491 |
|
targets_atom, |
492 |
|
rdesktop_clipboard_target_atom, |
493 |
|
wnd, CurrentTime); |
494 |
|
|
495 |
|
/* The rest of the transfer is handled in |
496 |
|
cliprdr_handle_SelectionNotify */ |
497 |
|
|
498 |
|
} else |
499 |
|
{ |
500 |
|
DEBUG_CLIPBOARD(("There were no owner for PRIMARY, sending empty string\n")); // FIXME: Should we always send an empty string? |
501 |
|
|
502 |
|
cliprdr_send_empty_datapacket(); |
503 |
|
} |
504 |
|
|
505 |
|
|
506 |
|
} |
507 |
|
|
508 |
|
|
509 |
void cliprdr_callback(STREAM s) |
void cliprdr_callback(STREAM s) |
510 |
{ |
{ |
511 |
uint32 length, flags; |
uint32 length, flags; |
544 |
} else if (5 == ptype0 && 1 == ptype1) |
} else if (5 == ptype0 && 1 == ptype1) |
545 |
{ |
{ |
546 |
cliprdr_handle_server_data(length, s); |
cliprdr_handle_server_data(length, s); |
547 |
|
} else if (4 == ptype0 && 0 == ptype1) |
548 |
|
{ |
549 |
|
cliprdr_handle_server_data_request(s); |
550 |
} |
} |
551 |
|
|
552 |
|
|
553 |
} |
} |
554 |
} |
} |
558 |
{ |
{ |
559 |
primary_atom = XInternAtom(display, "PRIMARY", False); |
primary_atom = XInternAtom(display, "PRIMARY", False); |
560 |
clipboard_atom = XInternAtom(display, "CLIPBOARD", False); |
clipboard_atom = XInternAtom(display, "CLIPBOARD", False); |
561 |
targets_atom = XInternAtom(display, "TARGETS", True); |
targets_atom = XInternAtom(display, "TARGETS", False); |
562 |
timestamp_atom = XInternAtom(display, "TIMESTAMP", True); |
timestamp_atom = XInternAtom(display, "TIMESTAMP", False); |
563 |
|
rdesktop_clipboard_target_atom = XInternAtom(display, "_RDESKTOP_CLIPBOARD_TARGET", False); |
564 |
} |
} |