From a664509c6b637e65fbd417b4a7dece831f5cf6e3 Mon Sep 17 00:00:00 2001 From: Federico Angelilli Date: Thu, 11 Jul 2024 15:26:43 +0200 Subject: Add override_redirect config --- src/config.c | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) (limited to 'src/config.c') diff --git a/src/config.c b/src/config.c index 39c58f5..07f5743 100644 --- a/src/config.c +++ b/src/config.c @@ -16,6 +16,7 @@ typedef enum { CONFIG_INT, CONFIG_UINT, CONFIG_DOUBLE, + CONFIG_BOOL, } config_type_t; typedef struct { @@ -25,10 +26,11 @@ typedef struct { } config_entry_t; static const config_entry_t config_entries[] = { - { "width", CONFIG_UINT, offsetof(config_t, width) }, - { "height", CONFIG_UINT, offsetof(config_t, height) }, - { "font", CONFIG_STRING, offsetof(config_t, font) }, - { "monitor", CONFIG_STRING, offsetof(config_t, monitor) }, + { "width", CONFIG_UINT, offsetof(config_t, width) }, + { "height", CONFIG_UINT, offsetof(config_t, height) }, + { "font", CONFIG_STRING, offsetof(config_t, font) }, + { "monitor", CONFIG_STRING, offsetof(config_t, monitor) }, + { "override_redirect", CONFIG_BOOL, offsetof(config_t, override_redirect) }, }; static bool config_read_string(const char *value, char **result) @@ -71,6 +73,24 @@ static bool config_read_uint(const char *value, unsigned int *result) return *end == '\0' && n != ULONG_MAX; } +static bool config_read_bool(const char *value, bool *result) +{ + size_t lenght = strlen(value); + + if (lenght == 5 && !strcmp(value, "false")) { + *result = false; + return true; + } + + if (lenght == 4 && !strcmp(value, "true")) { + *result = true; + return true; + } + + log_debug("Invalid bool value"); + return false; +} + static bool config_read_double(const char *value, double *result) { char *end; @@ -133,6 +153,13 @@ static bool config_entry(config_t *config, int line, const char *section, const } break; + case CONFIG_BOOL: + if (config_read_bool(value, (bool *)result)) { + log_debug("Config '%s' set to '%s'", key, *(bool *)result ? "true" : "false"); + return true; + } + break; + default: log_panic("Unreachable"); } @@ -169,6 +196,7 @@ void config_init(config_t *config) .monitor = NULL, .height = 50, .width = 100, + .override_redirect = false, }; memcpy(config, &config_default, sizeof(config_t)); -- cgit v1.2.3