diff options
author | Drew DeVault <sir@cmpwn.com> | 2018-05-12 08:59:25 -0400 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2018-05-12 08:59:25 -0400 |
commit | a2d7079b263290ccc7259a0d16749dbd0baae821 (patch) | |
tree | 88798745e165f6f9d9f01e66b3f0d6c817353c1b /sway/commands.c | |
parent | Fix typos (diff) | |
parent | Revert "Merge pull request #1943 from RyanDwyer/criteria-improvements" (diff) | |
download | sway-a2d7079b263290ccc7259a0d16749dbd0baae821.tar.gz sway-a2d7079b263290ccc7259a0d16749dbd0baae821.tar.zst sway-a2d7079b263290ccc7259a0d16749dbd0baae821.zip |
Merge branch 'master' into scdoc
Diffstat (limited to 'sway/commands.c')
-rw-r--r-- | sway/commands.c | 42 |
1 files changed, 26 insertions, 16 deletions
diff --git a/sway/commands.c b/sway/commands.c index 811f6cfa..2e1cdc2c 100644 --- a/sway/commands.c +++ b/sway/commands.c | |||
@@ -12,7 +12,6 @@ | |||
12 | #include "sway/security.h" | 12 | #include "sway/security.h" |
13 | #include "sway/input/input-manager.h" | 13 | #include "sway/input/input-manager.h" |
14 | #include "sway/input/seat.h" | 14 | #include "sway/input/seat.h" |
15 | #include "sway/tree/view.h" | ||
16 | #include "stringop.h" | 15 | #include "stringop.h" |
17 | #include "log.h" | 16 | #include "log.h" |
18 | 17 | ||
@@ -284,7 +283,7 @@ struct cmd_results *execute_command(char *_exec, struct sway_seat *seat) { | |||
284 | char *head = exec; | 283 | char *head = exec; |
285 | char *cmdlist; | 284 | char *cmdlist; |
286 | char *cmd; | 285 | char *cmd; |
287 | list_t *views = NULL; | 286 | list_t *containers = NULL; |
288 | 287 | ||
289 | if (seat == NULL) { | 288 | if (seat == NULL) { |
290 | // passing a NULL seat means we just pick the default seat | 289 | // passing a NULL seat means we just pick the default seat |
@@ -301,18 +300,31 @@ struct cmd_results *execute_command(char *_exec, struct sway_seat *seat) { | |||
301 | // Extract criteria (valid for this command list only). | 300 | // Extract criteria (valid for this command list only). |
302 | bool has_criteria = false; | 301 | bool has_criteria = false; |
303 | if (*head == '[') { | 302 | if (*head == '[') { |
304 | char *error = NULL; | 303 | has_criteria = true; |
305 | struct criteria *criteria = criteria_parse(head, &error); | 304 | ++head; |
306 | if (!criteria) { | 305 | char *criteria_string = argsep(&head, "]"); |
307 | results = cmd_results_new(CMD_INVALID, head, | 306 | if (head) { |
308 | "%s", error); | 307 | ++head; |
309 | free(error); | 308 | list_t *tokens = create_list(); |
309 | char *error; | ||
310 | |||
311 | if ((error = extract_crit_tokens(tokens, criteria_string))) { | ||
312 | wlr_log(L_DEBUG, "criteria string parse error: %s", error); | ||
313 | results = cmd_results_new(CMD_INVALID, criteria_string, | ||
314 | "Can't parse criteria string: %s", error); | ||
315 | free(error); | ||
316 | free(tokens); | ||
317 | goto cleanup; | ||
318 | } | ||
319 | containers = container_for_crit_tokens(tokens); | ||
320 | |||
321 | free(tokens); | ||
322 | } else { | ||
323 | if (!results) { | ||
324 | results = cmd_results_new(CMD_INVALID, criteria_string, "Unmatched ["); | ||
325 | } | ||
310 | goto cleanup; | 326 | goto cleanup; |
311 | } | 327 | } |
312 | views = criteria_get_views(criteria); | ||
313 | head += strlen(criteria->raw); | ||
314 | criteria_destroy(criteria); | ||
315 | has_criteria = true; | ||
316 | // Skip leading whitespace | 328 | // Skip leading whitespace |
317 | head += strspn(head, whitespace); | 329 | head += strspn(head, whitespace); |
318 | } | 330 | } |
@@ -369,9 +381,8 @@ struct cmd_results *execute_command(char *_exec, struct sway_seat *seat) { | |||
369 | } | 381 | } |
370 | free_cmd_results(res); | 382 | free_cmd_results(res); |
371 | } else { | 383 | } else { |
372 | for (int i = 0; i < views->length; ++i) { | 384 | for (int i = 0; i < containers->length; ++i) { |
373 | struct sway_view *view = views->items[i]; | 385 | config->handler_context.current_container = containers->items[i]; |
374 | config->handler_context.current_container = view->swayc; | ||
375 | struct cmd_results *res = handler->handle(argc-1, argv+1); | 386 | struct cmd_results *res = handler->handle(argc-1, argv+1); |
376 | if (res->status != CMD_SUCCESS) { | 387 | if (res->status != CMD_SUCCESS) { |
377 | free_argv(argc, argv); | 388 | free_argv(argc, argv); |
@@ -389,7 +400,6 @@ struct cmd_results *execute_command(char *_exec, struct sway_seat *seat) { | |||
389 | } while(head); | 400 | } while(head); |
390 | cleanup: | 401 | cleanup: |
391 | free(exec); | 402 | free(exec); |
392 | free(views); | ||
393 | if (!results) { | 403 | if (!results) { |
394 | results = cmd_results_new(CMD_SUCCESS, NULL, NULL); | 404 | results = cmd_results_new(CMD_SUCCESS, NULL, NULL); |
395 | } | 405 | } |