mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-02-12 04:27:51 -05:00
config: add value_to_dimensions()
This commit is contained in:
parent
d29c3cf7b7
commit
0c0a78498f
2 changed files with 15 additions and 14 deletions
25
config.c
25
config.c
|
|
@ -537,6 +537,17 @@ value_to_uint32(struct context *ctx, int base, uint32_t *res)
|
|||
return true;
|
||||
}
|
||||
|
||||
static bool NOINLINE
|
||||
value_to_dimensions(struct context *ctx, uint32_t *x, uint32_t *y)
|
||||
{
|
||||
if (sscanf(ctx->value, "%ux%u", x, y) != 2) {
|
||||
LOG_CONTEXTUAL_ERR("invalid dimensions (must be on the form AxB)");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool NOINLINE
|
||||
value_to_double(struct context *ctx, float *res)
|
||||
{
|
||||
|
|
@ -883,27 +894,17 @@ parse_section_main(struct context *ctx)
|
|||
return value_to_str(ctx, &conf->app_id);
|
||||
|
||||
else if (strcmp(key, "initial-window-size-pixels") == 0) {
|
||||
unsigned width, height;
|
||||
if (sscanf(value, "%ux%u", &width, &height) != 2 || width == 0 || height == 0) {
|
||||
LOG_CONTEXTUAL_ERR("invalid size (must be on the form WIDTHxHEIGHT)");
|
||||
if (!value_to_dimensions(ctx, &conf->size.width, &conf->size.height))
|
||||
return false;
|
||||
}
|
||||
|
||||
conf->size.type = CONF_SIZE_PX;
|
||||
conf->size.width = width;
|
||||
conf->size.height = height;
|
||||
}
|
||||
|
||||
else if (strcmp(key, "initial-window-size-chars") == 0) {
|
||||
unsigned width, height;
|
||||
if (sscanf(value, "%ux%u", &width, &height) != 2 || width == 0 || height == 0) {
|
||||
LOG_CONTEXTUAL_ERR("invalid size (must be on the form WIDTHxHEIGHT)");
|
||||
if (!value_to_dimensions(ctx, &conf->size.width, &conf->size.height))
|
||||
return false;
|
||||
}
|
||||
|
||||
conf->size.type = CONF_SIZE_CELLS;
|
||||
conf->size.width = width;
|
||||
conf->size.height = height;
|
||||
}
|
||||
|
||||
else if (strcmp(key, "pad") == 0) {
|
||||
|
|
|
|||
4
config.h
4
config.h
|
|
@ -74,8 +74,8 @@ struct config {
|
|||
|
||||
struct {
|
||||
enum conf_size_type type;
|
||||
unsigned width;
|
||||
unsigned height;
|
||||
uint32_t width;
|
||||
uint32_t height;
|
||||
} size;
|
||||
|
||||
unsigned pad_x;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue