aboutsummaryrefslogtreecommitdiff
path: root/sway/commands/for_window.c
diff options
context:
space:
mode:
authorRyan Dwyer <RyanDwyer@users.noreply.github.com>2018-05-12 17:52:51 +1000
committerGitHub <noreply@github.com>2018-05-12 17:52:51 +1000
commit4717c71da54a45f736bdfde04ee3f0db88918799 (patch)
treefa511907ae4ca82d8ca68cc3a2be254359af091f /sway/commands/for_window.c
parent935bda0f336bb9ca45a7fb96d7ed5f08ef04432f (diff)
parent2511adffc29996b64d01d85b3de31de9a2af9096 (diff)
Merge branch 'master' into fix-crash-on-fullscreen
Diffstat (limited to 'sway/commands/for_window.c')
-rw-r--r--sway/commands/for_window.c35
1 files changed, 12 insertions, 23 deletions
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);
}