diff options
-rw-r--r-- | sway/commands.c | 41 | ||||
-rw-r--r-- | sway/sway.5.scd | 7 |
2 files changed, 27 insertions, 21 deletions
diff --git a/sway/commands.c b/sway/commands.c index 237bfc28..377f2d01 100644 --- a/sway/commands.c +++ b/sway/commands.c | |||
@@ -227,28 +227,31 @@ list_t *execute_command(char *_exec, struct sway_seat *seat, | |||
227 | 227 | ||
228 | head = exec; | 228 | head = exec; |
229 | do { | 229 | do { |
230 | // Extract criteria (valid for this command list only). | ||
231 | config->handler_context.using_criteria = false; | ||
232 | if (*head == '[') { | ||
233 | char *error = NULL; | ||
234 | struct criteria *criteria = criteria_parse(head, &error); | ||
235 | if (!criteria) { | ||
236 | list_add(res_list, cmd_results_new(CMD_INVALID, "%s", error)); | ||
237 | free(error); | ||
238 | goto cleanup; | ||
239 | } | ||
240 | views = criteria_get_views(criteria); | ||
241 | head += strlen(criteria->raw); | ||
242 | criteria_destroy(criteria); | ||
243 | config->handler_context.using_criteria = true; | ||
244 | // Skip leading whitespace | ||
245 | for (; isspace(*head); ++head) {} | ||
246 | } | ||
247 | // Split command list | 230 | // Split command list |
248 | cmdlist = argsep(&head, ";"); | 231 | cmdlist = argsep(&head, ";"); |
249 | for (; isspace(*cmdlist); ++cmdlist) {} | ||
250 | do { | 232 | do { |
251 | // Split commands | 233 | // Skip leading whitespace |
234 | for (; isspace(*cmdlist); ++cmdlist) {} | ||
235 | // Extract criteria (valid for this command chain only). | ||
236 | config->handler_context.using_criteria = false; | ||
237 | if (*cmdlist == '[') { | ||
238 | char *error = NULL; | ||
239 | struct criteria *criteria = criteria_parse(cmdlist, &error); | ||
240 | if (!criteria) { | ||
241 | list_add(res_list, | ||
242 | cmd_results_new(CMD_INVALID, "%s", error)); | ||
243 | free(error); | ||
244 | goto cleanup; | ||
245 | } | ||
246 | list_free(views); | ||
247 | views = criteria_get_views(criteria); | ||
248 | cmdlist += strlen(criteria->raw); | ||
249 | criteria_destroy(criteria); | ||
250 | config->handler_context.using_criteria = true; | ||
251 | // Skip leading whitespace | ||
252 | for (; isspace(*cmdlist); ++cmdlist) {} | ||
253 | } | ||
254 | // Split command chain into commands | ||
252 | cmd = argsep(&cmdlist, ","); | 255 | cmd = argsep(&cmdlist, ","); |
253 | for (; isspace(*cmd); ++cmd) {} | 256 | for (; isspace(*cmd); ++cmd) {} |
254 | if (strcmp(cmd, "") == 0) { | 257 | if (strcmp(cmd, "") == 0) { |
diff --git a/sway/sway.5.scd b/sway/sway.5.scd index 6d098d94..db6dda0d 100644 --- a/sway/sway.5.scd +++ b/sway/sway.5.scd | |||
@@ -45,7 +45,8 @@ the bindsym command. | |||
45 | Commands are split into several arguments using spaces. You can enclose | 45 | Commands are split into several arguments using spaces. You can enclose |
46 | arguments with quotation marks (*"..."* or *'...'*) to add spaces to a single | 46 | arguments with quotation marks (*"..."* or *'...'*) to add spaces to a single |
47 | argument. You may also run several commands in order by separating each with | 47 | argument. You may also run several commands in order by separating each with |
48 | *,* or *;*. | 48 | *,* or *;*. Criteria is retained across commands separated by *,*, but will be |
49 | reset (and allow for new criteria, if desired) for commands separated by a *;*. | ||
49 | 50 | ||
50 | Throughout the documentation, *|* is used to distinguish between arguments for | 51 | Throughout the documentation, *|* is used to distinguish between arguments for |
51 | which you may only select one. *[...]* is used for optional arguments, and | 52 | which you may only select one. *[...]* is used for optional arguments, and |
@@ -753,7 +754,9 @@ A criteria is a string in the form of, for example: | |||
753 | 754 | ||
754 | The string contains one or more (space separated) attribute/value pairs. They | 755 | The string contains one or more (space separated) attribute/value pairs. They |
755 | are used by some commands to choose which views to execute actions on. All | 756 | are used by some commands to choose which views to execute actions on. All |
756 | attributes must match for the criteria to match. | 757 | attributes must match for the criteria to match. Criteria is retained across |
758 | commands separated by a *,*, but will be reset (and allow for new criteria, if | ||
759 | desired) for commands separated by a *;*. | ||
757 | 760 | ||
758 | Criteria may be used with either the *for_window* or *assign* commands to | 761 | Criteria may be used with either the *for_window* or *assign* commands to |
759 | specify operations to perform on new views. A criteria may also be used to | 762 | specify operations to perform on new views. A criteria may also be used to |