conf: pad: add center-when-fullscreen and center-when-maximized-and-fullscreen

Before this patch, the grid content was *always* centered when the
window was maximized or fullscreened, regardless of how the user had
configured padding.

Now, the behavior is controlled by the 'pad' option. Before this
patch, the syntax was

    pad MxN [center]

Now it is

    pad MxN [center|center-when-fullscreen|center-when-maximized-and-fullscreen]

The default is "pad 0x0 center-when-maximized-and-fullscreen", to
match current behavior.

Closes #2111
This commit is contained in:
Daniel Eklöf 2025-05-23 08:38:00 +02:00
parent 5621829bb0
commit 5a84f8d841
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
6 changed files with 60 additions and 20 deletions

View file

@ -91,9 +91,13 @@
buffers. They provide the necessary color precision required by buffers. They provide the necessary color precision required by
`gamma-correct-blending=yes`. `gamma-correct-blending=yes`.
* New cursor shapes, from `cursor-shape-v1` version 2. * 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 [2025]: https://codeberg.org/dnkl/foot/issues/2025
[1975]: https://codeberg.org/dnkl/foot/issues/1975 [1975]: https://codeberg.org/dnkl/foot/issues/1975
[2111]: https://codeberg.org/dnkl/foot/issues/2111
### Changed ### Changed

View file

@ -933,21 +933,34 @@ parse_section_main(struct context *ctx)
else if (streq(key, "pad")) { else if (streq(key, "pad")) {
unsigned x, y; 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); enum center_when center = CENTER_NEVER;
bool center = strcasecmp(mode, "center") == 0;
bool invalid_mode = !center && mode[0] != '\0';
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( 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; return false;
} }
conf->pad_x = x; conf->pad_x = x;
conf->pad_y = y; conf->pad_y = y;
conf->center = center; conf->center_when = ret == 2 ? CENTER_NEVER : center;
return true; return true;
} }
@ -3339,6 +3352,7 @@ config_load(struct config *conf, const char *conf_path,
}, },
.pad_x = 0, .pad_x = 0,
.pad_y = 0, .pad_y = 0,
.center_when = CENTER_MAXIMIZED_AND_FULLSCREEN,
.resize_by_cells = true, .resize_by_cells = true,
.resize_keep_grid = true, .resize_keep_grid = true,
.resize_delay_ms = 100, .resize_delay_ms = 100,

View file

@ -201,6 +201,14 @@ enum shm_bit_depth {
SHM_BITS_16, SHM_BITS_16,
}; };
enum center_when {
CENTER_INVALID,
CENTER_NEVER,
CENTER_FULLSCREEN,
CENTER_MAXIMIZED_AND_FULLSCREEN,
CENTER_ALWAYS,
};
struct config { struct config {
char *term; char *term;
char *shell; char *shell;
@ -218,7 +226,7 @@ struct config {
unsigned pad_x; unsigned pad_x;
unsigned pad_y; unsigned pad_y;
bool center; enum center_when center_when;
bool resize_by_cells; bool resize_by_cells;
bool resize_keep_grid; bool resize_keep_grid;

View file

@ -289,18 +289,29 @@ empty string to be set, but it must be quoted: *KEY=""*)
*pad* *pad*
Padding between border and glyphs, in pixels (subject to output 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 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 sides, and Y pixels on the top and bottom sides.
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.
To instead center the grid content, append *center* (e.g. *pad=5x5 When no centering is specified, the grid content is anchored to
center*). 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.
Default: _0x0_. If *center* is specified, the grid content is instead
centered. This may cause "jumpiness" when resizing the window.
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_ center-when-maximized-and-fullscreen.
*resize-delay-ms* *resize-delay-ms*

View file

@ -28,7 +28,7 @@
# initial-window-size-pixels=700x500 # Or, # initial-window-size-pixels=700x500 # Or,
# initial-window-size-chars=<COLSxROWS> # initial-window-size-chars=<COLSxROWS>
# initial-window-mode=windowed # initial-window-mode=windowed
# pad=0x0 # optionally append 'center' # pad=0x0 center-when-maximized-and-fullscreen
# resize-by-cells=yes # resize-by-cells=yes
# resize-keep-grid=yes # resize-keep-grid=yes
# resize-delay-ms=100 # resize-delay-ms=100

View file

@ -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_x_pad = term->width - grid_width;
const int total_y_pad = term->height - grid_height; const int total_y_pad = term->height - grid_height;
const bool centered_padding = term->conf->center const enum center_when center = term->conf->center_when;
|| term->window->is_fullscreen const bool centered_padding =
|| term->window->is_maximized; 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) { if (centered_padding && !term->window->is_resizing) {
term->margins.left = total_x_pad / 2; term->margins.left = total_x_pad / 2;