[Spice-commits] 3 commits - gtk/decode-glz.c gtk/spice-channel.c gtk/spice-widget.c gtk/spice-widget-priv.h

Marc-André Lureau elmarco at kemper.freedesktop.org
Fri Feb 3 05:50:46 PST 2012


 gtk/decode-glz.c        |    2 
 gtk/spice-channel.c     |    6 +-
 gtk/spice-widget-priv.h |    1 
 gtk/spice-widget.c      |  100 +++++++++++++++++++++++++++++++++---------------
 4 files changed, 74 insertions(+), 35 deletions(-)

New commits:
commit 96405efe4fe0e549c6a8110f323faf411e3c7e68
Author: Marc-André Lureau <marcandre.lureau at redhat.com>
Date:   Wed Feb 1 21:47:31 2012 +0100

    Lower or silence some harmless debug messages

diff --git a/gtk/decode-glz.c b/gtk/decode-glz.c
index fb6ecc9..4033480 100644
--- a/gtk/decode-glz.c
+++ b/gtk/decode-glz.c
@@ -142,8 +142,6 @@ static gboolean wait_for_image(gpointer data)
     struct glz_image *image = wait->window->images[slot];
     gboolean ready = image && image->hdr.id == wait->id;
 
-    SPICE_DEBUG("image with slot %d: %s", slot, ready ? "yes" : "no");
-
     return ready;
 }
 
diff --git a/gtk/spice-channel.c b/gtk/spice-channel.c
index bdfb02b..f20e8e6 100644
--- a/gtk/spice-channel.c
+++ b/gtk/spice-channel.c
@@ -1055,14 +1055,14 @@ static void spice_channel_recv_auth(SpiceChannel *channel)
 
     rc = spice_channel_read(channel, &link_res, sizeof(link_res));
     if (rc != sizeof(link_res)) {
-        g_critical("incomplete auth reply (%d/%" G_GSIZE_FORMAT ")",
-                   rc, sizeof(link_res));
+        SPICE_DEBUG("incomplete auth reply (%d/%" G_GSIZE_FORMAT ")",
+                    rc, sizeof(link_res));
         emit_main_context(channel, SPICE_CHANNEL_EVENT, SPICE_CHANNEL_ERROR_LINK);
         return;
     }
 
     if (link_res != SPICE_LINK_ERR_OK) {
-        g_critical("link result: reply %d", link_res);
+        SPICE_DEBUG("link result: reply %d", link_res);
         emit_main_context(channel, SPICE_CHANNEL_EVENT, SPICE_CHANNEL_ERROR_AUTH);
         return;
     }
commit fdb286483c2ff30bba15dabaa5a6487b739125ca
Author: Marc-André Lureau <marcandre.lureau at redhat.com>
Date:   Wed Feb 1 16:55:28 2012 +0100

    widget: allow defining a zoom-level
    
    Add a "zoom-level" property. Maintain the given scaling ratio when
    scaling is enabled.
    
    If scaling is disabled, this property is ignored.
    
    For example at 50%, this allows to fit a 640x480 desktop in a 320x240
    widget and when resizing it to 640x512 to have a 1280x1024 desktop.
    
    (this feature is required by virt-viewer)

diff --git a/gtk/spice-widget-priv.h b/gtk/spice-widget-priv.h
index e0c6c4c..898d86c 100644
--- a/gtk/spice-widget-priv.h
+++ b/gtk/spice-widget-priv.h
@@ -107,6 +107,7 @@ struct _SpiceDisplayPrivate {
 #ifdef WIN32
     HHOOK                   keyboard_hook;
 #endif
+    gint                    zoom_level;
 };
 
 int      spicex_image_create                 (SpiceDisplay *display);
diff --git a/gtk/spice-widget.c b/gtk/spice-widget.c
index 256363e..c5c5d33 100644
--- a/gtk/spice-widget.c
+++ b/gtk/spice-widget.c
@@ -101,6 +101,7 @@ enum {
     PROP_AUTO_CLIPBOARD,
     PROP_SCALING,
     PROP_DISABLE_INPUTS,
+    PROP_ZOOM_LEVEL
 };
 
 /* Signals */
@@ -169,6 +170,9 @@ static void spice_display_get_property(GObject    *object,
     case PROP_DISABLE_INPUTS:
         g_value_set_boolean(value, d->disable_inputs);
 	break;
+    case PROP_ZOOM_LEVEL:
+        g_value_set_int(value, d->zoom_level);
+        break;
     default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
         break;
@@ -247,6 +251,10 @@ static void spice_display_set_property(GObject      *object,
         update_keyboard_grab(display);
         update_mouse_grab(display);
         break;
+    case PROP_ZOOM_LEVEL:
+        d->zoom_level = g_value_get_int(value);
+        scaling_updated(display);
+        break;
     default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
         break;
@@ -755,6 +763,7 @@ static void recalc_geometry(GtkWidget *widget)
 {
     SpiceDisplay *display = SPICE_DISPLAY(widget);
     SpiceDisplayPrivate *d = SPICE_DISPLAY_GET_PRIVATE(display);
+    gdouble zoom = 1.0;
 
     d->mx = 0;
     d->my = 0;
@@ -763,14 +772,15 @@ static void recalc_geometry(GtkWidget *widget)
             d->mx = (d->ww - d->width) / 2;
         if (d->wh > d->height)
             d->my = (d->wh - d->height) / 2;
-    }
+    } else
+        zoom = (gdouble)d->zoom_level / 100;
 
-    SPICE_DEBUG("monitors: id %d, guest %dx%d, window %dx%d, offset +%d+%d",
-                d->channel_id, d->width, d->height, d->ww, d->wh, d->mx, d->my);
+    SPICE_DEBUG("monitors: id %d, guest %dx%d, window %dx%d, zoom %g, offset +%d+%d",
+                d->channel_id, d->width, d->height, d->ww, d->wh, zoom, d->mx, d->my);
 
     if (d->resize_guest_enable)
         spice_main_set_display(d->main, d->channel_id,
-                               0, 0, d->ww, d->wh);
+                               0, 0, d->ww / zoom, d->wh / zoom);
 }
 
 /* ---------------------------------------------------------------- */
@@ -1434,6 +1444,25 @@ static void spice_display_class_init(SpiceDisplayClass *klass)
                               G_PARAM_CONSTRUCT |
                               G_PARAM_STATIC_STRINGS));
 
+
+    /**
+     * SpiceDisplay:zoom-level:
+     *
+     * Zoom level in percentage, from 10 to 400. Default to 100.
+     * (this option is only supported with cairo backend when scaling
+     * is enabled)
+     *
+     * Since: 0.10
+     **/
+    g_object_class_install_property
+        (gobject_class, PROP_ZOOM_LEVEL,
+         g_param_spec_int("zoom-level", "Zoom Level",
+                          "Zoom Level",
+                          10, 400, 100,
+                          G_PARAM_READWRITE |
+                          G_PARAM_CONSTRUCT |
+                          G_PARAM_STATIC_STRINGS));
+
     /**
      * SpiceDisplay::mouse-grab:
      * @display: the #SpiceDisplay that emitted the signal
commit 36026a90e7bcb134822b6b91a90bc5b1c4945123
Author: Marc-André Lureau <marcandre.lureau at redhat.com>
Date:   Wed Feb 1 16:55:28 2012 +0100

    widget: factor out update_size_request() and scaling_updated()
    
    Factor out and simplify a little the code to allow easier addition of
    zoom-level property.
    
    The "set_display" parameter for recalc_geometry() seems to be useless,
    since the code was apparently trying to set the guest to the given
    d->width and d->height, but reseting it to the current value, which
    cancel the effect.
    
    We should fix the problem of setting the guest resolution at
    display-init time in a follow-up patch since it probably never worked
    with spice-gtk.

diff --git a/gtk/spice-widget.c b/gtk/spice-widget.c
index e574274..256363e 100644
--- a/gtk/spice-widget.c
+++ b/gtk/spice-widget.c
@@ -123,7 +123,7 @@ static void try_keyboard_ungrab(SpiceDisplay *display);
 static void update_mouse_grab(SpiceDisplay *display);
 static void try_mouse_grab(SpiceDisplay *display);
 static void try_mouse_ungrab(SpiceDisplay *display);
-static void recalc_geometry(GtkWidget *widget, gboolean set_display);
+static void recalc_geometry(GtkWidget *widget);
 static void disconnect_main(SpiceDisplay *display);
 static void disconnect_cursor(SpiceDisplay *display);
 static void disconnect_display(SpiceDisplay *display);
@@ -175,6 +175,36 @@ static void spice_display_get_property(GObject    *object,
     }
 }
 
+static void scaling_updated(SpiceDisplay *display)
+{
+    SpiceDisplayPrivate *d = SPICE_DISPLAY_GET_PRIVATE(display);
+    GdkWindow *window = gtk_widget_get_window(GTK_WIDGET(display));
+
+    recalc_geometry(GTK_WIDGET(display));
+    if (d->ximage && window) { /* if not yet shown */
+        int ww, wh;
+        gdk_drawable_get_size(gtk_widget_get_window(GTK_WIDGET(display)), &ww, &wh);
+        gtk_widget_queue_draw_area(GTK_WIDGET(display), 0, 0, ww, wh);
+    }
+}
+
+static void update_size_request(SpiceDisplay *display)
+{
+    SpiceDisplayPrivate *d = SPICE_DISPLAY_GET_PRIVATE(display);
+    gint reqwidth, reqheight;
+
+    if (d->resize_guest_enable) {
+        reqwidth = 640;
+        reqheight = 480;
+    } else {
+        reqwidth = d->width;
+        reqheight = d->height;
+    }
+
+    gtk_widget_set_size_request(GTK_WIDGET(display), reqwidth, reqheight);
+    recalc_geometry(GTK_WIDGET(display));
+}
+
 static void spice_display_set_property(GObject      *object,
                                        guint         prop_id,
                                        const GValue *value,
@@ -201,23 +231,11 @@ static void spice_display_set_property(GObject      *object,
         break;
     case PROP_RESIZE_GUEST:
         d->resize_guest_enable = g_value_get_boolean(value);
-        if (d->resize_guest_enable) {
-            gtk_widget_set_size_request(GTK_WIDGET(display), 640, 480);
-            recalc_geometry(GTK_WIDGET(display), TRUE);
-        } else {
-            gtk_widget_set_size_request(GTK_WIDGET(display),
-                                        d->width, d->height);
-        }
+        update_size_request(display);
         break;
     case PROP_SCALING:
         d->allow_scaling = g_value_get_boolean(value);
-        recalc_geometry(GTK_WIDGET(display), FALSE);
-        if (d->ximage &&
-            gtk_widget_get_window(GTK_WIDGET(display))) { /* if not yet shown */
-            int ww, wh;
-            gdk_drawable_get_size(gtk_widget_get_window(GTK_WIDGET(display)), &ww, &wh);
-            gtk_widget_queue_draw_area(GTK_WIDGET(display), 0, 0, ww, wh);
-        }
+        scaling_updated(display);
         break;
     case PROP_AUTO_CLIPBOARD:
         g_object_set(d->gtk_session, "auto-clipboard",
@@ -733,7 +751,7 @@ static void update_mouse_grab(SpiceDisplay *display)
         try_mouse_ungrab(display);
 }
 
-static void recalc_geometry(GtkWidget *widget, gboolean set_display)
+static void recalc_geometry(GtkWidget *widget)
 {
     SpiceDisplay *display = SPICE_DISPLAY(widget);
     SpiceDisplayPrivate *d = SPICE_DISPLAY_GET_PRIVATE(display);
@@ -750,10 +768,9 @@ static void recalc_geometry(GtkWidget *widget, gboolean set_display)
     SPICE_DEBUG("monitors: id %d, guest %dx%d, window %dx%d, offset +%d+%d",
                 d->channel_id, d->width, d->height, d->ww, d->wh, d->mx, d->my);
 
-    if (d->resize_guest_enable && set_display) {
+    if (d->resize_guest_enable)
         spice_main_set_display(d->main, d->channel_id,
                                0, 0, d->ww, d->wh);
-    }
 }
 
 /* ---------------------------------------------------------------- */
@@ -1277,7 +1294,7 @@ static gboolean configure_event(GtkWidget *widget, GdkEventConfigure *conf)
     if (conf->width != d->ww  || conf->height != d->wh) {
         d->ww = conf->width;
         d->wh = conf->height;
-        recalc_geometry(widget, TRUE);
+        recalc_geometry(widget);
     }
     return true;
 }
@@ -1503,7 +1520,6 @@ static void primary_create(SpiceChannel *channel, gint format,
 {
     SpiceDisplay *display = data;
     SpiceDisplayPrivate *d = SPICE_DISPLAY_GET_PRIVATE(display);
-    gboolean set_display = FALSE;
 
     d->format = format;
     d->stride = stride;
@@ -1511,14 +1527,9 @@ static void primary_create(SpiceChannel *channel, gint format,
     d->data_origin = d->data = imgdata;
 
     if (d->width != width || d->height != height) {
-        if (d->width != 0 && d->height != 0)
-            set_display = TRUE;
         d->width  = width;
         d->height = height;
-        recalc_geometry(GTK_WIDGET(display), set_display);
-        if (!d->resize_guest_enable) {
-            gtk_widget_set_size_request(GTK_WIDGET(display), width, height);
-        }
+        update_size_request(display);
     }
 }
 


More information about the Spice-commits mailing list