25 |
|
|
26 |
#define NUM_TARGETS 6 |
#define NUM_TARGETS 6 |
27 |
|
|
28 |
extern Display *display; |
extern Display *g_display; |
29 |
extern Window wnd; |
extern Window g_wnd; |
30 |
extern Time last_gesturetime; |
extern Time g_last_gesturetime; |
31 |
|
|
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, rdesktop_clipboard_formats_atom, incr_atom; |
static Atom rdesktop_clipboard_target_atom, rdesktop_clipboard_formats_atom, incr_atom; |
42 |
{ |
{ |
43 |
XEvent xev; |
XEvent xev; |
44 |
|
|
45 |
XChangeProperty(display, req->requestor, req->property, |
XChangeProperty(g_display, req->requestor, req->property, |
46 |
type, format, PropModeReplace, data, length); |
type, format, PropModeReplace, data, length); |
47 |
|
|
48 |
xev.xselection.type = SelectionNotify; |
xev.xselection.type = SelectionNotify; |
53 |
xev.xselection.target = req->target; |
xev.xselection.target = req->target; |
54 |
xev.xselection.property = req->property; |
xev.xselection.property = req->property; |
55 |
xev.xselection.time = req->time; |
xev.xselection.time = req->time; |
56 |
XSendEvent(display, req->requestor, False, NoEventMask, &xev); |
XSendEvent(g_display, req->requestor, False, NoEventMask, &xev); |
57 |
} |
} |
58 |
|
|
59 |
void |
void |
69 |
goto fail; |
goto fail; |
70 |
|
|
71 |
DEBUG_CLIPBOARD(("xclip_handle_SelectionNotify: selection=%s, target=%s, property=%s\n", |
DEBUG_CLIPBOARD(("xclip_handle_SelectionNotify: selection=%s, target=%s, property=%s\n", |
72 |
XGetAtomName(display, event->selection), |
XGetAtomName(g_display, event->selection), |
73 |
XGetAtomName(display, event->target), |
XGetAtomName(g_display, event->target), |
74 |
XGetAtomName(display, event->property))); |
XGetAtomName(g_display, event->property))); |
75 |
|
|
76 |
if (event->property == None) |
if (event->property == None) |
77 |
goto fail; |
goto fail; |
78 |
|
|
79 |
res = XGetWindowProperty(display, wnd, rdesktop_clipboard_target_atom, |
res = XGetWindowProperty(g_display, g_wnd, rdesktop_clipboard_target_atom, |
80 |
0, XMaxRequestSize(display), True, AnyPropertyType, |
0, XMaxRequestSize(g_display), True, AnyPropertyType, |
81 |
&type, &format, &nitems, &bytes_left, &data); |
&type, &format, &nitems, &bytes_left, &data); |
82 |
|
|
83 |
if (res != Success) |
if (res != Success) |
93 |
if (type != None) |
if (type != None) |
94 |
{ |
{ |
95 |
supported_targets = (Atom *) data; |
supported_targets = (Atom *) data; |
96 |
text_target = XInternAtom(display, "TEXT", False); |
text_target = XInternAtom(g_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, |
DEBUG_CLIPBOARD(("Target %d: %s\n", i, |
100 |
XGetAtomName(display, supported_targets[i]))); |
XGetAtomName(g_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, |
XConvertSelection(g_display, primary_atom, best_target, |
111 |
rdesktop_clipboard_target_atom, wnd, event->time); |
rdesktop_clipboard_target_atom, g_wnd, event->time); |
112 |
return; |
return; |
113 |
} |
} |
114 |
|
|
138 |
Atom type; |
Atom type; |
139 |
|
|
140 |
DEBUG_CLIPBOARD(("xclip_handle_SelectionRequest: selection=%s, target=%s, property=%s\n", |
DEBUG_CLIPBOARD(("xclip_handle_SelectionRequest: selection=%s, target=%s, property=%s\n", |
141 |
XGetAtomName(display, event->selection), |
XGetAtomName(g_display, event->selection), |
142 |
XGetAtomName(display, event->target), |
XGetAtomName(g_display, event->target), |
143 |
XGetAtomName(display, event->property))); |
XGetAtomName(g_display, event->property))); |
144 |
|
|
145 |
if (event->target == targets_atom) |
if (event->target == targets_atom) |
146 |
{ |
{ |
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 *) & g_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(g_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, |
&type, &format, &nitems, &bytes_left, |
160 |
(unsigned char **) &wanted_format); |
(unsigned char **) &wanted_format); |
175 |
{ |
{ |
176 |
DEBUG_CLIPBOARD(("xclip_handle_SelectionClear\n")); |
DEBUG_CLIPBOARD(("xclip_handle_SelectionClear\n")); |
177 |
have_primary = 0; |
have_primary = 0; |
178 |
XDeleteProperty(display, DefaultRootWindow(display), rdesktop_clipboard_formats_atom); |
XDeleteProperty(g_display, DefaultRootWindow(g_display), rdesktop_clipboard_formats_atom); |
179 |
cliprdr_send_text_format_announce(); |
cliprdr_send_text_format_announce(); |
180 |
} |
} |
181 |
|
|
195 |
|
|
196 |
if (event->state == PropertyNewValue) |
if (event->state == PropertyNewValue) |
197 |
{ |
{ |
198 |
res = XGetWindowProperty(display, DefaultRootWindow(display), |
res = XGetWindowProperty(g_display, DefaultRootWindow(g_display), |
199 |
rdesktop_clipboard_formats_atom, 0, |
rdesktop_clipboard_formats_atom, 0, |
200 |
XMaxRequestSize(display), False, XA_STRING, &type, &format, |
XMaxRequestSize(g_display), False, XA_STRING, &type, &format, |
201 |
&nitems, &bytes_left, &data); |
&nitems, &bytes_left, &data); |
202 |
|
|
203 |
if ((res == Success) && (nitems > 0)) |
if ((res == Success) && (nitems > 0)) |
217 |
void |
void |
218 |
ui_clip_format_announce(char *data, uint32 length) |
ui_clip_format_announce(char *data, uint32 length) |
219 |
{ |
{ |
220 |
XSetSelectionOwner(display, primary_atom, wnd, last_gesturetime); |
XSetSelectionOwner(g_display, primary_atom, g_wnd, g_last_gesturetime); |
221 |
if (XGetSelectionOwner(display, primary_atom) != wnd) |
if (XGetSelectionOwner(g_display, primary_atom) != g_wnd) |
222 |
{ |
{ |
223 |
warning("Failed to aquire ownership of PRIMARY clipboard\n"); |
warning("Failed to aquire ownership of PRIMARY clipboard\n"); |
224 |
return; |
return; |
225 |
} |
} |
226 |
|
|
227 |
have_primary = 1; |
have_primary = 1; |
228 |
XChangeProperty(display, DefaultRootWindow(display), |
XChangeProperty(g_display, DefaultRootWindow(g_display), |
229 |
rdesktop_clipboard_formats_atom, XA_STRING, 8, PropModeReplace, data, |
rdesktop_clipboard_formats_atom, XA_STRING, 8, PropModeReplace, data, |
230 |
length); |
length); |
231 |
|
|
232 |
XSetSelectionOwner(display, clipboard_atom, wnd, last_gesturetime); |
XSetSelectionOwner(g_display, clipboard_atom, g_wnd, g_last_gesturetime); |
233 |
if (XGetSelectionOwner(display, clipboard_atom) != wnd) |
if (XGetSelectionOwner(g_display, clipboard_atom) != g_wnd) |
234 |
warning("Failed to aquire ownership of CLIPBOARD clipboard\n"); |
warning("Failed to aquire ownership of CLIPBOARD clipboard\n"); |
235 |
} |
} |
236 |
|
|
250 |
|
|
251 |
if (rdesktop_is_selection_owner) |
if (rdesktop_is_selection_owner) |
252 |
{ |
{ |
253 |
XChangeProperty(display, wnd, rdesktop_clipboard_target_atom, |
XChangeProperty(g_display, g_wnd, rdesktop_clipboard_target_atom, |
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(g_display, primary_atom, rdesktop_clipboard_formats_atom, |
257 |
rdesktop_clipboard_target_atom, wnd, CurrentTime); |
rdesktop_clipboard_target_atom, g_wnd, CurrentTime); |
258 |
return; |
return; |
259 |
} |
} |
260 |
|
|
261 |
selectionowner = XGetSelectionOwner(display, primary_atom); |
selectionowner = XGetSelectionOwner(g_display, primary_atom); |
262 |
if (selectionowner != None) |
if (selectionowner != None) |
263 |
{ |
{ |
264 |
XConvertSelection(display, primary_atom, targets_atom, |
XConvertSelection(g_display, primary_atom, targets_atom, |
265 |
rdesktop_clipboard_target_atom, wnd, CurrentTime); |
rdesktop_clipboard_target_atom, g_wnd, CurrentTime); |
266 |
return; |
return; |
267 |
} |
} |
268 |
|
|
269 |
/* No PRIMARY, try CLIPBOARD */ |
/* No PRIMARY, try CLIPBOARD */ |
270 |
selectionowner = XGetSelectionOwner(display, clipboard_atom); |
selectionowner = XGetSelectionOwner(g_display, clipboard_atom); |
271 |
if (selectionowner != None) |
if (selectionowner != None) |
272 |
{ |
{ |
273 |
XConvertSelection(display, clipboard_atom, targets_atom, |
XConvertSelection(g_display, clipboard_atom, targets_atom, |
274 |
rdesktop_clipboard_target_atom, wnd, CurrentTime); |
rdesktop_clipboard_target_atom, g_wnd, CurrentTime); |
275 |
return; |
return; |
276 |
} |
} |
277 |
|
|
292 |
if (!cliprdr_init()) |
if (!cliprdr_init()) |
293 |
return; |
return; |
294 |
|
|
295 |
primary_atom = XInternAtom(display, "PRIMARY", False); |
primary_atom = XInternAtom(g_display, "PRIMARY", False); |
296 |
clipboard_atom = XInternAtom(display, "CLIPBOARD", False); |
clipboard_atom = XInternAtom(g_display, "CLIPBOARD", False); |
297 |
targets_atom = XInternAtom(display, "TARGETS", False); |
targets_atom = XInternAtom(g_display, "TARGETS", False); |
298 |
timestamp_atom = XInternAtom(display, "TIMESTAMP", False); |
timestamp_atom = XInternAtom(g_display, "TIMESTAMP", False); |
299 |
rdesktop_clipboard_target_atom = XInternAtom(display, "_RDESKTOP_CLIPBOARD_TARGET", False); |
rdesktop_clipboard_target_atom = XInternAtom(g_display, "_RDESKTOP_CLIPBOARD_TARGET", False); |
300 |
incr_atom = XInternAtom(display, "INCR", False); |
incr_atom = XInternAtom(g_display, "INCR", False); |
301 |
targets[0] = targets_atom; |
targets[0] = targets_atom; |
302 |
targets[1] = XInternAtom(display, "TEXT", False); |
targets[1] = XInternAtom(g_display, "TEXT", False); |
303 |
targets[2] = XInternAtom(display, "UTF8_STRING", False); |
targets[2] = XInternAtom(g_display, "UTF8_STRING", False); |
304 |
targets[3] = XInternAtom(display, "text/unicode", False); |
targets[3] = XInternAtom(g_display, "text/unicode", False); |
305 |
targets[4] = XInternAtom(display, "TIMESTAMP", False); |
targets[4] = XInternAtom(g_display, "TIMESTAMP", False); |
306 |
targets[5] = XA_STRING; |
targets[5] = XA_STRING; |
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 = |
rdesktop_clipboard_formats_atom = |
311 |
XInternAtom(display, "_RDESKTOP_CLIPBOARD_FORMATS", False); |
XInternAtom(g_display, "_RDESKTOP_CLIPBOARD_FORMATS", False); |
312 |
XSelectInput(display, DefaultRootWindow(display), PropertyChangeMask); |
XSelectInput(g_display, DefaultRootWindow(g_display), PropertyChangeMask); |
313 |
} |
} |