]> git.lizzy.rs Git - bspwm.git/commitdiff
Add monitor/desktop/node descriptor: `any`
authorBastien Dejean <nihilhill@gmail.com>
Wed, 7 Mar 2018 13:14:48 +0000 (14:14 +0100)
committerBastien Dejean <nihilhill@gmail.com>
Wed, 7 Mar 2018 13:14:48 +0000 (14:14 +0100)
contrib/zsh_completion
doc/bspwm.1
doc/bspwm.1.asciidoc
src/desktop.c
src/desktop.h
src/monitor.c
src/monitor.h
src/query.c
src/tree.c
src/tree.h

index a32515f1eb33049616ff436173a927b2d0817c6a..673141e6a06995290c2e9aafc0e524261a1f3206 100644 (file)
@@ -134,12 +134,12 @@ _bspc() {
                dir=(north west south east) \
                cycle_dir=(next prev)
        local -a jump=($dir first second brother parent 1 2) \
-               node_desc=($dir $cycle_dir last newest older newer focused pointed biggest) \
+               node_desc=($dir $cycle_dir any last newest older newer focused pointed biggest) \
                node_mod=($node_state $flag $layer focused automatic local \
                active leaf window same_class descendant_of ancestor_of) \
-               desktop_desc=($cycle_dir last newest older newer focused) \
+               desktop_desc=($cycle_dir any last newest older newer focused) \
                desktop_mod=(focused occupied local urgent) \
-               monitor_desc=($dir $cycle_dir primary last newest older newer focused pointed) \
+               monitor_desc=($dir $cycle_dir any last newest older newer focused pointed primary) \
                monitor_mod=(focused occupied) \
                presel_dir=($dir cancel)
        local quote="${compstate[quote]}" context state state_descr line
index ba2db7dfcde0d6fc26a4ffa43bdf48dd6fbc0f12..104223a7ebce88bf7eaf8603ae63e57afb4f7e20 100644 (file)
@@ -4,10 +4,10 @@
 .\" Generator: DocBook XSL Stylesheets v1.79.1 <http://docbook.sf.net/>
 .\"      Date: 03/07/2018
 .\"    Manual: Bspwm Manual
-.\"    Source: Bspwm 0.9.3-52-gf83f7ef
+.\"    Source: Bspwm 0.9.3-55-g7d639d1
 .\"  Language: English
 .\"
-.TH "BSPWM" "1" "03/07/2018" "Bspwm 0\&.9\&.3\-52\-gf83f7ef" "Bspwm Manual"
+.TH "BSPWM" "1" "03/07/2018" "Bspwm 0\&.9\&.3\-55\-g7d639d1" "Bspwm Manual"
 .\" -----------------------------------------------------------------
 .\" * Define some portability stuff
 .\" -----------------------------------------------------------------
@@ -100,7 +100,7 @@ Select a node\&.
 .RS 4
 .\}
 .nf
-NODE_SEL := [NODE_SEL#](DIR|CYCLE_DIR|PATH|last|newest|
+NODE_SEL := [NODE_SEL#](DIR|CYCLE_DIR|PATH|any|last|newest|
                         older|newer|focused|pointed|
                         biggest|<node_id>)[\&.[!]focused][\&.[!]automatic][\&.[!]local][\&.[!]active]
                                           [\&.[!]leaf][\&.[!]window][\&.[!]STATE][\&.[!]FLAG][\&.[!]LAYER]
@@ -143,6 +143,11 @@ Selects the window in the given (cyclic) direction relative to the reference nod
 Selects the node at the given path\&.
 .RE
 .PP
+any
+.RS 4
+Selects the first node that matches the given selectors\&.
+.RE
+.PP
 last
 .RS 4
 Selects the previously focused node relative to the reference node\&.
@@ -302,7 +307,7 @@ Select a desktop\&.
 .RS 4
 .\}
 .nf
-DESKTOP_SEL := [DESKTOP_SEL#](CYCLE_DIR|last|newest|older|newer|
+DESKTOP_SEL := [DESKTOP_SEL#](CYCLE_DIR|any|last|newest|older|newer|
                               [MONITOR_SEL:](focused|^<n>)|
                               <desktop_id>|<desktop_name>)[\&.[!]occupied][\&.[!]focused][\&.[!]urgent][\&.[!]local]
 .fi
@@ -323,6 +328,11 @@ DESKTOP_SEL := [DESKTOP_SEL#](CYCLE_DIR|last|newest|older|newer|
 Selects the desktop in the given direction relative to the reference desktop\&.
 .RE
 .PP
+any
+.RS 4
+Selects the first desktop that matches the given selectors\&.
+.RE
+.PP
 last
 .RS 4
 Selects the previously focused desktop relative to the reference desktop\&.
@@ -402,7 +412,7 @@ Select a monitor\&.
 .RS 4
 .\}
 .nf
-MONITOR_SEL := [MONITOR_SEL#](DIR|CYCLE_DIR|last|newest|older|newer|
+MONITOR_SEL := [MONITOR_SEL#](DIR|CYCLE_DIR|any|last|newest|older|newer|
                               focused|pointed|primary|^<n>|
                               <monitor_id>|<monitor_name>)[\&.[!]occupied][\&.[!]focused]
 .fi
@@ -428,6 +438,11 @@ Selects the monitor in the given (spacial) direction relative to the reference m
 Selects the monitor in the given (cyclic) direction relative to the reference monitor\&.
 .RE
 .PP
+any
+.RS 4
+Selects the first monitor that matches the given selectors\&.
+.RE
+.PP
 last
 .RS 4
 Selects the previously focused monitor relative to the reference monitor\&.
index acc2955996ee5b76cf71cdebe73755a2cff1fdd2..376ddf04e7f949375a0859d161411dfd7ac996f3 100644 (file)
@@ -74,7 +74,7 @@ Node
 Select a node.
 
 ----
-NODE_SEL := [NODE_SEL#](DIR|CYCLE_DIR|PATH|last|newest|
+NODE_SEL := [NODE_SEL#](DIR|CYCLE_DIR|PATH|any|last|newest|
                         older|newer|focused|pointed|
                         biggest|<node_id>)[.[!]focused][.[!]automatic][.[!]local][.[!]active]
                                           [.[!]leaf][.[!]window][.[!]STATE][.[!]FLAG][.[!]LAYER]
@@ -103,6 +103,9 @@ Descriptors
 'PATH'::
        Selects the node at the given path.
 
+any::
+       Selects the first node that matches the given selectors.
+
 last::
        Selects the previously focused node relative to the reference node.
 
@@ -192,7 +195,7 @@ Desktop
 Select a desktop.
 
 ----
-DESKTOP_SEL := [DESKTOP_SEL#](CYCLE_DIR|last|newest|older|newer|
+DESKTOP_SEL := [DESKTOP_SEL#](CYCLE_DIR|any|last|newest|older|newer|
                               [MONITOR_SEL:](focused|^<n>)|
                               <desktop_id>|<desktop_name>)[.[!]occupied][.[!]focused][.[!]urgent][.[!]local]
 ----
@@ -203,6 +206,9 @@ Descriptors
 'CYCLE_DIR'::
        Selects the desktop in the given direction relative to the reference desktop.
 
+any::
+       Selects the first desktop that matches the given selectors.
+
 last::
        Selects the previously focused desktop relative to the reference desktop.
 
@@ -248,7 +254,7 @@ Monitor
 Select a monitor.
 
 ----
-MONITOR_SEL := [MONITOR_SEL#](DIR|CYCLE_DIR|last|newest|older|newer|
+MONITOR_SEL := [MONITOR_SEL#](DIR|CYCLE_DIR|any|last|newest|older|newer|
                               focused|pointed|primary|^<n>|
                               <monitor_id>|<monitor_name>)[.[!]occupied][.[!]focused]
 ----
@@ -262,6 +268,9 @@ Descriptors
 'CYCLE_DIR'::
        Selects the monitor in the given (cyclic) direction relative to the reference monitor.
 
+any::
+       Selects the first monitor that matches the given selectors.
+
 last::
        Selects the previously focused monitor relative to the reference monitor.
 
index ef94746cdb105b146351b5b65d49546b05972153..d99325fea55d1f56905c9dc50f3a9c17239a8bc7 100644 (file)
@@ -116,6 +116,20 @@ bool find_closest_desktop(coordinates_t *ref, coordinates_t *dst, cycle_dir_t di
        return false;
 }
 
+bool find_any_desktop(coordinates_t *ref, coordinates_t *dst, desktop_select_t *sel)
+{
+       for (monitor_t *m = mon_head; m != NULL; m = m->next) {
+               for (desktop_t *d = m->desk_head; d != NULL; d = d->next) {
+                       coordinates_t loc = {m, d, NULL};
+                       if (desktop_matches(&loc, ref, sel)) {
+                               *dst = loc;
+                               return true;
+                       }
+               }
+       }
+       return false;
+}
+
 bool set_layout(monitor_t *m, desktop_t *d, layout_t l)
 {
        if (d->layout == l) {
index 2374b940fa77f7165def0e82c531d87260ef3505..dd544a494e910a1fd252586f954b9c43f7eb5cd3 100644 (file)
@@ -30,6 +30,7 @@
 void focus_desktop(monitor_t *m, desktop_t *d);
 bool activate_desktop(monitor_t *m, desktop_t *d);
 bool find_closest_desktop(coordinates_t *ref, coordinates_t *dst, cycle_dir_t dir, desktop_select_t *sel);
+bool find_any_desktop(coordinates_t *ref, coordinates_t *dst, desktop_select_t *sel);
 bool set_layout(monitor_t *m, desktop_t *d, layout_t l);
 void handle_presel_feedbacks(monitor_t *m, desktop_t *d);
 bool transfer_desktop(monitor_t *ms, monitor_t *md, desktop_t *d, bool follow);
index f1b51f128a8b9732350b486f541d3f3a812830b3..4b94cea53a4776ee337711007e379ead92652bfc 100644 (file)
@@ -441,6 +441,18 @@ monitor_t *nearest_monitor(monitor_t *m, direction_t dir, monitor_select_t *sel)
        return nearest;
 }
 
+bool find_any_monitor(coordinates_t *ref, coordinates_t *dst, monitor_select_t *sel)
+{
+       for (monitor_t *m = mon_head; m != NULL; m = m->next) {
+               coordinates_t loc = {m, NULL, NULL};
+               if (monitor_matches(&loc, ref, sel)) {
+                       *dst = loc;
+                       return true;
+               }
+       }
+       return false;
+}
+
 bool update_monitors(void)
 {
        xcb_randr_get_screen_resources_reply_t *sres = xcb_randr_get_screen_resources_reply(dpy, xcb_randr_get_screen_resources(dpy, root), NULL);
index 60e2bef16178fe3e855eee1cdfa086626acff3ce..33b64e5c2355a078adac0c1a8bb592ac40530c28 100644 (file)
@@ -46,6 +46,7 @@ bool is_inside_monitor(monitor_t *m, xcb_point_t pt);
 monitor_t *monitor_from_point(xcb_point_t pt);
 monitor_t *monitor_from_client(client_t *c);
 monitor_t *nearest_monitor(monitor_t *m, direction_t dir, monitor_select_t *sel);
+bool find_any_monitor(coordinates_t *ref, coordinates_t *dst, monitor_select_t *sel);
 bool update_monitors(void);
 
 #endif
index 7f64de5a5effab210b22fbcd42a112c28e622e39..f1c9c91c29f79910b6654758ead5eb4b607b7b27 100644 (file)
@@ -507,6 +507,8 @@ int node_from_desc(char *desc, coordinates_t *ref, coordinates_t *dst)
                find_closest_node(ref, dst, cyc, &sel);
        } else if (parse_history_direction(desc, &hdi)) {
                history_find_node(hdi, ref, dst, &sel);
+       } else if (streq("any", desc)) {
+               find_any_node(ref, dst, &sel);
        } else if (streq("last", desc)) {
                history_find_node(HISTORY_OLDER, ref, dst, &sel);
        } else if (streq("newest", desc)) {
@@ -643,6 +645,8 @@ int desktop_from_desc(char *desc, coordinates_t *ref, coordinates_t *dst)
                find_closest_desktop(ref, dst, cyc, &sel);
        } else if (parse_history_direction(desc, &hdi)) {
                history_find_desktop(hdi, ref, dst, &sel);
+       } else if (streq("any", desc)) {
+               find_any_desktop(ref, dst, &sel);
        } else if (streq("last", desc)) {
                history_find_desktop(HISTORY_OLDER, ref, dst, &sel);
        } else if (streq("newest", desc)) {
@@ -761,6 +765,8 @@ int monitor_from_desc(char *desc, coordinates_t *ref, coordinates_t *dst)
                dst->monitor = closest_monitor(ref->monitor, cyc, &sel);
        } else if (parse_history_direction(desc, &hdi)) {
                history_find_monitor(hdi, ref, dst, &sel);
+       } else if (streq("any", desc)) {
+               find_any_monitor(ref, dst, &sel);
        } else if (streq("last", desc)) {
                history_find_monitor(HISTORY_OLDER, ref, dst, &sel);
        } else if (streq("newest", desc)) {
index 97274b89d3354f6d7d3ff1d5a77a13fb08b393fa..2d0cc98e071575569d14db24514e036c88d0d32a 100644 (file)
@@ -960,6 +960,36 @@ 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)
+{
+       for (monitor_t *m = mon_head; m != NULL; m = m->next) {
+               for (desktop_t *d = m->desk_head; d != NULL; d = d->next) {
+                       if (find_any_node_in(m, d, d->root, ref, dst, sel)) {
+                               return;
+                       }
+               }
+       }
+}
+
+bool find_any_node_in(monitor_t *m, desktop_t *d, node_t *n, coordinates_t *ref, coordinates_t *dst, node_select_t *sel)
+{
+       if (n == NULL) {
+               return false;
+       } else {
+               coordinates_t loc = {m, d, n};
+               if (node_matches(&loc, ref, sel)) {
+                       *dst = loc;
+                       return true;
+               } else {
+                       if (find_any_node_in(m, d, n->first_child, ref, dst, sel)) {
+                               return true;
+                       } else {
+                               return find_any_node_in(m, d, n->second_child, ref, dst, sel);
+                       }
+               }
+       }
+}
+
 /* 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 59f721292ad183e7a632458cc407d6a424dfe001..05501f484568e5deed8692d64014ff11d9f9ba42 100644 (file)
@@ -66,6 +66,8 @@ bool is_child(node_t *a, node_t *b);
 bool is_descendant(node_t *a, node_t *b);
 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_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);