From: tobias Date: Mon, 9 Mar 2020 17:42:16 +0000 (+0100) Subject: Add node descriptor: `first_ancestor` X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=331902cc054156f35b6ee6bdcd8dd6f834aad779;p=bspwm.git Add node descriptor: `first_ancestor` --- diff --git a/doc/bspwm.1 b/doc/bspwm.1 index 732f119..7e0a5c4 100644 --- a/doc/bspwm.1 +++ b/doc/bspwm.1 @@ -2,12 +2,12 @@ .\" Title: bspwm .\" Author: [see the "Author" section] .\" Generator: DocBook XSL Stylesheets v1.79.1 -.\" Date: 08/13/2019 +.\" Date: 03/16/2020 .\" Manual: Bspwm Manual -.\" Source: Bspwm 0.9.9 +.\" Source: Bspwm 0.9.9-6-g41b2de0 .\" Language: English .\" -.TH "BSPWM" "1" "08/13/2019" "Bspwm 0\&.9\&.9" "Bspwm Manual" +.TH "BSPWM" "1" "03/16/2020" "Bspwm 0\&.9\&.9\-6\-g41b2de0" "Bspwm Manual" .\" ----------------------------------------------------------------- .\" * Define some portability stuff .\" ----------------------------------------------------------------- @@ -100,7 +100,7 @@ Select a node\&. .RS 4 .\} .nf -NODE_SEL := [NODE_SEL#](DIR|CYCLE_DIR|PATH|any|last|newest| +NODE_SEL := [NODE_SEL#](DIR|CYCLE_DIR|PATH|any|first_ancestor|last|newest| older|newer|focused|pointed|biggest|smallest| )[\&.[!]focused][\&.[!]active][\&.[!]automatic][\&.[!]local] [\&.[!]leaf][\&.[!]window][\&.[!]STATE][\&.[!]FLAG][\&.[!]LAYER] @@ -148,6 +148,11 @@ any Selects the first node that matches the given selectors\&. .RE .PP +first_ancestor +.RS 4 +Selects the first ancestor of the reference node that matches the given selectors\&. +.RE +.PP last .RS 4 Selects the previously focused node relative to the reference node\&. diff --git a/doc/bspwm.1.asciidoc b/doc/bspwm.1.asciidoc index 6fc237e..fac7616 100644 --- a/doc/bspwm.1.asciidoc +++ b/doc/bspwm.1.asciidoc @@ -74,7 +74,7 @@ Node Select a node. ---- -NODE_SEL := [NODE_SEL#](DIR|CYCLE_DIR|PATH|any|last|newest| +NODE_SEL := [NODE_SEL#](DIR|CYCLE_DIR|PATH|any|first_ancestor|last|newest| older|newer|focused|pointed|biggest|smallest| )[.[!]focused][.[!]active][.[!]automatic][.[!]local] [.[!]leaf][.[!]window][.[!]STATE][.[!]FLAG][.[!]LAYER] @@ -106,6 +106,9 @@ Descriptors any:: Selects the first node that matches the given selectors. +first_ancestor:: + Selects the first ancestor of the reference node that matches the given selectors. + last:: Selects the previously focused node relative to the reference node. diff --git a/src/query.c b/src/query.c index 9084e4c..4959f81 100644 --- a/src/query.c +++ b/src/query.c @@ -549,6 +549,8 @@ int node_from_desc(char *desc, coordinates_t *ref, coordinates_t *dst) history_find_node(hdi, ref, dst, &sel); } else if (streq("any", desc)) { find_any_node(ref, dst, &sel); + } else if (streq("first_ancestor", desc)) { + find_first_ancestor(ref, dst, &sel); } else if (streq("last", desc)) { history_find_node(HISTORY_OLDER, ref, dst, &sel); } else if (streq("newest", desc)) { diff --git a/src/tree.c b/src/tree.c index 2aa42eb..2441e91 100644 --- a/src/tree.c +++ b/src/tree.c @@ -1014,6 +1014,17 @@ bool find_any_node_in(monitor_t *m, desktop_t *d, node_t *n, coordinates_t *ref, } } +void find_first_ancestor(coordinates_t *ref, coordinates_t *dst, node_select_t *sel) +{ + coordinates_t loc = {ref->monitor, ref->desktop, ref->node}; + while ((loc.node = loc.node->parent) != NULL) { + if (node_matches(&loc, ref, sel)) { + *dst = loc; + return; + } + } +} + /* Based on https://github.com/ntrrgc/right-window */ void find_nearest_neighbor(coordinates_t *ref, coordinates_t *dst, direction_t dir, node_select_t *sel) { diff --git a/src/tree.h b/src/tree.h index b571ada..c4d1d0b 100644 --- a/src/tree.h +++ b/src/tree.h @@ -68,6 +68,7 @@ bool find_by_id(uint32_t id, coordinates_t *loc); node_t *find_by_id_in(node_t *r, uint32_t id); void find_any_node(coordinates_t *ref, coordinates_t *dst, node_select_t *sel); bool find_any_node_in(monitor_t *m, desktop_t *d, node_t *n, coordinates_t *ref, coordinates_t *dst, node_select_t *sel); +void find_first_ancestor(coordinates_t *ref, coordinates_t *dst, node_select_t *sel); void find_nearest_neighbor(coordinates_t *ref, coordinates_t *dst, direction_t dir, node_select_t *sel); unsigned int node_area(desktop_t *d, node_t *n); int tiled_count(node_t *n, bool include_receptacles);