/[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 912 by forsberg, Fri Jun 4 08:42:11 2004 UTC revision 913 by astrand, Mon Jun 27 12:18:48 2005 UTC
# Line 36  static Atom targets[NUM_TARGETS]; Line 36  static Atom targets[NUM_TARGETS];
36  static int have_primary = 0;  static int have_primary = 0;
37  static int rdesktop_is_selection_owner = 0;  static int rdesktop_is_selection_owner = 0;
38    
39    static int g_waiting_for_INCR = 0;
40    static uint8 *g_clip_buffer = 0;
41    static uint32 g_clip_buflen = 0;
42    
43  /* Replace CR-LF to LF (well, rather removing all CR:s) This is done  /* Replace CR-LF to LF (well, rather removing all CR:s) This is done
44     in-place. The length is updated. Handles embedded nulls */     in-place. The length is updated. Handles embedded nulls */
# Line 105  void Line 108  void
108  xclip_handle_SelectionNotify(XSelectionEvent * event)  xclip_handle_SelectionNotify(XSelectionEvent * event)
109  {  {
110          unsigned long nitems, bytes_left;          unsigned long nitems, bytes_left;
111            XWindowAttributes wa;
112          Atom type, best_target, text_target;          Atom type, best_target, text_target;
113          Atom *supported_targets;          Atom *supported_targets;
114          int res, i, format;          int res, i, format;
# Line 161  xclip_handle_SelectionNotify(XSelectionE Line 165  xclip_handle_SelectionNotify(XSelectionE
165    
166          if (type == incr_atom)          if (type == incr_atom)
167          {          {
168                  warning("We don't support INCR transfers at this time. Try cutting less data.\n");                  DEBUG_CLIPBOARD(("Received INCR.\n"));
169                  goto fail;  
170                    XGetWindowAttributes(g_display, g_wnd, &wa);
171                    if ((wa.your_event_mask | PropertyChangeMask) != wa.your_event_mask)
172                    {
173                            XSelectInput(g_display, g_wnd, (wa.your_event_mask | PropertyChangeMask));
174                    }
175                    XDeleteProperty(g_display, g_wnd, type);
176                    XFree(data);
177                    g_waiting_for_INCR = 1;
178    
179                    if ((XGetWindowProperty(g_display, g_wnd, rdesktop_clipboard_target_atom, 0,
180                                            4096L, True, AnyPropertyType,
181                                            &type, &format, &nitems, &bytes_left, &data) != Success))
182                    {
183                            DEBUG_CLIPBOARD(("XGetWindowProperty failed.\n"));
184                            goto fail;
185                    }
186                    else
187                    {
188                            uint8 *translated_data;
189                            uint32 length = nitems;
190    
191                            translated_data = lf2crlf(data, &length);
192    
193                            g_clip_buffer = (uint8 *) xmalloc(length);
194                            strncpy(g_clip_buffer, translated_data, length);
195                            xfree(translated_data);
196                            g_clip_buflen = length;
197    
198                            XFree(data);
199                            return;
200                    }
201          }          }
202    
203          /* Translate linebreaks, but only if not getting data from          /* Translate linebreaks, but only if not getting data from
# Line 248  xclip_handle_PropertyNotify(XPropertyEve Line 283  xclip_handle_PropertyNotify(XPropertyEve
283  {  {
284          unsigned long nitems, bytes_left;          unsigned long nitems, bytes_left;
285          int format, res;          int format, res;
286            XWindowAttributes wa;
287          uint8 *data;          uint8 *data;
288          Atom type;          Atom type;
289    
290            if (event->state == PropertyNewValue && g_waiting_for_INCR)
291            {
292                    DEBUG_CLIPBOARD(("x_clip_handle_PropertyNotify: g_waiting_for_INCR != 0\n"));
293                    if ((XGetWindowProperty(g_display, g_wnd, rdesktop_clipboard_target_atom, 0,
294                                            4096L, True, AnyPropertyType,
295                                            &type, &format, &nitems, &bytes_left, &data) != Success))
296                    {
297                            XFree(data);
298                            return;
299                    }
300    
301                    if (nitems == 0)
302                    {
303                            XGetWindowAttributes(g_display, g_wnd, &wa);
304                            XSelectInput(g_display, g_wnd, (wa.your_event_mask ^ PropertyChangeMask));
305                            XFree(data);
306                            g_waiting_for_INCR = 0;
307    
308                            if (g_clip_buflen > 0)
309                            {
310                                    cliprdr_send_data(g_clip_buffer, g_clip_buflen + 1);
311    
312                                    if (!rdesktop_is_selection_owner)
313                                            cliprdr_send_text_format_announce();
314    
315                                    xfree(g_clip_buffer);
316                                    g_clip_buffer = 0;
317                                    g_clip_buflen = 0;
318                            }
319                    }
320                    else
321                    {
322                            uint8 *translated_data;
323                            uint32 length = nitems;
324    
325                            DEBUG_CLIPBOARD(("Translating linebreaks before sending data\n"));
326                            translated_data = lf2crlf(data, &length);
327    
328                            uint8 *tmp = xmalloc(length + g_clip_buflen);
329                            strncpy(tmp, g_clip_buffer, g_clip_buflen);
330                            xfree(g_clip_buffer);
331    
332                            strncpy(tmp + g_clip_buflen, translated_data, length);
333                            xfree(translated_data);
334    
335                            g_clip_buffer = tmp;
336                            g_clip_buflen += length;
337    
338                            XFree(data);
339                            return;
340                    }
341            }
342    
343          if (event->atom != rdesktop_clipboard_formats_atom)          if (event->atom != rdesktop_clipboard_formats_atom)
344                  return;                  return;
345    

Legend:
Removed from v.912  
changed lines
  Added in v.913

  ViewVC Help
Powered by ViewVC 1.1.26