aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md4
-rw-r--r--config.c28
-rw-r--r--config.h10
-rw-r--r--doc/foot.ini.5.scd27
-rw-r--r--foot.ini2
-rw-r--r--render.c9
6 files changed, 60 insertions, 20 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 66fa7c93..9ade3b6f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -91,9 +91,13 @@
buffers. They provide the necessary color precision required by
`gamma-correct-blending=yes`.
* New cursor shapes, from `cursor-shape-v1` version 2.
+* `center-when-fullscreen` and `center-when-maximized-and-fullscreen`
+ to the `pad` option. This allows you to configure when the grid is
+ centered in more detail ([#2111][2111]).
[2025]: https://codeberg.org/dnkl/foot/issues/2025
[1975]: https://codeberg.org/dnkl/foot/issues/1975
+[2111]: https://codeberg.org/dnkl/foot/issues/2111
### Changed
diff --git a/config.c b/config.c
index 07f781d6..d8f1c0ed 100644
--- a/config.c
+++ b/config.c
@@ -933,21 +933,34 @@ parse_section_main(struct context *ctx)
else if (streq(key, "pad")) {
unsigned x, y;
- char mode[16] = {0};
+ char mode[64] = {0};
+ int ret = sscanf(value, "%ux%u %63s", &x, &y, mode);
- int ret = sscanf(value, "%ux%u %15s", &x, &y, mode);
- bool center = strcasecmp(mode, "center") == 0;
- bool invalid_mode = !center && mode[0] != '\0';
+ enum center_when center = CENTER_NEVER;
- if ((ret != 2 && ret != 3) || invalid_mode) {
+ if (ret == 3) {
+ if (strcasecmp(mode, "center") == 0)
+ center = CENTER_ALWAYS;
+ else if (strcasecmp(mode, "center-when-fullscreen") == 0)
+ center = CENTER_FULLSCREEN;
+ else if (strcasecmp(mode, "center-when-maximized-and-fullscreen") == 0)
+ center = CENTER_MAXIMIZED_AND_FULLSCREEN;
+ else
+ center = CENTER_INVALID;
+ }
+
+ if ((ret != 2 && ret != 3) || center == CENTER_INVALID) {
LOG_CONTEXTUAL_ERR(
- "invalid padding (must be in the form PAD_XxPAD_Y [center])");
+ "invalid padding (must be in the form PAD_XxPAD_Y "
+ "[center|"
+ "center-when-fullscreen|"
+ "center-when-maximized-and-fullscreen])");
return false;
}
conf->pad_x = x;
conf->pad_y = y;
- conf->center = center;
+ conf->center_when = ret == 2 ? CENTER_NEVER : center;
return true;
}
@@ -3339,6 +3352,7 @@ config_load(struct config *conf, const char *conf_path,
},
.pad_x = 0,
.pad_y = 0,
+ .center_when = CENTER_MAXIMIZED_AND_FULLSCREEN,
.resize_by_cells = true,
.resize_keep_grid = true,
.resize_delay_ms = 100,
diff --git a/config.h b/config.h
index 7cf6f6f5..315f7e24 100644
--- a/config.h
+++ b/config.h
@@ -201,6 +201,14 @@ enum shm_bit_depth {
SHM_BITS_16,
};
+enum center_when {
+ CENTER_INVALID,
+ CENTER_NEVER,
+ CENTER_FULLSCREEN,
+ CENTER_MAXIMIZED_AND_FULLSCREEN,
+ CENTER_ALWAYS,
+};
+
struct config {
char *term;
char *shell;
@@ -218,7 +226,7 @@ struct config {
unsigned pad_x;
unsigned pad_y;
- bool center;
+ enum center_when center_when;
bool resize_by_cells;
bool resize_keep_grid;
diff --git a/doc/foot.ini.5.scd b/doc/foot.ini.5.scd
index 81b88f64..74b3f35b 100644
--- a/doc/foot.ini.5.scd
+++ b/doc/foot.ini.5.scd
@@ -289,18 +289,29 @@ empty string to be set, but it must be quoted: *KEY=""*)
*pad*
Padding between border and glyphs, in pixels (subject to output
- scaling), in the form _XxY_.
+ scaling), in the form
+
+ ```
+ _XxY_ [center | center-when-fullscreen | center-when-maximized-and-fullscreen]
+ ```
This will add _at least_ X pixels on both the left and right
- sides, and Y pixels on the top and bottom sides. The grid content
- will be anchored in the top left corner. I.e. if the window
- manager forces an odd window size on foot, the additional pixels
- will be added to the right and bottom sides.
+ sides, and Y pixels on the top and bottom sides.
+
+ When no centering is specified, the grid content is anchored to
+ the top left corner. I.e. if the window manager forces an odd
+ window size on foot, the additional pixels will be added to the
+ right and bottom sides.
+
+ If *center* is specified, the grid content is instead
+ centered. This may cause "jumpiness" when resizing the window.
- To instead center the grid content, append *center* (e.g. *pad=5x5
- center*).
+ With *center-when-fullscreen* and
+ *center-when-maximized-and-fullscreen*, the grid is anchored to
+ the top left corner, unless the window is maximized, or
+ fullscreened.
- Default: _0x0_.
+ Default: _0x0_ center-when-maximized-and-fullscreen.
*resize-delay-ms*
diff --git a/foot.ini b/foot.ini
index f3ef6d85..73fdb7ab 100644
--- a/foot.ini
+++ b/foot.ini
@@ -28,7 +28,7 @@
# initial-window-size-pixels=700x500 # Or,
# initial-window-size-chars=<COLSxROWS>
# initial-window-mode=windowed
-# pad=0x0 # optionally append 'center'
+# pad=0x0 center-when-maximized-and-fullscreen
# resize-by-cells=yes
# resize-keep-grid=yes
# resize-delay-ms=100
diff --git a/render.c b/render.c
index a41eee0c..244152ef 100644
--- a/render.c
+++ b/render.c
@@ -4596,9 +4596,12 @@ render_resize(struct terminal *term, int width, int height, uint8_t opts)
const int total_x_pad = term->width - grid_width;
const int total_y_pad = term->height - grid_height;
- const bool centered_padding = term->conf->center
- || term->window->is_fullscreen
- || term->window->is_maximized;
+ const enum center_when center = term->conf->center_when;
+ const bool centered_padding =
+ center == CENTER_ALWAYS ||
+ (center == CENTER_MAXIMIZED_AND_FULLSCREEN &&
+ (term->window->is_fullscreen || term->window->is_maximized)) ||
+ (center == CENTER_FULLSCREEN && term->window->is_fullscreen);
if (centered_padding && !term->window->is_resizing) {
term->margins.left = total_x_pad / 2;