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) {
472 if (parse_split_type(*args, &typ)) {
473 set_type(trg.node, typ);
479 } else if (streq("-r", *args) || streq("--ratio", *args)) {
482 fail(rsp, "node %s: Not enough arguments.\n", *(args - 1));
485 if (trg.node == NULL) {
489 if ((*args)[0] == '+' || (*args)[0] == '-') {
491 if (sscanf(*args, "%f", &delta) == 1) {
492 double rat = trg.node->split_ratio;
493 if (delta > -1 && delta < 1) {
496 int max = (trg.node->split_type == TYPE_HORIZONTAL ? trg.node->rectangle.height : trg.node->rectangle.width);
497 rat = ((max * rat) + delta) / max;
499 if (rat > 0 && rat < 1) {
500 set_ratio(trg.node, rat);
506 fail(rsp, "node %s: Invalid argument: '%s'.\n", *(args - 1), *args);
511 if (sscanf(*args, "%lf", &rat) == 1 && rat > 0 && rat < 1) {
512 set_ratio(trg.node, rat);
514 fail(rsp, "node %s: Invalid argument: '%s'.\n", *(args - 1), *args);
519 } else if (streq("-F", *args) || streq("--flip", *args)) {
522 fail(rsp, "node %s: Not enough arguments.\n", *(args - 1));
525 if (trg.node == NULL) {
530 if (parse_flip(*args, &flp)) {
531 flip_tree(trg.node, flp);
537 } else if (streq("-R", *args) || streq("--rotate", *args)) {
540 fail(rsp, "node %s: Not enough arguments.\n", *(args - 1));
543 if (trg.node == NULL) {
548 if (parse_degree(*args, °)) {
549 rotate_tree(trg.node, deg);
552 fail(rsp, "node %s: Invalid argument: '%s'.\n", *(args - 1), *args);
555 } else if (streq("-E", *args) || streq("--equalize", *args)) {
556 if (trg.node == NULL) {
560 equalize_tree(trg.node);
562 } else if (streq("-B", *args) || streq("--balance", *args)) {
563 if (trg.node == NULL) {
567 balance_tree(trg.node);
569 } else if (streq("-C", *args) || streq("--circulate", *args)) {
572 fail(rsp, "node %s: Not enough arguments.\n", *(args - 1));
575 if (trg.node == NULL) {
580 if (parse_circulate_direction(*args, &cir)) {
581 circulate_leaves(trg.monitor, trg.desktop, trg.node, cir);
584 fail(rsp, "node %s: Invalid argument: '%s'.\n", *(args - 1), *args);
587 } else if (streq("-i", *args) || streq("--insert-receptacle", *args)) {
588 insert_receptacle(trg.monitor, trg.desktop, trg.node);
590 } else if (streq("-c", *args) || streq("--close", *args)) {
592 fail(rsp, "node %s: Trailing commands.\n", *args);
595 if (trg.node == NULL || locked_count(trg.node) > 0) {
599 close_node(trg.node);
601 } else if (streq("-k", *args) || streq("--kill", *args)) {
603 fail(rsp, "node %s: Trailing commands.\n", *args);
606 if (trg.node == NULL) {
610 kill_node(trg.monitor, trg.desktop, trg.node);
614 fail(rsp, "node: Unknown command: '%s'.\n", *args);
622 arrange(trg.monitor, trg.desktop);
626 void cmd_desktop(char **args, int num, FILE *rsp)
629 fail(rsp, "desktop: Missing arguments.\n");
633 coordinates_t ref = {mon, mon->desk, NULL};
634 coordinates_t trg = ref;
636 if ((*args)[0] != OPT_CHR) {
638 if ((ret = desktop_from_desc(*args, &ref, &trg)) == SELECTOR_OK) {
641 handle_failure(ret, "desktop", *args, rsp);
647 fail(rsp, "desktop: Missing commands.\n");
651 bool changed = false;
654 if (streq("-f", *args) || streq("--focus", *args)) {
655 coordinates_t dst = trg;
656 if (num > 1 && *(args + 1)[0] != OPT_CHR) {
659 if ((ret = desktop_from_desc(*args, &ref, &dst)) != SELECTOR_OK) {
660 handle_failure(ret, "desktop -f", *args, rsp);
664 focus_node(dst.monitor, dst.desktop, NULL);
665 } else if (streq("-a", *args) || streq("--activate", *args)) {
666 coordinates_t dst = trg;
667 if (num > 1 && *(args + 1)[0] != OPT_CHR) {
670 if ((ret = desktop_from_desc(*args, &ref, &dst)) != SELECTOR_OK) {
671 handle_failure(ret, "desktop -a", *args, rsp);
675 if (activate_desktop(dst.monitor, dst.desktop)) {
676 activate_node(dst.monitor, dst.desktop, NULL);
681 } else if (streq("-m", *args) || streq("--to-monitor", *args)) {
684 fail(rsp, "desktop %s: Not enough arguments.\n", *(args - 1));
687 if (trg.monitor->desk_head == trg.monitor->desk_tail) {
693 if ((ret = monitor_from_desc(*args, &ref, &dst)) == SELECTOR_OK) {
695 if (num > 1 && streq("--follow", *(args+1))) {
699 if (transfer_desktop(trg.monitor, dst.monitor, trg.desktop, follow)) {
700 trg.monitor = dst.monitor;
706 handle_failure(ret, "desktop -m", *args, rsp);
709 } else if (streq("-s", *args) || streq("--swap", *args)) {
712 fail(rsp, "desktop %s: Not enough arguments.\n", *(args - 1));
717 if ((ret = desktop_from_desc(*args, &ref, &dst)) == SELECTOR_OK) {
719 if (num > 1 && streq("--follow", *(args+1))) {
723 if (swap_desktops(trg.monitor, trg.desktop, dst.monitor, dst.desktop, follow)) {
724 trg.monitor = dst.monitor;
730 handle_failure(ret, "desktop -s", *args, rsp);
733 } else if (streq("-b", *args) || streq("--bubble", *args)) {
736 fail(rsp, "desktop %s: Not enough arguments.\n", *(args - 1));
740 if (parse_cycle_direction(*args, &cyc)) {
741 desktop_t *d = trg.desktop;
742 if (cyc == CYCLE_PREV) {
743 if (d->prev == NULL) {
744 while (d->next != NULL) {
745 swap_desktops(trg.monitor, d, trg.monitor, d->next, false);
748 swap_desktops(trg.monitor, d, trg.monitor, d->prev, false);
751 if (d->next == NULL) {
752 while (d->prev != NULL) {
753 swap_desktops(trg.monitor, d, trg.monitor, d->prev, false);
756 swap_desktops(trg.monitor, d, trg.monitor, d->next, false);
760 fail(rsp, "desktop %s: Invalid argument: '%s'.\n", *(args - 1), *args);
763 } else if (streq("-l", *args) || streq("--layout", *args)) {
766 fail(rsp, "desktop %s: Not enough arguments.\n", *(args - 1));
772 if (parse_cycle_direction(*args, &cyc)) {
773 ret = set_layout(trg.monitor, trg.desktop, (trg.desktop->user_layout + 1) % 2, true);
774 } else if (parse_layout(*args, &lyt)) {
775 ret = set_layout(trg.monitor, trg.desktop, lyt, true);
777 fail(rsp, "desktop %s: Invalid argument: '%s'.\n", *(args - 1), *args);
784 } else if (streq("-n", *args) || streq("--rename", *args)) {
787 fail(rsp, "desktop %s: Not enough arguments.\n", *(args - 1));
790 rename_desktop(trg.monitor, trg.desktop, *args);
791 } else if (streq("-r", *args) || streq("--remove", *args)) {
793 fail(rsp, "desktop %s: Trailing commands.\n", *args);
796 if (trg.monitor->desk_head != trg.monitor->desk_tail) {
797 desktop_t *fallback = trg.desktop->prev == NULL ?
800 merge_desktops(trg.monitor, trg.desktop, trg.monitor, fallback);
801 remove_desktop(trg.monitor, trg.desktop);
808 fail(rsp, "desktop: Unknown command: '%s'.\n", *args);
815 arrange(trg.monitor, trg.desktop);
819 void cmd_monitor(char **args, int num, FILE *rsp)
822 fail(rsp, "monitor: Missing arguments.\n");
826 coordinates_t ref = {mon, NULL, NULL};
827 coordinates_t trg = ref;
829 if ((*args)[0] != OPT_CHR) {
831 if ((ret = monitor_from_desc(*args, &ref, &trg)) == SELECTOR_OK) {
834 handle_failure(ret, "monitor", *args, rsp);
840 fail(rsp, "monitor: Missing commands.\n");
845 if (streq("-f", *args) || streq("--focus", *args)) {
846 coordinates_t dst = trg;
847 if (num > 1 && *(args + 1)[0] != OPT_CHR) {
850 if ((ret = monitor_from_desc(*args, &ref, &dst)) != SELECTOR_OK) {
851 handle_failure(ret, "monitor -f", *args, rsp);
856 focus_node(dst.monitor, NULL, NULL);
857 } else if (streq("-s", *args) || streq("--swap", *args)) {
860 fail(rsp, "monitor %s: Not enough arguments.\n", *(args - 1));
865 if ((ret = monitor_from_desc(*args, &ref, &dst)) == SELECTOR_OK) {
866 if (!swap_monitors(trg.monitor, dst.monitor)) {
871 handle_failure(ret, "monitor -s", *args, rsp);
874 } else if (streq("-d", *args) || streq("--reset-desktops", *args)) {
877 fail(rsp, "monitor %s: Not enough arguments.\n", *(args - 1));
880 desktop_t *d = trg.monitor->desk_head;
881 while (num > 0 && d != NULL) {
882 rename_desktop(trg.monitor, d, *args);
886 put_status(SBSC_MASK_REPORT);
888 add_desktop(trg.monitor, make_desktop(*args, XCB_NONE));
892 desktop_t *next = d->next;
893 if (d == mon->desk) {
894 focus_node(trg.monitor, d->prev, d->prev->focus);
896 merge_desktops(trg.monitor, d, mon, mon->desk);
897 remove_desktop(trg.monitor, d);
900 } else if (streq("-a", *args) || streq("--add-desktops", *args)) {
903 fail(rsp, "monitor %s: Not enough arguments.\n", *(args - 1));
907 add_desktop(trg.monitor, make_desktop(*args, XCB_NONE));
910 } else if (streq("-r", *args) || streq("--remove", *args)) {
912 fail(rsp, "monitor %s: Trailing commands.\n", *args);
915 if (mon_head == mon_tail) {
919 remove_monitor(trg.monitor);
921 } else if (streq("-o", *args) || streq("--reorder-desktops", *args)) {
924 fail(rsp, "monitor %s: Not enough arguments.\n", *(args - 1));
927 desktop_t *d = trg.monitor->desk_head;
928 while (d != NULL && num > 0) {
929 desktop_t *next = d->next;
931 if (locate_desktop(*args, &dst) && dst.monitor == trg.monitor) {
932 swap_desktops(trg.monitor, d, dst.monitor, dst.desktop, false);
933 if (next == dst.desktop) {
940 } else if (streq("-g", *args) || streq("--rectangle", *args)) {
943 fail(rsp, "monitor %s: Not enough arguments.\n", *(args - 1));
947 if (parse_rectangle(*args, &r)) {
948 update_root(trg.monitor, &r);
950 fail(rsp, "monitor %s: Invalid argument: '%s'.\n", *(args - 1), *args);
953 } else if (streq("-n", *args) || streq("--rename", *args)) {
956 fail(rsp, "monitor %s: Not enough arguments.\n", *(args - 1));
959 rename_monitor(trg.monitor, *args);
961 fail(rsp, "monitor: Unknown command: '%s'.\n", *args);
968 void cmd_query(char **args, int num, FILE *rsp)
970 coordinates_t monitor_ref = {mon, NULL, NULL};
971 coordinates_t desktop_ref = {mon, mon->desk, NULL};
972 coordinates_t node_ref = {mon, mon->desk, mon->desk->focus};
973 coordinates_t trg = {NULL, NULL, NULL};
974 monitor_select_t *monitor_sel = NULL;
975 desktop_select_t *desktop_sel = NULL;
976 node_select_t *node_sel = NULL;
977 domain_t dom = DOMAIN_TREE;
978 bool print_ids = true;
982 fail(rsp, "query: Missing arguments.\n");
987 if (streq("-T", *args) || streq("--tree", *args)) {
988 dom = DOMAIN_TREE, d++;
989 } else if (streq("-M", *args) || streq("--monitors", *args)) {
990 dom = DOMAIN_MONITOR, d++;
991 if (num > 1 && *(args + 1)[0] != OPT_CHR) {
994 coordinates_t tmp = monitor_ref;
995 monitor_ref.desktop = NULL;
996 monitor_ref.node = NULL;
997 if ((ret = monitor_from_desc(*args, &tmp, &monitor_ref)) != SELECTOR_OK) {
998 handle_failure(ret, "query -M", *args, rsp);
1002 } else if (streq("-D", *args) || streq("--desktops", *args)) {
1003 dom = DOMAIN_DESKTOP, d++;
1004 if (num > 1 && *(args + 1)[0] != OPT_CHR) {
1007 coordinates_t tmp = desktop_ref;
1008 desktop_ref.node = NULL;
1009 if ((ret = desktop_from_desc(*args, &tmp, &desktop_ref)) != SELECTOR_OK) {
1010 handle_failure(ret, "query -D", *args, rsp);
1014 } else if (streq("-N", *args) || streq("--nodes", *args)) {
1015 dom = DOMAIN_NODE, d++;
1016 if (num > 1 && *(args + 1)[0] != OPT_CHR) {
1019 coordinates_t tmp = node_ref;
1020 if ((ret = node_from_desc(*args, &tmp, &node_ref)) != SELECTOR_OK) {
1021 handle_failure(ret, "query -N", *args, rsp);
1025 } else if (streq("-m", *args) || streq("--monitor", *args)) {
1026 if (num > 1 && *(args + 1)[0] != OPT_CHR) {
1029 if ((*args)[0] == '.') {
1031 monitor_sel = malloc(sizeof(monitor_select_t));
1032 *monitor_sel = make_monitor_select();
1033 char *desc = copy_string(*args, strlen(*args));
1034 if (!parse_monitor_modifiers(desc, monitor_sel)) {
1035 handle_failure(SELECTOR_BAD_MODIFIERS, "query -m", *args, rsp);
1040 } else if ((ret = monitor_from_desc(*args, &monitor_ref, &trg)) != SELECTOR_OK) {
1041 handle_failure(ret, "query -m", *args, rsp);
1047 } else if (streq("-d", *args) || streq("--desktop", *args)) {
1048 if (num > 1 && *(args + 1)[0] != OPT_CHR) {
1051 if ((*args)[0] == '.') {
1053 desktop_sel = malloc(sizeof(desktop_select_t));
1054 *desktop_sel = make_desktop_select();
1055 char *desc = copy_string(*args, strlen(*args));
1056 if (!parse_desktop_modifiers(desc, desktop_sel)) {
1057 handle_failure(SELECTOR_BAD_MODIFIERS, "query -d", *args, rsp);
1062 } else if ((ret = desktop_from_desc(*args, &desktop_ref, &trg)) != SELECTOR_OK) {
1063 handle_failure(ret, "query -d", *args, rsp);
1069 } else if (streq("-n", *args) || streq("--node", *args)) {
1070 if (num > 1 && *(args + 1)[0] != OPT_CHR) {
1073 if ((*args)[0] == '.') {
1075 node_sel = malloc(sizeof(node_select_t));
1076 *node_sel = make_node_select();
1077 char *desc = copy_string(*args, strlen(*args));
1078 if (!parse_node_modifiers(desc, node_sel)) {
1079 handle_failure(SELECTOR_BAD_MODIFIERS, "query -n", *args, rsp);
1084 } else if ((ret = node_from_desc(*args, &node_ref, &trg)) != SELECTOR_OK) {
1085 handle_failure(ret, "query -n", *args, rsp);
1090 if (trg.node == NULL) {
1095 } else if (streq("--names", *args)) {
1098 fail(rsp, "query: Unknown option: '%s'.\n", *args);
1105 fail(rsp, "query: No commands given.\n");
1110 fail(rsp, "query: Multiple commands given.\n");
1114 if (dom == DOMAIN_TREE && trg.monitor == NULL) {
1115 fail(rsp, "query -T: No options given.\n");
1119 if (!print_ids && (dom == DOMAIN_NODE || dom == DOMAIN_TREE)) {
1120 fail(rsp, "query -%c: --names only applies to -M and -D.\n", dom == DOMAIN_NODE ? 'N' : 'T');
1124 if ((dom == DOMAIN_MONITOR && (desktop_sel != NULL || node_sel != NULL)) ||
1125 (dom == DOMAIN_DESKTOP && node_sel != NULL)) {
1126 fail(rsp, "query -%c: Incompatible descriptor-free constraints.\n", dom == DOMAIN_MONITOR ? 'M' : 'D');
1130 if (dom == DOMAIN_NODE) {
1131 if (query_node_ids(&monitor_ref, &desktop_ref, &node_ref, &trg, monitor_sel, desktop_sel, node_sel, rsp) < 1) {
1134 } else if (dom == DOMAIN_DESKTOP) {
1135 if (query_desktop_ids(&monitor_ref, &desktop_ref, &trg, monitor_sel, desktop_sel, print_ids ? fprint_desktop_id : fprint_desktop_name, rsp) < 1) {
1138 } else if (dom == DOMAIN_MONITOR) {
1139 if (query_monitor_ids(&monitor_ref, &trg, monitor_sel, print_ids ? fprint_monitor_id : fprint_monitor_name, rsp) < 1) {
1143 if (trg.node != NULL) {
1144 query_node(trg.node, rsp);
1145 } else if (trg.desktop != NULL) {
1146 query_desktop(trg.desktop, rsp);
1148 query_monitor(trg.monitor, rsp);
1159 void cmd_rule(char **args, int num, FILE *rsp)
1162 fail(rsp, "rule: Missing commands.\n");
1167 if (streq("-a", *args) || streq("--add", *args)) {
1170 fail(rsp, "rule %s: Not enough arguments.\n", *(args - 1));
1173 rule_t *rule = make_rule();
1174 char *class_name = strtok(*args, COL_TOK);
1175 char *instance_name = strtok(NULL, COL_TOK);
1176 char *name = strtok(NULL, COL_TOK);
1177 snprintf(rule->class_name, sizeof(rule->class_name), "%s", class_name);
1178 snprintf(rule->instance_name, sizeof(rule->instance_name), "%s", instance_name==NULL?MATCH_ANY:instance_name);
1179 snprintf(rule->name, sizeof(rule->name), "%s", name==NULL?MATCH_ANY:name);
1183 if (streq("-o", *args) || streq("--one-shot", *args)) {
1184 rule->one_shot = true;
1186 for (size_t j = 0; i < sizeof(rule->effect) && j < strlen(*args); i++, j++) {
1187 rule->effect[i] = (*args)[j];
1189 if (num > 1 && i < sizeof(rule->effect)) {
1190 rule->effect[i++] = ' ';
1195 rule->effect[MIN(i, sizeof(rule->effect) - 1)] = '\0';
1197 } else if (streq("-r", *args) || streq("--remove", *args)) {
1200 fail(rsp, "rule %s: Not enough arguments.\n", *(args - 1));
1205 if (parse_index(*args, &idx)) {
1206 remove_rule_by_index(idx - 1);
1207 } else if (streq("tail", *args)) {
1208 remove_rule(rule_tail);
1209 } else if (streq("head", *args)) {
1210 remove_rule(rule_head);
1212 remove_rule_by_cause(*args);
1216 } else if (streq("-l", *args) || streq("--list", *args)) {
1219 fail(rsp, "rule: Unknown command: '%s'.\n", *args);
1226 void cmd_wm(char **args, int num, FILE *rsp)
1229 fail(rsp, "wm: Missing commands.\n");
1234 if (streq("-d", *args) || streq("--dump-state", *args)) {
1237 } else if (streq("-l", *args) || streq("--load-state", *args)) {
1240 fail(rsp, "wm %s: Not enough arguments.\n", *(args - 1));
1243 if (!restore_state(*args)) {
1247 } else if (streq("-a", *args) || streq("--add-monitor", *args)) {
1250 fail(rsp, "wm %s: Not enough arguments.\n", *(args - 1));
1256 if (parse_rectangle(*args, &r)) {
1257 monitor_t *m = make_monitor(name, &r, XCB_NONE);
1259 add_desktop(m, make_desktop(NULL, XCB_NONE));
1261 fail(rsp, "wm %s: Invalid argument: '%s'.\n", *(args - 1), *args);
1264 } else if (streq("-O", *args) || streq("--reorder-monitors", *args)) {
1267 fail(rsp, "wm %s: Not enough arguments.\n", *(args - 1));
1270 monitor_t *m = mon_head;
1271 while (m != NULL && num > 0) {
1272 monitor_t *next = m->next;
1274 if (locate_monitor(*args, &dst)) {
1275 swap_monitors(m, dst.monitor);
1276 if (next == dst.monitor) {
1283 } else if (streq("-o", *args) || streq("--adopt-orphans", *args)) {
1285 } else if (streq("-g", *args) || streq("--get-status", *args)) {
1287 } else if (streq("-h", *args) || streq("--record-history", *args)) {
1290 fail(rsp, "wm %s: Not enough arguments.\n", *(args - 1));
1294 if (parse_bool(*args, &b)) {
1297 fail(rsp, "wm %s: Invalid argument: '%s'.\n", *(args - 1), *args);
1300 } else if (streq("-r", *args) || streq("--restart", *args)) {
1305 fail(rsp, "wm: Unknown command: '%s'.\n", *args);
1312 void cmd_subscribe(char **args, int num, FILE *rsp)
1317 char *fifo_path = NULL;
1318 subscriber_mask_t mask;
1321 if (streq("-c", *args) || streq("--count", *args)) {
1324 fail(rsp, "subscribe %s: Not enough arguments.\n", *(args - 1));
1327 if (sscanf(*args, "%i", &count) != 1 || count < 1) {
1328 fail(rsp, "subscribe %s: Invalid argument: '%s'.\n", *(args - 1), *args);
1331 } else if (streq("-f", *args) || streq("--fifo", *args)) {
1332 fifo_path = mktempfifo(FIFO_TEMPLATE);
1333 if (fifo_path == NULL) {
1334 fail(rsp, "subscribe %s: Can't create FIFO.\n", *(args - 1));
1337 } else if (parse_subscriber_mask(*args, &mask)) {
1340 fail(rsp, "subscribe: Invalid argument: '%s'.\n", *args);
1347 field = SBSC_MASK_REPORT;
1351 fprintf(rsp, "%s\n", fifo_path);
1355 stream = fopen(fifo_path, "w");
1357 if (stream == NULL) {
1358 perror("subscribe: fopen");
1359 goto free_fifo_path;
1363 subscriber_list_t *sb = make_subscriber(stream, fifo_path, field, count);
1378 void cmd_quit(char **args, int num, FILE *rsp)
1380 if (num > 0 && sscanf(*args, "%i", &exit_status) != 1) {
1381 fail(rsp, "%s: Invalid argument: '%s'.\n", *(args - 1), *args);
1387 void cmd_config(char **args, int num, FILE *rsp)
1390 fail(rsp, "config: Missing arguments.\n");
1394 coordinates_t ref = {mon, mon->desk, mon->desk->focus};
1395 coordinates_t trg = {NULL, NULL, NULL};
1397 while (num > 0 && (*args)[0] == OPT_CHR) {
1398 if (streq("-m", *args) || streq("--monitor", *args)) {
1401 fail(rsp, "config %s: Not enough arguments.\n", *(args - 1));
1405 if ((ret = monitor_from_desc(*args, &ref, &trg)) != SELECTOR_OK) {
1406 handle_failure(ret, "config -m", *args, rsp);
1409 } else if (streq("-d", *args) || streq("--desktop", *args)) {
1412 fail(rsp, "config %s: Not enough arguments.\n", *(args - 1));
1416 if ((ret = desktop_from_desc(*args, &ref, &trg)) != SELECTOR_OK) {
1417 handle_failure(ret, "config -d", *args, rsp);
1420 } else if (streq("-n", *args) || streq("--node", *args)) {
1423 fail(rsp, "config %s: Not enough arguments.\n", *(args - 1));
1427 if ((ret = node_from_desc(*args, &ref, &trg)) != SELECTOR_OK) {
1428 handle_failure(ret, "config -n", *args, rsp);
1432 fail(rsp, "config: Unknown option: '%s'.\n", *args);
1438 set_setting(trg, *args, *(args + 1), rsp);
1439 } else if (num == 1) {
1440 get_setting(trg, *args, rsp);
1442 fail(rsp, "config: Was expecting 1 or 2 arguments, received %i.\n", num);
1446 void set_setting(coordinates_t loc, char *name, char *value, FILE *rsp)
1448 bool colors_changed = false;
1449 #define SET_DEF_DEFMON_DEFDESK_WIN(k, v) \
1450 if (loc.node != NULL) { \
1451 for (node_t *n = first_extrema(loc.node); n != NULL; n = next_leaf(n, loc.node)) { \
1452 if (n->client != NULL) { \
1456 } else if (loc.desktop != NULL) { \
1457 loc.desktop->k = v; \
1458 for (node_t *n = first_extrema(loc.desktop->root); n != NULL; n = next_leaf(n, loc.desktop->root)) { \
1459 if (n->client != NULL) { \
1463 } else if (loc.monitor != NULL) { \
1464 loc.monitor->k = v; \
1465 for (desktop_t *d = loc.monitor->desk_head; d != NULL; d = d->next) { \
1467 for (node_t *n = first_extrema(d->root); n != NULL; n = next_leaf(n, d->root)) { \
1468 if (n->client != NULL) { \
1475 for (monitor_t *m = mon_head; m != NULL; m = m->next) { \
1477 for (desktop_t *d = m->desk_head; d != NULL; d = d->next) { \
1479 for (node_t *n = first_extrema(d->root); n != NULL; n = next_leaf(n, d->root)) { \
1480 if (n->client != NULL) { \
1487 if (streq("border_width", name)) {
1489 if (sscanf(value, "%u", &bw) != 1) {
1490 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1493 SET_DEF_DEFMON_DEFDESK_WIN(border_width, bw)
1494 #undef SET_DEF_DEFMON_DEFDESK_WIN
1495 #define SET_DEF_DEFMON_DESK(k, v) \
1496 if (loc.desktop != NULL) { \
1497 loc.desktop->k = v; \
1498 } else if (loc.monitor != NULL) { \
1499 loc.monitor->k = v; \
1500 for (desktop_t *d = loc.monitor->desk_head; d != NULL; d = d->next) { \
1505 for (monitor_t *m = mon_head; m != NULL; m = m->next) { \
1507 for (desktop_t *d = m->desk_head; d != NULL; d = d->next) { \
1512 } else if (streq("window_gap", name)) {
1514 if (sscanf(value, "%i", &wg) != 1) {
1518 SET_DEF_DEFMON_DESK(window_gap, wg)
1519 #undef SET_DEF_DEFMON_DESK
1520 #define SET_DEF_MON_DESK(k, v) \
1521 if (loc.desktop != NULL) { \
1522 loc.desktop->k = v; \
1523 } else if (loc.monitor != NULL) { \
1524 loc.monitor->k = v; \
1527 for (monitor_t *m = mon_head; m != NULL; m = m->next) { \
1531 } else if (streq("top_padding", name)) {
1533 if (sscanf(value, "%i", &tp) != 1) {
1534 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1537 SET_DEF_MON_DESK(padding.top, tp)
1538 } else if (streq("right_padding", name)) {
1540 if (sscanf(value, "%i", &rp) != 1) {
1541 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1544 SET_DEF_MON_DESK(padding.right, rp)
1545 } else if (streq("bottom_padding", name)) {
1547 if (sscanf(value, "%i", &bp) != 1) {
1548 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1551 SET_DEF_MON_DESK(padding.bottom, bp)
1552 } else if (streq("left_padding", name)) {
1554 if (sscanf(value, "%i", &lp) != 1) {
1555 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1558 SET_DEF_MON_DESK(padding.left, lp)
1559 #undef SET_DEF_MON_DESK
1560 } else if (streq("top_monocle_padding", name)) {
1561 if (sscanf(value, "%i", &monocle_padding.top) != 1) {
1562 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1564 } else if (streq("right_monocle_padding", name)) {
1565 if (sscanf(value, "%i", &monocle_padding.right) != 1) {
1566 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1568 } else if (streq("bottom_monocle_padding", name)) {
1569 if (sscanf(value, "%i", &monocle_padding.bottom) != 1) {
1570 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1572 } else if (streq("left_monocle_padding", name)) {
1573 if (sscanf(value, "%i", &monocle_padding.left) != 1) {
1574 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1576 #define SET_STR(s) \
1577 } else if (streq(#s, name)) { \
1578 if (snprintf(s, sizeof(s), "%s", value) < 0) { \
1582 SET_STR(external_rules_command)
1583 SET_STR(status_prefix)
1585 } else if (streq("split_ratio", name)) {
1587 if (sscanf(value, "%lf", &r) == 1 && r > 0 && r < 1) {
1590 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value); \
1594 #define SET_COLOR(s) \
1595 } else if (streq(#s, name)) { \
1596 if (!is_hex_color(value)) { \
1597 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value); \
1600 snprintf(s, sizeof(s), "%s", value); \
1601 colors_changed = true; \
1603 SET_COLOR(normal_border_color)
1604 SET_COLOR(active_border_color)
1605 SET_COLOR(focused_border_color)
1606 SET_COLOR(presel_feedback_color)
1608 } else if (streq("initial_polarity", name)) {
1610 if (parse_child_polarity(value, &p)) {
1611 initial_polarity = p;
1613 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1616 } else if (streq("automatic_scheme", name)) {
1617 automatic_scheme_t a;
1618 if (parse_automatic_scheme(value, &a)) {
1619 automatic_scheme = a;
1621 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1624 } else if (streq("mapping_events_count", name)) {
1625 if (sscanf(value, "%" SCNi8, &mapping_events_count) != 1) {
1626 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1629 } else if (streq("directional_focus_tightness", name)) {
1631 if (parse_tightness(value, &p)) {
1632 directional_focus_tightness = p;
1634 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1637 } else if (streq("ignore_ewmh_fullscreen", name)) {
1638 state_transition_t m;
1639 if (parse_state_transition(value, &m)) {
1640 ignore_ewmh_fullscreen = m;
1642 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1645 } else if (streq("pointer_modifier", name)) {
1646 if (parse_modifier_mask(value, &pointer_modifier)) {
1650 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1653 } else if (streq("pointer_motion_interval", name)) {
1654 if (sscanf(value, "%u", &pointer_motion_interval) != 1) {
1655 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1658 } else if (streq("pointer_action1", name) ||
1659 streq("pointer_action2", name) ||
1660 streq("pointer_action3", name)) {
1661 int index = name[14] - '1';
1662 if (parse_pointer_action(value, &pointer_actions[index])) {
1666 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1669 } else if (streq("click_to_focus", name)) {
1670 if (parse_button_index(value, &click_to_focus)) {
1674 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1677 } else if (streq("single_monocle", name)) {
1679 if (parse_bool(value, &b)) {
1680 if (b == single_monocle) {
1685 for (monitor_t *m = mon_head; m != NULL; m = m->next) {
1686 for (desktop_t *d = m->desk_head; d != NULL; d = d->next) {
1687 layout_t l = (single_monocle && tiled_count(d->root, true) <= 1) ? LAYOUT_MONOCLE : d->user_layout;
1688 set_layout(m, d, l, false);
1692 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1695 } else if (streq("focus_follows_pointer", name)) {
1697 if (parse_bool(value, &b)) {
1698 if (b == focus_follows_pointer) {
1702 focus_follows_pointer = b;
1703 for (monitor_t *m = mon_head; m != NULL; m = m->next) {
1704 if (focus_follows_pointer) {
1705 window_show(m->root);
1707 window_hide(m->root);
1709 for (desktop_t *d = m->desk_head; d != NULL; d = d->next) {
1710 listen_enter_notify(d->root, focus_follows_pointer);
1713 if (focus_follows_pointer) {
1714 update_motion_recorder();
1716 disable_motion_recorder();
1720 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1723 #define SET_BOOL(s) \
1724 } else if (streq(#s, name)) { \
1725 if (!parse_bool(value, &s)) { \
1726 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value); \
1729 SET_BOOL(presel_feedback)
1730 SET_BOOL(borderless_monocle)
1731 SET_BOOL(gapless_monocle)
1732 SET_BOOL(borderless_singleton)
1733 SET_BOOL(swallow_first_click)
1734 SET_BOOL(pointer_follows_focus)
1735 SET_BOOL(pointer_follows_monitor)
1736 SET_BOOL(ignore_ewmh_focus)
1737 SET_BOOL(ignore_ewmh_struts)
1738 SET_BOOL(center_pseudo_tiled)
1739 SET_BOOL(honor_size_hints)
1740 SET_BOOL(removal_adjustment)
1742 #define SET_MON_BOOL(s) \
1743 } else if (streq(#s, name)) { \
1744 if (!parse_bool(value, &s)) { \
1745 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value); \
1749 update_monitors(); \
1751 SET_MON_BOOL(remove_disabled_monitors)
1752 SET_MON_BOOL(remove_unplugged_monitors)
1753 SET_MON_BOOL(merge_overlapping_monitors)
1756 fail(rsp, "config: Unknown setting: '%s'.\n", name);
1760 for (monitor_t *m = mon_head; m != NULL; m = m->next) {
1761 for (desktop_t *d = m->desk_head; d != NULL; d = d->next) {
1763 if (colors_changed) {
1764 update_colors_in(d->root, d, m);
1770 void get_setting(coordinates_t loc, char *name, FILE* rsp)
1772 if (streq("split_ratio", name)) {
1773 fprintf(rsp, "%lf", split_ratio);
1774 } else if (streq("border_width", name)) {
1775 if (loc.node != NULL) {
1776 for (node_t *n = first_extrema(loc.node); n != NULL; n = next_leaf(n, loc.node)) {
1777 if (n->client != NULL) {
1778 fprintf(rsp, "%u", n->client->border_width);
1782 } else if (loc.desktop != NULL) {
1783 fprintf(rsp, "%u", loc.desktop->border_width);
1784 } else if (loc.monitor != NULL) {
1785 fprintf(rsp, "%u", loc.monitor->border_width);
1787 fprintf(rsp, "%u", border_width);
1789 } else if (streq("window_gap", name)) {
1790 if (loc.desktop != NULL) {
1791 fprintf(rsp, "%i", loc.desktop->window_gap);
1792 } else if (loc.monitor != NULL) {
1793 fprintf(rsp, "%i", loc.monitor->window_gap);
1795 fprintf(rsp, "%i", window_gap);
1797 #define GET_DEF_MON_DESK(k) \
1798 if (loc.desktop != NULL) { \
1799 fprintf(rsp, "%i", loc.desktop->k); \
1800 } else if (loc.monitor != NULL) { \
1801 fprintf(rsp, "%i", loc.monitor->k); \
1803 fprintf(rsp, "%i", k); \
1805 } else if (streq("top_padding", name)) {
1806 GET_DEF_MON_DESK(padding.top)
1807 } else if (streq("right_padding", name)) {
1808 GET_DEF_MON_DESK(padding.right)
1809 } else if (streq("bottom_padding", name)) {
1810 GET_DEF_MON_DESK(padding.bottom)
1811 } else if (streq("left_padding", name)) {
1812 GET_DEF_MON_DESK(padding.left)
1813 #undef GET_DEF_MON_DESK
1814 } else if (streq("top_monocle_padding", name)) {
1815 fprintf(rsp, "%i", monocle_padding.top);
1816 } else if (streq("right_monocle_padding", name)) {
1817 fprintf(rsp, "%i", monocle_padding.right);
1818 } else if (streq("bottom_monocle_padding", name)) {
1819 fprintf(rsp, "%i", monocle_padding.bottom);
1820 } else if (streq("left_monocle_padding", name)) {
1821 fprintf(rsp, "%i", monocle_padding.left);
1822 } else if (streq("external_rules_command", name)) {
1823 fprintf(rsp, "%s", external_rules_command);
1824 } else if (streq("status_prefix", name)) {
1825 fprintf(rsp, "%s", status_prefix);
1826 } else if (streq("initial_polarity", name)) {
1827 fprintf(rsp, "%s", CHILD_POL_STR(initial_polarity));
1828 } else if (streq("automatic_scheme", name)) {
1829 fprintf(rsp, "%s", AUTO_SCM_STR(automatic_scheme));
1830 } else if (streq("mapping_events_count", name)) {
1831 fprintf(rsp, "%" PRIi8, mapping_events_count);
1832 } else if (streq("directional_focus_tightness", name)) {
1833 fprintf(rsp, "%s", TIGHTNESS_STR(directional_focus_tightness));
1834 } else if (streq("ignore_ewmh_fullscreen", name)) {
1835 print_ignore_request(ignore_ewmh_fullscreen, rsp);
1836 } else if (streq("pointer_modifier", name)) {
1837 print_modifier_mask(pointer_modifier, rsp);
1838 } else if (streq("click_to_focus", name)) {
1839 print_button_index(click_to_focus, rsp);
1840 } else if (streq("pointer_motion_interval", name)) {
1841 fprintf(rsp, "%u", pointer_motion_interval);
1842 } else if (streq("pointer_action1", name) ||
1843 streq("pointer_action2", name) ||
1844 streq("pointer_action3", name)) {
1845 int index = name[14] - '1';
1846 print_pointer_action(pointer_actions[index], rsp);
1847 #define GET_COLOR(s) \
1848 } else if (streq(#s, name)) { \
1849 fprintf(rsp, "%s", s);
1850 GET_COLOR(normal_border_color)
1851 GET_COLOR(active_border_color)
1852 GET_COLOR(focused_border_color)
1853 GET_COLOR(presel_feedback_color)
1855 #define GET_BOOL(s) \
1856 } else if (streq(#s, name)) { \
1857 fprintf(rsp, "%s", BOOL_STR(s));
1858 GET_BOOL(presel_feedback)
1859 GET_BOOL(borderless_monocle)
1860 GET_BOOL(gapless_monocle)
1861 GET_BOOL(single_monocle)
1862 GET_BOOL(borderless_singleton)
1863 GET_BOOL(swallow_first_click)
1864 GET_BOOL(focus_follows_pointer)
1865 GET_BOOL(pointer_follows_focus)
1866 GET_BOOL(pointer_follows_monitor)
1867 GET_BOOL(ignore_ewmh_focus)
1868 GET_BOOL(ignore_ewmh_struts)
1869 GET_BOOL(center_pseudo_tiled)
1870 GET_BOOL(honor_size_hints)
1871 GET_BOOL(removal_adjustment)
1872 GET_BOOL(remove_disabled_monitors)
1873 GET_BOOL(remove_unplugged_monitors)
1874 GET_BOOL(merge_overlapping_monitors)
1877 fail(rsp, "config: Unknown setting: '%s'.\n", name);
1883 void handle_failure(int code, char *src, char *val, FILE *rsp)
1886 case SELECTOR_BAD_DESCRIPTOR:
1887 fail(rsp, "%s: Invalid descriptor found in '%s'.\n", src, val);
1889 case SELECTOR_BAD_MODIFIERS:
1890 fail(rsp, "%s: Invalid modifier found in '%s'.\n", src, val);
1892 case SELECTOR_INVALID:
1898 void fail(FILE *rsp, char *fmt, ...)
1900 fprintf(rsp, FAILURE_MESSAGE);
1903 vfprintf(rsp, fmt, ap);