[virt-tools-list] [PATCH virt-viewer 12/17] Resize guest desktop with SPICE
Marc-André Lureau
marcandre.lureau at gmail.com
Fri Jan 27 13:51:31 UTC 2012
This is the method we prefer, even though we can't keep aspect ratio.
We could eventually support aspect ration in spice-gtk.
---
src/virt-viewer-display-spice.c | 5 ++++-
src/virt-viewer-display.c | 21 +++++++++++++++++++--
src/virt-viewer-display.h | 2 ++
3 files changed, 25 insertions(+), 3 deletions(-)
diff --git a/src/virt-viewer-display-spice.c b/src/virt-viewer-display-spice.c
index c73692d..2ae40dd 100644
--- a/src/virt-viewer-display-spice.c
+++ b/src/virt-viewer-display-spice.c
@@ -73,6 +73,8 @@ static void
virt_viewer_display_spice_init(VirtViewerDisplaySpice *self G_GNUC_UNUSED)
{
self->priv = VIRT_VIEWER_DISPLAY_SPICE_GET_PRIVATE(self);
+
+ virt_viewer_display_set_maintain_aspect_ratio(VIRT_VIEWER_DISPLAY(self), FALSE);
}
static void
@@ -122,6 +124,7 @@ primary_create(SpiceChannel *channel G_GNUC_UNUSED,
DEBUG_LOG("spice desktop resize %dx%d", width, height);
virt_viewer_display_set_desktop_size(display, width, height);
+ virt_viewer_display_set_zoom_level(display, 100);
}
@@ -177,9 +180,9 @@ virt_viewer_display_spice_new(SpiceChannel *channel,
g_object_set(self->priv->display,
"grab-keyboard", TRUE,
"grab-mouse", TRUE,
- "resize-guest", FALSE,
"scaling", TRUE,
"auto-clipboard", TRUE,
+ "resize-guest", TRUE,
NULL);
g_signal_connect(self->priv->display,
diff --git a/src/virt-viewer-display.c b/src/virt-viewer-display.c
index fe25a8e..4558f68 100644
--- a/src/virt-viewer-display.c
+++ b/src/virt-viewer-display.c
@@ -40,6 +40,7 @@ struct _VirtViewerDisplayPrivate
gboolean zoom;
gint nth_display;
gint show_hint;
+ gboolean maintain_aspect_ratio;
};
static void virt_viewer_display_size_request(GtkWidget *widget,
@@ -219,6 +220,7 @@ virt_viewer_display_init(VirtViewerDisplay *display)
display->priv->zoom_level = 100;
display->priv->zoom = TRUE;
display->priv->dirty = TRUE;
+ display->priv->maintain_aspect_ratio = TRUE;
}
GtkWidget*
@@ -376,7 +378,13 @@ virt_viewer_display_size_allocate(GtkWidget *widget,
desktopAspect = (double)priv->desktopWidth / (double)priv->desktopHeight;
- if (child && gtk_widget_get_visible(child)) {
+ if (child &&
+ gtk_widget_get_visible(child)) {
+ if (!priv->maintain_aspect_ratio) {
+ gtk_widget_size_allocate(child, allocation);
+ goto end;
+ }
+
border_width = gtk_container_get_border_width(GTK_CONTAINER(display));
width = MAX(1, allocation->width - 2 * border_width);
@@ -398,7 +406,7 @@ virt_viewer_display_size_allocate(GtkWidget *widget,
gtk_widget_size_allocate(child, &child_allocation);
}
-
+end:
/* This unsets the size request, so that the user can
* manually resize the window smaller again
*/
@@ -409,6 +417,15 @@ virt_viewer_display_size_allocate(GtkWidget *widget,
}
+void virt_viewer_display_set_maintain_aspect_ratio(VirtViewerDisplay *display,
+ gboolean maintain)
+{
+ g_return_if_fail(VIRT_VIEWER_IS_DISPLAY(display));
+
+ display->priv->maintain_aspect_ratio = maintain;
+}
+
+
void virt_viewer_display_set_desktop_size(VirtViewerDisplay *display,
guint width,
guint height)
diff --git a/src/virt-viewer-display.h b/src/virt-viewer-display.h
index d49dd67..49365ff 100644
--- a/src/virt-viewer-display.h
+++ b/src/virt-viewer-display.h
@@ -84,6 +84,8 @@ GType virt_viewer_display_get_type(void);
GtkWidget *virt_viewer_display_new(void);
+void virt_viewer_display_set_maintain_aspect_ratio(VirtViewerDisplay *display,
+ gboolean maintain);
void virt_viewer_display_set_desktop_size(VirtViewerDisplay *display,
guint width,
guint height);
--
1.7.7.6
More information about the virt-tools-list
mailing list