summaryrefslogtreecommitdiffstats
path: root/sway/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'sway/main.c')
-rw-r--r--sway/main.c96
1 files changed, 93 insertions, 3 deletions
diff --git a/sway/main.c b/sway/main.c
index 2db4604c..f37f086d 100644
--- a/sway/main.c
+++ b/sway/main.c
@@ -4,31 +4,121 @@
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"
10#include "handlers.h" 11#include "handlers.h"
12#include "ipc.h"
13#include "sway.h"
14
15static bool terminate_request = false;
16
17void sway_terminate(void) {
18 terminate_request = true;
19 wlc_terminate();
20}
11 21
12static void sigchld_handle(int signal); 22static void sigchld_handle(int signal);
13 23
14int main(int argc, char **argv) { 24int main(int argc, char **argv) {
25 static int verbose = 0, debug = 0, validate = 0;
26
27 static struct option long_options[] = {
28 {"config", required_argument, NULL, 'c'},
29 {"validate", no_argument, &validate, 1},
30 {"debug", no_argument, &debug, 1},
31 {"version", no_argument, NULL, 'v'},
32 {"verbose", no_argument, &verbose, 1},
33 {"get-socketpath", no_argument, NULL, 'p'},
34 };
35
15 /* Signal handling */ 36 /* Signal handling */
16 signal(SIGCHLD, sigchld_handle); 37 signal(SIGCHLD, sigchld_handle);
17 38
18 setenv("WLC_DIM", "0", 0); 39 setenv("WLC_DIM", "0", 0);
40
41 FILE *devnull = fopen("/dev/null", "w");
42 if (devnull) {
43 // NOTE: Does not work, see wlc issue #54
44 wlc_set_log_file(devnull);
45 }
46
19 /* Changing code earlier than this point requires detailed review */ 47 /* Changing code earlier than this point requires detailed review */
20 if (!wlc_init(&interface, argc, argv)) { 48 if (!wlc_init(&interface, argc, argv)) {
21 return 1; 49 return 1;
22 } 50 }
23 51
24 init_log(L_DEBUG); // TODO: Control this with command line arg 52 char *config_path = NULL;
53
54 int c;
55 while (1) {
56 int option_index = 0;
57 c = getopt_long(argc, argv, "CdvVpc:", long_options, &option_index);
58 if (c == -1) {
59 break;
60 }
61 switch (c) {
62 case 0: // Flag
63 break;
64 case 'c': // config
65 config_path = strdup(optarg);
66 break;
67 case 'C': // validate
68 validate = 1;
69 break;
70 case 'd': // debug
71 debug = 1;
72 break;
73 case 'v': // version
74 // todo
75 exit(0);
76 break;
77 case 'V': // verbose
78 verbose = 1;
79 break;
80 case 'p': // --get-socketpath
81 // TODO
82 break;
83 }
84 }
85
86 if (debug) {
87 init_log(L_DEBUG);
88 wlc_set_log_file(stderr);
89 fclose(devnull);
90 devnull = NULL;
91 } else if (verbose || validate) {
92 init_log(L_INFO);
93 } else {
94 init_log(L_ERROR);
95 }
96
97 if (validate) {
98 bool valid = load_config(config_path);
99 return valid ? 0 : 1;
100 }
101
25 init_layout(); 102 init_layout();
26 103
27 if (!load_config()) { 104 if (!load_config(config_path)) {
28 sway_log(L_ERROR, "Error(s) loading config!"); 105 sway_log(L_ERROR, "Error(s) loading config!");
29 } 106 }
107 if (config_path) {
108 free(config_path);
109 }
110
111 ipc_init();
112
113 if (!terminate_request) {
114 wlc_run();
115 }
116
117 if (devnull) {
118 fclose(devnull);
119 }
30 120
31 wlc_run(); 121 ipc_terminate();
32 122
33 return 0; 123 return 0;
34} 124}