Allow user theme selection via config file

Relates to: #9
This commit is contained in:
Johannes Marbach 2021-11-14 13:30:23 +01:00
parent 5c3ad9bf9a
commit deff1ef4e9
8 changed files with 106 additions and 34 deletions

View file

@ -73,9 +73,12 @@ static bool parse_bool(const char *value, bool *result);
static void init_opts(ul_config_opts *opts) {
opts->general.animations = false;
opts->textarea.obscured = true;
opts->keyboard.autohide = true;
opts->keyboard.layout_id = SQ2LV_LAYOUT_US;
opts->keyboard.popovers = false;
opts->textarea.obscured = true;
opts->theme.default_id = UL_THEMES_THEME_BREEZY_DARK;
opts->theme.alternate_id = UL_THEMES_THEME_BREEZY_LIGHT;
}
static void parse_file(const char *path, ul_config_opts *opts) {
@ -93,12 +96,6 @@ static int parsing_handler(void* user_data, const char* section, const char* key
return 1;
}
}
} else if (strcmp(section, "textarea") == 0) {
if (strcmp(key, "obscured") == 0) {
if (parse_bool(value, &(opts->textarea.obscured))) {
return 1;
}
}
} else if (strcmp(section, "keyboard") == 0) {
if (strcmp(key, "autohide") == 0) {
if (parse_bool(value, &(opts->keyboard.autohide))) {
@ -115,6 +112,26 @@ static int parsing_handler(void* user_data, const char* section, const char* key
return 1;
}
}
} else if (strcmp(section, "textarea") == 0) {
if (strcmp(key, "obscured") == 0) {
if (parse_bool(value, &(opts->textarea.obscured))) {
return 1;
}
}
} else if (strcmp(section, "theme") == 0) {
if (strcmp(key, "default") == 0) {
ul_themes_theme_id_t id = ul_themes_find_theme_with_name(value);
if (id != UL_THEMES_THEME_NONE) {
opts->theme.default_id = id;
return 1;
}
} else if (strcmp(key, "alternate") == 0) {
ul_themes_theme_id_t id = ul_themes_find_theme_with_name(value);
if (id != UL_THEMES_THEME_NONE) {
opts->theme.alternate_id = id;
return 1;
}
}
}
ul_log(UL_LOG_LEVEL_ERROR, "Ignoring invalid config value \"%s\" for key \"%s\" in section \"%s\"", value, key, section);