From badfd6c91fe18c7d60593072360e7ce73f881221 Mon Sep 17 00:00:00 2001 From: Emanuele Torre Date: Tue, 1 Dec 2020 06:48:13 +0100 Subject: [PATCH] Allow negated window modifiers to match non-wins For example, `.!floating` used to only match nodes that hold a window that is not in floating state; now, `.!floating` will match any node that is not a node that holds a window that's in floating state. The old behavior was counterintuitive, since e.g. `.tiled` and `.!tiled` were not complementaries (they were complementaries with respect to the windows, not the nodes) while the other standard node modifiers were. Closes #1232. --- src/query.c | 65 ++++++++++++++++++++++++++--------------------------- 1 file changed, 32 insertions(+), 33 deletions(-) diff --git a/src/query.c b/src/query.c index c3faa0a..aaaf3ee 100644 --- a/src/query.c +++ b/src/query.c @@ -1135,26 +1135,16 @@ bool node_matches(coordinates_t *loc, coordinates_t *ref, node_select_t *sel) NFLAG(marked) #undef NFLAG - if (loc->node->client == NULL && - (sel->same_class != OPTION_NONE || - sel->tiled != OPTION_NONE || - sel->pseudo_tiled != OPTION_NONE || - sel->floating != OPTION_NONE || - sel->fullscreen != OPTION_NONE || - sel->below != OPTION_NONE || - sel->normal != OPTION_NONE || - sel->above != OPTION_NONE || - sel->urgent != OPTION_NONE)) { - return false; - } - - if (ref->node != NULL && ref->node->client != NULL && - sel->same_class != OPTION_NONE && - streq(loc->node->client->class_name, ref->node->client->class_name) - ? sel->same_class == OPTION_FALSE - : sel->same_class == OPTION_TRUE) { - return false; +#define NSPLIT(p, e) \ + if (sel->p != OPTION_NONE && \ + loc->node->split_type != e \ + ? sel->p == OPTION_TRUE \ + : sel->p == OPTION_FALSE) { \ + return false; \ } + NSPLIT(horizontal, TYPE_HORIZONTAL) + NSPLIT(vertical, TYPE_VERTICAL) +#undef NSPLIT if (sel->descendant_of != OPTION_NONE && !is_descendant(loc->node, ref->node) @@ -1170,6 +1160,29 @@ bool node_matches(coordinates_t *loc, coordinates_t *ref, node_select_t *sel) return false; } + if (loc->node->client == NULL) { + if (sel->same_class == OPTION_TRUE || + sel->tiled == OPTION_TRUE || + sel->pseudo_tiled == OPTION_TRUE || + sel->floating == OPTION_TRUE || + sel->fullscreen == OPTION_TRUE || + sel->below == OPTION_TRUE || + sel->normal == OPTION_TRUE || + sel->above == OPTION_TRUE || + sel->urgent == OPTION_TRUE) { + return false; + } + return true; + } + + if (ref->node != NULL && ref->node->client != NULL && + sel->same_class != OPTION_NONE && + streq(loc->node->client->class_name, ref->node->client->class_name) + ? sel->same_class == OPTION_FALSE + : sel->same_class == OPTION_TRUE) { + return false; + } + #define WSTATE(p, e) \ if (sel->p != OPTION_NONE && \ loc->node->client->state != e \ @@ -1205,20 +1218,6 @@ bool node_matches(coordinates_t *loc, coordinates_t *ref, node_select_t *sel) WFLAG(urgent) #undef WFLAG - if (sel->horizontal != OPTION_NONE && - loc->node->split_type != TYPE_HORIZONTAL - ? sel->horizontal == OPTION_TRUE - : sel->horizontal == OPTION_FALSE) { - return false; - } - - if (sel->vertical != OPTION_NONE && - loc->node->split_type != TYPE_VERTICAL - ? sel->vertical == OPTION_TRUE - : sel->vertical == OPTION_FALSE) { - return false; - } - return true; } -- 2.44.0