[virt-tools-list] [PATCH 1/1] virt-viewer : add support for window scaling
Richard W.M. Jones
rjones at redhat.com
Tue Jun 15 19:41:48 UTC 2010
On Sat, Jun 12, 2010 at 11:07:34AM +1000, ronnie sahlberg wrote:
> Hi,
>
> Please find attached a small patch to "virt-viewer".
>
> It adds a feature to scale the window by a certain percentage, when
> not in FullScreen mode.
> Default is 100, i.e. no scaling.
>
> But the scaling can be set to any factor between 10 and 200 from the
> command line by using the added --scaling argument.
>
> There is also a new Zoom submenu, where scaling of 25%, 50%, 75% and
> 100% can be adjusted at runtime.
>
>
> I find this useful since I often run many virtual machines and I can
> then dedicate a desktop to show a whole bunch of 25% thumbnails.
>
> I hope others will find it useful too.
Ronnie, I believe the right place for patches would be
gtk-vnc-list<at>gnome.org. Forwarding.
Rich.
> # HG changeset patch
> # User Ronnie Sahlberg <ronniesahlberg at gmail.com>
> # Date 1276304404 -36000
> # Node ID 408de18828b78fe08044b9367f6802e13bcfd1c0
> # Parent a0786647b8e9e3416da81a34bc7f386393cf2476
> Added window scaling support
>
> diff -r a0786647b8e9 -r 408de18828b7 src/main.c
> --- a/src/main.c Wed Jun 09 09:13:00 2010 +0000
> +++ b/src/main.c Sat Jun 12 11:00:04 2010 +1000
> @@ -43,6 +43,7 @@
> GError *error = NULL;
> int ret;
> char *uri = NULL;
> + int scaling = 100;
> gchar **args = NULL;
> gboolean verbose = FALSE;
> gboolean debug = FALSE;
> @@ -63,6 +64,8 @@
> N_("wait for domain to start"), NULL },
> { "reconnect", 'r', 0, G_OPTION_ARG_NONE, &reconnect,
> N_("reconnect to domain upon restart"), NULL },
> + { "scaling", 's', 0, G_OPTION_ARG_INT, &scaling,
> + N_("scaling of window, in percentage"), "SCALE" },
> { "debug", '\0', 0, G_OPTION_ARG_NONE, &debug,
> N_("display debugging information"), NULL },
> { G_OPTION_REMAINING, '\0', 0, G_OPTION_ARG_STRING_ARRAY, &args,
> @@ -96,7 +99,12 @@
> return 1;
> }
>
> - ret = viewer_start (uri, args[0], direct, waitvm, reconnect, verbose, debug, NULL);
> + if (scaling < 10 || scaling > 200) {
> + fprintf(stderr, "Scaling factor must be within 10-200\n");
> + return 1;
> + }
> +
> + ret = viewer_start (uri, args[0], scaling, direct, waitvm, reconnect, verbose, debug, NULL);
> if (ret != 0)
> return ret;
>
> diff -r a0786647b8e9 -r 408de18828b7 src/viewer.c
> --- a/src/viewer.c Wed Jun 09 09:13:00 2010 +0000
> +++ b/src/viewer.c Sat Jun 12 11:00:04 2010 +1000
> @@ -53,6 +53,8 @@
> #include "events.h"
> #include "auth.h"
>
> +#define SCALE(x) do { x = viewer->fullscreen ? x : x * viewer->scaling / 100; } while(0)
> +
> gboolean doDebug = FALSE;
>
> enum menuNums {
> @@ -108,6 +110,8 @@
> GtkWidget *container;
> GtkWidget *vnc;
>
> + int scaling;
> +
> int desktopWidth;
> int desktopHeight;
> gboolean autoResize;
> @@ -265,11 +269,12 @@
> dy = (alloc->height - height) / 2;
> }
>
> - DEBUG_LOG("Align widget=%p is %dx%d, desktop is %dx%d, setting VNC to %dx%d",
> + DEBUG_LOG("Align widget=%p is %dx%d, desktop is %dx%d, setting VNC to %dx%d (scaling %d%%)",
> widget,
> alloc->width, alloc->height,
> viewer->desktopWidth, viewer->desktopHeight,
> - width, height);
> + width, height,
> + viewer->scaling);
>
> child.x = alloc->x + dx;
> child.y = alloc->y + dy;
> @@ -342,6 +347,9 @@
> height = viewer->desktopHeight;
> }
>
> + SCALE(width);
> + SCALE(height);
> +
> viewer_set_widget_size(viewer,
> glade_xml_get_widget(viewer->glade, "vnc-align"),
> width,
> @@ -513,6 +521,42 @@
> }
> }
>
> +static void viewer_menu_view_zoom25(GtkWidget *menu, VirtViewer *viewer)
> +{
> + if (!viewer->window)
> + return;
> +
> + viewer->scaling = 25;
> + viewer_resize_main_window(viewer);
> +}
> +
> +static void viewer_menu_view_zoom50(GtkWidget *menu, VirtViewer *viewer)
> +{
> + if (!viewer->window)
> + return;
> +
> + viewer->scaling = 50;
> + viewer_resize_main_window(viewer);
> +}
> +
> +static void viewer_menu_view_zoom75(GtkWidget *menu, VirtViewer *viewer)
> +{
> + if (!viewer->window)
> + return;
> +
> + viewer->scaling = 75;
> + viewer_resize_main_window(viewer);
> +}
> +
> +static void viewer_menu_view_zoom100(GtkWidget *menu, VirtViewer *viewer)
> +{
> + if (!viewer->window)
> + return;
> +
> + viewer->scaling = 100;
> + viewer_resize_main_window(viewer);
> +}
> +
> static void viewer_menu_view_resize(GtkWidget *menu, VirtViewer *viewer)
> {
> if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(menu))) {
> @@ -1166,6 +1210,7 @@
> int
> viewer_start (const char *uri,
> const char *name,
> + gint scaling,
> gboolean direct,
> gboolean waitvm,
> gboolean reconnect,
> @@ -1198,6 +1243,7 @@
> viewer->verbose = verbose;
> viewer->domkey = g_strdup(name);
> viewer->uri = g_strdup(uri);
> + viewer->scaling = scaling;
>
> g_value_init(&viewer->accelSetting, G_TYPE_STRING);
>
> @@ -1229,6 +1275,14 @@
> G_CALLBACK(viewer_menu_file_screenshot), viewer);
> glade_xml_signal_connect_data(viewer->glade, "viewer_menu_view_fullscreen",
> G_CALLBACK(viewer_menu_view_fullscreen), viewer);
> + glade_xml_signal_connect_data(viewer->glade, "viewer_menu_view_zoom25",
> + G_CALLBACK(viewer_menu_view_zoom25), viewer);
> + glade_xml_signal_connect_data(viewer->glade, "viewer_menu_view_zoom50",
> + G_CALLBACK(viewer_menu_view_zoom50), viewer);
> + glade_xml_signal_connect_data(viewer->glade, "viewer_menu_view_zoom75",
> + G_CALLBACK(viewer_menu_view_zoom75), viewer);
> + glade_xml_signal_connect_data(viewer->glade, "viewer_menu_view_zoom100",
> + G_CALLBACK(viewer_menu_view_zoom100), viewer);
> glade_xml_signal_connect_data(viewer->glade, "viewer_menu_view_resize",
> G_CALLBACK(viewer_menu_view_resize), viewer);
> glade_xml_signal_connect_data(viewer->glade, "viewer_menu_send",
> diff -r a0786647b8e9 -r 408de18828b7 src/viewer.glade
> --- a/src/viewer.glade Wed Jun 09 09:13:00 2010 +0000
> +++ b/src/viewer.glade Sat Jun 12 11:00:04 2010 +1000
> @@ -62,6 +62,45 @@
> </widget>
> </child>
> <child>
> + <widget class="GtkMenuItem" id="menu-view-zoom">
> + <property name="visible">True</property>
> + <property name="label" translatable="yes">Zoom</property>
> + <child>
> + <widget class="GtkMenu" id="menu4">
> + <property name="visible">True</property>
> + <child>
> + <widget class="GtkMenuItem" id="menu-view-zoom-25">
> + <property name="visible">True</property>
> + <property name="label" translatable="yes">Zoom 25%</property>
> + <signal name="activate" handler="viewer_menu_view_zoom25"/>
> + </widget>
> + </child>
> + <child>
> + <widget class="GtkMenuItem" id="menu-view-zoom-50">
> + <property name="visible">True</property>
> + <property name="label" translatable="yes">Zoom 50%</property>
> + <signal name="activate" handler="viewer_menu_view_zoom50"/>
> + </widget>
> + </child>
> + <child>
> + <widget class="GtkMenuItem" id="menu-view-zoom-75">
> + <property name="visible">True</property>
> + <property name="label" translatable="yes">Zoom 75%</property>
> + <signal name="activate" handler="viewer_menu_view_zoom75"/>
> + </widget>
> + </child>
> + <child>
> + <widget class="GtkMenuItem" id="menu-view-zoom-100">
> + <property name="visible">True</property>
> + <property name="label" translatable="yes">Zoom 100%</property>
> + <signal name="activate" handler="viewer_menu_view_zoom100"/>
> + </widget>
> + </child>
> + </widget>
> + </child>
> + </widget>
> + </child>
> + <child>
> <widget class="GtkCheckMenuItem" id="menu-view-resize">
> <property name="visible">True</property>
> <property name="label" translatable="yes">Automatically resize</property>
> diff -r a0786647b8e9 -r 408de18828b7 src/viewer.h
> --- a/src/viewer.h Wed Jun 09 09:13:00 2010 +0000
> +++ b/src/viewer.h Sat Jun 12 11:00:04 2010 +1000
> @@ -27,6 +27,7 @@
>
> extern int viewer_start (const char *uri,
> const char *name,
> + gint scaling,
> gboolean direct,
> gboolean waitvm,
> gboolean reconnect,
> _______________________________________________
> virt-tools-list mailing list
> virt-tools-list at redhat.com
> https://www.redhat.com/mailman/listinfo/virt-tools-list
--
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
libguestfs lets you edit virtual machines. Supports shell scripting,
bindings from many languages. http://et.redhat.com/~rjones/libguestfs/
See what it can do: http://et.redhat.com/~rjones/libguestfs/recipes.html
-------------- next part --------------
# HG changeset patch
# User Ronnie Sahlberg <ronniesahlberg at gmail.com>
# Date 1276304404 -36000
# Node ID 408de18828b78fe08044b9367f6802e13bcfd1c0
# Parent a0786647b8e9e3416da81a34bc7f386393cf2476
Added window scaling support
diff -r a0786647b8e9 -r 408de18828b7 src/main.c
--- a/src/main.c Wed Jun 09 09:13:00 2010 +0000
+++ b/src/main.c Sat Jun 12 11:00:04 2010 +1000
@@ -43,6 +43,7 @@
GError *error = NULL;
int ret;
char *uri = NULL;
+ int scaling = 100;
gchar **args = NULL;
gboolean verbose = FALSE;
gboolean debug = FALSE;
@@ -63,6 +64,8 @@
N_("wait for domain to start"), NULL },
{ "reconnect", 'r', 0, G_OPTION_ARG_NONE, &reconnect,
N_("reconnect to domain upon restart"), NULL },
+ { "scaling", 's', 0, G_OPTION_ARG_INT, &scaling,
+ N_("scaling of window, in percentage"), "SCALE" },
{ "debug", '\0', 0, G_OPTION_ARG_NONE, &debug,
N_("display debugging information"), NULL },
{ G_OPTION_REMAINING, '\0', 0, G_OPTION_ARG_STRING_ARRAY, &args,
@@ -96,7 +99,12 @@
return 1;
}
- ret = viewer_start (uri, args[0], direct, waitvm, reconnect, verbose, debug, NULL);
+ if (scaling < 10 || scaling > 200) {
+ fprintf(stderr, "Scaling factor must be within 10-200\n");
+ return 1;
+ }
+
+ ret = viewer_start (uri, args[0], scaling, direct, waitvm, reconnect, verbose, debug, NULL);
if (ret != 0)
return ret;
diff -r a0786647b8e9 -r 408de18828b7 src/viewer.c
--- a/src/viewer.c Wed Jun 09 09:13:00 2010 +0000
+++ b/src/viewer.c Sat Jun 12 11:00:04 2010 +1000
@@ -53,6 +53,8 @@
#include "events.h"
#include "auth.h"
+#define SCALE(x) do { x = viewer->fullscreen ? x : x * viewer->scaling / 100; } while(0)
+
gboolean doDebug = FALSE;
enum menuNums {
@@ -108,6 +110,8 @@
GtkWidget *container;
GtkWidget *vnc;
+ int scaling;
+
int desktopWidth;
int desktopHeight;
gboolean autoResize;
@@ -265,11 +269,12 @@
dy = (alloc->height - height) / 2;
}
- DEBUG_LOG("Align widget=%p is %dx%d, desktop is %dx%d, setting VNC to %dx%d",
+ DEBUG_LOG("Align widget=%p is %dx%d, desktop is %dx%d, setting VNC to %dx%d (scaling %d%%)",
widget,
alloc->width, alloc->height,
viewer->desktopWidth, viewer->desktopHeight,
- width, height);
+ width, height,
+ viewer->scaling);
child.x = alloc->x + dx;
child.y = alloc->y + dy;
@@ -342,6 +347,9 @@
height = viewer->desktopHeight;
}
+ SCALE(width);
+ SCALE(height);
+
viewer_set_widget_size(viewer,
glade_xml_get_widget(viewer->glade, "vnc-align"),
width,
@@ -513,6 +521,42 @@
}
}
+static void viewer_menu_view_zoom25(GtkWidget *menu, VirtViewer *viewer)
+{
+ if (!viewer->window)
+ return;
+
+ viewer->scaling = 25;
+ viewer_resize_main_window(viewer);
+}
+
+static void viewer_menu_view_zoom50(GtkWidget *menu, VirtViewer *viewer)
+{
+ if (!viewer->window)
+ return;
+
+ viewer->scaling = 50;
+ viewer_resize_main_window(viewer);
+}
+
+static void viewer_menu_view_zoom75(GtkWidget *menu, VirtViewer *viewer)
+{
+ if (!viewer->window)
+ return;
+
+ viewer->scaling = 75;
+ viewer_resize_main_window(viewer);
+}
+
+static void viewer_menu_view_zoom100(GtkWidget *menu, VirtViewer *viewer)
+{
+ if (!viewer->window)
+ return;
+
+ viewer->scaling = 100;
+ viewer_resize_main_window(viewer);
+}
+
static void viewer_menu_view_resize(GtkWidget *menu, VirtViewer *viewer)
{
if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(menu))) {
@@ -1166,6 +1210,7 @@
int
viewer_start (const char *uri,
const char *name,
+ gint scaling,
gboolean direct,
gboolean waitvm,
gboolean reconnect,
@@ -1198,6 +1243,7 @@
viewer->verbose = verbose;
viewer->domkey = g_strdup(name);
viewer->uri = g_strdup(uri);
+ viewer->scaling = scaling;
g_value_init(&viewer->accelSetting, G_TYPE_STRING);
@@ -1229,6 +1275,14 @@
G_CALLBACK(viewer_menu_file_screenshot), viewer);
glade_xml_signal_connect_data(viewer->glade, "viewer_menu_view_fullscreen",
G_CALLBACK(viewer_menu_view_fullscreen), viewer);
+ glade_xml_signal_connect_data(viewer->glade, "viewer_menu_view_zoom25",
+ G_CALLBACK(viewer_menu_view_zoom25), viewer);
+ glade_xml_signal_connect_data(viewer->glade, "viewer_menu_view_zoom50",
+ G_CALLBACK(viewer_menu_view_zoom50), viewer);
+ glade_xml_signal_connect_data(viewer->glade, "viewer_menu_view_zoom75",
+ G_CALLBACK(viewer_menu_view_zoom75), viewer);
+ glade_xml_signal_connect_data(viewer->glade, "viewer_menu_view_zoom100",
+ G_CALLBACK(viewer_menu_view_zoom100), viewer);
glade_xml_signal_connect_data(viewer->glade, "viewer_menu_view_resize",
G_CALLBACK(viewer_menu_view_resize), viewer);
glade_xml_signal_connect_data(viewer->glade, "viewer_menu_send",
diff -r a0786647b8e9 -r 408de18828b7 src/viewer.glade
--- a/src/viewer.glade Wed Jun 09 09:13:00 2010 +0000
+++ b/src/viewer.glade Sat Jun 12 11:00:04 2010 +1000
@@ -62,6 +62,45 @@
</widget>
</child>
<child>
+ <widget class="GtkMenuItem" id="menu-view-zoom">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">Zoom</property>
+ <child>
+ <widget class="GtkMenu" id="menu4">
+ <property name="visible">True</property>
+ <child>
+ <widget class="GtkMenuItem" id="menu-view-zoom-25">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">Zoom 25%</property>
+ <signal name="activate" handler="viewer_menu_view_zoom25"/>
+ </widget>
+ </child>
+ <child>
+ <widget class="GtkMenuItem" id="menu-view-zoom-50">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">Zoom 50%</property>
+ <signal name="activate" handler="viewer_menu_view_zoom50"/>
+ </widget>
+ </child>
+ <child>
+ <widget class="GtkMenuItem" id="menu-view-zoom-75">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">Zoom 75%</property>
+ <signal name="activate" handler="viewer_menu_view_zoom75"/>
+ </widget>
+ </child>
+ <child>
+ <widget class="GtkMenuItem" id="menu-view-zoom-100">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">Zoom 100%</property>
+ <signal name="activate" handler="viewer_menu_view_zoom100"/>
+ </widget>
+ </child>
+ </widget>
+ </child>
+ </widget>
+ </child>
+ <child>
<widget class="GtkCheckMenuItem" id="menu-view-resize">
<property name="visible">True</property>
<property name="label" translatable="yes">Automatically resize</property>
diff -r a0786647b8e9 -r 408de18828b7 src/viewer.h
--- a/src/viewer.h Wed Jun 09 09:13:00 2010 +0000
+++ b/src/viewer.h Sat Jun 12 11:00:04 2010 +1000
@@ -27,6 +27,7 @@
extern int viewer_start (const char *uri,
const char *name,
+ gint scaling,
gboolean direct,
gboolean waitvm,
gboolean reconnect,
More information about the virt-tools-list
mailing list