diff options
author | 2015-08-10 16:51:18 -0500 | |
---|---|---|
committer | 2015-08-10 16:51:18 -0500 | |
commit | a386d98518a5a1838fafb10a2b2cfa3a4feb85cb (patch) | |
tree | dfdb037b48e2624832e15d0c3a23e4cfe06bda0a /sway | |
parent | Merge pull request #12 from taiyu-len/master (diff) | |
download | sway-a386d98518a5a1838fafb10a2b2cfa3a4feb85cb.tar.gz sway-a386d98518a5a1838fafb10a2b2cfa3a4feb85cb.tar.zst sway-a386d98518a5a1838fafb10a2b2cfa3a4feb85cb.zip |
Changed cmd handlers to use bool instead of int
Diffstat (limited to 'sway')
-rw-r--r-- | sway/commands.c | 100 | ||||
-rw-r--r-- | sway/commands.h | 2 | ||||
-rw-r--r-- | sway/handlers.c | 6 |
3 files changed, 54 insertions, 54 deletions
diff --git a/sway/commands.c b/sway/commands.c index f1440c57..41141f87 100644 --- a/sway/commands.c +++ b/sway/commands.c | |||
@@ -29,10 +29,10 @@ struct modifier_key modifiers[] = { | |||
29 | { "Mod5", WLC_BIT_MOD_MOD5 }, | 29 | { "Mod5", WLC_BIT_MOD_MOD5 }, |
30 | }; | 30 | }; |
31 | 31 | ||
32 | int cmd_bindsym(struct sway_config *config, int argc, char **argv) { | 32 | bool cmd_bindsym(struct sway_config *config, int argc, char **argv) { |
33 | if (argc < 2) { | 33 | if (argc < 2) { |
34 | sway_log(L_ERROR, "Invalid set command (expected 2 arguments, got %d)", argc); | 34 | sway_log(L_ERROR, "Invalid set command (expected 2 arguments, got %d)", argc); |
35 | return 1; | 35 | return false; |
36 | } | 36 | } |
37 | argv[0] = do_var_replacement(config, argv[0]); | 37 | argv[0] = do_var_replacement(config, argv[0]); |
38 | 38 | ||
@@ -59,7 +59,7 @@ int cmd_bindsym(struct sway_config *config, int argc, char **argv) { | |||
59 | xkb_keysym_t sym = xkb_keysym_from_name(split->items[i], XKB_KEYSYM_CASE_INSENSITIVE); | 59 | xkb_keysym_t sym = xkb_keysym_from_name(split->items[i], XKB_KEYSYM_CASE_INSENSITIVE); |
60 | if (!sym) { | 60 | if (!sym) { |
61 | sway_log(L_ERROR, "bindsym - unknown key %s", (char *)split->items[i]); | 61 | sway_log(L_ERROR, "bindsym - unknown key %s", (char *)split->items[i]); |
62 | return 1; | 62 | return false; |
63 | } | 63 | } |
64 | xkb_keysym_t *key = malloc(sizeof(xkb_keysym_t)); | 64 | xkb_keysym_t *key = malloc(sizeof(xkb_keysym_t)); |
65 | *key = sym; | 65 | *key = sym; |
@@ -71,18 +71,18 @@ int cmd_bindsym(struct sway_config *config, int argc, char **argv) { | |||
71 | list_add(config->current_mode->bindings, binding); | 71 | list_add(config->current_mode->bindings, binding); |
72 | 72 | ||
73 | sway_log(L_DEBUG, "bindsym - Bound %s to command %s", argv[0], binding->command); | 73 | sway_log(L_DEBUG, "bindsym - Bound %s to command %s", argv[0], binding->command); |
74 | return 0; | 74 | return true; |
75 | } | 75 | } |
76 | 76 | ||
77 | int cmd_exec(struct sway_config *config, int argc, char **argv) { | 77 | bool cmd_exec(struct sway_config *config, int argc, char **argv) { |
78 | if (argc < 1) { | 78 | if (argc < 1) { |
79 | sway_log(L_ERROR, "Invalid exec command (expected at least 1 argument, got %d)", argc); | 79 | sway_log(L_ERROR, "Invalid exec command (expected at least 1 argument, got %d)", argc); |
80 | return 1; | 80 | return false; |
81 | } | 81 | } |
82 | 82 | ||
83 | if (config->reloading) { | 83 | if (config->reloading) { |
84 | sway_log(L_DEBUG, "Ignoring exec %s due to reload", join_args(argv, argc)); | 84 | sway_log(L_DEBUG, "Ignoring exec %s due to reload", join_args(argv, argc)); |
85 | return 0; | 85 | return true; |
86 | } | 86 | } |
87 | 87 | ||
88 | if (fork() == 0) { | 88 | if (fork() == 0) { |
@@ -92,13 +92,13 @@ int cmd_exec(struct sway_config *config, int argc, char **argv) { | |||
92 | free(args); | 92 | free(args); |
93 | exit(0); | 93 | exit(0); |
94 | } | 94 | } |
95 | return 0; | 95 | return true; |
96 | } | 96 | } |
97 | 97 | ||
98 | int cmd_exec_always(struct sway_config *config, int argc, char **argv) { | 98 | bool cmd_exec_always(struct sway_config *config, int argc, char **argv) { |
99 | if (argc < 1) { | 99 | if (argc < 1) { |
100 | sway_log(L_ERROR, "Invalid exec_always command (expected at least 1 argument, got %d)", argc); | 100 | sway_log(L_ERROR, "Invalid exec_always command (expected at least 1 argument, got %d)", argc); |
101 | return 1; | 101 | return false; |
102 | } | 102 | } |
103 | 103 | ||
104 | if (fork() == 0) { | 104 | if (fork() == 0) { |
@@ -108,23 +108,23 @@ int cmd_exec_always(struct sway_config *config, int argc, char **argv) { | |||
108 | free(args); | 108 | free(args); |
109 | exit(0); | 109 | exit(0); |
110 | } | 110 | } |
111 | return 0; | 111 | return true; |
112 | } | 112 | } |
113 | 113 | ||
114 | int cmd_exit(struct sway_config *config, int argc, char **argv) { | 114 | bool cmd_exit(struct sway_config *config, int argc, char **argv) { |
115 | if (argc != 0) { | 115 | if (argc != 0) { |
116 | sway_log(L_ERROR, "Invalid exit command (expected 1 arguments, got %d)", argc); | 116 | sway_log(L_ERROR, "Invalid exit command (expected 1 arguments, got %d)", argc); |
117 | return 1; | 117 | return false; |
118 | } | 118 | } |
119 | // TODO: Some kind of clean up is probably in order | 119 | // TODO: Some kind of clean up is probably in order |
120 | exit(0); | 120 | exit(0); |
121 | return 0; | 121 | return true; |
122 | } | 122 | } |
123 | 123 | ||
124 | int cmd_focus(struct sway_config *config, int argc, char **argv) { | 124 | bool cmd_focus(struct sway_config *config, int argc, char **argv) { |
125 | if (argc != 1) { | 125 | if (argc != 1) { |
126 | sway_log(L_ERROR, "Invalid focus command (expected 1 arguments, got %d)", argc); | 126 | sway_log(L_ERROR, "Invalid focus command (expected 1 arguments, got %d)", argc); |
127 | return 1; | 127 | return false; |
128 | } | 128 | } |
129 | if (strcasecmp(argv[0], "left") == 0) { | 129 | if (strcasecmp(argv[0], "left") == 0) { |
130 | return move_focus(MOVE_LEFT); | 130 | return move_focus(MOVE_LEFT); |
@@ -137,23 +137,23 @@ int cmd_focus(struct sway_config *config, int argc, char **argv) { | |||
137 | } else if (strcasecmp(argv[0], "parent") == 0) { | 137 | } else if (strcasecmp(argv[0], "parent") == 0) { |
138 | return move_focus(MOVE_PARENT); | 138 | return move_focus(MOVE_PARENT); |
139 | } | 139 | } |
140 | return 0; | 140 | return true; |
141 | } | 141 | } |
142 | 142 | ||
143 | int cmd_focus_follows_mouse(struct sway_config *config, int argc, char **argv) { | 143 | bool cmd_focus_follows_mouse(struct sway_config *config, int argc, char **argv) { |
144 | if (argc != 1) { | 144 | if (argc != 1) { |
145 | sway_log(L_ERROR, "Invalid focus_follows_mouse command (expected 1 arguments, got %d)", argc); | 145 | sway_log(L_ERROR, "Invalid focus_follows_mouse command (expected 1 arguments, got %d)", argc); |
146 | return 1; | 146 | return false; |
147 | } | 147 | } |
148 | 148 | ||
149 | config->focus_follows_mouse = !strcasecmp(argv[0], "yes"); | 149 | config->focus_follows_mouse = !strcasecmp(argv[0], "yes"); |
150 | return 0; | 150 | return true; |
151 | } | 151 | } |
152 | 152 | ||
153 | int cmd_layout(struct sway_config *config, int argc, char **argv) { | 153 | bool cmd_layout(struct sway_config *config, int argc, char **argv) { |
154 | if (argc < 1) { | 154 | if (argc < 1) { |
155 | sway_log(L_ERROR, "Invalid layout command (expected at least 1 argument, got %d)", argc); | 155 | sway_log(L_ERROR, "Invalid layout command (expected at least 1 argument, got %d)", argc); |
156 | return 1; | 156 | return false; |
157 | } | 157 | } |
158 | swayc_t *parent = get_focused_container(&root_container); | 158 | swayc_t *parent = get_focused_container(&root_container); |
159 | while (parent->type == C_VIEW) { | 159 | while (parent->type == C_VIEW) { |
@@ -172,25 +172,25 @@ int cmd_layout(struct sway_config *config, int argc, char **argv) { | |||
172 | } | 172 | } |
173 | arrange_windows(parent, parent->width, parent->height); | 173 | arrange_windows(parent, parent->width, parent->height); |
174 | 174 | ||
175 | return 0; | 175 | return true; |
176 | } | 176 | } |
177 | 177 | ||
178 | int cmd_reload(struct sway_config *config, int argc, char **argv) { | 178 | bool cmd_reload(struct sway_config *config, int argc, char **argv) { |
179 | if (argc != 0) { | 179 | if (argc != 0) { |
180 | sway_log(L_ERROR, "Invalid reload command (expected 0 arguments, got %d)", argc); | 180 | sway_log(L_ERROR, "Invalid reload command (expected 0 arguments, got %d)", argc); |
181 | return 1; | 181 | return false; |
182 | } | 182 | } |
183 | if (!load_config()) { | 183 | if (!load_config()) { |
184 | return 1; | 184 | return false; |
185 | } | 185 | } |
186 | arrange_windows(&root_container, -1, -1); | 186 | arrange_windows(&root_container, -1, -1); |
187 | return 0; | 187 | return true; |
188 | } | 188 | } |
189 | 189 | ||
190 | int cmd_set(struct sway_config *config, int argc, char **argv) { | 190 | bool cmd_set(struct sway_config *config, int argc, char **argv) { |
191 | if (argc != 2) { | 191 | if (argc != 2) { |
192 | sway_log(L_ERROR, "Invalid set command (expected 2 arguments, got %d)", argc); | 192 | sway_log(L_ERROR, "Invalid set command (expected 2 arguments, got %d)", argc); |
193 | return 1; | 193 | return false; |
194 | } | 194 | } |
195 | struct sway_variable *var = malloc(sizeof(struct sway_variable)); | 195 | struct sway_variable *var = malloc(sizeof(struct sway_variable)); |
196 | var->name = malloc(strlen(argv[0]) + 1); | 196 | var->name = malloc(strlen(argv[0]) + 1); |
@@ -198,13 +198,13 @@ int cmd_set(struct sway_config *config, int argc, char **argv) { | |||
198 | var->value = malloc(strlen(argv[1]) + 1); | 198 | var->value = malloc(strlen(argv[1]) + 1); |
199 | strcpy(var->value, argv[1]); | 199 | strcpy(var->value, argv[1]); |
200 | list_add(config->symbols, var); | 200 | list_add(config->symbols, var); |
201 | return 0; | 201 | return true; |
202 | } | 202 | } |
203 | 203 | ||
204 | int _do_split(struct sway_config *config, int argc, char **argv, int layout) { | 204 | bool _do_split(struct sway_config *config, int argc, char **argv, int layout) { |
205 | if (argc != 0) { | 205 | if (argc != 0) { |
206 | sway_log(L_ERROR, "Invalid splitv command (expected 0 arguments, got %d)", argc); | 206 | sway_log(L_ERROR, "Invalid splitv command (expected 0 arguments, got %d)", argc); |
207 | return 1; | 207 | return false; |
208 | } | 208 | } |
209 | swayc_t *focused = get_focused_container(&root_container); | 209 | swayc_t *focused = get_focused_container(&root_container); |
210 | swayc_t *parent = focused->parent; | 210 | swayc_t *parent = focused->parent; |
@@ -223,36 +223,36 @@ int _do_split(struct sway_config *config, int argc, char **argv, int layout) { | |||
223 | list_add(new_container->children, focused); | 223 | list_add(new_container->children, focused); |
224 | focus_view(focused); | 224 | focus_view(focused); |
225 | arrange_windows(parent, -1, -1); | 225 | arrange_windows(parent, -1, -1); |
226 | return 0; | 226 | return true; |
227 | } | 227 | } |
228 | 228 | ||
229 | int cmd_splitv(struct sway_config *config, int argc, char **argv) { | 229 | bool cmd_splitv(struct sway_config *config, int argc, char **argv) { |
230 | return _do_split(config, argc, argv, L_VERT); | 230 | return _do_split(config, argc, argv, L_VERT); |
231 | } | 231 | } |
232 | 232 | ||
233 | int cmd_splith(struct sway_config *config, int argc, char **argv) { | 233 | bool cmd_splith(struct sway_config *config, int argc, char **argv) { |
234 | return _do_split(config, argc, argv, L_HORIZ); | 234 | return _do_split(config, argc, argv, L_HORIZ); |
235 | } | 235 | } |
236 | 236 | ||
237 | int cmd_log_colors(struct sway_config *config, int argc, char **argv) { | 237 | bool cmd_log_colors(struct sway_config *config, int argc, char **argv) { |
238 | if (argc != 1) { | 238 | if (argc != 1) { |
239 | sway_log(L_ERROR, "Invalid log_colors command (expected 1 argument, got %d)", argc); | 239 | sway_log(L_ERROR, "Invalid log_colors command (expected 1 argument, got %d)", argc); |
240 | return 1; | 240 | return false; |
241 | } | 241 | } |
242 | 242 | ||
243 | if (strcasecmp(argv[0], "no") != 0 && strcasecmp(argv[0], "yes") != 0) { | 243 | if (strcasecmp(argv[0], "no") != 0 && strcasecmp(argv[0], "yes") != 0) { |
244 | sway_log(L_ERROR, "Invalid log_colors command (expected `yes` or `no`, got '%s')", argv[0]); | 244 | sway_log(L_ERROR, "Invalid log_colors command (expected `yes` or `no`, got '%s')", argv[0]); |
245 | return 1; | 245 | return false; |
246 | } | 246 | } |
247 | 247 | ||
248 | sway_log_colors(!strcasecmp(argv[0], "yes")); | 248 | sway_log_colors(!strcasecmp(argv[0], "yes")); |
249 | return 0; | 249 | return true; |
250 | } | 250 | } |
251 | 251 | ||
252 | int cmd_fullscreen(struct sway_config *config, int argc, char **argv) { | 252 | bool cmd_fullscreen(struct sway_config *config, int argc, char **argv) { |
253 | if (argc != 1) { | 253 | if (argc != 1) { |
254 | sway_log(L_ERROR, "Invalid fullscreen command (expected 1 arguments, got %d)", argc); | 254 | sway_log(L_ERROR, "Invalid fullscreen command (expected 1 arguments, got %d)", argc); |
255 | return 1; | 255 | return false; |
256 | } | 256 | } |
257 | 257 | ||
258 | swayc_t *container = get_focused_container(&root_container); | 258 | swayc_t *container = get_focused_container(&root_container); |
@@ -260,13 +260,13 @@ int cmd_fullscreen(struct sway_config *config, int argc, char **argv) { | |||
260 | wlc_view_set_state(container->handle, WLC_BIT_FULLSCREEN, !current); | 260 | wlc_view_set_state(container->handle, WLC_BIT_FULLSCREEN, !current); |
261 | arrange_windows(container, -1, -1); | 261 | arrange_windows(container, -1, -1); |
262 | 262 | ||
263 | return 0; | 263 | return true; |
264 | } | 264 | } |
265 | 265 | ||
266 | int cmd_workspace(struct sway_config *config, int argc, char **argv) { | 266 | bool cmd_workspace(struct sway_config *config, int argc, char **argv) { |
267 | if (argc != 1) { | 267 | if (argc != 1) { |
268 | sway_log(L_ERROR, "Invalid workspace command (expected 1 arguments, got %d)", argc); | 268 | sway_log(L_ERROR, "Invalid workspace command (expected 1 arguments, got %d)", argc); |
269 | return 1; | 269 | return false; |
270 | } | 270 | } |
271 | 271 | ||
272 | swayc_t *workspace = workspace_find_by_name(argv[0]); | 272 | swayc_t *workspace = workspace_find_by_name(argv[0]); |
@@ -275,7 +275,7 @@ int cmd_workspace(struct sway_config *config, int argc, char **argv) { | |||
275 | } else sway_log(L_DEBUG, "workspace exists, all ok"); | 275 | } else sway_log(L_DEBUG, "workspace exists, all ok"); |
276 | 276 | ||
277 | workspace_switch(workspace); | 277 | workspace_switch(workspace); |
278 | return 0; | 278 | return true; |
279 | } | 279 | } |
280 | 280 | ||
281 | /* Keep alphabetized */ | 281 | /* Keep alphabetized */ |
@@ -363,7 +363,7 @@ struct cmd_handler *find_handler(struct cmd_handler handlers[], int l, char *lin | |||
363 | int handle_command(struct sway_config *config, char *exec) { | 363 | int handle_command(struct sway_config *config, char *exec) { |
364 | sway_log(L_INFO, "Handling command '%s'", exec); | 364 | sway_log(L_INFO, "Handling command '%s'", exec); |
365 | char *ptr, *cmd; | 365 | char *ptr, *cmd; |
366 | int ret; | 366 | bool exec_success; |
367 | 367 | ||
368 | if ((ptr = strchr(exec, ' ')) == NULL) { | 368 | if ((ptr = strchr(exec, ' ')) == NULL) { |
369 | cmd = exec; | 369 | cmd = exec; |
@@ -376,22 +376,22 @@ int handle_command(struct sway_config *config, char *exec) { | |||
376 | struct cmd_handler *handler = find_handler(handlers, sizeof(handlers) / sizeof(struct cmd_handler), cmd); | 376 | struct cmd_handler *handler = find_handler(handlers, sizeof(handlers) / sizeof(struct cmd_handler), cmd); |
377 | if (handler == NULL) { | 377 | if (handler == NULL) { |
378 | sway_log(L_ERROR, "Unknown command '%s'", cmd); | 378 | sway_log(L_ERROR, "Unknown command '%s'", cmd); |
379 | ret = 0; // TODO: return error, probably | 379 | exec_success = false; // TODO: return error, probably |
380 | } else { | 380 | } else { |
381 | int argc; | 381 | int argc; |
382 | char **argv = split_directive(exec + strlen(handler->command), &argc); | 382 | char **argv = split_directive(exec + strlen(handler->command), &argc); |
383 | int i; | 383 | int i; |
384 | ret = handler->handle(config, argc, argv); | 384 | exec_success = handler->handle(config, argc, argv); |
385 | for (i = 0; i < argc; ++i) { | 385 | for (i = 0; i < argc; ++i) { |
386 | free(argv[i]); | 386 | free(argv[i]); |
387 | } | 387 | } |
388 | free(argv); | 388 | free(argv); |
389 | if (ret != 0) { | 389 | if (!exec_success) { |
390 | sway_log(L_ERROR, "Command failed: %s", cmd); | 390 | sway_log(L_ERROR, "Command failed: %s", cmd); |
391 | } | 391 | } |
392 | } | 392 | } |
393 | if(ptr) { | 393 | if(ptr) { |
394 | free(cmd); | 394 | free(cmd); |
395 | } | 395 | } |
396 | return ret; | 396 | return exec_success; |
397 | } | 397 | } |
diff --git a/sway/commands.h b/sway/commands.h index 42b39f27..19fd3f33 100644 --- a/sway/commands.h +++ b/sway/commands.h | |||
@@ -5,7 +5,7 @@ | |||
5 | 5 | ||
6 | struct cmd_handler { | 6 | struct cmd_handler { |
7 | char *command; | 7 | char *command; |
8 | int (*handle)(struct sway_config *config, int argc, char **argv); | 8 | bool (*handle)(struct sway_config *config, int argc, char **argv); |
9 | }; | 9 | }; |
10 | 10 | ||
11 | int handle_command(struct sway_config *config, char *command); | 11 | int handle_command(struct sway_config *config, char *command); |
diff --git a/sway/handlers.c b/sway/handlers.c index cdf76554..938dc3fd 100644 --- a/sway/handlers.c +++ b/sway/handlers.c | |||
@@ -51,7 +51,7 @@ bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifiers | |||
51 | // TODO: handle keybindings with more than 1 non-modifier key involved | 51 | // TODO: handle keybindings with more than 1 non-modifier key involved |
52 | // Note: reminder to check conflicts with mod+q+a versus mod+q | 52 | // Note: reminder to check conflicts with mod+q+a versus mod+q |
53 | 53 | ||
54 | bool ret = true; | 54 | bool cmd_success = true; |
55 | struct sway_mode *mode = config->current_mode; | 55 | struct sway_mode *mode = config->current_mode; |
56 | 56 | ||
57 | // Lowercase if necessary | 57 | // Lowercase if necessary |
@@ -74,12 +74,12 @@ bool handle_key(wlc_handle view, uint32_t time, const struct wlc_modifiers | |||
74 | } | 74 | } |
75 | 75 | ||
76 | if (match) { | 76 | if (match) { |
77 | ret = handle_command(config, binding->command) != 0; | 77 | cmd_success = handle_command(config, binding->command); |
78 | } | 78 | } |
79 | } | 79 | } |
80 | } | 80 | } |
81 | } | 81 | } |
82 | return ret; | 82 | return cmd_success; |
83 | } | 83 | } |
84 | 84 | ||
85 | bool pointer_test(swayc_t *view, void *_origin) { | 85 | bool pointer_test(swayc_t *view, void *_origin) { |