1 /* Copyright (c) 2012, Bastien Dejean
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
7 * 1. Redistributions of source code must retain the above copyright notice, this
8 * list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright notice,
10 * this list of conditions and the following disclaimer in the documentation
11 * and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
17 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
20 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
46 void handle_message(char *msg, int msg_len, FILE *rsp)
50 char **args = calloc(cap, sizeof(char *));
53 perror("Handle message: calloc");
57 for (int i = 0, j = 0; i < msg_len; i++) {
59 args[num++] = msg + j;
64 char **new = realloc(args, cap * sizeof(char *));
67 perror("Handle message: realloc");
77 fail(rsp, "No arguments given.\n");
81 char **args_orig = args;
82 process_message(args, num, rsp);
86 void process_message(char **args, int num, FILE *rsp)
88 if (streq("node", *args)) {
89 cmd_node(++args, --num, rsp);
90 } else if (streq("desktop", *args)) {
91 cmd_desktop(++args, --num, rsp);
92 } else if (streq("monitor", *args)) {
93 cmd_monitor(++args, --num, rsp);
94 } else if (streq("query", *args)) {
95 cmd_query(++args, --num, rsp);
96 } else if (streq("subscribe", *args)) {
97 cmd_subscribe(++args, --num, rsp);
99 } else if (streq("wm", *args)) {
100 cmd_wm(++args, --num, rsp);
101 } else if (streq("rule", *args)) {
102 cmd_rule(++args, --num, rsp);
103 } else if (streq("config", *args)) {
104 cmd_config(++args, --num, rsp);
105 } else if (streq("quit", *args)) {
106 cmd_quit(++args, --num, rsp);
108 fail(rsp, "Unknown domain or command: '%s'.\n", *args);
115 void cmd_node(char **args, int num, FILE *rsp)
118 fail(rsp, "node: Missing arguments.\n");
122 coordinates_t ref = {mon, mon->desk, mon->desk->focus};
123 coordinates_t trg = ref;
125 if ((*args)[0] != OPT_CHR) {
127 if ((ret = node_from_desc(*args, &ref, &trg)) == SELECTOR_OK) {
130 handle_failure(ret, "node", *args, rsp);
136 fail(rsp, "node: Missing commands.\n");
140 bool changed = false;
143 if (streq("-f", *args) || streq("--focus", *args)) {
144 coordinates_t dst = trg;
145 if (num > 1 && *(args + 1)[0] != OPT_CHR) {
148 if ((ret = node_from_desc(*args, &ref, &dst)) != SELECTOR_OK) {
149 handle_failure(ret, "node -f", *args, rsp);
153 if (dst.node == NULL || !focus_node(dst.monitor, dst.desktop, dst.node)) {
157 } else if (streq("-a", *args) || streq("--activate", *args)) {
158 coordinates_t dst = trg;
159 if (num > 1 && *(args + 1)[0] != OPT_CHR) {
162 if ((ret = node_from_desc(*args, &ref, &dst)) != SELECTOR_OK) {
163 handle_failure(ret, "node -a", *args, rsp);
167 if (dst.node == NULL || !activate_node(dst.monitor, dst.desktop, dst.node)) {
171 } else if (streq("-d", *args) || streq("--to-desktop", *args)) {
174 fail(rsp, "node %s: Not enough arguments.\n", *(args - 1));
179 if ((ret = desktop_from_desc(*args, &ref, &dst)) == SELECTOR_OK) {
181 if (num > 1 && streq("--follow", *(args+1))) {
185 if (transfer_node(trg.monitor, trg.desktop, trg.node, dst.monitor, dst.desktop, dst.desktop->focus, follow)) {
186 trg.monitor = dst.monitor;
187 trg.desktop = dst.desktop;
193 handle_failure(ret, "node -d", *args, rsp);
196 } else if (streq("-m", *args) || streq("--to-monitor", *args)) {
199 fail(rsp, "node %s: Not enough arguments.\n", *(args - 1));
204 if ((ret = monitor_from_desc(*args, &ref, &dst)) == SELECTOR_OK) {
206 if (num > 1 && streq("--follow", *(args+1))) {
210 if (transfer_node(trg.monitor, trg.desktop, trg.node, dst.monitor, dst.monitor->desk, dst.monitor->desk->focus, follow)) {
211 trg.monitor = dst.monitor;
212 trg.desktop = dst.monitor->desk;
218 handle_failure(ret, "node -m", *args, rsp);
221 } else if (streq("-n", *args) || streq("--to-node", *args)) {
224 fail(rsp, "node %s: Not enough arguments.\n", *(args - 1));
229 if ((ret = node_from_desc(*args, &ref, &dst)) == SELECTOR_OK) {
231 if (num > 1 && streq("--follow", *(args+1))) {
235 if (transfer_node(trg.monitor, trg.desktop, trg.node, dst.monitor, dst.desktop, dst.node, follow)) {
236 trg.monitor = dst.monitor;
237 trg.desktop = dst.desktop;
243 handle_failure(ret, "node -n", *args, rsp);
246 } else if (streq("-s", *args) || streq("--swap", *args)) {
249 fail(rsp, "node %s: Not enough arguments.\n", *(args - 1));
254 if ((ret = node_from_desc(*args, &ref, &dst)) == SELECTOR_OK) {
256 if (num > 1 && streq("--follow", *(args+1))) {
260 if (swap_nodes(trg.monitor, trg.desktop, trg.node, dst.monitor, dst.desktop, dst.node, follow)) {
261 trg.monitor = dst.monitor;
262 trg.desktop = dst.desktop;
268 handle_failure(ret, "node -s", *args, rsp);
271 } else if (streq("-l", *args) || streq("--layer", *args)) {
274 fail(rsp, "node %s: Not enough arguments.\n", *(args - 1));
278 if (parse_stack_layer(*args, &lyr)) {
279 if (!set_layer(trg.monitor, trg.desktop, trg.node, lyr)) {
284 fail(rsp, "node %s: Invalid argument: '%s'.\n", *(args - 1), *args);
287 } else if (streq("-t", *args) || streq("--state", *args)) {
290 fail(rsp, "node %s: Not enough arguments.\n", *(args - 1));
294 bool alternate = false;
295 if ((*args)[0] == '~') {
299 if (parse_client_state(*args, &cst)) {
300 if (alternate && trg.node != NULL && trg.node->client != NULL &&
301 trg.node->client->state == cst) {
302 cst = trg.node->client->last_state;
304 if (!set_state(trg.monitor, trg.desktop, trg.node, cst)) {
310 fail(rsp, "node %s: Invalid argument: '%s'.\n", *(args - 1), *args);
313 } else if (streq("-g", *args) || streq("--flag", *args)) {
316 fail(rsp, "node %s: Not enough arguments.\n", *(args - 1));
319 if (trg.node == NULL) {
323 char *key = strtok(*args, EQL_TOK);
324 char *val = strtok(NULL, EQL_TOK);
330 if (parse_bool(val, &b)) {
333 fail(rsp, "node %s: Invalid value for %s: '%s'.\n", *(args - 1), key, val);
337 if (streq("hidden", key)) {
338 set_hidden(trg.monitor, trg.desktop, trg.node, (a == ALTER_SET ? b : !trg.node->hidden));
340 } else if (streq("sticky", key)) {
341 set_sticky(trg.monitor, trg.desktop, trg.node, (a == ALTER_SET ? b : !trg.node->sticky));
342 } else if (streq("private", key)) {
343 set_private(trg.monitor, trg.desktop, trg.node, (a == ALTER_SET ? b : !trg.node->private));
344 } else if (streq("locked", key)) {
345 set_locked(trg.monitor, trg.desktop, trg.node, (a == ALTER_SET ? b : !trg.node->locked));
346 } else if (streq("marked", key)) {
347 set_marked(trg.monitor, trg.desktop, trg.node, (a == ALTER_SET ? b : !trg.node->marked));
349 fail(rsp, "node %s: Invalid key: '%s'.\n", *(args - 1), key);
352 } else if (streq("-p", *args) || streq("--presel-dir", *args)) {
355 fail(rsp, "node %s: Not enough arguments.\n", *(args - 1));
358 if (trg.node == NULL || trg.node->vacant) {
362 if (streq("cancel", *args)) {
363 cancel_presel(trg.monitor, trg.desktop, trg.node);
365 bool alternate = false;
366 if ((*args)[0] == '~') {
371 if (parse_direction(*args, &dir)) {
372 if (alternate && trg.node->presel != NULL && trg.node->presel->split_dir == dir) {
373 cancel_presel(trg.monitor, trg.desktop, trg.node);
375 presel_dir(trg.monitor, trg.desktop, trg.node, dir);
376 if (!IS_RECEPTACLE(trg.node)) {
377 draw_presel_feedback(trg.monitor, trg.desktop, trg.node);
381 fail(rsp, "node %s: Invalid argument: '%s%s'.\n", *(args - 1), alternate?"~":"", *args);
385 } else if (streq("-o", *args) || streq("--presel-ratio", *args)) {
388 fail(rsp, "node %s: Not enough arguments.\n", *(args - 1));
391 if (trg.node == NULL || trg.node->vacant) {
396 if (sscanf(*args, "%lf", &rat) != 1 || rat <= 0 || rat >= 1) {
397 fail(rsp, "node %s: Invalid argument: '%s'.\n", *(args - 1), *args);
400 presel_ratio(trg.monitor, trg.desktop, trg.node, rat);
401 draw_presel_feedback(trg.monitor, trg.desktop, trg.node);
403 } else if (streq("-v", *args) || streq("--move", *args)) {
406 fail(rsp, "node %s: Not enough arguments.\n", *(args - 1));
410 if (sscanf(*args, "%i", &dx) == 1) {
412 if (sscanf(*args, "%i", &dy) == 1) {
413 if (!move_client(&trg, dx, dy)) {
418 fail(rsp, "node %s: Invalid dy argument: '%s'.\n", *(args - 3), *args);
422 fail(rsp, "node %s: Invalid dx argument: '%s'.\n", *(args - 2), *args);
425 } else if (streq("-z", *args) || streq("--resize", *args)) {
428 fail(rsp, "node %s: Not enough arguments.\n", *(args - 1));
432 if (parse_resize_handle(*args, &rh)) {
435 if (sscanf(*args, "%i", &dx) == 1) {
437 if (sscanf(*args, "%i", &dy) == 1) {
438 if (!resize_client(&trg, rh, dx, dy, true)) {
443 fail(rsp, "node %s: Invalid dy argument: '%s'.\n", *(args - 3), *args);
447 fail(rsp, "node %s: Invalid dx argument: '%s'.\n", *(args - 2), *args);
451 fail(rsp, "node %s: Invalid resize handle argument: '%s'.\n", *(args - 1), *args);
454 } else if (streq("-r", *args) || streq("--ratio", *args)) {
457 fail(rsp, "node %s: Not enough arguments.\n", *(args - 1));
460 if (trg.node == NULL) {
464 if ((*args)[0] == '+' || (*args)[0] == '-') {
466 if (sscanf(*args, "%f", &delta) == 1) {
467 double rat = trg.node->split_ratio;
468 if (delta > -1 && delta < 1) {
471 int max = (trg.node->split_type == TYPE_HORIZONTAL ? trg.node->rectangle.height : trg.node->rectangle.width);
472 rat = ((max * rat) + delta) / max;
474 if (rat > 0 && rat < 1) {
475 set_ratio(trg.node, rat);
481 fail(rsp, "node %s: Invalid argument: '%s'.\n", *(args - 1), *args);
486 if (sscanf(*args, "%lf", &rat) == 1 && rat > 0 && rat < 1) {
487 set_ratio(trg.node, rat);
489 fail(rsp, "node %s: Invalid argument: '%s'.\n", *(args - 1), *args);
494 } else if (streq("-F", *args) || streq("--flip", *args)) {
497 fail(rsp, "node %s: Not enough arguments.\n", *(args - 1));
500 if (trg.node == NULL) {
505 if (parse_flip(*args, &flp)) {
506 flip_tree(trg.node, flp);
512 } else if (streq("-R", *args) || streq("--rotate", *args)) {
515 fail(rsp, "node %s: Not enough arguments.\n", *(args - 1));
518 if (trg.node == NULL) {
523 if (parse_degree(*args, °)) {
524 rotate_tree(trg.node, deg);
527 fail(rsp, "node %s: Invalid argument: '%s'.\n", *(args - 1), *args);
530 } else if (streq("-E", *args) || streq("--equalize", *args)) {
531 if (trg.node == NULL) {
535 equalize_tree(trg.node);
537 } else if (streq("-B", *args) || streq("--balance", *args)) {
538 if (trg.node == NULL) {
542 balance_tree(trg.node);
544 } else if (streq("-C", *args) || streq("--circulate", *args)) {
547 fail(rsp, "node %s: Not enough arguments.\n", *(args - 1));
550 if (trg.node == NULL) {
555 if (parse_circulate_direction(*args, &cir)) {
556 circulate_leaves(trg.monitor, trg.desktop, trg.node, cir);
559 fail(rsp, "node %s: Invalid argument: '%s'.\n", *(args - 1), *args);
562 } else if (streq("-i", *args) || streq("--insert-receptacle", *args)) {
563 insert_receptacle(trg.monitor, trg.desktop, trg.node);
565 } else if (streq("-c", *args) || streq("--close", *args)) {
567 fail(rsp, "node %s: Trailing commands.\n", *args);
570 if (trg.node == NULL || locked_count(trg.node) > 0) {
574 close_node(trg.node);
576 } else if (streq("-k", *args) || streq("--kill", *args)) {
578 fail(rsp, "node %s: Trailing commands.\n", *args);
581 if (trg.node == NULL) {
585 kill_node(trg.monitor, trg.desktop, trg.node);
589 fail(rsp, "node: Unknown command: '%s'.\n", *args);
597 arrange(trg.monitor, trg.desktop);
601 void cmd_desktop(char **args, int num, FILE *rsp)
604 fail(rsp, "desktop: Missing arguments.\n");
608 coordinates_t ref = {mon, mon->desk, NULL};
609 coordinates_t trg = ref;
611 if ((*args)[0] != OPT_CHR) {
613 if ((ret = desktop_from_desc(*args, &ref, &trg)) == SELECTOR_OK) {
616 handle_failure(ret, "desktop", *args, rsp);
622 fail(rsp, "desktop: Missing commands.\n");
626 bool changed = false;
629 if (streq("-f", *args) || streq("--focus", *args)) {
630 coordinates_t dst = trg;
631 if (num > 1 && *(args + 1)[0] != OPT_CHR) {
634 if ((ret = desktop_from_desc(*args, &ref, &dst)) != SELECTOR_OK) {
635 handle_failure(ret, "desktop -f", *args, rsp);
639 focus_node(dst.monitor, dst.desktop, NULL);
640 } else if (streq("-a", *args) || streq("--activate", *args)) {
641 coordinates_t dst = trg;
642 if (num > 1 && *(args + 1)[0] != OPT_CHR) {
645 if ((ret = desktop_from_desc(*args, &ref, &dst)) != SELECTOR_OK) {
646 handle_failure(ret, "desktop -a", *args, rsp);
650 if (activate_desktop(dst.monitor, dst.desktop)) {
651 activate_node(dst.monitor, dst.desktop, NULL);
656 } else if (streq("-m", *args) || streq("--to-monitor", *args)) {
659 fail(rsp, "desktop %s: Not enough arguments.\n", *(args - 1));
662 if (trg.monitor->desk_head == trg.monitor->desk_tail) {
668 if ((ret = monitor_from_desc(*args, &ref, &dst)) == SELECTOR_OK) {
670 if (num > 1 && streq("--follow", *(args+1))) {
674 if (transfer_desktop(trg.monitor, dst.monitor, trg.desktop, follow)) {
675 trg.monitor = dst.monitor;
681 handle_failure(ret, "desktop -m", *args, rsp);
684 } else if (streq("-s", *args) || streq("--swap", *args)) {
687 fail(rsp, "desktop %s: Not enough arguments.\n", *(args - 1));
692 if ((ret = desktop_from_desc(*args, &ref, &dst)) == SELECTOR_OK) {
694 if (num > 1 && streq("--follow", *(args+1))) {
698 if (swap_desktops(trg.monitor, trg.desktop, dst.monitor, dst.desktop, follow)) {
699 trg.monitor = dst.monitor;
705 handle_failure(ret, "desktop -s", *args, rsp);
708 } else if (streq("-b", *args) || streq("--bubble", *args)) {
711 fail(rsp, "desktop %s: Not enough arguments.\n", *(args - 1));
715 if (parse_cycle_direction(*args, &cyc)) {
716 desktop_t *d = trg.desktop;
717 if (cyc == CYCLE_PREV) {
718 if (d->prev == NULL) {
719 while (d->next != NULL) {
720 swap_desktops(trg.monitor, d, trg.monitor, d->next, false);
723 swap_desktops(trg.monitor, d, trg.monitor, d->prev, false);
726 if (d->next == NULL) {
727 while (d->prev != NULL) {
728 swap_desktops(trg.monitor, d, trg.monitor, d->prev, false);
731 swap_desktops(trg.monitor, d, trg.monitor, d->next, false);
735 fail(rsp, "desktop %s: Invalid argument: '%s'.\n", *(args - 1), *args);
738 } else if (streq("-l", *args) || streq("--layout", *args)) {
741 fail(rsp, "desktop %s: Not enough arguments.\n", *(args - 1));
747 if (parse_cycle_direction(*args, &cyc)) {
748 ret = set_layout(trg.monitor, trg.desktop, (trg.desktop->user_layout + 1) % 2, true);
749 } else if (parse_layout(*args, &lyt)) {
750 ret = set_layout(trg.monitor, trg.desktop, lyt, true);
752 fail(rsp, "desktop %s: Invalid argument: '%s'.\n", *(args - 1), *args);
759 } else if (streq("-n", *args) || streq("--rename", *args)) {
762 fail(rsp, "desktop %s: Not enough arguments.\n", *(args - 1));
765 rename_desktop(trg.monitor, trg.desktop, *args);
766 } else if (streq("-r", *args) || streq("--remove", *args)) {
768 fail(rsp, "desktop %s: Trailing commands.\n", *args);
771 if (trg.monitor->desk_head != trg.monitor->desk_tail) {
772 desktop_t *fallback = trg.desktop->prev == NULL ?
775 merge_desktops(trg.monitor, trg.desktop, trg.monitor, fallback);
776 remove_desktop(trg.monitor, trg.desktop);
783 fail(rsp, "desktop: Unknown command: '%s'.\n", *args);
790 arrange(trg.monitor, trg.desktop);
794 void cmd_monitor(char **args, int num, FILE *rsp)
797 fail(rsp, "monitor: Missing arguments.\n");
801 coordinates_t ref = {mon, NULL, NULL};
802 coordinates_t trg = ref;
804 if ((*args)[0] != OPT_CHR) {
806 if ((ret = monitor_from_desc(*args, &ref, &trg)) == SELECTOR_OK) {
809 handle_failure(ret, "monitor", *args, rsp);
815 fail(rsp, "monitor: Missing commands.\n");
820 if (streq("-f", *args) || streq("--focus", *args)) {
821 coordinates_t dst = trg;
822 if (num > 1 && *(args + 1)[0] != OPT_CHR) {
825 if ((ret = monitor_from_desc(*args, &ref, &dst)) != SELECTOR_OK) {
826 handle_failure(ret, "monitor -f", *args, rsp);
831 focus_node(dst.monitor, NULL, NULL);
832 } else if (streq("-s", *args) || streq("--swap", *args)) {
835 fail(rsp, "monitor %s: Not enough arguments.\n", *(args - 1));
840 if ((ret = monitor_from_desc(*args, &ref, &dst)) == SELECTOR_OK) {
841 if (!swap_monitors(trg.monitor, dst.monitor)) {
846 handle_failure(ret, "monitor -s", *args, rsp);
849 } else if (streq("-d", *args) || streq("--reset-desktops", *args)) {
852 fail(rsp, "monitor %s: Not enough arguments.\n", *(args - 1));
855 desktop_t *d = trg.monitor->desk_head;
856 while (num > 0 && d != NULL) {
857 rename_desktop(trg.monitor, d, *args);
861 put_status(SBSC_MASK_REPORT);
863 add_desktop(trg.monitor, make_desktop(*args, XCB_NONE));
867 desktop_t *next = d->next;
868 if (d == mon->desk) {
869 focus_node(trg.monitor, d->prev, d->prev->focus);
871 merge_desktops(trg.monitor, d, mon, mon->desk);
872 remove_desktop(trg.monitor, d);
875 } else if (streq("-a", *args) || streq("--add-desktops", *args)) {
878 fail(rsp, "monitor %s: Not enough arguments.\n", *(args - 1));
882 add_desktop(trg.monitor, make_desktop(*args, XCB_NONE));
885 } else if (streq("-r", *args) || streq("--remove", *args)) {
887 fail(rsp, "monitor %s: Trailing commands.\n", *args);
890 if (mon_head == mon_tail) {
894 remove_monitor(trg.monitor);
896 } else if (streq("-o", *args) || streq("--reorder-desktops", *args)) {
899 fail(rsp, "monitor %s: Not enough arguments.\n", *(args - 1));
902 desktop_t *d = trg.monitor->desk_head;
903 while (d != NULL && num > 0) {
904 desktop_t *next = d->next;
906 if (locate_desktop(*args, &dst) && dst.monitor == trg.monitor) {
907 swap_desktops(trg.monitor, d, dst.monitor, dst.desktop, false);
908 if (next == dst.desktop) {
915 } else if (streq("-g", *args) || streq("--rectangle", *args)) {
918 fail(rsp, "monitor %s: Not enough arguments.\n", *(args - 1));
922 if (parse_rectangle(*args, &r)) {
923 update_root(trg.monitor, &r);
925 fail(rsp, "monitor %s: Invalid argument: '%s'.\n", *(args - 1), *args);
928 } else if (streq("-n", *args) || streq("--rename", *args)) {
931 fail(rsp, "monitor %s: Not enough arguments.\n", *(args - 1));
934 rename_monitor(trg.monitor, *args);
936 fail(rsp, "monitor: Unknown command: '%s'.\n", *args);
943 void cmd_query(char **args, int num, FILE *rsp)
945 coordinates_t ref = {mon, mon->desk, mon->desk->focus};
946 coordinates_t trg = {NULL, NULL, NULL};
947 monitor_select_t *monitor_sel = NULL;
948 desktop_select_t *desktop_sel = NULL;
949 node_select_t *node_sel = NULL;
950 domain_t dom = DOMAIN_TREE;
951 bool print_ids = true;
955 fail(rsp, "query: Missing arguments.\n");
960 if (streq("-T", *args) || streq("--tree", *args)) {
961 dom = DOMAIN_TREE, d++;
962 } else if (streq("-M", *args) || streq("--monitors", *args)) {
963 dom = DOMAIN_MONITOR, d++;
964 if (num > 1 && *(args + 1)[0] != OPT_CHR) {
967 coordinates_t tmp = ref;
970 if ((ret = monitor_from_desc(*args, &tmp, &ref)) != SELECTOR_OK) {
971 handle_failure(ret, "query -M", *args, rsp);
975 } else if (streq("-D", *args) || streq("--desktops", *args)) {
976 dom = DOMAIN_DESKTOP, d++;
977 if (num > 1 && *(args + 1)[0] != OPT_CHR) {
980 coordinates_t tmp = ref;
982 if ((ret = desktop_from_desc(*args, &tmp, &ref)) != SELECTOR_OK) {
983 handle_failure(ret, "query -D", *args, rsp);
987 } else if (streq("-N", *args) || streq("--nodes", *args)) {
988 dom = DOMAIN_NODE, d++;
989 if (num > 1 && *(args + 1)[0] != OPT_CHR) {
992 coordinates_t tmp = ref;
993 if ((ret = node_from_desc(*args, &tmp, &ref)) != SELECTOR_OK) {
994 handle_failure(ret, "query -N", *args, rsp);
998 } else if (streq("-m", *args) || streq("--monitor", *args)) {
999 if (num > 1 && *(args + 1)[0] != OPT_CHR) {
1002 if ((*args)[0] == '.') {
1004 monitor_sel = malloc(sizeof(monitor_select_t));
1005 *monitor_sel = make_monitor_select();
1006 char *desc = copy_string(*args, strlen(*args));
1007 if (!parse_monitor_modifiers(desc, monitor_sel)) {
1008 handle_failure(SELECTOR_BAD_MODIFIERS, "query -m", *args, rsp);
1013 } else if ((ret = monitor_from_desc(*args, &ref, &trg)) != SELECTOR_OK) {
1014 handle_failure(ret, "query -m", *args, rsp);
1018 trg.monitor = ref.monitor;
1020 } else if (streq("-d", *args) || streq("--desktop", *args)) {
1021 if (num > 1 && *(args + 1)[0] != OPT_CHR) {
1024 if ((*args)[0] == '.') {
1026 desktop_sel = malloc(sizeof(desktop_select_t));
1027 *desktop_sel = make_desktop_select();
1028 char *desc = copy_string(*args, strlen(*args));
1029 if (!parse_desktop_modifiers(desc, desktop_sel)) {
1030 handle_failure(SELECTOR_BAD_MODIFIERS, "query -d", *args, rsp);
1035 } else if ((ret = desktop_from_desc(*args, &ref, &trg)) != SELECTOR_OK) {
1036 handle_failure(ret, "query -d", *args, rsp);
1040 trg.monitor = ref.monitor;
1041 trg.desktop = ref.desktop;
1043 } else if (streq("-n", *args) || streq("--node", *args)) {
1044 if (num > 1 && *(args + 1)[0] != OPT_CHR) {
1047 if ((*args)[0] == '.') {
1049 node_sel = malloc(sizeof(node_select_t));
1050 *node_sel = make_node_select();
1051 char *desc = copy_string(*args, strlen(*args));
1052 if (!parse_node_modifiers(desc, node_sel)) {
1053 handle_failure(SELECTOR_BAD_MODIFIERS, "query -n", *args, rsp);
1058 } else if ((ret = node_from_desc(*args, &ref, &trg)) != SELECTOR_OK) {
1059 handle_failure(ret, "query -n", *args, rsp);
1064 if (ref.node == NULL) {
1069 } else if (streq("--names", *args)) {
1072 fail(rsp, "query: Unknown option: '%s'.\n", *args);
1079 fail(rsp, "query: No commands given.\n");
1084 fail(rsp, "query: Multiple commands given.\n");
1088 if (dom == DOMAIN_TREE && trg.monitor == NULL) {
1089 fail(rsp, "query -T: No options given.\n");
1093 if (!print_ids && (dom == DOMAIN_NODE || dom == DOMAIN_TREE)) {
1094 fail(rsp, "query -%c: --names only applies to -M and -D.\n", dom == DOMAIN_NODE ? 'N' : 'T');
1098 if ((dom == DOMAIN_MONITOR && (desktop_sel != NULL || node_sel != NULL)) ||
1099 (dom == DOMAIN_DESKTOP && node_sel != NULL)) {
1100 fail(rsp, "query -%c: Incompatible descriptor-free constraints.\n", dom == DOMAIN_MONITOR ? 'M' : 'D');
1104 if (dom == DOMAIN_NODE) {
1105 if (query_node_ids(&ref, &trg, monitor_sel, desktop_sel, node_sel, rsp) < 1) {
1108 } else if (dom == DOMAIN_DESKTOP) {
1109 if (query_desktop_ids(&ref, &trg, monitor_sel, desktop_sel, print_ids ? fprint_desktop_id : fprint_desktop_name, rsp) < 1) {
1112 } else if (dom == DOMAIN_MONITOR) {
1113 if (query_monitor_ids(&ref, &trg, monitor_sel, print_ids ? fprint_monitor_id : fprint_monitor_name, rsp) < 1) {
1117 if (trg.node != NULL) {
1118 query_node(trg.node, rsp);
1119 } else if (trg.desktop != NULL) {
1120 query_desktop(trg.desktop, rsp);
1122 query_monitor(trg.monitor, rsp);
1133 void cmd_rule(char **args, int num, FILE *rsp)
1136 fail(rsp, "rule: Missing commands.\n");
1141 if (streq("-a", *args) || streq("--add", *args)) {
1144 fail(rsp, "rule %s: Not enough arguments.\n", *(args - 1));
1147 rule_t *rule = make_rule();
1148 char *class_name = strtok(*args, COL_TOK);
1149 char *instance_name = strtok(NULL, COL_TOK);
1150 char *name = strtok(NULL, COL_TOK);
1151 snprintf(rule->class_name, sizeof(rule->class_name), "%s", class_name);
1152 snprintf(rule->instance_name, sizeof(rule->instance_name), "%s", instance_name==NULL?MATCH_ANY:instance_name);
1153 snprintf(rule->name, sizeof(rule->name), "%s", name==NULL?MATCH_ANY:name);
1157 if (streq("-o", *args) || streq("--one-shot", *args)) {
1158 rule->one_shot = true;
1160 for (size_t j = 0; i < sizeof(rule->effect) && j < strlen(*args); i++, j++) {
1161 rule->effect[i] = (*args)[j];
1163 if (num > 1 && i < sizeof(rule->effect)) {
1164 rule->effect[i++] = ' ';
1169 rule->effect[MIN(i, sizeof(rule->effect) - 1)] = '\0';
1171 } else if (streq("-r", *args) || streq("--remove", *args)) {
1174 fail(rsp, "rule %s: Not enough arguments.\n", *(args - 1));
1179 if (parse_index(*args, &idx)) {
1180 remove_rule_by_index(idx - 1);
1181 } else if (streq("tail", *args)) {
1182 remove_rule(rule_tail);
1183 } else if (streq("head", *args)) {
1184 remove_rule(rule_head);
1186 remove_rule_by_cause(*args);
1190 } else if (streq("-l", *args) || streq("--list", *args)) {
1193 fail(rsp, "rule: Unknown command: '%s'.\n", *args);
1200 void cmd_wm(char **args, int num, FILE *rsp)
1203 fail(rsp, "wm: Missing commands.\n");
1208 if (streq("-d", *args) || streq("--dump-state", *args)) {
1211 } else if (streq("-l", *args) || streq("--load-state", *args)) {
1214 fail(rsp, "wm %s: Not enough arguments.\n", *(args - 1));
1217 if (!restore_state(*args)) {
1221 } else if (streq("-a", *args) || streq("--add-monitor", *args)) {
1224 fail(rsp, "wm %s: Not enough arguments.\n", *(args - 1));
1230 if (parse_rectangle(*args, &r)) {
1231 monitor_t *m = make_monitor(name, &r, XCB_NONE);
1233 add_desktop(m, make_desktop(NULL, XCB_NONE));
1235 fail(rsp, "wm %s: Invalid argument: '%s'.\n", *(args - 1), *args);
1238 } else if (streq("-O", *args) || streq("--reorder-monitors", *args)) {
1241 fail(rsp, "wm %s: Not enough arguments.\n", *(args - 1));
1244 monitor_t *m = mon_head;
1245 while (m != NULL && num > 0) {
1246 monitor_t *next = m->next;
1248 if (locate_monitor(*args, &dst)) {
1249 swap_monitors(m, dst.monitor);
1250 if (next == dst.monitor) {
1257 } else if (streq("-o", *args) || streq("--adopt-orphans", *args)) {
1259 } else if (streq("-g", *args) || streq("--get-status", *args)) {
1261 } else if (streq("-h", *args) || streq("--record-history", *args)) {
1264 fail(rsp, "wm %s: Not enough arguments.\n", *(args - 1));
1268 if (parse_bool(*args, &b)) {
1271 fail(rsp, "wm %s: Invalid argument: '%s'.\n", *(args - 1), *args);
1274 } else if (streq("-r", *args) || streq("--restart", *args)) {
1279 fail(rsp, "wm: Unknown command: '%s'.\n", *args);
1286 void cmd_subscribe(char **args, int num, FILE *rsp)
1291 char *fifo_path = NULL;
1292 subscriber_mask_t mask;
1295 if (streq("-c", *args) || streq("--count", *args)) {
1298 fail(rsp, "subscribe %s: Not enough arguments.\n", *(args - 1));
1301 if (sscanf(*args, "%i", &count) != 1 || count < 1) {
1302 fail(rsp, "subscribe %s: Invalid argument: '%s'.\n", *(args - 1), *args);
1305 } else if (streq("-f", *args) || streq("--fifo", *args)) {
1306 fifo_path = mktempfifo(FIFO_TEMPLATE);
1307 if (fifo_path == NULL) {
1308 fail(rsp, "subscribe %s: Can't create FIFO.\n", *(args - 1));
1311 } else if (parse_subscriber_mask(*args, &mask)) {
1314 fail(rsp, "subscribe: Invalid argument: '%s'.\n", *args);
1321 field = SBSC_MASK_REPORT;
1325 fprintf(rsp, "%s\n", fifo_path);
1329 stream = fopen(fifo_path, "w");
1331 if (stream == NULL) {
1332 perror("subscribe: fopen");
1333 goto free_fifo_path;
1336 fprintf(rsp, SUBSCRIBE_MESSAGE);
1340 subscriber_list_t *sb = make_subscriber(stream, fifo_path, field, count);
1355 void cmd_quit(char **args, int num, FILE *rsp)
1357 if (num > 0 && sscanf(*args, "%i", &exit_status) != 1) {
1358 fail(rsp, "%s: Invalid argument: '%s'.\n", *(args - 1), *args);
1364 void cmd_config(char **args, int num, FILE *rsp)
1367 fail(rsp, "config: Missing arguments.\n");
1371 coordinates_t ref = {mon, mon->desk, mon->desk->focus};
1372 coordinates_t trg = {NULL, NULL, NULL};
1374 while (num > 0 && (*args)[0] == OPT_CHR) {
1375 if (streq("-m", *args) || streq("--monitor", *args)) {
1378 fail(rsp, "config %s: Not enough arguments.\n", *(args - 1));
1382 if ((ret = monitor_from_desc(*args, &ref, &trg)) != SELECTOR_OK) {
1383 handle_failure(ret, "config -m", *args, rsp);
1386 } else if (streq("-d", *args) || streq("--desktop", *args)) {
1389 fail(rsp, "config %s: Not enough arguments.\n", *(args - 1));
1393 if ((ret = desktop_from_desc(*args, &ref, &trg)) != SELECTOR_OK) {
1394 handle_failure(ret, "config -d", *args, rsp);
1397 } else if (streq("-n", *args) || streq("--node", *args)) {
1400 fail(rsp, "config %s: Not enough arguments.\n", *(args - 1));
1404 if ((ret = node_from_desc(*args, &ref, &trg)) != SELECTOR_OK) {
1405 handle_failure(ret, "config -n", *args, rsp);
1409 fail(rsp, "config: Unknown option: '%s'.\n", *args);
1415 set_setting(trg, *args, *(args + 1), rsp);
1416 } else if (num == 1) {
1417 get_setting(trg, *args, rsp);
1419 fail(rsp, "config: Was expecting 1 or 2 arguments, received %i.\n", num);
1423 void set_setting(coordinates_t loc, char *name, char *value, FILE *rsp)
1425 bool colors_changed = false;
1426 #define SET_DEF_DEFMON_DEFDESK_WIN(k, v) \
1427 if (loc.node != NULL) { \
1428 for (node_t *n = first_extrema(loc.node); n != NULL; n = next_leaf(n, loc.node)) { \
1429 if (n->client != NULL) { \
1433 } else if (loc.desktop != NULL) { \
1434 loc.desktop->k = v; \
1435 for (node_t *n = first_extrema(loc.desktop->root); n != NULL; n = next_leaf(n, loc.desktop->root)) { \
1436 if (n->client != NULL) { \
1440 } else if (loc.monitor != NULL) { \
1441 loc.monitor->k = v; \
1442 for (desktop_t *d = loc.monitor->desk_head; d != NULL; d = d->next) { \
1444 for (node_t *n = first_extrema(d->root); n != NULL; n = next_leaf(n, d->root)) { \
1445 if (n->client != NULL) { \
1452 for (monitor_t *m = mon_head; m != NULL; m = m->next) { \
1454 for (desktop_t *d = m->desk_head; d != NULL; d = d->next) { \
1456 for (node_t *n = first_extrema(d->root); n != NULL; n = next_leaf(n, d->root)) { \
1457 if (n->client != NULL) { \
1464 if (streq("border_width", name)) {
1466 if (sscanf(value, "%u", &bw) != 1) {
1467 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1470 SET_DEF_DEFMON_DEFDESK_WIN(border_width, bw)
1471 #undef SET_DEF_DEFMON_DEFDESK_WIN
1472 #define SET_DEF_DEFMON_DESK(k, v) \
1473 if (loc.desktop != NULL) { \
1474 loc.desktop->k = v; \
1475 } else if (loc.monitor != NULL) { \
1476 loc.monitor->k = v; \
1477 for (desktop_t *d = loc.monitor->desk_head; d != NULL; d = d->next) { \
1482 for (monitor_t *m = mon_head; m != NULL; m = m->next) { \
1484 for (desktop_t *d = m->desk_head; d != NULL; d = d->next) { \
1489 } else if (streq("window_gap", name)) {
1491 if (sscanf(value, "%i", &wg) != 1) {
1495 SET_DEF_DEFMON_DESK(window_gap, wg)
1496 #undef SET_DEF_DEFMON_DESK
1497 #define SET_DEF_MON_DESK(k, v) \
1498 if (loc.desktop != NULL) { \
1499 loc.desktop->k = v; \
1500 } else if (loc.monitor != NULL) { \
1501 loc.monitor->k = v; \
1504 for (monitor_t *m = mon_head; m != NULL; m = m->next) { \
1508 } else if (streq("top_padding", name)) {
1510 if (sscanf(value, "%i", &tp) != 1) {
1511 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1514 SET_DEF_MON_DESK(padding.top, tp)
1515 } else if (streq("right_padding", name)) {
1517 if (sscanf(value, "%i", &rp) != 1) {
1518 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1521 SET_DEF_MON_DESK(padding.right, rp)
1522 } else if (streq("bottom_padding", name)) {
1524 if (sscanf(value, "%i", &bp) != 1) {
1525 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1528 SET_DEF_MON_DESK(padding.bottom, bp)
1529 } else if (streq("left_padding", name)) {
1531 if (sscanf(value, "%i", &lp) != 1) {
1532 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1535 SET_DEF_MON_DESK(padding.left, lp)
1536 #undef SET_DEF_MON_DESK
1537 } else if (streq("top_monocle_padding", name)) {
1538 if (sscanf(value, "%i", &monocle_padding.top) != 1) {
1539 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1541 } else if (streq("right_monocle_padding", name)) {
1542 if (sscanf(value, "%i", &monocle_padding.right) != 1) {
1543 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1545 } else if (streq("bottom_monocle_padding", name)) {
1546 if (sscanf(value, "%i", &monocle_padding.bottom) != 1) {
1547 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1549 } else if (streq("left_monocle_padding", name)) {
1550 if (sscanf(value, "%i", &monocle_padding.left) != 1) {
1551 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1553 #define SET_STR(s) \
1554 } else if (streq(#s, name)) { \
1555 if (snprintf(s, sizeof(s), "%s", value) < 0) { \
1559 SET_STR(external_rules_command)
1560 SET_STR(status_prefix)
1562 } else if (streq("split_ratio", name)) {
1564 if (sscanf(value, "%lf", &r) == 1 && r > 0 && r < 1) {
1567 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value); \
1571 #define SET_COLOR(s) \
1572 } else if (streq(#s, name)) { \
1573 if (!is_hex_color(value)) { \
1574 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value); \
1577 snprintf(s, sizeof(s), "%s", value); \
1578 colors_changed = true; \
1580 SET_COLOR(normal_border_color)
1581 SET_COLOR(active_border_color)
1582 SET_COLOR(focused_border_color)
1583 SET_COLOR(presel_feedback_color)
1585 } else if (streq("initial_polarity", name)) {
1587 if (parse_child_polarity(value, &p)) {
1588 initial_polarity = p;
1590 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1593 } else if (streq("automatic_scheme", name)) {
1594 automatic_scheme_t a;
1595 if (parse_automatic_scheme(value, &a)) {
1596 automatic_scheme = a;
1598 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1601 } else if (streq("mapping_events_count", name)) {
1602 if (sscanf(value, "%" SCNi8, &mapping_events_count) != 1) {
1603 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1606 } else if (streq("directional_focus_tightness", name)) {
1608 if (parse_tightness(value, &p)) {
1609 directional_focus_tightness = p;
1611 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1614 } else if (streq("ignore_ewmh_fullscreen", name)) {
1615 state_transition_t m;
1616 if (parse_state_transition(value, &m)) {
1617 ignore_ewmh_fullscreen = m;
1619 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1622 } else if (streq("pointer_modifier", name)) {
1623 if (parse_modifier_mask(value, &pointer_modifier)) {
1627 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1630 } else if (streq("pointer_motion_interval", name)) {
1631 if (sscanf(value, "%u", &pointer_motion_interval) != 1) {
1632 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1635 } else if (streq("pointer_action1", name) ||
1636 streq("pointer_action2", name) ||
1637 streq("pointer_action3", name)) {
1638 int index = name[14] - '1';
1639 if (parse_pointer_action(value, &pointer_actions[index])) {
1643 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1646 } else if (streq("click_to_focus", name)) {
1647 if (parse_button_index(value, &click_to_focus)) {
1651 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1654 } else if (streq("single_monocle", name)) {
1656 if (parse_bool(value, &b)) {
1657 if (b == single_monocle) {
1662 for (monitor_t *m = mon_head; m != NULL; m = m->next) {
1663 for (desktop_t *d = m->desk_head; d != NULL; d = d->next) {
1664 layout_t l = (single_monocle && tiled_count(d->root, true) <= 1) ? LAYOUT_MONOCLE : d->user_layout;
1665 set_layout(m, d, l, false);
1669 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1672 } else if (streq("focus_follows_pointer", name)) {
1674 if (parse_bool(value, &b)) {
1675 if (b == focus_follows_pointer) {
1679 focus_follows_pointer = b;
1680 for (monitor_t *m = mon_head; m != NULL; m = m->next) {
1681 if (focus_follows_pointer) {
1682 window_show(m->root);
1684 window_hide(m->root);
1686 for (desktop_t *d = m->desk_head; d != NULL; d = d->next) {
1687 listen_enter_notify(d->root, focus_follows_pointer);
1690 if (focus_follows_pointer) {
1691 update_motion_recorder();
1693 disable_motion_recorder();
1697 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1700 #define SET_BOOL(s) \
1701 } else if (streq(#s, name)) { \
1702 if (!parse_bool(value, &s)) { \
1703 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value); \
1706 SET_BOOL(presel_feedback)
1707 SET_BOOL(borderless_monocle)
1708 SET_BOOL(gapless_monocle)
1709 SET_BOOL(swallow_first_click)
1710 SET_BOOL(pointer_follows_focus)
1711 SET_BOOL(pointer_follows_monitor)
1712 SET_BOOL(ignore_ewmh_focus)
1713 SET_BOOL(ignore_ewmh_struts)
1714 SET_BOOL(center_pseudo_tiled)
1715 SET_BOOL(honor_size_hints)
1716 SET_BOOL(removal_adjustment)
1718 #define SET_MON_BOOL(s) \
1719 } else if (streq(#s, name)) { \
1720 if (!parse_bool(value, &s)) { \
1721 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value); \
1725 update_monitors(); \
1727 SET_MON_BOOL(remove_disabled_monitors)
1728 SET_MON_BOOL(remove_unplugged_monitors)
1729 SET_MON_BOOL(merge_overlapping_monitors)
1732 fail(rsp, "config: Unknown setting: '%s'.\n", name);
1736 for (monitor_t *m = mon_head; m != NULL; m = m->next) {
1737 for (desktop_t *d = m->desk_head; d != NULL; d = d->next) {
1739 if (colors_changed) {
1740 update_colors_in(d->root, d, m);
1746 void get_setting(coordinates_t loc, char *name, FILE* rsp)
1748 if (streq("split_ratio", name)) {
1749 fprintf(rsp, "%lf", split_ratio);
1750 } else if (streq("border_width", name)) {
1751 if (loc.node != NULL) {
1752 for (node_t *n = first_extrema(loc.node); n != NULL; n = next_leaf(n, loc.node)) {
1753 if (n->client != NULL) {
1754 fprintf(rsp, "%u", n->client->border_width);
1758 } else if (loc.desktop != NULL) {
1759 fprintf(rsp, "%u", loc.desktop->border_width);
1760 } else if (loc.monitor != NULL) {
1761 fprintf(rsp, "%u", loc.monitor->border_width);
1763 fprintf(rsp, "%u", border_width);
1765 } else if (streq("window_gap", name)) {
1766 if (loc.desktop != NULL) {
1767 fprintf(rsp, "%i", loc.desktop->window_gap);
1768 } else if (loc.monitor != NULL) {
1769 fprintf(rsp, "%i", loc.monitor->window_gap);
1771 fprintf(rsp, "%i", window_gap);
1773 #define GET_DEF_MON_DESK(k) \
1774 if (loc.desktop != NULL) { \
1775 fprintf(rsp, "%i", loc.desktop->k); \
1776 } else if (loc.monitor != NULL) { \
1777 fprintf(rsp, "%i", loc.monitor->k); \
1779 fprintf(rsp, "%i", k); \
1781 } else if (streq("top_padding", name)) {
1782 GET_DEF_MON_DESK(padding.top)
1783 } else if (streq("right_padding", name)) {
1784 GET_DEF_MON_DESK(padding.right)
1785 } else if (streq("bottom_padding", name)) {
1786 GET_DEF_MON_DESK(padding.bottom)
1787 } else if (streq("left_padding", name)) {
1788 GET_DEF_MON_DESK(padding.left)
1789 #undef GET_DEF_MON_DESK
1790 } else if (streq("top_monocle_padding", name)) {
1791 fprintf(rsp, "%i", monocle_padding.top);
1792 } else if (streq("right_monocle_padding", name)) {
1793 fprintf(rsp, "%i", monocle_padding.right);
1794 } else if (streq("bottom_monocle_padding", name)) {
1795 fprintf(rsp, "%i", monocle_padding.bottom);
1796 } else if (streq("left_monocle_padding", name)) {
1797 fprintf(rsp, "%i", monocle_padding.left);
1798 } else if (streq("external_rules_command", name)) {
1799 fprintf(rsp, "%s", external_rules_command);
1800 } else if (streq("status_prefix", name)) {
1801 fprintf(rsp, "%s", status_prefix);
1802 } else if (streq("initial_polarity", name)) {
1803 fprintf(rsp, "%s", CHILD_POL_STR(initial_polarity));
1804 } else if (streq("automatic_scheme", name)) {
1805 fprintf(rsp, "%s", AUTO_SCM_STR(automatic_scheme));
1806 } else if (streq("mapping_events_count", name)) {
1807 fprintf(rsp, "%" PRIi8, mapping_events_count);
1808 } else if (streq("directional_focus_tightness", name)) {
1809 fprintf(rsp, "%s", TIGHTNESS_STR(directional_focus_tightness));
1810 } else if (streq("ignore_ewmh_fullscreen", name)) {
1811 print_ignore_request(ignore_ewmh_fullscreen, rsp);
1812 } else if (streq("pointer_modifier", name)) {
1813 print_modifier_mask(pointer_modifier, rsp);
1814 } else if (streq("click_to_focus", name)) {
1815 print_button_index(click_to_focus, rsp);
1816 } else if (streq("pointer_motion_interval", name)) {
1817 fprintf(rsp, "%u", pointer_motion_interval);
1818 } else if (streq("pointer_action1", name) ||
1819 streq("pointer_action2", name) ||
1820 streq("pointer_action3", name)) {
1821 int index = name[14] - '1';
1822 print_pointer_action(pointer_actions[index], rsp);
1823 #define GET_COLOR(s) \
1824 } else if (streq(#s, name)) { \
1825 fprintf(rsp, "%s", s);
1826 GET_COLOR(normal_border_color)
1827 GET_COLOR(active_border_color)
1828 GET_COLOR(focused_border_color)
1829 GET_COLOR(presel_feedback_color)
1831 #define GET_BOOL(s) \
1832 } else if (streq(#s, name)) { \
1833 fprintf(rsp, "%s", BOOL_STR(s));
1834 GET_BOOL(presel_feedback)
1835 GET_BOOL(borderless_monocle)
1836 GET_BOOL(gapless_monocle)
1837 GET_BOOL(single_monocle)
1838 GET_BOOL(swallow_first_click)
1839 GET_BOOL(focus_follows_pointer)
1840 GET_BOOL(pointer_follows_focus)
1841 GET_BOOL(pointer_follows_monitor)
1842 GET_BOOL(ignore_ewmh_focus)
1843 GET_BOOL(ignore_ewmh_struts)
1844 GET_BOOL(center_pseudo_tiled)
1845 GET_BOOL(honor_size_hints)
1846 GET_BOOL(removal_adjustment)
1847 GET_BOOL(remove_disabled_monitors)
1848 GET_BOOL(remove_unplugged_monitors)
1849 GET_BOOL(merge_overlapping_monitors)
1852 fail(rsp, "config: Unknown setting: '%s'.\n", name);
1858 void handle_failure(int code, char *src, char *val, FILE *rsp)
1861 case SELECTOR_BAD_DESCRIPTOR:
1862 fail(rsp, "%s: Invalid descriptor found in '%s'.\n", src, val);
1864 case SELECTOR_BAD_MODIFIERS:
1865 fail(rsp, "%s: Invalid modifier found in '%s'.\n", src, val);
1867 case SELECTOR_INVALID:
1873 void fail(FILE *rsp, char *fmt, ...)
1875 fprintf(rsp, FAILURE_MESSAGE);
1878 vfprintf(rsp, fmt, ap);