[gnome-terminal] screen: Use VteTerminal:font-scale to implement zoom



commit dfd92cbd6df03b31e3040934f39c38a4214248e4
Author: Christian Persch <chpe gnome org>
Date:   Sun Apr 6 16:13:36 2014 +0200

    screen: Use VteTerminal:font-scale to implement zoom
    
    Much easier than manipulating the font description.
    
    Requires vte commit 2067d8a6baf72e8b16cec2dbca989f7b60c421b1.

 src/terminal-screen.c |   52 +++++++++---------------------------------------
 src/terminal-screen.h |    5 ----
 src/terminal-window.c |   20 ++++++++++--------
 3 files changed, 21 insertions(+), 56 deletions(-)
---
diff --git a/src/terminal-screen.c b/src/terminal-screen.c
index c046721..dead0c0 100644
--- a/src/terminal-screen.c
+++ b/src/terminal-screen.c
@@ -83,7 +83,6 @@ struct _TerminalScreenPrivate
   char **override_command;
   gboolean shell;
   int child_pid;
-  double font_scale;
   GSList *match_tags;
   guint launch_child_source_id;
 };
@@ -127,6 +126,7 @@ static void terminal_screen_drag_data_received (GtkWidget        *widget,
                                                 GtkSelectionData *selection_data,
                                                 guint             info,
                                                 guint             time);
+static void terminal_screen_set_font (TerminalScreen *screen);
 static void terminal_screen_system_font_changed_cb (GSettings *,
                                                     const char*,
                                                     TerminalScreen *screen);
@@ -315,8 +315,6 @@ terminal_screen_init (TerminalScreen *screen)
 
   priv->child_pid = -1;
 
-  priv->font_scale = PANGO_SCALE_MEDIUM;
-
   for (i = 0; i < n_url_regexes; ++i)
     {
       TagData *tag_data;
@@ -658,7 +656,7 @@ terminal_screen_new (GSettings       *profile,
   if (child_env)
     terminal_screen_set_initial_environment (screen, child_env);
 
-  terminal_screen_set_font_scale (screen, zoom);
+  vte_terminal_set_font_scale (VTE_TERMINAL (screen), zoom);
   terminal_screen_set_font (screen);
 
   return screen;
@@ -886,7 +884,7 @@ update_color_scheme (TerminalScreen *screen)
   vte_terminal_set_color_bold_rgba (VTE_TERMINAL (screen), boldp);
 }
 
-void
+static void
 terminal_screen_set_font (TerminalScreen *screen)
 {
   TerminalScreenPrivate *priv = screen->priv;
@@ -906,13 +904,13 @@ terminal_screen_set_font (TerminalScreen *screen)
     }
 
   size = pango_font_description_get_size (desc);
-  if (size == 0)
-    size = 10;
-
-  if (pango_font_description_get_size_is_absolute (desc))
-    pango_font_description_set_absolute_size (desc, priv->font_scale * size);
-  else
-    pango_font_description_set_size (desc, priv->font_scale * size);
+  /* Sanity check */
+  if (size == 0) {
+    if (pango_font_description_get_size_is_absolute (desc))
+      pango_font_description_set_absolute_size (desc, 10);
+    else
+      pango_font_description_set_size (desc, 10);
+  }
 
   vte_terminal_set_font (VTE_TERMINAL (screen), desc);
 
@@ -1619,36 +1617,6 @@ terminal_screen_get_current_dir (TerminalScreen *screen)
   return NULL;
 }
 
-void
-terminal_screen_set_font_scale (TerminalScreen *screen,
-                                double          factor)
-{
-  TerminalScreenPrivate *priv = screen->priv;
-  
-  g_return_if_fail (TERMINAL_IS_SCREEN (screen));
-
-  if (factor < TERMINAL_SCALE_MINIMUM)
-    factor = TERMINAL_SCALE_MINIMUM;
-  if (factor > TERMINAL_SCALE_MAXIMUM)
-    factor = TERMINAL_SCALE_MAXIMUM;
-  
-  priv->font_scale = factor;
-  
-  if (gtk_widget_get_realized (GTK_WIDGET (screen)))
-    {
-      /* Update the font */
-      terminal_screen_set_font (screen);
-    }
-}
-
-double
-terminal_screen_get_font_scale (TerminalScreen *screen)
-{
-  g_return_val_if_fail (TERMINAL_IS_SCREEN (screen), 1.0);
-  
-  return screen->priv->font_scale;
-}
-
 static void
 terminal_screen_window_title_changed (VteTerminal *vte_terminal,
                                       TerminalScreen *screen)
diff --git a/src/terminal-screen.h b/src/terminal-screen.h
index 5c8207c..d0341c8 100644
--- a/src/terminal-screen.h
+++ b/src/terminal-screen.h
@@ -113,11 +113,6 @@ void terminal_screen_set_user_title (TerminalScreen *screen,
 
 char *terminal_screen_get_current_dir (TerminalScreen *screen);
 
-void        terminal_screen_set_font (TerminalScreen *screen);
-void        terminal_screen_set_font_scale    (TerminalScreen *screen,
-                                               double          factor);
-double      terminal_screen_get_font_scale    (TerminalScreen *screen);
-
 void       terminal_screen_get_size (TerminalScreen *screen,
                                      int *width_chars,
                                      int *height_chars);
diff --git a/src/terminal-window.c b/src/terminal-window.c
index ce7abb9..61fb82b 100644
--- a/src/terminal-window.c
+++ b/src/terminal-window.c
@@ -819,17 +819,17 @@ action_zoom_cb (GSimpleAction *action,
   if (value == 0) {
     zoom = PANGO_SCALE_MEDIUM;
   } else if (value == 1) {
-    zoom = terminal_screen_get_font_scale (priv->active_screen);
+    zoom = vte_terminal_get_font_scale (VTE_TERMINAL (priv->active_screen));
     if (!find_larger_zoom_factor (zoom, &zoom))
       return;
   } else if (value == -1) {
-    zoom = terminal_screen_get_font_scale (priv->active_screen);
+    zoom = vte_terminal_get_font_scale (VTE_TERMINAL (priv->active_screen));
     if (!find_smaller_zoom_factor (zoom, &zoom))
       return;
   } else
     g_assert_not_reached ();
 
-  terminal_screen_set_font_scale (priv->active_screen, zoom);
+  vte_terminal_set_font_scale (VTE_TERMINAL (priv->active_screen), zoom);
   terminal_window_update_zoom_sensitivity (window);
 }
 
@@ -1777,7 +1777,7 @@ terminal_window_update_zoom_sensitivity (TerminalWindow *window)
   if (screen == NULL)
     return;
 
-  current = terminal_screen_get_font_scale (screen);
+  current = vte_terminal_get_font_scale (VTE_TERMINAL (screen));
 
   action = gtk_action_group_get_action (priv->action_group, "ViewZoomOut");
   gtk_action_set_sensitive (action, find_smaller_zoom_factor (current, &zoom));
@@ -3032,9 +3032,9 @@ sync_screen_icon_title_set (TerminalScreen *screen,
 }
 
 static void
-screen_font_desc_changed_cb (TerminalScreen *screen,
-                             GParamSpec *psepc,
-                             TerminalWindow *window)
+screen_font_any_changed_cb (TerminalScreen *screen,
+                            GParamSpec *psepc,
+                            TerminalWindow *window)
 {
   TerminalWindowPrivate *priv = window->priv;
 
@@ -3362,7 +3362,9 @@ mdi_screen_added_cb (TerminalMdiContainer *container,
   g_signal_connect (screen, "notify::icon-title-set",
                     G_CALLBACK (sync_screen_icon_title_set), window);
   g_signal_connect (screen, "notify::font-desc",
-                    G_CALLBACK (screen_font_desc_changed_cb), window);
+                    G_CALLBACK (screen_font_any_changed_cb), window);
+  g_signal_connect (screen, "notify::font-scale",
+                    G_CALLBACK (screen_font_any_changed_cb), window);
   g_signal_connect (screen, "selection-changed",
                     G_CALLBACK (terminal_window_update_copy_sensitivity), window);
 
@@ -3435,7 +3437,7 @@ mdi_screen_removed_cb (TerminalMdiContainer *container,
                                         window);
 
   g_signal_handlers_disconnect_by_func (G_OBJECT (screen),
-                                        G_CALLBACK (screen_font_desc_changed_cb),
+                                        G_CALLBACK (screen_font_any_changed_cb),
                                         window);
 
   g_signal_handlers_disconnect_by_func (G_OBJECT (screen),


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