diff options
author | Drew DeVault <sir@cmpwn.com> | 2018-05-12 08:52:54 -0400 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2018-05-12 08:52:54 -0400 |
commit | 32a572cecfd0f6072a78ce0a381a2f8365f9010a (patch) | |
tree | ff3860acec8478bd3962145bafaa2bac19717bad /sway/commands | |
parent | Revert "Merge pull request #1953 from RyanDwyer/criteria-focused" (diff) | |
download | sway-32a572cecfd0f6072a78ce0a381a2f8365f9010a.tar.gz sway-32a572cecfd0f6072a78ce0a381a2f8365f9010a.tar.zst sway-32a572cecfd0f6072a78ce0a381a2f8365f9010a.zip |
Revert "Merge pull request #1943 from RyanDwyer/criteria-improvements"
This reverts commit 3e1bf721c69cb6df70c3dc3d3d4933e987339676, reversing
changes made to 2217518bd554d0f11dafa7ec4e8f35f2e4762fbd.
Diffstat (limited to 'sway/commands')
-rw-r--r-- | sway/commands/assign.c | 58 | ||||
-rw-r--r-- | sway/commands/for_window.c | 35 |
2 files changed, 55 insertions, 38 deletions
diff --git a/sway/commands/assign.c b/sway/commands/assign.c index 9d15e166..eb7329aa 100644 --- a/sway/commands/assign.c +++ b/sway/commands/assign.c | |||
@@ -5,7 +5,6 @@ | |||
5 | #include "sway/criteria.h" | 5 | #include "sway/criteria.h" |
6 | #include "list.h" | 6 | #include "list.h" |
7 | #include "log.h" | 7 | #include "log.h" |
8 | #include "stringop.h" | ||
9 | 8 | ||
10 | struct cmd_results *cmd_assign(int argc, char **argv) { | 9 | struct cmd_results *cmd_assign(int argc, char **argv) { |
11 | struct cmd_results *error = NULL; | 10 | struct cmd_results *error = NULL; |
@@ -13,39 +12,46 @@ struct cmd_results *cmd_assign(int argc, char **argv) { | |||
13 | return error; | 12 | return error; |
14 | } | 13 | } |
15 | 14 | ||
16 | // Create criteria | 15 | char *criteria = *argv++; |
17 | char *err_str = NULL; | ||
18 | struct criteria *criteria = criteria_parse(argv[0], &err_str); | ||
19 | if (!criteria) { | ||
20 | error = cmd_results_new(CMD_INVALID, "assign", err_str); | ||
21 | free(err_str); | ||
22 | return error; | ||
23 | } | ||
24 | |||
25 | ++argv; | ||
26 | int target_len = argc - 1; | ||
27 | 16 | ||
28 | if (strncmp(*argv, "→", strlen("→")) == 0) { | 17 | if (strncmp(*argv, "→", strlen("→")) == 0) { |
29 | if (argc < 3) { | 18 | if (argc < 3) { |
30 | return cmd_results_new(CMD_INVALID, "assign", "Missing workspace"); | 19 | return cmd_results_new(CMD_INVALID, "assign", "Missing workspace"); |
31 | } | 20 | } |
32 | ++argv; | 21 | argv++; |
33 | --target_len; | ||
34 | } | 22 | } |
35 | 23 | ||
36 | if (strcmp(*argv, "output") == 0) { | 24 | char *movecmd = "move container to workspace "; |
37 | criteria->type = CT_ASSIGN_OUTPUT; | 25 | size_t arglen = strlen(movecmd) + strlen(*argv) + 1; |
38 | ++argv; | 26 | char *cmdlist = calloc(1, arglen); |
39 | --target_len; | 27 | if (!cmdlist) { |
40 | } else { | 28 | return cmd_results_new(CMD_FAILURE, "assign", "Unable to allocate command list"); |
41 | criteria->type = CT_ASSIGN_WORKSPACE; | ||
42 | } | 29 | } |
30 | snprintf(cmdlist, arglen, "%s%s", movecmd, *argv); | ||
43 | 31 | ||
44 | criteria->target = join_args(argv, target_len); | 32 | struct criteria *crit = malloc(sizeof(struct criteria)); |
45 | 33 | if (!crit) { | |
46 | list_add(config->criteria, criteria); | 34 | free(cmdlist); |
47 | wlr_log(L_DEBUG, "assign: '%s' -> '%s' added", criteria->raw, | 35 | return cmd_results_new(CMD_FAILURE, "assign", "Unable to allocate criteria"); |
48 | criteria->target); | 36 | } |
37 | crit->crit_raw = strdup(criteria); | ||
38 | crit->cmdlist = cmdlist; | ||
39 | crit->tokens = create_list(); | ||
40 | char *err_str = extract_crit_tokens(crit->tokens, crit->crit_raw); | ||
49 | 41 | ||
50 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | 42 | if (err_str) { |
43 | error = cmd_results_new(CMD_INVALID, "assign", err_str); | ||
44 | free(err_str); | ||
45 | free_criteria(crit); | ||
46 | } else if (crit->tokens->length == 0) { | ||
47 | error = cmd_results_new(CMD_INVALID, "assign", "Found no name/value pairs in criteria"); | ||
48 | free_criteria(crit); | ||
49 | } else if (list_seq_find(config->criteria, criteria_cmp, crit) != -1) { | ||
50 | wlr_log(L_DEBUG, "assign: Duplicate, skipping."); | ||
51 | free_criteria(crit); | ||
52 | } else { | ||
53 | wlr_log(L_DEBUG, "assign: '%s' -> '%s' added", crit->crit_raw, crit->cmdlist); | ||
54 | list_add(config->criteria, crit); | ||
55 | } | ||
56 | return error ? error : cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
51 | } | 57 | } |
diff --git a/sway/commands/for_window.c b/sway/commands/for_window.c index 8c425a1d..dd5461f0 100644 --- a/sway/commands/for_window.c +++ b/sway/commands/for_window.c | |||
@@ -11,20 +11,31 @@ struct cmd_results *cmd_for_window(int argc, char **argv) { | |||
11 | if ((error = checkarg(argc, "for_window", EXPECTED_AT_LEAST, 2))) { | 11 | if ((error = checkarg(argc, "for_window", EXPECTED_AT_LEAST, 2))) { |
12 | return error; | 12 | return error; |
13 | } | 13 | } |
14 | // add command to a criteria/command pair that is run against views when they appear. | ||
15 | char *criteria = argv[0], *cmdlist = join_args(argv + 1, argc - 1); | ||
14 | 16 | ||
15 | char *err_str = NULL; | 17 | struct criteria *crit = calloc(sizeof(struct criteria), 1); |
16 | struct criteria *criteria = criteria_parse(argv[0], &err_str); | 18 | if (!crit) { |
17 | if (!criteria) { | 19 | return cmd_results_new(CMD_FAILURE, "for_window", "Unable to allocate criteria"); |
20 | } | ||
21 | crit->crit_raw = strdup(criteria); | ||
22 | crit->cmdlist = cmdlist; | ||
23 | crit->tokens = create_list(); | ||
24 | char *err_str = extract_crit_tokens(crit->tokens, crit->crit_raw); | ||
25 | |||
26 | if (err_str) { | ||
18 | error = cmd_results_new(CMD_INVALID, "for_window", err_str); | 27 | error = cmd_results_new(CMD_INVALID, "for_window", err_str); |
19 | free(err_str); | 28 | free(err_str); |
20 | return error; | 29 | free_criteria(crit); |
30 | } else if (crit->tokens->length == 0) { | ||
31 | error = cmd_results_new(CMD_INVALID, "for_window", "Found no name/value pairs in criteria"); | ||
32 | free_criteria(crit); | ||
33 | } else if (list_seq_find(config->criteria, criteria_cmp, crit) != -1) { | ||
34 | wlr_log(L_DEBUG, "for_window: Duplicate, skipping."); | ||
35 | free_criteria(crit); | ||
36 | } else { | ||
37 | wlr_log(L_DEBUG, "for_window: '%s' -> '%s' added", crit->crit_raw, crit->cmdlist); | ||
38 | list_add(config->criteria, crit); | ||
21 | } | 39 | } |
22 | 40 | return error ? error : cmd_results_new(CMD_SUCCESS, NULL, NULL); | |
23 | criteria->type = CT_COMMAND; | ||
24 | criteria->cmdlist = join_args(argv + 1, argc - 1); | ||
25 | |||
26 | list_add(config->criteria, criteria); | ||
27 | wlr_log(L_DEBUG, "for_window: '%s' -> '%s' added", criteria->raw, criteria->cmdlist); | ||
28 | |||
29 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
30 | } | 41 | } |