/[rdesktop]/sourceforge.net/trunk/rdesktop/xclip.c
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /sourceforge.net/trunk/rdesktop/xclip.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 432 by matthewc, Tue Jul 1 09:31:25 2003 UTC revision 1027 by forsberg, Mon Nov 14 14:11:42 2005 UTC
# Line 23  Line 23 
23  #include <X11/Xatom.h>  #include <X11/Xatom.h>
24  #include "rdesktop.h"  #include "rdesktop.h"
25    
26  #define NUM_TARGETS 6  /*
27      To gain better understanding of this code, one could be assisted by the following documents:
28      - Inter-Client Communication Conventions Manual (ICCCM)
29        HTML: http://tronche.com/gui/x/icccm/
30        PDF:  http://ftp.xfree86.org/pub/XFree86/4.5.0/doc/PDF/icccm.pdf
31      - MSDN: Clipboard Formats
32        http://msdn.microsoft.com/library/en-us/winui/winui/windowsuserinterface/dataexchange/clipboard/clipboardformats.asp
33    */
34    
35  extern Display *display;  #define NUM_TARGETS 6
 extern Window wnd;  
 extern Time last_gesturetime;  
36    
37  static Atom clipboard_atom, primary_atom, targets_atom, timestamp_atom;  extern Display *g_display;
38  static Atom rdesktop_clipboard_target_atom, rdesktop_clipboard_formats_atom, incr_atom;  extern Window g_wnd;
39    extern Time g_last_gesturetime;
40    
41    /* Atoms of the two X selections we're dealing with: CLIPBOARD (explicit-copy) and PRIMARY (selection-copy) */
42    static Atom clipboard_atom, primary_atom;
43    /* Atom of the TARGETS clipboard target */
44    static Atom targets_atom;
45    /* Atom of the TIMESTAMP clipboard target */
46    static Atom timestamp_atom;
47    /* Atom _RDESKTOP_CLIPBOARD_TARGET which has multiple uses:
48       - The 'property' argument in XConvertSelection calls: This is the property of our
49         window into which XConvertSelection will store the received clipboard data.
50       - In a clipboard request of target _RDESKTOP_CLIPBOARD_FORMATS, an XA_INTEGER-typed
51         property carrying the Windows native (CF_...) format desired by the requestor.
52         Requestor set this property (e.g. requestor_wnd[_RDESKTOP_CLIPBOARD_TARGET] = CF_TEXT)
53         before requesting clipboard data from a fellow rdesktop using
54         the _RDESKTOP_CLIPBOARD_FORMATS target. */
55    static Atom rdesktop_clipboard_target_atom;
56    /* Atom _RDESKTOP_CLIPBOARD_FORMATS which has multiple uses:
57       - The clipboard target (X jargon for "clipboard format") for rdesktop-to-rdesktop interchange
58         of Windows native clipboard data.
59         This target cannot be used standalone; the requestor must keep the
60         _RDESKTOP_CLIPBOARD_TARGET property on his window denoting
61         the Windows native clipboard format being requested.
62       - The root window property set by rdesktop when it owns the clipboard,
63         denoting all Windows native clipboard formats it offers via
64         requests of the _RDESKTOP_CLIPBOARD_FORMATS target. */
65    static Atom rdesktop_clipboard_formats_atom;
66    /* Atom of the INCR clipboard type (see ICCCM on "INCR Properties") */
67    static Atom incr_atom;
68    /* Stores the last "selection request" (= another X client requesting clipboard data from us).
69       To satisfy such a request, we request the clipboard data from the RDP server.
70       When we receive the response from the RDP server (asynchronously), this variable gives us
71       the context to proceed. */
72  static XSelectionRequestEvent selection_request;  static XSelectionRequestEvent selection_request;
73    /* Array of offered clipboard targets that will be sent to fellow X clients upon a TARGETS request. */
74  static Atom targets[NUM_TARGETS];  static Atom targets[NUM_TARGETS];
75    /* Denotes that this client currently holds the PRIMARY selection. */
76  static int have_primary = 0;  static int have_primary = 0;
77    /* Denotes that an rdesktop (not this rdesktop) is owning the selection,
78       allowing us to interchange Windows native clipboard data directly. */
79  static int rdesktop_is_selection_owner = 0;  static int rdesktop_is_selection_owner = 0;
80    
81    /* Denotes that an INCR ("chunked") transfer is in progress. */
82    static int g_waiting_for_INCR = 0;
83    /* Buffers an INCR transfer. */
84    static uint8 *g_clip_buffer = 0;
85    /* Denotes the size of g_clip_buffer. */
86    static uint32 g_clip_buflen = 0;
87    
88    /* Translate LF to CR-LF. To do this, we must allocate more memory.
89       The returned string is null-terminated, as required by CF_TEXT.
90       Does not stop on embedded nulls.
91       The length is updated. */
92  static void  static void
93  xclip_provide_selection(XSelectionRequestEvent *req, Atom type, unsigned int format, uint8 *data, uint32 length)  crlf2lf(uint8 * data, uint32 * length)
94    {
95            uint8 *dst, *src;
96            src = dst = data;
97            while (src < data + *length)
98            {
99                    if (*src != '\x0d')
100                            *dst++ = *src;
101                    src++;
102            }
103            *length = dst - data;
104    }
105    
106    /* Translate LF to CR-LF. To do this, we must allocate more memory.  
107       The length is updated. */
108    static uint8 *
109    lf2crlf(uint8 * data, uint32 * length)
110    {
111            uint8 *result, *p, *o;
112    
113            /* Worst case: Every char is LF */
114            result = xmalloc(*length * 2);
115    
116            p = data;
117            o = result;
118    
119            while (p < data + *length)
120            {
121                    if (*p == '\x0a')
122                            *o++ = '\x0d';
123                    *o++ = *p++;
124            }
125            *length = o - result;
126    
127            /* Convenience */
128            *o++ = '\0';
129    
130            return result;
131    }
132    
133    
134    static void
135    xclip_provide_selection(XSelectionRequestEvent * req, Atom type, unsigned int format, uint8 * data,
136                            uint32 length)
137  {  {
138          XEvent xev;          XEvent xev;
139    
140          XChangeProperty(display, req->requestor, req->property,          XChangeProperty(g_display, req->requestor, req->property,
141                          type, format, PropModeReplace, data, length);                          type, format, PropModeReplace, data, length);
142    
143          xev.xselection.type = SelectionNotify;          xev.xselection.type = SelectionNotify;
# Line 52  xclip_provide_selection(XSelectionReques Line 148  xclip_provide_selection(XSelectionReques
148          xev.xselection.target = req->target;          xev.xselection.target = req->target;
149          xev.xselection.property = req->property;          xev.xselection.property = req->property;
150          xev.xselection.time = req->time;          xev.xselection.time = req->time;
151          XSendEvent(display, req->requestor, False, NoEventMask, &xev);          XSendEvent(g_display, req->requestor, False, NoEventMask, &xev);
152  }  }
153    
154    /* This function is called for SelectionNotify events.
155       The SelectionNotify message is sent from the clipboard owner to the requestor
156       after his request was satisfied.
157       If this function is called, we're the requestor side. */
158    #ifndef MAKE_PROTO
159  void  void
160  xclip_handle_SelectionNotify(XSelectionEvent * event)  xclip_handle_SelectionNotify(XSelectionEvent * event)
161  {  {
162          unsigned long nitems, bytes_left;          unsigned long nitems, bytes_left;
163            XWindowAttributes wa;
164          Atom type, best_target, text_target;          Atom type, best_target, text_target;
165          Atom *supported_targets;          Atom *supported_targets;
166          int res, i, format;          int res, i, format;
# Line 68  xclip_handle_SelectionNotify(XSelectionE Line 170  xclip_handle_SelectionNotify(XSelectionE
170                  goto fail;                  goto fail;
171    
172          DEBUG_CLIPBOARD(("xclip_handle_SelectionNotify: selection=%s, target=%s, property=%s\n",          DEBUG_CLIPBOARD(("xclip_handle_SelectionNotify: selection=%s, target=%s, property=%s\n",
173                           XGetAtomName(display, event->selection),                           XGetAtomName(g_display, event->selection),
174                           XGetAtomName(display, event->target),                           XGetAtomName(g_display, event->target),
175                           XGetAtomName(display, event->property)));                           XGetAtomName(g_display, event->property)));
176    
177          if (event->property == None)          if (event->property == None)
178                  goto fail;                  goto fail;
179    
180          res = XGetWindowProperty(display, wnd, rdesktop_clipboard_target_atom,          res = XGetWindowProperty(g_display, g_wnd, rdesktop_clipboard_target_atom,
181                                   0, XMaxRequestSize(display), True, AnyPropertyType,                                   0, XMaxRequestSize(g_display), False, AnyPropertyType,
182                                   &type, &format, &nitems, &bytes_left, &data);                                   &type, &format, &nitems, &bytes_left, &data);
183    
184          if (res != Success)          if (res != Success)
# Line 85  xclip_handle_SelectionNotify(XSelectionE Line 187  xclip_handle_SelectionNotify(XSelectionE
187                  goto fail;                  goto fail;
188          }          }
189    
190    
191            if (type == incr_atom)
192            {
193                    DEBUG_CLIPBOARD(("Received INCR.\n"));
194    
195                    XGetWindowAttributes(g_display, g_wnd, &wa);
196                    if ((wa.your_event_mask | PropertyChangeMask) != wa.your_event_mask)
197                    {
198                            XSelectInput(g_display, g_wnd, (wa.your_event_mask | PropertyChangeMask));
199                    }
200                    XDeleteProperty(g_display, g_wnd, rdesktop_clipboard_target_atom);
201                    XFree(data);
202                    g_waiting_for_INCR = 1;
203                    return;
204            }
205            
206            XDeleteProperty(g_display, g_wnd, rdesktop_clipboard_target_atom);
207                    
208            /* Negotiate target format */
209          if (event->target == targets_atom)          if (event->target == targets_atom)
210          {          {
211                  /* FIXME: We should choose format here based on what the server wanted */                  /* FIXME: We should choose format here based on what the server wanted */
# Line 92  xclip_handle_SelectionNotify(XSelectionE Line 213  xclip_handle_SelectionNotify(XSelectionE
213                  if (type != None)                  if (type != None)
214                  {                  {
215                          supported_targets = (Atom *) data;                          supported_targets = (Atom *) data;
216                          text_target = XInternAtom(display, "TEXT", False);                          text_target = XInternAtom(g_display, "TEXT", False);
217                          for (i = 0; i < nitems; i++)                          for (i = 0; i < nitems; i++)
218                          {                          {
219                                  DEBUG_CLIPBOARD(("Target %d: %s\n", i, XGetAtomName(display, supported_targets[i])));                                  DEBUG_CLIPBOARD(("Target %d: %s\n", i,
220                                                     XGetAtomName(g_display, supported_targets[i])));
221                                  if (supported_targets[i] == text_target)                                  if (supported_targets[i] == text_target)
222                                  {                                  {
223                                          DEBUG_CLIPBOARD(("Other party supports TEXT, choosing that as best_target\n"));                                          DEBUG_CLIPBOARD(("Other party supports TEXT, choosing that as best_target\n"));
224                                          best_target = text_target;                                          best_target = text_target;
225                                            break;
226                                  }                                  }
227                          }                          }
228                          XFree(data);                          XFree(data);
229                  }                  }
230    
231                  XConvertSelection(display, primary_atom, best_target, rdesktop_clipboard_target_atom, wnd, event->time);                  XConvertSelection(g_display, primary_atom, best_target,
232                                      rdesktop_clipboard_target_atom, g_wnd, event->time);
233                  return;                  return;
234          }          }
235    
236          if (type == incr_atom)          /* Translate linebreaks, but only if not getting data from
237               other rdesktop instance */
238            if (event->target != rdesktop_clipboard_formats_atom)
239            {
240                    uint8 *translated_data;
241                    uint32 length = nitems;
242    
243                    DEBUG_CLIPBOARD(("Translating linebreaks before sending data\n"));
244                    translated_data = lf2crlf(data, &length);
245                    cliprdr_send_data(translated_data, length + 1);
246                    xfree(translated_data); /* Not the same thing as XFree! */
247            }
248            else
249          {          {
250                  warning("We don't support INCR transfers at this time. Try cutting less data.\n");                  cliprdr_send_data(data, nitems + 1);
                 goto fail;  
251          }          }
   
         cliprdr_send_data(data, nitems+1);  
252          XFree(data);          XFree(data);
253    
254          if (!rdesktop_is_selection_owner)          if (!rdesktop_is_selection_owner)
255                  cliprdr_send_text_format_announce();                  cliprdr_send_simple_native_format_announce(CF_TEXT);
256          return;          return;
257    
258  fail:   fail:
259            XDeleteProperty(g_display, g_wnd, rdesktop_clipboard_target_atom);
260            XFree(data);
261          cliprdr_send_data(NULL, 0);          cliprdr_send_data(NULL, 0);
262  }  }
263    
264    /* This function is called for SelectionRequest events.
265       The SelectionRequest message is sent from the requestor to the clipboard owner
266       to request clipboard data.
267     */
268  void  void
269  xclip_handle_SelectionRequest(XSelectionRequestEvent *event)  xclip_handle_SelectionRequest(XSelectionRequestEvent * event)
270  {  {
271          unsigned long nitems, bytes_left;          unsigned long nitems, bytes_left;
272            unsigned char *prop_return;
273          uint32 *wanted_format;          uint32 *wanted_format;
274          int format, res;          int format, res;
275          Atom type;          Atom type;
276    
277          DEBUG_CLIPBOARD(("xclip_handle_SelectionRequest: selection=%s, target=%s, property=%s\n",          DEBUG_CLIPBOARD(("xclip_handle_SelectionRequest: selection=%s, target=%s, property=%s\n",
278                           XGetAtomName(display, event->selection),                           XGetAtomName(g_display, event->selection),
279                           XGetAtomName(display, event->target),                           XGetAtomName(g_display, event->target),
280                           XGetAtomName(display, event->property)));                           XGetAtomName(g_display, event->property)));
281    
282          if (event->target == targets_atom)          if (event->target == targets_atom)
283          {          {
284                  xclip_provide_selection(event, XA_ATOM, 32, (uint8 *)&targets, NUM_TARGETS);                  xclip_provide_selection(event, XA_ATOM, 32, (uint8 *) & targets, NUM_TARGETS);
285                  return;                  return;
286          }          }
287          else if (event->target == timestamp_atom)          else if (event->target == timestamp_atom)
288          {          {
289                  xclip_provide_selection(event, XA_INTEGER, 32, (uint8 *)&last_gesturetime, 1);                  xclip_provide_selection(event, XA_INTEGER, 32, (uint8 *) & g_last_gesturetime, 1);
290                  return;                  return;
291          }          }
292          else if (event->target == rdesktop_clipboard_formats_atom)          else if (event->target == rdesktop_clipboard_formats_atom)
293          {          {
294                  res = XGetWindowProperty(display, event->requestor,                  res = XGetWindowProperty(g_display, event->requestor,
295                                  rdesktop_clipboard_target_atom, 0, 1, True, XA_INTEGER,                                           rdesktop_clipboard_target_atom, 0, 1, True, XA_INTEGER,
296                                  &type, &format, &nitems, &bytes_left, (unsigned char **) &wanted_format);                                           &type, &format, &nitems, &bytes_left, &prop_return);
297                    wanted_format = (uint32 *) prop_return;
298                  format = (res == Success) ? *wanted_format : CF_TEXT;                  format = (res == Success) ? *wanted_format : CF_TEXT;
299                    /* FIXME: Need to free returned data? */
300          }          }
301          else          else
302          {          {
# Line 166  xclip_handle_SelectionRequest(XSelection Line 308  xclip_handle_SelectionRequest(XSelection
308          /* wait for data */          /* wait for data */
309  }  }
310    
311    /* When this rdesktop holds ownership over the clipboard, it means the clipboard data
312       is offered by the RDP server (and when its pasted inside RDP, there's no network
313       roundtrip). This event symbolizes this rdesktop lost onwership of the clipboard
314       to some other X client. We should find out what clipboard formats this other
315       client offers and announce that to RDP. */
316  void  void
317  xclip_handle_SelectionClear(void)  xclip_handle_SelectionClear(void)
318  {  {
319          DEBUG_CLIPBOARD(("xclip_handle_SelectionClear\n"));          DEBUG_CLIPBOARD(("xclip_handle_SelectionClear\n"));
320          have_primary = 0;          have_primary = 0;
321          XDeleteProperty(display, DefaultRootWindow(display), rdesktop_clipboard_formats_atom);          XDeleteProperty(g_display, DefaultRootWindow(g_display), rdesktop_clipboard_formats_atom);
322          cliprdr_send_text_format_announce();          cliprdr_send_simple_native_format_announce(CF_TEXT);
323  }  }
324    
325    /* Called when any property changes in our window or the root window. */
326  void  void
327  xclip_handle_PropertyNotify(XPropertyEvent *event)  xclip_handle_PropertyNotify(XPropertyEvent * event)
328  {  {
329          unsigned long nitems, bytes_left;          unsigned long nitems;
330            unsigned long offset = 0;
331            unsigned long bytes_left = 1;
332          int format, res;          int format, res;
333            XWindowAttributes wa;
334          uint8 *data;          uint8 *data;
335          Atom type;          Atom type;
336    
337            if (event->state == PropertyNewValue && g_waiting_for_INCR)
338            {
339                    DEBUG_CLIPBOARD(("x_clip_handle_PropertyNotify: g_waiting_for_INCR != 0\n"));
340    
341                    while (bytes_left > 0) {
342                            if ((XGetWindowProperty(g_display, g_wnd, rdesktop_clipboard_target_atom, offset,
343                                                    4096L, False, AnyPropertyType,
344                                                    &type, &format, &nitems, &bytes_left, &data) != Success))
345                            {
346                                    XFree(data);
347                                    return;
348                            }
349    
350                            if (nitems == 0)
351                            {
352                                    XGetWindowAttributes(g_display, g_wnd, &wa);
353                                    XSelectInput(g_display, g_wnd, (wa.your_event_mask ^ PropertyChangeMask));
354                                    XFree(data);
355                                    g_waiting_for_INCR = 0;
356    
357                                    if (g_clip_buflen > 0)
358                                    {
359                                            cliprdr_send_data(g_clip_buffer, g_clip_buflen + 1);
360    
361                                            if (!rdesktop_is_selection_owner)
362                                                    cliprdr_send_simple_native_format_announce(CF_TEXT);
363    
364                                            xfree(g_clip_buffer);
365                                            g_clip_buffer = 0;
366                                            g_clip_buflen = 0;
367                                    }
368                            }
369                            else
370                            {
371                                    uint8 *translated_data;
372                                    uint32 length = nitems;
373                                    uint8 *tmp;
374    
375                                    offset += (length/4);
376                                    DEBUG_CLIPBOARD(("Translating linebreaks before sending data\n"));
377                                    translated_data = lf2crlf(data, &length);
378    
379                                    tmp = xmalloc(length + g_clip_buflen);
380                                    strncpy((char *) tmp, (char *) g_clip_buffer, g_clip_buflen);
381                                    xfree(g_clip_buffer);
382    
383                                    strncpy((char *) (tmp + g_clip_buflen), (char *) translated_data, length);
384                                    xfree(translated_data);
385    
386                                    g_clip_buffer = tmp;
387                                    g_clip_buflen += length;
388    
389                                    XFree(data);
390                            }
391                    }
392                    XDeleteProperty(g_display, g_wnd, rdesktop_clipboard_target_atom);
393            }
394    
395          if (event->atom != rdesktop_clipboard_formats_atom)          if (event->atom != rdesktop_clipboard_formats_atom)
396                  return;                  return;
397    
398          if (have_primary) /* from us */          if (have_primary)       /* from us */
399                  return;                  return;
400    
401          if (event->state == PropertyNewValue)          if (event->state == PropertyNewValue)
402          {          {
403                  res = XGetWindowProperty(display, DefaultRootWindow(display),                  res = XGetWindowProperty(g_display, DefaultRootWindow(g_display),
404                          rdesktop_clipboard_formats_atom, 0, XMaxRequestSize(display), False, XA_STRING,                                           rdesktop_clipboard_formats_atom, 0,
405                          &type, &format, &nitems, &bytes_left, &data);                                           XMaxRequestSize(g_display), False, XA_STRING, &type,
406                                             &format, &nitems, &bytes_left, &data);
407    
408                  if ((res == Success) && (nitems > 0))                  if ((res == Success) && (nitems > 0))
409                  {                  {
# Line 204  xclip_handle_PropertyNotify(XPropertyEve Line 414  xclip_handle_PropertyNotify(XPropertyEve
414          }          }
415    
416          /* PropertyDelete, or XGetWindowProperty failed */          /* PropertyDelete, or XGetWindowProperty failed */
417          cliprdr_send_text_format_announce();          cliprdr_send_simple_native_format_announce(CF_TEXT);
418          rdesktop_is_selection_owner = 0;          rdesktop_is_selection_owner = 0;
419  }  }
420    #endif
421    
422    
423    /* Called when the RDP server announces new clipboard data formats.
424       In response, we:
425       - take ownership over the clipboard
426       - declare those formats in their Windows native form
427         to other rdesktop instances on this X server */
428  void  void
429  ui_clip_format_announce(char *data, uint32 length)  ui_clip_format_announce(uint8 * data, uint32 length)
430  {  {
431          XSetSelectionOwner(display, primary_atom, wnd, last_gesturetime);          XSetSelectionOwner(g_display, primary_atom, g_wnd, g_last_gesturetime);
432          if (XGetSelectionOwner(display, primary_atom) != wnd)          if (XGetSelectionOwner(g_display, primary_atom) != g_wnd)
433          {          {
434                  warning("Failed to aquire ownership of PRIMARY clipboard\n");                  warning("Failed to aquire ownership of PRIMARY clipboard\n");
435                  return;                  return;
436          }          }
437    
438          have_primary = 1;          have_primary = 1;
439          XChangeProperty(display, DefaultRootWindow(display),          XChangeProperty(g_display, DefaultRootWindow(g_display),
440                          rdesktop_clipboard_formats_atom, XA_STRING, 8, PropModeReplace, data, length);                          rdesktop_clipboard_formats_atom, XA_STRING, 8, PropModeReplace, data,
441                            length);
442    
443          XSetSelectionOwner(display, clipboard_atom, wnd, last_gesturetime);          XSetSelectionOwner(g_display, clipboard_atom, g_wnd, g_last_gesturetime);
444          if (XGetSelectionOwner(display, clipboard_atom) != wnd)          if (XGetSelectionOwner(g_display, clipboard_atom) != g_wnd)
445                  warning("Failed to aquire ownership of CLIPBOARD clipboard\n");                  warning("Failed to aquire ownership of CLIPBOARD clipboard\n");
446  }  }
447    
448    
449  void  void
450  ui_clip_handle_data(char *data, uint32 length)  ui_clip_handle_data(uint8 * data, uint32 length)
451  {  {
452          xclip_provide_selection(&selection_request, XA_STRING, 8, data, length-1);          if (selection_request.target != rdesktop_clipboard_formats_atom)
453            {
454                    uint8 *firstnull;
455    
456                    /* translate linebreaks */
457                    crlf2lf(data, &length);
458    
459                    /* Only send data up to null byte, if any */
460                    firstnull = (uint8 *) strchr((char *) data, '\0');
461                    if (firstnull)
462                    {
463                            length = firstnull - data + 1;
464                    }
465            }
466    
467            xclip_provide_selection(&selection_request, XA_STRING, 8, data, length - 1);
468  }  }
469    
470  void  void
# Line 244  ui_clip_request_data(uint32 format) Line 476  ui_clip_request_data(uint32 format)
476    
477          if (rdesktop_is_selection_owner)          if (rdesktop_is_selection_owner)
478          {          {
479                  XChangeProperty(display, wnd, rdesktop_clipboard_target_atom,                  XChangeProperty(g_display, g_wnd, rdesktop_clipboard_target_atom,
480                                  XA_INTEGER, 32, PropModeReplace, (unsigned char *) &format, 1);                                  XA_INTEGER, 32, PropModeReplace, (unsigned char *) &format, 1);
481    
482                  XConvertSelection(display, primary_atom, rdesktop_clipboard_formats_atom,                  XConvertSelection(g_display, primary_atom, rdesktop_clipboard_formats_atom,
483                                          rdesktop_clipboard_target_atom, wnd, CurrentTime);                                    rdesktop_clipboard_target_atom, g_wnd, CurrentTime);
484                  return;                  return;
485          }          }
486    
487          selectionowner = XGetSelectionOwner(display, primary_atom);          selectionowner = XGetSelectionOwner(g_display, primary_atom);
488          if (selectionowner != None)          if (selectionowner != None)
489          {          {
490                  XConvertSelection(display, primary_atom, targets_atom,                  XConvertSelection(g_display, primary_atom, targets_atom,
491                                          rdesktop_clipboard_target_atom, wnd, CurrentTime);                                    rdesktop_clipboard_target_atom, g_wnd, CurrentTime);
492                  return;                  return;
493          }          }
494    
495          /* No PRIMARY, try CLIPBOARD */          /* No PRIMARY, try CLIPBOARD */
496          selectionowner = XGetSelectionOwner(display, clipboard_atom);          selectionowner = XGetSelectionOwner(g_display, clipboard_atom);
497          if (selectionowner != None)          if (selectionowner != None)
498          {          {
499                  XConvertSelection(display, clipboard_atom, targets_atom,                  XConvertSelection(g_display, clipboard_atom, targets_atom,
500                                          rdesktop_clipboard_target_atom, wnd, CurrentTime);                                    rdesktop_clipboard_target_atom, g_wnd, CurrentTime);
501                  return;                  return;
502          }          }
503    
# Line 276  ui_clip_request_data(uint32 format) Line 508  ui_clip_request_data(uint32 format)
508  void  void
509  ui_clip_sync(void)  ui_clip_sync(void)
510  {  {
511          cliprdr_send_text_format_announce();          cliprdr_send_simple_native_format_announce(CF_TEXT);
512  }  }
513    
514    
# Line 286  xclip_init(void) Line 518  xclip_init(void)
518          if (!cliprdr_init())          if (!cliprdr_init())
519                  return;                  return;
520    
521          primary_atom = XInternAtom(display, "PRIMARY", False);          primary_atom = XInternAtom(g_display, "PRIMARY", False);
522          clipboard_atom = XInternAtom(display, "CLIPBOARD", False);          clipboard_atom = XInternAtom(g_display, "CLIPBOARD", False);
523          targets_atom = XInternAtom(display, "TARGETS", False);          targets_atom = XInternAtom(g_display, "TARGETS", False);
524          timestamp_atom = XInternAtom(display, "TIMESTAMP", False);          timestamp_atom = XInternAtom(g_display, "TIMESTAMP", False);
525          rdesktop_clipboard_target_atom = XInternAtom(display, "_RDESKTOP_CLIPBOARD_TARGET", False);          rdesktop_clipboard_target_atom =
526          incr_atom = XInternAtom(display, "INCR", False);                  XInternAtom(g_display, "_RDESKTOP_CLIPBOARD_TARGET", False);
527            incr_atom = XInternAtom(g_display, "INCR", False);
528          targets[0] = targets_atom;          targets[0] = targets_atom;
529          targets[1] = XInternAtom(display, "TEXT", False);          targets[1] = XInternAtom(g_display, "TEXT", False);
530          targets[2] = XInternAtom(display, "UTF8_STRING", False);          targets[2] = XInternAtom(g_display, "STRING", False);
531          targets[3] = XInternAtom(display, "text/unicode", False);          targets[3] = XInternAtom(g_display, "text/unicode", False);
532          targets[4] = XInternAtom(display, "TIMESTAMP", False);          targets[4] = XInternAtom(g_display, "TIMESTAMP", False);
533          targets[5] = XA_STRING;          targets[5] = XA_STRING;
534    
535          /* 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.
536             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. */
537          rdesktop_clipboard_formats_atom = XInternAtom(display, "_RDESKTOP_CLIPBOARD_FORMATS", False);          rdesktop_clipboard_formats_atom =
538          XSelectInput(display, DefaultRootWindow(display), PropertyChangeMask);                  XInternAtom(g_display, "_RDESKTOP_CLIPBOARD_FORMATS", False);
539            XSelectInput(g_display, DefaultRootWindow(g_display), PropertyChangeMask);
540  }  }

Legend:
Removed from v.432  
changed lines
  Added in v.1027

  ViewVC Help
Powered by ViewVC 1.1.26