aboutsummaryrefslogtreecommitdiffstats
path: root/sway/config.c
diff options
context:
space:
mode:
authorLibravatar Ian Fan <ianfan0@gmail.com>2018-12-03 11:28:23 +0000
committerLibravatar emersion <contact@emersion.fr>2018-12-03 13:28:31 +0100
commitbca21ee0cf504f7878a5a2a80cc30cb09e5d5509 (patch)
treefc7b11df475839ae34f1c8fb61c1ff884d53e097 /sway/config.c
parentconfig: set $XDG_CONFIG_HOME if empty (diff)
downloadsway-bca21ee0cf504f7878a5a2a80cc30cb09e5d5509.tar.gz
sway-bca21ee0cf504f7878a5a2a80cc30cb09e5d5509.tar.zst
sway-bca21ee0cf504f7878a5a2a80cc30cb09e5d5509.zip
config: do not set $XDG_CONFIG_HOME if unset or empty
Instead redefine the config paths to use the default $HOME/.config
Diffstat (limited to 'sway/config.c')
-rw-r--r--sway/config.c30
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
352static bool load_config(const char *path, struct sway_config *config, 340static bool load_config(const char *path, struct sway_config *config,