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 |
{ |
{ |
|
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); |
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) |
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 */ |
datap = data; |
251 |
|
|
252 |
out = sec_init(encryption ? SEC_ENCRYPT : 0, |
if (nitems+1 <= MAX_CLIPRDR_STANDALONE_DATASIZE) |
253 |
20+nitems); |
{ |
254 |
out_uint32_le(out, 12+nitems); |
out = sec_init(encryption ? SEC_ENCRYPT : 0, |
255 |
out_uint32_le(out, 0x13); |
20+nitems+1); |
256 |
out_uint16_le(out, 5); |
out_uint32_le(out, 12+nitems+1); |
257 |
out_uint16_le(out, 1); |
out_uint32_le(out, 0x13); |
258 |
out_uint32_le(out, nitems); |
out_uint16_le(out, 5); |
259 |
out_uint8p(out, data, nitems); |
out_uint16_le(out, 1); |
260 |
/* Insert null string here? */ |
out_uint32_le(out, nitems+1); |
261 |
out_uint32_le(out, 0); |
out_uint8p(out, datap, nitems+1); |
262 |
s_mark_end(out); |
out_uint32_le(out, 0); |
263 |
|
s_mark_end(out); |
264 |
|
|
265 |
sec_send_to_channel(out, encryption ? SEC_ENCRYPT : 0, 1005); // FIXME: Don't hardcode channel! |
sec_send_to_channel(out, encryption ? SEC_ENCRYPT : 0, |
266 |
|
clipboard_channelno); |
267 |
|
|
268 |
cliprdr_send_format_announce(); |
} |
269 |
|
else |
270 |
|
{ |
271 |
|
DEBUG_CLIPBOARD(("Sending %d bytes of data\n", |
272 |
|
16+MAX_CLIPRDR_STANDALONE_DATASIZE)); |
273 |
|
out = sec_init(encryption ? SEC_ENCRYPT : 0, |
274 |
|
16+MAX_CLIPRDR_STANDALONE_DATASIZE); |
275 |
|
out_uint32_le(out, nitems+12); |
276 |
|
out_uint32_le(out, 0x11); |
277 |
|
out_uint16_le(out, 5); |
278 |
|
out_uint16_le(out, 1); |
279 |
|
out_uint32_le(out, nitems); |
280 |
|
out_uint8p(out, datap, |
281 |
|
MAX_CLIPRDR_STANDALONE_DATASIZE); |
282 |
|
s_mark_end(out); |
283 |
|
|
284 |
|
sec_send_to_channel(out, encryption ? SEC_ENCRYPT : 0, |
285 |
|
clipboard_channelno); |
286 |
|
|
287 |
|
bytes_left_to_transfer = nitems - MAX_CLIPRDR_STANDALONE_DATASIZE; |
288 |
|
datap+=MAX_CLIPRDR_STANDALONE_DATASIZE; |
289 |
|
|
290 |
|
while (bytes_left_to_transfer > MAX_CLIPRDR_STANDALONE_DATASIZE) |
291 |
|
{ |
292 |
|
DEBUG_CLIPBOARD(("Sending %d bytes of data\n", |
293 |
|
16+MAX_CLIPRDR_CONTINUATION_DATASIZE)); |
294 |
|
out = sec_init(encryption ? SEC_ENCRYPT : 0, |
295 |
|
8+MAX_CLIPRDR_CONTINUATION_DATASIZE); |
296 |
|
out_uint32_le(out, nitems); |
297 |
|
out_uint32_le(out, 0x10); |
298 |
|
out_uint8p(out, datap, |
299 |
|
MAX_CLIPRDR_CONTINUATION_DATASIZE); |
300 |
|
s_mark_end(out); |
301 |
|
|
302 |
|
sec_send_to_channel(out, |
303 |
|
encryption ? SEC_ENCRYPT : 0, |
304 |
|
clipboard_channelno); |
305 |
|
bytes_left_to_transfer-= MAX_CLIPRDR_CONTINUATION_DATASIZE; |
306 |
|
datap+=MAX_CLIPRDR_CONTINUATION_DATASIZE; |
307 |
|
|
308 |
|
} |
309 |
|
DEBUG_CLIPBOARD(("Sending %u bytes of data\n", |
310 |
|
12+bytes_left_to_transfer)); |
311 |
|
out = sec_init(encryption ? SEC_ENCRYPT : 0, |
312 |
|
12+bytes_left_to_transfer); |
313 |
|
out_uint32_le(out, nitems); |
314 |
|
out_uint32_le(out, 0x12); |
315 |
|
out_uint8p(out, datap, |
316 |
|
bytes_left_to_transfer); |
317 |
|
out_uint32_le(out, 0x0); |
318 |
|
s_mark_end(out); |
319 |
|
|
320 |
|
sec_send_to_channel(out, encryption ? SEC_ENCRYPT : 0, |
321 |
|
clipboard_channelno); |
322 |
|
|
323 |
|
} |
324 |
|
|
325 |
|
|
326 |
|
XFree(data); |
327 |
|
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 |
|
|
358 |
|
|
359 |
s_mark_end(s); |
s_mark_end(s); |
360 |
|
|
361 |
sec_send_to_channel(s, encryption ? SEC_ENCRYPT : 0, 1005); // FIXME: Don't hardcode channel! |
sec_send_to_channel(s, encryption ? SEC_ENCRYPT : 0, |
362 |
|
clipboard_channelno); |
363 |
} |
} |
364 |
|
|
365 |
|
|
367 |
cliprdr_handle_SelectionRequest(XSelectionRequestEvent *xevent) |
cliprdr_handle_SelectionRequest(XSelectionRequestEvent *xevent) |
368 |
{ |
{ |
369 |
|
|
|
Atom *targets; |
|
|
int res; |
|
|
|
|
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 |
targets = xmalloc(4*sizeof(Atom)); |
XChangeProperty(display, |
423 |
targets[0] = xevent->target; |
xevent->requestor, |
424 |
targets[1] = XInternAtom(display, "TEXT", True); |
xevent->property, |
425 |
targets[2] = XInternAtom(display, "UTF8_STRING", True); |
XA_ATOM, |
426 |
targets[3] = XInternAtom(display, "TIMESTAMP", True); |
32, |
427 |
res = XChangeProperty(display, |
PropModeAppend, |
428 |
xevent->requestor, |
(unsigned char *)&targets, |
429 |
xevent->property, |
NUM_TARGETS); |
430 |
XA_ATOM, |
|
431 |
32, |
XSendEvent(display, |
432 |
PropModeAppend, |
xevent->requestor, |
433 |
(unsigned char *)targets, |
False, |
434 |
3); |
NoEventMask, |
435 |
|
(XEvent *)&xev); |
|
res = XSendEvent(display, |
|
|
xevent->requestor, |
|
|
False, |
|
|
NoEventMask, |
|
|
(XEvent *)&xev); |
|
436 |
return; |
return; |
437 |
} else if (timestamp_atom == xevent->target) |
} else if (timestamp_atom == xevent->target) |
438 |
{ |
{ |
439 |
DEBUG_CLIPBOARD(("TIMESTAMP requested... sending 0x%x\n", |
DEBUG_CLIPBOARD(("Sending TIMESTAMP\n")); |
440 |
(unsigned)last_gesturetime)); |
XChangeProperty(display, |
441 |
res = XChangeProperty(display, |
xevent->requestor, |
442 |
xevent->requestor, |
xevent->property, |
443 |
xevent->property, |
XA_INTEGER, |
444 |
XA_INTEGER, |
32, |
445 |
32, |
PropModeAppend, |
446 |
PropModeAppend, |
(unsigned char *)&last_gesturetime, |
447 |
(unsigned char *)&last_gesturetime, |
1); |
448 |
1); |
XSendEvent(display, |
449 |
res = XSendEvent(display, |
xevent->requestor, |
450 |
xevent->requestor, |
False, |
451 |
False, |
NoEventMask, |
452 |
NoEventMask, |
(XEvent *)&xev); |
|
(XEvent *)&xev); |
|
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 |
} |
} |
473 |
|
|
474 |
s_mark_end(s); |
s_mark_end(s); |
475 |
|
|
476 |
sec_send_to_channel(s, encryption ? SEC_ENCRYPT : 0, 1005); // FIXME: Don't hardcode channel! |
sec_send_to_channel(s, encryption ? SEC_ENCRYPT : 0, |
477 |
|
clipboard_channelno); |
478 |
} |
} |
479 |
|
|
480 |
|
|
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 |
560 |
cliprdr_send_format_announce(); |
cliprdr_send_format_announce(); |
561 |
} |
} |
562 |
|
|
563 |
void cliprdr_handle_server_data(uint32 length, STREAM s) |
void cliprdr_handle_server_data(uint32 length, uint32 flags, STREAM s) |
564 |
{ |
{ |
565 |
uint32 remaining_length; |
static uint32 remaining_length; |
566 |
char *data; |
static char *data, *datap; |
567 |
in_uint32_le(s, remaining_length); |
static uint32 bytes_left_to_read; |
568 |
data = s->p; |
DEBUG_CLIPBOARD(("In cliprdr_handle_server_data, flags is %d\n", |
569 |
|
flags)); |
570 |
|
if (3 == flags) /* One-op write, no packets follows */ |
571 |
|
{ |
572 |
|
in_uint32_le(s, remaining_length); |
573 |
|
data = s->p; |
574 |
|
} else if (1 == flags) /* First of several packets */ |
575 |
|
{ |
576 |
|
in_uint32_le(s, remaining_length); |
577 |
|
DEBUG_CLIPBOARD(("Remaining length is %d\n", |
578 |
|
remaining_length)); |
579 |
|
data = xmalloc(remaining_length); |
580 |
|
datap = data; |
581 |
|
DEBUG_CLIPBOARD(("Copying first %d bytes\n", |
582 |
|
MAX_CLIPRDR_STANDALONE_DATASIZE)); |
583 |
|
memcpy(datap, s->p, MAX_CLIPRDR_STANDALONE_DATASIZE); |
584 |
|
|
585 |
|
datap+=MAX_CLIPRDR_STANDALONE_DATASIZE; |
586 |
|
bytes_left_to_read = remaining_length-MAX_CLIPRDR_STANDALONE_DATASIZE; |
587 |
|
return; |
588 |
|
} else if (0 == flags) |
589 |
|
{ |
590 |
|
DEBUG_CLIPBOARD(("Copying %d middle bytes", |
591 |
|
MAX_CLIPRDR_CONTINUATION_DATASIZE)); |
592 |
|
memcpy(datap, s->p, MAX_CLIPRDR_CONTINUATION_DATASIZE); |
593 |
|
|
594 |
|
datap+=MAX_CLIPRDR_CONTINUATION_DATASIZE; |
595 |
|
bytes_left_to_read-=MAX_CLIPRDR_CONTINUATION_DATASIZE; |
596 |
|
return; |
597 |
|
} else if (2 == flags) |
598 |
|
{ |
599 |
|
DEBUG_CLIPBOARD(("Copying last %d bytes\n", |
600 |
|
bytes_left_to_read)); |
601 |
|
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, |
610 |
8, |
8, |
611 |
PropModeAppend, |
PropModeAppend, |
612 |
data, |
data, |
613 |
remaining_length); |
remaining_length-1); |
614 |
|
|
615 |
XSendEvent(display, |
XSendEvent(display, |
616 |
selection_event.requestor, |
selection_event.requestor, |
617 |
False, |
False, |
618 |
NoEventMask, |
NoEventMask, |
619 |
(XEvent *)&selection_event); |
(XEvent *)&selection_event); |
620 |
|
|
621 |
|
if (2 == flags) |
622 |
|
xfree(data); |
623 |
|
|
624 |
} |
} |
625 |
|
|
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 |
|
|
679 |
} |
} |
680 |
|
|
681 |
|
|
682 |
void cliprdr_callback(STREAM s) |
void cliprdr_callback(STREAM s, uint16 channelno) |
683 |
{ |
{ |
684 |
|
static int failed_clipboard_acks = 0; |
685 |
|
struct timeval timeval; |
686 |
uint32 length, flags; |
uint32 length, flags; |
687 |
uint16 ptype0, ptype1; |
uint16 ptype0, ptype1; |
688 |
DEBUG_CLIPBOARD(("cliprdr_callback called, clipboard data:\n")); |
clipboard_channelno = channelno; |
689 |
|
DEBUG_CLIPBOARD(("cliprdr_callback called with channelno %d, clipboard data:\n", channelno)); |
690 |
#ifdef WITH_DEBUG_CLIPBOARD |
#ifdef WITH_DEBUG_CLIPBOARD |
691 |
hexdump(s->p, s->end - s->p); |
// hexdump(s->p, s->end - s->p); |
692 |
#endif |
#endif |
693 |
in_uint32_le(s, length); |
in_uint32_le(s, length); |
694 |
in_uint32_le(s, flags); |
in_uint32_le(s, flags); |
695 |
|
|
696 |
DEBUG_CLIPBOARD(("length is %d, flags are %d\n", length, flags)); |
DEBUG_CLIPBOARD(("length is %d, flags are %d\n", length, flags)); |
697 |
|
|
698 |
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 */ |
699 |
{ |
{ |
700 |
in_uint16_le(s, ptype0); |
in_uint16_le(s, ptype0); |
701 |
in_uint16_le(s, ptype1); |
in_uint16_le(s, ptype1); |
709 |
// 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, |
710 |
// but probably not. |
// but probably not. |
711 |
DEBUG_CLIPBOARD(("Received format announce ACK\n")); |
DEBUG_CLIPBOARD(("Received format announce ACK\n")); |
712 |
|
failed_clipboard_acks = 0; |
713 |
return; |
return; |
714 |
|
|
715 |
|
} else if (3 == ptype0 && 2 == ptype1) |
716 |
|
{ |
717 |
|
DEBUG_CLIPBOARD(("Received failed clipboard format announce ACK, retrying\n")); |
718 |
|
|
719 |
|
/* This is a fairly portable way to sleep 1/10 of |
720 |
|
a second.. */ |
721 |
|
timeval.tv_sec = 0; |
722 |
|
timeval.tv_usec = 100; |
723 |
|
select(0, NULL, NULL, NULL, &timeval); |
724 |
|
if (failed_clipboard_acks < 3) |
725 |
|
{ |
726 |
|
|
727 |
|
cliprdr_send_format_announce(); |
728 |
|
/* Make sure we don't get stuck in this loop */ |
729 |
|
failed_clipboard_acks++; |
730 |
|
} |
731 |
|
else |
732 |
|
{ |
733 |
|
warning("Reached maximum number of clipboard format announce attempts. Pasting in Windows probably won't work well now.\n"); |
734 |
|
} |
735 |
} else if (2 == ptype0 && 0 == ptype1) |
} else if (2 == ptype0 && 0 == ptype1) |
736 |
{ |
{ |
737 |
cliprdr_register_server_formats(s); |
cliprdr_register_server_formats(s); |
740 |
return; |
return; |
741 |
} else if (5 == ptype0 && 1 == ptype1) |
} else if (5 == ptype0 && 1 == ptype1) |
742 |
{ |
{ |
743 |
cliprdr_handle_server_data(length, s); |
cliprdr_handle_server_data(length, flags, s); |
744 |
} else if (4 == ptype0 && 0 == ptype1) |
} else if (4 == ptype0 && 0 == ptype1) |
745 |
{ |
{ |
746 |
cliprdr_handle_server_data_request(s); |
cliprdr_handle_server_data_request(s); |
747 |
} |
} |
748 |
|
|
749 |
|
|
750 |
|
} |
751 |
|
else |
752 |
|
{ |
753 |
|
DEBUG_CLIPBOARD(("Handling middle or last packet\n")); |
754 |
|
cliprdr_handle_server_data(length, flags, s); |
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 |
{ |
{ |
771 |
targets_atom = XInternAtom(display, "TARGETS", False); |
targets_atom = XInternAtom(display, "TARGETS", False); |
772 |
timestamp_atom = XInternAtom(display, "TIMESTAMP", False); |
timestamp_atom = XInternAtom(display, "TIMESTAMP", False); |
773 |
rdesktop_clipboard_target_atom = XInternAtom(display, "_RDESKTOP_CLIPBOARD_TARGET", False); |
rdesktop_clipboard_target_atom = XInternAtom(display, "_RDESKTOP_CLIPBOARD_TARGET", False); |
774 |
|
incr_atom = XInternAtom(display, "INCR", False); |
775 |
|
targets[0] = targets_atom; |
776 |
|
targets[1] = XInternAtom(display, "TEXT", False); |
777 |
|
targets[2] = XInternAtom(display, "UTF8_STRING", False); |
778 |
|
targets[3] = XInternAtom(display, "text/unicode", False); |
779 |
|
targets[4] = XInternAtom(display, "TIMESTAMP", False); |
780 |
|
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 |
} |
} |