diff options
author | Wolfgang Müller | 2019-08-06 16:22:51 +0200 |
---|---|---|
committer | Wolfgang Müller | 2019-08-31 18:06:46 +0200 |
commit | bfd2e398c1ec6bafab52a38e3ce24fa0658205c0 (patch) | |
tree | a5e6eedfbb5c7b1d38cb3f00b059f6511ad5da46 /terminal.vala | |
parent | 7b06beba65e08a706964ff9b9dea43f4261f13fd (diff) | |
download | weltschmerz-bfd2e398c1ec6bafab52a38e3ce24fa0658205c0.tar.gz |
Add support for adjusting the font scale at runtime
Diffstat (limited to 'terminal.vala')
-rw-r--r-- | terminal.vala | 65 |
1 files changed, 63 insertions, 2 deletions
diff --git a/terminal.vala b/terminal.vala index d0f9480..c6c2525 100644 --- a/terminal.vala +++ b/terminal.vala @@ -9,6 +9,15 @@ class Terminal : Gtk.Overlay { const uint PCRE2_JIT_PARTIAL_SOFT = 0x00000002u; const uint PCRE2_ERROR_JIT_BADOPTION = -45; + /* The following values were chosen to be powers of 1.2 that lie within the + * range of VTE's bounds for the font scale: [0.25, 4]. + * + * They allow for 7 steps above or below the default scale of 1. + */ + const double FONT_SCALE_MIN = 0.2790816472336535; // 1.2 ^ -7 + const double FONT_SCALE_MAX = 3.583180799999999; // 1.2 ^ 7 + const double FONT_SCALE_FACTOR = 1.2; + struct PaletteEntry { string name; string normal; @@ -42,6 +51,7 @@ class Terminal : Gtk.Overlay { bool has_search; string url_match; uint? infobar_timeout_id; + double scroll_delta; public Terminal(string[] args, Gtk.Container parent, Gtk.Window window) { Object(parent: parent, window: window); @@ -135,12 +145,16 @@ class Terminal : Gtk.Overlay { } } + bool match_modifiers(int state, Gdk.ModifierType modifiers) { + return (state & modifiers) == modifiers; + } + bool match_button(Gdk.EventButton event, Gdk.ModifierType modifiers, uint button) { - return (event.state & modifiers) == modifiers && event.button == button; + return match_modifiers(event.state, modifiers) && event.button == button; } bool match_key(Gdk.EventKey event, Gdk.ModifierType modifiers, uint key) { - return (event.state & modifiers) == modifiers && event.keyval == key; + return match_modifiers(event.state, modifiers) && event.keyval == key; } void infobar_show(string message, Gtk.MessageType level, uint? timeout = null) { @@ -300,6 +314,18 @@ class Terminal : Gtk.Overlay { clipboard.set_text(url_match, -1); } + void adjust_font_scale(double scale) { + vte.set_font_scale(scale.clamp(FONT_SCALE_MIN, FONT_SCALE_MAX)); + } + + void increase_font_scale() { + adjust_font_scale(vte.get_font_scale() * FONT_SCALE_FACTOR); + } + + void decrease_font_scale() { + adjust_font_scale(vte.get_font_scale() / FONT_SCALE_FACTOR); + } + [GtkCallback] void vte_copy() { if (vte.get_has_selection()) { @@ -366,6 +392,41 @@ class Terminal : Gtk.Overlay { return true; } + if (match_key(event, CONTROL_MASK, Gdk.Key.@0)) { + vte.set_font_scale(1.0); + return true; + } + + if (match_key(event, CONTROL_MASK, Gdk.Key.equal)) { + increase_font_scale(); + return true; + } + + if (match_key(event, CONTROL_MASK, Gdk.Key.minus)) { + decrease_font_scale(); + return true; + } + + return false; + } + + [GtkCallback] + bool vte_scroll(Gdk.EventScroll event) { + if (match_modifiers(event.state, CONTROL_MASK)) { + scroll_delta += event.delta_y; + + if (Math.fabs(scroll_delta) >= 1) { + if (scroll_delta < 0) { + increase_font_scale(); + } else { + decrease_font_scale(); + } + scroll_delta = 0; + } + + return true; + } + return false; } |