diff options
author | Wolfgang Müller | 2021-06-18 19:53:41 +0200 |
---|---|---|
committer | Wolfgang Müller | 2021-06-19 15:53:07 +0200 |
commit | 89f8571cbcf48b7810c7027faf26ee5cf4b968b1 (patch) | |
tree | eaf84e00488e332f52c865167290a441d27f447e /terminal.vala | |
parent | ff27c3da1266df519aa15d95cfc32ad9d0d7b5e5 (diff) | |
download | weltschmerz-89f8571cbcf48b7810c7027faf26ee5cf4b968b1.tar.gz |
Calculate base_width dynamically
weltschmerz sets window geometry hints to indicate how the terminal
window is to be sized and resized. New sizes are always kept at a
multiple of the character width and height. Effectively, this ensures
that terminal windows never have "negative space" that is not used for
any terminal output.
In order to account for padding and non-terminal widgets, one may
specify base_height and base_width. These values indicate how much space
to add in a final step, after the character width and heights have been
multiplied with the amount of columns and rows respectively. For
example, allowed window widths are always:
(char_width * N) + base_width
Currently, we always use a base_width of 2 * 2. This is to account for
the padding of 2 pixels as specified in terminal.css.
weltschmerz uses GtkScrolledWindow and overlay scrolling by default.
With overlay_scrolling enabled, the scrollbar does not take up any extra
space. The previous commit works around a problem with GtkScrolledWindow
and sets PolicyType.ALWAYS when overlay scrolling is turned off. This
means that we now also have to account for the size of that scrollbar.
Since we cannot simply query the size of the scrollbar, we have to be a
bit more creative. Use the full window width and subtract the width of
the terminal at startup (we know it is always 80 columns) to get the
amount of space taken up by "anything else". This includes VTE padding
and the scrollbar size.
Importantly, this needs only be done once and is completely agnostic to
any further changes to the terminal or font size (which affects the cell
width and height). We only assume that both the size of the scrollbar
and the amount of padding is constant, which we feel to be a reasonable
trade-off.
Diffstat (limited to 'terminal.vala')
-rw-r--r-- | terminal.vala | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/terminal.vala b/terminal.vala index 42da259..58c77e9 100644 --- a/terminal.vala +++ b/terminal.vala @@ -42,6 +42,7 @@ class Terminal : Gtk.Overlay { string hyperlink_match; uint? infobar_timeout_id; double scroll_delta; + int base_width = -1; public Terminal(string[] args, Gtk.Container parent, Gtk.Window window) { Object(parent: parent, window: window); @@ -102,9 +103,17 @@ class Terminal : Gtk.Overlay { var char_width = (int)vte.get_char_width(); var char_height = (int)vte.get_char_height(); + + if (base_width == -1) { + int window_width; + window.get_size(out window_width, null); + + base_width = window_width - (80 * char_width); + } + var geometry = Gdk.Geometry() { + base_width = base_width, // This must be kept in sync with the padding size in terminal.css - base_width = 2 * 2, base_height = 2 * 2, min_width = char_width, min_height = char_height, |