/[rdesktop]/sourceforge.net/trunk/rdesktop/cliprdr.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/cliprdr.c

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

revision 387 by forsberg, Fri Jun 6 09:25:30 2003 UTC revision 390 by forsberg, Fri Jun 6 09:28:21 2003 UTC
# Line 25  Line 25 
25  extern BOOL encryption;  extern BOOL encryption;
26  extern Display *display;  extern Display *display;
27  extern Window wnd;  extern Window wnd;
28  extern Time last_keyrelease;  extern Time last_gesturetime;
29    
30    // static Time selection_timestamp;
31  static Atom clipboard_atom, primary_atom, targets_atom, timestamp_atom;  static Atom clipboard_atom, primary_atom, targets_atom, timestamp_atom;
32  static Atom rdesktop_clipboard_target_atom;  static Atom rdesktop_clipboard_target_atom;
33  static cliprdr_dataformat *server_formats = NULL;  static cliprdr_dataformat *server_formats = NULL;
34  static uint16 num_server_formats = 0;  static uint16 num_server_formats = 0;
35  static XSelectionEvent selection_event;  static XSelectionEvent selection_event;
36    static uint16 clipboard_channelno;
37    
38  static void  static void
39  cliprdr_print_server_formats(void)  cliprdr_print_server_formats(void)
# Line 50  cliprdr_print_server_formats(void) Line 52  cliprdr_print_server_formats(void)
52          DEBUG_CLIPBOARD(("There were %d server formats.\n", i));          DEBUG_CLIPBOARD(("There were %d server formats.\n", i));
53  #endif  #endif
54  }  }
55    /*
56    static void
57    cliprdr_set_selection_timestamp(void)
58    {
59            XEvent xev;
60            DEBUG_CLIPBOARD(("Changing a property in order to get a timestamp\n"));
61            fflush(stdout);
62            XChangeProperty(display, wnd, rdesktop_clipboard_target_atom,
63                            XA_ATOM, 32, PropModeAppend, 0, 0);
64            DEBUG_CLIPBOARD(("Waiting for PropertyChange on wnd\n"));
65            fflush(stdout);
66            XWindowEvent(display, wnd,
67                         PropertyChangeMask, &xev);
68            DEBUG_CLIPBOARD(("Setting selection_timestamp\n"));
69            fflush(stdout);
70            selection_timestamp = xev.xproperty.time;
71    }      
72    */      
73    
74  static void  static void
75  cliprdr_send_format_announce(void)  cliprdr_send_format_announce(void)
76  {  {
77            DEBUG_CLIPBOARD(("Sending format announce\n"));
78    
79          STREAM s;          STREAM s;
80          int number_of_formats = 1;          int number_of_formats = 1;
81          s = sec_init(encryption ? SEC_ENCRYPT : 0, number_of_formats*36+12+4+4);          s = sec_init(encryption ? SEC_ENCRYPT : 0, number_of_formats*36+12+4+4);
# Line 74  cliprdr_send_format_announce(void) Line 96  cliprdr_send_format_announce(void)
96          out_uint32_le(s, 0);          out_uint32_le(s, 0);
97    
98          s_mark_end(s);          s_mark_end(s);
99          sec_send_to_channel(s, encryption ? SEC_ENCRYPT : 0, 1005); // FIXME: Don't hardcode channel!          sec_send_to_channel(s, encryption ? SEC_ENCRYPT : 0,
100                                clipboard_channelno);
101  }  }
102    
103    
# Line 93  cliprdr_send_empty_datapacket(void) Line 116  cliprdr_send_empty_datapacket(void)
116          out_uint32_le(out, 0);          out_uint32_le(out, 0);
117          s_mark_end(out);          s_mark_end(out);
118                    
119          sec_send_to_channel(out, encryption ? SEC_ENCRYPT : 0, 1005); // FIXME: Don't hardcode channel!            sec_send_to_channel(out, encryption ? SEC_ENCRYPT : 0,
120                                clipboard_channelno);
121  }  }
122    
123    
# Line 177  cliprdr_handle_SelectionNotify(XSelectio Line 201  cliprdr_handle_SelectionNotify(XSelectio
201                  /* We need to handle INCR as well */                  /* We need to handle INCR as well */
202    
203                  out =  sec_init(encryption ? SEC_ENCRYPT : 0,                  out =  sec_init(encryption ? SEC_ENCRYPT : 0,
204                                  20+nitems);                                  20+nitems+1);
205                  out_uint32_le(out, 12+nitems);                  out_uint32_le(out, 12+nitems+1);
206                  out_uint32_le(out, 0x13);                  out_uint32_le(out, 0x13);
207                  out_uint16_le(out, 5);                  out_uint16_le(out, 5);
208                  out_uint16_le(out, 1);                  out_uint16_le(out, 1);
209                  out_uint32_le(out, nitems);                  out_uint32_le(out, nitems+1);
210                  out_uint8p(out, data, nitems);                  out_uint8p(out, data, nitems+1);
211                  /* Insert null string here? */                  /* Insert null string here? */
212                  out_uint32_le(out, 0);                  out_uint32_le(out, 0);
213                  s_mark_end(out);                  s_mark_end(out);
214                    
215                  sec_send_to_channel(out, encryption ? SEC_ENCRYPT : 0, 1005); // FIXME: Don't hardcode channel!                    sec_send_to_channel(out, encryption ? SEC_ENCRYPT : 0,
216                                        clipboard_channelno);
217    
218                    cliprdr_send_format_announce();
219                                    
220          }          }
221                    
# Line 202  cliprdr_handle_SelectionClear(void) Line 229  cliprdr_handle_SelectionClear(void)
229          cliprdr_send_format_announce();          cliprdr_send_format_announce();
230  }  }
231    
 void print_X_error(int res)  
 {  
         switch(res) {  
         case Success:  
                 DEBUG_CLIPBOARD(("Success\n"));  
                 break;  
   
         case BadAtom:  
                 DEBUG_CLIPBOARD(("BadAtom\n"));  
                 break;  
   
         case BadRequest:  
                 DEBUG_CLIPBOARD(("BadRequest\n"));  
                 break;  
   
         case BadAlloc:  
                 DEBUG_CLIPBOARD(("BadAlloc\n"));  
                 break;  
   
         case BadMatch:  
                 DEBUG_CLIPBOARD(("BadMatch\n"));  
                 break;  
   
         case BadValue:  
                 DEBUG_CLIPBOARD(("BadValue\n"));  
                 break;  
   
         case BadWindow:  
                 DEBUG_CLIPBOARD(("BadWindow\n"));  
                 break;  
   
         default:  
                 DEBUG_CLIPBOARD(("Unknown X error code %d\n", res));  
         }  
 }  
232    
233  static void  static void
234  cliprdr_request_clipboard_data(uint32 formatcode)  cliprdr_request_clipboard_data(uint32 formatcode)
# Line 253  cliprdr_request_clipboard_data(uint32 fo Line 245  cliprdr_request_clipboard_data(uint32 fo
245    
246          s_mark_end(s);          s_mark_end(s);
247    
248          sec_send_to_channel(s, encryption ? SEC_ENCRYPT : 0, 1005); // FIXME: Don't hardcode channel!          sec_send_to_channel(s, encryption ? SEC_ENCRYPT : 0,
249                                clipboard_channelno);
250  }  }
251    
252    
# Line 305  cliprdr_handle_SelectionRequest(XSelecti Line 298  cliprdr_handle_SelectionRequest(XSelecti
298                                        PropModeAppend,                                        PropModeAppend,
299                                        (unsigned char *)targets,                                        (unsigned char *)targets,
300                                        3);                                        3);
                 DEBUG_CLIPBOARD(("res after XChangeProperty is "));  
                 print_X_error(res);      
301    
302                  res = XSendEvent(display,                  res = XSendEvent(display,
303                                   xevent->requestor,                                   xevent->requestor,
# Line 317  cliprdr_handle_SelectionRequest(XSelecti Line 308  cliprdr_handle_SelectionRequest(XSelecti
308          } else if (timestamp_atom == xevent->target)          } else if (timestamp_atom == xevent->target)
309          {          {
310                  DEBUG_CLIPBOARD(("TIMESTAMP requested... sending 0x%x\n",                  DEBUG_CLIPBOARD(("TIMESTAMP requested... sending 0x%x\n",
311                                   (unsigned)last_keyrelease));                                   (unsigned)last_gesturetime));
312                  res = XChangeProperty(display,                  res = XChangeProperty(display,
313                                        xevent->requestor,                                        xevent->requestor,
314                                        xevent->property,                                        xevent->property,
315                                        XA_INTEGER,                                        XA_INTEGER,
316                                        32,                                        32,
317                                        PropModeAppend,                                        PropModeAppend,
318                                        (unsigned char *)&last_keyrelease,                                        (unsigned char *)&last_gesturetime,
319                                        1);                                        1);
320                  res = XSendEvent(display,                  res = XSendEvent(display,
321                                   xevent->requestor,                                   xevent->requestor,
# Line 355  cliprdr_ack_format_list(void) Line 346  cliprdr_ack_format_list(void)
346    
347          s_mark_end(s);          s_mark_end(s);
348    
349          sec_send_to_channel(s, encryption ? SEC_ENCRYPT : 0, 1005); // FIXME: Don't hardcode channel!          sec_send_to_channel(s, encryption ? SEC_ENCRYPT : 0,
350                                clipboard_channelno);
351  }  }
352    
353                                    
# Line 407  cliprdr_register_server_formats(STREAM s Line 399  cliprdr_register_server_formats(STREAM s
399  static void  static void
400  cliprdr_select_X_clipboards(void)  cliprdr_select_X_clipboards(void)
401  {  {
402          XSetSelectionOwner(display, primary_atom, wnd, last_keyrelease);          XSetSelectionOwner(display, primary_atom, wnd, last_gesturetime);
403          if (wnd != XGetSelectionOwner(display, primary_atom))          if (wnd != XGetSelectionOwner(display, primary_atom))
404          {          {
405                  warning("Failed to aquire ownership of PRIMARY clipboard\n");                  warning("Failed to aquire ownership of PRIMARY clipboard\n");
406          }          }
407          XSetSelectionOwner(display, clipboard_atom, wnd, CurrentTime);          XSetSelectionOwner(display, clipboard_atom, wnd, last_gesturetime);
408          if (wnd != XGetSelectionOwner(display, clipboard_atom))          if (wnd != XGetSelectionOwner(display, clipboard_atom))
409          {          {
410                  warning("Failed to aquire ownership of CLIPBOARD clipboard\n");                  warning("Failed to aquire ownership of CLIPBOARD clipboard\n");
# Line 439  void cliprdr_handle_server_data(uint32 l Line 431  void cliprdr_handle_server_data(uint32 l
431  {  {
432          uint32 remaining_length;          uint32 remaining_length;
433          char *data;          char *data;
         int res;  
434          in_uint32_le(s, remaining_length);          in_uint32_le(s, remaining_length);
435          data = s->p;          data = s->p;
436          res = XChangeProperty(display,          XChangeProperty(display,
437                                selection_event.requestor,                          selection_event.requestor,
438                                selection_event.property,                          selection_event.property,
439                                XInternAtom(display, "STRING", False),                          XInternAtom(display, "STRING", False),
440                                8,                          8,
441                                PropModeAppend,                          PropModeAppend,
442                                data,                          data,
443                                remaining_length);                          remaining_length);
444    
445          DEBUG_CLIPBOARD(("res after XChangeProperty is "));          XSendEvent(display,
446          print_X_error(res);                         selection_event.requestor,
447                               False,
448          res = XSendEvent(display,                     NoEventMask,
449                           selection_event.requestor,                     (XEvent *)&selection_event);
                          False,  
                          NoEventMask,  
                          (XEvent *)&selection_event);  
450                    
         DEBUG_CLIPBOARD(("res after XSendEvent is "));  
         print_X_error(res);  
451    
452  }  }
453    
# Line 506  void cliprdr_handle_server_data_request( Line 492  void cliprdr_handle_server_data_request(
492  }  }
493                    
494    
495  void cliprdr_callback(STREAM s)  void cliprdr_callback(STREAM s, uint16 channelno)
496  {  {
497            static int failed_clipboard_acks = 0;
498            struct timeval timeval;
499          uint32 length, flags;          uint32 length, flags;
500          uint16 ptype0, ptype1;          uint16 ptype0, ptype1;
501          DEBUG_CLIPBOARD(("cliprdr_callback called, clipboard data:\n"));          clipboard_channelno = channelno;
502            DEBUG_CLIPBOARD(("cliprdr_callback called with channelno %d, clipboard data:\n", channelno));
503  #ifdef WITH_DEBUG_CLIPBOARD  #ifdef WITH_DEBUG_CLIPBOARD
504          hexdump(s->p, s->end - s->p);          hexdump(s->p, s->end - s->p);
505  #endif  #endif
# Line 533  void cliprdr_callback(STREAM s) Line 522  void cliprdr_callback(STREAM s)
522                          // There is a strange pad in this packet that we might need some time,                          // There is a strange pad in this packet that we might need some time,
523                          // but probably not.                          // but probably not.
524                          DEBUG_CLIPBOARD(("Received format announce ACK\n"));                          DEBUG_CLIPBOARD(("Received format announce ACK\n"));
525                            failed_clipboard_acks = 0;
526                          return;                          return;
527    
528                    } else if (3 == ptype0 && 2 == ptype1)
529                    {
530                            DEBUG_CLIPBOARD(("Received failed clipboard format announce ACK, retrying\n"));
531    
532                            /* This is a fairly portable way to sleep 1/10 of
533                               a second.. */
534                            timeval.tv_sec = 0;
535                            timeval.tv_usec = 100;
536                            select(0, NULL, NULL, NULL, &timeval);
537                            if (failed_clipboard_acks < 3)
538                            {
539                                    
540                                    cliprdr_send_format_announce();
541                                    /* Make sure we don't get stuck in this loop */
542                                    failed_clipboard_acks++;
543                            }
544                            else
545                            {
546                                    warning("Reached maximum number of clipboard format announce attempts. Pasting in Windows probably won't work well now.\n");
547                            }
548                  } else if (2 == ptype0 && 0 == ptype1)                  } else if (2 == ptype0 && 0 == ptype1)
549                  {                  {
550                          cliprdr_register_server_formats(s);                          cliprdr_register_server_formats(s);

Legend:
Removed from v.387  
changed lines
  Added in v.390

  ViewVC Help
Powered by ViewVC 1.1.26