[virt-tools-list] [PATCH virt-viewer] display-spice: Set dimensions when display became ready

Pavel Grunt pgrunt at redhat.com
Tue Apr 21 09:55:46 UTC 2015


The display can be set as enabled before it is ready (i.e. it doesn't
have desktop dimensions). When it became ready the "show-hint" notify
is emitted that triggers calculation of the minimal zoom level, which
will return wrong value due to wrong desktop dimensions.

This commit makes sure that dimensions of the display are set before
the display is set as ready.

related: rhbz#1206460
---
 src/virt-viewer-display-spice.c | 40 +++++++++++++++++++++++++++++++++++++++-
 1 file changed, 39 insertions(+), 1 deletion(-)

diff --git a/src/virt-viewer-display-spice.c b/src/virt-viewer-display-spice.c
index 399c207..c96b370 100644
--- a/src/virt-viewer-display-spice.c
+++ b/src/virt-viewer-display-spice.c
@@ -138,12 +138,50 @@ virt_viewer_display_spice_get_pixbuf(VirtViewerDisplay *display)
 }
 
 static void
+virt_viewer_display_spice_set_desktop_from_channel(VirtViewerDisplaySpice *self)
+{
+    GArray *monitors = NULL;
+    guint i, nth, monitor_id, channelid;
+    SpiceChannel *channel = self->priv->channel;
+
+    g_object_get(G_OBJECT(self), "nth-display", &nth, NULL);
+    g_object_get(G_OBJECT(channel),
+                 "channel-id", &channelid,
+                 "monitors", &monitors,
+                 NULL);
+
+    monitor_id = nth - channelid;
+    for (i = 0; i < monitors->len; i++) {
+        SpiceDisplayMonitorConfig *monitor = &g_array_index(monitors,
+                                                            SpiceDisplayMonitorConfig,
+                                                            i);
+        if (monitor_id == monitor->id) {
+            g_debug("Setting dimensions of #%d display from channel", nth);
+            virt_viewer_display_spice_set_desktop(VIRT_VIEWER_DISPLAY(self),
+                                                  monitor->x, monitor->y,
+                                                  monitor->width, monitor->height);
+            break;
+        }
+    }
+    g_warn_if_fail(i < monitors->len);
+
+    g_clear_pointer(&monitors, g_array_unref);
+}
+
+static void
 update_display_ready(VirtViewerDisplaySpice *self)
 {
-    gboolean ready;
+    gboolean ready, was_ready;
 
     g_object_get(self->priv->display, "ready", &ready, NULL);
 
+    was_ready = virt_viewer_display_get_show_hint(VIRT_VIEWER_DISPLAY(self)) &
+                VIRT_VIEWER_DISPLAY_SHOW_HINT_READY;
+    if (!was_ready && ready) {
+        /* display wasn't ready, update its initial dimensions */
+        virt_viewer_display_spice_set_desktop_from_channel(self);
+    }
+
     virt_viewer_display_set_show_hint(VIRT_VIEWER_DISPLAY(self),
                                       VIRT_VIEWER_DISPLAY_SHOW_HINT_READY, ready);
 }
-- 
2.3.5




More information about the virt-tools-list mailing list