[Spice-devel] [PATCH spice 12/17] spicec-x11: Force processing of ownerchange event when releasing the cb

Hans de Goede hdegoede at redhat.com
Mon Oct 4 03:35:03 PDT 2010


Make sure we process the XFixesSetSelectionOwnerNotify event caused by
us setting the clipboard owner to none, directly after setting the owner
to none. Otherwise we may end up changing the clipboard owner to none, after
it has already been re-owned because the XFixesSetSelectionOwnerNotify event
to owner none is event is still pending when we set the new owner, and
then changes the owner back to none once processed messing up our clipboard
ownership state tracking.

I saw this happening when doing copy twice in succession inside the guest.
---
 client/red_client.cpp       |    3 +--
 client/windows/platform.cpp |    1 +
 client/x11/platform.cpp     |   13 +++++++++++++
 3 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/client/red_client.cpp b/client/red_client.cpp
index a022499..8e7dfe0 100644
--- a/client/red_client.cpp
+++ b/client/red_client.cpp
@@ -1133,12 +1133,11 @@ void RedClient::dispatch_agent_message(VDAgentMessage* msg, void* data)
         break;
     case VD_AGENT_CLIPBOARD_RELEASE:
         if (Platform::get_clipboard_owner() != Platform::owner_guest) {
-            LOG_WARN("received clipboard release from guest while clipboard is not owned by guest");
+            LOG_INFO("received clipboard release from guest while clipboard is not owned by guest");
             break;
         }
 
         Platform::on_clipboard_release();
-        Platform::set_clipboard_owner(Platform::owner_none);
         break;
     default:
         DBG(0, "Unsupported message type %u size %u", msg->type, msg->size);
diff --git a/client/windows/platform.cpp b/client/windows/platform.cpp
index db47079..580a40a 100644
--- a/client/windows/platform.cpp
+++ b/client/windows/platform.cpp
@@ -1011,6 +1011,7 @@ bool Platform::on_clipboard_request(uint32_t type)
 void Platform::on_clipboard_release()
 {
     SetEvent(clipboard_event);
+    set_clipboard_owner(owner_none);
 }
 
 static bool has_console = false;
diff --git a/client/x11/platform.cpp b/client/x11/platform.cpp
index ea2558d..75b34c6 100644
--- a/client/x11/platform.cpp
+++ b/client/x11/platform.cpp
@@ -3342,5 +3342,18 @@ bool Platform::on_clipboard_request(uint32_t type)
 
 void Platform::on_clipboard_release()
 {
+    XEvent event;
+
     XSetSelectionOwner(x_display, clipboard_prop, None, CurrentTime);
+    /* Make sure we process the XFixesSetSelectionOwnerNotify event caused
+       by this, so we don't end up changing the clipboard owner to none, after
+       it has already been re-owned because this event is still pending. */
+    XSync(x_display, False);
+    while (XCheckTypedEvent(x_display,
+                            XFixesSelectionNotify + xfixes_event_base,
+                            &event))
+        root_win_proc(event);
+
+    /* Note no need to do a set_clipboard_owner(owner_none) here, as that is
+       already done by processing the XFixesSetSelectionOwnerNotify event. */
 }
-- 
1.7.2.2



More information about the Spice-devel mailing list