[virt-tools-list] [PATCH virt-viewer v2 3/3] Monitor config at sometimes leaves additional monitors enabled

Jonathon Jongsma jjongsma at redhat.com
Thu Mar 19 16:16:12 UTC 2015


When using the configuration file to specify which remote monitors should be
enabled when using the --full-screen option, it sometimes left additional
displays enabled, or didn't place the displays on the right monitor, or didn't
fullscreen them.

This was especially true when not enabling the first display on the remote
host. For example:

  monitor-mapping=2:2;3:3

(note that configuration file uses 1-based indexes, rather than 0-based
indexes, so the numbers used below will be 1 less than those above)

Previously, when performing fullscreen auto-conf, we were configuring displays
starting at #0 and ending at ndisplays. So for the previous configuration, we
looped from i = 0 to i < 2 (i.e. display #0 and #1) even though we should have
configured display #1 and #2. After this fix, we configure the exact displays
that were specified in the monitor-mapping configuration.

Resolves: rhbz#1200750
---
 src/virt-viewer-app.c           | 41 ++++++++++++++++++++++++++++++++---------
 src/virt-viewer-app.h           |  2 +-
 src/virt-viewer-session-spice.c | 13 ++++++++-----
 3 files changed, 41 insertions(+), 15 deletions(-)

diff --git a/src/virt-viewer-app.c b/src/virt-viewer-app.c
index 2153d54..6793555 100644
--- a/src/virt-viewer-app.c
+++ b/src/virt-viewer-app.c
@@ -301,12 +301,35 @@ virt_viewer_app_quit(VirtViewerApp *self)
     gtk_main_quit();
 }
 
-gint virt_viewer_app_get_n_initial_displays(VirtViewerApp* self)
+GList* virt_viewer_app_get_initial_displays(VirtViewerApp* self)
 {
-    if (self->priv->initial_display_map)
-        return g_hash_table_size(self->priv->initial_display_map);
+    if (!self->priv->initial_display_map) {
+        GList *l = NULL;
+        gint i;
+        gint n = gdk_screen_get_n_monitors(gdk_screen_get_default());
 
-    return gdk_screen_get_n_monitors(gdk_screen_get_default());
+        for (i = 0; i < n; i++) {
+            l = g_list_append(l, GINT_TO_POINTER(i));
+        }
+        return l;
+    }
+    return g_hash_table_get_keys(self->priv->initial_display_map);
+}
+
+static gint virt_viewer_app_get_first_monitor(VirtViewerApp *self)
+{
+    if (self->priv->fullscreen && self->priv->initial_display_map) {
+        gint first = G_MAXINT;
+        GHashTableIter iter;
+        gpointer key, value;
+        g_hash_table_iter_init(&iter, self->priv->initial_display_map);
+        while (g_hash_table_iter_next(&iter, &key, &value)) {
+            gint monitor = GPOINTER_TO_INT(key);
+            first = MIN(first, monitor);
+        }
+        return first;
+    }
+    return 0;
 }
 
 gint virt_viewer_app_get_initial_monitor_for_display(VirtViewerApp* self, gint display)
@@ -1711,14 +1734,16 @@ title_maybe_changed(VirtViewerApp *self, GParamSpec* pspec G_GNUC_UNUSED, gpoint
 }
 
 static void
-virt_viewer_app_init (VirtViewerApp *self)
+virt_viewer_app_init(VirtViewerApp *self)
 {
     GError *error = NULL;
+    self->priv = GET_PRIVATE(self);
 
     gtk_window_set_default_icon_name("virt-viewer");
     virt_viewer_app_set_debug(opt_debug);
+    virt_viewer_app_set_fullscreen(self, opt_fullscreen);
+    virt_viewer_app_set_hotkeys(self, opt_hotkeys);
 
-    self->priv = GET_PRIVATE(self);
     self->priv->displays = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, g_object_unref);
     self->priv->config = g_key_file_new();
     self->priv->config_file = g_build_filename(g_get_user_config_dir(),
@@ -1803,11 +1828,9 @@ virt_viewer_app_constructed (GObject *object)
 {
     VirtViewerApp *self = VIRT_VIEWER_APP(object);
 
-    self->priv->main_window = virt_viewer_app_window_new(self, 0);
+    self->priv->main_window = virt_viewer_app_window_new(self,virt_viewer_app_get_first_monitor(self));
     self->priv->main_notebook = GTK_WIDGET(virt_viewer_window_get_notebook(self->priv->main_window));
 
-    virt_viewer_app_set_fullscreen(self, opt_fullscreen);
-    virt_viewer_app_set_hotkeys(self, opt_hotkeys);
     virt_viewer_app_set_kiosk(self, opt_kiosk);
     virt_viewer_window_set_zoom_level(self->priv->main_window, opt_zoom);
 
diff --git a/src/virt-viewer-app.h b/src/virt-viewer-app.h
index d214279..c6449be 100644
--- a/src/virt-viewer-app.h
+++ b/src/virt-viewer-app.h
@@ -97,7 +97,7 @@ VirtViewerSession* virt_viewer_app_get_session(VirtViewerApp *self);
 gboolean virt_viewer_app_get_fullscreen(VirtViewerApp *app);
 GOptionGroup* virt_viewer_app_get_option_group(void);
 void virt_viewer_app_clear_hotkeys(VirtViewerApp *app);
-gint virt_viewer_app_get_n_initial_displays(VirtViewerApp* self);
+GList* virt_viewer_app_get_initial_displays(VirtViewerApp* self);
 gint virt_viewer_app_get_initial_monitor_for_display(VirtViewerApp* self, gint display);
 void virt_viewer_app_set_enable_accel(VirtViewerApp *app, gboolean enable);
 void virt_viewer_app_show_preferences(VirtViewerApp *app, GtkWidget *parent);
diff --git a/src/virt-viewer-session-spice.c b/src/virt-viewer-session-spice.c
index 5eb7234..4fdab2b 100644
--- a/src/virt-viewer-session-spice.c
+++ b/src/virt-viewer-session-spice.c
@@ -824,7 +824,8 @@ virt_viewer_session_spice_fullscreen_auto_conf(VirtViewerSessionSpice *self)
     GdkRectangle *displays;
     gboolean agent_connected;
     gint i;
-    gsize ndisplays = 0;
+    GList *initial_displays, *l;
+    guint ndisplays;
 
     /* only do auto-conf once at startup. Avoid repeating auto-conf later due to
      * agent disconnection/re-connection, etc */
@@ -854,18 +855,20 @@ virt_viewer_session_spice_fullscreen_auto_conf(VirtViewerSessionSpice *self)
 
     spice_main_set_display_enabled(cmain, -1, FALSE);
 
-    ndisplays = virt_viewer_app_get_n_initial_displays(app);
-    g_debug("Performing full screen auto-conf, %" G_GSIZE_FORMAT " host monitors", ndisplays);
+    initial_displays = virt_viewer_app_get_initial_displays(app);
+    ndisplays = g_list_length(initial_displays);
+    g_debug("Performing full screen auto-conf, %u host monitors", ndisplays);
     displays = g_new0(GdkRectangle, ndisplays);
 
-    for (i = 0; i < ndisplays; i++) {
+    for (i = 0, l = initial_displays; l != NULL; l = l->next, i++) {
         GdkRectangle* rect = &displays[i];
-        gint j = virt_viewer_app_get_initial_monitor_for_display(app, i);
+        gint j = virt_viewer_app_get_initial_monitor_for_display(app, GPOINTER_TO_INT(l->data));
         if (j == -1)
             continue;
 
         gdk_screen_get_monitor_geometry(screen, j, rect);
     }
+    g_list_free(initial_displays);
 
     virt_viewer_shift_monitors_to_origin(displays, ndisplays);
 
-- 
2.1.0




More information about the virt-tools-list mailing list