diff options
author | Luminarys <kizunanohikari@gmail.com> | 2015-08-10 14:22:22 -0500 |
---|---|---|
committer | Luminarys <kizunanohikari@gmail.com> | 2015-08-10 14:22:22 -0500 |
commit | 508980e3ab930fd1ea16cbb769771126110aa329 (patch) | |
tree | e6588fe0754e908bc4d33c529a529904bfe0cd68 | |
parent | Spaces to Tabs (diff) | |
download | sway-508980e3ab930fd1ea16cbb769771126110aa329.tar.gz sway-508980e3ab930fd1ea16cbb769771126110aa329.tar.zst sway-508980e3ab930fd1ea16cbb769771126110aa329.zip |
Abstracted load_config
-rw-r--r-- | sway/commands.c | 3 | ||||
-rw-r--r-- | sway/config.c | 19 | ||||
-rw-r--r-- | sway/config.h | 1 | ||||
-rw-r--r-- | sway/main.c | 22 |
4 files changed, 26 insertions, 19 deletions
diff --git a/sway/commands.c b/sway/commands.c index af24cc95..98786885 100644 --- a/sway/commands.c +++ b/sway/commands.c | |||
@@ -195,6 +195,9 @@ int cmd_reload(struct sway_config *config, int argc, char **argv) { | |||
195 | free(temp); | 195 | free(temp); |
196 | config = read_config(f, true); | 196 | config = read_config(f, true); |
197 | fclose(f); | 197 | fclose(f); |
198 | if (load_config()) { | ||
199 | |||
200 | } | ||
198 | 201 | ||
199 | return 0; | 202 | return 0; |
200 | } | 203 | } |
diff --git a/sway/config.c b/sway/config.c index 280900ca..3c7badec 100644 --- a/sway/config.c +++ b/sway/config.c | |||
@@ -8,6 +8,25 @@ | |||
8 | #include "commands.h" | 8 | #include "commands.h" |
9 | #include "config.h" | 9 | #include "config.h" |
10 | 10 | ||
11 | bool load_config() { | ||
12 | // TODO: Allow use of more config file locations | ||
13 | const char *name = "/.sway/config"; | ||
14 | const char *home = getenv("HOME"); | ||
15 | char *temp = malloc(strlen(home) + strlen(name) + 1); | ||
16 | strcpy(temp, home); | ||
17 | strcat(temp, name); | ||
18 | FILE *f = fopen(temp, "r"); | ||
19 | if (!f) { | ||
20 | fprintf(stderr, "Unable to open %s for reading", temp); | ||
21 | free(temp); | ||
22 | return false; | ||
23 | } | ||
24 | free(temp); | ||
25 | config = read_config(f, false); | ||
26 | fclose(f); | ||
27 | return true; | ||
28 | } | ||
29 | |||
11 | void config_defaults(struct sway_config *config) { | 30 | void config_defaults(struct sway_config *config) { |
12 | config->symbols = create_list(); | 31 | config->symbols = create_list(); |
13 | config->modes = create_list(); | 32 | config->modes = create_list(); |
diff --git a/sway/config.h b/sway/config.h index 733aaaae..62b65723 100644 --- a/sway/config.h +++ b/sway/config.h | |||
@@ -33,6 +33,7 @@ struct sway_config { | |||
33 | bool reloading; | 33 | bool reloading; |
34 | }; | 34 | }; |
35 | 35 | ||
36 | bool load_config(); | ||
36 | struct sway_config *read_config(FILE *file, bool is_active); | 37 | struct sway_config *read_config(FILE *file, bool is_active); |
37 | char *do_var_replacement(struct sway_config *config, char *str); | 38 | char *do_var_replacement(struct sway_config *config, char *str); |
38 | 39 | ||
diff --git a/sway/main.c b/sway/main.c index 298e530d..900e6e5d 100644 --- a/sway/main.c +++ b/sway/main.c | |||
@@ -9,24 +9,6 @@ | |||
9 | 9 | ||
10 | struct sway_config *config; | 10 | struct sway_config *config; |
11 | 11 | ||
12 | void load_config() { | ||
13 | // TODO: Allow use of more config file locations | ||
14 | const char *name = "/.sway/config"; | ||
15 | const char *home = getenv("HOME"); | ||
16 | char *temp = malloc(strlen(home) + strlen(name) + 1); | ||
17 | strcpy(temp, home); | ||
18 | strcat(temp, name); | ||
19 | FILE *f = fopen(temp, "r"); | ||
20 | if (!f) { | ||
21 | fprintf(stderr, "Unable to open %s for reading", temp); | ||
22 | free(temp); | ||
23 | exit(1); | ||
24 | } | ||
25 | free(temp); | ||
26 | config = read_config(f, false); | ||
27 | fclose(f); | ||
28 | } | ||
29 | |||
30 | int main(int argc, char **argv) { | 12 | int main(int argc, char **argv) { |
31 | init_log(L_DEBUG); // TODO: Control this with command line arg | 13 | init_log(L_DEBUG); // TODO: Control this with command line arg |
32 | init_layout(); | 14 | init_layout(); |
@@ -61,7 +43,9 @@ int main(int argc, char **argv) { | |||
61 | } | 43 | } |
62 | 44 | ||
63 | setenv("DISPLAY", ":1", 1); | 45 | setenv("DISPLAY", ":1", 1); |
64 | load_config(); | 46 | if (load_config()) { |
47 | exit(1); | ||
48 | } | ||
65 | 49 | ||
66 | wlc_run(); | 50 | wlc_run(); |
67 | return 0; | 51 | return 0; |