Add support for zoom levels

Add a menu for zooming in/out of the virtual desktop.

Add a --zoom command line to set the initial zoom level.

Defaults to 100% zoom at startup
This commit is contained in:
Ronnie Sahlberg 2010-07-05 17:45:18 +01:00
parent 2343ff6879
commit abee3c912b
6 changed files with 101 additions and 1 deletions

View File

@ -12,6 +12,7 @@ With additional patches from:
Richard W.M. Jones <rjones-at-redhat-dot-com>
Guido G\374nther <agx-at-sigxcpu-dot-org>
Hiroyuki Kaguchi <fj7025cf-at-aa-dot-jp-dot-fujitsu-dot-com>
Ronnie Sahlberg <ronniesahlberg@gmail.com>
...send patches to get your name here...

View File

@ -47,6 +47,10 @@ Wait for the domain to start up before attempting to connect to the console
Automatically reconnect to the domain if it shuts down and restarts
=item -z, --zoom=PCT
Zoom level of the VNC window in percentage. Range 10-200.
=item -d, --direct
Do not attempt to tunnel the console over SSH, even if the main connection URI

View File

@ -43,6 +43,7 @@ int main(int argc, char **argv)
GError *error = NULL;
int ret;
char *uri = NULL;
int zoom = 100;
gchar **args = NULL;
gboolean verbose = FALSE;
gboolean debug = FALSE;
@ -63,6 +64,8 @@ int main(int argc, char **argv)
N_("wait for domain to start"), NULL },
{ "reconnect", 'r', 0, G_OPTION_ARG_NONE, &reconnect,
N_("reconnect to domain upon restart"), NULL },
{ "zoom", 'z', 0, G_OPTION_ARG_INT, &zoom,
N_("Zoom level of window, in percentage"), "ZOOM" },
{ "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 @@ int main(int argc, char **argv)
return 1;
}
ret = viewer_start (uri, args[0], direct, waitvm, reconnect, verbose, debug, NULL);
if (zoom < 10 || zoom > 200) {
fprintf(stderr, "Zoom level must be within 10-200\n");
return 1;
}
ret = viewer_start (uri, args[0], zoom, direct, waitvm, reconnect, verbose, debug, NULL);
if (ret != 0)
return ret;

View File

@ -53,6 +53,8 @@
#include "events.h"
#include "auth.h"
#define SCALE(x) do { x = viewer->fullscreen ? x : x * viewer->zoomlevel / 100; } while (0);
gboolean doDebug = FALSE;
enum menuNums {
@ -108,6 +110,8 @@ typedef struct VirtViewer {
GtkWidget *container;
GtkWidget *vnc;
int zoomlevel;
int desktopWidth;
int desktopHeight;
gboolean autoResize;
@ -342,12 +346,39 @@ viewer_resize_main_window(VirtViewer *viewer)
height = viewer->desktopHeight;
}
SCALE(width);
SCALE(height);
viewer_set_widget_size(viewer,
glade_xml_get_widget(viewer->glade, "vnc-align"),
width,
height);
}
static void viewer_menu_view_zoom_out(GtkWidget *menu, VirtViewer *viewer)
{
viewer->zoomlevel -= 10;
if (viewer->zoomlevel < 10)
viewer->zoomlevel = 10;
viewer_resize_main_window(viewer);
}
static void viewer_menu_view_zoom_in(GtkWidget *menu, VirtViewer *viewer)
{
viewer->zoomlevel += 10;
if (viewer->zoomlevel > 200)
viewer->zoomlevel = 200;
viewer_resize_main_window(viewer);
}
static void viewer_menu_view_zoom_reset(GtkWidget *menu, VirtViewer *viewer)
{
viewer->zoomlevel = 100;
viewer_resize_main_window(viewer);
}
/*
* Called when VNC desktop size changes.
@ -1166,6 +1197,7 @@ static void viewer_error_func (void *data G_GNUC_UNUSED, virErrorPtr error G_GNU
int
viewer_start (const char *uri,
const char *name,
gint zoom,
gboolean direct,
gboolean waitvm,
gboolean reconnect,
@ -1198,6 +1230,7 @@ viewer_start (const char *uri,
viewer->verbose = verbose;
viewer->domkey = g_strdup(name);
viewer->uri = g_strdup(uri);
viewer->zoomlevel = zoom;
g_value_init(&viewer->accelSetting, G_TYPE_STRING);
@ -1229,6 +1262,12 @@ viewer_start (const char *uri,
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_zoom_in",
G_CALLBACK(viewer_menu_view_zoom_in), viewer);
glade_xml_signal_connect_data(viewer->glade, "viewer_menu_view_zoom_out",
G_CALLBACK(viewer_menu_view_zoom_out), viewer);
glade_xml_signal_connect_data(viewer->glade, "viewer_menu_view_zoom_reset",
G_CALLBACK(viewer_menu_view_zoom_reset), 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",

View File

@ -61,6 +61,53 @@
<signal name="toggled" handler="viewer_menu_view_fullscreen"/>
</widget>
</child>
<child>
<widget class="GtkMenuItem" id="menu-view-zoom">
<property name="visible">True</property>
<property name="label" translatable="yes">_Zoom</property>
<property name="use_underline">True</property>
<child>
<widget class="GtkMenu" id="menu4">
<property name="visible">True</property>
<child>
<widget class="GtkMenuItem" id="menu-view-zoom-in">
<property name="visible">True</property>
<property name="label">gtk-zoom-in</property>
<property name="use_stock">True</property>
<property name="tooltip" translatable="no">Zoom in on virtual machine</property>
<signal name="activate" handler="viewer_menu_view_zoom_in"/>
<accelerator key="plus" signal="activate" modifiers="GDK_CONTROL_MASK"/>
</widget>
</child>
<child>
<widget class="GtkMenuItem" id="menu-view-zoom-out">
<property name="visible">True</property>
<property name="label">gtk-zoom-out</property>
<property name="use_stock">True</property>
<property name="tooltip" translatable="no">Zoom out from virtual machine</property>
<signal name="activate" handler="viewer_menu_view_zoom_out"/>
<accelerator key="minus" signal="activate" modifiers="GDK_CONTROL_MASK"/>
</widget>
</child>
<child>
<widget class="GtkSeparatorMenuItem" id="separatormenuitem4">
<property name="visible">True</property>
</widget>
</child>
<child>
<widget class="GtkMenuItem" id="menu-view-zoom-reset">
<property name="visible">True</property>
<property name="label">gtk-zoom-100</property>
<property name="use_stock">True</property>
<property name="tooltip" translatable="no">Reset zoom to normal</property>
<signal name="activate" handler="viewer_menu_view_zoom_reset"/>
<accelerator key="0" signal="activate" modifiers="GDK_CONTROL_MASK"/>
</widget>
</child>
</widget>
</child>
</widget>
</child>
<child>
<widget class="GtkCheckMenuItem" id="menu-view-resize">
<property name="visible">True</property>

View File

@ -27,6 +27,7 @@
extern int viewer_start (const char *uri,
const char *name,
gint zoom,
gboolean direct,
gboolean waitvm,
gboolean reconnect,