[linux/vd-agent,09/11] clipboard: filter out only our own events

Submitted by marcandre.lureau@redhat.com on March 22, 2019, 3:12 p.m.

Details

Message ID 20190322151246.17766-10-marcandre.lureau@redhat.com
State New
Headers show
Series "Clipboard improvements" ( rev: 2 ) in Spice

Not browsing as part of any series.

Commit Message

marcandre.lureau@redhat.com March 22, 2019, 3:12 p.m.
From: Marc-André Lureau <marcandre.lureau@redhat.com>

Do not rely on internal state when receiving clipboard events, as this
may race with external events. Use gtk_clipboard_set_with_owner()

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 src/vdagent/clipboard.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

Patch hide | download patch | download mbox

diff --git a/src/vdagent/clipboard.c b/src/vdagent/clipboard.c
index cf6e344..9fb87e3 100644
--- a/src/vdagent/clipboard.c
+++ b/src/vdagent/clipboard.c
@@ -238,8 +238,9 @@  static void clipboard_owner_change_cb(GtkClipboard        *clipboard,
     Selection *sel = &c->selections[sel_id];
 
     /* if the event was caused by gtk_clipboard_set_with_data(), ignore it  */
-    if (sel->owner == OWNER_CLIENT)
+    if (gtk_clipboard_get_owner(clipboard) == G_OBJECT(c)) {
         return;
+    }
 
     if (sel->owner == OWNER_GUEST) {
         clipboard_new_owner(c, sel_id, OWNER_NONE);
@@ -357,9 +358,10 @@  void vdagent_clipboard_grab(VDAgentClipboards *c, guint sel_id,
         g_clear_pointer(&sel->last_targets_req, request_ref_cancel);
     }
 
-    if (gtk_clipboard_set_with_data(sel->clipboard,
-                                    targets, n_targets,
-                                    clipboard_get_cb, clipboard_clear_cb, c))
+    if (gtk_clipboard_set_with_owner(sel->clipboard,
+                                     targets, n_targets,
+                                     clipboard_get_cb, clipboard_clear_cb,
+                                     G_OBJECT(c)))
         clipboard_new_owner(c, sel_id, OWNER_CLIENT);
     else {
         syslog(LOG_ERR, "%s: sel_id=%u: clipboard grab failed", __func__, sel_id);