aboutsummaryrefslogtreecommitdiff
path: root/src/config.c
diff options
context:
space:
mode:
authorFederico Angelilli <code@fedang.net>2024-07-11 15:26:43 +0200
committerFederico Angelilli <code@fedang.net>2024-07-11 15:26:43 +0200
commita664509c6b637e65fbd417b4a7dece831f5cf6e3 (patch)
treeb71d8e09afc098a8e57c44d83bdd3f0a422e3527 /src/config.c
parent6942efee2d41a768501e23bd06f38dbb4fde197b (diff)
Add override_redirect config
Diffstat (limited to 'src/config.c')
-rw-r--r--src/config.c36
1 files changed, 32 insertions, 4 deletions
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));