]> git.lizzy.rs Git - bspwm.git/commitdiff
Accept an optional reference in all the selectors
authorBastien Dejean <nihilhill@gmail.com>
Fri, 20 May 2016 09:41:36 +0000 (11:41 +0200)
committerBastien Dejean <nihilhill@gmail.com>
Fri, 20 May 2016 09:41:36 +0000 (11:41 +0200)
Fixes #486.

doc/bspwm.1
doc/bspwm.1.asciidoc
query.c

index ae6d518ce10a0448c6148125e9e39f8978b8f49b..b28085999190e6f95d7e300d26f81f6424366a3f 100644 (file)
@@ -2,12 +2,12 @@
 .\"     Title: bspwm
 .\"    Author: [see the "Author" section]
 .\" Generator: DocBook XSL Stylesheets v1.78.1 <http://docbook.sf.net/>
-.\"      Date: 05/09/2016
+.\"      Date: 05/20/2016
 .\"    Manual: Bspwm Manual
-.\"    Source: Bspwm 0.9.1-57-ge471298
+.\"    Source: Bspwm 0.9.1-75-g666af89
 .\"  Language: English
 .\"
-.TH "BSPWM" "1" "05/09/2016" "Bspwm 0\&.9\&.1\-57\-ge471298" "Bspwm Manual"
+.TH "BSPWM" "1" "05/20/2016" "Bspwm 0\&.9\&.1\-75\-g666af89" "Bspwm Manual"
 .\" -----------------------------------------------------------------
 .\" * Define some portability stuff
 .\" -----------------------------------------------------------------
@@ -73,19 +73,21 @@ CYCLE_DIR   := next | prev
 .sp
 Selectors are used to select a target node, desktop, or monitor\&. A selector can either describe the target relatively or name it globally\&.
 .sp
-Selectors consist of a descriptor and any number of non\-conflicting modifiers as follows:
+Selectors consist of an optional reference, a descriptor and any number of non\-conflicting modifiers as follows:
 .sp
 .if n \{\
 .RS 4
 .\}
 .nf
-DESCRIPTOR(\&.MODIFIER)*
+[REFERENCE#]DESCRIPTOR(\&.MODIFIER)*
 .fi
 .if n \{\
 .RE
 .\}
 .sp
-An exclamation mark can be prepended to certain modifiers in order to reverse their meaning\&.
+The relative targets are computed in relation to the given reference (the default reference value is \fBfocused\fR)\&.
+.sp
+An exclamation mark can be prepended to any modifier in order to reverse its meaning\&.
 .SS "Node"
 .sp
 Select a node\&.
@@ -94,7 +96,7 @@ Select a node\&.
 .RS 4
 .\}
 .nf
-NODE_SEL := (DIR|CYCLE_DIR|PATH|last|older|newer|focused|pointed|biggest|<node_id>)[\&.[!]focused][\&.[!]automatic][\&.[!]local][\&.[!]leaf][\&.[!]window][\&.[!]STATE][\&.[!]FLAG][\&.[!]LAYER][\&.[!]same_class][\&.[!]descendant_of][\&.[!]ancestor_of]
+NODE_SEL := [NODE_SEL#](DIR|CYCLE_DIR|PATH|last|older|newer|focused|pointed|biggest|<node_id>)[\&.[!]focused][\&.[!]automatic][\&.[!]local][\&.[!]leaf][\&.[!]window][\&.[!]STATE][\&.[!]FLAG][\&.[!]LAYER][\&.[!]same_class][\&.[!]descendant_of][\&.[!]ancestor_of]
 
 STATE := tiled|pseudo_tiled|floating|fullscreen
 
@@ -225,7 +227,7 @@ Only consider nodes in automatic or manual insertion mode\&.
 .PP
 [!]local
 .RS 4
-Only consider nodes in or not in the current desktop\&.
+Only consider nodes in or not in the reference desktop\&.
 .RE
 .PP
 [!]leaf
@@ -276,7 +278,7 @@ Select a desktop\&.
 .RS 4
 .\}
 .nf
-DESKTOP_SEL := (CYCLE_DIR|last|older|newer|[MONITOR_SEL:](focused|^<n>)|<desktop_id>|<desktop_name>)[\&.[!]occupied][\&.[!]focused][\&.[!]urgent][\&.[!]local]
+DESKTOP_SEL := [DESKTOP_SEL#](CYCLE_DIR|last|older|newer|[MONITOR_SEL:](focused|^<n>)|<desktop_id>|<desktop_name>)[\&.[!]occupied][\&.[!]focused][\&.[!]urgent][\&.[!]local]
 .fi
 .if n \{\
 .RE
@@ -292,22 +294,22 @@ DESKTOP_SEL := (CYCLE_DIR|last|older|newer|[MONITOR_SEL:](focused|^<n>)|<desktop
 .PP
 \fICYCLE_DIR\fR
 .RS 4
-Selects the desktop in the given direction relative to the active desktop\&.
+Selects the desktop in the given direction relative to the reference desktop\&.
 .RE
 .PP
 last
 .RS 4
-Selects the previously focused desktop\&.
+Selects the previously focused desktop relative to the reference desktop\&.
 .RE
 .PP
 older
 .RS 4
-Selects the desktop older than the focused desktop in the history\&.
+Selects the desktop older than the reference desktop in the history\&.
 .RE
 .PP
 newer
 .RS 4
-Selects the desktop newer than the focused desktop in the history\&.
+Selects the desktop newer than the reference desktop in the history\&.
 .RE
 .PP
 focused
@@ -356,7 +358,7 @@ Only consider urgent or non urgent desktops\&.
 .PP
 [!]local
 .RS 4
-Only consider inside or outside of the current monitor\&.
+Only consider inside or outside of the reference monitor\&.
 .RE
 .RE
 .SS "Monitor"
@@ -367,7 +369,7 @@ Select a monitor\&.
 .RS 4
 .\}
 .nf
-MONITOR_SEL := (DIR|CYCLE_DIR|last|older|newer|focused|primary|^<n>|<monitor_id>|<monitor_name>)[\&.[!]occupied][\&.[!]focused]
+MONITOR_SEL := [MONITOR_SEL#](DIR|CYCLE_DIR|last|older|newer|focused|primary|^<n>|<monitor_id>|<monitor_name>)[\&.[!]occupied][\&.[!]focused]
 .fi
 .if n \{\
 .RE
@@ -383,27 +385,27 @@ MONITOR_SEL := (DIR|CYCLE_DIR|last|older|newer|focused|primary|^<n>|<monitor_id>
 .PP
 \fIDIR\fR
 .RS 4
-Selects the monitor in the given (spacial) direction relative to the active monitor\&.
+Selects the monitor in the given (spacial) direction relative to the reference monitor\&.
 .RE
 .PP
 \fICYCLE_DIR\fR
 .RS 4
-Selects the monitor in the given (cyclic) direction relative to the active monitor\&.
+Selects the monitor in the given (cyclic) direction relative to the reference monitor\&.
 .RE
 .PP
 last
 .RS 4
-Selects the previously focused monitor\&.
+Selects the previously focused monitor relative to the reference monitor\&.
 .RE
 .PP
 older
 .RS 4
-Selects the monitor older than the focused monitor in the history\&.
+Selects the monitor older than the reference monitor in the history\&.
 .RE
 .PP
 newer
 .RS 4
-Selects the monitor newer than the focused monitor in the history\&.
+Selects the monitor newer than the reference monitor in the history\&.
 .RE
 .PP
 focused
@@ -802,6 +804,8 @@ query \fICOMMANDS\fR [\fIOPTIONS\fR]
 .ps +1
 \fBCommands\fR
 .RS 4
+.sp
+The optional selectors are references\&.
 .PP
 \fB\-N\fR, \fB\-\-nodes\fR [\fINODE_SEL\fR]
 .RS 4
index 23500c61822e99102caa946829e2bf14a4a6d48d..9714eb3e4a2d51eacd03723d199590ffc6121563 100644 (file)
@@ -53,12 +53,16 @@ Selectors
 Selectors are used to select a target node, desktop, or monitor. A selector
 can either describe the target relatively or name it globally.
 
-Selectors consist of a descriptor and any number of non-conflicting modifiers
-as follows:
+Selectors consist of an optional reference, a descriptor and any number of
+non-conflicting modifiers as follows:
 
-       DESCRIPTOR(.MODIFIER)*
+       [REFERENCE#]DESCRIPTOR(.MODIFIER)*
 
-An exclamation mark can be prepended to certain modifiers in order to reverse their meaning.
+The relative targets are computed in relation to the given reference (the
+default reference value is *focused*).
+
+An exclamation mark can be prepended to any modifier in order to reverse its
+meaning.
 
 Node
 ~~~~
@@ -66,7 +70,7 @@ Node
 Select a node.
 
 ----
-NODE_SEL := (DIR|CYCLE_DIR|PATH|last|older|newer|focused|pointed|biggest|<node_id>)[.[!]focused][.[!]automatic][.[!]local][.[!]leaf][.[!]window][.[!]STATE][.[!]FLAG][.[!]LAYER][.[!]same_class][.[!]descendant_of][.[!]ancestor_of]
+NODE_SEL := [NODE_SEL#](DIR|CYCLE_DIR|PATH|last|older|newer|focused|pointed|biggest|<node_id>)[.[!]focused][.[!]automatic][.[!]local][.[!]leaf][.[!]window][.[!]STATE][.[!]FLAG][.[!]LAYER][.[!]same_class][.[!]descendant_of][.[!]ancestor_of]
 
 STATE := tiled|pseudo_tiled|floating|fullscreen
 
@@ -142,7 +146,7 @@ Modifiers
        Only consider nodes in automatic or manual insertion mode.
 
 [!]local::
-       Only consider nodes in or not in the current desktop.
+       Only consider nodes in or not in the reference desktop.
 
 [!]leaf::
        Only consider leaves or internal nodes.
@@ -174,23 +178,23 @@ Desktop
 Select a desktop.
 
 ----
-DESKTOP_SEL := (CYCLE_DIR|last|older|newer|[MONITOR_SEL:](focused|^<n>)|<desktop_id>|<desktop_name>)[.[!]occupied][.[!]focused][.[!]urgent][.[!]local]
+DESKTOP_SEL := [DESKTOP_SEL#](CYCLE_DIR|last|older|newer|[MONITOR_SEL:](focused|^<n>)|<desktop_id>|<desktop_name>)[.[!]occupied][.[!]focused][.[!]urgent][.[!]local]
 ----
 
 Descriptors
 ^^^^^^^^^^^
 
 'CYCLE_DIR'::
-       Selects the desktop in the given direction relative to the active desktop.
+       Selects the desktop in the given direction relative to the reference desktop.
 
 last::
-       Selects the previously focused desktop.
+       Selects the previously focused desktop relative to the reference desktop.
 
 older::
-       Selects the desktop older than the focused desktop in the history.
+       Selects the desktop older than the reference desktop in the history.
 
 newer::
-       Selects the desktop newer than the focused desktop in the history.
+       Selects the desktop newer than the reference desktop in the history.
 
 focused::
        Selects the currently focused desktop.
@@ -217,7 +221,7 @@ Modifiers
        Only consider urgent or non urgent desktops.
 
 [!]local::
-       Only consider inside or outside of the current monitor.
+       Only consider inside or outside of the reference monitor.
 
 Monitor
 ~~~~~~~
@@ -225,26 +229,26 @@ Monitor
 Select a monitor.
 
 ----
-MONITOR_SEL := (DIR|CYCLE_DIR|last|older|newer|focused|primary|^<n>|<monitor_id>|<monitor_name>)[.[!]occupied][.[!]focused]
+MONITOR_SEL := [MONITOR_SEL#](DIR|CYCLE_DIR|last|older|newer|focused|primary|^<n>|<monitor_id>|<monitor_name>)[.[!]occupied][.[!]focused]
 ----
 
 Descriptors
 ^^^^^^^^^^^
 
 'DIR'::
-       Selects the monitor in the given (spacial) direction relative to the active monitor.
+       Selects the monitor in the given (spacial) direction relative to the reference monitor.
 
 'CYCLE_DIR'::
-       Selects the monitor in the given (cyclic) direction relative to the active monitor.
+       Selects the monitor in the given (cyclic) direction relative to the reference monitor.
 
 last::
-       Selects the previously focused monitor.
+       Selects the previously focused monitor relative to the reference monitor.
 
 older::
-       Selects the monitor older than the focused monitor in the history.
+       Selects the monitor older than the reference monitor in the history.
 
 newer::
-       Selects the monitor newer than the focused monitor in the history.
+       Selects the monitor newer than the reference monitor in the history.
 
 focused::
        Selects the currently focused monitor.
@@ -479,6 +483,8 @@ query 'COMMANDS' ['OPTIONS']
 Commands
 ^^^^^^^^
 
+The optional selectors are references.
+
 *-N*, *--nodes* ['NODE_SEL']::
        List the IDs of the matching nodes.
 
diff --git a/query.c b/query.c
index b9f80632aafd7c21654f6ca35a0e817a7ca40c3b..7a0e3e214047777dde5b8d9ffd7dec9a791d979e 100644 (file)
--- a/query.c
+++ b/query.c
@@ -379,8 +379,33 @@ monitor_select_t make_monitor_select(void)
 
 int node_from_desc(char *desc, coordinates_t *ref, coordinates_t *dst)
 {
+       coordinates_t ref_copy = *ref;
+       ref = &ref_copy;
        char *desc_copy = copy_string(desc, strlen(desc));
        desc = desc_copy;
+
+       char *hash = NULL;
+       char *path = strrchr(desc, '@');
+       if (path == NULL) {
+               hash = strrchr(desc, '#');
+       } else {
+               if (path != desc && *(path - 1) == '#') {
+                       hash = path - 1;
+               }
+       }
+
+       if (hash != NULL) {
+               *hash = '\0';
+               int ret;
+               coordinates_t tmp = {mon, mon->desk, mon->desk->focus};
+               if ((ret = node_from_desc(desc, &tmp, ref)) == SELECTOR_OK) {
+                       desc = hash + 1;
+               } else {
+                       free(desc_copy);
+                       return ret;
+               }
+       }
+
        node_select_t sel = make_node_select();
        char *colon = strrchr(desc, ':');
 
@@ -492,8 +517,25 @@ int node_from_desc(char *desc, coordinates_t *ref, coordinates_t *dst)
 
 int desktop_from_desc(char *desc, coordinates_t *ref, coordinates_t *dst)
 {
+       coordinates_t ref_copy = *ref;
+       ref = &ref_copy;
        char *desc_copy = copy_string(desc, strlen(desc));
        desc = desc_copy;
+
+       char *hash = strrchr(desc, '#');
+
+       if (hash != NULL) {
+               *hash = '\0';
+               int ret;
+               coordinates_t tmp = {mon, mon->desk, NULL};
+               if ((ret = desktop_from_desc(desc, &tmp, ref)) == SELECTOR_OK) {
+                       desc = hash + 1;
+               } else {
+                       free(desc_copy);
+                       return ret;
+               }
+       }
+
        desktop_select_t sel = make_desktop_select();
        char *colon = strrchr(desc, ':');
 
@@ -582,8 +624,25 @@ int desktop_from_desc(char *desc, coordinates_t *ref, coordinates_t *dst)
 
 int monitor_from_desc(char *desc, coordinates_t *ref, coordinates_t *dst)
 {
+       coordinates_t ref_copy = *ref;
+       ref = &ref_copy;
        char *desc_copy = copy_string(desc, strlen(desc));
        desc = desc_copy;
+
+       char *hash = strrchr(desc, '#');
+
+       if (hash != NULL) {
+               *hash = '\0';
+               int ret;
+               coordinates_t tmp = {mon, NULL, NULL};
+               if ((ret = monitor_from_desc(desc, &tmp, ref)) == SELECTOR_OK) {
+                       desc = hash + 1;
+               } else {
+                       free(desc_copy);
+                       return ret;
+               }
+       }
+
        monitor_select_t sel = make_monitor_select();
 
        if (!parse_monitor_modifiers(desc, &sel)) {