<div dir="ltr">ping<br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Jul 4, 2019 at 12:29 PM Kevin Pouget <<a href="mailto:kpouget@redhat.com">kpouget@redhat.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Instead of sending only the preferred video codec (selected), spicy<br>
now sends an ordered list. When a video codec is selected in the radio<br>
box, this codec is moved to beginning of the list.<br>
<br>
Signed-off-by: Kevin Pouget <<a href="mailto:kpouget@redhat.com" target="_blank">kpouget@redhat.com</a>><br>
---<br>
 tools/spicy.c | 31 +++++++++++++++++++++++++++++--<br>
 1 file changed, 29 insertions(+), 2 deletions(-)<br>
<br>
diff --git a/tools/spicy.c b/tools/spicy.c<br>
index 8a6d077..403a66d 100644<br>
--- a/tools/spicy.c<br>
+++ b/tools/spicy.c<br>
@@ -1014,8 +1014,35 @@ static void video_codec_type_cb(GtkRadioAction *action G_GNUC_UNUSED,<br>
                                 GtkRadioAction *current,<br>
                                 gpointer user_data)<br>
 {<br>
-    spice_display_channel_change_preferred_video_codec_type(SPICE_CHANNEL(user_data),<br>
-                                                            gtk_radio_action_get_current_value(current));<br>
+    static GArray *preferred_codecs = NULL;<br>
+    gint selected_codec = gtk_radio_action_get_current_value(current);<br>
+    guint i;<br>
+    GError *err = NULL;<br>
+<br>
+    if (!preferred_codecs) {<br>
+        preferred_codecs = g_array_sized_new(FALSE, FALSE,<br>
+                                             sizeof(gint),<br>
+                                             G_N_ELEMENTS(video_codec_type_entries));<br>
+        /* initialize with the menu ordering */<br>
+        for (i = 0; i < G_N_ELEMENTS(video_codec_type_entries); i++) {<br>
+            g_array_append_val(preferred_codecs, video_codec_type_entries[i].value);<br>
+        }<br>
+    }<br>
+<br>
+    /* remove codec from array and insert at the beginning */<br>
+    for (i = 0; i < preferred_codecs->len &&<br>
+                g_array_index(preferred_codecs, gint, i) != selected_codec; i++);<br>
+<br>
+    g_assert(i < preferred_codecs->len);<br>
+    g_array_remove_index(preferred_codecs, i);<br>
+    g_array_prepend_val(preferred_codecs, selected_codec);<br>
+<br>
+    if (!spice_display_channel_change_preferred_video_codec_types(SPICE_CHANNEL(user_data),<br>
+                                                                  (gint *) preferred_codecs->data,<br>
+                                                                  preferred_codecs->len, &err)) {<br>
+        g_warning("setting preferred video codecs failed: %s", err->message);<br>
+        g_error_free(err);<br>
+    }<br>
 }<br>
<br>
 static void<br>
-- <br>
2.21.0<br>
<br>
</blockquote></div>