aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar S. Christoffer Eliesen <christoffer@eliesen.no>2015-11-18 19:03:24 +0100
committerLibravatar S. Christoffer Eliesen <christoffer@eliesen.no>2015-11-24 16:29:28 +0100
commitdb92920cf9bcdd0008ba446df4d7249e7902373a (patch)
tree4f706f14f54c2f250c8bb2d720072b9443ea7777
parentstringop: Properly handle criteria strings. (diff)
downloadsway-db92920cf9bcdd0008ba446df4d7249e7902373a.tar.gz
sway-db92920cf9bcdd0008ba446df4d7249e7902373a.tar.zst
sway-db92920cf9bcdd0008ba446df4d7249e7902373a.zip
handle_command: Skip commands that has a criteria string.
We can't handle them currently (the criteria needs to e.g. be passed to each command handler which then needs to do the right thing), so it's better to just do nothing than to create unexpected results (because the command was executed on the wrong view). (Before this patch any command list with a criteria string would simply fail to parse, so this is at least a step in the right direction.)
-rw-r--r--sway/commands.c21
1 files changed, 19 insertions, 2 deletions
diff --git a/sway/commands.c b/sway/commands.c
index f6d56bb4..42105d5f 100644
--- a/sway/commands.c
+++ b/sway/commands.c
@@ -1401,17 +1401,34 @@ struct cmd_results *handle_command(char *_exec) {
1401 1401
1402 head = exec; 1402 head = exec;
1403 do { 1403 do {
1404 // Handle criteria 1404 // Extract criteria (valid for this command list only).
1405 criteria = NULL;
1405 if (*head == '[') { 1406 if (*head == '[') {
1407 ++head;
1406 criteria = argsep(&head, "]"); 1408 criteria = argsep(&head, "]");
1407 if (head) { 1409 if (head) {
1408 ++head; 1410 ++head;
1409 // TODO handle criteria 1411 // TODO handle criteria
1410 } else { 1412 } else {
1411 results = cmd_results_new(CMD_INVALID, NULL, "Unmatched ["); 1413 if (!results) {
1414 results = cmd_results_new(CMD_INVALID, criteria, "Unmatched [");
1415 }
1416 goto cleanup;
1412 } 1417 }
1413 // Skip leading whitespace 1418 // Skip leading whitespace
1414 head += strspn(head, whitespace); 1419 head += strspn(head, whitespace);
1420
1421 // TODO: it will yield unexpected results to execute commands
1422 // (on any view) that where meant for certain views only.
1423 if (!results) {
1424 int len = strlen(criteria) + strlen(head) + 4;
1425 char *tmp = malloc(len);
1426 snprintf(tmp, len, "[%s] %s", criteria, head);
1427 results = cmd_results_new(CMD_INVALID, tmp,
1428 "Can't handle criteria string: Refusing to execute command");
1429 free(tmp);
1430 }
1431 goto cleanup;
1415 } 1432 }
1416 // Split command list 1433 // Split command list
1417 cmdlist = argsep(&head, ";"); 1434 cmdlist = argsep(&head, ";");