1 /* Copyright (c) 2012, Bastien Dejean
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
7 * 1. Redistributions of source code must retain the above copyright notice, this
8 * list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright notice,
10 * this list of conditions and the following disclaimer in the documentation
11 * and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
17 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
20 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
46 void handle_message(char *msg, int msg_len, FILE *rsp)
50 char **args = calloc(cap, sizeof(char *));
53 perror("Handle message: calloc");
57 for (int i = 0, j = 0; i < msg_len; i++) {
59 args[num++] = msg + j;
64 char **new = realloc(args, cap * sizeof(char *));
67 perror("Handle message: realloc");
77 fail(rsp, "No arguments given.\n");
81 char **args_orig = args;
82 process_message(args, num, rsp);
86 void process_message(char **args, int num, FILE *rsp)
88 if (streq("node", *args)) {
89 cmd_node(++args, --num, rsp);
90 } else if (streq("desktop", *args)) {
91 cmd_desktop(++args, --num, rsp);
92 } else if (streq("monitor", *args)) {
93 cmd_monitor(++args, --num, rsp);
94 } else if (streq("query", *args)) {
95 cmd_query(++args, --num, rsp);
96 } else if (streq("subscribe", *args)) {
97 cmd_subscribe(++args, --num, rsp);
99 } else if (streq("wm", *args)) {
100 cmd_wm(++args, --num, rsp);
101 } else if (streq("rule", *args)) {
102 cmd_rule(++args, --num, rsp);
103 } else if (streq("config", *args)) {
104 cmd_config(++args, --num, rsp);
105 } else if (streq("quit", *args)) {
106 cmd_quit(++args, --num, rsp);
108 fail(rsp, "Unknown domain or command: '%s'.\n", *args);
115 void cmd_node(char **args, int num, FILE *rsp)
118 fail(rsp, "node: Missing arguments.\n");
122 coordinates_t ref = {mon, mon->desk, mon->desk->focus};
123 coordinates_t trg = ref;
125 if ((*args)[0] != OPT_CHR) {
127 if ((ret = node_from_desc(*args, &ref, &trg)) == SELECTOR_OK) {
130 handle_failure(ret, "node", *args, rsp);
136 fail(rsp, "node: Missing commands.\n");
140 bool changed = false;
143 if (streq("-f", *args) || streq("--focus", *args)) {
144 coordinates_t dst = trg;
145 if (num > 1 && *(args + 1)[0] != OPT_CHR) {
148 if ((ret = node_from_desc(*args, &ref, &dst)) != SELECTOR_OK) {
149 handle_failure(ret, "node -f", *args, rsp);
153 if (dst.node == NULL || !focus_node(dst.monitor, dst.desktop, dst.node)) {
157 } else if (streq("-a", *args) || streq("--activate", *args)) {
158 coordinates_t dst = trg;
159 if (num > 1 && *(args + 1)[0] != OPT_CHR) {
162 if ((ret = node_from_desc(*args, &ref, &dst)) != SELECTOR_OK) {
163 handle_failure(ret, "node -a", *args, rsp);
167 if (dst.node == NULL || !activate_node(dst.monitor, dst.desktop, dst.node)) {
171 } else if (streq("-d", *args) || streq("--to-desktop", *args)) {
174 fail(rsp, "node %s: Not enough arguments.\n", *(args - 1));
179 if ((ret = desktop_from_desc(*args, &ref, &dst)) == SELECTOR_OK) {
181 if (num > 1 && streq("--follow", *(args+1))) {
185 if (transfer_node(trg.monitor, trg.desktop, trg.node, dst.monitor, dst.desktop, dst.desktop->focus, follow)) {
186 trg.monitor = dst.monitor;
187 trg.desktop = dst.desktop;
193 handle_failure(ret, "node -d", *args, rsp);
196 } else if (streq("-m", *args) || streq("--to-monitor", *args)) {
199 fail(rsp, "node %s: Not enough arguments.\n", *(args - 1));
204 if ((ret = monitor_from_desc(*args, &ref, &dst)) == SELECTOR_OK) {
206 if (num > 1 && streq("--follow", *(args+1))) {
210 if (transfer_node(trg.monitor, trg.desktop, trg.node, dst.monitor, dst.monitor->desk, dst.monitor->desk->focus, follow)) {
211 trg.monitor = dst.monitor;
212 trg.desktop = dst.monitor->desk;
218 handle_failure(ret, "node -m", *args, rsp);
221 } else if (streq("-n", *args) || streq("--to-node", *args)) {
224 fail(rsp, "node %s: Not enough arguments.\n", *(args - 1));
229 if ((ret = node_from_desc(*args, &ref, &dst)) == SELECTOR_OK) {
231 if (num > 1 && streq("--follow", *(args+1))) {
235 if (transfer_node(trg.monitor, trg.desktop, trg.node, dst.monitor, dst.desktop, dst.node, follow)) {
236 trg.monitor = dst.monitor;
237 trg.desktop = dst.desktop;
243 handle_failure(ret, "node -n", *args, rsp);
246 } else if (streq("-s", *args) || streq("--swap", *args)) {
249 fail(rsp, "node %s: Not enough arguments.\n", *(args - 1));
254 if ((ret = node_from_desc(*args, &ref, &dst)) == SELECTOR_OK) {
256 if (num > 1 && streq("--follow", *(args+1))) {
260 if (swap_nodes(trg.monitor, trg.desktop, trg.node, dst.monitor, dst.desktop, dst.node, follow)) {
261 trg.monitor = dst.monitor;
262 trg.desktop = dst.desktop;
268 handle_failure(ret, "node -s", *args, rsp);
271 } else if (streq("-l", *args) || streq("--layer", *args)) {
274 fail(rsp, "node %s: Not enough arguments.\n", *(args - 1));
278 if (parse_stack_layer(*args, &lyr)) {
279 if (!set_layer(trg.monitor, trg.desktop, trg.node, lyr)) {
284 fail(rsp, "node %s: Invalid argument: '%s'.\n", *(args - 1), *args);
287 } else if (streq("-t", *args) || streq("--state", *args)) {
290 fail(rsp, "node %s: Not enough arguments.\n", *(args - 1));
294 bool alternate = false;
295 if ((*args)[0] == '~') {
299 if (parse_client_state(*args, &cst)) {
300 if (alternate && trg.node != NULL && trg.node->client != NULL &&
301 trg.node->client->state == cst) {
302 cst = trg.node->client->last_state;
304 if (!set_state(trg.monitor, trg.desktop, trg.node, cst)) {
310 fail(rsp, "node %s: Invalid argument: '%s'.\n", *(args - 1), *args);
313 } else if (streq("-g", *args) || streq("--flag", *args)) {
316 fail(rsp, "node %s: Not enough arguments.\n", *(args - 1));
319 if (trg.node == NULL) {
323 char *key = strtok(*args, EQL_TOK);
324 char *val = strtok(NULL, EQL_TOK);
330 if (parse_bool(val, &b)) {
333 fail(rsp, "node %s: Invalid value for %s: '%s'.\n", *(args - 1), key, val);
337 if (streq("hidden", key)) {
338 set_hidden(trg.monitor, trg.desktop, trg.node, (a == ALTER_SET ? b : !trg.node->hidden));
340 } else if (streq("sticky", key)) {
341 set_sticky(trg.monitor, trg.desktop, trg.node, (a == ALTER_SET ? b : !trg.node->sticky));
342 } else if (streq("private", key)) {
343 set_private(trg.monitor, trg.desktop, trg.node, (a == ALTER_SET ? b : !trg.node->private));
344 } else if (streq("locked", key)) {
345 set_locked(trg.monitor, trg.desktop, trg.node, (a == ALTER_SET ? b : !trg.node->locked));
346 } else if (streq("marked", key)) {
347 set_marked(trg.monitor, trg.desktop, trg.node, (a == ALTER_SET ? b : !trg.node->marked));
349 fail(rsp, "node %s: Invalid key: '%s'.\n", *(args - 1), key);
352 } else if (streq("-p", *args) || streq("--presel-dir", *args)) {
355 fail(rsp, "node %s: Not enough arguments.\n", *(args - 1));
358 if (trg.node == NULL || trg.node->vacant) {
362 if (streq("cancel", *args)) {
363 cancel_presel(trg.monitor, trg.desktop, trg.node);
365 bool alternate = false;
366 if ((*args)[0] == '~') {
371 if (parse_direction(*args, &dir)) {
372 if (alternate && trg.node->presel != NULL && trg.node->presel->split_dir == dir) {
373 cancel_presel(trg.monitor, trg.desktop, trg.node);
375 presel_dir(trg.monitor, trg.desktop, trg.node, dir);
376 if (!IS_RECEPTACLE(trg.node)) {
377 draw_presel_feedback(trg.monitor, trg.desktop, trg.node);
381 fail(rsp, "node %s: Invalid argument: '%s%s'.\n", *(args - 1), alternate?"~":"", *args);
385 } else if (streq("-o", *args) || streq("--presel-ratio", *args)) {
388 fail(rsp, "node %s: Not enough arguments.\n", *(args - 1));
391 if (trg.node == NULL || trg.node->vacant) {
396 if (sscanf(*args, "%lf", &rat) != 1 || rat <= 0 || rat >= 1) {
397 fail(rsp, "node %s: Invalid argument: '%s'.\n", *(args - 1), *args);
400 presel_ratio(trg.monitor, trg.desktop, trg.node, rat);
401 draw_presel_feedback(trg.monitor, trg.desktop, trg.node);
403 } else if (streq("-v", *args) || streq("--move", *args)) {
406 fail(rsp, "node %s: Not enough arguments.\n", *(args - 1));
410 if (sscanf(*args, "%i", &dx) == 1) {
412 if (sscanf(*args, "%i", &dy) == 1) {
413 if (!move_client(&trg, dx, dy)) {
418 fail(rsp, "node %s: Invalid dy argument: '%s'.\n", *(args - 3), *args);
422 fail(rsp, "node %s: Invalid dx argument: '%s'.\n", *(args - 2), *args);
425 } else if (streq("-z", *args) || streq("--resize", *args)) {
428 fail(rsp, "node %s: Not enough arguments.\n", *(args - 1));
432 if (parse_resize_handle(*args, &rh)) {
435 if (sscanf(*args, "%i", &dx) == 1) {
437 if (sscanf(*args, "%i", &dy) == 1) {
438 if (!resize_client(&trg, rh, dx, dy, true)) {
443 fail(rsp, "node %s: Invalid dy argument: '%s'.\n", *(args - 3), *args);
447 fail(rsp, "node %s: Invalid dx argument: '%s'.\n", *(args - 2), *args);
451 fail(rsp, "node %s: Invalid resize handle argument: '%s'.\n", *(args - 1), *args);
454 } else if (streq("-r", *args) || streq("--ratio", *args)) {
457 fail(rsp, "node %s: Not enough arguments.\n", *(args - 1));
460 if (trg.node == NULL) {
464 if ((*args)[0] == '+' || (*args)[0] == '-') {
466 if (sscanf(*args, "%f", &delta) == 1) {
467 double rat = trg.node->split_ratio;
468 if (delta > -1 && delta < 1) {
471 int max = (trg.node->split_type == TYPE_HORIZONTAL ? trg.node->rectangle.height : trg.node->rectangle.width);
472 rat = ((max * rat) + delta) / max;
474 if (rat > 0 && rat < 1) {
475 set_ratio(trg.node, rat);
481 fail(rsp, "node %s: Invalid argument: '%s'.\n", *(args - 1), *args);
486 if (sscanf(*args, "%lf", &rat) == 1 && rat > 0 && rat < 1) {
487 set_ratio(trg.node, rat);
489 fail(rsp, "node %s: Invalid argument: '%s'.\n", *(args - 1), *args);
494 } else if (streq("-F", *args) || streq("--flip", *args)) {
497 fail(rsp, "node %s: Not enough arguments.\n", *(args - 1));
500 if (trg.node == NULL) {
505 if (parse_flip(*args, &flp)) {
506 flip_tree(trg.node, flp);
512 } else if (streq("-R", *args) || streq("--rotate", *args)) {
515 fail(rsp, "node %s: Not enough arguments.\n", *(args - 1));
518 if (trg.node == NULL) {
523 if (parse_degree(*args, °)) {
524 rotate_tree(trg.node, deg);
527 fail(rsp, "node %s: Invalid argument: '%s'.\n", *(args - 1), *args);
530 } else if (streq("-E", *args) || streq("--equalize", *args)) {
531 if (trg.node == NULL) {
535 equalize_tree(trg.node);
537 } else if (streq("-B", *args) || streq("--balance", *args)) {
538 if (trg.node == NULL) {
542 balance_tree(trg.node);
544 } else if (streq("-C", *args) || streq("--circulate", *args)) {
547 fail(rsp, "node %s: Not enough arguments.\n", *(args - 1));
550 if (trg.node == NULL) {
555 if (parse_circulate_direction(*args, &cir)) {
556 circulate_leaves(trg.monitor, trg.desktop, trg.node, cir);
559 fail(rsp, "node %s: Invalid argument: '%s'.\n", *(args - 1), *args);
562 } else if (streq("-i", *args) || streq("--insert-receptacle", *args)) {
563 insert_receptacle(trg.monitor, trg.desktop, trg.node);
565 } else if (streq("-c", *args) || streq("--close", *args)) {
567 fail(rsp, "node %s: Trailing commands.\n", *args);
570 if (trg.node == NULL || locked_count(trg.node) > 0) {
574 close_node(trg.node);
576 } else if (streq("-k", *args) || streq("--kill", *args)) {
578 fail(rsp, "node %s: Trailing commands.\n", *args);
581 if (trg.node == NULL) {
585 kill_node(trg.monitor, trg.desktop, trg.node);
589 fail(rsp, "node: Unknown command: '%s'.\n", *args);
597 arrange(trg.monitor, trg.desktop);
601 void cmd_desktop(char **args, int num, FILE *rsp)
604 fail(rsp, "desktop: Missing arguments.\n");
608 coordinates_t ref = {mon, mon->desk, NULL};
609 coordinates_t trg = ref;
611 if ((*args)[0] != OPT_CHR) {
613 if ((ret = desktop_from_desc(*args, &ref, &trg)) == SELECTOR_OK) {
616 handle_failure(ret, "desktop", *args, rsp);
622 fail(rsp, "desktop: Missing commands.\n");
626 bool changed = false;
629 if (streq("-f", *args) || streq("--focus", *args)) {
630 coordinates_t dst = trg;
631 if (num > 1 && *(args + 1)[0] != OPT_CHR) {
634 if ((ret = desktop_from_desc(*args, &ref, &dst)) != SELECTOR_OK) {
635 handle_failure(ret, "desktop -f", *args, rsp);
639 focus_node(dst.monitor, dst.desktop, NULL);
640 } else if (streq("-a", *args) || streq("--activate", *args)) {
641 coordinates_t dst = trg;
642 if (num > 1 && *(args + 1)[0] != OPT_CHR) {
645 if ((ret = desktop_from_desc(*args, &ref, &dst)) != SELECTOR_OK) {
646 handle_failure(ret, "desktop -a", *args, rsp);
650 if (activate_desktop(dst.monitor, dst.desktop)) {
651 activate_node(dst.monitor, dst.desktop, NULL);
656 } else if (streq("-m", *args) || streq("--to-monitor", *args)) {
659 fail(rsp, "desktop %s: Not enough arguments.\n", *(args - 1));
662 if (trg.monitor->desk_head == trg.monitor->desk_tail) {
668 if ((ret = monitor_from_desc(*args, &ref, &dst)) == SELECTOR_OK) {
670 if (num > 1 && streq("--follow", *(args+1))) {
674 if (transfer_desktop(trg.monitor, dst.monitor, trg.desktop, follow)) {
675 trg.monitor = dst.monitor;
681 handle_failure(ret, "desktop -m", *args, rsp);
684 } else if (streq("-s", *args) || streq("--swap", *args)) {
687 fail(rsp, "desktop %s: Not enough arguments.\n", *(args - 1));
692 if ((ret = desktop_from_desc(*args, &ref, &dst)) == SELECTOR_OK) {
694 if (num > 1 && streq("--follow", *(args+1))) {
698 if (swap_desktops(trg.monitor, trg.desktop, dst.monitor, dst.desktop, follow)) {
699 trg.monitor = dst.monitor;
705 handle_failure(ret, "desktop -s", *args, rsp);
708 } else if (streq("-b", *args) || streq("--bubble", *args)) {
711 fail(rsp, "desktop %s: Not enough arguments.\n", *(args - 1));
715 if (parse_cycle_direction(*args, &cyc)) {
716 desktop_t *d = trg.desktop;
717 if (cyc == CYCLE_PREV) {
718 if (d->prev == NULL) {
719 while (d->next != NULL) {
720 swap_desktops(trg.monitor, d, trg.monitor, d->next, false);
723 swap_desktops(trg.monitor, d, trg.monitor, d->prev, false);
726 if (d->next == NULL) {
727 while (d->prev != NULL) {
728 swap_desktops(trg.monitor, d, trg.monitor, d->prev, false);
731 swap_desktops(trg.monitor, d, trg.monitor, d->next, false);
735 fail(rsp, "desktop %s: Invalid argument: '%s'.\n", *(args - 1), *args);
738 } else if (streq("-l", *args) || streq("--layout", *args)) {
741 fail(rsp, "desktop %s: Not enough arguments.\n", *(args - 1));
747 if (parse_cycle_direction(*args, &cyc)) {
748 ret = set_layout(trg.monitor, trg.desktop, (trg.desktop->layout + 1) % 2);
749 } else if (parse_layout(*args, &lyt)) {
750 ret = set_layout(trg.monitor, trg.desktop, lyt);
752 fail(rsp, "desktop %s: Invalid argument: '%s'.\n", *(args - 1), *args);
759 } else if (streq("-n", *args) || streq("--rename", *args)) {
762 fail(rsp, "desktop %s: Not enough arguments.\n", *(args - 1));
765 rename_desktop(trg.monitor, trg.desktop, *args);
766 } else if (streq("-r", *args) || streq("--remove", *args)) {
768 fail(rsp, "desktop %s: Trailing commands.\n", *args);
771 if (trg.monitor->desk_head != trg.monitor->desk_tail) {
772 desktop_t *fallback = trg.desktop->prev == NULL ?
775 merge_desktops(trg.monitor, trg.desktop, trg.monitor, fallback);
776 remove_desktop(trg.monitor, trg.desktop);
783 fail(rsp, "desktop: Unknown command: '%s'.\n", *args);
790 arrange(trg.monitor, trg.desktop);
794 void cmd_monitor(char **args, int num, FILE *rsp)
797 fail(rsp, "monitor: Missing arguments.\n");
801 coordinates_t ref = {mon, NULL, NULL};
802 coordinates_t trg = ref;
804 if ((*args)[0] != OPT_CHR) {
806 if ((ret = monitor_from_desc(*args, &ref, &trg)) == SELECTOR_OK) {
809 handle_failure(ret, "monitor", *args, rsp);
815 fail(rsp, "monitor: Missing commands.\n");
820 if (streq("-f", *args) || streq("--focus", *args)) {
821 coordinates_t dst = trg;
822 if (num > 1 && *(args + 1)[0] != OPT_CHR) {
825 if ((ret = monitor_from_desc(*args, &ref, &dst)) != SELECTOR_OK) {
826 handle_failure(ret, "monitor -f", *args, rsp);
831 focus_node(dst.monitor, NULL, NULL);
832 } else if (streq("-s", *args) || streq("--swap", *args)) {
835 fail(rsp, "monitor %s: Not enough arguments.\n", *(args - 1));
840 if ((ret = monitor_from_desc(*args, &ref, &dst)) == SELECTOR_OK) {
841 if (!swap_monitors(trg.monitor, dst.monitor)) {
846 handle_failure(ret, "monitor -s", *args, rsp);
849 } else if (streq("-d", *args) || streq("--reset-desktops", *args)) {
852 fail(rsp, "monitor %s: Not enough arguments.\n", *(args - 1));
855 desktop_t *d = trg.monitor->desk_head;
856 while (num > 0 && d != NULL) {
857 rename_desktop(trg.monitor, d, *args);
861 put_status(SBSC_MASK_REPORT);
863 add_desktop(trg.monitor, make_desktop(*args, XCB_NONE));
867 desktop_t *next = d->next;
868 if (d == mon->desk) {
869 focus_node(trg.monitor, d->prev, d->prev->focus);
871 merge_desktops(trg.monitor, d, mon, mon->desk);
872 remove_desktop(trg.monitor, d);
875 } else if (streq("-a", *args) || streq("--add-desktops", *args)) {
878 fail(rsp, "monitor %s: Not enough arguments.\n", *(args - 1));
882 add_desktop(trg.monitor, make_desktop(*args, XCB_NONE));
885 } else if (streq("-r", *args) || streq("--remove", *args)) {
887 fail(rsp, "monitor %s: Trailing commands.\n", *args);
890 if (mon_head == mon_tail) {
894 remove_monitor(trg.monitor);
896 } else if (streq("-o", *args) || streq("--reorder-desktops", *args)) {
899 fail(rsp, "monitor %s: Not enough arguments.\n", *(args - 1));
902 desktop_t *d = trg.monitor->desk_head;
903 while (d != NULL && num > 0) {
904 desktop_t *next = d->next;
906 if (locate_desktop(*args, &dst) && dst.monitor == trg.monitor) {
907 swap_desktops(trg.monitor, d, dst.monitor, dst.desktop, false);
908 if (next == dst.desktop) {
915 } else if (streq("-g", *args) || streq("--rectangle", *args)) {
918 fail(rsp, "monitor %s: Not enough arguments.\n", *(args - 1));
922 if (parse_rectangle(*args, &r)) {
923 update_root(trg.monitor, &r);
925 fail(rsp, "monitor %s: Invalid argument: '%s'.\n", *(args - 1), *args);
928 } else if (streq("-n", *args) || streq("--rename", *args)) {
931 fail(rsp, "monitor %s: Not enough arguments.\n", *(args - 1));
934 rename_monitor(trg.monitor, *args);
936 fail(rsp, "monitor: Unknown command: '%s'.\n", *args);
943 void cmd_query(char **args, int num, FILE *rsp)
945 coordinates_t ref = {mon, mon->desk, mon->desk->focus};
946 coordinates_t trg = {NULL, NULL, NULL};
947 monitor_select_t *monitor_sel = NULL;
948 desktop_select_t *desktop_sel = NULL;
949 node_select_t *node_sel = NULL;
950 domain_t dom = DOMAIN_TREE;
951 bool print_ids = true;
955 fail(rsp, "query: Missing arguments.\n");
960 if (streq("-T", *args) || streq("--tree", *args)) {
961 dom = DOMAIN_TREE, d++;
962 } else if (streq("-M", *args) || streq("--monitors", *args)) {
963 dom = DOMAIN_MONITOR, d++;
964 if (num > 1 && *(args + 1)[0] != OPT_CHR) {
967 coordinates_t tmp = ref;
968 if ((ret = monitor_from_desc(*args, &tmp, &ref)) != SELECTOR_OK) {
969 handle_failure(ret, "query -M", *args, rsp);
973 } else if (streq("-D", *args) || streq("--desktops", *args)) {
974 dom = DOMAIN_DESKTOP, d++;
975 if (num > 1 && *(args + 1)[0] != OPT_CHR) {
978 coordinates_t tmp = ref;
979 if ((ret = desktop_from_desc(*args, &tmp, &ref)) != SELECTOR_OK) {
980 handle_failure(ret, "query -D", *args, rsp);
984 } else if (streq("-N", *args) || streq("--nodes", *args)) {
985 dom = DOMAIN_NODE, d++;
986 if (num > 1 && *(args + 1)[0] != OPT_CHR) {
989 coordinates_t tmp = ref;
990 if ((ret = node_from_desc(*args, &tmp, &ref)) != SELECTOR_OK) {
991 handle_failure(ret, "query -N", *args, rsp);
995 } else if (streq("-m", *args) || streq("--monitor", *args)) {
996 if (num > 1 && *(args + 1)[0] != OPT_CHR) {
999 if ((*args)[0] == '.') {
1001 monitor_sel = malloc(sizeof(monitor_select_t));
1002 *monitor_sel = make_monitor_select();
1003 char *desc = copy_string(*args, strlen(*args));
1004 if (!parse_monitor_modifiers(desc, monitor_sel)) {
1005 handle_failure(SELECTOR_BAD_MODIFIERS, "query -m", *args, rsp);
1010 } else if ((ret = monitor_from_desc(*args, &ref, &trg)) != SELECTOR_OK) {
1011 handle_failure(ret, "query -m", *args, rsp);
1015 trg.monitor = ref.monitor;
1017 } else if (streq("-d", *args) || streq("--desktop", *args)) {
1018 if (num > 1 && *(args + 1)[0] != OPT_CHR) {
1021 if ((*args)[0] == '.') {
1023 desktop_sel = malloc(sizeof(desktop_select_t));
1024 *desktop_sel = make_desktop_select();
1025 char *desc = copy_string(*args, strlen(*args));
1026 if (!parse_desktop_modifiers(desc, desktop_sel)) {
1027 handle_failure(SELECTOR_BAD_MODIFIERS, "query -d", *args, rsp);
1032 } else if ((ret = desktop_from_desc(*args, &ref, &trg)) != SELECTOR_OK) {
1033 handle_failure(ret, "query -d", *args, rsp);
1037 trg.monitor = ref.monitor;
1038 trg.desktop = ref.desktop;
1040 } else if (streq("-n", *args) || streq("--node", *args)) {
1041 if (num > 1 && *(args + 1)[0] != OPT_CHR) {
1044 if ((*args)[0] == '.') {
1046 node_sel = malloc(sizeof(node_select_t));
1047 *node_sel = make_node_select();
1048 char *desc = copy_string(*args, strlen(*args));
1049 if (!parse_node_modifiers(desc, node_sel)) {
1050 handle_failure(SELECTOR_BAD_MODIFIERS, "query -n", *args, rsp);
1055 } else if ((ret = node_from_desc(*args, &ref, &trg)) != SELECTOR_OK) {
1056 handle_failure(ret, "query -n", *args, rsp);
1061 if (ref.node == NULL) {
1066 } else if (streq("--names", *args)) {
1069 fail(rsp, "query: Unknown option: '%s'.\n", *args);
1076 fail(rsp, "query: No commands given.\n");
1081 fail(rsp, "query: Multiple commands given.\n");
1085 if (dom == DOMAIN_TREE && trg.monitor == NULL) {
1086 fail(rsp, "query -T: No options given.\n");
1090 if (!print_ids && (dom == DOMAIN_NODE || dom == DOMAIN_TREE)) {
1091 fail(rsp, "query -%c: --names only applies to -M and -D.\n", dom == DOMAIN_NODE ? 'N' : 'T');
1095 if (dom == DOMAIN_NODE) {
1096 if (query_node_ids(&ref, &trg, node_sel, rsp) < 1) {
1099 } else if (dom == DOMAIN_DESKTOP) {
1100 if (query_desktop_ids(&ref, &trg, desktop_sel, print_ids ? fprint_desktop_id : fprint_desktop_name, rsp) < 1) {
1103 } else if (dom == DOMAIN_MONITOR) {
1104 if (query_monitor_ids(&ref, &trg, monitor_sel, print_ids ? fprint_monitor_id : fprint_monitor_name, rsp) < 1) {
1108 if (trg.node != NULL) {
1109 query_node(trg.node, rsp);
1110 } else if (trg.desktop != NULL) {
1111 query_desktop(trg.desktop, rsp);
1113 query_monitor(trg.monitor, rsp);
1124 void cmd_rule(char **args, int num, FILE *rsp)
1127 fail(rsp, "rule: Missing commands.\n");
1132 if (streq("-a", *args) || streq("--add", *args)) {
1135 fail(rsp, "rule %s: Not enough arguments.\n", *(args - 1));
1138 rule_t *rule = make_rule();
1139 char *class_name = strtok(*args, COL_TOK);
1140 char *instance_name = strtok(NULL, COL_TOK);
1141 snprintf(rule->class_name, sizeof(rule->class_name), "%s", class_name);
1142 snprintf(rule->instance_name, sizeof(rule->instance_name), "%s", instance_name==NULL?MATCH_ANY:instance_name);
1146 if (streq("-o", *args) || streq("--one-shot", *args)) {
1147 rule->one_shot = true;
1149 for (size_t j = 0; i < sizeof(rule->effect) && j < strlen(*args); i++, j++) {
1150 rule->effect[i] = (*args)[j];
1152 if (num > 1 && i < sizeof(rule->effect)) {
1153 rule->effect[i++] = ' ';
1158 rule->effect[MIN(i, sizeof(rule->effect) - 1)] = '\0';
1160 } else if (streq("-r", *args) || streq("--remove", *args)) {
1163 fail(rsp, "rule %s: Not enough arguments.\n", *(args - 1));
1168 if (parse_index(*args, &idx)) {
1169 remove_rule_by_index(idx - 1);
1170 } else if (streq("tail", *args)) {
1171 remove_rule(rule_tail);
1172 } else if (streq("head", *args)) {
1173 remove_rule(rule_head);
1175 remove_rule_by_cause(*args);
1179 } else if (streq("-l", *args) || streq("--list", *args)) {
1182 fail(rsp, "rule: Unknown command: '%s'.\n", *args);
1189 void cmd_wm(char **args, int num, FILE *rsp)
1192 fail(rsp, "wm: Missing commands.\n");
1197 if (streq("-d", *args) || streq("--dump-state", *args)) {
1200 } else if (streq("-l", *args) || streq("--load-state", *args)) {
1203 fail(rsp, "wm %s: Not enough arguments.\n", *(args - 1));
1206 if (!restore_state(*args)) {
1210 } else if (streq("-a", *args) || streq("--add-monitor", *args)) {
1213 fail(rsp, "wm %s: Not enough arguments.\n", *(args - 1));
1219 if (parse_rectangle(*args, &r)) {
1220 monitor_t *m = make_monitor(name, &r, XCB_NONE);
1222 add_desktop(m, make_desktop(NULL, XCB_NONE));
1224 fail(rsp, "wm %s: Invalid argument: '%s'.\n", *(args - 1), *args);
1227 } else if (streq("-O", *args) || streq("--reorder-monitors", *args)) {
1230 fail(rsp, "wm %s: Not enough arguments.\n", *(args - 1));
1233 monitor_t *m = mon_head;
1234 while (m != NULL && num > 0) {
1235 monitor_t *next = m->next;
1237 if (locate_monitor(*args, &dst)) {
1238 swap_monitors(m, dst.monitor);
1239 if (next == dst.monitor) {
1246 } else if (streq("-o", *args) || streq("--adopt-orphans", *args)) {
1248 } else if (streq("-g", *args) || streq("--get-status", *args)) {
1250 } else if (streq("-h", *args) || streq("--record-history", *args)) {
1253 fail(rsp, "wm %s: Not enough arguments.\n", *(args - 1));
1257 if (parse_bool(*args, &b)) {
1260 fail(rsp, "wm %s: Invalid argument: '%s'.\n", *(args - 1), *args);
1263 } else if (streq("-r", *args) || streq("--restart", *args)) {
1268 fail(rsp, "wm: Unknown command: '%s'.\n", *args);
1275 void cmd_subscribe(char **args, int num, FILE *rsp)
1280 char *fifo_path = NULL;
1281 subscriber_mask_t mask;
1284 if (streq("-c", *args) || streq("--count", *args)) {
1287 fail(rsp, "subscribe %s: Not enough arguments.\n", *(args - 1));
1290 if (sscanf(*args, "%i", &count) != 1 || count < 1) {
1291 fail(rsp, "subscribe %s: Invalid argument: '%s'.\n", *(args - 1), *args);
1294 } else if (streq("-f", *args) || streq("--fifo", *args)) {
1295 fifo_path = mktempfifo(FIFO_TEMPLATE);
1296 if (fifo_path == NULL) {
1297 fail(rsp, "subscribe %s: Can't create FIFO.\n", *(args - 1));
1300 } else if (parse_subscriber_mask(*args, &mask)) {
1303 fail(rsp, "subscribe: Invalid argument: '%s'.\n", *args);
1310 field = SBSC_MASK_REPORT;
1314 fprintf(rsp, "%s\n", fifo_path);
1318 stream = fopen(fifo_path, "w");
1320 if (stream == NULL) {
1321 perror("subscribe: fopen");
1322 goto free_fifo_path;
1326 subscriber_list_t *sb = make_subscriber(stream, fifo_path, field, count);
1341 void cmd_quit(char **args, int num, FILE *rsp)
1343 if (num > 0 && sscanf(*args, "%i", &exit_status) != 1) {
1344 fail(rsp, "%s: Invalid argument: '%s'.\n", *(args - 1), *args);
1350 void cmd_config(char **args, int num, FILE *rsp)
1353 fail(rsp, "config: Missing arguments.\n");
1357 coordinates_t ref = {mon, mon->desk, mon->desk->focus};
1358 coordinates_t trg = {NULL, NULL, NULL};
1360 while (num > 0 && (*args)[0] == OPT_CHR) {
1361 if (streq("-m", *args) || streq("--monitor", *args)) {
1364 fail(rsp, "config %s: Not enough arguments.\n", *(args - 1));
1368 if ((ret = monitor_from_desc(*args, &ref, &trg)) != SELECTOR_OK) {
1369 handle_failure(ret, "config -m", *args, rsp);
1372 } else if (streq("-d", *args) || streq("--desktop", *args)) {
1375 fail(rsp, "config %s: Not enough arguments.\n", *(args - 1));
1379 if ((ret = desktop_from_desc(*args, &ref, &trg)) != SELECTOR_OK) {
1380 handle_failure(ret, "config -d", *args, rsp);
1383 } else if (streq("-n", *args) || streq("--node", *args)) {
1386 fail(rsp, "config %s: Not enough arguments.\n", *(args - 1));
1390 if ((ret = node_from_desc(*args, &ref, &trg)) != SELECTOR_OK) {
1391 handle_failure(ret, "config -n", *args, rsp);
1395 fail(rsp, "config: Unknown option: '%s'.\n", *args);
1401 set_setting(trg, *args, *(args + 1), rsp);
1402 } else if (num == 1) {
1403 get_setting(trg, *args, rsp);
1405 fail(rsp, "config: Was expecting 1 or 2 arguments, received %i.\n", num);
1409 void set_setting(coordinates_t loc, char *name, char *value, FILE *rsp)
1411 bool colors_changed = false;
1412 #define SET_DEF_DEFMON_DEFDESK_WIN(k, v) \
1413 if (loc.node != NULL) { \
1414 for (node_t *n = first_extrema(loc.node); n != NULL; n = next_leaf(n, loc.node)) { \
1415 if (n->client != NULL) { \
1419 } else if (loc.desktop != NULL) { \
1420 loc.desktop->k = v; \
1421 for (node_t *n = first_extrema(loc.desktop->root); n != NULL; n = next_leaf(n, loc.desktop->root)) { \
1422 if (n->client != NULL) { \
1426 } else if (loc.monitor != NULL) { \
1427 loc.monitor->k = v; \
1428 for (desktop_t *d = loc.monitor->desk_head; d != NULL; d = d->next) { \
1430 for (node_t *n = first_extrema(d->root); n != NULL; n = next_leaf(n, d->root)) { \
1431 if (n->client != NULL) { \
1438 for (monitor_t *m = mon_head; m != NULL; m = m->next) { \
1440 for (desktop_t *d = m->desk_head; d != NULL; d = d->next) { \
1442 for (node_t *n = first_extrema(d->root); n != NULL; n = next_leaf(n, d->root)) { \
1443 if (n->client != NULL) { \
1450 if (streq("border_width", name)) {
1452 if (sscanf(value, "%u", &bw) != 1) {
1453 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1456 SET_DEF_DEFMON_DEFDESK_WIN(border_width, bw)
1457 #undef SET_DEF_DEFMON_DEFDESK_WIN
1458 #define SET_DEF_DEFMON_DESK(k, v) \
1459 if (loc.desktop != NULL) { \
1460 loc.desktop->k = v; \
1461 } else if (loc.monitor != NULL) { \
1462 loc.monitor->k = v; \
1463 for (desktop_t *d = loc.monitor->desk_head; d != NULL; d = d->next) { \
1468 for (monitor_t *m = mon_head; m != NULL; m = m->next) { \
1470 for (desktop_t *d = m->desk_head; d != NULL; d = d->next) { \
1475 } else if (streq("window_gap", name)) {
1477 if (sscanf(value, "%i", &wg) != 1) {
1481 SET_DEF_DEFMON_DESK(window_gap, wg)
1482 #undef SET_DEF_DEFMON_DESK
1483 #define SET_DEF_MON_DESK(k, v) \
1484 if (loc.desktop != NULL) { \
1485 loc.desktop->k = v; \
1486 } else if (loc.monitor != NULL) { \
1487 loc.monitor->k = v; \
1490 for (monitor_t *m = mon_head; m != NULL; m = m->next) { \
1494 } else if (streq("top_padding", name)) {
1496 if (sscanf(value, "%i", &tp) != 1) {
1497 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1500 SET_DEF_MON_DESK(padding.top, tp)
1501 } else if (streq("right_padding", name)) {
1503 if (sscanf(value, "%i", &rp) != 1) {
1504 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1507 SET_DEF_MON_DESK(padding.right, rp)
1508 } else if (streq("bottom_padding", name)) {
1510 if (sscanf(value, "%i", &bp) != 1) {
1511 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1514 SET_DEF_MON_DESK(padding.bottom, bp)
1515 } else if (streq("left_padding", name)) {
1517 if (sscanf(value, "%i", &lp) != 1) {
1518 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1521 SET_DEF_MON_DESK(padding.left, lp)
1522 #undef SET_DEF_MON_DESK
1523 } else if (streq("top_monocle_padding", name)) {
1524 if (sscanf(value, "%i", &monocle_padding.top) != 1) {
1525 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1527 } else if (streq("right_monocle_padding", name)) {
1528 if (sscanf(value, "%i", &monocle_padding.right) != 1) {
1529 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1531 } else if (streq("bottom_monocle_padding", name)) {
1532 if (sscanf(value, "%i", &monocle_padding.bottom) != 1) {
1533 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1535 } else if (streq("left_monocle_padding", name)) {
1536 if (sscanf(value, "%i", &monocle_padding.left) != 1) {
1537 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1539 #define SET_STR(s) \
1540 } else if (streq(#s, name)) { \
1541 if (snprintf(s, sizeof(s), "%s", value) < 0) { \
1545 SET_STR(external_rules_command)
1546 SET_STR(status_prefix)
1548 } else if (streq("split_ratio", name)) {
1550 if (sscanf(value, "%lf", &r) == 1 && r > 0 && r < 1) {
1553 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value); \
1557 #define SET_COLOR(s) \
1558 } else if (streq(#s, name)) { \
1559 if (!is_hex_color(value)) { \
1560 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value); \
1563 snprintf(s, sizeof(s), "%s", value); \
1564 colors_changed = true; \
1566 SET_COLOR(normal_border_color)
1567 SET_COLOR(active_border_color)
1568 SET_COLOR(focused_border_color)
1569 SET_COLOR(presel_feedback_color)
1571 } else if (streq("initial_polarity", name)) {
1573 if (parse_child_polarity(value, &p)) {
1574 initial_polarity = p;
1576 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1579 } else if (streq("automatic_scheme", name)) {
1580 automatic_scheme_t a;
1581 if (parse_automatic_scheme(value, &a)) {
1582 automatic_scheme = a;
1584 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1587 } else if (streq("mapping_events_count", name)) {
1588 if (sscanf(value, "%" SCNi8, &mapping_events_count) != 1) {
1589 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1592 } else if (streq("directional_focus_tightness", name)) {
1594 if (parse_tightness(value, &p)) {
1595 directional_focus_tightness = p;
1597 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1600 } else if (streq("ignore_ewmh_fullscreen", name)) {
1601 state_transition_t m;
1602 if (parse_state_transition(value, &m)) {
1603 ignore_ewmh_fullscreen = m;
1605 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1608 } else if (streq("pointer_modifier", name)) {
1609 if (parse_modifier_mask(value, &pointer_modifier)) {
1613 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1616 } else if (streq("pointer_motion_interval", name)) {
1617 if (sscanf(value, "%u", &pointer_motion_interval) != 1) {
1618 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1621 } else if (streq("pointer_action1", name) ||
1622 streq("pointer_action2", name) ||
1623 streq("pointer_action3", name)) {
1624 int index = name[14] - '1';
1625 if (parse_pointer_action(value, &pointer_actions[index])) {
1629 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1632 } else if (streq("click_to_focus", name)) {
1633 if (parse_button_index(value, &click_to_focus)) {
1637 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1640 } else if (streq("focus_follows_pointer", name)) {
1642 if (parse_bool(value, &b)) {
1643 if (b == focus_follows_pointer) {
1647 focus_follows_pointer = b;
1648 for (monitor_t *m = mon_head; m != NULL; m = m->next) {
1649 if (focus_follows_pointer) {
1650 window_show(m->root);
1652 window_hide(m->root);
1654 for (desktop_t *d = m->desk_head; d != NULL; d = d->next) {
1655 listen_enter_notify(d->root, focus_follows_pointer);
1658 if (focus_follows_pointer) {
1659 update_motion_recorder();
1661 disable_motion_recorder();
1665 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1668 #define SET_BOOL(s) \
1669 } else if (streq(#s, name)) { \
1670 if (!parse_bool(value, &s)) { \
1671 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value); \
1674 SET_BOOL(presel_feedback)
1675 SET_BOOL(borderless_monocle)
1676 SET_BOOL(gapless_monocle)
1677 SET_BOOL(single_monocle)
1678 put_status(SBSC_MASK_REPORT);
1679 SET_BOOL(swallow_first_click)
1680 SET_BOOL(pointer_follows_focus)
1681 SET_BOOL(pointer_follows_monitor)
1682 SET_BOOL(ignore_ewmh_focus)
1683 SET_BOOL(ignore_ewmh_struts)
1684 SET_BOOL(center_pseudo_tiled)
1685 SET_BOOL(honor_size_hints)
1686 SET_BOOL(removal_adjustment)
1688 #define SET_MON_BOOL(s) \
1689 } else if (streq(#s, name)) { \
1690 if (!parse_bool(value, &s)) { \
1691 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value); \
1695 update_monitors(); \
1697 SET_MON_BOOL(remove_disabled_monitors)
1698 SET_MON_BOOL(remove_unplugged_monitors)
1699 SET_MON_BOOL(merge_overlapping_monitors)
1702 fail(rsp, "config: Unknown setting: '%s'.\n", name);
1706 for (monitor_t *m = mon_head; m != NULL; m = m->next) {
1707 for (desktop_t *d = m->desk_head; d != NULL; d = d->next) {
1709 if (colors_changed) {
1710 update_colors_in(d->root, d, m);
1716 void get_setting(coordinates_t loc, char *name, FILE* rsp)
1718 if (streq("split_ratio", name)) {
1719 fprintf(rsp, "%lf", split_ratio);
1720 } else if (streq("border_width", name)) {
1721 if (loc.node != NULL) {
1722 for (node_t *n = first_extrema(loc.node); n != NULL; n = next_leaf(n, loc.node)) {
1723 if (n->client != NULL) {
1724 fprintf(rsp, "%u", n->client->border_width);
1728 } else if (loc.desktop != NULL) {
1729 fprintf(rsp, "%u", loc.desktop->border_width);
1730 } else if (loc.monitor != NULL) {
1731 fprintf(rsp, "%u", loc.monitor->border_width);
1733 fprintf(rsp, "%u", border_width);
1735 } else if (streq("window_gap", name)) {
1736 if (loc.desktop != NULL) {
1737 fprintf(rsp, "%i", loc.desktop->window_gap);
1738 } else if (loc.monitor != NULL) {
1739 fprintf(rsp, "%i", loc.monitor->window_gap);
1741 fprintf(rsp, "%i", window_gap);
1743 #define GET_DEF_MON_DESK(k) \
1744 if (loc.desktop != NULL) { \
1745 fprintf(rsp, "%i", loc.desktop->k); \
1746 } else if (loc.monitor != NULL) { \
1747 fprintf(rsp, "%i", loc.monitor->k); \
1749 fprintf(rsp, "%i", k); \
1751 } else if (streq("top_padding", name)) {
1752 GET_DEF_MON_DESK(padding.top)
1753 } else if (streq("right_padding", name)) {
1754 GET_DEF_MON_DESK(padding.right)
1755 } else if (streq("bottom_padding", name)) {
1756 GET_DEF_MON_DESK(padding.bottom)
1757 } else if (streq("left_padding", name)) {
1758 GET_DEF_MON_DESK(padding.left)
1759 #undef GET_DEF_MON_DESK
1760 } else if (streq("top_monocle_padding", name)) {
1761 fprintf(rsp, "%i", monocle_padding.top);
1762 } else if (streq("right_monocle_padding", name)) {
1763 fprintf(rsp, "%i", monocle_padding.right);
1764 } else if (streq("bottom_monocle_padding", name)) {
1765 fprintf(rsp, "%i", monocle_padding.bottom);
1766 } else if (streq("left_monocle_padding", name)) {
1767 fprintf(rsp, "%i", monocle_padding.left);
1768 } else if (streq("external_rules_command", name)) {
1769 fprintf(rsp, "%s", external_rules_command);
1770 } else if (streq("status_prefix", name)) {
1771 fprintf(rsp, "%s", status_prefix);
1772 } else if (streq("initial_polarity", name)) {
1773 fprintf(rsp, "%s", CHILD_POL_STR(initial_polarity));
1774 } else if (streq("automatic_scheme", name)) {
1775 fprintf(rsp, "%s", AUTO_SCM_STR(automatic_scheme));
1776 } else if (streq("mapping_events_count", name)) {
1777 fprintf(rsp, "%" PRIi8, mapping_events_count);
1778 } else if (streq("directional_focus_tightness", name)) {
1779 fprintf(rsp, "%s", TIGHTNESS_STR(directional_focus_tightness));
1780 } else if (streq("ignore_ewmh_fullscreen", name)) {
1781 print_ignore_request(ignore_ewmh_fullscreen, rsp);
1782 } else if (streq("pointer_modifier", name)) {
1783 print_modifier_mask(pointer_modifier, rsp);
1784 } else if (streq("click_to_focus", name)) {
1785 print_button_index(click_to_focus, rsp);
1786 } else if (streq("pointer_motion_interval", name)) {
1787 fprintf(rsp, "%u", pointer_motion_interval);
1788 } else if (streq("pointer_action1", name) ||
1789 streq("pointer_action2", name) ||
1790 streq("pointer_action3", name)) {
1791 int index = name[14] - '1';
1792 print_pointer_action(pointer_actions[index], rsp);
1793 #define GET_COLOR(s) \
1794 } else if (streq(#s, name)) { \
1795 fprintf(rsp, "%s", s);
1796 GET_COLOR(normal_border_color)
1797 GET_COLOR(active_border_color)
1798 GET_COLOR(focused_border_color)
1799 GET_COLOR(presel_feedback_color)
1801 #define GET_BOOL(s) \
1802 } else if (streq(#s, name)) { \
1803 fprintf(rsp, "%s", BOOL_STR(s));
1804 GET_BOOL(presel_feedback)
1805 GET_BOOL(borderless_monocle)
1806 GET_BOOL(gapless_monocle)
1807 GET_BOOL(single_monocle)
1808 GET_BOOL(swallow_first_click)
1809 GET_BOOL(focus_follows_pointer)
1810 GET_BOOL(pointer_follows_focus)
1811 GET_BOOL(pointer_follows_monitor)
1812 GET_BOOL(ignore_ewmh_focus)
1813 GET_BOOL(ignore_ewmh_struts)
1814 GET_BOOL(center_pseudo_tiled)
1815 GET_BOOL(honor_size_hints)
1816 GET_BOOL(removal_adjustment)
1817 GET_BOOL(remove_disabled_monitors)
1818 GET_BOOL(remove_unplugged_monitors)
1819 GET_BOOL(merge_overlapping_monitors)
1822 fail(rsp, "config: Unknown setting: '%s'.\n", name);
1828 void handle_failure(int code, char *src, char *val, FILE *rsp)
1831 case SELECTOR_BAD_DESCRIPTOR:
1832 fail(rsp, "%s: Invalid descriptor found in '%s'.\n", src, val);
1834 case SELECTOR_BAD_MODIFIERS:
1835 fail(rsp, "%s: Invalid modifier found in '%s'.\n", src, val);
1837 case SELECTOR_INVALID:
1843 void fail(FILE *rsp, char *fmt, ...)
1845 fprintf(rsp, FAILURE_MESSAGE);
1848 vfprintf(rsp, fmt, ap);