30 |
static Atom clipboard_atom, primary_atom, targets_atom, timestamp_atom; |
static Atom clipboard_atom, primary_atom, targets_atom, timestamp_atom; |
31 |
static cliprdr_dataformat *server_formats = NULL; |
static cliprdr_dataformat *server_formats = NULL; |
32 |
static uint16 num_server_formats = 0; |
static uint16 num_server_formats = 0; |
33 |
|
static XSelectionEvent selection_event; |
34 |
|
|
35 |
static void |
static void |
36 |
cliprdr_print_server_formats(void) |
cliprdr_print_server_formats(void) |
46 |
i++; |
i++; |
47 |
this = this->next; |
this = this->next; |
48 |
} |
} |
49 |
DEBUG_CLIPBOARD(("There was %d server formats.\n", i)); |
DEBUG_CLIPBOARD(("There were %d server formats.\n", i)); |
50 |
#endif |
#endif |
51 |
} |
} |
52 |
|
|
90 |
break; |
break; |
91 |
|
|
92 |
case BadWindow: |
case BadWindow: |
93 |
DEBUG_CLIPBOARD(("BadWindo\n")); |
DEBUG_CLIPBOARD(("BadWindow\n")); |
94 |
break; |
break; |
95 |
|
|
96 |
default: |
default: |
98 |
} |
} |
99 |
} |
} |
100 |
|
|
101 |
|
static void |
102 |
|
cliprdr_request_clipboard_data(uint32 formatcode) |
103 |
|
{ |
104 |
|
STREAM s; |
105 |
|
s = sec_init(encryption ? SEC_ENCRYPT : 0, 24); |
106 |
|
out_uint32_le(s, 16); |
107 |
|
out_uint32_le(s, 0x13); |
108 |
|
out_uint16_le(s, 4); |
109 |
|
out_uint16_le(s, 0); |
110 |
|
out_uint32_le(s, 4); // Remaining length |
111 |
|
out_uint32_le(s, formatcode); |
112 |
|
out_uint32_le(s, 0); // Unknown. Garbage pad? |
113 |
|
|
114 |
|
s_mark_end(s); |
115 |
|
|
116 |
|
sec_send_to_channel(s, encryption ? SEC_ENCRYPT : 0, 1005); // FIXME: Don't hardcode channel! |
117 |
|
} |
118 |
|
|
119 |
|
|
120 |
void |
void |
121 |
cliprdr_handle_SelectionRequest(XSelectionRequestEvent *xevent) |
cliprdr_handle_SelectionRequest(XSelectionRequestEvent *xevent) |
122 |
{ |
{ |
123 |
|
|
|
Atom type_return; |
|
124 |
Atom *targets; |
Atom *targets; |
|
int format_return; |
|
|
long nitems_return; |
|
|
long bytes_after_return; |
|
|
char **prop_return; |
|
125 |
int res; |
int res; |
126 |
|
|
127 |
XSelectionEvent xev; |
XSelectionEvent xev; |
128 |
DEBUG_CLIPBOARD(("cliprdr_handle_SelectionRequest\n")); |
DEBUG_CLIPBOARD(("cliprdr_handle_SelectionRequest\n")); |
129 |
DEBUG_CLIPBOARD(("Requestor window id 0x%x ", xevent->requestor)); |
DEBUG_CLIPBOARD(("Requestor window id 0x%x ", |
130 |
|
(unsigned)xevent->requestor)); |
131 |
if (clipboard_atom == xevent->selection) { |
if (clipboard_atom == xevent->selection) { |
132 |
DEBUG_CLIPBOARD(("wants CLIPBOARD\n")); |
DEBUG_CLIPBOARD(("wants CLIPBOARD\n")); |
133 |
} |
} |
136 |
} |
} |
137 |
DEBUG_CLIPBOARD(("Target is %s (0x%x), property is %s (0x%x)\n", |
DEBUG_CLIPBOARD(("Target is %s (0x%x), property is %s (0x%x)\n", |
138 |
XGetAtomName(display, xevent->target), |
XGetAtomName(display, xevent->target), |
139 |
xevent->target, |
(unsigned)xevent->target, |
140 |
XGetAtomName(display, xevent->property), |
XGetAtomName(display, xevent->property), |
141 |
xevent->property)); |
(unsigned)xevent->property)); |
142 |
|
|
143 |
xev.type = SelectionNotify; |
xev.type = SelectionNotify; |
144 |
xev.serial = 0; |
xev.serial = 0; |
177 |
} else if (timestamp_atom == xevent->target) |
} else if (timestamp_atom == xevent->target) |
178 |
{ |
{ |
179 |
DEBUG_CLIPBOARD(("TIMESTAMP requested... sending 0x%x\n", |
DEBUG_CLIPBOARD(("TIMESTAMP requested... sending 0x%x\n", |
180 |
last_keyrelease)); |
(unsigned)last_keyrelease)); |
181 |
res = XChangeProperty(display, |
res = XChangeProperty(display, |
182 |
xevent->requestor, |
xevent->requestor, |
183 |
xevent->property, |
xevent->property, |
193 |
(XEvent *)&xev); |
(XEvent *)&xev); |
194 |
} else /* Some other target */ |
} else /* Some other target */ |
195 |
{ |
{ |
196 |
res = XChangeProperty(display, |
cliprdr_request_clipboard_data(CF_TEXT); |
197 |
xevent->requestor, |
memcpy(&selection_event, &xev, sizeof(xev)); |
198 |
xevent->property, |
/* Return and wait for data, handled by |
199 |
XInternAtom(display, "STRING", False), |
cliprdr_handle_server_data */ |
200 |
8, |
} |
201 |
PropModeAppend, |
} |
|
"krattoflabkat", |
|
|
13); |
|
202 |
|
|
|
DEBUG_CLIPBOARD(("res after XChangeProperty is ")); |
|
|
print_X_error(res); |
|
|
|
|
|
xev.type = SelectionNotify; |
|
|
xev.serial = 0; |
|
|
xev.send_event = True; |
|
|
xev.requestor = xevent->requestor; |
|
|
xev.selection = xevent->selection; |
|
|
xev.target = xevent->target; |
|
|
xev.property = xevent->property; |
|
|
xev.time = xevent->time; |
|
203 |
|
|
204 |
res = XSendEvent(display, |
static void |
205 |
xevent->requestor, |
cliprdr_ack_format_list(void) |
206 |
False, |
{ |
207 |
NoEventMask, |
STREAM s; |
208 |
(XEvent *)&xev); |
s = sec_init(encryption ? SEC_ENCRYPT : 0, 20); |
209 |
|
out_uint32_le(s, 12); |
210 |
DEBUG_CLIPBOARD(("res after XSendEvent is ")); |
out_uint32_le(s, 0x13); |
211 |
print_X_error(res); |
out_uint16_le(s, 3); |
212 |
} |
out_uint16_le(s, 1); |
213 |
|
out_uint32_le(s, 0); |
214 |
|
out_uint32_le(s, 0x0000c0da); |
215 |
|
|
216 |
|
s_mark_end(s); |
217 |
|
|
218 |
|
sec_send_to_channel(s, encryption ? SEC_ENCRYPT : 0, 1005); // FIXME: Don't hardcode channel! |
219 |
} |
} |
220 |
|
|
221 |
|
|
222 |
|
|
223 |
|
|
224 |
|
|
225 |
static void |
static void |
226 |
cliprdr_register_server_formats(STREAM s) |
cliprdr_register_server_formats(STREAM s) |
250 |
while (1 < num_formats) { |
while (1 < num_formats) { |
251 |
in_uint32_le(s, this->identifier); |
in_uint32_le(s, this->identifier); |
252 |
in_uint8a(s, this->textual_description, 32); |
in_uint8a(s, this->textual_description, 32); |
253 |
DEBUG_CLIPBOARD(("Stored format description with numeric id %d\n", this->identifier)); |
DEBUG_CLIPBOARD(("Stored format description with numeric id %d\n", |
254 |
|
this->identifier)); |
255 |
this-> next = xmalloc(sizeof(cliprdr_dataformat)); |
this-> next = xmalloc(sizeof(cliprdr_dataformat)); |
256 |
this = this->next; |
this = this->next; |
257 |
num_formats--; |
num_formats--; |
280 |
|
|
281 |
} |
} |
282 |
|
|
283 |
|
|
284 |
|
|
285 |
static void |
static void |
286 |
cliprdr_send_format_announce(void) |
cliprdr_send_format_announce(void) |
287 |
{ |
{ |
303 |
s_mark_end(s); |
s_mark_end(s); |
304 |
sec_send_to_channel(s, encryption ? SEC_ENCRYPT : 0, 1005); // FIXME: Don't hardcode channel! |
sec_send_to_channel(s, encryption ? SEC_ENCRYPT : 0, 1005); // FIXME: Don't hardcode channel! |
305 |
} |
} |
306 |
|
|
307 |
|
|
308 |
static void |
static void |
309 |
cliprdr_handle_first_handshake(STREAM s) |
cliprdr_handle_first_handshake(STREAM s) |
316 |
cliprdr_send_format_announce(); |
cliprdr_send_format_announce(); |
317 |
} |
} |
318 |
|
|
319 |
|
void cliprdr_handle_server_data(uint32 length, STREAM s) |
320 |
|
{ |
321 |
|
uint32 remaining_length; |
322 |
|
char *data; |
323 |
|
int res; |
324 |
|
in_uint32_le(s, remaining_length); |
325 |
|
data = s->p; |
326 |
|
res = XChangeProperty(display, |
327 |
|
selection_event.requestor, |
328 |
|
selection_event.property, |
329 |
|
XInternAtom(display, "STRING", False), |
330 |
|
8, |
331 |
|
PropModeAppend, |
332 |
|
data, |
333 |
|
remaining_length); |
334 |
|
|
335 |
|
DEBUG_CLIPBOARD(("res after XChangeProperty is ")); |
336 |
|
print_X_error(res); |
337 |
|
|
338 |
|
res = XSendEvent(display, |
339 |
|
selection_event.requestor, |
340 |
|
False, |
341 |
|
NoEventMask, |
342 |
|
(XEvent *)&selection_event); |
343 |
|
|
344 |
|
DEBUG_CLIPBOARD(("res after XSendEvent is ")); |
345 |
|
print_X_error(res); |
346 |
|
|
347 |
|
} |
348 |
|
|
349 |
void cliprdr_callback(STREAM s) |
void cliprdr_callback(STREAM s) |
350 |
{ |
{ |
351 |
uint32 length, flags; |
uint32 length, flags; |
374 |
// but probably not. |
// but probably not. |
375 |
DEBUG_CLIPBOARD(("Received format announce ACK\n")); |
DEBUG_CLIPBOARD(("Received format announce ACK\n")); |
376 |
return; |
return; |
377 |
|
|
378 |
} else if (2 == ptype0 && 0 == ptype1) |
} else if (2 == ptype0 && 0 == ptype1) |
379 |
{ |
{ |
380 |
cliprdr_register_server_formats(s); |
cliprdr_register_server_formats(s); |
381 |
cliprdr_select_X_clipboards(); |
cliprdr_select_X_clipboards(); |
382 |
|
cliprdr_ack_format_list(); |
383 |
return; |
return; |
384 |
|
} else if (5 == ptype0 && 1 == ptype1) |
385 |
|
{ |
386 |
|
cliprdr_handle_server_data(length, s); |
387 |
} |
} |
388 |
|
|
389 |
} |
} |
390 |
} |
} |
391 |
|
|
392 |
|
|
393 |
void cliprdr_init(void) |
void cliprdr_init(void) |
394 |
{ |
{ |
395 |
primary_atom = XInternAtom(display, "PRIMARY", False); |
primary_atom = XInternAtom(display, "PRIMARY", False); |