aboutsummaryrefslogtreecommitdiffstats
path: root/sway/commands.c
diff options
context:
space:
mode:
authorLibravatar Ryan Dwyer <ryandwyer1@gmail.com>2018-05-13 08:16:36 +1000
committerLibravatar Ryan Dwyer <ryandwyer1@gmail.com>2018-05-14 11:38:09 +1000
commit1e9aaa54a85e98d6b46ca594b4f50770f71047ea (patch)
treecb6a2748d1c53dfc80f9faa5da7052790e668400 /sway/commands.c
parentActually fix swayidle (diff)
downloadsway-1e9aaa54a85e98d6b46ca594b4f50770f71047ea.tar.gz
sway-1e9aaa54a85e98d6b46ca594b4f50770f71047ea.tar.zst
sway-1e9aaa54a85e98d6b46ca594b4f50770f71047ea.zip
Revert "Revert "Merge pull request #1943 from RyanDwyer/criteria-improvements""
This reverts commit 32a572cecfd0f6072a78ce0a381a2f8365f9010a. This reimplements the criteria overhaul in preparation for fixing a known bug.
Diffstat (limited to 'sway/commands.c')
-rw-r--r--sway/commands.c42
1 files changed, 16 insertions, 26 deletions
diff --git a/sway/commands.c b/sway/commands.c
index 37ead367..60c64776 100644
--- a/sway/commands.c
+++ b/sway/commands.c
@@ -12,6 +12,7 @@
12#include "sway/security.h" 12#include "sway/security.h"
13#include "sway/input/input-manager.h" 13#include "sway/input/input-manager.h"
14#include "sway/input/seat.h" 14#include "sway/input/seat.h"
15#include "sway/tree/view.h"
15#include "stringop.h" 16#include "stringop.h"
16#include "log.h" 17#include "log.h"
17 18
@@ -284,7 +285,7 @@ struct cmd_results *execute_command(char *_exec, struct sway_seat *seat) {
284 char *head = exec; 285 char *head = exec;
285 char *cmdlist; 286 char *cmdlist;
286 char *cmd; 287 char *cmd;
287 list_t *containers = NULL; 288 list_t *views = NULL;
288 289
289 if (seat == NULL) { 290 if (seat == NULL) {
290 // passing a NULL seat means we just pick the default seat 291 // passing a NULL seat means we just pick the default seat
@@ -301,31 +302,18 @@ struct cmd_results *execute_command(char *_exec, struct sway_seat *seat) {
301 // Extract criteria (valid for this command list only). 302 // Extract criteria (valid for this command list only).
302 bool has_criteria = false; 303 bool has_criteria = false;
303 if (*head == '[') { 304 if (*head == '[') {
304 has_criteria = true; 305 char *error = NULL;
305 ++head; 306 struct criteria *criteria = criteria_parse(head, &error);
306 char *criteria_string = argsep(&head, "]"); 307 if (!criteria) {
307 if (head) { 308 results = cmd_results_new(CMD_INVALID, head,
308 ++head; 309 "%s", error);
309 list_t *tokens = create_list(); 310 free(error);
310 char *error;
311
312 if ((error = extract_crit_tokens(tokens, criteria_string))) {
313 wlr_log(L_DEBUG, "criteria string parse error: %s", error);
314 results = cmd_results_new(CMD_INVALID, criteria_string,
315 "Can't parse criteria string: %s", error);
316 free(error);
317 free(tokens);
318 goto cleanup;
319 }
320 containers = container_for_crit_tokens(tokens);
321
322 free(tokens);
323 } else {
324 if (!results) {
325 results = cmd_results_new(CMD_INVALID, criteria_string, "Unmatched [");
326 }
327 goto cleanup; 311 goto cleanup;
328 } 312 }
313 views = criteria_get_views(criteria);
314 head += strlen(criteria->raw);
315 criteria_destroy(criteria);
316 has_criteria = true;
329 // Skip leading whitespace 317 // Skip leading whitespace
330 head += strspn(head, whitespace); 318 head += strspn(head, whitespace);
331 } 319 }
@@ -382,8 +370,9 @@ struct cmd_results *execute_command(char *_exec, struct sway_seat *seat) {
382 } 370 }
383 free_cmd_results(res); 371 free_cmd_results(res);
384 } else { 372 } else {
385 for (int i = 0; i < containers->length; ++i) { 373 for (int i = 0; i < views->length; ++i) {
386 config->handler_context.current_container = containers->items[i]; 374 struct sway_view *view = views->items[i];
375 config->handler_context.current_container = view->swayc;
387 struct cmd_results *res = handler->handle(argc-1, argv+1); 376 struct cmd_results *res = handler->handle(argc-1, argv+1);
388 if (res->status != CMD_SUCCESS) { 377 if (res->status != CMD_SUCCESS) {
389 free_argv(argc, argv); 378 free_argv(argc, argv);
@@ -401,6 +390,7 @@ struct cmd_results *execute_command(char *_exec, struct sway_seat *seat) {
401 } while(head); 390 } while(head);
402cleanup: 391cleanup:
403 free(exec); 392 free(exec);
393 free(views);
404 if (!results) { 394 if (!results) {
405 results = cmd_results_new(CMD_SUCCESS, NULL, NULL); 395 results = cmd_results_new(CMD_SUCCESS, NULL, NULL);
406 } 396 }