From d29c3cf7b76c6a1935684124b4d7cad69de94c78 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sat, 6 Nov 2021 12:01:57 +0100 Subject: config: add {str,value}_to_uint{16,32}() This allows us to pass the final pointer directly to the conversion functions, as well as allowing us to print outside-range errors. --- config.h | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'config.h') diff --git a/config.h b/config.h index b47c3537..4b23e465 100644 --- a/config.h +++ b/config.h @@ -19,7 +19,7 @@ enum conf_size_type {CONF_SIZE_PX, CONF_SIZE_CELLS}; struct config_font { char *pattern; - double pt_size; + float pt_size; int px_size; }; DEFINE_LIST(struct config_font); @@ -115,7 +115,7 @@ struct config { } bell; struct { - int lines; + uint32_t lines; struct { enum { @@ -132,7 +132,7 @@ struct config { wchar_t *text; } indicator; - double multiplier; + float multiplier; } scrollback; struct { @@ -212,10 +212,10 @@ struct config { struct { enum { CONF_CSD_PREFER_NONE, CONF_CSD_PREFER_SERVER, CONF_CSD_PREFER_CLIENT } preferred; - int title_height; - int border_width; - int border_width_visible; - int button_width; + uint16_t title_height; + uint16_t border_width; + uint16_t border_width_visible; + uint16_t button_width; struct { bool title_set:1; @@ -235,7 +235,7 @@ struct config { struct config_font_list font; } csd; - size_t render_worker_count; + uint16_t render_worker_count; char *server_socket_path; bool presentation_timings; bool hold_at_exit; @@ -257,8 +257,8 @@ struct config { bool render_timer_osd; bool render_timer_log; bool damage_whole_window; - uint64_t delayed_render_lower_ns; - uint64_t delayed_render_upper_ns; + uint32_t delayed_render_lower_ns; + uint32_t delayed_render_upper_ns; off_t max_shm_pool_size; float box_drawing_base_thickness; bool box_drawing_solid_shades; -- cgit v1.3 From 0c0a78498f4207ca9816cd41c5badaf516230072 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sat, 6 Nov 2021 12:32:20 +0100 Subject: config: add value_to_dimensions() --- config.c | 25 +++++++++++++------------ config.h | 4 ++-- 2 files changed, 15 insertions(+), 14 deletions(-) (limited to 'config.h') diff --git a/config.c b/config.c index e6ae1c14..fd646bb7 100644 --- a/config.c +++ b/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) { diff --git a/config.h b/config.h index 4b23e465..f0f95035 100644 --- a/config.h +++ b/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; -- cgit v1.3