From 50e092cbc075435fe89e2200c5e15fcadfd057b7 Mon Sep 17 00:00:00 2001 From: Yuxuan Shui Date: Sun, 19 May 2024 22:54:44 +0100 Subject: [PATCH] inspect: fix reporting of matched rules When we checked each rule, we didn't just match the window against that one rule, we were matching it against all subsequent rules in the list as well. This commit fixes that. Signed-off-by: Yuxuan Shui --- src/c2.c | 15 +++++++++++++++ src/c2.h | 2 ++ src/inspect.c | 2 +- 3 files changed, 18 insertions(+), 1 deletion(-) 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);