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 (alternate && (*args)[0] == '\0') {
300 if (trg.node != NULL && trg.node->client != NULL) {
301 cst = trg.node->client->last_state;
306 } else if (parse_client_state(*args, &cst)) {
307 if (alternate && trg.node != NULL && trg.node->client != NULL &&
308 trg.node->client->state == cst) {
309 cst = trg.node->client->last_state;
312 fail(rsp, "node %s: Invalid argument: '%s'.\n", *(args - 1), *args);
315 if (!set_state(trg.monitor, trg.desktop, trg.node, cst)) {
320 } else if (streq("-g", *args) || streq("--flag", *args)) {
323 fail(rsp, "node %s: Not enough arguments.\n", *(args - 1));
326 if (trg.node == NULL) {
330 char *key = strtok(*args, EQL_TOK);
331 char *val = strtok(NULL, EQL_TOK);
337 if (parse_bool(val, &b)) {
340 fail(rsp, "node %s: Invalid value for %s: '%s'.\n", *(args - 1), key, val);
344 if (streq("hidden", key)) {
345 set_hidden(trg.monitor, trg.desktop, trg.node, (a == ALTER_SET ? b : !trg.node->hidden));
347 } else if (streq("sticky", key)) {
348 set_sticky(trg.monitor, trg.desktop, trg.node, (a == ALTER_SET ? b : !trg.node->sticky));
349 } else if (streq("private", key)) {
350 set_private(trg.monitor, trg.desktop, trg.node, (a == ALTER_SET ? b : !trg.node->private));
351 } else if (streq("locked", key)) {
352 set_locked(trg.monitor, trg.desktop, trg.node, (a == ALTER_SET ? b : !trg.node->locked));
353 } else if (streq("marked", key)) {
354 set_marked(trg.monitor, trg.desktop, trg.node, (a == ALTER_SET ? b : !trg.node->marked));
356 fail(rsp, "node %s: Invalid key: '%s'.\n", *(args - 1), key);
359 } else if (streq("-p", *args) || streq("--presel-dir", *args)) {
362 fail(rsp, "node %s: Not enough arguments.\n", *(args - 1));
365 if (trg.node == NULL || trg.node->vacant) {
369 if (streq("cancel", *args)) {
370 cancel_presel(trg.monitor, trg.desktop, trg.node);
372 bool alternate = false;
373 if ((*args)[0] == '~') {
378 if (parse_direction(*args, &dir)) {
379 if (alternate && trg.node->presel != NULL && trg.node->presel->split_dir == dir) {
380 cancel_presel(trg.monitor, trg.desktop, trg.node);
382 presel_dir(trg.monitor, trg.desktop, trg.node, dir);
383 if (!IS_RECEPTACLE(trg.node)) {
384 draw_presel_feedback(trg.monitor, trg.desktop, trg.node);
388 fail(rsp, "node %s: Invalid argument: '%s%s'.\n", *(args - 1), alternate?"~":"", *args);
392 } else if (streq("-o", *args) || streq("--presel-ratio", *args)) {
395 fail(rsp, "node %s: Not enough arguments.\n", *(args - 1));
398 if (trg.node == NULL || trg.node->vacant) {
403 if (sscanf(*args, "%lf", &rat) != 1 || rat <= 0 || rat >= 1) {
404 fail(rsp, "node %s: Invalid argument: '%s'.\n", *(args - 1), *args);
407 presel_ratio(trg.monitor, trg.desktop, trg.node, rat);
408 draw_presel_feedback(trg.monitor, trg.desktop, trg.node);
410 } else if (streq("-v", *args) || streq("--move", *args)) {
413 fail(rsp, "node %s: Not enough arguments.\n", *(args - 1));
417 if (sscanf(*args, "%i", &dx) == 1) {
419 if (sscanf(*args, "%i", &dy) == 1) {
420 if (!move_client(&trg, dx, dy)) {
425 fail(rsp, "node %s: Invalid dy argument: '%s'.\n", *(args - 3), *args);
429 fail(rsp, "node %s: Invalid dx argument: '%s'.\n", *(args - 2), *args);
432 } else if (streq("-z", *args) || streq("--resize", *args)) {
435 fail(rsp, "node %s: Not enough arguments.\n", *(args - 1));
439 if (parse_resize_handle(*args, &rh)) {
442 if (sscanf(*args, "%i", &dx) == 1) {
444 if (sscanf(*args, "%i", &dy) == 1) {
445 if (!resize_client(&trg, rh, dx, dy, true)) {
450 fail(rsp, "node %s: Invalid dy argument: '%s'.\n", *(args - 3), *args);
454 fail(rsp, "node %s: Invalid dx argument: '%s'.\n", *(args - 2), *args);
458 fail(rsp, "node %s: Invalid resize handle argument: '%s'.\n", *(args - 1), *args);
461 } else if (streq("-r", *args) || streq("--ratio", *args)) {
464 fail(rsp, "node %s: Not enough arguments.\n", *(args - 1));
467 if (trg.node == NULL) {
471 if ((*args)[0] == '+' || (*args)[0] == '-') {
473 if (sscanf(*args, "%f", &delta) == 1) {
474 double rat = trg.node->split_ratio;
475 if (delta > -1 && delta < 1) {
478 int max = (trg.node->split_type == TYPE_HORIZONTAL ? trg.node->rectangle.height : trg.node->rectangle.width);
479 rat = ((max * rat) + delta) / max;
481 if (rat > 0 && rat < 1) {
482 set_ratio(trg.node, rat);
488 fail(rsp, "node %s: Invalid argument: '%s'.\n", *(args - 1), *args);
493 if (sscanf(*args, "%lf", &rat) == 1 && rat > 0 && rat < 1) {
494 set_ratio(trg.node, rat);
496 fail(rsp, "node %s: Invalid argument: '%s'.\n", *(args - 1), *args);
501 } else if (streq("-F", *args) || streq("--flip", *args)) {
504 fail(rsp, "node %s: Not enough arguments.\n", *(args - 1));
507 if (trg.node == NULL) {
512 if (parse_flip(*args, &flp)) {
513 flip_tree(trg.node, flp);
519 } else if (streq("-R", *args) || streq("--rotate", *args)) {
522 fail(rsp, "node %s: Not enough arguments.\n", *(args - 1));
525 if (trg.node == NULL) {
530 if (parse_degree(*args, °)) {
531 rotate_tree(trg.node, deg);
534 fail(rsp, "node %s: Invalid argument: '%s'.\n", *(args - 1), *args);
537 } else if (streq("-E", *args) || streq("--equalize", *args)) {
538 if (trg.node == NULL) {
542 equalize_tree(trg.node);
544 } else if (streq("-B", *args) || streq("--balance", *args)) {
545 if (trg.node == NULL) {
549 balance_tree(trg.node);
551 } else if (streq("-C", *args) || streq("--circulate", *args)) {
554 fail(rsp, "node %s: Not enough arguments.\n", *(args - 1));
557 if (trg.node == NULL) {
562 if (parse_circulate_direction(*args, &cir)) {
563 circulate_leaves(trg.monitor, trg.desktop, trg.node, cir);
566 fail(rsp, "node %s: Invalid argument: '%s'.\n", *(args - 1), *args);
569 } else if (streq("-i", *args) || streq("--insert-receptacle", *args)) {
570 insert_receptacle(trg.monitor, trg.desktop, trg.node);
572 } else if (streq("-c", *args) || streq("--close", *args)) {
574 fail(rsp, "node %s: Trailing commands.\n", *args);
577 if (trg.node == NULL || locked_count(trg.node) > 0) {
581 close_node(trg.node);
583 } else if (streq("-k", *args) || streq("--kill", *args)) {
585 fail(rsp, "node %s: Trailing commands.\n", *args);
588 if (trg.node == NULL) {
592 kill_node(trg.monitor, trg.desktop, trg.node);
596 fail(rsp, "node: Unknown command: '%s'.\n", *args);
604 arrange(trg.monitor, trg.desktop);
608 void cmd_desktop(char **args, int num, FILE *rsp)
611 fail(rsp, "desktop: Missing arguments.\n");
615 coordinates_t ref = {mon, mon->desk, NULL};
616 coordinates_t trg = ref;
618 if ((*args)[0] != OPT_CHR) {
620 if ((ret = desktop_from_desc(*args, &ref, &trg)) == SELECTOR_OK) {
623 handle_failure(ret, "desktop", *args, rsp);
629 fail(rsp, "desktop: Missing commands.\n");
633 bool changed = false;
636 if (streq("-f", *args) || streq("--focus", *args)) {
637 coordinates_t dst = trg;
638 if (num > 1 && *(args + 1)[0] != OPT_CHR) {
641 if ((ret = desktop_from_desc(*args, &ref, &dst)) != SELECTOR_OK) {
642 handle_failure(ret, "desktop -f", *args, rsp);
646 focus_node(dst.monitor, dst.desktop, NULL);
647 } else if (streq("-a", *args) || streq("--activate", *args)) {
648 coordinates_t dst = trg;
649 if (num > 1 && *(args + 1)[0] != OPT_CHR) {
652 if ((ret = desktop_from_desc(*args, &ref, &dst)) != SELECTOR_OK) {
653 handle_failure(ret, "desktop -a", *args, rsp);
657 if (activate_desktop(dst.monitor, dst.desktop)) {
658 activate_node(dst.monitor, dst.desktop, NULL);
663 } else if (streq("-m", *args) || streq("--to-monitor", *args)) {
666 fail(rsp, "desktop %s: Not enough arguments.\n", *(args - 1));
669 if (trg.monitor->desk_head == trg.monitor->desk_tail) {
675 if ((ret = monitor_from_desc(*args, &ref, &dst)) == SELECTOR_OK) {
677 if (num > 1 && streq("--follow", *(args+1))) {
681 if (transfer_desktop(trg.monitor, dst.monitor, trg.desktop, follow)) {
682 trg.monitor = dst.monitor;
688 handle_failure(ret, "desktop -m", *args, rsp);
691 } else if (streq("-s", *args) || streq("--swap", *args)) {
694 fail(rsp, "desktop %s: Not enough arguments.\n", *(args - 1));
699 if ((ret = desktop_from_desc(*args, &ref, &dst)) == SELECTOR_OK) {
701 if (num > 1 && streq("--follow", *(args+1))) {
705 if (swap_desktops(trg.monitor, trg.desktop, dst.monitor, dst.desktop, follow)) {
706 trg.monitor = dst.monitor;
712 handle_failure(ret, "desktop -s", *args, rsp);
715 } else if (streq("-b", *args) || streq("--bubble", *args)) {
718 fail(rsp, "desktop %s: Not enough arguments.\n", *(args - 1));
722 if (parse_cycle_direction(*args, &cyc)) {
723 desktop_t *d = trg.desktop;
724 if (cyc == CYCLE_PREV) {
725 if (d->prev == NULL) {
726 while (d->next != NULL) {
727 swap_desktops(trg.monitor, d, trg.monitor, d->next, false);
730 swap_desktops(trg.monitor, d, trg.monitor, d->prev, false);
733 if (d->next == NULL) {
734 while (d->prev != NULL) {
735 swap_desktops(trg.monitor, d, trg.monitor, d->prev, false);
738 swap_desktops(trg.monitor, d, trg.monitor, d->next, false);
742 fail(rsp, "desktop %s: Invalid argument: '%s'.\n", *(args - 1), *args);
745 } else if (streq("-l", *args) || streq("--layout", *args)) {
748 fail(rsp, "desktop %s: Not enough arguments.\n", *(args - 1));
754 if (parse_cycle_direction(*args, &cyc)) {
755 ret = set_layout(trg.monitor, trg.desktop, (trg.desktop->user_layout + 1) % 2, true);
756 } else if (parse_layout(*args, &lyt)) {
757 ret = set_layout(trg.monitor, trg.desktop, lyt, true);
759 fail(rsp, "desktop %s: Invalid argument: '%s'.\n", *(args - 1), *args);
766 } else if (streq("-n", *args) || streq("--rename", *args)) {
769 fail(rsp, "desktop %s: Not enough arguments.\n", *(args - 1));
772 rename_desktop(trg.monitor, trg.desktop, *args);
773 } else if (streq("-r", *args) || streq("--remove", *args)) {
775 fail(rsp, "desktop %s: Trailing commands.\n", *args);
778 if (trg.monitor->desk_head != trg.monitor->desk_tail) {
779 desktop_t *fallback = trg.desktop->prev == NULL ?
782 merge_desktops(trg.monitor, trg.desktop, trg.monitor, fallback);
783 remove_desktop(trg.monitor, trg.desktop);
790 fail(rsp, "desktop: Unknown command: '%s'.\n", *args);
797 arrange(trg.monitor, trg.desktop);
801 void cmd_monitor(char **args, int num, FILE *rsp)
804 fail(rsp, "monitor: Missing arguments.\n");
808 coordinates_t ref = {mon, NULL, NULL};
809 coordinates_t trg = ref;
811 if ((*args)[0] != OPT_CHR) {
813 if ((ret = monitor_from_desc(*args, &ref, &trg)) == SELECTOR_OK) {
816 handle_failure(ret, "monitor", *args, rsp);
822 fail(rsp, "monitor: Missing commands.\n");
827 if (streq("-f", *args) || streq("--focus", *args)) {
828 coordinates_t dst = trg;
829 if (num > 1 && *(args + 1)[0] != OPT_CHR) {
832 if ((ret = monitor_from_desc(*args, &ref, &dst)) != SELECTOR_OK) {
833 handle_failure(ret, "monitor -f", *args, rsp);
838 focus_node(dst.monitor, NULL, NULL);
839 } else if (streq("-s", *args) || streq("--swap", *args)) {
842 fail(rsp, "monitor %s: Not enough arguments.\n", *(args - 1));
847 if ((ret = monitor_from_desc(*args, &ref, &dst)) == SELECTOR_OK) {
848 if (!swap_monitors(trg.monitor, dst.monitor)) {
853 handle_failure(ret, "monitor -s", *args, rsp);
856 } else if (streq("-d", *args) || streq("--reset-desktops", *args)) {
859 fail(rsp, "monitor %s: Not enough arguments.\n", *(args - 1));
862 desktop_t *d = trg.monitor->desk_head;
863 while (num > 0 && d != NULL) {
864 rename_desktop(trg.monitor, d, *args);
868 put_status(SBSC_MASK_REPORT);
870 add_desktop(trg.monitor, make_desktop(*args, XCB_NONE));
874 desktop_t *next = d->next;
875 if (d == mon->desk) {
876 focus_node(trg.monitor, d->prev, d->prev->focus);
878 merge_desktops(trg.monitor, d, mon, mon->desk);
879 remove_desktop(trg.monitor, d);
882 } else if (streq("-a", *args) || streq("--add-desktops", *args)) {
885 fail(rsp, "monitor %s: Not enough arguments.\n", *(args - 1));
889 add_desktop(trg.monitor, make_desktop(*args, XCB_NONE));
892 } else if (streq("-r", *args) || streq("--remove", *args)) {
894 fail(rsp, "monitor %s: Trailing commands.\n", *args);
897 if (mon_head == mon_tail) {
901 remove_monitor(trg.monitor);
903 } else if (streq("-o", *args) || streq("--reorder-desktops", *args)) {
906 fail(rsp, "monitor %s: Not enough arguments.\n", *(args - 1));
909 desktop_t *d = trg.monitor->desk_head;
910 while (d != NULL && num > 0) {
911 desktop_t *next = d->next;
913 if (locate_desktop(*args, &dst) && dst.monitor == trg.monitor) {
914 swap_desktops(trg.monitor, d, dst.monitor, dst.desktop, false);
915 if (next == dst.desktop) {
922 } else if (streq("-g", *args) || streq("--rectangle", *args)) {
925 fail(rsp, "monitor %s: Not enough arguments.\n", *(args - 1));
929 if (parse_rectangle(*args, &r)) {
930 update_root(trg.monitor, &r);
932 fail(rsp, "monitor %s: Invalid argument: '%s'.\n", *(args - 1), *args);
935 } else if (streq("-n", *args) || streq("--rename", *args)) {
938 fail(rsp, "monitor %s: Not enough arguments.\n", *(args - 1));
941 rename_monitor(trg.monitor, *args);
943 fail(rsp, "monitor: Unknown command: '%s'.\n", *args);
950 void cmd_query(char **args, int num, FILE *rsp)
952 coordinates_t monitor_ref = {mon, NULL, NULL};
953 coordinates_t desktop_ref = {mon, mon->desk, NULL};
954 coordinates_t node_ref = {mon, mon->desk, mon->desk->focus};
955 coordinates_t trg = {NULL, NULL, NULL};
956 monitor_select_t *monitor_sel = NULL;
957 desktop_select_t *desktop_sel = NULL;
958 node_select_t *node_sel = NULL;
959 domain_t dom = DOMAIN_TREE;
960 bool print_ids = true;
964 fail(rsp, "query: Missing arguments.\n");
969 if (streq("-T", *args) || streq("--tree", *args)) {
970 dom = DOMAIN_TREE, d++;
971 } else if (streq("-M", *args) || streq("--monitors", *args)) {
972 dom = DOMAIN_MONITOR, d++;
973 if (num > 1 && *(args + 1)[0] != OPT_CHR) {
976 coordinates_t tmp = monitor_ref;
977 monitor_ref.desktop = NULL;
978 monitor_ref.node = NULL;
979 if ((ret = monitor_from_desc(*args, &tmp, &monitor_ref)) != SELECTOR_OK) {
980 handle_failure(ret, "query -M", *args, rsp);
984 } else if (streq("-D", *args) || streq("--desktops", *args)) {
985 dom = DOMAIN_DESKTOP, d++;
986 if (num > 1 && *(args + 1)[0] != OPT_CHR) {
989 coordinates_t tmp = desktop_ref;
990 desktop_ref.node = NULL;
991 if ((ret = desktop_from_desc(*args, &tmp, &desktop_ref)) != SELECTOR_OK) {
992 handle_failure(ret, "query -D", *args, rsp);
996 } else if (streq("-N", *args) || streq("--nodes", *args)) {
997 dom = DOMAIN_NODE, d++;
998 if (num > 1 && *(args + 1)[0] != OPT_CHR) {
1001 coordinates_t tmp = node_ref;
1002 if ((ret = node_from_desc(*args, &tmp, &node_ref)) != SELECTOR_OK) {
1003 handle_failure(ret, "query -N", *args, rsp);
1007 } else if (streq("-m", *args) || streq("--monitor", *args)) {
1008 if (num > 1 && *(args + 1)[0] != OPT_CHR) {
1011 if ((*args)[0] == '.') {
1013 monitor_sel = malloc(sizeof(monitor_select_t));
1014 *monitor_sel = make_monitor_select();
1015 char *desc = copy_string(*args, strlen(*args));
1016 if (!parse_monitor_modifiers(desc, monitor_sel)) {
1017 handle_failure(SELECTOR_BAD_MODIFIERS, "query -m", *args, rsp);
1022 } else if ((ret = monitor_from_desc(*args, &monitor_ref, &trg)) != SELECTOR_OK) {
1023 handle_failure(ret, "query -m", *args, rsp);
1029 } else if (streq("-d", *args) || streq("--desktop", *args)) {
1030 if (num > 1 && *(args + 1)[0] != OPT_CHR) {
1033 if ((*args)[0] == '.') {
1035 desktop_sel = malloc(sizeof(desktop_select_t));
1036 *desktop_sel = make_desktop_select();
1037 char *desc = copy_string(*args, strlen(*args));
1038 if (!parse_desktop_modifiers(desc, desktop_sel)) {
1039 handle_failure(SELECTOR_BAD_MODIFIERS, "query -d", *args, rsp);
1044 } else if ((ret = desktop_from_desc(*args, &desktop_ref, &trg)) != SELECTOR_OK) {
1045 handle_failure(ret, "query -d", *args, rsp);
1051 } else if (streq("-n", *args) || streq("--node", *args)) {
1052 if (num > 1 && *(args + 1)[0] != OPT_CHR) {
1055 if ((*args)[0] == '.') {
1057 node_sel = malloc(sizeof(node_select_t));
1058 *node_sel = make_node_select();
1059 char *desc = copy_string(*args, strlen(*args));
1060 if (!parse_node_modifiers(desc, node_sel)) {
1061 handle_failure(SELECTOR_BAD_MODIFIERS, "query -n", *args, rsp);
1066 } else if ((ret = node_from_desc(*args, &node_ref, &trg)) != SELECTOR_OK) {
1067 handle_failure(ret, "query -n", *args, rsp);
1072 if (trg.node == NULL) {
1077 } else if (streq("--names", *args)) {
1080 fail(rsp, "query: Unknown option: '%s'.\n", *args);
1087 fail(rsp, "query: No commands given.\n");
1092 fail(rsp, "query: Multiple commands given.\n");
1096 if (dom == DOMAIN_TREE && trg.monitor == NULL) {
1097 fail(rsp, "query -T: No options given.\n");
1101 if (!print_ids && (dom == DOMAIN_NODE || dom == DOMAIN_TREE)) {
1102 fail(rsp, "query -%c: --names only applies to -M and -D.\n", dom == DOMAIN_NODE ? 'N' : 'T');
1106 if ((dom == DOMAIN_MONITOR && (desktop_sel != NULL || node_sel != NULL)) ||
1107 (dom == DOMAIN_DESKTOP && node_sel != NULL)) {
1108 fail(rsp, "query -%c: Incompatible descriptor-free constraints.\n", dom == DOMAIN_MONITOR ? 'M' : 'D');
1112 if (dom == DOMAIN_NODE) {
1113 if (query_node_ids(&monitor_ref, &desktop_ref, &node_ref, &trg, monitor_sel, desktop_sel, node_sel, rsp) < 1) {
1116 } else if (dom == DOMAIN_DESKTOP) {
1117 if (query_desktop_ids(&monitor_ref, &desktop_ref, &trg, monitor_sel, desktop_sel, print_ids ? fprint_desktop_id : fprint_desktop_name, rsp) < 1) {
1120 } else if (dom == DOMAIN_MONITOR) {
1121 if (query_monitor_ids(&monitor_ref, &trg, monitor_sel, print_ids ? fprint_monitor_id : fprint_monitor_name, rsp) < 1) {
1125 if (trg.node != NULL) {
1126 query_node(trg.node, rsp);
1127 } else if (trg.desktop != NULL) {
1128 query_desktop(trg.desktop, rsp);
1130 query_monitor(trg.monitor, rsp);
1141 void cmd_rule(char **args, int num, FILE *rsp)
1144 fail(rsp, "rule: Missing commands.\n");
1149 if (streq("-a", *args) || streq("--add", *args)) {
1152 fail(rsp, "rule %s: Not enough arguments.\n", *(args - 1));
1155 rule_t *rule = make_rule();
1156 char *class_name = strtok(*args, COL_TOK);
1157 char *instance_name = strtok(NULL, COL_TOK);
1158 char *name = strtok(NULL, COL_TOK);
1159 snprintf(rule->class_name, sizeof(rule->class_name), "%s", class_name);
1160 snprintf(rule->instance_name, sizeof(rule->instance_name), "%s", instance_name==NULL?MATCH_ANY:instance_name);
1161 snprintf(rule->name, sizeof(rule->name), "%s", name==NULL?MATCH_ANY:name);
1165 if (streq("-o", *args) || streq("--one-shot", *args)) {
1166 rule->one_shot = true;
1168 for (size_t j = 0; i < sizeof(rule->effect) && j < strlen(*args); i++, j++) {
1169 rule->effect[i] = (*args)[j];
1171 if (num > 1 && i < sizeof(rule->effect)) {
1172 rule->effect[i++] = ' ';
1177 rule->effect[MIN(i, sizeof(rule->effect) - 1)] = '\0';
1179 } else if (streq("-r", *args) || streq("--remove", *args)) {
1182 fail(rsp, "rule %s: Not enough arguments.\n", *(args - 1));
1187 if (parse_index(*args, &idx)) {
1188 remove_rule_by_index(idx - 1);
1189 } else if (streq("tail", *args)) {
1190 remove_rule(rule_tail);
1191 } else if (streq("head", *args)) {
1192 remove_rule(rule_head);
1194 remove_rule_by_cause(*args);
1198 } else if (streq("-l", *args) || streq("--list", *args)) {
1201 fail(rsp, "rule: Unknown command: '%s'.\n", *args);
1208 void cmd_wm(char **args, int num, FILE *rsp)
1211 fail(rsp, "wm: Missing commands.\n");
1216 if (streq("-d", *args) || streq("--dump-state", *args)) {
1219 } else if (streq("-l", *args) || streq("--load-state", *args)) {
1222 fail(rsp, "wm %s: Not enough arguments.\n", *(args - 1));
1225 if (!restore_state(*args)) {
1229 } else if (streq("-a", *args) || streq("--add-monitor", *args)) {
1232 fail(rsp, "wm %s: Not enough arguments.\n", *(args - 1));
1238 if (parse_rectangle(*args, &r)) {
1239 monitor_t *m = make_monitor(name, &r, XCB_NONE);
1241 add_desktop(m, make_desktop(NULL, XCB_NONE));
1243 fail(rsp, "wm %s: Invalid argument: '%s'.\n", *(args - 1), *args);
1246 } else if (streq("-O", *args) || streq("--reorder-monitors", *args)) {
1249 fail(rsp, "wm %s: Not enough arguments.\n", *(args - 1));
1252 monitor_t *m = mon_head;
1253 while (m != NULL && num > 0) {
1254 monitor_t *next = m->next;
1256 if (locate_monitor(*args, &dst)) {
1257 swap_monitors(m, dst.monitor);
1258 if (next == dst.monitor) {
1265 } else if (streq("-o", *args) || streq("--adopt-orphans", *args)) {
1267 } else if (streq("-g", *args) || streq("--get-status", *args)) {
1269 } else if (streq("-h", *args) || streq("--record-history", *args)) {
1272 fail(rsp, "wm %s: Not enough arguments.\n", *(args - 1));
1276 if (parse_bool(*args, &b)) {
1279 fail(rsp, "wm %s: Invalid argument: '%s'.\n", *(args - 1), *args);
1282 } else if (streq("-r", *args) || streq("--restart", *args)) {
1287 fail(rsp, "wm: Unknown command: '%s'.\n", *args);
1294 void cmd_subscribe(char **args, int num, FILE *rsp)
1299 char *fifo_path = NULL;
1300 subscriber_mask_t mask;
1303 if (streq("-c", *args) || streq("--count", *args)) {
1306 fail(rsp, "subscribe %s: Not enough arguments.\n", *(args - 1));
1309 if (sscanf(*args, "%i", &count) != 1 || count < 1) {
1310 fail(rsp, "subscribe %s: Invalid argument: '%s'.\n", *(args - 1), *args);
1313 } else if (streq("-f", *args) || streq("--fifo", *args)) {
1314 fifo_path = mktempfifo(FIFO_TEMPLATE);
1315 if (fifo_path == NULL) {
1316 fail(rsp, "subscribe %s: Can't create FIFO.\n", *(args - 1));
1319 } else if (parse_subscriber_mask(*args, &mask)) {
1322 fail(rsp, "subscribe: Invalid argument: '%s'.\n", *args);
1329 field = SBSC_MASK_REPORT;
1333 fprintf(rsp, "%s\n", fifo_path);
1337 stream = fopen(fifo_path, "w");
1339 if (stream == NULL) {
1340 perror("subscribe: fopen");
1341 goto free_fifo_path;
1345 subscriber_list_t *sb = make_subscriber(stream, fifo_path, field, count);
1360 void cmd_quit(char **args, int num, FILE *rsp)
1362 if (num > 0 && sscanf(*args, "%i", &exit_status) != 1) {
1363 fail(rsp, "%s: Invalid argument: '%s'.\n", *(args - 1), *args);
1369 void cmd_config(char **args, int num, FILE *rsp)
1372 fail(rsp, "config: Missing arguments.\n");
1376 coordinates_t ref = {mon, mon->desk, mon->desk->focus};
1377 coordinates_t trg = {NULL, NULL, NULL};
1379 while (num > 0 && (*args)[0] == OPT_CHR) {
1380 if (streq("-m", *args) || streq("--monitor", *args)) {
1383 fail(rsp, "config %s: Not enough arguments.\n", *(args - 1));
1387 if ((ret = monitor_from_desc(*args, &ref, &trg)) != SELECTOR_OK) {
1388 handle_failure(ret, "config -m", *args, rsp);
1391 } else if (streq("-d", *args) || streq("--desktop", *args)) {
1394 fail(rsp, "config %s: Not enough arguments.\n", *(args - 1));
1398 if ((ret = desktop_from_desc(*args, &ref, &trg)) != SELECTOR_OK) {
1399 handle_failure(ret, "config -d", *args, rsp);
1402 } else if (streq("-n", *args) || streq("--node", *args)) {
1405 fail(rsp, "config %s: Not enough arguments.\n", *(args - 1));
1409 if ((ret = node_from_desc(*args, &ref, &trg)) != SELECTOR_OK) {
1410 handle_failure(ret, "config -n", *args, rsp);
1414 fail(rsp, "config: Unknown option: '%s'.\n", *args);
1420 set_setting(trg, *args, *(args + 1), rsp);
1421 } else if (num == 1) {
1422 get_setting(trg, *args, rsp);
1424 fail(rsp, "config: Was expecting 1 or 2 arguments, received %i.\n", num);
1428 void set_setting(coordinates_t loc, char *name, char *value, FILE *rsp)
1430 bool colors_changed = false;
1431 #define SET_DEF_DEFMON_DEFDESK_WIN(k, v) \
1432 if (loc.node != NULL) { \
1433 for (node_t *n = first_extrema(loc.node); n != NULL; n = next_leaf(n, loc.node)) { \
1434 if (n->client != NULL) { \
1438 } else if (loc.desktop != NULL) { \
1439 loc.desktop->k = v; \
1440 for (node_t *n = first_extrema(loc.desktop->root); n != NULL; n = next_leaf(n, loc.desktop->root)) { \
1441 if (n->client != NULL) { \
1445 } else if (loc.monitor != NULL) { \
1446 loc.monitor->k = v; \
1447 for (desktop_t *d = loc.monitor->desk_head; d != NULL; d = d->next) { \
1449 for (node_t *n = first_extrema(d->root); n != NULL; n = next_leaf(n, d->root)) { \
1450 if (n->client != NULL) { \
1457 for (monitor_t *m = mon_head; m != NULL; m = m->next) { \
1459 for (desktop_t *d = m->desk_head; d != NULL; d = d->next) { \
1461 for (node_t *n = first_extrema(d->root); n != NULL; n = next_leaf(n, d->root)) { \
1462 if (n->client != NULL) { \
1469 if (streq("border_width", name)) {
1471 if (sscanf(value, "%u", &bw) != 1) {
1472 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1475 SET_DEF_DEFMON_DEFDESK_WIN(border_width, bw)
1476 #undef SET_DEF_DEFMON_DEFDESK_WIN
1477 #define SET_DEF_DEFMON_DESK(k, v) \
1478 if (loc.desktop != NULL) { \
1479 loc.desktop->k = v; \
1480 } else if (loc.monitor != NULL) { \
1481 loc.monitor->k = v; \
1482 for (desktop_t *d = loc.monitor->desk_head; d != NULL; d = d->next) { \
1487 for (monitor_t *m = mon_head; m != NULL; m = m->next) { \
1489 for (desktop_t *d = m->desk_head; d != NULL; d = d->next) { \
1494 } else if (streq("window_gap", name)) {
1496 if (sscanf(value, "%i", &wg) != 1) {
1500 SET_DEF_DEFMON_DESK(window_gap, wg)
1501 #undef SET_DEF_DEFMON_DESK
1502 #define SET_DEF_MON_DESK(k, v) \
1503 if (loc.desktop != NULL) { \
1504 loc.desktop->k = v; \
1505 } else if (loc.monitor != NULL) { \
1506 loc.monitor->k = v; \
1509 for (monitor_t *m = mon_head; m != NULL; m = m->next) { \
1513 } else if (streq("top_padding", name)) {
1515 if (sscanf(value, "%i", &tp) != 1) {
1516 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1519 SET_DEF_MON_DESK(padding.top, tp)
1520 } else if (streq("right_padding", name)) {
1522 if (sscanf(value, "%i", &rp) != 1) {
1523 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1526 SET_DEF_MON_DESK(padding.right, rp)
1527 } else if (streq("bottom_padding", name)) {
1529 if (sscanf(value, "%i", &bp) != 1) {
1530 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1533 SET_DEF_MON_DESK(padding.bottom, bp)
1534 } else if (streq("left_padding", name)) {
1536 if (sscanf(value, "%i", &lp) != 1) {
1537 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1540 SET_DEF_MON_DESK(padding.left, lp)
1541 #undef SET_DEF_MON_DESK
1542 } else if (streq("top_monocle_padding", name)) {
1543 if (sscanf(value, "%i", &monocle_padding.top) != 1) {
1544 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1546 } else if (streq("right_monocle_padding", name)) {
1547 if (sscanf(value, "%i", &monocle_padding.right) != 1) {
1548 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1550 } else if (streq("bottom_monocle_padding", name)) {
1551 if (sscanf(value, "%i", &monocle_padding.bottom) != 1) {
1552 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1554 } else if (streq("left_monocle_padding", name)) {
1555 if (sscanf(value, "%i", &monocle_padding.left) != 1) {
1556 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1558 #define SET_STR(s) \
1559 } else if (streq(#s, name)) { \
1560 if (snprintf(s, sizeof(s), "%s", value) < 0) { \
1564 SET_STR(external_rules_command)
1565 SET_STR(status_prefix)
1567 } else if (streq("split_ratio", name)) {
1569 if (sscanf(value, "%lf", &r) == 1 && r > 0 && r < 1) {
1572 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value); \
1576 #define SET_COLOR(s) \
1577 } else if (streq(#s, name)) { \
1578 if (!is_hex_color(value)) { \
1579 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value); \
1582 snprintf(s, sizeof(s), "%s", value); \
1583 colors_changed = true; \
1585 SET_COLOR(normal_border_color)
1586 SET_COLOR(active_border_color)
1587 SET_COLOR(focused_border_color)
1588 SET_COLOR(presel_feedback_color)
1590 } else if (streq("initial_polarity", name)) {
1592 if (parse_child_polarity(value, &p)) {
1593 initial_polarity = p;
1595 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1598 } else if (streq("automatic_scheme", name)) {
1599 automatic_scheme_t a;
1600 if (parse_automatic_scheme(value, &a)) {
1601 automatic_scheme = a;
1603 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1606 } else if (streq("mapping_events_count", name)) {
1607 if (sscanf(value, "%" SCNi8, &mapping_events_count) != 1) {
1608 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1611 } else if (streq("directional_focus_tightness", name)) {
1613 if (parse_tightness(value, &p)) {
1614 directional_focus_tightness = p;
1616 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1619 } else if (streq("ignore_ewmh_fullscreen", name)) {
1620 state_transition_t m;
1621 if (parse_state_transition(value, &m)) {
1622 ignore_ewmh_fullscreen = m;
1624 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1627 } else if (streq("pointer_modifier", name)) {
1628 if (parse_modifier_mask(value, &pointer_modifier)) {
1632 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1635 } else if (streq("pointer_motion_interval", name)) {
1636 if (sscanf(value, "%u", &pointer_motion_interval) != 1) {
1637 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1640 } else if (streq("pointer_action1", name) ||
1641 streq("pointer_action2", name) ||
1642 streq("pointer_action3", name)) {
1643 int index = name[14] - '1';
1644 if (parse_pointer_action(value, &pointer_actions[index])) {
1648 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1651 } else if (streq("click_to_focus", name)) {
1652 if (parse_button_index(value, &click_to_focus)) {
1656 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1659 } else if (streq("single_monocle", name)) {
1661 if (parse_bool(value, &b)) {
1662 if (b == single_monocle) {
1667 for (monitor_t *m = mon_head; m != NULL; m = m->next) {
1668 for (desktop_t *d = m->desk_head; d != NULL; d = d->next) {
1669 layout_t l = (single_monocle && tiled_count(d->root, true) <= 1) ? LAYOUT_MONOCLE : d->user_layout;
1670 set_layout(m, d, l, false);
1674 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1677 } else if (streq("focus_follows_pointer", name)) {
1679 if (parse_bool(value, &b)) {
1680 if (b == focus_follows_pointer) {
1684 focus_follows_pointer = b;
1685 for (monitor_t *m = mon_head; m != NULL; m = m->next) {
1686 if (focus_follows_pointer) {
1687 window_show(m->root);
1689 window_hide(m->root);
1691 for (desktop_t *d = m->desk_head; d != NULL; d = d->next) {
1692 listen_enter_notify(d->root, focus_follows_pointer);
1695 if (focus_follows_pointer) {
1696 update_motion_recorder();
1698 disable_motion_recorder();
1702 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1705 #define SET_BOOL(s) \
1706 } else if (streq(#s, name)) { \
1707 if (!parse_bool(value, &s)) { \
1708 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value); \
1711 SET_BOOL(presel_feedback)
1712 SET_BOOL(borderless_monocle)
1713 SET_BOOL(gapless_monocle)
1714 SET_BOOL(borderless_singleton)
1715 SET_BOOL(swallow_first_click)
1716 SET_BOOL(pointer_follows_focus)
1717 SET_BOOL(pointer_follows_monitor)
1718 SET_BOOL(ignore_ewmh_focus)
1719 SET_BOOL(ignore_ewmh_struts)
1720 SET_BOOL(center_pseudo_tiled)
1721 SET_BOOL(honor_size_hints)
1722 SET_BOOL(removal_adjustment)
1724 #define SET_MON_BOOL(s) \
1725 } else if (streq(#s, name)) { \
1726 if (!parse_bool(value, &s)) { \
1727 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value); \
1731 update_monitors(); \
1733 SET_MON_BOOL(remove_disabled_monitors)
1734 SET_MON_BOOL(remove_unplugged_monitors)
1735 SET_MON_BOOL(merge_overlapping_monitors)
1738 fail(rsp, "config: Unknown setting: '%s'.\n", name);
1742 for (monitor_t *m = mon_head; m != NULL; m = m->next) {
1743 for (desktop_t *d = m->desk_head; d != NULL; d = d->next) {
1745 if (colors_changed) {
1746 update_colors_in(d->root, d, m);
1752 void get_setting(coordinates_t loc, char *name, FILE* rsp)
1754 if (streq("split_ratio", name)) {
1755 fprintf(rsp, "%lf", split_ratio);
1756 } else if (streq("border_width", name)) {
1757 if (loc.node != NULL) {
1758 for (node_t *n = first_extrema(loc.node); n != NULL; n = next_leaf(n, loc.node)) {
1759 if (n->client != NULL) {
1760 fprintf(rsp, "%u", n->client->border_width);
1764 } else if (loc.desktop != NULL) {
1765 fprintf(rsp, "%u", loc.desktop->border_width);
1766 } else if (loc.monitor != NULL) {
1767 fprintf(rsp, "%u", loc.monitor->border_width);
1769 fprintf(rsp, "%u", border_width);
1771 } else if (streq("window_gap", name)) {
1772 if (loc.desktop != NULL) {
1773 fprintf(rsp, "%i", loc.desktop->window_gap);
1774 } else if (loc.monitor != NULL) {
1775 fprintf(rsp, "%i", loc.monitor->window_gap);
1777 fprintf(rsp, "%i", window_gap);
1779 #define GET_DEF_MON_DESK(k) \
1780 if (loc.desktop != NULL) { \
1781 fprintf(rsp, "%i", loc.desktop->k); \
1782 } else if (loc.monitor != NULL) { \
1783 fprintf(rsp, "%i", loc.monitor->k); \
1785 fprintf(rsp, "%i", k); \
1787 } else if (streq("top_padding", name)) {
1788 GET_DEF_MON_DESK(padding.top)
1789 } else if (streq("right_padding", name)) {
1790 GET_DEF_MON_DESK(padding.right)
1791 } else if (streq("bottom_padding", name)) {
1792 GET_DEF_MON_DESK(padding.bottom)
1793 } else if (streq("left_padding", name)) {
1794 GET_DEF_MON_DESK(padding.left)
1795 #undef GET_DEF_MON_DESK
1796 } else if (streq("top_monocle_padding", name)) {
1797 fprintf(rsp, "%i", monocle_padding.top);
1798 } else if (streq("right_monocle_padding", name)) {
1799 fprintf(rsp, "%i", monocle_padding.right);
1800 } else if (streq("bottom_monocle_padding", name)) {
1801 fprintf(rsp, "%i", monocle_padding.bottom);
1802 } else if (streq("left_monocle_padding", name)) {
1803 fprintf(rsp, "%i", monocle_padding.left);
1804 } else if (streq("external_rules_command", name)) {
1805 fprintf(rsp, "%s", external_rules_command);
1806 } else if (streq("status_prefix", name)) {
1807 fprintf(rsp, "%s", status_prefix);
1808 } else if (streq("initial_polarity", name)) {
1809 fprintf(rsp, "%s", CHILD_POL_STR(initial_polarity));
1810 } else if (streq("automatic_scheme", name)) {
1811 fprintf(rsp, "%s", AUTO_SCM_STR(automatic_scheme));
1812 } else if (streq("mapping_events_count", name)) {
1813 fprintf(rsp, "%" PRIi8, mapping_events_count);
1814 } else if (streq("directional_focus_tightness", name)) {
1815 fprintf(rsp, "%s", TIGHTNESS_STR(directional_focus_tightness));
1816 } else if (streq("ignore_ewmh_fullscreen", name)) {
1817 print_ignore_request(ignore_ewmh_fullscreen, rsp);
1818 } else if (streq("pointer_modifier", name)) {
1819 print_modifier_mask(pointer_modifier, rsp);
1820 } else if (streq("click_to_focus", name)) {
1821 print_button_index(click_to_focus, rsp);
1822 } else if (streq("pointer_motion_interval", name)) {
1823 fprintf(rsp, "%u", pointer_motion_interval);
1824 } else if (streq("pointer_action1", name) ||
1825 streq("pointer_action2", name) ||
1826 streq("pointer_action3", name)) {
1827 int index = name[14] - '1';
1828 print_pointer_action(pointer_actions[index], rsp);
1829 #define GET_COLOR(s) \
1830 } else if (streq(#s, name)) { \
1831 fprintf(rsp, "%s", s);
1832 GET_COLOR(normal_border_color)
1833 GET_COLOR(active_border_color)
1834 GET_COLOR(focused_border_color)
1835 GET_COLOR(presel_feedback_color)
1837 #define GET_BOOL(s) \
1838 } else if (streq(#s, name)) { \
1839 fprintf(rsp, "%s", BOOL_STR(s));
1840 GET_BOOL(presel_feedback)
1841 GET_BOOL(borderless_monocle)
1842 GET_BOOL(gapless_monocle)
1843 GET_BOOL(single_monocle)
1844 GET_BOOL(borderless_singleton)
1845 GET_BOOL(swallow_first_click)
1846 GET_BOOL(focus_follows_pointer)
1847 GET_BOOL(pointer_follows_focus)
1848 GET_BOOL(pointer_follows_monitor)
1849 GET_BOOL(ignore_ewmh_focus)
1850 GET_BOOL(ignore_ewmh_struts)
1851 GET_BOOL(center_pseudo_tiled)
1852 GET_BOOL(honor_size_hints)
1853 GET_BOOL(removal_adjustment)
1854 GET_BOOL(remove_disabled_monitors)
1855 GET_BOOL(remove_unplugged_monitors)
1856 GET_BOOL(merge_overlapping_monitors)
1859 fail(rsp, "config: Unknown setting: '%s'.\n", name);
1865 void handle_failure(int code, char *src, char *val, FILE *rsp)
1868 case SELECTOR_BAD_DESCRIPTOR:
1869 fail(rsp, "%s: Invalid descriptor found in '%s'.\n", src, val);
1871 case SELECTOR_BAD_MODIFIERS:
1872 fail(rsp, "%s: Invalid modifier found in '%s'.\n", src, val);
1874 case SELECTOR_INVALID:
1880 void fail(FILE *rsp, char *fmt, ...)
1882 fprintf(rsp, FAILURE_MESSAGE);
1885 vfprintf(rsp, fmt, ap);