37 |
static int rdesktop_is_selection_owner = 0; |
static int rdesktop_is_selection_owner = 0; |
38 |
|
|
39 |
static void |
static void |
40 |
xclip_provide_selection(XSelectionRequestEvent *req, Atom type, unsigned int format, uint8 *data, uint32 length) |
xclip_provide_selection(XSelectionRequestEvent * req, Atom type, unsigned int format, uint8 * data, |
41 |
|
uint32 length) |
42 |
{ |
{ |
43 |
XEvent xev; |
XEvent xev; |
44 |
|
|
96 |
text_target = XInternAtom(display, "TEXT", False); |
text_target = XInternAtom(display, "TEXT", False); |
97 |
for (i = 0; i < nitems; i++) |
for (i = 0; i < nitems; i++) |
98 |
{ |
{ |
99 |
DEBUG_CLIPBOARD(("Target %d: %s\n", i, XGetAtomName(display, supported_targets[i]))); |
DEBUG_CLIPBOARD(("Target %d: %s\n", i, |
100 |
|
XGetAtomName(display, supported_targets[i]))); |
101 |
if (supported_targets[i] == text_target) |
if (supported_targets[i] == text_target) |
102 |
{ |
{ |
103 |
DEBUG_CLIPBOARD(("Other party supports TEXT, choosing that as best_target\n")); |
DEBUG_CLIPBOARD(("Other party supports TEXT, choosing that as best_target\n")); |
107 |
XFree(data); |
XFree(data); |
108 |
} |
} |
109 |
|
|
110 |
XConvertSelection(display, primary_atom, best_target, rdesktop_clipboard_target_atom, wnd, event->time); |
XConvertSelection(display, primary_atom, best_target, |
111 |
|
rdesktop_clipboard_target_atom, wnd, event->time); |
112 |
return; |
return; |
113 |
} |
} |
114 |
|
|
118 |
goto fail; |
goto fail; |
119 |
} |
} |
120 |
|
|
121 |
cliprdr_send_data(data, nitems+1); |
cliprdr_send_data(data, nitems + 1); |
122 |
XFree(data); |
XFree(data); |
123 |
|
|
124 |
if (!rdesktop_is_selection_owner) |
if (!rdesktop_is_selection_owner) |
125 |
cliprdr_send_text_format_announce(); |
cliprdr_send_text_format_announce(); |
126 |
return; |
return; |
127 |
|
|
128 |
fail: |
fail: |
129 |
cliprdr_send_data(NULL, 0); |
cliprdr_send_data(NULL, 0); |
130 |
} |
} |
131 |
|
|
132 |
void |
void |
133 |
xclip_handle_SelectionRequest(XSelectionRequestEvent *event) |
xclip_handle_SelectionRequest(XSelectionRequestEvent * event) |
134 |
{ |
{ |
135 |
unsigned long nitems, bytes_left; |
unsigned long nitems, bytes_left; |
136 |
uint32 *wanted_format; |
uint32 *wanted_format; |
144 |
|
|
145 |
if (event->target == targets_atom) |
if (event->target == targets_atom) |
146 |
{ |
{ |
147 |
xclip_provide_selection(event, XA_ATOM, 32, (uint8 *)&targets, NUM_TARGETS); |
xclip_provide_selection(event, XA_ATOM, 32, (uint8 *) & targets, NUM_TARGETS); |
148 |
return; |
return; |
149 |
} |
} |
150 |
else if (event->target == timestamp_atom) |
else if (event->target == timestamp_atom) |
151 |
{ |
{ |
152 |
xclip_provide_selection(event, XA_INTEGER, 32, (uint8 *)&last_gesturetime, 1); |
xclip_provide_selection(event, XA_INTEGER, 32, (uint8 *) & last_gesturetime, 1); |
153 |
return; |
return; |
154 |
} |
} |
155 |
else if (event->target == rdesktop_clipboard_formats_atom) |
else if (event->target == rdesktop_clipboard_formats_atom) |
156 |
{ |
{ |
157 |
res = XGetWindowProperty(display, event->requestor, |
res = XGetWindowProperty(display, event->requestor, |
158 |
rdesktop_clipboard_target_atom, 0, 1, True, XA_INTEGER, |
rdesktop_clipboard_target_atom, 0, 1, True, XA_INTEGER, |
159 |
&type, &format, &nitems, &bytes_left, (unsigned char **) &wanted_format); |
&type, &format, &nitems, &bytes_left, |
160 |
|
(unsigned char **) &wanted_format); |
161 |
format = (res == Success) ? *wanted_format : CF_TEXT; |
format = (res == Success) ? *wanted_format : CF_TEXT; |
162 |
} |
} |
163 |
else |
else |
180 |
} |
} |
181 |
|
|
182 |
void |
void |
183 |
xclip_handle_PropertyNotify(XPropertyEvent *event) |
xclip_handle_PropertyNotify(XPropertyEvent * event) |
184 |
{ |
{ |
185 |
unsigned long nitems, bytes_left; |
unsigned long nitems, bytes_left; |
186 |
int format, res; |
int format, res; |
190 |
if (event->atom != rdesktop_clipboard_formats_atom) |
if (event->atom != rdesktop_clipboard_formats_atom) |
191 |
return; |
return; |
192 |
|
|
193 |
if (have_primary) /* from us */ |
if (have_primary) /* from us */ |
194 |
return; |
return; |
195 |
|
|
196 |
if (event->state == PropertyNewValue) |
if (event->state == PropertyNewValue) |
197 |
{ |
{ |
198 |
res = XGetWindowProperty(display, DefaultRootWindow(display), |
res = XGetWindowProperty(display, DefaultRootWindow(display), |
199 |
rdesktop_clipboard_formats_atom, 0, XMaxRequestSize(display), False, XA_STRING, |
rdesktop_clipboard_formats_atom, 0, |
200 |
&type, &format, &nitems, &bytes_left, &data); |
XMaxRequestSize(display), False, XA_STRING, &type, &format, |
201 |
|
&nitems, &bytes_left, &data); |
202 |
|
|
203 |
if ((res == Success) && (nitems > 0)) |
if ((res == Success) && (nitems > 0)) |
204 |
{ |
{ |
226 |
|
|
227 |
have_primary = 1; |
have_primary = 1; |
228 |
XChangeProperty(display, DefaultRootWindow(display), |
XChangeProperty(display, DefaultRootWindow(display), |
229 |
rdesktop_clipboard_formats_atom, XA_STRING, 8, PropModeReplace, data, length); |
rdesktop_clipboard_formats_atom, XA_STRING, 8, PropModeReplace, data, |
230 |
|
length); |
231 |
|
|
232 |
XSetSelectionOwner(display, clipboard_atom, wnd, last_gesturetime); |
XSetSelectionOwner(display, clipboard_atom, wnd, last_gesturetime); |
233 |
if (XGetSelectionOwner(display, clipboard_atom) != wnd) |
if (XGetSelectionOwner(display, clipboard_atom) != wnd) |
238 |
void |
void |
239 |
ui_clip_handle_data(char *data, uint32 length) |
ui_clip_handle_data(char *data, uint32 length) |
240 |
{ |
{ |
241 |
xclip_provide_selection(&selection_request, XA_STRING, 8, data, length-1); |
xclip_provide_selection(&selection_request, XA_STRING, 8, data, length - 1); |
242 |
} |
} |
243 |
|
|
244 |
void |
void |
254 |
XA_INTEGER, 32, PropModeReplace, (unsigned char *) &format, 1); |
XA_INTEGER, 32, PropModeReplace, (unsigned char *) &format, 1); |
255 |
|
|
256 |
XConvertSelection(display, primary_atom, rdesktop_clipboard_formats_atom, |
XConvertSelection(display, primary_atom, rdesktop_clipboard_formats_atom, |
257 |
rdesktop_clipboard_target_atom, wnd, CurrentTime); |
rdesktop_clipboard_target_atom, wnd, CurrentTime); |
258 |
return; |
return; |
259 |
} |
} |
260 |
|
|
262 |
if (selectionowner != None) |
if (selectionowner != None) |
263 |
{ |
{ |
264 |
XConvertSelection(display, primary_atom, targets_atom, |
XConvertSelection(display, primary_atom, targets_atom, |
265 |
rdesktop_clipboard_target_atom, wnd, CurrentTime); |
rdesktop_clipboard_target_atom, wnd, CurrentTime); |
266 |
return; |
return; |
267 |
} |
} |
268 |
|
|
271 |
if (selectionowner != None) |
if (selectionowner != None) |
272 |
{ |
{ |
273 |
XConvertSelection(display, clipboard_atom, targets_atom, |
XConvertSelection(display, clipboard_atom, targets_atom, |
274 |
rdesktop_clipboard_target_atom, wnd, CurrentTime); |
rdesktop_clipboard_target_atom, wnd, CurrentTime); |
275 |
return; |
return; |
276 |
} |
} |
277 |
|
|
307 |
|
|
308 |
/* rdesktop sets _RDESKTOP_CLIPBOARD_FORMATS on the root window when acquiring the clipboard. |
/* rdesktop sets _RDESKTOP_CLIPBOARD_FORMATS on the root window when acquiring the clipboard. |
309 |
Other interested rdesktops can use this to notify their server of the available formats. */ |
Other interested rdesktops can use this to notify their server of the available formats. */ |
310 |
rdesktop_clipboard_formats_atom = XInternAtom(display, "_RDESKTOP_CLIPBOARD_FORMATS", False); |
rdesktop_clipboard_formats_atom = |
311 |
|
XInternAtom(display, "_RDESKTOP_CLIPBOARD_FORMATS", False); |
312 |
XSelectInput(display, DefaultRootWindow(display), PropertyChangeMask); |
XSelectInput(display, DefaultRootWindow(display), PropertyChangeMask); |
313 |
} |
} |