[vinagre/gnome-2-28] Keep the aspect ratio when using scaling mode. Closes #593192.
- From: Jonh Wendell <jwendell src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [vinagre/gnome-2-28] Keep the aspect ratio when using scaling mode. Closes #593192.
- Date: Mon, 19 Oct 2009 11:32:06 +0000 (UTC)
commit 346e3229faa22cf5812dcad01556bffdc829fbde
Author: Jonh Wendell <jwendell gnome org>
Date: Sat Oct 17 11:56:24 2009 -0300
Keep the aspect ratio when using scaling mode. Closes #593192.
plugins/vnc/vinagre-vnc-tab.c | 50 ++++++++++++++++++++++++++++++++++++++++-
1 files changed, 49 insertions(+), 1 deletions(-)
---
diff --git a/plugins/vnc/vinagre-vnc-tab.c b/plugins/vnc/vinagre-vnc-tab.c
index 0c7dcea..21eb54c 100644
--- a/plugins/vnc/vinagre-vnc-tab.c
+++ b/plugins/vnc/vinagre-vnc-tab.c
@@ -790,10 +790,52 @@ vnc_tab_clipboard_cb (GtkClipboard *cb, GdkEvent *event, VinagreVncTab *vnc_tab)
g_free (text);
}
+/*
+ * Called when the main container widget's size has been set.
+ * It attempts to fit the VNC widget into this space while
+ * maintaining aspect ratio
+ *
+ * Code borrowed from from virt-viewer, thanks Daniel Berrange :)
+ */
+static void
+vnc_tab_resize_align (GtkWidget *widget,
+ GtkAllocation *alloc,
+ VinagreVncTab *vnc_tab)
+{
+ double desktopAspect = (double)vnc_display_get_width (VNC_DISPLAY (vnc_tab->priv->vnc)) / (double)vnc_display_get_height (VNC_DISPLAY (vnc_tab->priv->vnc));
+ double scrollAspect = (double)alloc->width / (double)alloc->height;
+ int height, width;
+ GtkAllocation child;
+ int dx = 0, dy = 0;
+
+ if (!vnc_display_is_open (VNC_DISPLAY (vnc_tab->priv->vnc)))
+ return;
+
+ if (scrollAspect > desktopAspect)
+ {
+ width = alloc->height * desktopAspect;
+ dx = (alloc->width - width) / 2;
+ height = alloc->height;
+ }
+ else
+ {
+ width = alloc->width;
+ height = alloc->width / desktopAspect;
+ dy = (alloc->height - height) / 2;
+ }
+
+ child.x = alloc->x + dx;
+ child.y = alloc->y + dy;
+ child.width = width;
+ child.height = height;
+ gtk_widget_size_allocate(vnc_tab->priv->vnc, &child);
+}
+
static void
vinagre_vnc_tab_init (VinagreVncTab *vnc_tab)
{
GtkClipboard *cb;
+ GtkWidget *align;
vnc_tab->priv = VINAGRE_VNC_TAB_GET_PRIVATE (vnc_tab);
vnc_tab->priv->clipboard_str = NULL;
@@ -802,7 +844,13 @@ vinagre_vnc_tab_init (VinagreVncTab *vnc_tab)
/* Create the vnc widget */
vnc_tab->priv->vnc = vnc_display_new ();
- vinagre_tab_add_view (VINAGRE_TAB (vnc_tab), vnc_tab->priv->vnc);
+ align = gtk_alignment_new (0.5, 0.5, 1, 1);
+
+ g_signal_connect(align, "size-allocate",
+ G_CALLBACK (vnc_tab_resize_align), vnc_tab);
+ gtk_container_add (GTK_CONTAINER (align), vnc_tab->priv->vnc);
+
+ vinagre_tab_add_view (VINAGRE_TAB (vnc_tab), align);
g_signal_connect (vnc_tab->priv->vnc,
"vnc-connected",
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]