Add the --names option to the query domain

Fixes #562.
This commit is contained in:
Bastien Dejean 2016-11-04 10:28:24 +01:00
parent 0482a74ceb
commit 73be87d104
5 changed files with 52 additions and 14 deletions

View 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

View 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
~~

View 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 {

28
query.c
View file

@ -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) {

11
query.h
View file

@ -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);