diff options
-rw-r--r-- | sway/config.c | 30 |
1 files changed, 9 insertions, 21 deletions
diff --git a/sway/config.c b/sway/config.c index 8bc65857..ff7de4b9 100644 --- a/sway/config.c +++ b/sway/config.c | |||
@@ -316,28 +316,16 @@ static char *get_config_path(void) { | |||
316 | SYSCONFDIR "/i3/config", | 316 | SYSCONFDIR "/i3/config", |
317 | }; | 317 | }; |
318 | 318 | ||
319 | char *curr_config_home = getenv("XDG_CONFIG_HOME"); | 319 | char *config_home = getenv("XDG_CONFIG_HOME"); |
320 | if (!curr_config_home || !*curr_config_home) { | 320 | if (!config_home || !*config_home) { |
321 | char *home = getenv("HOME"); | 321 | config_paths[1] = "$HOME/.config/sway/config"; |
322 | char *config_home = malloc(strlen(home) + strlen("/.config") + 1); | 322 | config_paths[3] = "$HOME/.config/i3/config"; |
323 | if (!config_home) { | ||
324 | wlr_log(WLR_ERROR, "Unable to allocate $HOME/.config"); | ||
325 | } else { | ||
326 | strcpy(config_home, home); | ||
327 | strcat(config_home, "/.config"); | ||
328 | setenv("XDG_CONFIG_HOME", config_home, 1); | ||
329 | wlr_log(WLR_DEBUG, "Set XDG_CONFIG_HOME to %s", config_home); | ||
330 | free(config_home); | ||
331 | } | ||
332 | } | 323 | } |
333 | 324 | ||
334 | wordexp_t p; | 325 | for (size_t i = 0; i < sizeof(config_paths) / sizeof(char *); ++i) { |
335 | char *path; | 326 | wordexp_t p; |
336 | 327 | if (wordexp(config_paths[i], &p, WRDE_UNDEF) == 0) { | |
337 | int i; | 328 | char *path = strdup(p.we_wordv[0]); |
338 | for (i = 0; i < (int)(sizeof(config_paths) / sizeof(char *)); ++i) { | ||
339 | if (wordexp(config_paths[i], &p, 0) == 0) { | ||
340 | path = strdup(p.we_wordv[0]); | ||
341 | wordfree(&p); | 329 | wordfree(&p); |
342 | if (file_exists(path)) { | 330 | if (file_exists(path)) { |
343 | return path; | 331 | return path; |
@@ -346,7 +334,7 @@ static char *get_config_path(void) { | |||
346 | } | 334 | } |
347 | } | 335 | } |
348 | 336 | ||
349 | return NULL; // Not reached | 337 | return NULL; |
350 | } | 338 | } |
351 | 339 | ||
352 | static bool load_config(const char *path, struct sway_config *config, | 340 | static bool load_config(const char *path, struct sway_config *config, |