/[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 942 by astrand, Tue Aug 2 09:27:46 2005 UTC revision 1026 by forsberg, Wed Nov 9 15:15:28 2005 UTC
# Line 127  xclip_handle_SelectionNotify(XSelectionE Line 127  xclip_handle_SelectionNotify(XSelectionE
127                  goto fail;                  goto fail;
128    
129          res = XGetWindowProperty(g_display, g_wnd, rdesktop_clipboard_target_atom,          res = XGetWindowProperty(g_display, g_wnd, rdesktop_clipboard_target_atom,
130                                   0, XMaxRequestSize(g_display), True, AnyPropertyType,                                   0, XMaxRequestSize(g_display), False, AnyPropertyType,
131                                   &type, &format, &nitems, &bytes_left, &data);                                   &type, &format, &nitems, &bytes_left, &data);
132    
133          if (res != Success)          if (res != Success)
# Line 136  xclip_handle_SelectionNotify(XSelectionE Line 136  xclip_handle_SelectionNotify(XSelectionE
136                  goto fail;                  goto fail;
137          }          }
138    
139    
140            if (type == incr_atom)
141            {
142                    DEBUG_CLIPBOARD(("Received INCR.\n"));
143    
144                    XGetWindowAttributes(g_display, g_wnd, &wa);
145                    if ((wa.your_event_mask | PropertyChangeMask) != wa.your_event_mask)
146                    {
147                            XSelectInput(g_display, g_wnd, (wa.your_event_mask | PropertyChangeMask));
148                    }
149                    XDeleteProperty(g_display, g_wnd, rdesktop_clipboard_target_atom);
150                    XFree(data);
151                    g_waiting_for_INCR = 1;
152                    return;
153            }
154            
155            XDeleteProperty(g_display, g_wnd, rdesktop_clipboard_target_atom);
156                    
157          /* Negotiate target format */          /* Negotiate target format */
158          if (event->target == targets_atom)          if (event->target == targets_atom)
159          {          {
# Line 164  xclip_handle_SelectionNotify(XSelectionE Line 182  xclip_handle_SelectionNotify(XSelectionE
182                  return;                  return;
183          }          }
184    
         if (type == incr_atom)  
         {  
                 DEBUG_CLIPBOARD(("Received INCR.\n"));  
   
                 XGetWindowAttributes(g_display, g_wnd, &wa);  
                 if ((wa.your_event_mask | PropertyChangeMask) != wa.your_event_mask)  
                 {  
                         XSelectInput(g_display, g_wnd, (wa.your_event_mask | PropertyChangeMask));  
                 }  
                 XDeleteProperty(g_display, g_wnd, type);  
                 XFree(data);  
                 g_waiting_for_INCR = 1;  
   
                 if ((XGetWindowProperty(g_display, g_wnd, rdesktop_clipboard_target_atom, 0,  
                                         4096L, True, AnyPropertyType,  
                                         &type, &format, &nitems, &bytes_left, &data) != Success))  
                 {  
                         DEBUG_CLIPBOARD(("XGetWindowProperty failed.\n"));  
                         goto fail;  
                 }  
                 else  
                 {  
                         uint8 *translated_data;  
                         uint32 length = nitems;  
   
                         translated_data = lf2crlf(data, &length);  
   
                         g_clip_buffer = (uint8 *) xmalloc(length);  
                         strncpy((char *) g_clip_buffer, (char *) translated_data, length);  
                         xfree(translated_data);  
                         g_clip_buflen = length;  
   
                         XFree(data);  
                         return;  
                 }  
         }  
   
185          /* Translate linebreaks, but only if not getting data from          /* Translate linebreaks, but only if not getting data from
186             other rdesktop instance */             other rdesktop instance */
187          if (event->target != rdesktop_clipboard_formats_atom)          if (event->target != rdesktop_clipboard_formats_atom)
# Line 220  xclip_handle_SelectionNotify(XSelectionE Line 201  xclip_handle_SelectionNotify(XSelectionE
201          XFree(data);          XFree(data);
202    
203          if (!rdesktop_is_selection_owner)          if (!rdesktop_is_selection_owner)
204                  cliprdr_send_text_format_announce();                  cliprdr_send_simple_native_format_announce(CF_TEXT);
205          return;          return;
206    
207        fail:   fail:
208            XDeleteProperty(g_display, g_wnd, rdesktop_clipboard_target_atom);
209            XFree(data);
210          cliprdr_send_data(NULL, 0);          cliprdr_send_data(NULL, 0);
211  }  }
212    
# Line 276  xclip_handle_SelectionClear(void) Line 259  xclip_handle_SelectionClear(void)
259          DEBUG_CLIPBOARD(("xclip_handle_SelectionClear\n"));          DEBUG_CLIPBOARD(("xclip_handle_SelectionClear\n"));
260          have_primary = 0;          have_primary = 0;
261          XDeleteProperty(g_display, DefaultRootWindow(g_display), rdesktop_clipboard_formats_atom);          XDeleteProperty(g_display, DefaultRootWindow(g_display), rdesktop_clipboard_formats_atom);
262          cliprdr_send_text_format_announce();          cliprdr_send_simple_native_format_announce(CF_TEXT);
263  }  }
264    
265  void  void
266  xclip_handle_PropertyNotify(XPropertyEvent * event)  xclip_handle_PropertyNotify(XPropertyEvent * event)
267  {  {
268          unsigned long nitems, bytes_left;          unsigned long nitems;
269            unsigned long offset = 0;
270            unsigned long bytes_left = 1;
271          int format, res;          int format, res;
272          XWindowAttributes wa;          XWindowAttributes wa;
273          uint8 *data;          uint8 *data;
# Line 291  xclip_handle_PropertyNotify(XPropertyEve Line 276  xclip_handle_PropertyNotify(XPropertyEve
276          if (event->state == PropertyNewValue && g_waiting_for_INCR)          if (event->state == PropertyNewValue && g_waiting_for_INCR)
277          {          {
278                  DEBUG_CLIPBOARD(("x_clip_handle_PropertyNotify: g_waiting_for_INCR != 0\n"));                  DEBUG_CLIPBOARD(("x_clip_handle_PropertyNotify: g_waiting_for_INCR != 0\n"));
                 if ((XGetWindowProperty(g_display, g_wnd, rdesktop_clipboard_target_atom, 0,  
                                         4096L, True, AnyPropertyType,  
                                         &type, &format, &nitems, &bytes_left, &data) != Success))  
                 {  
                         XFree(data);  
                         return;  
                 }  
279    
280                  if (nitems == 0)                  while (bytes_left > 0) {
281                  {                          if ((XGetWindowProperty(g_display, g_wnd, rdesktop_clipboard_target_atom, offset,
282                          XGetWindowAttributes(g_display, g_wnd, &wa);                                                  4096L, False, AnyPropertyType,
283                          XSelectInput(g_display, g_wnd, (wa.your_event_mask ^ PropertyChangeMask));                                                  &type, &format, &nitems, &bytes_left, &data) != Success))
284                          XFree(data);                          {
285                          g_waiting_for_INCR = 0;                                  XFree(data);
286                                    return;
287                            }
288    
289                          if (g_clip_buflen > 0)                          if (nitems == 0)
290                          {                          {
291                                  cliprdr_send_data(g_clip_buffer, g_clip_buflen + 1);                                  XGetWindowAttributes(g_display, g_wnd, &wa);
292                                    XSelectInput(g_display, g_wnd, (wa.your_event_mask ^ PropertyChangeMask));
293                                    XFree(data);
294                                    g_waiting_for_INCR = 0;
295    
296                                  if (!rdesktop_is_selection_owner)                                  if (g_clip_buflen > 0)
297                                          cliprdr_send_text_format_announce();                                  {
298                                            cliprdr_send_data(g_clip_buffer, g_clip_buflen + 1);
299    
300                                  xfree(g_clip_buffer);                                          if (!rdesktop_is_selection_owner)
301                                  g_clip_buffer = 0;                                                  cliprdr_send_simple_native_format_announce(CF_TEXT);
302                                  g_clip_buflen = 0;  
303                                            xfree(g_clip_buffer);
304                                            g_clip_buffer = 0;
305                                            g_clip_buflen = 0;
306                                    }
307                          }                          }
308                  }                          else
309                  else                          {
310                  {                                  uint8 *translated_data;
311                          uint8 *translated_data;                                  uint32 length = nitems;
312                          uint32 length = nitems;                                  uint8 *tmp;
313                          uint8 *tmp;  
314                                    offset += (length/4);
315                          DEBUG_CLIPBOARD(("Translating linebreaks before sending data\n"));                                  DEBUG_CLIPBOARD(("Translating linebreaks before sending data\n"));
316                          translated_data = lf2crlf(data, &length);                                  translated_data = lf2crlf(data, &length);
   
                         tmp = xmalloc(length + g_clip_buflen);  
                         strncpy((char *) tmp, (char *) g_clip_buffer, g_clip_buflen);  
                         xfree(g_clip_buffer);  
317    
318                          strncpy((char *) (tmp + g_clip_buflen), (char *) translated_data, length);                                  tmp = xmalloc(length + g_clip_buflen);
319                          xfree(translated_data);                                  strncpy((char *) tmp, (char *) g_clip_buffer, g_clip_buflen);
320                                    xfree(g_clip_buffer);
321    
322                          g_clip_buffer = tmp;                                  strncpy((char *) (tmp + g_clip_buflen), (char *) translated_data, length);
323                          g_clip_buflen += length;                                  xfree(translated_data);
324    
325                          XFree(data);                                  g_clip_buffer = tmp;
326                          return;                                  g_clip_buflen += length;
327    
328                                    XFree(data);
329                            }
330                  }                  }
331                    XDeleteProperty(g_display, g_wnd, rdesktop_clipboard_target_atom);
332          }          }
333    
334          if (event->atom != rdesktop_clipboard_formats_atom)          if (event->atom != rdesktop_clipboard_formats_atom)
# Line 364  xclip_handle_PropertyNotify(XPropertyEve Line 353  xclip_handle_PropertyNotify(XPropertyEve
353          }          }
354    
355          /* PropertyDelete, or XGetWindowProperty failed */          /* PropertyDelete, or XGetWindowProperty failed */
356          cliprdr_send_text_format_announce();          cliprdr_send_simple_native_format_announce(CF_TEXT);
357          rdesktop_is_selection_owner = 0;          rdesktop_is_selection_owner = 0;
358  }  }
359  #endif  #endif
# Line 453  ui_clip_request_data(uint32 format) Line 442  ui_clip_request_data(uint32 format)
442  void  void
443  ui_clip_sync(void)  ui_clip_sync(void)
444  {  {
445          cliprdr_send_text_format_announce();          cliprdr_send_simple_native_format_announce(CF_TEXT);
446  }  }
447    
448    

Legend:
Removed from v.942  
changed lines
  Added in v.1026

  ViewVC Help
Powered by ViewVC 1.1.26