[Spice-devel,spice-gtk,v1,4/7] gtk-session: do an early check of clipboard grab

Submitted by Victor Toso on Feb. 22, 2017, 1:11 p.m.

Details

Message ID 20170222131112.14079-5-victortoso@redhat.com
State New
Headers show
Series "clipboard_get_targets() on spice-gtk-session.c" ( rev: 4 3 2 1 ) in Spice

Not browsing as part of any series.

Commit Message

Victor Toso Feb. 22, 2017, 1:11 p.m.
From: Victor Toso <me@victortoso.com>

As we will not be doing anything in case clipboard is already grabbed

Signed-off-by: Victor Toso <victortoso@redhat.com>
---
 src/spice-gtk-session.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

Patch hide | download patch | download mbox

diff --git a/src/spice-gtk-session.c b/src/spice-gtk-session.c
index cda2c3a..651e438 100644
--- a/src/spice-gtk-session.c
+++ b/src/spice-gtk-session.c
@@ -623,6 +623,11 @@  static void clipboard_get_targets(GtkClipboard *clipboard,
     selection = get_selection_from_clipboard(s, clipboard);
     g_return_if_fail(selection != -1);
 
+    if (s->clip_grabbed[selection]) {
+        SPICE_DEBUG("Clipboard is already grabbed, ignoring %d atoms", n_atoms);
+        return;
+    }
+
     SPICE_DEBUG("%s:", __FUNCTION__);
     if (spice_util_get_debug()) {
         for (a = 0; a < n_atoms; a++) {
@@ -663,14 +668,13 @@  static void clipboard_get_targets(GtkClipboard *clipboard,
         return;
     }
 
-    if (!s->clip_grabbed[selection]) {
-        s->clip_grabbed[selection] = TRUE;
+    s->clip_grabbed[selection] = TRUE;
 
-        if (spice_main_agent_test_capability(s->main, VD_AGENT_CAP_CLIPBOARD_BY_DEMAND))
-            spice_main_clipboard_selection_grab(s->main, selection, types, num_types);
-        /* Sending a grab causes the agent to do an implicit release */
-        s->nclip_targets[selection] = 0;
-    }
+    if (spice_main_agent_test_capability(s->main, VD_AGENT_CAP_CLIPBOARD_BY_DEMAND))
+        spice_main_clipboard_selection_grab(s->main, selection, types, num_types);
+
+    /* Sending a grab causes the agent to do an implicit release */
+    s->nclip_targets[selection] = 0;
 }
 
 static void clipboard_owner_change(GtkClipboard        *clipboard,