aboutsummaryrefslogtreecommitdiffstats
path: root/sway/commands.c
diff options
context:
space:
mode:
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 2e1cdc2c..811f6cfa 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
@@ -283,7 +284,7 @@ struct cmd_results *execute_command(char *_exec, struct sway_seat *seat) {
283 char *head = exec; 284 char *head = exec;
284 char *cmdlist; 285 char *cmdlist;
285 char *cmd; 286 char *cmd;
286 list_t *containers = NULL; 287 list_t *views = NULL;
287 288
288 if (seat == NULL) { 289 if (seat == NULL) {
289 // passing a NULL seat means we just pick the default seat 290 // passing a NULL seat means we just pick the default seat
@@ -300,31 +301,18 @@ struct cmd_results *execute_command(char *_exec, struct sway_seat *seat) {
300 // Extract criteria (valid for this command list only). 301 // Extract criteria (valid for this command list only).
301 bool has_criteria = false; 302 bool has_criteria = false;
302 if (*head == '[') { 303 if (*head == '[') {
303 has_criteria = true; 304 char *error = NULL;
304 ++head; 305 struct criteria *criteria = criteria_parse(head, &error);
305 char *criteria_string = argsep(&head, "]"); 306 if (!criteria) {
306 if (head) { 307 results = cmd_results_new(CMD_INVALID, head,
307 ++head; 308 "%s", error);
308 list_t *tokens = create_list(); 309 free(error);
309 char *error;
310
311 if ((error = extract_crit_tokens(tokens, criteria_string))) {
312 wlr_log(L_DEBUG, "criteria string parse error: %s", error);
313 results = cmd_results_new(CMD_INVALID, criteria_string,
314 "Can't parse criteria string: %s", error);
315 free(error);
316 free(tokens);
317 goto cleanup;
318 }
319 containers = container_for_crit_tokens(tokens);
320
321 free(tokens);
322 } else {
323 if (!results) {
324 results = cmd_results_new(CMD_INVALID, criteria_string, "Unmatched [");
325 }
326 goto cleanup; 310 goto cleanup;
327 } 311 }
312 views = criteria_get_views(criteria);
313 head += strlen(criteria->raw);
314 criteria_destroy(criteria);
315 has_criteria = true;
328 // Skip leading whitespace 316 // Skip leading whitespace
329 head += strspn(head, whitespace); 317 head += strspn(head, whitespace);
330 } 318 }
@@ -381,8 +369,9 @@ struct cmd_results *execute_command(char *_exec, struct sway_seat *seat) {
381 } 369 }
382 free_cmd_results(res); 370 free_cmd_results(res);
383 } else { 371 } else {
384 for (int i = 0; i < containers->length; ++i) { 372 for (int i = 0; i < views->length; ++i) {
385 config->handler_context.current_container = containers->items[i]; 373 struct sway_view *view = views->items[i];
374 config->handler_context.current_container = view->swayc;
386 struct cmd_results *res = handler->handle(argc-1, argv+1); 375 struct cmd_results *res = handler->handle(argc-1, argv+1);
387 if (res->status != CMD_SUCCESS) { 376 if (res->status != CMD_SUCCESS) {
388 free_argv(argc, argv); 377 free_argv(argc, argv);
@@ -400,6 +389,7 @@ struct cmd_results *execute_command(char *_exec, struct sway_seat *seat) {
400 } while(head); 389 } while(head);
401cleanup: 390cleanup:
402 free(exec); 391 free(exec);
392 free(views);
403 if (!results) { 393 if (!results) {
404 results = cmd_results_new(CMD_SUCCESS, NULL, NULL); 394 results = cmd_results_new(CMD_SUCCESS, NULL, NULL);
405 } 395 }