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("-y", *args) || streq("--type", *args)) {
464 fail(rsp, "node %s: Not enough arguments.\n", *(args - 1));
467 if (trg.node == NULL) {
473 if (parse_cycle_direction(*args, &cyc)) {
474 set_type(trg.node, (trg.node->split_type + 1) % 2);
475 } else if (parse_split_type(*args, &typ)) {
476 set_type(trg.node, typ);
482 } else if (streq("-r", *args) || streq("--ratio", *args)) {
485 fail(rsp, "node %s: Not enough arguments.\n", *(args - 1));
488 if (trg.node == NULL) {
492 if ((*args)[0] == '+' || (*args)[0] == '-') {
494 if (sscanf(*args, "%f", &delta) == 1) {
495 double rat = trg.node->split_ratio;
496 if (delta > -1 && delta < 1) {
499 int max = (trg.node->split_type == TYPE_HORIZONTAL ? trg.node->rectangle.height : trg.node->rectangle.width);
500 rat = ((max * rat) + delta) / max;
502 if (rat > 0 && rat < 1) {
503 set_ratio(trg.node, rat);
509 fail(rsp, "node %s: Invalid argument: '%s'.\n", *(args - 1), *args);
514 if (sscanf(*args, "%lf", &rat) == 1 && rat > 0 && rat < 1) {
515 set_ratio(trg.node, rat);
517 fail(rsp, "node %s: Invalid argument: '%s'.\n", *(args - 1), *args);
522 } else if (streq("-F", *args) || streq("--flip", *args)) {
525 fail(rsp, "node %s: Not enough arguments.\n", *(args - 1));
528 if (trg.node == NULL) {
533 if (parse_flip(*args, &flp)) {
534 flip_tree(trg.node, flp);
540 } else if (streq("-R", *args) || streq("--rotate", *args)) {
543 fail(rsp, "node %s: Not enough arguments.\n", *(args - 1));
546 if (trg.node == NULL) {
551 if (parse_degree(*args, °)) {
552 rotate_tree(trg.node, deg);
555 fail(rsp, "node %s: Invalid argument: '%s'.\n", *(args - 1), *args);
558 } else if (streq("-E", *args) || streq("--equalize", *args)) {
559 if (trg.node == NULL) {
563 equalize_tree(trg.node);
565 } else if (streq("-B", *args) || streq("--balance", *args)) {
566 if (trg.node == NULL) {
570 balance_tree(trg.node);
572 } else if (streq("-C", *args) || streq("--circulate", *args)) {
575 fail(rsp, "node %s: Not enough arguments.\n", *(args - 1));
578 if (trg.node == NULL) {
583 if (parse_circulate_direction(*args, &cir)) {
584 circulate_leaves(trg.monitor, trg.desktop, trg.node, cir);
587 fail(rsp, "node %s: Invalid argument: '%s'.\n", *(args - 1), *args);
590 } else if (streq("-i", *args) || streq("--insert-receptacle", *args)) {
591 insert_receptacle(trg.monitor, trg.desktop, trg.node);
593 } else if (streq("-c", *args) || streq("--close", *args)) {
595 fail(rsp, "node %s: Trailing commands.\n", *args);
598 if (trg.node == NULL || locked_count(trg.node) > 0) {
602 close_node(trg.node);
604 } else if (streq("-k", *args) || streq("--kill", *args)) {
606 fail(rsp, "node %s: Trailing commands.\n", *args);
609 if (trg.node == NULL) {
613 kill_node(trg.monitor, trg.desktop, trg.node);
617 fail(rsp, "node: Unknown command: '%s'.\n", *args);
625 arrange(trg.monitor, trg.desktop);
629 void cmd_desktop(char **args, int num, FILE *rsp)
632 fail(rsp, "desktop: Missing arguments.\n");
636 coordinates_t ref = {mon, mon->desk, NULL};
637 coordinates_t trg = ref;
639 if ((*args)[0] != OPT_CHR) {
641 if ((ret = desktop_from_desc(*args, &ref, &trg)) == SELECTOR_OK) {
644 handle_failure(ret, "desktop", *args, rsp);
650 fail(rsp, "desktop: Missing commands.\n");
654 bool changed = false;
657 if (streq("-f", *args) || streq("--focus", *args)) {
658 coordinates_t dst = trg;
659 if (num > 1 && *(args + 1)[0] != OPT_CHR) {
662 if ((ret = desktop_from_desc(*args, &ref, &dst)) != SELECTOR_OK) {
663 handle_failure(ret, "desktop -f", *args, rsp);
667 focus_node(dst.monitor, dst.desktop, NULL);
668 } else if (streq("-a", *args) || streq("--activate", *args)) {
669 coordinates_t dst = trg;
670 if (num > 1 && *(args + 1)[0] != OPT_CHR) {
673 if ((ret = desktop_from_desc(*args, &ref, &dst)) != SELECTOR_OK) {
674 handle_failure(ret, "desktop -a", *args, rsp);
678 if (activate_desktop(dst.monitor, dst.desktop)) {
679 activate_node(dst.monitor, dst.desktop, NULL);
684 } else if (streq("-m", *args) || streq("--to-monitor", *args)) {
687 fail(rsp, "desktop %s: Not enough arguments.\n", *(args - 1));
690 if (trg.monitor->desk_head == trg.monitor->desk_tail) {
696 if ((ret = monitor_from_desc(*args, &ref, &dst)) == SELECTOR_OK) {
698 if (num > 1 && streq("--follow", *(args+1))) {
702 if (transfer_desktop(trg.monitor, dst.monitor, trg.desktop, follow)) {
703 trg.monitor = dst.monitor;
709 handle_failure(ret, "desktop -m", *args, rsp);
712 } else if (streq("-s", *args) || streq("--swap", *args)) {
715 fail(rsp, "desktop %s: Not enough arguments.\n", *(args - 1));
720 if ((ret = desktop_from_desc(*args, &ref, &dst)) == SELECTOR_OK) {
722 if (num > 1 && streq("--follow", *(args+1))) {
726 if (swap_desktops(trg.monitor, trg.desktop, dst.monitor, dst.desktop, follow)) {
727 trg.monitor = dst.monitor;
733 handle_failure(ret, "desktop -s", *args, rsp);
736 } else if (streq("-b", *args) || streq("--bubble", *args)) {
739 fail(rsp, "desktop %s: Not enough arguments.\n", *(args - 1));
743 if (parse_cycle_direction(*args, &cyc)) {
744 desktop_t *d = trg.desktop;
745 if (cyc == CYCLE_PREV) {
746 if (d->prev == NULL) {
747 while (d->next != NULL) {
748 swap_desktops(trg.monitor, d, trg.monitor, d->next, false);
751 swap_desktops(trg.monitor, d, trg.monitor, d->prev, false);
754 if (d->next == NULL) {
755 while (d->prev != NULL) {
756 swap_desktops(trg.monitor, d, trg.monitor, d->prev, false);
759 swap_desktops(trg.monitor, d, trg.monitor, d->next, false);
763 fail(rsp, "desktop %s: Invalid argument: '%s'.\n", *(args - 1), *args);
766 } else if (streq("-l", *args) || streq("--layout", *args)) {
769 fail(rsp, "desktop %s: Not enough arguments.\n", *(args - 1));
775 if (parse_cycle_direction(*args, &cyc)) {
776 ret = set_layout(trg.monitor, trg.desktop, (trg.desktop->user_layout + 1) % 2, true);
777 } else if (parse_layout(*args, &lyt)) {
778 ret = set_layout(trg.monitor, trg.desktop, lyt, true);
780 fail(rsp, "desktop %s: Invalid argument: '%s'.\n", *(args - 1), *args);
787 } else if (streq("-n", *args) || streq("--rename", *args)) {
790 fail(rsp, "desktop %s: Not enough arguments.\n", *(args - 1));
793 rename_desktop(trg.monitor, trg.desktop, *args);
794 } else if (streq("-r", *args) || streq("--remove", *args)) {
796 fail(rsp, "desktop %s: Trailing commands.\n", *args);
799 if (trg.monitor->desk_head != trg.monitor->desk_tail) {
800 desktop_t *fallback = trg.desktop->prev == NULL ?
803 merge_desktops(trg.monitor, trg.desktop, trg.monitor, fallback);
804 remove_desktop(trg.monitor, trg.desktop);
811 fail(rsp, "desktop: Unknown command: '%s'.\n", *args);
818 arrange(trg.monitor, trg.desktop);
822 void cmd_monitor(char **args, int num, FILE *rsp)
825 fail(rsp, "monitor: Missing arguments.\n");
829 coordinates_t ref = {mon, NULL, NULL};
830 coordinates_t trg = ref;
832 if ((*args)[0] != OPT_CHR) {
834 if ((ret = monitor_from_desc(*args, &ref, &trg)) == SELECTOR_OK) {
837 handle_failure(ret, "monitor", *args, rsp);
843 fail(rsp, "monitor: Missing commands.\n");
848 if (streq("-f", *args) || streq("--focus", *args)) {
849 coordinates_t dst = trg;
850 if (num > 1 && *(args + 1)[0] != OPT_CHR) {
853 if ((ret = monitor_from_desc(*args, &ref, &dst)) != SELECTOR_OK) {
854 handle_failure(ret, "monitor -f", *args, rsp);
859 focus_node(dst.monitor, NULL, NULL);
860 } else if (streq("-s", *args) || streq("--swap", *args)) {
863 fail(rsp, "monitor %s: Not enough arguments.\n", *(args - 1));
868 if ((ret = monitor_from_desc(*args, &ref, &dst)) == SELECTOR_OK) {
869 if (!swap_monitors(trg.monitor, dst.monitor)) {
874 handle_failure(ret, "monitor -s", *args, rsp);
877 } else if (streq("-d", *args) || streq("--reset-desktops", *args)) {
880 fail(rsp, "monitor %s: Not enough arguments.\n", *(args - 1));
883 desktop_t *d = trg.monitor->desk_head;
884 while (num > 0 && d != NULL) {
885 rename_desktop(trg.monitor, d, *args);
889 put_status(SBSC_MASK_REPORT);
891 add_desktop(trg.monitor, make_desktop(*args, XCB_NONE));
895 desktop_t *next = d->next;
896 if (d == mon->desk) {
897 focus_node(trg.monitor, d->prev, d->prev->focus);
899 merge_desktops(trg.monitor, d, mon, mon->desk);
900 remove_desktop(trg.monitor, d);
903 } else if (streq("-a", *args) || streq("--add-desktops", *args)) {
906 fail(rsp, "monitor %s: Not enough arguments.\n", *(args - 1));
910 add_desktop(trg.monitor, make_desktop(*args, XCB_NONE));
913 } else if (streq("-r", *args) || streq("--remove", *args)) {
915 fail(rsp, "monitor %s: Trailing commands.\n", *args);
918 if (mon_head == mon_tail) {
922 remove_monitor(trg.monitor);
924 } else if (streq("-o", *args) || streq("--reorder-desktops", *args)) {
927 fail(rsp, "monitor %s: Not enough arguments.\n", *(args - 1));
930 desktop_t *d = trg.monitor->desk_head;
931 while (d != NULL && num > 0) {
932 desktop_t *next = d->next;
934 if (locate_desktop(*args, &dst) && dst.monitor == trg.monitor) {
935 swap_desktops(trg.monitor, d, dst.monitor, dst.desktop, false);
936 if (next == dst.desktop) {
943 } else if (streq("-g", *args) || streq("--rectangle", *args)) {
946 fail(rsp, "monitor %s: Not enough arguments.\n", *(args - 1));
950 if (parse_rectangle(*args, &r)) {
951 update_root(trg.monitor, &r);
953 fail(rsp, "monitor %s: Invalid argument: '%s'.\n", *(args - 1), *args);
956 } else if (streq("-n", *args) || streq("--rename", *args)) {
959 fail(rsp, "monitor %s: Not enough arguments.\n", *(args - 1));
962 rename_monitor(trg.monitor, *args);
964 fail(rsp, "monitor: Unknown command: '%s'.\n", *args);
971 void cmd_query(char **args, int num, FILE *rsp)
973 coordinates_t monitor_ref = {mon, NULL, NULL};
974 coordinates_t desktop_ref = {mon, mon->desk, NULL};
975 coordinates_t node_ref = {mon, mon->desk, mon->desk->focus};
976 coordinates_t trg = {NULL, NULL, NULL};
977 monitor_select_t *monitor_sel = NULL;
978 desktop_select_t *desktop_sel = NULL;
979 node_select_t *node_sel = NULL;
980 domain_t dom = DOMAIN_TREE;
981 bool print_ids = true;
985 fail(rsp, "query: Missing arguments.\n");
990 if (streq("-T", *args) || streq("--tree", *args)) {
991 dom = DOMAIN_TREE, d++;
992 } else if (streq("-M", *args) || streq("--monitors", *args)) {
993 dom = DOMAIN_MONITOR, d++;
994 if (num > 1 && *(args + 1)[0] != OPT_CHR) {
997 coordinates_t tmp = monitor_ref;
998 monitor_ref.desktop = NULL;
999 monitor_ref.node = NULL;
1000 if ((ret = monitor_from_desc(*args, &tmp, &monitor_ref)) != SELECTOR_OK) {
1001 handle_failure(ret, "query -M", *args, rsp);
1005 } else if (streq("-D", *args) || streq("--desktops", *args)) {
1006 dom = DOMAIN_DESKTOP, d++;
1007 if (num > 1 && *(args + 1)[0] != OPT_CHR) {
1010 coordinates_t tmp = desktop_ref;
1011 desktop_ref.node = NULL;
1012 if ((ret = desktop_from_desc(*args, &tmp, &desktop_ref)) != SELECTOR_OK) {
1013 handle_failure(ret, "query -D", *args, rsp);
1017 } else if (streq("-N", *args) || streq("--nodes", *args)) {
1018 dom = DOMAIN_NODE, d++;
1019 if (num > 1 && *(args + 1)[0] != OPT_CHR) {
1022 coordinates_t tmp = node_ref;
1023 if ((ret = node_from_desc(*args, &tmp, &node_ref)) != SELECTOR_OK) {
1024 handle_failure(ret, "query -N", *args, rsp);
1028 } else if (streq("-m", *args) || streq("--monitor", *args)) {
1029 if (num > 1 && *(args + 1)[0] != OPT_CHR) {
1032 if ((*args)[0] == '.') {
1034 monitor_sel = malloc(sizeof(monitor_select_t));
1035 *monitor_sel = make_monitor_select();
1036 char *desc = copy_string(*args, strlen(*args));
1037 if (!parse_monitor_modifiers(desc, monitor_sel)) {
1038 handle_failure(SELECTOR_BAD_MODIFIERS, "query -m", *args, rsp);
1043 } else if ((ret = monitor_from_desc(*args, &monitor_ref, &trg)) != SELECTOR_OK) {
1044 handle_failure(ret, "query -m", *args, rsp);
1050 } else if (streq("-d", *args) || streq("--desktop", *args)) {
1051 if (num > 1 && *(args + 1)[0] != OPT_CHR) {
1054 if ((*args)[0] == '.') {
1056 desktop_sel = malloc(sizeof(desktop_select_t));
1057 *desktop_sel = make_desktop_select();
1058 char *desc = copy_string(*args, strlen(*args));
1059 if (!parse_desktop_modifiers(desc, desktop_sel)) {
1060 handle_failure(SELECTOR_BAD_MODIFIERS, "query -d", *args, rsp);
1065 } else if ((ret = desktop_from_desc(*args, &desktop_ref, &trg)) != SELECTOR_OK) {
1066 handle_failure(ret, "query -d", *args, rsp);
1072 } else if (streq("-n", *args) || streq("--node", *args)) {
1073 if (num > 1 && *(args + 1)[0] != OPT_CHR) {
1076 if ((*args)[0] == '.') {
1078 node_sel = malloc(sizeof(node_select_t));
1079 *node_sel = make_node_select();
1080 char *desc = copy_string(*args, strlen(*args));
1081 if (!parse_node_modifiers(desc, node_sel)) {
1082 handle_failure(SELECTOR_BAD_MODIFIERS, "query -n", *args, rsp);
1087 } else if ((ret = node_from_desc(*args, &node_ref, &trg)) != SELECTOR_OK) {
1088 handle_failure(ret, "query -n", *args, rsp);
1093 if (trg.node == NULL) {
1098 } else if (streq("--names", *args)) {
1101 fail(rsp, "query: Unknown option: '%s'.\n", *args);
1108 fail(rsp, "query: No commands given.\n");
1113 fail(rsp, "query: Multiple commands given.\n");
1117 if (dom == DOMAIN_TREE && trg.monitor == NULL) {
1118 fail(rsp, "query -T: No options given.\n");
1122 if (!print_ids && (dom == DOMAIN_NODE || dom == DOMAIN_TREE)) {
1123 fail(rsp, "query -%c: --names only applies to -M and -D.\n", dom == DOMAIN_NODE ? 'N' : 'T');
1127 if ((dom == DOMAIN_MONITOR && (desktop_sel != NULL || node_sel != NULL)) ||
1128 (dom == DOMAIN_DESKTOP && node_sel != NULL)) {
1129 fail(rsp, "query -%c: Incompatible descriptor-free constraints.\n", dom == DOMAIN_MONITOR ? 'M' : 'D');
1133 if (dom == DOMAIN_NODE) {
1134 if (query_node_ids(&monitor_ref, &desktop_ref, &node_ref, &trg, monitor_sel, desktop_sel, node_sel, rsp) < 1) {
1137 } else if (dom == DOMAIN_DESKTOP) {
1138 if (query_desktop_ids(&monitor_ref, &desktop_ref, &trg, monitor_sel, desktop_sel, print_ids ? fprint_desktop_id : fprint_desktop_name, rsp) < 1) {
1141 } else if (dom == DOMAIN_MONITOR) {
1142 if (query_monitor_ids(&monitor_ref, &trg, monitor_sel, print_ids ? fprint_monitor_id : fprint_monitor_name, rsp) < 1) {
1146 if (trg.node != NULL) {
1147 query_node(trg.node, rsp);
1148 } else if (trg.desktop != NULL) {
1149 query_desktop(trg.desktop, rsp);
1151 query_monitor(trg.monitor, rsp);
1162 void cmd_rule(char **args, int num, FILE *rsp)
1165 fail(rsp, "rule: Missing commands.\n");
1170 if (streq("-a", *args) || streq("--add", *args)) {
1173 fail(rsp, "rule %s: Not enough arguments.\n", *(args - 1));
1176 rule_t *rule = make_rule();
1177 char *class_name = strtok(*args, COL_TOK);
1178 char *instance_name = strtok(NULL, COL_TOK);
1179 char *name = strtok(NULL, COL_TOK);
1180 snprintf(rule->class_name, sizeof(rule->class_name), "%s", class_name);
1181 snprintf(rule->instance_name, sizeof(rule->instance_name), "%s", instance_name==NULL?MATCH_ANY:instance_name);
1182 snprintf(rule->name, sizeof(rule->name), "%s", name==NULL?MATCH_ANY:name);
1186 if (streq("-o", *args) || streq("--one-shot", *args)) {
1187 rule->one_shot = true;
1189 for (size_t j = 0; i < sizeof(rule->effect) && j < strlen(*args); i++, j++) {
1190 rule->effect[i] = (*args)[j];
1192 if (num > 1 && i < sizeof(rule->effect)) {
1193 rule->effect[i++] = ' ';
1198 rule->effect[MIN(i, sizeof(rule->effect) - 1)] = '\0';
1200 } else if (streq("-r", *args) || streq("--remove", *args)) {
1203 fail(rsp, "rule %s: Not enough arguments.\n", *(args - 1));
1208 if (parse_index(*args, &idx)) {
1209 remove_rule_by_index(idx - 1);
1210 } else if (streq("tail", *args)) {
1211 remove_rule(rule_tail);
1212 } else if (streq("head", *args)) {
1213 remove_rule(rule_head);
1215 remove_rule_by_cause(*args);
1219 } else if (streq("-l", *args) || streq("--list", *args)) {
1222 fail(rsp, "rule: Unknown command: '%s'.\n", *args);
1229 void cmd_wm(char **args, int num, FILE *rsp)
1232 fail(rsp, "wm: Missing commands.\n");
1237 if (streq("-d", *args) || streq("--dump-state", *args)) {
1240 } else if (streq("-l", *args) || streq("--load-state", *args)) {
1243 fail(rsp, "wm %s: Not enough arguments.\n", *(args - 1));
1246 if (!restore_state(*args)) {
1250 } else if (streq("-a", *args) || streq("--add-monitor", *args)) {
1253 fail(rsp, "wm %s: Not enough arguments.\n", *(args - 1));
1259 if (parse_rectangle(*args, &r)) {
1260 monitor_t *m = make_monitor(name, &r, XCB_NONE);
1262 add_desktop(m, make_desktop(NULL, XCB_NONE));
1264 fail(rsp, "wm %s: Invalid argument: '%s'.\n", *(args - 1), *args);
1267 } else if (streq("-O", *args) || streq("--reorder-monitors", *args)) {
1270 fail(rsp, "wm %s: Not enough arguments.\n", *(args - 1));
1273 monitor_t *m = mon_head;
1274 while (m != NULL && num > 0) {
1275 monitor_t *next = m->next;
1277 if (locate_monitor(*args, &dst)) {
1278 swap_monitors(m, dst.monitor);
1279 if (next == dst.monitor) {
1286 } else if (streq("-o", *args) || streq("--adopt-orphans", *args)) {
1288 } else if (streq("-g", *args) || streq("--get-status", *args)) {
1290 } else if (streq("-h", *args) || streq("--record-history", *args)) {
1293 fail(rsp, "wm %s: Not enough arguments.\n", *(args - 1));
1297 if (parse_bool(*args, &b)) {
1300 fail(rsp, "wm %s: Invalid argument: '%s'.\n", *(args - 1), *args);
1303 } else if (streq("-r", *args) || streq("--restart", *args)) {
1308 fail(rsp, "wm: Unknown command: '%s'.\n", *args);
1315 void cmd_subscribe(char **args, int num, FILE *rsp)
1320 char *fifo_path = NULL;
1321 subscriber_mask_t mask;
1324 if (streq("-c", *args) || streq("--count", *args)) {
1327 fail(rsp, "subscribe %s: Not enough arguments.\n", *(args - 1));
1330 if (sscanf(*args, "%i", &count) != 1 || count < 1) {
1331 fail(rsp, "subscribe %s: Invalid argument: '%s'.\n", *(args - 1), *args);
1334 } else if (streq("-f", *args) || streq("--fifo", *args)) {
1335 fifo_path = mktempfifo(FIFO_TEMPLATE);
1336 if (fifo_path == NULL) {
1337 fail(rsp, "subscribe %s: Can't create FIFO.\n", *(args - 1));
1340 } else if (parse_subscriber_mask(*args, &mask)) {
1343 fail(rsp, "subscribe: Invalid argument: '%s'.\n", *args);
1350 field = SBSC_MASK_REPORT;
1354 fprintf(rsp, "%s\n", fifo_path);
1358 stream = fopen(fifo_path, "w");
1360 if (stream == NULL) {
1361 perror("subscribe: fopen");
1362 goto free_fifo_path;
1366 subscriber_list_t *sb = make_subscriber(stream, fifo_path, field, count);
1381 void cmd_quit(char **args, int num, FILE *rsp)
1383 if (num > 0 && sscanf(*args, "%i", &exit_status) != 1) {
1384 fail(rsp, "%s: Invalid argument: '%s'.\n", *(args - 1), *args);
1390 void cmd_config(char **args, int num, FILE *rsp)
1393 fail(rsp, "config: Missing arguments.\n");
1397 coordinates_t ref = {mon, mon->desk, mon->desk->focus};
1398 coordinates_t trg = {NULL, NULL, NULL};
1400 while (num > 0 && (*args)[0] == OPT_CHR) {
1401 if (streq("-m", *args) || streq("--monitor", *args)) {
1404 fail(rsp, "config %s: Not enough arguments.\n", *(args - 1));
1408 if ((ret = monitor_from_desc(*args, &ref, &trg)) != SELECTOR_OK) {
1409 handle_failure(ret, "config -m", *args, rsp);
1412 } else if (streq("-d", *args) || streq("--desktop", *args)) {
1415 fail(rsp, "config %s: Not enough arguments.\n", *(args - 1));
1419 if ((ret = desktop_from_desc(*args, &ref, &trg)) != SELECTOR_OK) {
1420 handle_failure(ret, "config -d", *args, rsp);
1423 } else if (streq("-n", *args) || streq("--node", *args)) {
1426 fail(rsp, "config %s: Not enough arguments.\n", *(args - 1));
1430 if ((ret = node_from_desc(*args, &ref, &trg)) != SELECTOR_OK) {
1431 handle_failure(ret, "config -n", *args, rsp);
1435 fail(rsp, "config: Unknown option: '%s'.\n", *args);
1441 set_setting(trg, *args, *(args + 1), rsp);
1442 } else if (num == 1) {
1443 get_setting(trg, *args, rsp);
1445 fail(rsp, "config: Was expecting 1 or 2 arguments, received %i.\n", num);
1449 void set_setting(coordinates_t loc, char *name, char *value, FILE *rsp)
1451 bool colors_changed = false;
1452 #define SET_DEF_DEFMON_DEFDESK_WIN(k, v) \
1453 if (loc.node != NULL) { \
1454 for (node_t *n = first_extrema(loc.node); n != NULL; n = next_leaf(n, loc.node)) { \
1455 if (n->client != NULL) { \
1459 } else if (loc.desktop != NULL) { \
1460 loc.desktop->k = v; \
1461 for (node_t *n = first_extrema(loc.desktop->root); n != NULL; n = next_leaf(n, loc.desktop->root)) { \
1462 if (n->client != NULL) { \
1466 } else if (loc.monitor != NULL) { \
1467 loc.monitor->k = v; \
1468 for (desktop_t *d = loc.monitor->desk_head; d != NULL; d = d->next) { \
1470 for (node_t *n = first_extrema(d->root); n != NULL; n = next_leaf(n, d->root)) { \
1471 if (n->client != NULL) { \
1478 for (monitor_t *m = mon_head; m != NULL; m = m->next) { \
1480 for (desktop_t *d = m->desk_head; d != NULL; d = d->next) { \
1482 for (node_t *n = first_extrema(d->root); n != NULL; n = next_leaf(n, d->root)) { \
1483 if (n->client != NULL) { \
1490 if (streq("border_width", name)) {
1492 if (sscanf(value, "%u", &bw) != 1) {
1493 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1496 SET_DEF_DEFMON_DEFDESK_WIN(border_width, bw)
1497 #undef SET_DEF_DEFMON_DEFDESK_WIN
1498 #define SET_DEF_DEFMON_DESK(k, v) \
1499 if (loc.desktop != NULL) { \
1500 loc.desktop->k = v; \
1501 } else if (loc.monitor != NULL) { \
1502 loc.monitor->k = v; \
1503 for (desktop_t *d = loc.monitor->desk_head; d != NULL; d = d->next) { \
1508 for (monitor_t *m = mon_head; m != NULL; m = m->next) { \
1510 for (desktop_t *d = m->desk_head; d != NULL; d = d->next) { \
1515 } else if (streq("window_gap", name)) {
1517 if (sscanf(value, "%i", &wg) != 1) {
1521 SET_DEF_DEFMON_DESK(window_gap, wg)
1522 #undef SET_DEF_DEFMON_DESK
1523 #define SET_DEF_MON_DESK(k, v) \
1524 if (loc.desktop != NULL) { \
1525 loc.desktop->k = v; \
1526 } else if (loc.monitor != NULL) { \
1527 loc.monitor->k = v; \
1530 for (monitor_t *m = mon_head; m != NULL; m = m->next) { \
1534 } else if (streq("top_padding", name)) {
1536 if (sscanf(value, "%i", &tp) != 1) {
1537 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1540 SET_DEF_MON_DESK(padding.top, tp)
1541 } else if (streq("right_padding", name)) {
1543 if (sscanf(value, "%i", &rp) != 1) {
1544 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1547 SET_DEF_MON_DESK(padding.right, rp)
1548 } else if (streq("bottom_padding", name)) {
1550 if (sscanf(value, "%i", &bp) != 1) {
1551 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1554 SET_DEF_MON_DESK(padding.bottom, bp)
1555 } else if (streq("left_padding", name)) {
1557 if (sscanf(value, "%i", &lp) != 1) {
1558 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1561 SET_DEF_MON_DESK(padding.left, lp)
1562 #undef SET_DEF_MON_DESK
1563 } else if (streq("top_monocle_padding", name)) {
1564 if (sscanf(value, "%i", &monocle_padding.top) != 1) {
1565 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1567 } else if (streq("right_monocle_padding", name)) {
1568 if (sscanf(value, "%i", &monocle_padding.right) != 1) {
1569 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1571 } else if (streq("bottom_monocle_padding", name)) {
1572 if (sscanf(value, "%i", &monocle_padding.bottom) != 1) {
1573 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1575 } else if (streq("left_monocle_padding", name)) {
1576 if (sscanf(value, "%i", &monocle_padding.left) != 1) {
1577 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1579 #define SET_STR(s) \
1580 } else if (streq(#s, name)) { \
1581 if (snprintf(s, sizeof(s), "%s", value) < 0) { \
1585 SET_STR(external_rules_command)
1586 SET_STR(status_prefix)
1588 } else if (streq("split_ratio", name)) {
1590 if (sscanf(value, "%lf", &r) == 1 && r > 0 && r < 1) {
1593 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value); \
1597 #define SET_COLOR(s) \
1598 } else if (streq(#s, name)) { \
1599 if (!is_hex_color(value)) { \
1600 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value); \
1603 snprintf(s, sizeof(s), "%s", value); \
1604 colors_changed = true; \
1606 SET_COLOR(normal_border_color)
1607 SET_COLOR(active_border_color)
1608 SET_COLOR(focused_border_color)
1609 SET_COLOR(presel_feedback_color)
1611 } else if (streq("initial_polarity", name)) {
1613 if (parse_child_polarity(value, &p)) {
1614 initial_polarity = p;
1616 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1619 } else if (streq("automatic_scheme", name)) {
1620 automatic_scheme_t a;
1621 if (parse_automatic_scheme(value, &a)) {
1622 automatic_scheme = a;
1624 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1627 } else if (streq("mapping_events_count", name)) {
1628 if (sscanf(value, "%" SCNi8, &mapping_events_count) != 1) {
1629 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1632 } else if (streq("directional_focus_tightness", name)) {
1634 if (parse_tightness(value, &p)) {
1635 directional_focus_tightness = p;
1637 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1640 } else if (streq("ignore_ewmh_fullscreen", name)) {
1641 state_transition_t m;
1642 if (parse_state_transition(value, &m)) {
1643 ignore_ewmh_fullscreen = m;
1645 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1648 } else if (streq("pointer_modifier", name)) {
1649 if (parse_modifier_mask(value, &pointer_modifier)) {
1653 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1656 } else if (streq("pointer_motion_interval", name)) {
1657 if (sscanf(value, "%u", &pointer_motion_interval) != 1) {
1658 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1661 } else if (streq("pointer_action1", name) ||
1662 streq("pointer_action2", name) ||
1663 streq("pointer_action3", name)) {
1664 int index = name[14] - '1';
1665 if (parse_pointer_action(value, &pointer_actions[index])) {
1669 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1672 } else if (streq("click_to_focus", name)) {
1673 if (parse_button_index(value, &click_to_focus)) {
1677 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1680 } else if (streq("single_monocle", name)) {
1682 if (parse_bool(value, &b)) {
1683 if (b == single_monocle) {
1688 for (monitor_t *m = mon_head; m != NULL; m = m->next) {
1689 for (desktop_t *d = m->desk_head; d != NULL; d = d->next) {
1690 layout_t l = (single_monocle && tiled_count(d->root, true) <= 1) ? LAYOUT_MONOCLE : d->user_layout;
1691 set_layout(m, d, l, false);
1695 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1698 } else if (streq("focus_follows_pointer", name)) {
1700 if (parse_bool(value, &b)) {
1701 if (b == focus_follows_pointer) {
1705 focus_follows_pointer = b;
1706 for (monitor_t *m = mon_head; m != NULL; m = m->next) {
1707 if (focus_follows_pointer) {
1708 window_show(m->root);
1710 window_hide(m->root);
1712 for (desktop_t *d = m->desk_head; d != NULL; d = d->next) {
1713 listen_enter_notify(d->root, focus_follows_pointer);
1716 if (focus_follows_pointer) {
1717 update_motion_recorder();
1719 disable_motion_recorder();
1723 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1726 #define SET_BOOL(s) \
1727 } else if (streq(#s, name)) { \
1728 if (!parse_bool(value, &s)) { \
1729 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value); \
1732 SET_BOOL(presel_feedback)
1733 SET_BOOL(borderless_monocle)
1734 SET_BOOL(gapless_monocle)
1735 SET_BOOL(borderless_singleton)
1736 SET_BOOL(swallow_first_click)
1737 SET_BOOL(pointer_follows_focus)
1738 SET_BOOL(pointer_follows_monitor)
1739 SET_BOOL(ignore_ewmh_focus)
1740 SET_BOOL(ignore_ewmh_struts)
1741 SET_BOOL(center_pseudo_tiled)
1742 SET_BOOL(honor_size_hints)
1743 SET_BOOL(removal_adjustment)
1745 #define SET_MON_BOOL(s) \
1746 } else if (streq(#s, name)) { \
1747 if (!parse_bool(value, &s)) { \
1748 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value); \
1752 update_monitors(); \
1754 SET_MON_BOOL(remove_disabled_monitors)
1755 SET_MON_BOOL(remove_unplugged_monitors)
1756 SET_MON_BOOL(merge_overlapping_monitors)
1759 fail(rsp, "config: Unknown setting: '%s'.\n", name);
1763 for (monitor_t *m = mon_head; m != NULL; m = m->next) {
1764 for (desktop_t *d = m->desk_head; d != NULL; d = d->next) {
1766 if (colors_changed) {
1767 update_colors_in(d->root, d, m);
1773 void get_setting(coordinates_t loc, char *name, FILE* rsp)
1775 if (streq("split_ratio", name)) {
1776 fprintf(rsp, "%lf", split_ratio);
1777 } else if (streq("border_width", name)) {
1778 if (loc.node != NULL) {
1779 for (node_t *n = first_extrema(loc.node); n != NULL; n = next_leaf(n, loc.node)) {
1780 if (n->client != NULL) {
1781 fprintf(rsp, "%u", n->client->border_width);
1785 } else if (loc.desktop != NULL) {
1786 fprintf(rsp, "%u", loc.desktop->border_width);
1787 } else if (loc.monitor != NULL) {
1788 fprintf(rsp, "%u", loc.monitor->border_width);
1790 fprintf(rsp, "%u", border_width);
1792 } else if (streq("window_gap", name)) {
1793 if (loc.desktop != NULL) {
1794 fprintf(rsp, "%i", loc.desktop->window_gap);
1795 } else if (loc.monitor != NULL) {
1796 fprintf(rsp, "%i", loc.monitor->window_gap);
1798 fprintf(rsp, "%i", window_gap);
1800 #define GET_DEF_MON_DESK(k) \
1801 if (loc.desktop != NULL) { \
1802 fprintf(rsp, "%i", loc.desktop->k); \
1803 } else if (loc.monitor != NULL) { \
1804 fprintf(rsp, "%i", loc.monitor->k); \
1806 fprintf(rsp, "%i", k); \
1808 } else if (streq("top_padding", name)) {
1809 GET_DEF_MON_DESK(padding.top)
1810 } else if (streq("right_padding", name)) {
1811 GET_DEF_MON_DESK(padding.right)
1812 } else if (streq("bottom_padding", name)) {
1813 GET_DEF_MON_DESK(padding.bottom)
1814 } else if (streq("left_padding", name)) {
1815 GET_DEF_MON_DESK(padding.left)
1816 #undef GET_DEF_MON_DESK
1817 } else if (streq("top_monocle_padding", name)) {
1818 fprintf(rsp, "%i", monocle_padding.top);
1819 } else if (streq("right_monocle_padding", name)) {
1820 fprintf(rsp, "%i", monocle_padding.right);
1821 } else if (streq("bottom_monocle_padding", name)) {
1822 fprintf(rsp, "%i", monocle_padding.bottom);
1823 } else if (streq("left_monocle_padding", name)) {
1824 fprintf(rsp, "%i", monocle_padding.left);
1825 } else if (streq("external_rules_command", name)) {
1826 fprintf(rsp, "%s", external_rules_command);
1827 } else if (streq("status_prefix", name)) {
1828 fprintf(rsp, "%s", status_prefix);
1829 } else if (streq("initial_polarity", name)) {
1830 fprintf(rsp, "%s", CHILD_POL_STR(initial_polarity));
1831 } else if (streq("automatic_scheme", name)) {
1832 fprintf(rsp, "%s", AUTO_SCM_STR(automatic_scheme));
1833 } else if (streq("mapping_events_count", name)) {
1834 fprintf(rsp, "%" PRIi8, mapping_events_count);
1835 } else if (streq("directional_focus_tightness", name)) {
1836 fprintf(rsp, "%s", TIGHTNESS_STR(directional_focus_tightness));
1837 } else if (streq("ignore_ewmh_fullscreen", name)) {
1838 print_ignore_request(ignore_ewmh_fullscreen, rsp);
1839 } else if (streq("pointer_modifier", name)) {
1840 print_modifier_mask(pointer_modifier, rsp);
1841 } else if (streq("click_to_focus", name)) {
1842 print_button_index(click_to_focus, rsp);
1843 } else if (streq("pointer_motion_interval", name)) {
1844 fprintf(rsp, "%u", pointer_motion_interval);
1845 } else if (streq("pointer_action1", name) ||
1846 streq("pointer_action2", name) ||
1847 streq("pointer_action3", name)) {
1848 int index = name[14] - '1';
1849 print_pointer_action(pointer_actions[index], rsp);
1850 #define GET_COLOR(s) \
1851 } else if (streq(#s, name)) { \
1852 fprintf(rsp, "%s", s);
1853 GET_COLOR(normal_border_color)
1854 GET_COLOR(active_border_color)
1855 GET_COLOR(focused_border_color)
1856 GET_COLOR(presel_feedback_color)
1858 #define GET_BOOL(s) \
1859 } else if (streq(#s, name)) { \
1860 fprintf(rsp, "%s", BOOL_STR(s));
1861 GET_BOOL(presel_feedback)
1862 GET_BOOL(borderless_monocle)
1863 GET_BOOL(gapless_monocle)
1864 GET_BOOL(single_monocle)
1865 GET_BOOL(borderless_singleton)
1866 GET_BOOL(swallow_first_click)
1867 GET_BOOL(focus_follows_pointer)
1868 GET_BOOL(pointer_follows_focus)
1869 GET_BOOL(pointer_follows_monitor)
1870 GET_BOOL(ignore_ewmh_focus)
1871 GET_BOOL(ignore_ewmh_struts)
1872 GET_BOOL(center_pseudo_tiled)
1873 GET_BOOL(honor_size_hints)
1874 GET_BOOL(removal_adjustment)
1875 GET_BOOL(remove_disabled_monitors)
1876 GET_BOOL(remove_unplugged_monitors)
1877 GET_BOOL(merge_overlapping_monitors)
1880 fail(rsp, "config: Unknown setting: '%s'.\n", name);
1886 void handle_failure(int code, char *src, char *val, FILE *rsp)
1889 case SELECTOR_BAD_DESCRIPTOR:
1890 fail(rsp, "%s: Invalid descriptor found in '%s'.\n", src, val);
1892 case SELECTOR_BAD_MODIFIERS:
1893 fail(rsp, "%s: Invalid modifier found in '%s'.\n", src, val);
1895 case SELECTOR_INVALID:
1901 void fail(FILE *rsp, char *fmt, ...)
1903 fprintf(rsp, FAILURE_MESSAGE);
1906 vfprintf(rsp, fmt, ap);