diff options
author | Drew DeVault <sir@cmpwn.com> | 2018-05-11 20:39:43 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-05-11 20:39:43 -0400 |
commit | 3e1bf721c69cb6df70c3dc3d3d4933e987339676 (patch) | |
tree | 850a10903fc975d643cee28307aa35e7523ba0bc /sway/commands.c | |
parent | 2217518bd554d0f11dafa7ec4e8f35f2e4762fbd (diff) | |
parent | 8595fc5a6f81f00ab62bfea127f8fad5c0b249de (diff) |
Merge pull request #1943 from RyanDwyer/criteria-improvements
Overhaul criteria implementation
Diffstat (limited to 'sway/commands.c')
-rw-r--r-- | sway/commands.c | 42 |
1 files changed, 16 insertions, 26 deletions
diff --git a/sway/commands.c b/sway/commands.c index 2e1cdc2c..811f6cfa 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -12,6 +12,7 @@ #include "sway/security.h" #include "sway/input/input-manager.h" #include "sway/input/seat.h" +#include "sway/tree/view.h" #include "stringop.h" #include "log.h" @@ -283,7 +284,7 @@ struct cmd_results *execute_command(char *_exec, struct sway_seat *seat) { char *head = exec; char *cmdlist; char *cmd; - list_t *containers = NULL; + list_t *views = NULL; if (seat == NULL) { // passing a NULL seat means we just pick the default seat @@ -300,31 +301,18 @@ struct cmd_results *execute_command(char *_exec, struct sway_seat *seat) { // Extract criteria (valid for this command list only). bool has_criteria = false; if (*head == '[') { - has_criteria = true; - ++head; - char *criteria_string = argsep(&head, "]"); - if (head) { - ++head; - list_t *tokens = create_list(); - char *error; - - if ((error = extract_crit_tokens(tokens, criteria_string))) { - wlr_log(L_DEBUG, "criteria string parse error: %s", error); - results = cmd_results_new(CMD_INVALID, criteria_string, - "Can't parse criteria string: %s", error); - free(error); - free(tokens); - goto cleanup; - } - containers = container_for_crit_tokens(tokens); - - free(tokens); - } else { - if (!results) { - results = cmd_results_new(CMD_INVALID, criteria_string, "Unmatched ["); - } + char *error = NULL; + struct criteria *criteria = criteria_parse(head, &error); + if (!criteria) { + results = cmd_results_new(CMD_INVALID, head, + "%s", error); + free(error); goto cleanup; } + views = criteria_get_views(criteria); + head += strlen(criteria->raw); + criteria_destroy(criteria); + has_criteria = true; // Skip leading whitespace head += strspn(head, whitespace); } @@ -381,8 +369,9 @@ struct cmd_results *execute_command(char *_exec, struct sway_seat *seat) { } free_cmd_results(res); } else { - for (int i = 0; i < containers->length; ++i) { - config->handler_context.current_container = containers->items[i]; + for (int i = 0; i < views->length; ++i) { + struct sway_view *view = views->items[i]; + config->handler_context.current_container = view->swayc; struct cmd_results *res = handler->handle(argc-1, argv+1); if (res->status != CMD_SUCCESS) { free_argv(argc, argv); @@ -400,6 +389,7 @@ struct cmd_results *execute_command(char *_exec, struct sway_seat *seat) { } while(head); cleanup: free(exec); + free(views); if (!results) { results = cmd_results_new(CMD_SUCCESS, NULL, NULL); } |