[Spice-commits] 4 commits - src/spice-gtk-session.c

Victor Toso de Carvalho victortoso at kemper.freedesktop.org
Thu May 25 05:47:33 UTC 2017


 src/spice-gtk-session.c |   66 ++++++++++++++++++++++++++----------------------
 1 file changed, 36 insertions(+), 30 deletions(-)

New commits:
commit ce1da251a70ed3953fe4bc2c0492b0d38114a6a6
Author: Victor Toso <me at victortoso.com>
Date:   Fri Feb 24 14:44:50 2017 +0100

    gtk-session: move variables to internal scope
    
    Signed-off-by: Victor Toso <victortoso at redhat.com>
    Acked-by: Frediano Ziglio <fziglio at redhat.com>

diff --git a/src/spice-gtk-session.c b/src/spice-gtk-session.c
index d233f83..33db3c8 100644
--- a/src/spice-gtk-session.c
+++ b/src/spice-gtk-session.c
@@ -619,8 +619,7 @@ static void clipboard_get_targets(GtkClipboard *clipboard,
     SpiceGtkSessionPrivate *s = self->priv;
     guint32 types[SPICE_N_ELEMENTS(atom2agent)] = { 0 };
     gint num_types;
-    char *name;
-    int a, m, t;
+    int a;
     int selection;
 
     if (s->main == NULL)
@@ -637,11 +636,14 @@ static void clipboard_get_targets(GtkClipboard *clipboard,
     /* Set all Atoms that matches our current protocol implementation */
     num_types = 0;
     for (a = 0; a < n_atoms; a++) {
-        name = gdk_atom_name(atoms[a]);
+        guint m;
+        gchar *name = gdk_atom_name(atoms[a]);
 
         SPICE_DEBUG(" \"%s\"", name);
 
         for (m = 0; m < SPICE_N_ELEMENTS(atom2agent); m++) {
+            guint t;
+
             if (strcasecmp(name, atom2agent[m].xatom) != 0) {
                 continue;
             }
commit e5f0e9d2661b3087e8215849ea817242a01b30dc
Author: Victor Toso <me at victortoso.com>
Date:   Fri Feb 24 14:44:02 2017 +0100

    gtk-session: move atom's debug
    
    We already iterate in all n_atoms and get its name with
    gdk_atom_name(), let's move the debug there too;
    
    While at it, move the generic SPICE_DEBUG of the function to the top.
    It should help us identify when the function was triggered but not
    used due the early returns.
    
    Signed-off-by: Victor Toso <victortoso at redhat.com>
    Acked-by: Pavel Grunt <pgrunt at redhat.com>

diff --git a/src/spice-gtk-session.c b/src/spice-gtk-session.c
index aa66811..d233f83 100644
--- a/src/spice-gtk-session.c
+++ b/src/spice-gtk-session.c
@@ -604,6 +604,8 @@ static void clipboard_get_targets(GtkClipboard *clipboard,
 {
     SpiceGtkSession *self = free_weak_ref(user_data);
 
+    SPICE_DEBUG("%s:", __FUNCTION__);
+
     if (self == NULL)
         return;
 
@@ -627,15 +629,6 @@ static void clipboard_get_targets(GtkClipboard *clipboard,
     selection = get_selection_from_clipboard(s, clipboard);
     g_return_if_fail(selection != -1);
 
-    SPICE_DEBUG("%s:", __FUNCTION__);
-    if (spice_util_get_debug()) {
-        for (a = 0; a < n_atoms; a++) {
-            name = gdk_atom_name(atoms[a]);
-            SPICE_DEBUG(" \"%s\"", name);
-            g_free(name);
-        }
-    }
-
     if (s->clip_grabbed[selection]) {
         SPICE_DEBUG("Clipboard is already grabbed, ignoring %d atoms", n_atoms);
         return;
@@ -645,6 +638,9 @@ static void clipboard_get_targets(GtkClipboard *clipboard,
     num_types = 0;
     for (a = 0; a < n_atoms; a++) {
         name = gdk_atom_name(atoms[a]);
+
+        SPICE_DEBUG(" \"%s\"", name);
+
         for (m = 0; m < SPICE_N_ELEMENTS(atom2agent); m++) {
             if (strcasecmp(name, atom2agent[m].xatom) != 0) {
                 continue;
commit a02dd91fb4e8ad2577ad8eba0ab7a4c24ac9fa16
Author: Victor Toso <me at victortoso.com>
Date:   Wed Feb 22 14:11:09 2017 +0100

    gtk-session: do an early check of clipboard grab
    
    As we will not be doing anything in case clipboard is already grabbed
    
    Signed-off-by: Victor Toso <victortoso at redhat.com>
    Acked-by: Frediano Ziglio <fziglio at redhat.com>

diff --git a/src/spice-gtk-session.c b/src/spice-gtk-session.c
index 50cc00d..aa66811 100644
--- a/src/spice-gtk-session.c
+++ b/src/spice-gtk-session.c
@@ -636,6 +636,11 @@ static void clipboard_get_targets(GtkClipboard *clipboard,
         }
     }
 
+    if (s->clip_grabbed[selection]) {
+        SPICE_DEBUG("Clipboard is already grabbed, ignoring %d atoms", n_atoms);
+        return;
+    }
+
     /* Set all Atoms that matches our current protocol implementation */
     num_types = 0;
     for (a = 0; a < n_atoms; a++) {
@@ -666,14 +671,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,
commit d48ea37d610f1cac4b1448a4c1c7d1ccd2f3bab4
Author: Victor Toso <me at victortoso.com>
Date:   Wed Feb 22 14:11:08 2017 +0100

    gtk-session: use clear variable for array's size
    
    By using 'num_types' variables, we have a clear variable with a clear
    purpose: It will track the number of VD_AGENT_CLIPBOARD types we are
    storing in types[] array.
    
    This new variable helps:
    - removing one 'for' loop which was counting the number stored types;
    - doing fewer iterations in one 'for' loop
    
    A few extra comments were included to clarify what the logic should be
    doing and a extra debug was included to point out situations where the
    desktop has sent us valid clipboard data but none will be sent the
    guest.
    
    Signed-off-by: Victor Toso <victortoso at redhat.com>
    Acked-by: Frediano Ziglio <fziglio at redhat.com>

diff --git a/src/spice-gtk-session.c b/src/spice-gtk-session.c
index cfdfc4c..50cc00d 100644
--- a/src/spice-gtk-session.c
+++ b/src/spice-gtk-session.c
@@ -616,6 +616,7 @@ static void clipboard_get_targets(GtkClipboard *clipboard,
 
     SpiceGtkSessionPrivate *s = self->priv;
     guint32 types[SPICE_N_ELEMENTS(atom2agent)] = { 0 };
+    gint num_types;
     char *name;
     int a, m, t;
     int selection;
@@ -635,38 +636,41 @@ static void clipboard_get_targets(GtkClipboard *clipboard,
         }
     }
 
+    /* Set all Atoms that matches our current protocol implementation */
+    num_types = 0;
     for (a = 0; a < n_atoms; a++) {
         name = gdk_atom_name(atoms[a]);
         for (m = 0; m < SPICE_N_ELEMENTS(atom2agent); m++) {
             if (strcasecmp(name, atom2agent[m].xatom) != 0) {
                 continue;
             }
-            /* found match */
-            for (t = 0; t < SPICE_N_ELEMENTS(atom2agent); t++) {
+
+            /* check if type is already in list */
+            for (t = 0; t < num_types; t++) {
                 if (types[t] == atom2agent[m].vdagent) {
-                    /* type already in list */
-                    break;
-                }
-                if (types[t] == 0) {
-                    /* add type to empty slot */
-                    types[t] = atom2agent[m].vdagent;
                     break;
                 }
             }
-            break;
+
+            if (t == num_types) {
+                /* add type to empty slot */
+                types[t] = atom2agent[m].vdagent;
+                num_types++;
+            }
         }
         g_free(name);
     }
-    for (t = 0; t < SPICE_N_ELEMENTS(atom2agent); t++) {
-        if (types[t] == 0) {
-            break;
-        }
+
+    if (num_types == 0) {
+        SPICE_DEBUG("No GdkAtoms will be sent from %d", n_atoms);
+        return;
     }
-    if (!s->clip_grabbed[selection] && t > 0) {
+
+    if (!s->clip_grabbed[selection]) {
         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, t);
+            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;
     }


More information about the Spice-commits mailing list