[virt-tools-list] [PATCH virt-viewer] spice: only autoresize once with screen size in fullscreen

Marc-André Lureau marcandre.lureau at gmail.com
Wed Oct 17 22:48:36 UTC 2012


It's currently not possible to configure guest with higher resolution
than native, as it will switch back to native, since the gtk widget
allocation will always end up being the size of the screen. We
special-case fullscreen mode, and only resize when entering
fullscreen. Furthermore, it avoids sending extra unnecessary resize
events to the guest whenever gtk+ call size allocate in various
stages, with different values.

https://bugzilla.redhat.com/show_bug.cgi?id=864929
---
 src/virt-viewer-app.c           |  8 ++++++++
 src/virt-viewer-app.h           |  1 +
 src/virt-viewer-display-spice.c | 31 +++++++++++++++++++++++++++++--
 3 files changed, 38 insertions(+), 2 deletions(-)

diff --git a/src/virt-viewer-app.c b/src/virt-viewer-app.c
index 2e6c895..7dcc4c1 100644
--- a/src/virt-viewer-app.c
+++ b/src/virt-viewer-app.c
@@ -1591,6 +1591,14 @@ static void fullscreen_cb(gpointer key,
         virt_viewer_window_leave_fullscreen(vwin);
 }
 
+gboolean
+virt_viewer_app_get_fullscreen(VirtViewerApp *self)
+{
+    g_return_val_if_fail(VIRT_VIEWER_IS_APP(self), FALSE);
+
+    return self->priv->fullscreen;
+}
+
 static void
 virt_viewer_app_set_fullscreen(VirtViewerApp *self, gboolean fullscreen)
 {
diff --git a/src/virt-viewer-app.h b/src/virt-viewer-app.h
index 812a7fe..2cd3547 100644
--- a/src/virt-viewer-app.h
+++ b/src/virt-viewer-app.h
@@ -95,6 +95,7 @@ void virt_viewer_app_show_display(VirtViewerApp *self);
 GHashTable* virt_viewer_app_get_windows(VirtViewerApp *self);
 gboolean virt_viewer_app_get_enable_accel(VirtViewerApp *self);
 VirtViewerSession* virt_viewer_app_get_session(VirtViewerApp *self);
+gboolean virt_viewer_app_get_fullscreen(VirtViewerApp *app);
 
 G_END_DECLS
 
diff --git a/src/virt-viewer-display-spice.c b/src/virt-viewer-display-spice.c
index a035517..753e369 100644
--- a/src/virt-viewer-display-spice.c
+++ b/src/virt-viewer-display-spice.c
@@ -38,6 +38,13 @@ G_DEFINE_TYPE (VirtViewerDisplaySpice, virt_viewer_display_spice, VIRT_VIEWER_TY
 struct _VirtViewerDisplaySpicePrivate {
     SpiceChannel *channel; /* weak reference */
     SpiceDisplay *display;
+    int auto_resize;
+};
+
+enum {
+    AUTO_RESIZE_ALWAYS,
+    AUTO_RESIZE_FULLSCREEN,
+    AUTO_RESIZE_NEVER,
 };
 
 #define VIRT_VIEWER_DISPLAY_SPICE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), VIRT_VIEWER_TYPE_DISPLAY_SPICE, VirtViewerDisplaySpicePrivate))
@@ -189,6 +196,12 @@ virt_viewer_display_spice_size_allocate(VirtViewerDisplaySpice *self,
     if (virt_viewer_display_get_show_hint(VIRT_VIEWER_DISPLAY(self)) & VIRT_VIEWER_DISPLAY_SHOW_HINT_DISABLED)
         return;
 
+    if (self->priv->auto_resize == AUTO_RESIZE_FULLSCREEN) {
+        GdkScreen *screen = gtk_widget_get_screen(GTK_WIDGET(self));
+        dw = gdk_screen_get_width(screen);
+        dh = gdk_screen_get_height(screen);
+    }
+
     if (virt_viewer_display_get_zoom(VIRT_VIEWER_DISPLAY(self))) {
         zoom = virt_viewer_display_get_zoom_level(VIRT_VIEWER_DISPLAY(self));
 
@@ -198,8 +211,11 @@ virt_viewer_display_spice_size_allocate(VirtViewerDisplaySpice *self,
 
     g_object_get(self, "nth-display", &nth, NULL);
 
-    spice_main_set_display(get_main(VIRT_VIEWER_DISPLAY(self)),
-                           nth, 0, 0, dw, dh);
+    if (self->priv->auto_resize != AUTO_RESIZE_NEVER)
+        spice_main_set_display(get_main(VIRT_VIEWER_DISPLAY(self)),
+                               nth, 0, 0, dw, dh);
+    if (self->priv->auto_resize == AUTO_RESIZE_FULLSCREEN)
+        self->priv->auto_resize = AUTO_RESIZE_NEVER;
 }
 
 static void
@@ -216,6 +232,15 @@ enable_accel_changed(VirtViewerApp *app,
     }
 }
 
+static void
+fullscreen_changed(VirtViewerApp *app,
+                   GParamSpec *pspec G_GNUC_UNUSED,
+                   VirtViewerDisplaySpice *self)
+{
+    self->priv->auto_resize = virt_viewer_app_get_fullscreen(app) ?
+        AUTO_RESIZE_FULLSCREEN : AUTO_RESIZE_ALWAYS;
+}
+
 GtkWidget *
 virt_viewer_display_spice_new(VirtViewerSessionSpice *session,
                               SpiceChannel *channel,
@@ -268,6 +293,8 @@ virt_viewer_display_spice_new(VirtViewerSessionSpice *session,
     app = virt_viewer_session_get_app(VIRT_VIEWER_SESSION(session));
     virt_viewer_signal_connect_object(app, "notify::enable-accel",
                                       G_CALLBACK(enable_accel_changed), self, 0);
+    virt_viewer_signal_connect_object(app, "notify::fullscreen",
+                                      G_CALLBACK(fullscreen_changed), self, 0);
     enable_accel_changed(app, NULL, self);
 
     return GTK_WIDGET(self);
-- 
1.7.11.7




More information about the virt-tools-list mailing list