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_tree(*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);
1264 fail(rsp, "wm: Unknown command: '%s'.\n", *args);
1271 void cmd_subscribe(char **args, int num, FILE *rsp)
1276 char *fifo_path = NULL;
1277 subscriber_mask_t mask;
1280 if (streq("-c", *args) || streq("--count", *args)) {
1283 fail(rsp, "subscribe %s: Not enough arguments.\n", *(args - 1));
1286 if (sscanf(*args, "%i", &count) != 1 || count < 1) {
1287 fail(rsp, "subscribe %s: Invalid argument: '%s'.\n", *(args - 1), *args);
1290 } else if (streq("-f", *args) || streq("--fifo", *args)) {
1291 fifo_path = mktempfifo(FIFO_TEMPLATE);
1292 if (fifo_path == NULL) {
1293 fail(rsp, "subscribe %s: Can't create FIFO.\n", *(args - 1));
1296 } else if (parse_subscriber_mask(*args, &mask)) {
1299 fail(rsp, "subscribe: Invalid argument: '%s'.\n", *args);
1306 field = SBSC_MASK_REPORT;
1310 fprintf(rsp, "%s\n", fifo_path);
1314 stream = fopen(fifo_path, "w");
1316 if (stream == NULL) {
1317 perror("subscribe: fopen");
1318 goto free_fifo_path;
1322 add_subscriber(stream, fifo_path, field, count);
1336 void cmd_quit(char **args, int num, FILE *rsp)
1338 if (num > 0 && sscanf(*args, "%i", &exit_status) != 1) {
1339 fail(rsp, "%s: Invalid argument: '%s'.\n", *(args - 1), *args);
1345 void cmd_config(char **args, int num, FILE *rsp)
1348 fail(rsp, "config: Missing arguments.\n");
1352 coordinates_t ref = {mon, mon->desk, mon->desk->focus};
1353 coordinates_t trg = {NULL, NULL, NULL};
1355 while (num > 0 && (*args)[0] == OPT_CHR) {
1356 if (streq("-m", *args) || streq("--monitor", *args)) {
1359 fail(rsp, "config %s: Not enough arguments.\n", *(args - 1));
1363 if ((ret = monitor_from_desc(*args, &ref, &trg)) != SELECTOR_OK) {
1364 handle_failure(ret, "config -m", *args, rsp);
1367 } else if (streq("-d", *args) || streq("--desktop", *args)) {
1370 fail(rsp, "config %s: Not enough arguments.\n", *(args - 1));
1374 if ((ret = desktop_from_desc(*args, &ref, &trg)) != SELECTOR_OK) {
1375 handle_failure(ret, "config -d", *args, rsp);
1378 } else if (streq("-n", *args) || streq("--node", *args)) {
1381 fail(rsp, "config %s: Not enough arguments.\n", *(args - 1));
1385 if ((ret = node_from_desc(*args, &ref, &trg)) != SELECTOR_OK) {
1386 handle_failure(ret, "config -n", *args, rsp);
1390 fail(rsp, "config: Unknown option: '%s'.\n", *args);
1396 set_setting(trg, *args, *(args + 1), rsp);
1397 } else if (num == 1) {
1398 get_setting(trg, *args, rsp);
1400 fail(rsp, "config: Was expecting 1 or 2 arguments, received %i.\n", num);
1404 void set_setting(coordinates_t loc, char *name, char *value, FILE *rsp)
1406 bool colors_changed = false;
1407 #define SET_DEF_DEFMON_DEFDESK_WIN(k, v) \
1408 if (loc.node != NULL) { \
1409 for (node_t *n = first_extrema(loc.node); n != NULL; n = next_leaf(n, loc.node)) { \
1410 if (n->client != NULL) { \
1414 } else if (loc.desktop != NULL) { \
1415 loc.desktop->k = v; \
1416 for (node_t *n = first_extrema(loc.desktop->root); n != NULL; n = next_leaf(n, loc.desktop->root)) { \
1417 if (n->client != NULL) { \
1421 } else if (loc.monitor != NULL) { \
1422 loc.monitor->k = v; \
1423 for (desktop_t *d = loc.monitor->desk_head; d != NULL; d = d->next) { \
1425 for (node_t *n = first_extrema(d->root); n != NULL; n = next_leaf(n, d->root)) { \
1426 if (n->client != NULL) { \
1433 for (monitor_t *m = mon_head; m != NULL; m = m->next) { \
1435 for (desktop_t *d = m->desk_head; d != NULL; d = d->next) { \
1437 for (node_t *n = first_extrema(d->root); n != NULL; n = next_leaf(n, d->root)) { \
1438 if (n->client != NULL) { \
1445 if (streq("border_width", name)) {
1447 if (sscanf(value, "%u", &bw) != 1) {
1448 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1451 SET_DEF_DEFMON_DEFDESK_WIN(border_width, bw)
1452 #undef SET_DEF_DEFMON_DEFDESK_WIN
1453 #define SET_DEF_DEFMON_DESK(k, v) \
1454 if (loc.desktop != NULL) { \
1455 loc.desktop->k = v; \
1456 } else if (loc.monitor != NULL) { \
1457 loc.monitor->k = v; \
1458 for (desktop_t *d = loc.monitor->desk_head; d != NULL; d = d->next) { \
1463 for (monitor_t *m = mon_head; m != NULL; m = m->next) { \
1465 for (desktop_t *d = m->desk_head; d != NULL; d = d->next) { \
1470 } else if (streq("window_gap", name)) {
1472 if (sscanf(value, "%i", &wg) != 1) {
1476 SET_DEF_DEFMON_DESK(window_gap, wg)
1477 #undef SET_DEF_DEFMON_DESK
1478 #define SET_DEF_MON_DESK(k, v) \
1479 if (loc.desktop != NULL) { \
1480 loc.desktop->k = v; \
1481 } else if (loc.monitor != NULL) { \
1482 loc.monitor->k = v; \
1485 for (monitor_t *m = mon_head; m != NULL; m = m->next) { \
1489 } else if (streq("top_padding", name)) {
1491 if (sscanf(value, "%i", &tp) != 1) {
1492 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1495 SET_DEF_MON_DESK(padding.top, tp)
1496 } else if (streq("right_padding", name)) {
1498 if (sscanf(value, "%i", &rp) != 1) {
1499 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1502 SET_DEF_MON_DESK(padding.right, rp)
1503 } else if (streq("bottom_padding", name)) {
1505 if (sscanf(value, "%i", &bp) != 1) {
1506 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1509 SET_DEF_MON_DESK(padding.bottom, bp)
1510 } else if (streq("left_padding", name)) {
1512 if (sscanf(value, "%i", &lp) != 1) {
1513 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1516 SET_DEF_MON_DESK(padding.left, lp)
1517 #undef SET_DEF_MON_DESK
1518 } else if (streq("top_monocle_padding", name)) {
1519 if (sscanf(value, "%i", &monocle_padding.top) != 1) {
1520 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1522 } else if (streq("right_monocle_padding", name)) {
1523 if (sscanf(value, "%i", &monocle_padding.right) != 1) {
1524 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1526 } else if (streq("bottom_monocle_padding", name)) {
1527 if (sscanf(value, "%i", &monocle_padding.bottom) != 1) {
1528 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1530 } else if (streq("left_monocle_padding", name)) {
1531 if (sscanf(value, "%i", &monocle_padding.left) != 1) {
1532 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1534 #define SET_STR(s) \
1535 } else if (streq(#s, name)) { \
1536 if (snprintf(s, sizeof(s), "%s", value) < 0) { \
1540 SET_STR(external_rules_command)
1541 SET_STR(status_prefix)
1543 } else if (streq("split_ratio", name)) {
1545 if (sscanf(value, "%lf", &r) == 1 && r > 0 && r < 1) {
1548 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value); \
1552 #define SET_COLOR(s) \
1553 } else if (streq(#s, name)) { \
1554 if (!is_hex_color(value)) { \
1555 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value); \
1558 snprintf(s, sizeof(s), "%s", value); \
1559 colors_changed = true; \
1561 SET_COLOR(normal_border_color)
1562 SET_COLOR(active_border_color)
1563 SET_COLOR(focused_border_color)
1564 SET_COLOR(presel_feedback_color)
1566 } else if (streq("initial_polarity", name)) {
1568 if (parse_child_polarity(value, &p)) {
1569 initial_polarity = p;
1571 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1574 } else if (streq("automatic_scheme", name)) {
1575 automatic_scheme_t a;
1576 if (parse_automatic_scheme(value, &a)) {
1577 automatic_scheme = a;
1579 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1582 } else if (streq("mapping_events_count", name)) {
1583 if (sscanf(value, "%" SCNi8, &mapping_events_count) != 1) {
1584 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1587 } else if (streq("directional_focus_tightness", name)) {
1589 if (parse_tightness(value, &p)) {
1590 directional_focus_tightness = p;
1592 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1595 } else if (streq("ignore_ewmh_fullscreen", name)) {
1596 state_transition_t m;
1597 if (parse_state_transition(value, &m)) {
1598 ignore_ewmh_fullscreen = m;
1600 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1603 } else if (streq("pointer_modifier", name)) {
1604 if (parse_modifier_mask(value, &pointer_modifier)) {
1608 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1611 } else if (streq("pointer_motion_interval", name)) {
1612 if (sscanf(value, "%u", &pointer_motion_interval) != 1) {
1613 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1616 } else if (streq("pointer_action1", name) ||
1617 streq("pointer_action2", name) ||
1618 streq("pointer_action3", name)) {
1619 int index = name[14] - '1';
1620 if (parse_pointer_action(value, &pointer_actions[index])) {
1624 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1627 } else if (streq("click_to_focus", name)) {
1628 if (parse_button_index(value, &click_to_focus)) {
1632 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1635 } else if (streq("focus_follows_pointer", name)) {
1637 if (parse_bool(value, &b)) {
1638 if (b == focus_follows_pointer) {
1642 focus_follows_pointer = b;
1643 for (monitor_t *m = mon_head; m != NULL; m = m->next) {
1644 if (focus_follows_pointer) {
1645 window_show(m->root);
1647 window_hide(m->root);
1649 for (desktop_t *d = m->desk_head; d != NULL; d = d->next) {
1650 listen_enter_notify(d->root, focus_follows_pointer);
1653 if (focus_follows_pointer) {
1654 update_motion_recorder();
1656 disable_motion_recorder();
1660 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value);
1663 #define SET_BOOL(s) \
1664 } else if (streq(#s, name)) { \
1665 if (!parse_bool(value, &s)) { \
1666 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value); \
1669 SET_BOOL(presel_feedback)
1670 SET_BOOL(borderless_monocle)
1671 SET_BOOL(gapless_monocle)
1672 SET_BOOL(single_monocle)
1673 SET_BOOL(swallow_first_click)
1674 SET_BOOL(pointer_follows_focus)
1675 SET_BOOL(pointer_follows_monitor)
1676 SET_BOOL(ignore_ewmh_focus)
1677 SET_BOOL(ignore_ewmh_struts)
1678 SET_BOOL(center_pseudo_tiled)
1679 SET_BOOL(honor_size_hints)
1680 SET_BOOL(removal_adjustment)
1682 #define SET_MON_BOOL(s) \
1683 } else if (streq(#s, name)) { \
1684 if (!parse_bool(value, &s)) { \
1685 fail(rsp, "config: %s: Invalid value: '%s'.\n", name, value); \
1689 update_monitors(); \
1691 SET_MON_BOOL(remove_disabled_monitors)
1692 SET_MON_BOOL(remove_unplugged_monitors)
1693 SET_MON_BOOL(merge_overlapping_monitors)
1696 fail(rsp, "config: Unknown setting: '%s'.\n", name);
1700 for (monitor_t *m = mon_head; m != NULL; m = m->next) {
1701 for (desktop_t *d = m->desk_head; d != NULL; d = d->next) {
1703 if (colors_changed) {
1704 update_colors_in(d->root, d, m);
1710 void get_setting(coordinates_t loc, char *name, FILE* rsp)
1712 if (streq("split_ratio", name)) {
1713 fprintf(rsp, "%lf", split_ratio);
1714 } else if (streq("border_width", name)) {
1715 if (loc.node != NULL) {
1716 for (node_t *n = first_extrema(loc.node); n != NULL; n = next_leaf(n, loc.node)) {
1717 if (n->client != NULL) {
1718 fprintf(rsp, "%u", n->client->border_width);
1722 } else if (loc.desktop != NULL) {
1723 fprintf(rsp, "%u", loc.desktop->border_width);
1724 } else if (loc.monitor != NULL) {
1725 fprintf(rsp, "%u", loc.monitor->border_width);
1727 fprintf(rsp, "%u", border_width);
1729 } else if (streq("window_gap", name)) {
1730 if (loc.desktop != NULL) {
1731 fprintf(rsp, "%i", loc.desktop->window_gap);
1732 } else if (loc.monitor != NULL) {
1733 fprintf(rsp, "%i", loc.monitor->window_gap);
1735 fprintf(rsp, "%i", window_gap);
1737 #define GET_DEF_MON_DESK(k) \
1738 if (loc.desktop != NULL) { \
1739 fprintf(rsp, "%i", loc.desktop->k); \
1740 } else if (loc.monitor != NULL) { \
1741 fprintf(rsp, "%i", loc.monitor->k); \
1743 fprintf(rsp, "%i", k); \
1745 } else if (streq("top_padding", name)) {
1746 GET_DEF_MON_DESK(padding.top)
1747 } else if (streq("right_padding", name)) {
1748 GET_DEF_MON_DESK(padding.right)
1749 } else if (streq("bottom_padding", name)) {
1750 GET_DEF_MON_DESK(padding.bottom)
1751 } else if (streq("left_padding", name)) {
1752 GET_DEF_MON_DESK(padding.left)
1753 #undef GET_DEF_MON_DESK
1754 } else if (streq("top_monocle_padding", name)) {
1755 fprintf(rsp, "%i", monocle_padding.top);
1756 } else if (streq("right_monocle_padding", name)) {
1757 fprintf(rsp, "%i", monocle_padding.right);
1758 } else if (streq("bottom_monocle_padding", name)) {
1759 fprintf(rsp, "%i", monocle_padding.bottom);
1760 } else if (streq("left_monocle_padding", name)) {
1761 fprintf(rsp, "%i", monocle_padding.left);
1762 } else if (streq("external_rules_command", name)) {
1763 fprintf(rsp, "%s", external_rules_command);
1764 } else if (streq("status_prefix", name)) {
1765 fprintf(rsp, "%s", status_prefix);
1766 } else if (streq("initial_polarity", name)) {
1767 fprintf(rsp, "%s", CHILD_POL_STR(initial_polarity));
1768 } else if (streq("automatic_scheme", name)) {
1769 fprintf(rsp, "%s", AUTO_SCM_STR(automatic_scheme));
1770 } else if (streq("mapping_events_count", name)) {
1771 fprintf(rsp, "%" PRIi8, mapping_events_count);
1772 } else if (streq("directional_focus_tightness", name)) {
1773 fprintf(rsp, "%s", TIGHTNESS_STR(directional_focus_tightness));
1774 } else if (streq("ignore_ewmh_fullscreen", name)) {
1775 print_ignore_request(ignore_ewmh_fullscreen, rsp);
1776 } else if (streq("pointer_modifier", name)) {
1777 print_modifier_mask(pointer_modifier, rsp);
1778 } else if (streq("click_to_focus", name)) {
1779 print_button_index(click_to_focus, rsp);
1780 } else if (streq("pointer_motion_interval", name)) {
1781 fprintf(rsp, "%u", pointer_motion_interval);
1782 } else if (streq("pointer_action1", name) ||
1783 streq("pointer_action2", name) ||
1784 streq("pointer_action3", name)) {
1785 int index = name[14] - '1';
1786 print_pointer_action(pointer_actions[index], rsp);
1787 #define GET_COLOR(s) \
1788 } else if (streq(#s, name)) { \
1789 fprintf(rsp, "%s", s);
1790 GET_COLOR(normal_border_color)
1791 GET_COLOR(active_border_color)
1792 GET_COLOR(focused_border_color)
1793 GET_COLOR(presel_feedback_color)
1795 #define GET_BOOL(s) \
1796 } else if (streq(#s, name)) { \
1797 fprintf(rsp, "%s", BOOL_STR(s));
1798 GET_BOOL(presel_feedback)
1799 GET_BOOL(borderless_monocle)
1800 GET_BOOL(gapless_monocle)
1801 GET_BOOL(single_monocle)
1802 GET_BOOL(swallow_first_click)
1803 GET_BOOL(focus_follows_pointer)
1804 GET_BOOL(pointer_follows_focus)
1805 GET_BOOL(pointer_follows_monitor)
1806 GET_BOOL(ignore_ewmh_focus)
1807 GET_BOOL(ignore_ewmh_struts)
1808 GET_BOOL(center_pseudo_tiled)
1809 GET_BOOL(honor_size_hints)
1810 GET_BOOL(removal_adjustment)
1811 GET_BOOL(remove_disabled_monitors)
1812 GET_BOOL(remove_unplugged_monitors)
1813 GET_BOOL(merge_overlapping_monitors)
1816 fail(rsp, "config: Unknown setting: '%s'.\n", name);
1822 void handle_failure(int code, char *src, char *val, FILE *rsp)
1825 case SELECTOR_BAD_DESCRIPTOR:
1826 fail(rsp, "%s: Invalid descriptor found in '%s'.\n", src, val);
1828 case SELECTOR_BAD_MODIFIERS:
1829 fail(rsp, "%s: Invalid modifier found in '%s'.\n", src, val);
1831 case SELECTOR_INVALID:
1837 void fail(FILE *rsp, char *fmt, ...)
1839 fprintf(rsp, FAILURE_MESSAGE);
1842 vfprintf(rsp, fmt, ap);