aboutsummaryrefslogtreecommitdiff
path: root/sway/commands
diff options
context:
space:
mode:
Diffstat (limited to 'sway/commands')
-rw-r--r--sway/commands/assign.c58
-rw-r--r--sway/commands/default_border.c8
-rw-r--r--sway/commands/for_window.c35
-rw-r--r--sway/commands/move.c10
4 files changed, 48 insertions, 63 deletions
diff --git a/sway/commands/assign.c b/sway/commands/assign.c
index eb7329aa..9d15e166 100644
--- a/sway/commands/assign.c
+++ b/sway/commands/assign.c
@@ -5,6 +5,7 @@
#include "sway/criteria.h"
#include "list.h"
#include "log.h"
+#include "stringop.h"
struct cmd_results *cmd_assign(int argc, char **argv) {
struct cmd_results *error = NULL;
@@ -12,46 +13,39 @@ struct cmd_results *cmd_assign(int argc, char **argv) {
return error;
}
- char *criteria = *argv++;
+ // Create criteria
+ char *err_str = NULL;
+ struct criteria *criteria = criteria_parse(argv[0], &err_str);
+ if (!criteria) {
+ error = cmd_results_new(CMD_INVALID, "assign", err_str);
+ free(err_str);
+ return error;
+ }
+
+ ++argv;
+ int target_len = argc - 1;
if (strncmp(*argv, "→", strlen("→")) == 0) {
if (argc < 3) {
return cmd_results_new(CMD_INVALID, "assign", "Missing workspace");
}
- argv++;
+ ++argv;
+ --target_len;
}
- char *movecmd = "move container to workspace ";
- size_t arglen = strlen(movecmd) + strlen(*argv) + 1;
- char *cmdlist = calloc(1, arglen);
- if (!cmdlist) {
- return cmd_results_new(CMD_FAILURE, "assign", "Unable to allocate command list");
+ if (strcmp(*argv, "output") == 0) {
+ criteria->type = CT_ASSIGN_OUTPUT;
+ ++argv;
+ --target_len;
+ } else {
+ criteria->type = CT_ASSIGN_WORKSPACE;
}
- snprintf(cmdlist, arglen, "%s%s", movecmd, *argv);
- struct criteria *crit = malloc(sizeof(struct criteria));
- if (!crit) {
- free(cmdlist);
- return cmd_results_new(CMD_FAILURE, "assign", "Unable to allocate criteria");
- }
- crit->crit_raw = strdup(criteria);
- crit->cmdlist = cmdlist;
- crit->tokens = create_list();
- char *err_str = extract_crit_tokens(crit->tokens, crit->crit_raw);
+ criteria->target = join_args(argv, target_len);
- if (err_str) {
- error = cmd_results_new(CMD_INVALID, "assign", err_str);
- free(err_str);
- free_criteria(crit);
- } else if (crit->tokens->length == 0) {
- error = cmd_results_new(CMD_INVALID, "assign", "Found no name/value pairs in criteria");
- free_criteria(crit);
- } else if (list_seq_find(config->criteria, criteria_cmp, crit) != -1) {
- wlr_log(L_DEBUG, "assign: Duplicate, skipping.");
- free_criteria(crit);
- } else {
- wlr_log(L_DEBUG, "assign: '%s' -> '%s' added", crit->crit_raw, crit->cmdlist);
- list_add(config->criteria, crit);
- }
- return error ? error : cmd_results_new(CMD_SUCCESS, NULL, NULL);
+ list_add(config->criteria, criteria);
+ wlr_log(L_DEBUG, "assign: '%s' -> '%s' added", criteria->raw,
+ criteria->target);
+
+ return cmd_results_new(CMD_SUCCESS, NULL, NULL);
}
diff --git a/sway/commands/default_border.c b/sway/commands/default_border.c
index fcd2c075..2e356d3d 100644
--- a/sway/commands/default_border.c
+++ b/sway/commands/default_border.c
@@ -15,12 +15,12 @@ struct cmd_results *cmd_default_border(int argc, char **argv) {
config->border = B_NORMAL;
} else if (strcmp(argv[0], "pixel") == 0) {
config->border = B_PIXEL;
- if (argc == 2) {
- config->border_thickness = atoi(argv[1]);
- }
} else {
return cmd_results_new(CMD_INVALID, "default_border",
- "Expected 'default_border <none|normal|pixel>' or 'default_border pixel <px>'");
+ "Expected 'default_border <none|normal|pixel>' or 'default_border <normal|pixel> <px>'");
+ }
+ if (argc == 2) {
+ config->border_thickness = atoi(argv[1]);
}
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
diff --git a/sway/commands/for_window.c b/sway/commands/for_window.c
index dd5461f0..8c425a1d 100644
--- a/sway/commands/for_window.c
+++ b/sway/commands/for_window.c
@@ -11,31 +11,20 @@ struct cmd_results *cmd_for_window(int argc, char **argv) {
if ((error = checkarg(argc, "for_window", EXPECTED_AT_LEAST, 2))) {
return error;
}
- // add command to a criteria/command pair that is run against views when they appear.
- char *criteria = argv[0], *cmdlist = join_args(argv + 1, argc - 1);
- struct criteria *crit = calloc(sizeof(struct criteria), 1);
- if (!crit) {
- return cmd_results_new(CMD_FAILURE, "for_window", "Unable to allocate criteria");
- }
- crit->crit_raw = strdup(criteria);
- crit->cmdlist = cmdlist;
- crit->tokens = create_list();
- char *err_str = extract_crit_tokens(crit->tokens, crit->crit_raw);
-
- if (err_str) {
+ char *err_str = NULL;
+ struct criteria *criteria = criteria_parse(argv[0], &err_str);
+ if (!criteria) {
error = cmd_results_new(CMD_INVALID, "for_window", err_str);
free(err_str);
- free_criteria(crit);
- } else if (crit->tokens->length == 0) {
- error = cmd_results_new(CMD_INVALID, "for_window", "Found no name/value pairs in criteria");
- free_criteria(crit);
- } else if (list_seq_find(config->criteria, criteria_cmp, crit) != -1) {
- wlr_log(L_DEBUG, "for_window: Duplicate, skipping.");
- free_criteria(crit);
- } else {
- wlr_log(L_DEBUG, "for_window: '%s' -> '%s' added", crit->crit_raw, crit->cmdlist);
- list_add(config->criteria, crit);
+ return error;
}
- return error ? error : cmd_results_new(CMD_SUCCESS, NULL, NULL);
+
+ criteria->type = CT_COMMAND;
+ criteria->cmdlist = join_args(argv + 1, argc - 1);
+
+ list_add(config->criteria, criteria);
+ wlr_log(L_DEBUG, "for_window: '%s' -> '%s' added", criteria->raw, criteria->cmdlist);
+
+ return cmd_results_new(CMD_SUCCESS, NULL, NULL);
}
diff --git a/sway/commands/move.c b/sway/commands/move.c
index a5273ba4..890b1a8c 100644
--- a/sway/commands/move.c
+++ b/sway/commands/move.c
@@ -90,12 +90,14 @@ static struct cmd_results *cmd_move_container(struct sway_container *current,
}
free(ws_name);
struct sway_container *old_parent = current->parent;
- struct sway_container *focus = seat_get_focus_inactive(
+ struct sway_container *destination = seat_get_focus_inactive(
config->handler_context.seat, ws);
- container_move_to(current, focus);
- seat_set_focus(config->handler_context.seat, old_parent);
+ container_move_to(current, destination);
+ struct sway_container *focus = seat_get_focus_inactive(
+ config->handler_context.seat, old_parent);
+ seat_set_focus(config->handler_context.seat, focus);
container_reap_empty(old_parent);
- container_reap_empty(focus->parent);
+ container_reap_empty(destination->parent);
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
} else if (strcasecmp(argv[1], "to") == 0
&& strcasecmp(argv[2], "output") == 0) {