From 9ab9247b88be94e222add13d5bb93d34f02281d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sat, 15 Feb 2020 19:00:56 +0100 Subject: [PATCH 1/4] config: add 'pad' option, default to 2 --- config.c | 15 +++++++++++++++ config.h | 2 ++ 2 files changed, 17 insertions(+) diff --git a/config.c b/config.c index 80e0e868..1dd6652f 100644 --- a/config.c +++ b/config.c @@ -172,6 +172,19 @@ parse_section_main(const char *key, const char *value, struct config *conf, conf->height = height; } + else if (strcmp(key, "pad") == 0) { + unsigned x, y; + if (sscanf(value, "%ux%u", &x, &y) != 2) { + LOG_ERR( + "%s: %d: expected PAD_XxPAD_Y, where both are positive integers: %s", + path, lineno, value); + return false; + } + + conf->pad_x = x; + conf->pad_y = y; + } + else if (strcmp(key, "font") == 0) { char *copy = strdup(value); for (const char *font = strtok(copy, ","); font != NULL; font = strtok(NULL, ",")) { @@ -472,6 +485,8 @@ config_load(struct config *conf, const char *conf_path) .shell = get_shell(), .width = -1, .height = -1, + .pad_x = 2, + .pad_y = 2, .fonts = tll_init(), .scrollback_lines = 1000, diff --git a/config.h b/config.h index 2fb82151..90376fc0 100644 --- a/config.h +++ b/config.h @@ -12,6 +12,8 @@ struct config { char *shell; unsigned width; unsigned height; + unsigned pad_x; + unsigned pad_y; tll(char *) fonts; From b036a66c42aba0b5439e7976b117392cd42be2a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sat, 15 Feb 2020 19:01:26 +0100 Subject: [PATCH 2/4] render: resize: take padding from configuration into account --- render.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/render.c b/render.c index b78e6454..a9305752 100644 --- a/render.c +++ b/render.c @@ -1122,16 +1122,30 @@ maybe_resize(struct terminal *term, int width, int height, bool force) const int scrollback_lines = term->render.scrollback_lines; + /* Screen rows/cols before resize */ const int old_cols = term->cols; const int old_rows = term->rows; + + /* Grid rows/cols before resize */ const int old_normal_grid_rows = term->normal.num_rows; const int old_alt_grid_rows = term->alt.num_rows; - const int new_cols = term->width / term->cell_width; - const int new_rows = term->height / term->cell_height; + /* Padding */ + const int pad_x = term->width > 2 * scale * term->conf->pad_x ? scale * term->conf->pad_x : 0; + const int pad_y = term->height > 2 * scale * term->conf->pad_y ? scale * term->conf->pad_y : 0; + + /* Screen rows/cols after resize */ + const int new_cols = max((term->width - 2 * pad_x) / term->cell_width, 1); + const int new_rows = max((term->height - 2 * pad_y) / term->cell_height, 1); + + /* Grid rows/cols after resize */ const int new_normal_grid_rows = 1 << (32 - __builtin_clz(new_rows + scrollback_lines - 1)); const int new_alt_grid_rows = 1 << (32 - __builtin_clz(new_rows)); + assert(new_cols >= 1); + assert(new_rows >= 1); + + /* Margins */ term->x_margin = (term->width - new_cols * term->cell_width) / 2; term->y_margin = (term->height - new_rows * term->cell_height) / 2; From 7f211d8f03bea576de7d9ce19c3c72c0c11bed49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sat, 15 Feb 2020 19:01:54 +0100 Subject: [PATCH 3/4] footrc: add 'pad' option --- footrc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/footrc b/footrc index 966b975f..d001e644 100644 --- a/footrc +++ b/footrc @@ -1,6 +1,9 @@ +# -*- conf -*- + # font=monospace # scrollback=1000 # geometry=500x300 +# pad=2x2 # shell= (you may need to override if you need a login shell) # term=foot # workers= From faf3bdaec3fa4040d5f3d64f835f5417ff6df725 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sat, 15 Feb 2020 19:02:05 +0100 Subject: [PATCH 4/4] doc: foot.5: document new 'pad' configuration option --- doc/foot.5.scd | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/doc/foot.5.scd b/doc/foot.5.scd index a2394ea4..c11404fc 100644 --- a/doc/foot.5.scd +++ b/doc/foot.5.scd @@ -33,7 +33,12 @@ in this order: Default: _monospace_. *geometry* - Initial window width and height, on the form _WIDTHxHEIGHT_. + Initial window width and height in pixels, on the form + _WIDTHxHEIGHT_. + +*pad* + Padding between border and glyphs, in pixels, on the form + _X-PADxY-PAD_. *shell* Executable to launch. Typically a shell. Default: the user's