[Spice-devel] [spice-gtk v1 3/7] gtk-session: use clear variable for array's size
Victor Toso
victortoso at redhat.com
Wed Feb 22 13:11:08 UTC 2017
From: Victor Toso <me at victortoso.com>
There is no need to use an index variable to keep track of the number
of VD_AGENT_CLIPBOARD types we are storing.
Signed-off-by: Victor Toso <victortoso at redhat.com>
---
src/spice-gtk-session.c | 17 +++++++++++------
1 file changed, 11 insertions(+), 6 deletions(-)
diff --git a/src/spice-gtk-session.c b/src/spice-gtk-session.c
index bc47f6b..cda2c3a 100644
--- a/src/spice-gtk-session.c
+++ b/src/spice-gtk-session.c
@@ -615,6 +615,7 @@ static void clipboard_get_targets(GtkClipboard *clipboard,
char *name;
int a, m, t;
int selection;
+ gint num_types;
if (s->main == NULL)
return;
@@ -631,6 +632,8 @@ 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++) {
@@ -646,6 +649,7 @@ static void clipboard_get_targets(GtkClipboard *clipboard,
if (types[t] == 0) {
/* add type to empty slot */
types[t] = atom2agent[m].vdagent;
+ num_types++;
break;
}
}
@@ -653,16 +657,17 @@ static void clipboard_get_targets(GtkClipboard *clipboard,
}
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;
}
--
2.9.3
More information about the Spice-devel
mailing list