[PATCH virt-viewer 3/3] Adjust zoom level when window is resized and guest cannot be resized

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



When resizing the window and it is not possible to resize the guest
desktop, VirtViewerDisplay acts like the zoom level was changed.
Because this change is not stored anywhere, zoom operations are not
working correctly (e.g. 'zooming in' decreases the zoom level).

This commit solves the problem by dynamically adjusting the zoom level
when it is not possible to resize the guest display.

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

diff --git a/src/virt-viewer-display.c b/src/virt-viewer-display.c
index 3efe24c..3bdc9b8 100644
--- a/src/virt-viewer-display.c
+++ b/src/virt-viewer-display.c
@@ -519,6 +519,7 @@ virt_viewer_display_size_allocate(GtkWidget *widget,
     desktopAspect = (double)priv->desktopWidth / (double)priv->desktopHeight;
 
     if (child && gtk_widget_get_visible(child)) {
+        guint new_zoom;
         border_width = gtk_container_get_border_width(GTK_CONTAINER(display));
 
         width  = MAX(1, allocation->width - 2 * border_width);
@@ -532,6 +533,14 @@ virt_viewer_display_size_allocate(GtkWidget *widget,
             child_allocation.width = width;
             child_allocation.height = round(width / desktopAspect);
         }
+        new_zoom = round((double) NORMAL_ZOOM_LEVEL * child_allocation.width / priv->desktopWidth);
+
+        if (!virt_viewer_session_can_resize_guest(priv->session) && new_zoom != priv->zoom_level) {
+            g_debug("cannot resize guest, changing zoom level from %d to %d",
+                    priv->zoom_level, new_zoom);
+            priv->zoom_level = new_zoom;
+            g_object_notify(G_OBJECT(display), "zoom-level");
+        }
 
         child_allocation.x = 0.5 * (width - child_allocation.width) + allocation->x + border_width;
         child_allocation.y = 0.5 * (height - child_allocation.height) + allocation->y + border_width;
-- 
2.4.1

_______________________________________________
virt-tools-list mailing list
virt-tools-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/virt-tools-list




[Index of Archives]     [Linux Virtualization]     [KVM Development]     [CentOS Virtualization]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite Forum]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]     [Video 4 Linux]

  Powered by Linux