diff --git a/src/c2.c b/src/c2.c index 2e8da444..0b8996ab 100644 --- a/src/c2.c +++ b/src/c2.c @@ -1875,6 +1875,21 @@ bool c2_match(struct c2_state *state, const struct managed_win *w, return false; } +/// Match a window against the first condition in a condition linked list. +bool c2_match_one(struct c2_state *state, const struct managed_win *w, + const c2_lptr_t *condlst, void **pdata) { + if (!condlst) { + return false; + } + if (c2_match_once(state, w, condlst->ptr)) { + if (pdata) { + *pdata = condlst->data; + } + return true; + } + return false; +} + /// Iterate over all conditions in a condition linked list. Call the callback for /// each of the conditions. If the callback returns true, the iteration stops /// early. diff --git a/src/c2.h b/src/c2.h index 8589ebee..681e54a5 100644 --- a/src/c2.h +++ b/src/c2.h @@ -59,6 +59,8 @@ void c2_window_state_update(struct c2_state *state, struct c2_window_state *wind bool c2_match(struct c2_state *state, const struct managed_win *w, const c2_lptr_t *condlst, void **pdata); +bool c2_match_one(struct c2_state *state, const struct managed_win *w, + const c2_lptr_t *condlst, void **pdata); bool c2_list_postprocess(struct c2_state *state, xcb_connection_t *c, c2_lptr_t *list); typedef bool (*c2_list_foreach_cb_t)(const c2_lptr_t *cond, void *data); diff --git a/src/inspect.c b/src/inspect.c index 94e9e707..4dc9b4da 100644 --- a/src/inspect.c +++ b/src/inspect.c @@ -148,7 +148,7 @@ bool c2_match_once_and_log(const c2_lptr_t *cond, void *data) { struct c2_match_state *state = data; void *rule_data = NULL; printf(" %s ... ", c2_lptr_to_str(cond)); - bool matched = c2_match(state->state, state->w, cond, &rule_data); + bool matched = c2_match_one(state->state, state->w, cond, rule_data); printf("%s", matched ? "\033[1;32mmatched\033[0m" : "not matched"); if (state->print_value && matched) { printf("/%lu", (unsigned long)(intptr_t)rule_data);