diff options
author | Calvin Lee <[email protected]> | 2017-04-04 21:20:27 -0600 |
---|---|---|
committer | Calvin Lee <[email protected]> | 2017-04-05 22:07:23 -0600 |
commit | 069d37f987c4e323cdb9396f0d80ac83d00566ff (patch) | |
tree | b883a5553107ab24d5346db42062518f9e7bdca9 /sway/criteria.c | |
parent | 7d43a76b4e765eb8072c09cdec3847e877cf65d7 (diff) |
Improve criteria handling
This commit changes how commands decide what container to act on.
Commands get the current container though `current_container`, a global
defined in sway/commands.c. If a criteria is given before a command,
then the following command will be run once for every container the
criteria matches with a reference to the matching container in
'current_container'. Commands should use this instead of
`get_focused_container()` from now on.
This commit also fixes a few (minor) mistakes made in implementing marks
such as non-escaped arrows in sway(5) and calling the "mark" command
"floating" by accident. It also cleans up `criteria.c` in a few places.
Diffstat (limited to 'sway/criteria.c')
-rw-r--r-- | sway/criteria.c | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/sway/criteria.c b/sway/criteria.c index 3ffc48f0..bd99461d 100644 --- a/sway/criteria.c +++ b/sway/criteria.c @@ -245,7 +245,7 @@ ect_cleanup: return error; } -int regex_cmp(const char *item, const regex_t *regex) { +static int regex_cmp(const char *item, const regex_t *regex) { return regexec(regex, item, 0, NULL, 0); } @@ -272,7 +272,10 @@ static bool criteria_test(swayc_t *cont, list_t *tokens) { break; case CRIT_CON_MARK: if (crit->regex && cont->marks && (list_seq_find(cont->marks, (int (*)(const void *, const void *))regex_cmp, crit->regex) != -1)) { - ++matches; + // Make sure it isn't matching the NUL string + if ((strcmp(crit->raw, "") == 0) == (list_seq_find(cont->marks, (int (*)(const void *, const void *))strcmp, "") != -1)) { + ++matches; + } } break; case CRIT_ID: @@ -285,7 +288,7 @@ static bool criteria_test(swayc_t *cont, list_t *tokens) { case CRIT_INSTANCE: if (!cont->instance) { // ignore - } else if (strcmp(crit->raw, "focused") == 0) { + } else if (crit_is_focused(crit->raw)) { swayc_t *focused = get_focused_view(&root_container); if (focused->instance && strcmp(cont->instance, focused->instance) == 0) { matches++; @@ -373,3 +376,21 @@ list_t *criteria_for(swayc_t *cont) { } return matches; } + +struct list_tokens { + list_t *list; + list_t *tokens; +}; + +static void container_match_add(swayc_t *container, struct list_tokens *list_tokens) { + if (criteria_test(container, list_tokens->tokens)) { + list_add(list_tokens->list, container); + } +} +list_t *container_for(list_t *tokens) { + struct list_tokens list_tokens = (struct list_tokens){create_list(), tokens}; + + container_map(&root_container, (void (*)(swayc_t *, void *))container_match_add, &list_tokens); + + return list_tokens.list; +} |