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

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Thu Dec 6 15:36:32 UTC 2018


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

New commits:
commit 9ebd49f7da83d6c9e31391af3c98c0f6e1f5ef75
Author: Victor Toso <me at victortoso.com>
Date:   Tue Dec 4 17:29:26 2018 +0100

    gtk-session: better variable name
    
    Not saying it is perfect name but 'i' as index does not state much
    after the for loop in g_memdup() and gtk_clipboard_set_with_owner().
    
    Using number of elements as indexes is far from unusual so let's
    rename it and reduce by one the single letter vars.
    
    Also note that the change in indentation on arguments of
    gtk_clipboard_set_with_owner() while renaming 'i' -> 'num_targets'.
    Follow up patch will rename some callbacks, so keeping one argument
    per line would reduce slightly the change set of patch set.
    
    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 fa34b7b..1ccae07 100644
--- a/src/spice-gtk-session.c
+++ b/src/spice-gtk-session.c
@@ -786,22 +786,22 @@ static gboolean clipboard_grab(SpiceMainChannel *main, guint selection,
     gboolean target_selected[SPICE_N_ELEMENTS(atom2agent)] = { FALSE, };
     gboolean found;
     GtkClipboard* cb;
-    int m, n, i;
+    int m, n;
+    int num_targets = 0;
 
     cb = get_clipboard_from_selection(s, selection);
     g_return_val_if_fail(cb != NULL, FALSE);
 
-    i = 0;
     for (n = 0; n < ntypes; ++n) {
         found = FALSE;
         for (m = 0; m < SPICE_N_ELEMENTS(atom2agent); m++) {
             if (atom2agent[m].vdagent == types[n] && !target_selected[m]) {
                 found = TRUE;
-                g_return_val_if_fail(i < SPICE_N_ELEMENTS(atom2agent), FALSE);
-                targets[i].target = (gchar*)atom2agent[m].xatom;
-                targets[i].info = m;
+                g_return_val_if_fail(num_targets < SPICE_N_ELEMENTS(atom2agent), FALSE);
+                targets[num_targets].target = (gchar*)atom2agent[m].xatom;
+                targets[num_targets].info = m;
                 target_selected[m] = TRUE;
-                i += 1;
+                num_targets++;
             }
         }
         if (!found) {
@@ -811,8 +811,8 @@ static gboolean clipboard_grab(SpiceMainChannel *main, guint selection,
     }
 
     g_free(s->clip_targets[selection]);
-    s->nclip_targets[selection] = i;
-    s->clip_targets[selection] = g_memdup(targets, sizeof(GtkTargetEntry) * i);
+    s->nclip_targets[selection] = num_targets;
+    s->clip_targets[selection] = g_memdup(targets, sizeof(GtkTargetEntry) * num_targets);
     /* Receiving a grab implies we've released our own grab */
     s->clip_grabbed[selection] = FALSE;
 
@@ -822,8 +822,12 @@ static gboolean clipboard_grab(SpiceMainChannel *main, guint selection,
         return TRUE;
     }
 
-    if (!gtk_clipboard_set_with_owner(cb, targets, i,
-                                      clipboard_get, clipboard_clear, G_OBJECT(self))) {
+    if (!gtk_clipboard_set_with_owner(cb,
+                                      targets,
+                                      num_targets,
+                                      clipboard_get,
+                                      clipboard_clear,
+                                      G_OBJECT(self))) {
         g_warning("clipboard grab failed");
         return FALSE;
     }
commit 5de7db9bb1cc3ba3b06e17993aca6d7495b4061f
Author: Victor Toso <me at victortoso.com>
Date:   Tue Dec 4 17:25:01 2018 +0100

    gtk-session: remove single goto usage
    
    Returning TRUE here should be fine. Not much error handling around the
    label.
    
    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 20a4060..fa34b7b 100644
--- a/src/spice-gtk-session.c
+++ b/src/spice-gtk-session.c
@@ -818,8 +818,9 @@ static gboolean clipboard_grab(SpiceMainChannel *main, guint selection,
 
     if (read_only(self) ||
         !s->auto_clipboard_enable ||
-        s->nclip_targets[selection] == 0)
-        goto skip_grab_clipboard;
+        s->nclip_targets[selection] == 0) {
+        return TRUE;
+    }
 
     if (!gtk_clipboard_set_with_owner(cb, targets, i,
                                       clipboard_get, clipboard_clear, G_OBJECT(self))) {
@@ -829,7 +830,6 @@ static gboolean clipboard_grab(SpiceMainChannel *main, guint selection,
     s->clipboard_by_guest[selection] = TRUE;
     s->clip_hasdata[selection] = FALSE;
 
-skip_grab_clipboard:
     return TRUE;
 }
 


More information about the Spice-commits mailing list