diff options
author | Drew DeVault <sir@cmpwn.com> | 2015-08-13 11:00:00 -0400 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2015-08-13 11:00:00 -0400 |
commit | 94e81fd64c4f63815047fa1ad895cade9afa8bd4 (patch) | |
tree | 9770eded52cae4f9d3d033123e1470d7873624c5 | |
parent | This space intentionally left blank (diff) | |
parent | small change (diff) | |
download | sway-94e81fd64c4f63815047fa1ad895cade9afa8bd4.tar.gz sway-94e81fd64c4f63815047fa1ad895cade9afa8bd4.tar.zst sway-94e81fd64c4f63815047fa1ad895cade9afa8bd4.zip |
Merge pull request #23 from taiyu-len/master
moving things around + statics + forking + exec cleanup + fixed cmd_focus return + keep exec programs out of logs
-rw-r--r-- | sway/commands.c | 151 | ||||
-rw-r--r-- | sway/handlers.c | 49 | ||||
-rw-r--r-- | sway/handlers.h | 17 | ||||
-rw-r--r-- | sway/log.c | 12 | ||||
-rw-r--r-- | sway/main.c | 35 | ||||
-rw-r--r-- | sway/movement.c | 10 | ||||
-rw-r--r-- | sway/movement.h | 2 |
7 files changed, 155 insertions, 121 deletions
diff --git a/sway/commands.c b/sway/commands.c index 870a2377..da33c5de 100644 --- a/sway/commands.c +++ b/sway/commands.c | |||
@@ -18,7 +18,7 @@ struct modifier_key { | |||
18 | uint32_t mod; | 18 | uint32_t mod; |
19 | }; | 19 | }; |
20 | 20 | ||
21 | struct modifier_key modifiers[] = { | 21 | static struct modifier_key modifiers[] = { |
22 | { XKB_MOD_NAME_SHIFT, WLC_BIT_MOD_SHIFT }, | 22 | { XKB_MOD_NAME_SHIFT, WLC_BIT_MOD_SHIFT }, |
23 | { XKB_MOD_NAME_CAPS, WLC_BIT_MOD_CAPS }, | 23 | { XKB_MOD_NAME_CAPS, WLC_BIT_MOD_CAPS }, |
24 | { XKB_MOD_NAME_CTRL, WLC_BIT_MOD_CTRL }, | 24 | { XKB_MOD_NAME_CTRL, WLC_BIT_MOD_CTRL }, |
@@ -29,11 +29,46 @@ struct modifier_key modifiers[] = { | |||
29 | { "Mod5", WLC_BIT_MOD_MOD5 }, | 29 | { "Mod5", WLC_BIT_MOD_MOD5 }, |
30 | }; | 30 | }; |
31 | 31 | ||
32 | bool cmd_bindsym(struct sway_config *config, int argc, char **argv) { | 32 | enum expected_args { |
33 | if (argc < 2) { | 33 | EXPECTED_MORE_THAN, |
34 | sway_log(L_ERROR, "Invalid set command (expected 2 arguments, got %d)", argc); | 34 | EXPECTED_LESS_THAN, |
35 | return false; | 35 | EXPECTED_EQUAL_TO |
36 | }; | ||
37 | |||
38 | static bool checkarg(int argc, char *name, enum expected_args type, int val) { | ||
39 | switch (type) { | ||
40 | case EXPECTED_MORE_THAN: | ||
41 | if (argc > val) { | ||
42 | return true; | ||
43 | } | ||
44 | sway_log(L_ERROR, "Invalid %s command." | ||
45 | "(expected more then %d argument%s, got %d", | ||
46 | name, val, (char*[2]){"s", ""}[argc==1], argc); | ||
47 | break; | ||
48 | case EXPECTED_LESS_THAN: | ||
49 | if (argc < val) { | ||
50 | return true; | ||
51 | }; | ||
52 | sway_log(L_ERROR, "Invalid %s command." | ||
53 | "(expected less then %d argument%s, got %d", | ||
54 | name, val, (char*[2]){"s", ""}[argc==1], argc); | ||
55 | break; | ||
56 | case EXPECTED_EQUAL_TO: | ||
57 | if (argc == val) { | ||
58 | return true; | ||
59 | }; | ||
60 | sway_log(L_ERROR, "Invalid %s command." | ||
61 | "(expected %d arguments, got %d", name, val, argc); | ||
62 | break; | ||
36 | } | 63 | } |
64 | return false; | ||
65 | } | ||
66 | |||
67 | |||
68 | static bool cmd_bindsym(struct sway_config *config, int argc, char **argv) { | ||
69 | if (!checkarg(argc, "bindsym", EXPECTED_MORE_THAN, 1)) { | ||
70 | return false; | ||
71 | }; | ||
37 | 72 | ||
38 | struct sway_binding *binding = malloc(sizeof(struct sway_binding)); | 73 | struct sway_binding *binding = malloc(sizeof(struct sway_binding)); |
39 | binding->keys = create_list(); | 74 | binding->keys = create_list(); |
@@ -73,46 +108,43 @@ bool cmd_bindsym(struct sway_config *config, int argc, char **argv) { | |||
73 | return true; | 108 | return true; |
74 | } | 109 | } |
75 | 110 | ||
76 | bool cmd_exec(struct sway_config *config, int argc, char **argv) { | 111 | static bool cmd_exec_always(struct sway_config *config, int argc, char **argv) { |
77 | if (argc < 1) { | 112 | if (!checkarg(argc, "exec_always", EXPECTED_MORE_THAN, 0)) { |
78 | sway_log(L_ERROR, "Invalid exec command (expected at least 1 argument, got %d)", argc); | ||
79 | return false; | 113 | return false; |
80 | } | 114 | } |
81 | 115 | ||
82 | if (config->reloading) { | 116 | pid_t pid = fork(); |
83 | sway_log(L_DEBUG, "Ignoring exec %s due to reload", join_args(argv, argc)); | 117 | /* Failed to fork */ |
84 | return true; | 118 | if (pid < 0) { |
119 | sway_log(L_ERROR, "exec command failed, sway did not fork"); | ||
120 | return false; | ||
85 | } | 121 | } |
86 | 122 | /* Child process */ | |
87 | if (fork() == 0) { | 123 | if (pid == 0) { |
88 | char *args = join_args(argv, argc); | 124 | char *args = join_args(argv, argc); |
89 | sway_log(L_DEBUG, "Executing %s", args); | 125 | sway_log(L_DEBUG, "Executing %s", args); |
90 | execl("/bin/sh", "sh", "-c", args, (char *)NULL); | 126 | execl("/bin/sh", "sh", "-c", args, (char *)NULL); |
127 | /* Execl doesnt return unless failure */ | ||
128 | sway_log(L_ERROR, "could not find /bin/sh"); | ||
91 | free(args); | 129 | free(args); |
92 | exit(0); | 130 | exit(-1); |
93 | } | 131 | } |
132 | /* Parent */ | ||
94 | return true; | 133 | return true; |
95 | } | 134 | } |
96 | 135 | ||
97 | bool cmd_exec_always(struct sway_config *config, int argc, char **argv) { | 136 | static bool cmd_exec(struct sway_config *config, int argc, char **argv) { |
98 | if (argc < 1) { | 137 | if (config->reloading) { |
99 | sway_log(L_ERROR, "Invalid exec_always command (expected at least 1 argument, got %d)", argc); | ||
100 | return false; | ||
101 | } | ||
102 | |||
103 | if (fork() == 0) { | ||
104 | char *args = join_args(argv, argc); | 138 | char *args = join_args(argv, argc); |
105 | sway_log(L_DEBUG, "Executing %s", args); | 139 | sway_log(L_DEBUG, "Ignoring exec %s due to reload", args); |
106 | execl("/bin/sh", "sh", "-c", args, (char *)NULL); | ||
107 | free(args); | 140 | free(args); |
108 | exit(0); | 141 | return true; |
109 | } | 142 | } |
110 | return true; | 143 | return cmd_exec_always(config, argc, argv); |
111 | } | 144 | } |
112 | 145 | ||
113 | bool cmd_exit(struct sway_config *config, int argc, char **argv) { | 146 | static bool cmd_exit(struct sway_config *config, int argc, char **argv) { |
114 | if (argc != 0) { | 147 | if (!checkarg(argc, "exit", EXPECTED_EQUAL_TO, 0)) { |
115 | sway_log(L_ERROR, "Invalid exit command (expected 1 arguments, got %d)", argc); | ||
116 | return false; | 148 | return false; |
117 | } | 149 | } |
118 | // TODO: Some kind of clean up is probably in order | 150 | // TODO: Some kind of clean up is probably in order |
@@ -120,9 +152,8 @@ bool cmd_exit(struct sway_config *config, int argc, char **argv) { | |||
120 | return true; | 152 | return true; |
121 | } | 153 | } |
122 | 154 | ||
123 | bool cmd_focus(struct sway_config *config, int argc, char **argv) { | 155 | static bool cmd_focus(struct sway_config *config, int argc, char **argv) { |
124 | if (argc != 1) { | 156 | if (!checkarg(argc, "focus", EXPECTED_EQUAL_TO, 1)) { |
125 | sway_log(L_ERROR, "Invalid focus command (expected 1 arguments, got %d)", argc); | ||
126 | return false; | 157 | return false; |
127 | } | 158 | } |
128 | if (strcasecmp(argv[0], "left") == 0) { | 159 | if (strcasecmp(argv[0], "left") == 0) { |
@@ -139,9 +170,8 @@ bool cmd_focus(struct sway_config *config, int argc, char **argv) { | |||
139 | return true; | 170 | return true; |
140 | } | 171 | } |
141 | 172 | ||
142 | bool cmd_focus_follows_mouse(struct sway_config *config, int argc, char **argv) { | 173 | static bool cmd_focus_follows_mouse(struct sway_config *config, int argc, char **argv) { |
143 | if (argc != 1) { | 174 | if (!checkarg(argc, "focus_follows_mouse", EXPECTED_EQUAL_TO, 1)) { |
144 | sway_log(L_ERROR, "Invalid focus_follows_mouse command (expected 1 arguments, got %d)", argc); | ||
145 | return false; | 175 | return false; |
146 | } | 176 | } |
147 | 177 | ||
@@ -149,9 +179,8 @@ bool cmd_focus_follows_mouse(struct sway_config *config, int argc, char **argv) | |||
149 | return true; | 179 | return true; |
150 | } | 180 | } |
151 | 181 | ||
152 | bool cmd_layout(struct sway_config *config, int argc, char **argv) { | 182 | static bool cmd_layout(struct sway_config *config, int argc, char **argv) { |
153 | if (argc < 1) { | 183 | if (!checkarg(argc, "layout", EXPECTED_MORE_THAN, 0)) { |
154 | sway_log(L_ERROR, "Invalid layout command (expected at least 1 argument, got %d)", argc); | ||
155 | return false; | 184 | return false; |
156 | } | 185 | } |
157 | swayc_t *parent = get_focused_container(&root_container); | 186 | swayc_t *parent = get_focused_container(&root_container); |
@@ -174,9 +203,8 @@ bool cmd_layout(struct sway_config *config, int argc, char **argv) { | |||
174 | return true; | 203 | return true; |
175 | } | 204 | } |
176 | 205 | ||
177 | bool cmd_reload(struct sway_config *config, int argc, char **argv) { | 206 | static bool cmd_reload(struct sway_config *config, int argc, char **argv) { |
178 | if (argc != 0) { | 207 | if (!checkarg(argc, "reload", EXPECTED_EQUAL_TO, 0)) { |
179 | sway_log(L_ERROR, "Invalid reload command (expected 0 arguments, got %d)", argc); | ||
180 | return false; | 208 | return false; |
181 | } | 209 | } |
182 | if (!load_config()) { | 210 | if (!load_config()) { |
@@ -186,9 +214,8 @@ bool cmd_reload(struct sway_config *config, int argc, char **argv) { | |||
186 | return true; | 214 | return true; |
187 | } | 215 | } |
188 | 216 | ||
189 | bool cmd_set(struct sway_config *config, int argc, char **argv) { | 217 | static bool cmd_set(struct sway_config *config, int argc, char **argv) { |
190 | if (argc != 2) { | 218 | if (!checkarg(argc, "set", EXPECTED_EQUAL_TO, 2)) { |
191 | sway_log(L_ERROR, "Invalid set command (expected 2 arguments, got %d)", argc); | ||
192 | return false; | 219 | return false; |
193 | } | 220 | } |
194 | struct sway_variable *var = malloc(sizeof(struct sway_variable)); | 221 | struct sway_variable *var = malloc(sizeof(struct sway_variable)); |
@@ -200,9 +227,11 @@ bool cmd_set(struct sway_config *config, int argc, char **argv) { | |||
200 | return true; | 227 | return true; |
201 | } | 228 | } |
202 | 229 | ||
203 | bool _do_split(struct sway_config *config, int argc, char **argv, int layout) { | 230 | static bool _do_split(struct sway_config *config, int argc, char **argv, int layout) { |
204 | if (argc != 0) { | 231 | char *name = layout == L_VERT ? "splitv": |
205 | sway_log(L_ERROR, "Invalid splitv command (expected 0 arguments, got %d)", argc); | 232 | layout == L_HORIZ ? "splith": |
233 | "split"; | ||
234 | if (!checkarg(argc, name, EXPECTED_EQUAL_TO, 0)) { | ||
206 | return false; | 235 | return false; |
207 | } | 236 | } |
208 | swayc_t *focused = get_focused_container(&root_container); | 237 | swayc_t *focused = get_focused_container(&root_container); |
@@ -225,20 +254,18 @@ bool _do_split(struct sway_config *config, int argc, char **argv, int layout) { | |||
225 | return true; | 254 | return true; |
226 | } | 255 | } |
227 | 256 | ||
228 | bool cmd_splitv(struct sway_config *config, int argc, char **argv) { | 257 | static bool cmd_splitv(struct sway_config *config, int argc, char **argv) { |
229 | return _do_split(config, argc, argv, L_VERT); | 258 | return _do_split(config, argc, argv, L_VERT); |
230 | } | 259 | } |
231 | 260 | ||
232 | bool cmd_splith(struct sway_config *config, int argc, char **argv) { | 261 | static bool cmd_splith(struct sway_config *config, int argc, char **argv) { |
233 | return _do_split(config, argc, argv, L_HORIZ); | 262 | return _do_split(config, argc, argv, L_HORIZ); |
234 | } | 263 | } |
235 | 264 | ||
236 | bool cmd_log_colors(struct sway_config *config, int argc, char **argv) { | 265 | static bool cmd_log_colors(struct sway_config *config, int argc, char **argv) { |
237 | if (argc != 1) { | 266 | if (!checkarg(argc, "log_colors", EXPECTED_EQUAL_TO, 1)) { |
238 | sway_log(L_ERROR, "Invalid log_colors command (expected 1 argument, got %d)", argc); | ||
239 | return false; | 267 | return false; |
240 | } | 268 | } |
241 | |||
242 | if (strcasecmp(argv[0], "no") != 0 && strcasecmp(argv[0], "yes") != 0) { | 269 | if (strcasecmp(argv[0], "no") != 0 && strcasecmp(argv[0], "yes") != 0) { |
243 | sway_log(L_ERROR, "Invalid log_colors command (expected `yes` or `no`, got '%s')", argv[0]); | 270 | sway_log(L_ERROR, "Invalid log_colors command (expected `yes` or `no`, got '%s')", argv[0]); |
244 | return false; | 271 | return false; |
@@ -248,9 +275,8 @@ bool cmd_log_colors(struct sway_config *config, int argc, char **argv) { | |||
248 | return true; | 275 | return true; |
249 | } | 276 | } |
250 | 277 | ||
251 | bool cmd_fullscreen(struct sway_config *config, int argc, char **argv) { | 278 | static bool cmd_fullscreen(struct sway_config *config, int argc, char **argv) { |
252 | if (argc != 1) { | 279 | if (!checkarg(argc, "fullscreen", EXPECTED_EQUAL_TO, 0)) { |
253 | sway_log(L_ERROR, "Invalid fullscreen command (expected 1 arguments, got %d)", argc); | ||
254 | return false; | 280 | return false; |
255 | } | 281 | } |
256 | 282 | ||
@@ -262,9 +288,8 @@ bool cmd_fullscreen(struct sway_config *config, int argc, char **argv) { | |||
262 | return true; | 288 | return true; |
263 | } | 289 | } |
264 | 290 | ||
265 | bool cmd_workspace(struct sway_config *config, int argc, char **argv) { | 291 | static bool cmd_workspace(struct sway_config *config, int argc, char **argv) { |
266 | if (argc != 1) { | 292 | if (!checkarg(argc, "workspace", EXPECTED_EQUAL_TO, 1)) { |
267 | sway_log(L_ERROR, "Invalid workspace command (expected 1 arguments, got %d)", argc); | ||
268 | return false; | 293 | return false; |
269 | } | 294 | } |
270 | 295 | ||
@@ -278,7 +303,7 @@ bool cmd_workspace(struct sway_config *config, int argc, char **argv) { | |||
278 | } | 303 | } |
279 | 304 | ||
280 | /* Keep alphabetized */ | 305 | /* Keep alphabetized */ |
281 | struct cmd_handler handlers[] = { | 306 | static struct cmd_handler handlers[] = { |
282 | { "bindsym", cmd_bindsym }, | 307 | { "bindsym", cmd_bindsym }, |
283 | { "exec", cmd_exec }, | 308 | { "exec", cmd_exec }, |
284 | { "exec_always", cmd_exec_always }, | 309 | { "exec_always", cmd_exec_always }, |
@@ -295,7 +320,7 @@ struct cmd_handler handlers[] = { | |||
295 | { "workspace", cmd_workspace } | 320 | { "workspace", cmd_workspace } |
296 | }; | 321 | }; |
297 | 322 | ||
298 | char **split_directive(char *line, int *argc) { | 323 | static char **split_directive(char *line, int *argc) { |
299 | const char *delimiters = " "; | 324 | const char *delimiters = " "; |
300 | *argc = 0; | 325 | *argc = 0; |
301 | while (isspace(*line) && *line) ++line; | 326 | while (isspace(*line) && *line) ++line; |
@@ -347,13 +372,13 @@ char **split_directive(char *line, int *argc) { | |||
347 | return parts; | 372 | return parts; |
348 | } | 373 | } |
349 | 374 | ||
350 | int handler_compare(const void *_a, const void *_b) { | 375 | static int handler_compare(const void *_a, const void *_b) { |
351 | const struct cmd_handler *a = _a; | 376 | const struct cmd_handler *a = _a; |
352 | const struct cmd_handler *b = _b; | 377 | const struct cmd_handler *b = _b; |
353 | return strcasecmp(a->command, b->command); | 378 | return strcasecmp(a->command, b->command); |
354 | } | 379 | } |
355 | 380 | ||
356 | struct cmd_handler *find_handler(struct cmd_handler handlers[], int l, char *line) { | 381 | static struct cmd_handler *find_handler(struct cmd_handler handlers[], int l, char *line) { |
357 | struct cmd_handler d = { .command=line }; | 382 | struct cmd_handler d = { .command=line }; |
358 | struct cmd_handler *res = bsearch(&d, handlers, l, sizeof(struct cmd_handler), handler_compare); | 383 | struct cmd_handler *res = bsearch(&d, handlers, l, sizeof(struct cmd_handler), handler_compare); |
359 | return res; | 384 | return res; |
@@ -395,7 +420,7 @@ bool handle_command(struct sway_config *config, char *exec) { | |||
395 | sway_log(L_ERROR, "Command failed: %s", cmd); | 420 | sway_log(L_ERROR, "Command failed: %s", cmd); |
396 | } | 421 | } |
397 | } | 422 | } |
398 | if(ptr) { | 423 | if (ptr) { |
399 | free(cmd); | 424 | free(cmd); |
400 | } | 425 | } |
401 | return exec_success; | 426 | return exec_success; |
diff --git a/sway/handlers.c b/sway/handlers.c index 78ca1363..fe7de75b 100644 --- a/sway/handlers.c +++ b/sway/handlers.c | |||
@@ -9,16 +9,16 @@ | |||
9 | #include "commands.h" | 9 | #include "commands.h" |
10 | #include "handlers.h" | 10 | #include "handlers.h" |
11 | 11 | ||
12 | bool handle_output_created(wlc_handle output) { | 12 | static bool handle_output_created(wlc_handle output) { |
13 | add_output(output); | 13 | add_output(output); |
14 | return true; | 14 | return true; |
15 | } | 15 | } |
16 | 16 | ||
17 | void handle_output_destroyed(wlc_handle output) { | 17 | static void handle_output_destroyed(wlc_handle output) { |
18 | destroy_output(output); | 18 | destroy_output(output); |
19 | } | 19 | } |
20 | 20 | ||
21 | void handle_output_resolution_change(wlc_handle output, const struct wlc_size *from, const struct wlc_size *to) { | 21 | static void handle_output_resolution_change(wlc_handle output, const struct wlc_size *from, const struct wlc_size *to) { |
22 | sway_log(L_DEBUG, "Output %d resolution changed to %d x %d", output, to->w, to->h); | 22 | sway_log(L_DEBUG, "Output %d resolution changed to %d x %d", output, to->w, to->h); |
23 | swayc_t *c = get_swayc_for_handle(output, &root_container); | 23 | swayc_t *c = get_swayc_for_handle(output, &root_container); |
24 | if (!c) return; | 24 | if (!c) return; |
@@ -27,7 +27,7 @@ void handle_output_resolution_change(wlc_handle output, const struct wlc_size *f | |||
27 | arrange_windows(&root_container, -1, -1); | 27 | arrange_windows(&root_container, -1, -1); |
28 | } | 28 | } |
29 | 29 | ||
30 | void handle_output_focused(wlc_handle output, bool focus) { | 30 | static void handle_output_focused(wlc_handle output, bool focus) { |
31 | swayc_t *c = get_swayc_for_handle(output, &root_container); | 31 | swayc_t *c = get_swayc_for_handle(output, &root_container); |
32 | if (!c) return; | 32 | if (!c) return; |
33 | if (focus) { | 33 | if (focus) { |
@@ -36,27 +36,26 @@ void handle_output_focused(wlc_handle output, bool focus) { | |||
36 | } | 36 | } |
37 | } | 37 | } |
38 | 38 | ||
39 | bool handle_view_created(wlc_handle view) { | 39 | static bool handle_view_created(wlc_handle view) { |
40 | add_view(view); | 40 | add_view(view); |
41 | return true; | 41 | return true; |
42 | } | 42 | } |
43 | 43 | ||
44 | void handle_view_destroyed(wlc_handle view) { | 44 | static void handle_view_destroyed(wlc_handle view) { |
45 | sway_log(L_DEBUG, "Destroying window %d", view); | 45 | sway_log(L_DEBUG, "Destroying window %d", view); |
46 | destroy_view(get_swayc_for_handle(view, &root_container)); | 46 | destroy_view(get_swayc_for_handle(view, &root_container)); |
47 | return true; | ||
48 | } | 47 | } |
49 | 48 | ||
50 | void handle_view_focus(wlc_handle view, bool focus) { | 49 | static void handle_view_focus(wlc_handle view, bool focus) { |
51 | return; | 50 | return; |
52 | } | 51 | } |
53 | 52 | ||
54 | void handle_view_geometry_request(wlc_handle view, const struct wlc_geometry* geometry) { | 53 | static void handle_view_geometry_request(wlc_handle view, const struct wlc_geometry* geometry) { |
55 | // deny that shit | 54 | // deny that shit |
56 | } | 55 | } |
57 | 56 | ||
58 | 57 | ||
59 | bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifiers | 58 | static bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifiers |
60 | *modifiers, uint32_t key, uint32_t sym, enum wlc_key_state state) { | 59 | *modifiers, uint32_t key, uint32_t sym, enum wlc_key_state state) { |
61 | enum { QSIZE = 32 }; | 60 | enum { QSIZE = 32 }; |
62 | static uint8_t head = 0; | 61 | static uint8_t head = 0; |
@@ -133,7 +132,7 @@ bool pointer_test(swayc_t *view, void *_origin) { | |||
133 | 132 | ||
134 | struct wlc_origin mouse_origin; | 133 | struct wlc_origin mouse_origin; |
135 | 134 | ||
136 | bool handle_pointer_motion(wlc_handle view, uint32_t time, const struct wlc_origin *origin) { | 135 | static bool handle_pointer_motion(wlc_handle view, uint32_t time, const struct wlc_origin *origin) { |
137 | mouse_origin = *origin; | 136 | mouse_origin = *origin; |
138 | if (!config->focus_follows_mouse) { | 137 | if (!config->focus_follows_mouse) { |
139 | return true; | 138 | return true; |
@@ -148,7 +147,7 @@ bool handle_pointer_motion(wlc_handle view, uint32_t time, const struct wlc_orig | |||
148 | return true; | 147 | return true; |
149 | } | 148 | } |
150 | 149 | ||
151 | bool handle_pointer_button(wlc_handle view, uint32_t time, const struct wlc_modifiers *modifiers, | 150 | static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct wlc_modifiers *modifiers, |
152 | uint32_t button, enum wlc_button_state state) { | 151 | uint32_t button, enum wlc_button_state state) { |
153 | if (state == WLC_BUTTON_STATE_PRESSED) { | 152 | if (state == WLC_BUTTON_STATE_PRESSED) { |
154 | swayc_t *c = find_container(&root_container, pointer_test, &mouse_origin); | 153 | swayc_t *c = find_container(&root_container, pointer_test, &mouse_origin); |
@@ -163,3 +162,29 @@ bool handle_pointer_button(wlc_handle view, uint32_t time, const struct wlc_modi | |||
163 | } | 162 | } |
164 | return true; | 163 | return true; |
165 | } | 164 | } |
165 | |||
166 | |||
167 | struct wlc_interface interface = { | ||
168 | .output = { | ||
169 | .created = handle_output_created, | ||
170 | .destroyed = handle_output_destroyed, | ||
171 | .resolution = handle_output_resolution_change, | ||
172 | .focus = handle_output_focused | ||
173 | }, | ||
174 | .view = { | ||
175 | .created = handle_view_created, | ||
176 | .destroyed = handle_view_destroyed, | ||
177 | .focus = handle_view_focus, | ||
178 | .request = { | ||
179 | .geometry = handle_view_geometry_request | ||
180 | } | ||
181 | }, | ||
182 | .keyboard = { | ||
183 | .key = handle_key | ||
184 | }, | ||
185 | .pointer = { | ||
186 | .motion = handle_pointer_motion, | ||
187 | .button = handle_pointer_button | ||
188 | } | ||
189 | }; | ||
190 | |||
diff --git a/sway/handlers.h b/sway/handlers.h index 9792b6d7..798b3b50 100644 --- a/sway/handlers.h +++ b/sway/handlers.h | |||
@@ -4,21 +4,6 @@ | |||
4 | #include <stdbool.h> | 4 | #include <stdbool.h> |
5 | #include <wlc/wlc.h> | 5 | #include <wlc/wlc.h> |
6 | 6 | ||
7 | bool handle_output_created(wlc_handle output); | 7 | extern struct wlc_interface interface; |
8 | void handle_output_destroyed(wlc_handle output); | ||
9 | void handle_output_resolution_change(wlc_handle output, const struct wlc_size *from, const struct wlc_size *to); | ||
10 | void handle_output_focused(wlc_handle output, bool focus); | ||
11 | |||
12 | bool handle_view_created(wlc_handle view); | ||
13 | void handle_view_destroyed(wlc_handle view); | ||
14 | void handle_view_focus(wlc_handle view, bool focus); | ||
15 | void handle_view_geometry_request(wlc_handle view, const struct wlc_geometry* geometry); | ||
16 | |||
17 | bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifiers | ||
18 | *modifiers, uint32_t key, uint32_t sym, enum wlc_key_state state); | ||
19 | |||
20 | bool handle_pointer_motion(wlc_handle view, uint32_t time, const struct wlc_origin *origin); | ||
21 | bool handle_pointer_button(wlc_handle view, uint32_t time, const struct wlc_modifiers *modifiers, | ||
22 | uint32_t button, enum wlc_button_state state); | ||
23 | 8 | ||
24 | #endif | 9 | #endif |
@@ -2,6 +2,8 @@ | |||
2 | #include <stdarg.h> | 2 | #include <stdarg.h> |
3 | #include <stdio.h> | 3 | #include <stdio.h> |
4 | #include <stdlib.h> | 4 | #include <stdlib.h> |
5 | #include <fcntl.h> | ||
6 | #include <unistd.h> | ||
5 | 7 | ||
6 | int colored = 1; | 8 | int colored = 1; |
7 | int v = 0; | 9 | int v = 0; |
@@ -15,6 +17,16 @@ const char *verbosity_colors[] = { | |||
15 | 17 | ||
16 | void init_log(int verbosity) { | 18 | void init_log(int verbosity) { |
17 | v = verbosity; | 19 | v = verbosity; |
20 | /* set FD_CLOEXEC flag to prevent programs called with exec to write into | ||
21 | * logs */ | ||
22 | int i, flag; | ||
23 | int fd[] = { STDOUT_FILENO, STDIN_FILENO, STDERR_FILENO }; | ||
24 | for (i = 0; i < 3; ++i) { | ||
25 | flag = fcntl(fd[i], F_GETFD); | ||
26 | if (flag != -1) { | ||
27 | fcntl(fd[i], F_SETFD, flag | FD_CLOEXEC); | ||
28 | } | ||
29 | } | ||
18 | } | 30 | } |
19 | 31 | ||
20 | void sway_log_colors(int mode) { | 32 | void sway_log_colors(int mode) { |
diff --git a/sway/main.c b/sway/main.c index a7814364..7477b08c 100644 --- a/sway/main.c +++ b/sway/main.c | |||
@@ -2,40 +2,22 @@ | |||
2 | #include <stdlib.h> | 2 | #include <stdlib.h> |
3 | #include <stdbool.h> | 3 | #include <stdbool.h> |
4 | #include <wlc/wlc.h> | 4 | #include <wlc/wlc.h> |
5 | #include <sys/wait.h> | ||
6 | #include <signal.h> | ||
5 | #include "layout.h" | 7 | #include "layout.h" |
6 | #include "config.h" | 8 | #include "config.h" |
7 | #include "log.h" | 9 | #include "log.h" |
8 | #include "handlers.h" | 10 | #include "handlers.h" |
9 | 11 | ||
12 | static void sigchld_handle(int signal); | ||
10 | 13 | ||
11 | int main(int argc, char **argv) { | 14 | int main(int argc, char **argv) { |
12 | init_log(L_DEBUG); // TODO: Control this with command line arg | 15 | init_log(L_DEBUG); // TODO: Control this with command line arg |
13 | init_layout(); | 16 | init_layout(); |
14 | 17 | ||
15 | static struct wlc_interface interface = { | 18 | /* Signal handling */ |
16 | .output = { | 19 | signal(SIGCHLD, sigchld_handle); |
17 | .created = handle_output_created, | 20 | |
18 | .destroyed = handle_output_destroyed, | ||
19 | .resolution = handle_output_resolution_change, | ||
20 | .focus = handle_output_focused | ||
21 | }, | ||
22 | .view = { | ||
23 | .created = handle_view_created, | ||
24 | .destroyed = handle_view_destroyed, | ||
25 | .focus = handle_view_focus, | ||
26 | .request = { | ||
27 | .geometry = handle_view_geometry_request | ||
28 | } | ||
29 | }, | ||
30 | .keyboard = { | ||
31 | .key = handle_key | ||
32 | }, | ||
33 | .pointer = { | ||
34 | .motion = handle_pointer_motion, | ||
35 | .button = handle_pointer_button | ||
36 | } | ||
37 | |||
38 | }; | ||
39 | 21 | ||
40 | setenv("WLC_DIM", "0", 0); | 22 | setenv("WLC_DIM", "0", 0); |
41 | if (!wlc_init(&interface, argc, argv)) { | 23 | if (!wlc_init(&interface, argc, argv)) { |
@@ -50,3 +32,8 @@ int main(int argc, char **argv) { | |||
50 | wlc_run(); | 32 | wlc_run(); |
51 | return 0; | 33 | return 0; |
52 | } | 34 | } |
35 | |||
36 | static void sigchld_handle(int signal) { | ||
37 | (void) signal; | ||
38 | while (waitpid((pid_t)-1, 0, WNOHANG) > 0); | ||
39 | } | ||
diff --git a/sway/movement.c b/sway/movement.c index a55d0350..166e6508 100644 --- a/sway/movement.c +++ b/sway/movement.c | |||
@@ -5,7 +5,7 @@ | |||
5 | #include "layout.h" | 5 | #include "layout.h" |
6 | #include "movement.h" | 6 | #include "movement.h" |
7 | 7 | ||
8 | int move_focus(enum movement_direction direction) { | 8 | bool move_focus(enum movement_direction direction) { |
9 | swayc_t *current = get_focused_container(&root_container); | 9 | swayc_t *current = get_focused_container(&root_container); |
10 | swayc_t *parent = current->parent; | 10 | swayc_t *parent = current->parent; |
11 | 11 | ||
@@ -14,12 +14,12 @@ int move_focus(enum movement_direction direction) { | |||
14 | parent = parent->parent; | 14 | parent = parent->parent; |
15 | if (parent->type == C_ROOT) { | 15 | if (parent->type == C_ROOT) { |
16 | sway_log(L_DEBUG, "Focus cannot move to parent"); | 16 | sway_log(L_DEBUG, "Focus cannot move to parent"); |
17 | return 1; | 17 | return false; |
18 | } else { | 18 | } else { |
19 | sway_log(L_DEBUG, "Moving focus away from %p", current); | 19 | sway_log(L_DEBUG, "Moving focus away from %p", current); |
20 | unfocus_all(parent); | 20 | unfocus_all(parent); |
21 | focus_view(parent); | 21 | focus_view(parent); |
22 | return 0; | 22 | return true; |
23 | } | 23 | } |
24 | } | 24 | } |
25 | 25 | ||
@@ -56,7 +56,7 @@ int move_focus(enum movement_direction direction) { | |||
56 | } else { | 56 | } else { |
57 | unfocus_all(&root_container); | 57 | unfocus_all(&root_container); |
58 | focus_view(parent->children->items[desired]); | 58 | focus_view(parent->children->items[desired]); |
59 | return 0; | 59 | return true; |
60 | } | 60 | } |
61 | } | 61 | } |
62 | if (!can_move) { | 62 | if (!can_move) { |
@@ -65,7 +65,7 @@ int move_focus(enum movement_direction direction) { | |||
65 | parent = parent->parent; | 65 | parent = parent->parent; |
66 | if (parent->type == C_ROOT) { | 66 | if (parent->type == C_ROOT) { |
67 | // Nothing we can do | 67 | // Nothing we can do |
68 | return 1; | 68 | return false; |
69 | } | 69 | } |
70 | } | 70 | } |
71 | } | 71 | } |
diff --git a/sway/movement.h b/sway/movement.h index a527674c..dd701877 100644 --- a/sway/movement.h +++ b/sway/movement.h | |||
@@ -12,6 +12,6 @@ enum movement_direction { | |||
12 | MOVE_PARENT | 12 | MOVE_PARENT |
13 | }; | 13 | }; |
14 | 14 | ||
15 | int move_focus(enum movement_direction direction); | 15 | bool move_focus(enum movement_direction direction); |
16 | 16 | ||
17 | #endif | 17 | #endif |