Include the "zoom" functionality to increase or decrease the font size of the terminal, and return it to its original state. I continued the work by Rostislav Lisovy. I tried to improve the provided patch a little bit: * It uses the pango functions to specify the size of the font. * Use "plus" and "minus" as the default shourtcuts for the zoom. * Include the "Normal size" functionality in order to return to the size of the preferences. * Make the hot updating of the font preference and zoom cohexist. * Included consistent gtk icons. Still remaining issues: * With multiple tabs it sometimes works correctly, sometimes the whole window changes its size a little Signed-off-by: Asier Llano diff --git a/terminal/terminal-preferences.c b/terminal/terminal-preferences.c index 0809118..b33f628 100644 --- a/terminal/terminal-preferences.c +++ b/terminal/terminal-preferences.c @@ -55,6 +55,9 @@ enum PROP_ACCEL_SHOW_TOOLBARS, PROP_ACCEL_SHOW_BORDERS, PROP_ACCEL_FULLSCREEN, + PROP_ACCEL_ZOOM_IN, + PROP_ACCEL_ZOOM_OUT, + PROP_ACCEL_ZOOM_NORMAL, PROP_ACCEL_SET_TITLE, PROP_ACCEL_RESET, PROP_ACCEL_RESET_AND_CLEAR, @@ -444,6 +447,39 @@ terminal_preferences_class_init (TerminalPreferencesClass *klass) EXO_PARAM_READWRITE)); /** + * TerminalPreferences:accel-zoom-in: + **/ + g_object_class_install_property (gobject_class, + PROP_ACCEL_ZOOM_IN, + g_param_spec_string ("accel-zoom-in", + _("Zoom in"), + "AccelZoomIn", + "plus", + EXO_PARAM_READWRITE)); + + /** + * TerminalPreferences:accel-zoom-out: + **/ + g_object_class_install_property (gobject_class, + PROP_ACCEL_ZOOM_OUT, + g_param_spec_string ("accel-zoom-out", + _("Zoom out"), + "AccelZoomOut", + "minus", + EXO_PARAM_READWRITE)); + + /** + * TerminalPreferences:accel-zoom-normal: + **/ + g_object_class_install_property (gobject_class, + PROP_ACCEL_ZOOM_NORMAL, + g_param_spec_string ("accel-zoom-normal", + _("Normal size"), + "AccelZoomNormal", + "0", + EXO_PARAM_READWRITE)); + + /** * TerminalPreferences:accel-set-title: **/ g_object_class_install_property (gobject_class, diff --git a/terminal/terminal-screen.c b/terminal/terminal-screen.c index 1aaced5..36af2b9 100644 --- a/terminal/terminal-screen.c +++ b/terminal/terminal-screen.c @@ -153,6 +153,7 @@ struct _TerminalScreen guint activity_timeout_id; time_t last_size_change; + gint zoom; }; @@ -817,18 +818,36 @@ terminal_screen_update_font (TerminalScreen *screen) if (G_LIKELY (font_name != NULL)) { + PangoFontDescription *font_desc = NULL; + font_desc = pango_font_description_from_string(font_name); vte_terminal_set_allow_bold (VTE_TERMINAL (screen->terminal), font_allow_bold); + if (screen->zoom) + { + gint font_size = pango_font_description_get_size (font_desc); + gint zoom = screen->zoom; + while (zoom > 0) { + font_size += font_size >> 3; + zoom--; + } + while (zoom < 0) { + font_size -= font_size >> 3; + zoom++; + } + pango_font_description_set_size (font_desc, font_size); + } + #if TERMINAL_HAS_ANTI_ALIAS_SETTING antialias = font_anti_alias ? VTE_ANTI_ALIAS_USE_DEFAULT : VTE_ANTI_ALIAS_FORCE_DISABLE; - vte_terminal_set_font_from_string_full (VTE_TERMINAL (screen->terminal), - font_name, antialias); + vte_terminal_set_font_full (VTE_TERMINAL (screen->terminal), + font_desc, antialias); #else - vte_terminal_set_font_from_string (VTE_TERMINAL (screen->terminal), font_name); + vte_terminal_set_font (VTE_TERMINAL (screen->terminal), font_desc); #endif + pango_font_description_free (font_desc); g_free (font_name); } } @@ -1883,3 +1902,29 @@ terminal_screen_focus (TerminalScreen *screen) gtk_widget_grab_focus (GTK_WIDGET (screen->terminal)); } + +void +terminal_screen_zoom (TerminalScreen *screen, gint change) +{ + /* Decide the new zoom */ + if (change > 0) + { + if (screen->zoom >= 7) + return; + screen->zoom++; + } + else if (change < 0) + { + if (screen->zoom <= -7) + return; + screen->zoom --; + } + else { + if (!screen->zoom) + return; + screen->zoom = 0; + } + + /* Update the font of the terminal with the new zoom */ + terminal_screen_update_font(screen); +} diff --git a/terminal/terminal-screen.h b/terminal/terminal-screen.h index 7498409..a322a72 100644 --- a/terminal/terminal-screen.h +++ b/terminal/terminal-screen.h @@ -88,6 +88,9 @@ GtkWidget *terminal_screen_get_tab_label (TerminalScreen *scree void terminal_screen_focus (TerminalScreen *screen); +void terminal_screen_zoom (TerminalScreen *screen, + gint change); + G_END_DECLS #endif /* !__TERMINAL_SCREEN_H__ */ diff --git a/terminal/terminal-shortcut-editor.c b/terminal/terminal-shortcut-editor.c index ed057f2..f45dc09 100644 --- a/terminal/terminal-shortcut-editor.c +++ b/terminal/terminal-shortcut-editor.c @@ -112,6 +112,9 @@ static const ToplevelMenu toplevel_menus[] = "accel-show-toolbars", "accel-show-borders", "accel-fullscreen", + "accel-zoom-in", + "accel-zoom-out", + "accel-zoom-normal", NULL, }, }, diff --git a/terminal/terminal-window-ui.xml b/terminal/terminal-window-ui.xml index 9709078..fb4c786 100644 --- a/terminal/terminal-window-ui.xml +++ b/terminal/terminal-window-ui.xml @@ -30,6 +30,10 @@ + + + + diff --git a/terminal/terminal-window.c b/terminal/terminal-window.c index 6294ef2..83fec68 100644 --- a/terminal/terminal-window.c +++ b/terminal/terminal-window.c @@ -166,6 +166,12 @@ static void terminal_window_action_show_borders (GtkToggleA TerminalWindow *window); static void terminal_window_action_fullscreen (GtkToggleAction *action, TerminalWindow *window); +static void terminal_window_action_zoom_in (GtkToggleAction *action, + TerminalWindow *window); +static void terminal_window_action_zoom_out (GtkToggleAction *action, + TerminalWindow *window); +static void terminal_window_action_zoom_normal (GtkToggleAction *action, + TerminalWindow *window); static void terminal_window_action_prev_tab (GtkAction *action, TerminalWindow *window); static void terminal_window_action_next_tab (GtkAction *action, @@ -231,6 +237,9 @@ static const GtkActionEntry action_entries[] = { "edit-toolbars", NULL, N_ ("_Toolbars..."), NULL, N_ ("Customize the toolbars"), G_CALLBACK (terminal_window_action_edit_toolbars), }, { "preferences", GTK_STOCK_PREFERENCES, N_ ("Pr_eferences..."), NULL, N_ ("Open the Terminal preferences dialog"), G_CALLBACK (terminal_window_action_prefs), }, { "view-menu", NULL, N_ ("_View"), NULL, NULL, NULL, }, + { "zoom-in", GTK_STOCK_ZOOM_IN, N_ ("Zoom _in"), NULL, N_ ("Increase font size"), G_CALLBACK (terminal_window_action_zoom_in), }, + { "zoom-out", GTK_STOCK_ZOOM_OUT, N_ ("Zoom _out"), NULL, N_ ("Reduce font size"), G_CALLBACK (terminal_window_action_zoom_out), }, + { "zoom-normal", GTK_STOCK_ZOOM_100, N_("_Normal size"), NULL, N_ ("Use the original font size"), G_CALLBACK (terminal_window_action_zoom_normal), }, { "terminal-menu", NULL, N_ ("_Terminal"), NULL, NULL, NULL, }, { "set-title", NULL, N_ ("_Set Title..."), NULL, N_ ("Set a custom title for the current tab"), G_CALLBACK (terminal_window_action_set_title), }, { "reset", GTK_STOCK_REFRESH, N_ ("_Reset"), NULL, N_ ("Reset"), G_CALLBACK (terminal_window_action_reset), }, @@ -1471,6 +1480,36 @@ terminal_window_action_fullscreen (GtkToggleAction *action, static void +terminal_window_action_zoom_in (GtkToggleAction *action, + TerminalWindow *window) +{ + if (G_LIKELY (window->active != NULL) ) + terminal_screen_zoom(window->active, 1); +} + + + +static void +terminal_window_action_zoom_out (GtkToggleAction *action, + TerminalWindow *window) +{ + if (G_LIKELY (window->active != NULL) ) + terminal_screen_zoom(window->active, -1); +} + + + +static void +terminal_window_action_zoom_normal (GtkToggleAction *action, + TerminalWindow *window) +{ + if (G_LIKELY (window->active != NULL) ) + terminal_screen_zoom(window->active, 0); +} + + + +static void terminal_window_action_prev_tab (GtkAction *action, TerminalWindow *window) {