[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [virt-tools-list] [PATCH 1/1] virt-viewer : add support for window scaling



Thanks for your suggestion.

I have refactored the patch to use the stock items for In/Out/Normal.

I also changed the command line argument to --zoom.


regards
ronnie sahlberg


On Wed, Jun 16, 2010 at 10:15 PM, Daniel P. Berrange
<berrange redhat com> wrote:
> 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.
>
> This looks fine.
>
>> There is also a new Zoom submenu, where scaling of 25%, 50%, 75% and
>> 100% can be adjusted at runtime.
>
> I think the menu would be more flexible if it worked like the firefox
> menu for zooming eg
>
>   View
>   ----
>   Zoom -> Zoom In (Ctrl + +)
>           Zoom Out (Ctrl + -)
>           ------------------
>           Normal (Ctrl + 0)
>           Best fit
>
> The nice bit is that GTK has stock icons defined for the Zoom In,
> Zoom Out, Normal and Best Fit that are standardized across apps.
>
>
>> 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.
>
> Thanks for the proposal.  Your code looks good - if you can change the
> menu structure I'd be happy to merge it.
>
> Regards,
> Daniel
> --
> |: Red Hat, Engineering, London    -o-   http://people.redhat.com/berrange/ :|
> |: http://libvirt.org -o- http://virt-manager.org -o- http://deltacloud.org :|
> |: http://autobuild.org        -o-         http://search.cpan.org/~danberr/ :|
> |: GnuPG: 7D3B9505  -o-   F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|
>
# HG changeset patch
# User Ronnie Sahlberg <ronniesahlberg gmail com>
# Date 1278146424 -36000
# Node ID d960350974bf9305b6cf6915bb4752b3894f46ed
# Parent  10cd88edd331c002ed83ed0b1c7858cbdfa613bd
Add a zoom menu to zoom in/out the vnc widget

diff -r 10cd88edd331 -r d960350974bf man/virt-viewer.pod
--- a/man/virt-viewer.pod	Sun Jun 27 11:35:03 2010 +0000
+++ b/man/virt-viewer.pod	Sat Jul 03 18:40:24 2010 +1000
@@ -47,6 +47,10 @@
 
 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
diff -r 10cd88edd331 -r d960350974bf src/main.c
--- a/src/main.c	Sun Jun 27 11:35:03 2010 +0000
+++ b/src/main.c	Sat Jul 03 18:40:24 2010 +1000
@@ -43,6 +43,7 @@
 	GError *error = NULL;
 	int ret;
 	char *uri = NULL;
+	int zoom = 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 },
+		{ "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 @@
 		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;
 
diff -r 10cd88edd331 -r d960350974bf src/viewer.c
--- a/src/viewer.c	Sun Jun 27 11:35:03 2010 +0000
+++ b/src/viewer.c	Sat Jul 03 18:40:24 2010 +1000
@@ -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 @@
 	GtkWidget *container;
 	GtkWidget *vnc;
 
+	int zoomlevel;
+
 	int desktopWidth;
 	int desktopHeight;
 	gboolean autoResize;
@@ -342,12 +346,39 @@
 		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 @@
 int
 viewer_start (const char *uri,
 	      const char *name,
+	      gint zoom,
 	      gboolean direct,
 	      gboolean waitvm,
 	      gboolean reconnect,
@@ -1198,6 +1230,7 @@
 	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 @@
 				      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",
diff -r 10cd88edd331 -r d960350974bf src/viewer.glade
--- a/src/viewer.glade	Sun Jun 27 11:35:03 2010 +0000
+++ b/src/viewer.glade	Sat Jul 03 18:40:24 2010 +1000
@@ -62,6 +62,53 @@
                       </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>
                         <property name="label" translatable="yes">Automatically resize</property>
diff -r 10cd88edd331 -r d960350974bf src/viewer.h
--- a/src/viewer.h	Sun Jun 27 11:35:03 2010 +0000
+++ b/src/viewer.h	Sat Jul 03 18:40:24 2010 +1000
@@ -27,6 +27,7 @@
 
 extern int viewer_start (const char *uri,
 			 const char *name,
+			 gint zoom,
 			 gboolean direct,
 			 gboolean waitvm,
 			 gboolean reconnect,

Attachment: zoom.diff.gz
Description: GNU Zip compressed data


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]