[virt-tools-list] [PATCH virt-viewer] virt-viewer-window: Change zoom with respect to real zoom

Pavel Grunt pgrunt at redhat.com
Tue Jun 2 12:23:24 UTC 2015


The zoom can be changed by resizing the window (VNC / Spice without
the agent). It is necessary to recalculate the zoom level before
changing it, otherwise zoom operations will not work correctly.

Resolves: https://bugs.freedesktop.org/show_bug.cgi?id=90582
---
 src/virt-viewer-window.c | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/src/virt-viewer-window.c b/src/virt-viewer-window.c
index d67fbc1..5123e43 100644
--- a/src/virt-viewer-window.c
+++ b/src/virt-viewer-window.c
@@ -368,19 +368,32 @@ virt_viewer_window_desktop_resize(VirtViewerDisplay *display G_GNUC_UNUSED,
     virt_viewer_window_resize(self, FALSE);
 }
 
+static gint
+virt_viewer_window_get_real_zoom_level(VirtViewerWindow *self)
+{
+    GtkAllocation allocation;
+    guint width, height;
+
+    gtk_widget_get_allocation(GTK_WIDGET(self->priv->display), &allocation);
+    virt_viewer_display_get_desktop_size(self->priv->display, &width, &height);
+
+    return round((double) NORMAL_ZOOM_LEVEL * allocation.width / width);
+}
 
 G_MODULE_EXPORT void
 virt_viewer_window_menu_view_zoom_out(GtkWidget *menu G_GNUC_UNUSED,
                                       VirtViewerWindow *self)
 {
-    virt_viewer_window_set_zoom_level(self, self->priv->zoomlevel - ZOOM_STEP);
+    virt_viewer_window_set_zoom_level(self,
+                                      virt_viewer_window_get_real_zoom_level(self) - ZOOM_STEP);
 }
 
 G_MODULE_EXPORT void
 virt_viewer_window_menu_view_zoom_in(GtkWidget *menu G_GNUC_UNUSED,
                                      VirtViewerWindow *self)
 {
-    virt_viewer_window_set_zoom_level(self, self->priv->zoomlevel + ZOOM_STEP);
+    virt_viewer_window_set_zoom_level(self,
+                                      virt_viewer_window_get_real_zoom_level(self) + ZOOM_STEP);
 }
 
 G_MODULE_EXPORT void
@@ -1471,7 +1484,7 @@ virt_viewer_window_set_zoom_level(VirtViewerWindow *self, gint zoom_level)
         priv->zoomlevel = min_zoom;
     }
 
-    if (priv->zoomlevel == virt_viewer_display_get_zoom_level(priv->display)) {
+    if (priv->zoomlevel == virt_viewer_window_get_real_zoom_level(self)) {
         g_debug("Zoom level not changed, using: %d", priv->zoomlevel);
         return;
     }
-- 
2.4.2




More information about the virt-tools-list mailing list