]> git.lizzy.rs Git - bspwm.git/commitdiff
Add node descriptor: `first_ancestor`
authortobias <tobias@freedom.localdomain>
Mon, 9 Mar 2020 17:42:16 +0000 (18:42 +0100)
committerBastien Dejean <nihilhill@gmail.com>
Mon, 16 Mar 2020 11:14:29 +0000 (12:14 +0100)
doc/bspwm.1
doc/bspwm.1.asciidoc
src/query.c
src/tree.c
src/tree.h

index 732f1190e01c05f4781cc8b73db5a2d68207cb65..7e0a5c4c434b2e9e4befbeea4ddedfebd3d8e859 100644 (file)
@@ -2,12 +2,12 @@
 .\"     Title: bspwm
 .\"    Author: [see the "Author" section]
 .\" Generator: DocBook XSL Stylesheets v1.79.1 <http://docbook.sf.net/>
-.\"      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|
                         <node_id>)[\&.[!]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\&.
index 6fc237ed0e4cbb0dbdf8e97b42584063290b0b92..fac7616f37394fd50077e9de8b078eda9d73973f 100644 (file)
@@ -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|
                         <node_id>)[.[!]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.
 
index 9084e4c44ab94c97ec47d541598a8499f77504e6..4959f8195f8dc3c8851eaaedbc2f39fa9c543c23 100644 (file)
@@ -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)) {
index 2aa42ebea586c304f0352b1a4fdee52f2aafbf49..2441e9100db2702a4c1ff991bd89b30980636497 100644 (file)
@@ -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)
 {
index b571ada9f58e9efd76d43c0baa32eecfbeff95c2..c4d1d0bcd99f7d3f528c3effbaca5cfd93d7f0e8 100644 (file)
@@ -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);