]> git.lizzy.rs Git - bspwm.git/commitdiff
Add the `--names` option to the `query` domain
authorBastien Dejean <nihilhill@gmail.com>
Fri, 4 Nov 2016 09:28:24 +0000 (10:28 +0100)
committerBastien Dejean <nihilhill@gmail.com>
Fri, 4 Nov 2016 09:28:24 +0000 (10:28 +0100)
Fixes #562.

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

index 525e3a542cc036c9ce5530efa5bafd4984508f33..4c4b970651d2a2d8b884b45674ae90766f12cc1e 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: 10/30/2016
+.\"      Date: 11/04/2016
 .\"    Manual: Bspwm Manual
 .\"    Source: Bspwm 0.9.2
 .\"  Language: English
 .\"
-.TH "BSPWM" "1" "10/30/2016" "Bspwm 0\&.9\&.2" "Bspwm Manual"
+.TH "BSPWM" "1" "11/04/2016" "Bspwm 0\&.9\&.2" "Bspwm Manual"
 .\" -----------------------------------------------------------------
 .\" * Define some portability stuff
 .\" -----------------------------------------------------------------
@@ -819,12 +819,12 @@ List the IDs of the matching nodes\&.
 .PP
 \fB\-D\fR, \fB\-\-desktops\fR [\fIDESKTOP_SEL\fR]
 .RS 4
-List the IDs of the matching desktops\&.
+List the IDs (or names) of the matching desktops\&.
 .RE
 .PP
 \fB\-M\fR, \fB\-\-monitors\fR [\fIMONITOR_SEL\fR]
 .RS 4
-List the IDs of the matching monitors\&.
+List the IDs (or names) of the matching monitors\&.
 .RE
 .PP
 \fB\-T\fR, \fB\-\-tree\fR
@@ -849,6 +849,11 @@ Constrain matches to the selected monitor, desktop or node\&. The descriptor can
 and
 \fI\-N\fR\&.
 .RE
+.PP
+\fB\-\-names\fR
+.RS 4
+Print names instead of IDs\&.
+.RE
 .RE
 .SS "Wm"
 .sp
index f3a5c2cd07815a55bd2b2a0c01e38b8d3ffd8505..a11980d7350ab24ab1a7c647f73f424fe48e6ec3 100644 (file)
@@ -492,10 +492,10 @@ The optional selectors are references.
        List the IDs of the matching nodes.
 
 *-D*, *--desktops* ['DESKTOP_SEL']::
-       List the IDs of the matching desktops.
+       List the IDs (or names) of the matching desktops.
 
 *-M*, *--monitors* ['MONITOR_SEL']::
-       List the IDs of the matching monitors.
+       List the IDs (or names) of the matching monitors.
 
 *-T*, *--tree*::
        Print a JSON representation of the matching item.
@@ -508,6 +508,9 @@ Options
 *-n*, *--node* ['NODE_SEL']::
        Constrain matches to the selected monitor, desktop or node. The descriptor can be omitted for '-M', '-D' and '-N'.
 
+*--names*::
+       Print names instead of IDs.
+
 Wm
 ~~
 
index adbfa17c4a86428cea935cfa465666ff94f3a268..9bd0391427201a27f348398842e79ac8862479f5 100644 (file)
@@ -894,6 +894,7 @@ void cmd_query(char **args, int num, FILE *rsp)
        desktop_select_t *desktop_sel = NULL;
        node_select_t *node_sel = NULL;
        domain_t dom = DOMAIN_TREE;
+       bool print_ids = true;
        uint8_t d = 0;
 
        if (num < 1) {
@@ -1008,6 +1009,8 @@ void cmd_query(char **args, int num, FILE *rsp)
                                        goto end;
                                }
                        }
+               } else if (streq("--names", *args)) {
+                       print_ids = false;
                } else {
                        fail(rsp, "query: Unknown option: '%s'.\n", *args);
                        goto end;
@@ -1035,11 +1038,11 @@ void cmd_query(char **args, int num, FILE *rsp)
                        fail(rsp, "");
                }
        } else if (dom == DOMAIN_DESKTOP) {
-               if (query_desktop_ids(&ref, &trg, desktop_sel, rsp) < 1) {
+               if (query_desktop_ids(&ref, &trg, desktop_sel, print_ids ? fprint_desktop_id : fprint_desktop_name, rsp) < 1) {
                        fail(rsp, "");
                }
        } else if (dom == DOMAIN_MONITOR) {
-               if (query_monitor_ids(&ref, &trg, monitor_sel, rsp) < 1) {
+               if (query_monitor_ids(&ref, &trg, monitor_sel, print_ids ? fprint_monitor_id : fprint_monitor_name, rsp) < 1) {
                        fail(rsp, "");
                }
        } else {
diff --git a/query.c b/query.c
index 025d5063c8948c348f15569931928770d137fb8a..bc51a4a233617ef1c2a00619a39796023e8cc569 100644 (file)
--- a/query.c
+++ b/query.c
@@ -247,7 +247,7 @@ int query_node_ids_in(node_t *n, desktop_t *d, monitor_t *m, coordinates_t *ref,
        return count;
 }
 
-int query_desktop_ids(coordinates_t *ref, coordinates_t *trg, desktop_select_t *sel, FILE *rsp)
+int query_desktop_ids(coordinates_t *ref, coordinates_t *trg, desktop_select_t *sel, desktop_printer_t printer, FILE *rsp)
 {
        int count = 0;
        for (monitor_t *m = mon_head; m != NULL; m = m->next) {
@@ -260,14 +260,14 @@ int query_desktop_ids(coordinates_t *ref, coordinates_t *trg, desktop_select_t *
                            (sel != NULL && !desktop_matches(&loc, ref, *sel))) {
                                continue;
                        }
-                       fprintf(rsp, "0x%08X\n", d->id);
+                       printer(d, rsp);
                        count++;
                }
        }
        return count;
 }
 
-int query_monitor_ids(coordinates_t *ref, coordinates_t *trg, monitor_select_t *sel, FILE *rsp)
+int query_monitor_ids(coordinates_t *ref, coordinates_t *trg, monitor_select_t *sel, monitor_printer_t printer, FILE *rsp)
 {
        int count = 0;
        for (monitor_t *m = mon_head; m != NULL; m = m->next) {
@@ -276,12 +276,32 @@ int query_monitor_ids(coordinates_t *ref, coordinates_t *trg, monitor_select_t *
                        (sel != NULL && !monitor_matches(&loc, ref, *sel))) {
                        continue;
                }
-               fprintf(rsp, "0x%08X\n", m->id);
+               printer(m, rsp);
                count++;
        }
        return count;
 }
 
+void fprint_monitor_id(monitor_t *m, FILE *rsp)
+{
+       fprintf(rsp, "0x%08X\n", m->id);
+}
+
+void fprint_monitor_name(monitor_t *m, FILE *rsp)
+{
+       fprintf(rsp, "%s\n", m->name);
+}
+
+void fprint_desktop_id(desktop_t *d, FILE *rsp)
+{
+       fprintf(rsp, "0x%08X\n", d->id);
+}
+
+void fprint_desktop_name(desktop_t *d, FILE *rsp)
+{
+       fprintf(rsp, "%s\n", d->name);
+}
+
 void print_modifier_mask(uint16_t m, FILE *rsp)
 {
        switch (m) {
diff --git a/query.h b/query.h
index e6be90254960ead4441bd9b73c1be84fe85988e9..2ff20d7bbfb93de89082b664f3e1a4cfd6334f72 100644 (file)
--- a/query.h
+++ b/query.h
@@ -41,6 +41,9 @@ enum {
        SELECTOR_BAD_DESCRIPTOR
 };
 
+typedef void (*monitor_printer_t)(monitor_t *m, FILE *rsp);
+typedef void (*desktop_printer_t)(desktop_t *m, FILE *rsp);
+
 void query_tree(FILE *rsp);
 void query_monitor(monitor_t *m, FILE *rsp);
 void query_desktop(desktop_t *d, FILE *rsp);
@@ -54,8 +57,12 @@ void query_coordinates(coordinates_t *loc, FILE *rsp);
 void query_stack(FILE *rsp);
 int query_node_ids(coordinates_t *ref, coordinates_t *trg, node_select_t *sel, FILE *rsp);
 int query_node_ids_in(node_t *n, desktop_t *d, monitor_t *m, coordinates_t *ref, coordinates_t *trg, node_select_t *sel, FILE *rsp);
-int query_desktop_ids(coordinates_t *ref, coordinates_t *trg, desktop_select_t *sel, FILE *rsp);
-int query_monitor_ids(coordinates_t *ref, coordinates_t *trg, monitor_select_t *sel, FILE *rsp);
+int query_desktop_ids(coordinates_t *ref, coordinates_t *trg, desktop_select_t *sel, desktop_printer_t printer, FILE *rsp);
+int query_monitor_ids(coordinates_t *ref, coordinates_t *trg, monitor_select_t *sel, monitor_printer_t printer, FILE *rsp);
+void fprint_monitor_id(monitor_t *m, FILE *rsp);
+void fprint_monitor_name(monitor_t *m, FILE *rsp);
+void fprint_desktop_id(desktop_t *d, FILE *rsp);
+void fprint_desktop_name(desktop_t *d, FILE *rsp);
 void print_modifier_mask(uint16_t m, FILE *rsp);
 void print_pointer_action(pointer_action_t a, FILE *rsp);
 node_select_t make_node_select(void);