[virt-tools-list] [PATCH virt-viewer 1/4] Use ZOOM constants instead of numbers

Pavel Grunt pgrunt at redhat.com
Mon Mar 30 20:17:35 UTC 2015


---
 src/virt-viewer-app.c     |  4 ++--
 src/virt-viewer-display.c | 16 ++++++++--------
 src/virt-viewer-window.c  | 26 +++++++++++++-------------
 src/virt-viewer-window.h  |  2 ++
 4 files changed, 25 insertions(+), 23 deletions(-)

diff --git a/src/virt-viewer-app.c b/src/virt-viewer-app.c
index e6a2ec0..aef0778 100644
--- a/src/virt-viewer-app.c
+++ b/src/virt-viewer-app.c
@@ -1723,7 +1723,7 @@ gboolean virt_viewer_app_start(VirtViewerApp *self, GError **error)
     return self->priv->started;
 }
 
-static int opt_zoom = 100;
+static int opt_zoom = NORMAL_ZOOM_LEVEL;
 static gchar *opt_hotkeys = NULL;
 static gboolean opt_verbose = FALSE;
 static gboolean opt_debug = FALSE;
@@ -1764,7 +1764,7 @@ virt_viewer_app_init(VirtViewerApp *self)
 
     if (opt_zoom < MIN_ZOOM_LEVEL || opt_zoom > MAX_ZOOM_LEVEL) {
         g_printerr(_("Zoom level must be within %d-%d\n"), MIN_ZOOM_LEVEL, MAX_ZOOM_LEVEL);
-        opt_zoom = 100;
+        opt_zoom = NORMAL_ZOOM_LEVEL;
     }
 
     self->priv->initial_display_map = virt_viewer_app_get_monitor_mapping_for_section(self, "fallback");
diff --git a/src/virt-viewer-display.c b/src/virt-viewer-display.c
index 66429f1..50245cb 100644
--- a/src/virt-viewer-display.c
+++ b/src/virt-viewer-display.c
@@ -144,7 +144,7 @@ virt_viewer_display_class_init(VirtViewerDisplayClass *class)
                                                      "Zoom level",
                                                      MIN_ZOOM_LEVEL,
                                                      MAX_ZOOM_LEVEL,
-                                                     100,
+                                                     NORMAL_ZOOM_LEVEL,
                                                      G_PARAM_READWRITE));
 
     g_object_class_install_property(object_class,
@@ -276,7 +276,7 @@ virt_viewer_display_init(VirtViewerDisplay *display)
 
     display->priv->desktopWidth = 100;
     display->priv->desktopHeight = 100;
-    display->priv->zoom_level = 100;
+    display->priv->zoom_level = NORMAL_ZOOM_LEVEL;
     display->priv->zoom = TRUE;
 #if !GTK_CHECK_VERSION(3, 0, 0)
     display->priv->dirty = TRUE;
@@ -393,8 +393,8 @@ void virt_viewer_display_get_preferred_size(VirtViewerDisplay *self,
     requisition->height = border_width * 2;
 
     if (priv->zoom) {
-        requisition->width += round(priv->desktopWidth * priv->zoom_level / 100.0);
-        requisition->height += round(priv->desktopHeight * priv->zoom_level / 100.0);
+        requisition->width += round(priv->desktopWidth * priv->zoom_level / (double) NORMAL_ZOOM_LEVEL);
+        requisition->height += round(priv->desktopHeight * priv->zoom_level / (double) NORMAL_ZOOM_LEVEL);
     } else {
         requisition->width += priv->desktopWidth;
         requisition->height += priv->desktopHeight;
@@ -463,7 +463,7 @@ static void virt_viewer_display_get_preferred_width(GtkWidget *widget,
     *minwidth = 50 + 2 * border_width;
 
     if (priv->zoom) {
-        *defwidth = round(priv->desktopWidth * priv->zoom_level / 100.0) +
+        *defwidth = round(priv->desktopWidth * priv->zoom_level / (double) NORMAL_ZOOM_LEVEL) +
                     2 * border_width;
     } else {
         *defwidth = priv->desktopWidth + 2 * border_width;
@@ -482,7 +482,7 @@ static void virt_viewer_display_get_preferred_height(GtkWidget *widget,
     *minheight = 50 + 2 * border_height;
 
     if (priv->zoom) {
-        *defheight = round(priv->desktopHeight * priv->zoom_level / 100.0) +
+        *defheight = round(priv->desktopHeight * priv->zoom_level / (double) NORMAL_ZOOM_LEVEL) +
                     2 * border_height;
     } else {
         *defheight = priv->desktopHeight + 2 * border_height;
@@ -817,8 +817,8 @@ void virt_viewer_display_get_preferred_monitor_geometry(VirtViewerDisplay* self,
         if (virt_viewer_display_get_zoom(VIRT_VIEWER_DISPLAY(self))) {
             guint zoom = virt_viewer_display_get_zoom_level(VIRT_VIEWER_DISPLAY(self));
 
-            preferred->width = round(preferred->width * 100 / zoom);
-            preferred->height = round(preferred->height * 100 / zoom);
+            preferred->width = round(preferred->width * NORMAL_ZOOM_LEVEL / zoom);
+            preferred->height = round(preferred->height * NORMAL_ZOOM_LEVEL / zoom);
         }
     }
 }
diff --git a/src/virt-viewer-window.c b/src/virt-viewer-window.c
index d668f74..67fd814 100644
--- a/src/virt-viewer-window.c
+++ b/src/virt-viewer-window.c
@@ -347,7 +347,7 @@ virt_viewer_window_init (VirtViewerWindow *self)
         g_object_ref(G_OBJECT(accels->data));
     }
 
-    priv->zoomlevel = 100;
+    priv->zoomlevel = NORMAL_ZOOM_LEVEL;
 }
 
 static void
@@ -366,21 +366,21 @@ G_MODULE_EXPORT void
 virt_viewer_window_menu_view_zoom_out(GtkWidget *menu G_GNUC_UNUSED,
                                       VirtViewerWindow *self)
 {
-    virt_viewer_window_set_zoom_level(self, self->priv->zoomlevel - 10);
+    virt_viewer_window_set_zoom_level(self, self->priv->zoomlevel - ZOOM_STEP);
 }
 
 G_MODULE_EXPORT void
 virt_viewer_window_menu_view_zoom_in(GtkWidget *menu G_GNUC_UNUSED,
                                      VirtViewerWindow *self)
 {
-    virt_viewer_window_set_zoom_level(self, self->priv->zoomlevel + 10);
+    virt_viewer_window_set_zoom_level(self, self->priv->zoomlevel + ZOOM_STEP);
 }
 
 G_MODULE_EXPORT void
 virt_viewer_window_menu_view_zoom_reset(GtkWidget *menu G_GNUC_UNUSED,
                                         VirtViewerWindow *self)
 {
-    virt_viewer_window_set_zoom_level(self, 100);
+    virt_viewer_window_set_zoom_level(self, NORMAL_ZOOM_LEVEL);
 }
 
 /* Kick GtkWindow to tell it to adjust to our new widget sizes */
@@ -441,8 +441,8 @@ virt_viewer_window_resize(VirtViewerWindow *self, gboolean keep_win_size)
     desktopAspect = (double)desktopWidth / (double)desktopHeight;
     screenAspect = (double)fullscreen.width / (double)fullscreen.height;
 
-    display_width = desktopWidth * priv->zoomlevel / 100.0;
-    display_height = desktopHeight * priv->zoomlevel / 100.0;
+    display_width = desktopWidth * priv->zoomlevel / (double) NORMAL_ZOOM_LEVEL;
+    display_height = desktopHeight * priv->zoomlevel / (double) NORMAL_ZOOM_LEVEL;
 
     if ((display_width > fullscreen.width) ||
         (display_height > fullscreen.height)) {
@@ -455,8 +455,8 @@ virt_viewer_window_resize(VirtViewerWindow *self, gboolean keep_win_size)
             width = fullscreen.width;
             height = fullscreen.width / desktopAspect;
         }
-        width *= 100.0 / priv->zoomlevel;
-        height *= 100.0 / priv->zoomlevel;
+        width *= (double) NORMAL_ZOOM_LEVEL / priv->zoomlevel;
+        height *= (double) NORMAL_ZOOM_LEVEL / priv->zoomlevel;
     } else {
         width = desktopWidth;
         height = desktopHeight;
@@ -1406,10 +1406,10 @@ virt_viewer_window_set_zoom_level(VirtViewerWindow *self, gint zoom_level)
     g_return_if_fail(VIRT_VIEWER_IS_WINDOW(self));
     priv = self->priv;
 
-    if (zoom_level < 10)
-        zoom_level = 10;
-    if (zoom_level > 400)
-        zoom_level = 400;
+    if (zoom_level < MIN_ZOOM_LEVEL)
+        zoom_level = MIN_ZOOM_LEVEL;
+    if (zoom_level > MAX_ZOOM_LEVEL)
+        zoom_level = MAX_ZOOM_LEVEL;
     priv->zoomlevel = zoom_level;
 
     if (!priv->display)
@@ -1422,7 +1422,7 @@ virt_viewer_window_set_zoom_level(VirtViewerWindow *self, gint zoom_level)
 
 gint virt_viewer_window_get_zoom_level(VirtViewerWindow *self)
 {
-    g_return_val_if_fail(VIRT_VIEWER_IS_WINDOW(self), 100);
+    g_return_val_if_fail(VIRT_VIEWER_IS_WINDOW(self), NORMAL_ZOOM_LEVEL);
     return self->priv->zoomlevel;
 }
 
diff --git a/src/virt-viewer-window.h b/src/virt-viewer-window.h
index 4639708..8a4322b 100644
--- a/src/virt-viewer-window.h
+++ b/src/virt-viewer-window.h
@@ -32,6 +32,8 @@ G_BEGIN_DECLS
 
 #define MIN_ZOOM_LEVEL 10
 #define MAX_ZOOM_LEVEL 400
+#define NORMAL_ZOOM_LEVEL 100
+#define ZOOM_STEP 10
 
 #define VIRT_VIEWER_TYPE_WINDOW virt_viewer_window_get_type()
 
-- 
2.3.4




More information about the virt-tools-list mailing list