aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Brian Ashworth <bosrsf04@gmail.com>2019-06-05 01:31:50 -0400
committerLibravatar Drew DeVault <sir@cmpwn.com>2019-06-05 11:02:35 -0400
commitf0f5de9a9e87ca1f0d74e7cbf82ffceba51ffbe6 (patch)
tree396dc81beb04174d2b8bab75d07294c991d95d3c
parentadd seat sub command 'xcursor_theme' (diff)
downloadsway-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.
-rw-r--r--sway/commands.c41
-rw-r--r--sway/sway.5.scd7
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.
45Commands are split into several arguments using spaces. You can enclose 45Commands are split into several arguments using spaces. You can enclose
46arguments with quotation marks (*"..."* or *'...'*) to add spaces to a single 46arguments with quotation marks (*"..."* or *'...'*) to add spaces to a single
47argument. You may also run several commands in order by separating each with 47argument. 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
49reset (and allow for new criteria, if desired) for commands separated by a *;*.
49 50
50Throughout the documentation, *|* is used to distinguish between arguments for 51Throughout the documentation, *|* is used to distinguish between arguments for
51which you may only select one. *[...]* is used for optional arguments, and 52which 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
754The string contains one or more (space separated) attribute/value pairs. They 755The string contains one or more (space separated) attribute/value pairs. They
755are used by some commands to choose which views to execute actions on. All 756are used by some commands to choose which views to execute actions on. All
756attributes must match for the criteria to match. 757attributes must match for the criteria to match. Criteria is retained across
758commands separated by a *,*, but will be reset (and allow for new criteria, if
759desired) for commands separated by a *;*.
757 760
758Criteria may be used with either the *for_window* or *assign* commands to 761Criteria may be used with either the *for_window* or *assign* commands to
759specify operations to perform on new views. A criteria may also be used to 762specify operations to perform on new views. A criteria may also be used to