aboutsummaryrefslogtreecommitdiff
path: root/sway/commands/assign.c
diff options
context:
space:
mode:
authorRyan Dwyer <ryandwyer1@gmail.com>2018-05-13 08:16:36 +1000
committerRyan Dwyer <ryandwyer1@gmail.com>2018-05-14 11:38:09 +1000
commit1e9aaa54a85e98d6b46ca594b4f50770f71047ea (patch)
treecb6a2748d1c53dfc80f9faa5da7052790e668400 /sway/commands/assign.c
parent270c1ee7e507f1d2960920a7f4f0cc70f4e13d26 (diff)
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/assign.c')
-rw-r--r--sway/commands/assign.c58
1 files changed, 26 insertions, 32 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);
}