support four-sided padding (top/right/bottom/left)

This commit is contained in:
pi66 2025-12-19 12:17:29 +01:00
parent 4e96780eef
commit e133122147
6 changed files with 70 additions and 29 deletions

View file

@ -943,13 +943,12 @@ parse_section_main(struct context *ctx)
}
else if (streq(key, "pad")) {
unsigned x, y;
unsigned x, y, t, r, b, l;
char mode[64] = {0};
int ret = sscanf(value, "%ux%u %63s", &x, &y, mode);
int ret = sscanf(value, "%ux%ux%ux%u %63s", &r, &t, &l, &b, mode);
enum center_when center = CENTER_NEVER;
if (ret == 3) {
if (ret == 5) {
if (strcasecmp(mode, "center") == 0)
center = CENTER_ALWAYS;
else if (strcasecmp(mode, "center-when-fullscreen") == 0)
@ -958,20 +957,38 @@ parse_section_main(struct context *ctx)
center = CENTER_MAXIMIZED_AND_FULLSCREEN;
else
center = CENTER_INVALID;
} else if (ret < 4) {
ret = sscanf(value, "%ux%u %63s", &x, &y, mode);
if (ret >= 2) {
t = b = y;
l = r = x;
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) {
if ((ret < 2 || ret > 5) || center == CENTER_INVALID) {
LOG_CONTEXTUAL_ERR(
"invalid padding (must be in the form PAD_XxPAD_Y "
"invalid padding (must be in the form RIGHTxTOPxLEFTxBOTTOM or XxY "
"[center|"
"center-when-fullscreen|"
"center-when-maximized-and-fullscreen])");
return false;
}
conf->pad_x = x;
conf->pad_y = y;
conf->center_when = ret == 2 ? CENTER_NEVER : center;
conf->pad_top = t;
conf->pad_right = r;
conf->pad_bottom = b;
conf->pad_left = l;
conf->center_when = (ret == 4 || ret == 2) ? CENTER_NEVER : center;
return true;
}
@ -3381,8 +3398,10 @@ config_load(struct config *conf, const char *conf_path,
.width = 700,
.height = 500,
},
.pad_x = 0,
.pad_y = 0,
.pad_top = 0,
.pad_right = 0,
.pad_bottom = 0,
.pad_left = 0,
.center_when = CENTER_MAXIMIZED_AND_FULLSCREEN,
.resize_by_cells = true,
.resize_keep_grid = true,