CVS: rdesktop xclip.c,1.29,1.30

Pierre Ossman <[email protected]> Mon, 27 Mar 2006 00:49:40 -0800
Newsgroups gmane.network.rdesktop.cvs
Message-ID <[email protected]>
Update of /cvsroot/rdesktop/rdesktop
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14988

Modified Files:
	xclip.c 
Log Message:
Examine timestamps of PRIMARY and CLIPBOARD to determine which is more
recent and should therefore be used.


Index: xclip.c
===================================================================
RCS file: /cvsroot/rdesktop/rdesktop/xclip.c,v
retrieving revision 1.29
retrieving revision 1.30
diff -C2 -d -r1.29 -r1.30
*** xclip.c	27 Mar 2006 08:41:16 -0000	1.29
--- xclip.c	27 Mar 2006 08:49:38 -0000	1.30
***************
*** 70,73 ****
--- 70,79 ----
       the _RDESKTOP_CLIPBOARD_FORMATS target. */
  static Atom rdesktop_clipboard_target_atom;
+ /* Atoms _RDESKTOP_PRIMARY_TIMESTAMP_TARGET and _RDESKTOP_CLIPBOARD_TIMESTAMP_TARGET
+    are used to store the timestamps for when a window got ownership of the selections.
+    We use these to determine which is more recent and should be used. */
+ static Atom rdesktop_primary_timestamp_target_atom, rdesktop_clipboard_timestamp_target_atom;
+ /* Storage for timestamps since we get them in two separate notifications. */
+ static Time primary_timestamp, clipboard_timestamp;
  /* Atom _RDESKTOP_CLIPBOARD_FORMATS which has multiple uses:
     - The clipboard target (X jargon for "clipboard format") for rdesktop-to-rdesktop interchange
***************
*** 373,376 ****
--- 379,390 ----
  }
  
+ static void
+ xclip_clear_target_props()
+ {
+ 	XDeleteProperty(g_display, g_wnd, rdesktop_clipboard_target_atom);
+ 	XDeleteProperty(g_display, g_wnd, rdesktop_primary_timestamp_target_atom);
+ 	XDeleteProperty(g_display, g_wnd, rdesktop_clipboard_timestamp_target_atom);
+ }
+ 
  /* This function is called for SelectionNotify events.
     The SelectionNotify event is sent from the clipboard owner to the requestor
***************
*** 396,401 ****
  			 XGetAtomName(g_display, event->property)));
  
! 	if (event->property == None)
! 		goto fail;
  
  	res = XGetWindowProperty(g_display, g_wnd, rdesktop_clipboard_target_atom,
--- 410,478 ----
  			 XGetAtomName(g_display, event->property)));
  
! 	if (event->target == timestamp_atom)
! 	{
! 		if (event->selection == primary_atom)
! 		{
! 			res = XGetWindowProperty(g_display, g_wnd,
! 						 rdesktop_primary_timestamp_target_atom, 0,
! 						 XMaxRequestSize(g_display), False, XA_INTEGER,
! 						 &type, &format, &nitems, &bytes_left, &data);
! 		}
! 		else
! 		{
! 			res = XGetWindowProperty(g_display, g_wnd,
! 						 rdesktop_clipboard_timestamp_target_atom, 0,
! 						 XMaxRequestSize(g_display), False, XA_INTEGER,
! 						 &type, &format, &nitems, &bytes_left, &data);
! 		}
! 
! 
! 		if ((res != Success) || (nitems != 1))
! 		{
! 			DEBUG_CLIPBOARD(("XGetWindowProperty failed!\n"));
! 			goto fail;
! 		}
! 
! 		if (event->selection == primary_atom)
! 		{
! 			primary_timestamp = *(Time *) data;
! 			if (primary_timestamp == 0)
! 				primary_timestamp++;
! 			XDeleteProperty(g_display, g_wnd, rdesktop_primary_timestamp_target_atom);
! 			DEBUG_CLIPBOARD(("Got PRIMARY timestamp: %u\n",
! 					 (unsigned) primary_timestamp));
! 		}
! 		else
! 		{
! 			clipboard_timestamp = *(Time *) data;
! 			if (clipboard_timestamp == 0)
! 				clipboard_timestamp++;
! 			XDeleteProperty(g_display, g_wnd, rdesktop_clipboard_timestamp_target_atom);
! 			DEBUG_CLIPBOARD(("Got CLIPBOARD timestamp: %u\n",
! 					 (unsigned) clipboard_timestamp));
! 		}
! 
! 		XFree(data);
! 
! 		if (primary_timestamp && clipboard_timestamp)
! 		{
! 			if (primary_timestamp > clipboard_timestamp)
! 			{
! 				DEBUG_CLIPBOARD(("PRIMARY is most recent selection.\n"));
! 				XConvertSelection(g_display, primary_atom, targets_atom,
! 						  rdesktop_clipboard_target_atom, g_wnd,
! 						  event->time);
! 			}
! 			else
! 			{
! 				DEBUG_CLIPBOARD(("CLIPBOARD is most recent selection.\n"));
! 				XConvertSelection(g_display, clipboard_atom, targets_atom,
! 						  rdesktop_clipboard_target_atom, g_wnd,
! 						  event->time);
! 			}
! 		}
! 
! 		return;
! 	}
  
  	res = XGetWindowProperty(g_display, g_wnd, rdesktop_clipboard_target_atom,
***************
*** 403,406 ****
--- 480,485 ----
  				 &type, &format, &nitems, &bytes_left, &data);
  
+ 	xclip_clear_target_props();
+ 
  	if (res != Success)
  	{
***************
*** 418,422 ****
  			XSelectInput(g_display, g_wnd, (wa.your_event_mask | PropertyChangeMask));
  		}
- 		XDeleteProperty(g_display, g_wnd, rdesktop_clipboard_target_atom);
  		XFree(data);
  		g_incr_target = event->target;
--- 497,500 ----
***************
*** 425,430 ****
  	}
  
- 	XDeleteProperty(g_display, g_wnd, rdesktop_clipboard_target_atom);
- 
  	/* Negotiate target format */
  	if (event->target == targets_atom)
--- 503,506 ----
***************
*** 503,507 ****
  
        fail:
! 	XDeleteProperty(g_display, g_wnd, rdesktop_clipboard_target_atom);
  	if (data)
  		XFree(data);
--- 579,583 ----
  
        fail:
! 	xclip_clear_target_props();
  	if (data)
  		XFree(data);
***************
*** 810,818 ****
  ui_clip_request_data(uint32 format)
  {
! 	Window selectionowner;
  
  	DEBUG_CLIPBOARD(("Request from server for format %d\n", format));
  	rdp_clipboard_request_format = format;
  
  	if (rdesktop_is_selection_owner)
  	{
--- 886,896 ----
  ui_clip_request_data(uint32 format)
  {
! 	Window primary_owner, clipboard_owner;
  
  	DEBUG_CLIPBOARD(("Request from server for format %d\n", format));
  	rdp_clipboard_request_format = format;
  
+ 	xclip_clear_target_props();
+ 
  	if (rdesktop_is_selection_owner)
  	{
***************
*** 825,830 ****
  	}
  
! 	selectionowner = XGetSelectionOwner(g_display, primary_atom);
! 	if (selectionowner != None)
  	{
  		XConvertSelection(g_display, primary_atom, targets_atom,
--- 903,923 ----
  	}
  
! 	primary_owner = XGetSelectionOwner(g_display, primary_atom);
! 	clipboard_owner = XGetSelectionOwner(g_display, clipboard_atom);
! 
! 	/* Both available */
! 	if ((primary_owner != None) && (clipboard_owner != None))
! 	{
! 		primary_timestamp = 0;
! 		clipboard_timestamp = 0;
! 		XConvertSelection(g_display, primary_atom, timestamp_atom,
! 				  rdesktop_primary_timestamp_target_atom, g_wnd, CurrentTime);
! 		XConvertSelection(g_display, clipboard_atom, timestamp_atom,
! 				  rdesktop_clipboard_timestamp_target_atom, g_wnd, CurrentTime);
! 		return;
! 	}
! 
! 	/* Just PRIMARY */
! 	if (primary_owner != None)
  	{
  		XConvertSelection(g_display, primary_atom, targets_atom,
***************
*** 833,839 ****
  	}
  
! 	/* No PRIMARY, try CLIPBOARD */
! 	selectionowner = XGetSelectionOwner(g_display, clipboard_atom);
! 	if (selectionowner != None)
  	{
  		XConvertSelection(g_display, clipboard_atom, targets_atom,
--- 926,931 ----
  	}
  
! 	/* Just CLIPBOARD */
! 	if (clipboard_owner != None)
  	{
  		XConvertSelection(g_display, clipboard_atom, targets_atom,
***************
*** 865,868 ****
--- 957,964 ----
  	rdesktop_clipboard_target_atom =
  		XInternAtom(g_display, "_RDESKTOP_CLIPBOARD_TARGET", False);
+ 	rdesktop_primary_timestamp_target_atom =
+ 		XInternAtom(g_display, "_RDESKTOP_PRIMARY_TIMESTAMP_TARGET", False);
+ 	rdesktop_clipboard_timestamp_target_atom =
+ 		XInternAtom(g_display, "_RDESKTOP_CLIPBOARD_TIMESTAMP_TARGET", False);
  	incr_atom = XInternAtom(g_display, "INCR", False);
  	format_string_atom = XInternAtom(g_display, "STRING", False);



-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642