diff options
author | Brian Ashworth <bosrsf04@gmail.com> | 2019-06-05 01:31:50 -0400 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2019-06-05 11:02:35 -0400 |
commit | f0f5de9a9e87ca1f0d74e7cbf82ffceba51ffbe6 (patch) | |
tree | 396dc81beb04174d2b8bab75d07294c991d95d3c /sway/commands.c | |
parent | add seat sub command 'xcursor_theme' (diff) | |
download | sway-f0f5de9a9e87ca1f0d74e7cbf82ffceba51ffbe6.tar.gz sway-f0f5de9a9e87ca1f0d74e7cbf82ffceba51ffbe6.tar.zst sway-f0f5de9a9e87ca1f0d74e7cbf82ffceba51ffbe6.zip |
criteria: reset on semicolon separation
This matches i3's behavior of only retaining criteria across comma
separated commands. When separating commands with a semicolon, the
criteria is reset and allows for new criteria to be set, if desired.
Diffstat (limited to 'sway/commands.c')
-rw-r--r-- | sway/commands.c | 41 |
1 files changed, 22 insertions, 19 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) { |