[virt-tools-list] [PATCH virt-viewer] virt-viewer-window: Change zoom with respect to real zoom
Jonathon Jongsma
jjongsma at redhat.com
Tue Jun 2 14:52:24 UTC 2015
On Tue, 2015-06-02 at 14:23 +0200, Pavel Grunt wrote:
> 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;
> }
This last hunk doesn't quite look right to me, because you're changing
what you're comparing against. The old code was comparing the *Window*'s
new zoom level with the *Display*'s current zoom level. The new code is
comparing the *Window*'s new zoom level with the *Window*'s effective
zoom level. This means that if the new zoom level doesn't match the
Display's zoom level, but it does match the window's effective zoom
level, the Display's zoom level will not be updated properly.
Jonathon
More information about the virt-tools-list
mailing list