config: parse XDG_CURRENT_DESKTOP as a list

This commit is contained in:
columbarius 2021-04-22 23:17:53 +02:00
parent c60b2b6ca8
commit feede20314

View file

@ -119,13 +119,32 @@ static char *get_config_path(void) {
prefix[0] = config_home; prefix[0] = config_home;
prefix[1] = SYSCONFDIR "/xdg"; prefix[1] = SYSCONFDIR "/xdg";
const char *config[2]; char *xdg_current_desktop = getenv("XDG_CURRENT_DESKTOP");
config[0] = getenv("XDG_CURRENT_DESKTOP"); char *config_fallback = "config";
config[1] = "config";
char *config_list = NULL;
for (size_t i = 0; i < 2; i++) { for (size_t i = 0; i < 2; i++) {
for (size_t j = 0; j < 2; j++) { if (xdg_current_desktop) {
char *path = config_path(prefix[i], config[j]); config_list = strdup(xdg_current_desktop);
char *config = strtok(config_list, ":");
while (config) {
char *path = config_path(prefix[i], config);
if (!path) {
config = strtok(NULL, ":");
continue;
}
logprint(TRACE, "config: trying config file %s", path);
if (file_exists(path)) {
free(config_list);
free(config_home_fallback);
return path;
}
free(path);
config = strtok(NULL, ":");
}
free(config_list);
}
char *path = config_path(prefix[i], config_fallback);
if (!path) { if (!path) {
continue; continue;
} }
@ -136,7 +155,6 @@ static char *get_config_path(void) {
} }
free(path); free(path);
} }
}
free(config_home_fallback); free(config_home_fallback);
return NULL; return NULL;