diff options
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: | |||
245 | return error; | 245 | return error; |
246 | } | 246 | } |
247 | 247 | ||
248 | int regex_cmp(const char *item, const regex_t *regex) { | 248 | static int regex_cmp(const char *item, const regex_t *regex) { |
249 | return regexec(regex, item, 0, NULL, 0); | 249 | return regexec(regex, item, 0, NULL, 0); |
250 | } | 250 | } |
251 | 251 | ||
@@ -272,7 +272,10 @@ static bool criteria_test(swayc_t *cont, list_t *tokens) { | |||
272 | break; | 272 | break; |
273 | case CRIT_CON_MARK: | 273 | case CRIT_CON_MARK: |
274 | if (crit->regex && cont->marks && (list_seq_find(cont->marks, (int (*)(const void *, const void *))regex_cmp, crit->regex) != -1)) { | 274 | if (crit->regex && cont->marks && (list_seq_find(cont->marks, (int (*)(const void *, const void *))regex_cmp, crit->regex) != -1)) { |
275 | ++matches; | 275 | // Make sure it isn't matching the NUL string |
276 | if ((strcmp(crit->raw, "") == 0) == (list_seq_find(cont->marks, (int (*)(const void *, const void *))strcmp, "") != -1)) { | ||
277 | ++matches; | ||
278 | } | ||
276 | } | 279 | } |
277 | break; | 280 | break; |
278 | case CRIT_ID: | 281 | case CRIT_ID: |
@@ -285,7 +288,7 @@ static bool criteria_test(swayc_t *cont, list_t *tokens) { | |||
285 | case CRIT_INSTANCE: | 288 | case CRIT_INSTANCE: |
286 | if (!cont->instance) { | 289 | if (!cont->instance) { |
287 | // ignore | 290 | // ignore |
288 | } else if (strcmp(crit->raw, "focused") == 0) { | 291 | } else if (crit_is_focused(crit->raw)) { |
289 | swayc_t *focused = get_focused_view(&root_container); | 292 | swayc_t *focused = get_focused_view(&root_container); |
290 | if (focused->instance && strcmp(cont->instance, focused->instance) == 0) { | 293 | if (focused->instance && strcmp(cont->instance, focused->instance) == 0) { |
291 | matches++; | 294 | matches++; |
@@ -373,3 +376,21 @@ list_t *criteria_for(swayc_t *cont) { | |||
373 | } | 376 | } |
374 | return matches; | 377 | return matches; |
375 | } | 378 | } |
379 | |||
380 | struct list_tokens { | ||
381 | list_t *list; | ||
382 | list_t *tokens; | ||
383 | }; | ||
384 | |||
385 | static void container_match_add(swayc_t *container, struct list_tokens *list_tokens) { | ||
386 | if (criteria_test(container, list_tokens->tokens)) { | ||
387 | list_add(list_tokens->list, container); | ||
388 | } | ||
389 | } | ||
390 | list_t *container_for(list_t *tokens) { | ||
391 | struct list_tokens list_tokens = (struct list_tokens){create_list(), tokens}; | ||
392 | |||
393 | container_map(&root_container, (void (*)(swayc_t *, void *))container_match_add, &list_tokens); | ||
394 | |||
395 | return list_tokens.list; | ||
396 | } | ||