diff options
Diffstat (limited to 'sway')
-rw-r--r-- | sway/commands.c | 2 | ||||
-rw-r--r-- | sway/config.c | 9 | ||||
-rw-r--r-- | sway/main.c | 78 |
3 files changed, 84 insertions, 5 deletions
diff --git a/sway/commands.c b/sway/commands.c index a3f74747..803d9a21 100644 --- a/sway/commands.c +++ b/sway/commands.c | |||
@@ -414,7 +414,7 @@ static bool cmd_reload(struct sway_config *config, int argc, char **argv) { | |||
414 | if (!checkarg(argc, "reload", EXPECTED_EQUAL_TO, 0)) { | 414 | if (!checkarg(argc, "reload", EXPECTED_EQUAL_TO, 0)) { |
415 | return false; | 415 | return false; |
416 | } | 416 | } |
417 | if (!load_config()) { | 417 | if (!load_config(NULL)) { // TODO: Use config given from -c |
418 | return false; | 418 | return false; |
419 | } | 419 | } |
420 | arrange_windows(&root_container, -1, -1); | 420 | arrange_windows(&root_container, -1, -1); |
diff --git a/sway/config.c b/sway/config.c index 94bc2abb..9f65e8a2 100644 --- a/sway/config.c +++ b/sway/config.c | |||
@@ -144,10 +144,15 @@ _continue: | |||
144 | return test; | 144 | return test; |
145 | } | 145 | } |
146 | 146 | ||
147 | bool load_config(void) { | 147 | bool load_config(const char *file) { |
148 | sway_log(L_INFO, "Loading config"); | 148 | sway_log(L_INFO, "Loading config"); |
149 | 149 | ||
150 | char *path = get_config_path(); | 150 | char *path; |
151 | if (file != NULL) { | ||
152 | path = strdup(file); | ||
153 | } else { | ||
154 | path = get_config_path(); | ||
155 | } | ||
151 | 156 | ||
152 | if (path == NULL) { | 157 | if (path == NULL) { |
153 | sway_log(L_ERROR, "Unable to find a config file!"); | 158 | sway_log(L_ERROR, "Unable to find a config file!"); |
diff --git a/sway/main.c b/sway/main.c index 2db4604c..4a7e13c1 100644 --- a/sway/main.c +++ b/sway/main.c | |||
@@ -4,6 +4,7 @@ | |||
4 | #include <wlc/wlc.h> | 4 | #include <wlc/wlc.h> |
5 | #include <sys/wait.h> | 5 | #include <sys/wait.h> |
6 | #include <signal.h> | 6 | #include <signal.h> |
7 | #include <getopt.h> | ||
7 | #include "layout.h" | 8 | #include "layout.h" |
8 | #include "config.h" | 9 | #include "config.h" |
9 | #include "log.h" | 10 | #include "log.h" |
@@ -12,23 +13,96 @@ | |||
12 | static void sigchld_handle(int signal); | 13 | static void sigchld_handle(int signal); |
13 | 14 | ||
14 | int main(int argc, char **argv) { | 15 | int main(int argc, char **argv) { |
16 | static int verbose = 0, debug = 0, validate = 0; | ||
17 | |||
18 | static struct option long_options[] = { | ||
19 | {"config", required_argument, NULL, 'c'}, | ||
20 | {"validate", no_argument, &validate, 1}, | ||
21 | {"debug", no_argument, &debug, 1}, | ||
22 | {"version", no_argument, NULL, 'v'}, | ||
23 | {"verbose", no_argument, &verbose, 1}, | ||
24 | {"get-socketpath", no_argument, NULL, 'p'}, | ||
25 | }; | ||
26 | |||
15 | /* Signal handling */ | 27 | /* Signal handling */ |
16 | signal(SIGCHLD, sigchld_handle); | 28 | signal(SIGCHLD, sigchld_handle); |
17 | 29 | ||
18 | setenv("WLC_DIM", "0", 0); | 30 | setenv("WLC_DIM", "0", 0); |
31 | |||
32 | FILE *devnull = fopen("/dev/null", "w"); | ||
33 | if (devnull) { | ||
34 | // NOTE: Does not work, see wlc issue #54 | ||
35 | wlc_set_log_file(devnull); | ||
36 | } | ||
37 | |||
19 | /* Changing code earlier than this point requires detailed review */ | 38 | /* Changing code earlier than this point requires detailed review */ |
20 | if (!wlc_init(&interface, argc, argv)) { | 39 | if (!wlc_init(&interface, argc, argv)) { |
21 | return 1; | 40 | return 1; |
22 | } | 41 | } |
23 | 42 | ||
24 | init_log(L_DEBUG); // TODO: Control this with command line arg | 43 | char *config_path = NULL; |
44 | |||
45 | int c; | ||
46 | while (1) { | ||
47 | int option_index = 0; | ||
48 | c = getopt_long(argc, argv, "CdvVpc:", long_options, &option_index); | ||
49 | if (c == -1) { | ||
50 | break; | ||
51 | } | ||
52 | switch (c) { | ||
53 | case 0: // Flag | ||
54 | break; | ||
55 | case 'c': // config | ||
56 | config_path = strdup(optarg); | ||
57 | break; | ||
58 | case 'C': // validate | ||
59 | validate = 1; | ||
60 | break; | ||
61 | case 'd': // debug | ||
62 | debug = 1; | ||
63 | break; | ||
64 | case 'v': // version | ||
65 | // todo | ||
66 | exit(0); | ||
67 | break; | ||
68 | case 'V': // verbose | ||
69 | verbose = 1; | ||
70 | break; | ||
71 | case 'p': // --get-socketpath | ||
72 | // TODO | ||
73 | break; | ||
74 | } | ||
75 | } | ||
76 | |||
77 | if (debug) { | ||
78 | init_log(L_DEBUG); | ||
79 | wlc_set_log_file(stderr); | ||
80 | fclose(devnull); | ||
81 | devnull = NULL; | ||
82 | } else if (verbose || validate) { | ||
83 | init_log(L_INFO); | ||
84 | } else { | ||
85 | init_log(L_ERROR); | ||
86 | } | ||
87 | |||
88 | if (validate) { | ||
89 | bool valid = load_config(config_path); | ||
90 | return valid ? 0 : 1; | ||
91 | } | ||
92 | |||
25 | init_layout(); | 93 | init_layout(); |
26 | 94 | ||
27 | if (!load_config()) { | 95 | if (!load_config(config_path)) { |
28 | sway_log(L_ERROR, "Error(s) loading config!"); | 96 | sway_log(L_ERROR, "Error(s) loading config!"); |
29 | } | 97 | } |
98 | if (config_path) { | ||
99 | free(config_path); | ||
100 | } | ||
30 | 101 | ||
31 | wlc_run(); | 102 | wlc_run(); |
103 | if (devnull) { | ||
104 | fclose(devnull); | ||
105 | } | ||
32 | 106 | ||
33 | return 0; | 107 | return 0; |
34 | } | 108 | } |