[virt-tools-list] [PATCH virt-viewer 3/3] virt-viewer-window: Change zoom when cannot resize guest to fit within monitor

Pavel Grunt pgrunt at redhat.com
Thu May 21 17:19:20 UTC 2015


The zoom level should be changed instead of changing the desktop size
when it is not possible to resize the desktop of the guest (VNC, Spice
without the agent). Because zoom operations take into account
'desktopWidth' and 'desktopHeight' of VirtViewerDisplay, so when these
dimensions are wrong, the result of a zoom operation is wrong too.

Resolves: rhbz#1221501
---
 src/virt-viewer-window.c | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/src/virt-viewer-window.c b/src/virt-viewer-window.c
index 2a72207..8ebd9bd 100644
--- a/src/virt-viewer-window.c
+++ b/src/virt-viewer-window.c
@@ -423,6 +423,7 @@ virt_viewer_window_resize(VirtViewerWindow *self, gboolean keep_win_size)
     guint desktopWidth, display_width;
     guint desktopHeight, display_height;
     VirtViewerWindowPrivate *priv = self->priv;
+    guint new_zoom = priv->zoomlevel;
 
     if (priv->fullscreen)
         return;
@@ -462,6 +463,7 @@ virt_viewer_window_resize(VirtViewerWindow *self, gboolean keep_win_size)
             width = fullscreen.width;
             height = fullscreen.width / desktopAspect;
         }
+        new_zoom = NORMAL_ZOOM_LEVEL * width / desktopWidth;
         width *= (double) NORMAL_ZOOM_LEVEL / priv->zoomlevel;
         height *= (double) NORMAL_ZOOM_LEVEL / priv->zoomlevel;
     } else {
@@ -469,12 +471,18 @@ virt_viewer_window_resize(VirtViewerWindow *self, gboolean keep_win_size)
         height = desktopHeight;
     }
 
-    g_debug("Decided todo %dx%d (desktop is %dx%d, fullscreen is %dx%d",
-              width, height, desktopWidth, desktopHeight,
-              fullscreen.width, fullscreen.height);
-
-    virt_viewer_display_set_desktop_size(VIRT_VIEWER_DISPLAY(priv->display),
-                                         width, height);
+    if (virt_viewer_session_can_resize_guest(virt_viewer_app_get_session(self->priv->app))) {
+        g_debug("Decided todo %dx%d (desktop is %dx%d, fullscreen is %dx%d",
+                width, height, desktopWidth, desktopHeight,
+                fullscreen.width, fullscreen.height);
+        virt_viewer_display_set_desktop_size(VIRT_VIEWER_DISPLAY(priv->display),
+                                             width, height);
+    } else if (new_zoom != priv->zoomlevel) {
+        g_debug("window does not fit to monitor, changing zoom from %d to %d",
+                priv->zoomlevel, new_zoom);
+        virt_viewer_window_set_zoom_level(self, new_zoom);
+        return;
+    }
 
     if (!keep_win_size)
         virt_viewer_window_queue_resize(self);
-- 
2.4.1




More information about the virt-tools-list mailing list