mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-02-04 04:06:06 -05:00
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:
parent
5621829bb0
commit
5a84f8d841
6 changed files with 60 additions and 20 deletions
|
|
@ -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
|
||||
|
|
|
|||
28
config.c
28
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,
|
||||
|
|
|
|||
10
config.h
10
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;
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
||||
To instead center the grid content, append *center* (e.g. *pad=5x5
|
||||
center*).
|
||||
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.
|
||||
|
||||
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*
|
||||
|
||||
|
|
|
|||
2
foot.ini
2
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
|
||||
|
|
|
|||
9
render.c
9
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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue