diff options
author | Luminarys <kizunanohikari@gmail.com> | 2015-08-15 20:03:33 -0500 |
---|---|---|
committer | Luminarys <kizunanohikari@gmail.com> | 2015-08-15 20:03:33 -0500 |
commit | 24231bef0efb557d90e09398e3b3c0d5828db917 (patch) | |
tree | 3f56a0cce9b1ba7fce38685ecd4ee08f9ec34145 | |
parent | Added in config file loading from multiple sources (diff) | |
download | sway-24231bef0efb557d90e09398e3b3c0d5828db917.tar.gz sway-24231bef0efb557d90e09398e3b3c0d5828db917.tar.zst sway-24231bef0efb557d90e09398e3b3c0d5828db917.zip |
Added in additional checks for i3 config paths
-rw-r--r-- | sway/config.c | 54 |
1 files changed, 53 insertions, 1 deletions
diff --git a/sway/config.c b/sway/config.c index eb08641a..4f576bb9 100644 --- a/sway/config.c +++ b/sway/config.c | |||
@@ -19,8 +19,8 @@ static char* get_config_path() { | |||
19 | char *name = "/.sway/config"; | 19 | char *name = "/.sway/config"; |
20 | const char *home = getenv("HOME"); | 20 | const char *home = getenv("HOME"); |
21 | 21 | ||
22 | sway_log(L_DEBUG, "Trying to find config in ~/.sway/config"); | ||
23 | // Check home dir | 22 | // Check home dir |
23 | sway_log(L_DEBUG, "Trying to find config in ~/.sway/config"); | ||
24 | char *temp = malloc(strlen(home) + strlen(name) + 1); | 24 | char *temp = malloc(strlen(home) + strlen(name) + 1); |
25 | strcpy(temp, home); | 25 | strcpy(temp, home); |
26 | strcat(temp, name); | 26 | strcat(temp, name); |
@@ -73,6 +73,58 @@ static char* get_config_path() { | |||
73 | free_flat_list(paths); | 73 | free_flat_list(paths); |
74 | } | 74 | } |
75 | 75 | ||
76 | //Now fall back to i3 paths and try the same thing | ||
77 | name = "/.i3/config"; | ||
78 | sway_log(L_DEBUG, "Trying to find config in ~/.i3/config"); | ||
79 | char *temp = malloc(strlen(home) + strlen(name) + 1); | ||
80 | strcpy(temp, home); | ||
81 | strcat(temp, name); | ||
82 | if (exists(temp)) { | ||
83 | return temp; | ||
84 | } | ||
85 | |||
86 | sway_log(L_DEBUG, "Trying to find config in XDG_CONFIG_HOME/i3/config"); | ||
87 | char *xdg_config_home = getenv("XDG_CONFIG_HOME"); | ||
88 | if (xdg_config_home == NULL) { | ||
89 | sway_log(L_DEBUG, "Falling back to ~/.config/i3/config"); | ||
90 | name = "/.config/i3/config"; | ||
91 | temp = malloc(strlen(home) + strlen(name) + 1); | ||
92 | strcpy(temp, home); | ||
93 | strcat(temp, name); | ||
94 | } else { | ||
95 | name = "/i3/config"; | ||
96 | temp = malloc(strlen(xdg_config_home) + strlen(name) + 1); | ||
97 | strcpy(temp, home); | ||
98 | strcat(temp, name); | ||
99 | } | ||
100 | if (exists(temp)) { | ||
101 | return temp; | ||
102 | } | ||
103 | |||
104 | sway_log(L_DEBUG, "Trying to find config in /etc/i3/config"); | ||
105 | strcpy(temp, "/etc/i3/config"); | ||
106 | if (exists(temp)) { | ||
107 | return temp; | ||
108 | } | ||
109 | |||
110 | sway_log(L_DEBUG, "Trying to find config in XDG_CONFIG_DIRS"); | ||
111 | char *xdg_config_dirs = getenv("XDG_CONFIG_DIRS"); | ||
112 | if (xdg_config_dirs != NULL) { | ||
113 | list_t *paths = split_string(xdg_config_dirs, ":"); | ||
114 | name = "/i3/config"; | ||
115 | int i; | ||
116 | for (i = 0; i < paths->length; i++ ) { | ||
117 | temp = malloc(strlen(paths->items[i]) + strlen(name) + 1); | ||
118 | strcpy(temp, paths->items[i]); | ||
119 | strcat(temp, name); | ||
120 | if (exists(temp)) { | ||
121 | free_flat_list(paths); | ||
122 | return temp; | ||
123 | } | ||
124 | } | ||
125 | free_flat_list(paths); | ||
126 | } | ||
127 | |||
76 | return NULL; | 128 | return NULL; |
77 | } | 129 | } |
78 | 130 | ||