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.
42 #include "subscribe.h"
45 int handle_message(char *msg, int msg_len, FILE *rsp)
49 char **args = malloc(cap * sizeof(char *));
53 for (int i = 0, j = 0; i < msg_len; i++) {
55 args[num++] = msg + j;
60 char **new = realloc(args, cap * sizeof(char *));
75 char **args_orig = args;
76 int ret = process_message(args, num, rsp);
81 int process_message(char **args, int num, FILE *rsp)
83 if (streq("window", *args)) {
84 return cmd_window(++args, --num);
85 } else if (streq("desktop", *args)) {
86 return cmd_desktop(++args, --num);
87 } else if (streq("monitor", *args)) {
88 return cmd_monitor(++args, --num);
89 } else if (streq("query", *args)) {
90 return cmd_query(++args, --num, rsp);
91 } else if (streq("restore", *args)) {
92 return cmd_restore(++args, --num);
93 } else if (streq("control", *args)) {
94 return cmd_control(++args, --num, rsp);
95 } else if (streq("rule", *args)) {
96 return cmd_rule(++args, --num, rsp);
97 } else if (streq("pointer", *args)) {
98 return cmd_pointer(++args, --num);
99 } else if (streq("config", *args)) {
100 return cmd_config(++args, --num, rsp);
101 } else if (streq("quit", *args)) {
102 return cmd_quit(++args, --num);
108 int cmd_window(char **args, int num)
113 coordinates_t ref = {mon, mon->desk, mon->desk->focus};
114 coordinates_t trg = ref;
116 if ((*args)[0] != OPT_CHR) {
117 if (node_from_desc(*args, &ref, &trg))
123 if (trg.node == NULL)
129 if (streq("-f", *args) || streq("--focus", *args)) {
130 coordinates_t dst = trg;
131 if (num > 1 && *(args + 1)[0] != OPT_CHR) {
133 if (!node_from_desc(*args, &trg, &dst))
136 focus_node(dst.monitor, dst.desktop, dst.node);
137 } else if (streq("-d", *args) || streq("--to-desktop", *args)) {
140 if (desktop_from_desc(*args, &trg, &dst)) {
141 if (transfer_node(trg.monitor, trg.desktop, trg.node, dst.monitor, dst.desktop, dst.desktop->focus)) {
142 trg.monitor = dst.monitor;
143 trg.desktop = dst.desktop;
148 } else if (streq("-m", *args) || streq("--to-monitor", *args)) {
153 if (monitor_from_desc(*args, &trg, &dst)) {
154 if (transfer_node(trg.monitor, trg.desktop, trg.node, dst.monitor, dst.monitor->desk, dst.monitor->desk->focus)) {
155 trg.monitor = dst.monitor;
156 trg.desktop = dst.monitor->desk;
161 } else if (streq("-w", *args) || streq("--to-window", *args)) {
166 if (node_from_desc(*args, &trg, &dst)) {
167 if (transfer_node(trg.monitor, trg.desktop, trg.node, dst.monitor, dst.desktop, dst.node)) {
168 trg.monitor = dst.monitor;
169 trg.desktop = dst.desktop;
174 } else if (streq("-s", *args) || streq("--swap", *args)) {
179 if (node_from_desc(*args, &trg, &dst)) {
180 if (swap_nodes(trg.monitor, trg.desktop, trg.node, dst.monitor, dst.desktop, dst.node)) {
181 if (trg.desktop != dst.desktop)
182 arrange(trg.monitor, trg.desktop);
183 trg.monitor = dst.monitor;
184 trg.desktop = dst.desktop;
190 } else if (streq("-t", *args) || streq("--toggle", *args)) {
194 char *key = strtok(*args, EQL_TOK);
195 char *val = strtok(NULL, EQL_TOK);
201 if (parse_bool(val, &b))
206 if (streq("fullscreen", key)) {
207 set_fullscreen(trg.node, (a == ALTER_SET ? b : !trg.node->client->fullscreen));
209 } else if (streq("pseudo_tiled", key)) {
210 set_pseudo_tiled(trg.node, (a == ALTER_SET ? b : !trg.node->client->pseudo_tiled));
212 } else if (streq("floating", key)) {
213 set_floating(trg.node, (a == ALTER_SET ? b : !trg.node->client->floating));
215 } else if (streq("locked", key)) {
216 set_locked(trg.monitor, trg.desktop, trg.node, (a == ALTER_SET ? b : !trg.node->client->locked));
217 } else if (streq("sticky", key)) {
218 set_sticky(trg.monitor, trg.desktop, trg.node, (a == ALTER_SET ? b : !trg.node->client->sticky));
219 } else if (streq("private", key)) {
220 set_private(trg.monitor, trg.desktop, trg.node, (a == ALTER_SET ? b : !trg.node->client->private));
224 } else if (streq("-p", *args) || streq("--presel", *args)) {
228 if (!is_tiled(trg.node->client) ||
229 trg.desktop->layout != LAYOUT_TILED)
231 if (streq("cancel", *args)) {
235 if (parse_direction(*args, &dir)) {
236 double rat = trg.node->split_ratio;
237 if (num > 1 && *(args + 1)[0] != OPT_CHR) {
239 if (sscanf(*args, "%lf", &rat) != 1 || rat <= 0 || rat >= 1)
242 if (auto_cancel && trg.node->split_mode == MODE_MANUAL &&
243 dir == trg.node->split_dir &&
244 rat == trg.node->split_ratio) {
247 trg.node->split_mode = MODE_MANUAL;
248 trg.node->split_dir = dir;
249 trg.node->split_ratio = rat;
251 window_draw_border(trg.node, trg.desktop->focus == trg.node, mon == trg.monitor);
256 } else if (streq("-e", *args) || streq("--edge", *args)) {
260 if (!is_tiled(trg.node->client))
263 if (!parse_direction(*args, &dir))
265 node_t *n = find_fence(trg.node, dir);
269 if ((*args)[0] == '+' || (*args)[0] == '-') {
271 if (sscanf(*args, "%i", &pix) == 1) {
272 int max = (n->split_type == TYPE_HORIZONTAL ? n->rectangle.height : n->rectangle.width);
273 double rat = ((max * n->split_ratio) + pix) / max;
274 if (rat > 0 && rat < 1)
275 n->split_ratio = rat;
283 if (sscanf(*args, "%lf", &rat) == 1 && rat > 0 && rat < 1)
284 n->split_ratio = rat;
289 } else if (streq("-r", *args) || streq("--ratio", *args)) {
294 if (sscanf(*args, "%lf", &rat) == 1 && rat > 0 && rat < 1) {
295 trg.node->split_ratio = rat;
296 window_draw_border(trg.node, trg.desktop->focus == trg.node, mon == trg.monitor);
300 } else if (streq("-R", *args) || streq("--rotate", *args)) {
305 if (!parse_direction(*args, &dir))
307 node_t *n = find_fence(trg.node, dir);
312 if (parse_degree(*args, °)) {
318 } else if (streq("-c", *args) || streq("--close", *args)) {
321 window_close(trg.node);
322 } else if (streq("-k", *args) || streq("--kill", *args)) {
325 window_kill(trg.monitor, trg.desktop, trg.node);
335 arrange(trg.monitor, trg.desktop);
340 int cmd_desktop(char **args, int num)
345 coordinates_t ref = {mon, mon->desk, NULL};
346 coordinates_t trg = ref;
348 if ((*args)[0] != OPT_CHR) {
349 if (desktop_from_desc(*args, &ref, &trg))
358 if (streq("-f", *args) || streq("--focus", *args)) {
359 coordinates_t dst = trg;
360 if (num > 1 && *(args + 1)[0] != OPT_CHR) {
362 if (!desktop_from_desc(*args, &trg, &dst))
365 if (auto_alternate && dst.desktop == mon->desk) {
366 desktop_select_t sel = {DESKTOP_STATUS_ALL, false, false};
367 history_find_desktop(HISTORY_OLDER, &trg, &dst, sel);
369 focus_node(dst.monitor, dst.desktop, dst.desktop->focus);
370 } else if (streq("-m", *args) || streq("--to-monitor", *args)) {
374 if (trg.monitor->desk_head == trg.monitor->desk_tail)
377 if (monitor_from_desc(*args, &trg, &dst)) {
378 transfer_desktop(trg.monitor, dst.monitor, trg.desktop);
379 trg.monitor = dst.monitor;
384 } else if (streq("-s", *args) || streq("--swap", *args)) {
389 if (desktop_from_desc(*args, &trg, &dst))
390 swap_desktops(trg.monitor, trg.desktop, dst.monitor, dst.desktop);
393 } else if (streq("-b", *args) || streq("--bubble", *args)) {
398 if (parse_cycle_direction(*args, &cyc)) {
399 desktop_t *d = trg.desktop;
400 if (cyc == CYCLE_PREV) {
401 if (d->prev == NULL) {
402 while (d->next != NULL) {
403 swap_desktops(trg.monitor, d, trg.monitor, d->next);
406 swap_desktops(trg.monitor, d, trg.monitor, d->prev);
409 if (d->next == NULL) {
410 while (d->prev != NULL) {
411 swap_desktops(trg.monitor, d, trg.monitor, d->prev);
414 swap_desktops(trg.monitor, d, trg.monitor, d->next);
420 } else if (streq("-l", *args) || streq("--layout", *args)) {
426 if (parse_cycle_direction(*args, &cyc))
427 change_layout(trg.monitor, trg.desktop, (trg.desktop->layout + 1) % 2);
428 else if (parse_layout(*args, &lyt))
429 change_layout(trg.monitor, trg.desktop, lyt);
432 } else if (streq("-n", *args) || streq("--rename", *args)) {
436 put_status(SBSC_MASK_DESKTOP_RENAME, "desktop_rename %s %s %s\n", trg.monitor->name, trg.desktop->name, *args);
437 snprintf(trg.desktop->name, sizeof(trg.desktop->name), "%s", *args);
438 ewmh_update_desktop_names();
439 put_status(SBSC_MASK_REPORT);
440 } else if (streq("-r", *args) || streq("--remove", *args)) {
441 if (trg.desktop->root == NULL &&
442 trg.monitor->desk_head != trg.monitor->desk_tail) {
443 remove_desktop(trg.monitor, trg.desktop);
444 show_desktop(trg.monitor->desk);
450 } else if (streq("-c", *args) || streq("--cancel-presel", *args)) {
452 } else if (streq("-F", *args) || streq("--flip", *args)) {
457 if (parse_flip(*args, &flp)) {
458 flip_tree(trg.desktop->root, flp);
463 } else if (streq("-R", *args) || streq("--rotate", *args)) {
468 if (parse_degree(*args, °)) {
469 rotate_tree(trg.desktop->root, deg);
474 } else if (streq("-E", *args) || streq("--equalize", *args)) {
475 equalize_tree(trg.desktop->root);
477 } else if (streq("-B", *args) || streq("--balance", *args)) {
478 balance_tree(trg.desktop->root);
480 } else if (streq("-C", *args) || streq("--circulate", *args)) {
485 if (parse_circulate_direction(*args, &cir)) {
486 circulate_leaves(trg.monitor, trg.desktop, cir);
491 } else if (streq("-t", *args) || streq("--toggle", *args)) {
495 char *key = strtok(*args, EQL_TOK);
496 char *val = strtok(NULL, EQL_TOK);
502 if (parse_bool(val, &b))
507 if (streq("floating", key))
508 trg.desktop->floating = (a == ALTER_SET ? b : !trg.desktop->floating);
518 arrange(trg.monitor, trg.desktop);
523 int cmd_monitor(char **args, int num)
528 coordinates_t ref = {mon, NULL, NULL};
529 coordinates_t trg = ref;
531 if ((*args)[0] != OPT_CHR) {
532 if (monitor_from_desc(*args, &ref, &trg))
539 if (streq("-f", *args) || streq("--focus", *args)) {
540 coordinates_t dst = trg;
541 if (num > 1 && *(args + 1)[0] != OPT_CHR) {
543 if (!monitor_from_desc(*args, &trg, &dst))
546 if (auto_alternate && dst.monitor == mon) {
547 desktop_select_t sel = {DESKTOP_STATUS_ALL, false, false};
548 history_find_monitor(HISTORY_OLDER, &trg, &dst, sel);
550 focus_node(dst.monitor, dst.monitor->desk, dst.monitor->desk->focus);
551 } else if (streq("-d", *args) || streq("--reset-desktops", *args)) {
555 desktop_t *d = trg.monitor->desk_head;
556 while (num > 0 && d != NULL) {
557 put_status(SBSC_MASK_DESKTOP_RENAME, "desktop_rename %s %s %s\n", trg.monitor->name, d->name, *args);
558 snprintf(d->name, sizeof(d->name), "%s", *args);
559 initialize_desktop(d);
560 arrange(trg.monitor, d);
564 put_status(SBSC_MASK_REPORT);
566 add_desktop(trg.monitor, make_desktop(*args));
570 desktop_t *next = d->next;
572 focus_node(trg.monitor, d->prev, d->prev->focus);
573 merge_desktops(trg.monitor, d, mon, mon->desk);
574 remove_desktop(trg.monitor, d);
577 } else if (streq("-a", *args) || streq("--add-desktops", *args)) {
582 add_desktop(trg.monitor, make_desktop(*args));
585 } else if (streq("-r", *args) || streq("--remove-desktops", *args)) {
591 if (locate_desktop(*args, &dst) && dst.monitor->desk_head != dst.monitor->desk_tail && dst.desktop->root == NULL) {
592 remove_desktop(dst.monitor, dst.desktop);
593 show_desktop(dst.monitor->desk);
597 } else if (streq("-o", *args) || streq("--order-desktops", *args)) {
601 desktop_t *d = trg.monitor->desk_head;
602 while (d != NULL && num > 0) {
603 desktop_t *next = d->next;
605 if (locate_desktop(*args, &dst) && dst.monitor == trg.monitor) {
606 swap_desktops(trg.monitor, d, dst.monitor, dst.desktop);
607 if (next == dst.desktop)
613 } else if (streq("-n", *args) || streq("--rename", *args)) {
617 put_status(SBSC_MASK_MONITOR_RENAME, "monitor_rename %s %s\n", trg.monitor->name, *args);
618 snprintf(trg.monitor->name, sizeof(trg.monitor->name), "%s", *args);
619 put_status(SBSC_MASK_REPORT);
620 } else if (streq("-s", *args) || streq("--swap", *args)) {
625 if (monitor_from_desc(*args, &trg, &dst))
626 swap_monitors(trg.monitor, dst.monitor);
638 int cmd_query(char **args, int num, FILE *rsp)
640 coordinates_t ref = {mon, mon->desk, mon->desk->focus};
641 coordinates_t trg = {NULL, NULL, NULL};
642 domain_t dom = DOMAIN_TREE;
646 if (streq("-T", *args) || streq("--tree", *args)) {
647 dom = DOMAIN_TREE, d++;
648 } else if (streq("-M", *args) || streq("--monitors", *args)) {
649 dom = DOMAIN_MONITOR, d++;
650 } else if (streq("-D", *args) || streq("--desktops", *args)) {
651 dom = DOMAIN_DESKTOP, d++;
652 } else if (streq("-W", *args) || streq("--windows", *args)) {
653 dom = DOMAIN_WINDOW, d++;
654 } else if (streq("-H", *args) || streq("--history", *args)) {
655 dom = DOMAIN_HISTORY, d++;
656 } else if (streq("-S", *args) || streq("--stack", *args)) {
657 dom = DOMAIN_STACK, d++;
658 } else if (streq("-m", *args) || streq("--monitor", *args)) {
659 trg.monitor = ref.monitor;
660 if (num > 1 && *(args + 1)[0] != OPT_CHR) {
662 if (!monitor_from_desc(*args, &ref, &trg))
666 } else if (streq("-d", *args) || streq("--desktop", *args)) {
667 trg.monitor = ref.monitor;
668 trg.desktop = ref.desktop;
669 if (num > 1 && *(args + 1)[0] != OPT_CHR) {
671 if (!desktop_from_desc(*args, &ref, &trg))
675 } else if (streq("-w", *args) || streq("--window", *args)) {
677 if (num > 1 && *(args + 1)[0] != OPT_CHR) {
679 if (!node_from_desc(*args, &ref, &trg))
692 if (dom == DOMAIN_HISTORY)
693 query_history(trg, rsp);
694 else if (dom == DOMAIN_STACK)
696 else if (dom == DOMAIN_WINDOW)
697 query_windows(trg, rsp);
699 query_monitors(trg, dom, rsp);
704 int cmd_rule(char **args, int num, FILE *rsp)
709 if (streq("-a", *args) || streq("--add", *args)) {
713 rule_t *rule = make_rule();
714 snprintf(rule->cause, sizeof(rule->cause), "%s", *args);
718 if (streq("-o", *args) || streq("--one-shot", *args)) {
719 rule->one_shot = true;
721 for (size_t j = 0; i < sizeof(rule->effect) && j < strlen(*args); i++, j++)
722 rule->effect[i] = (*args)[j];
723 if (num > 1 && i < sizeof(rule->effect))
724 rule->effect[i++] = ' ';
728 rule->effect[MIN(i, sizeof(rule->effect) - 1)] = '\0';
730 } else if (streq("-r", *args) || streq("--remove", *args)) {
736 if (parse_index(*args, &idx))
737 remove_rule_by_index(idx - 1);
738 else if (streq("tail", *args))
739 remove_rule(rule_tail);
740 else if (streq("head", *args))
741 remove_rule(rule_head);
743 remove_rule_by_cause(*args);
746 } else if (streq("-l", *args) || streq("--list", *args)) {
748 list_rules(num > 0 ? *args : NULL, rsp);
758 int cmd_pointer(char **args, int num)
763 if (streq("-t", *args) || streq("--track", *args)) {
768 if (sscanf(*args, "%i", &x) == 1 && sscanf(*(args + 1), "%i", &y) == 1)
773 } else if (streq("-g", *args) || streq("--grab", *args)) {
777 pointer_action_t pac;
778 if (parse_pointer_action(*args, &pac))
782 } else if (streq("-u", *args) || streq("--ungrab", *args)) {
793 int cmd_restore(char **args, int num)
798 if (streq("-T", *args) || streq("--tree", *args)) {
803 } else if (streq("-H", *args) || streq("--history", *args)) {
807 restore_history(*args);
808 } else if (streq("-S", *args) || streq("--stack", *args)) {
812 restore_stack(*args);
822 int cmd_control(char **args, int num, FILE *rsp)
827 if (streq("--adopt-orphans", *args)) {
829 } else if (streq("--toggle-visibility", *args)) {
831 } else if (streq("--subscribe", *args)) {
835 field = SBSC_MASK_REPORT;
837 subscriber_mask_t mask;
839 if (parse_subscriber_mask(*args, &mask)) {
847 add_subscriber(rsp, field);
848 return MSG_SUBSCRIBE;
849 } else if (streq("--get-status", *args)) {
851 } else if (streq("--record-history", *args)) {
856 if (parse_bool(*args, &b))
869 int cmd_config(char **args, int num, FILE *rsp)
873 coordinates_t ref = {mon, mon->desk, mon->desk->focus};
874 coordinates_t trg = {NULL, NULL, NULL};
875 if ((*args)[0] == OPT_CHR) {
876 if (streq("-m", *args) || streq("--monitor", *args)) {
880 if (!monitor_from_desc(*args, &ref, &trg))
882 } else if (streq("-d", *args) || streq("--desktop", *args)) {
886 if (!desktop_from_desc(*args, &ref, &trg))
888 } else if (streq("-w", *args) || streq("--window", *args)) {
892 if (!node_from_desc(*args, &ref, &trg))
900 return set_setting(trg, *args, *(args + 1));
902 return get_setting(trg, *args, rsp);
907 int cmd_quit(char **args, int num)
909 if (num > 0 && sscanf(*args, "%i", &exit_status) != 1)
915 int set_setting(coordinates_t loc, char *name, char *value)
917 #define DESKWINDEFSET(k, v) \
918 if (loc.node != NULL) \
919 loc.node->client->k = v; \
920 else if (loc.desktop != NULL) \
921 loc.desktop->k = v; \
922 else if (loc.monitor != NULL) \
923 for (desktop_t *d = loc.monitor->desk_head; d != NULL; d = d->next) \
927 if (streq("border_width", name)) {
929 if (sscanf(value, "%u", &bw) != 1)
931 DESKWINDEFSET(border_width, bw)
933 #define DESKDEFSET(k, v) \
934 if (loc.desktop != NULL) \
935 loc.desktop->k = v; \
936 else if (loc.monitor != NULL) \
937 for (desktop_t *d = loc.monitor->desk_head; d != NULL; d = d->next) \
941 } else if (streq("window_gap", name)) {
943 if (sscanf(value, "%i", &wg) != 1)
945 DESKDEFSET(window_gap, wg)
947 #define MONDESKSET(k, v) \
948 if (loc.desktop != NULL) \
949 loc.desktop->k = v; \
950 else if (loc.monitor != NULL) \
951 loc.monitor->k = v; \
953 for (monitor_t *m = mon_head; m != NULL; m = m->next) \
955 } else if (streq("top_padding", name)) {
957 if (sscanf(value, "%i", &tp) != 1)
959 MONDESKSET(top_padding, tp)
960 } else if (streq("right_padding", name)) {
962 if (sscanf(value, "%i", &rp) != 1)
964 MONDESKSET(right_padding, rp)
965 } else if (streq("bottom_padding", name)) {
967 if (sscanf(value, "%i", &bp) != 1)
969 MONDESKSET(bottom_padding, bp)
970 } else if (streq("left_padding", name)) {
972 if (sscanf(value, "%i", &lp) != 1)
974 MONDESKSET(left_padding, lp)
977 } else if (streq(#s, name)) { \
978 if (snprintf(s, sizeof(s), "%s", value) < 0) \
980 SETSTR(external_rules_command)
981 SETSTR(status_prefix)
983 } else if (streq("split_ratio", name)) {
985 if (sscanf(value, "%lf", &r) == 1 && r > 0 && r < 1)
990 #define SETCOLOR(s) \
991 } else if (streq(#s, name)) { \
992 snprintf(s, sizeof(s), "%s", value);
993 SETCOLOR(focused_border_color)
994 SETCOLOR(active_border_color)
995 SETCOLOR(normal_border_color)
996 SETCOLOR(presel_border_color)
997 SETCOLOR(focused_locked_border_color)
998 SETCOLOR(active_locked_border_color)
999 SETCOLOR(normal_locked_border_color)
1000 SETCOLOR(focused_sticky_border_color)
1001 SETCOLOR(active_sticky_border_color)
1002 SETCOLOR(normal_sticky_border_color)
1003 SETCOLOR(focused_private_border_color)
1004 SETCOLOR(active_private_border_color)
1005 SETCOLOR(normal_private_border_color)
1006 SETCOLOR(urgent_border_color)
1008 } else if (streq("initial_polarity", name)) {
1010 if (parse_child_polarity(value, &p)) {
1011 initial_polarity = p;
1015 } else if (streq("focus_follows_pointer", name)) {
1017 if (parse_bool(value, &b) && b != focus_follows_pointer) {
1018 focus_follows_pointer = b;
1019 uint32_t values[] = {CLIENT_EVENT_MASK | (focus_follows_pointer ? XCB_EVENT_MASK_ENTER_WINDOW : 0)};
1020 for (monitor_t *m = mon_head; m != NULL; m = m->next) {
1021 for (desktop_t *d = m->desk_head; d != NULL; d = d->next) {
1022 for (node_t *n = first_extrema(d->root); n != NULL; n = next_leaf(n, d->root)) {
1023 xcb_change_window_attributes(dpy, n->client->window, XCB_CW_EVENT_MASK, values);
1027 if (focus_follows_pointer) {
1028 for (monitor_t *m = mon_head; m != NULL; m = m->next) {
1029 window_show(m->root);
1032 for (monitor_t *m = mon_head; m != NULL; m = m->next) {
1033 window_hide(m->root);
1035 disable_motion_recorder();
1041 #define SETBOOL(s) \
1042 } else if (streq(#s, name)) { \
1043 if (!parse_bool(value, &s)) \
1045 SETBOOL(borderless_monocle)
1046 SETBOOL(gapless_monocle)
1047 SETBOOL(leaf_monocle)
1048 SETBOOL(pointer_follows_focus)
1049 SETBOOL(pointer_follows_monitor)
1050 SETBOOL(apply_floating_atom)
1051 SETBOOL(auto_alternate)
1052 SETBOOL(auto_cancel)
1053 SETBOOL(history_aware_focus)
1054 SETBOOL(focus_by_distance)
1055 SETBOOL(ignore_ewmh_focus)
1056 SETBOOL(center_pseudo_tiled)
1058 #define SETMONBOOL(s) \
1059 } else if (streq(#s, name)) { \
1060 if (!parse_bool(value, &s)) \
1061 return MSG_FAILURE; \
1064 SETMONBOOL(remove_disabled_monitors)
1065 SETMONBOOL(remove_unplugged_monitors)
1066 SETMONBOOL(merge_overlapping_monitors)
1072 for (monitor_t *m = mon_head; m != NULL; m = m->next)
1073 for (desktop_t *d = m->desk_head; d != NULL; d = d->next)
1079 int get_setting(coordinates_t loc, char *name, FILE* rsp)
1081 if (streq("split_ratio", name))
1082 fprintf(rsp, "%lf", split_ratio);
1083 else if (streq("window_gap", name))
1084 if (loc.desktop != NULL)
1085 fprintf(rsp, "%i", loc.desktop->window_gap);
1087 fprintf(rsp, "%i", window_gap);
1088 else if (streq("border_width", name))
1089 if (loc.node != NULL)
1090 fprintf(rsp, "%u", loc.node->client->border_width);
1091 else if (loc.desktop != NULL)
1092 fprintf(rsp, "%u", loc.desktop->border_width);
1094 fprintf(rsp, "%u", border_width);
1095 else if (streq("external_rules_command", name))
1096 fprintf(rsp, "%s", external_rules_command);
1097 else if (streq("status_prefix", name))
1098 fprintf(rsp, "%s", status_prefix);
1099 else if (streq("initial_polarity", name))
1100 fprintf(rsp, "%s", initial_polarity == FIRST_CHILD ? "first_child" : "second_child");
1101 #define MONDESKGET(k) \
1102 else if (streq(#k, name)) \
1103 if (loc.desktop != NULL) \
1104 fprintf(rsp, "%i", loc.desktop->k); \
1105 else if (loc.monitor != NULL) \
1106 fprintf(rsp, "%i", loc.monitor->k); \
1109 MONDESKGET(top_padding)
1110 MONDESKGET(right_padding)
1111 MONDESKGET(bottom_padding)
1112 MONDESKGET(left_padding)
1114 #define GETCOLOR(s) \
1115 else if (streq(#s, name)) \
1116 fprintf(rsp, "%s", s);
1117 GETCOLOR(focused_border_color)
1118 GETCOLOR(active_border_color)
1119 GETCOLOR(normal_border_color)
1120 GETCOLOR(presel_border_color)
1121 GETCOLOR(focused_locked_border_color)
1122 GETCOLOR(active_locked_border_color)
1123 GETCOLOR(normal_locked_border_color)
1124 GETCOLOR(focused_sticky_border_color)
1125 GETCOLOR(active_sticky_border_color)
1126 GETCOLOR(normal_sticky_border_color)
1127 GETCOLOR(urgent_border_color)
1129 #define GETBOOL(s) \
1130 else if (streq(#s, name)) \
1131 fprintf(rsp, "%s", BOOLSTR(s));
1132 GETBOOL(borderless_monocle)
1133 GETBOOL(gapless_monocle)
1134 GETBOOL(leaf_monocle)
1135 GETBOOL(focus_follows_pointer)
1136 GETBOOL(pointer_follows_focus)
1137 GETBOOL(pointer_follows_monitor)
1138 GETBOOL(apply_floating_atom)
1139 GETBOOL(auto_alternate)
1140 GETBOOL(auto_cancel)
1141 GETBOOL(history_aware_focus)
1142 GETBOOL(focus_by_distance)
1143 GETBOOL(ignore_ewmh_focus)
1144 GETBOOL(center_pseudo_tiled)
1145 GETBOOL(remove_disabled_monitors)
1146 GETBOOL(remove_unplugged_monitors)
1147 GETBOOL(merge_overlapping_monitors)
1154 bool parse_subscriber_mask(char *s, subscriber_mask_t *mask)
1156 if (streq("all", s)) {
1157 *mask = SBSC_MASK_ALL;
1158 } else if (streq("window", s)) {
1159 *mask = SBSC_MASK_WINDOW;
1160 } else if (streq("desktop", s)) {
1161 *mask = SBSC_MASK_DESKTOP;
1162 } else if (streq("monitor", s)) {
1163 *mask = SBSC_MASK_MONITOR;
1164 } else if (streq("window_manage", s)) {
1165 *mask = SBSC_MASK_WINDOW_MANAGE;
1166 } else if (streq("window_unmanage", s)) {
1167 *mask = SBSC_MASK_WINDOW_UNMANAGE;
1168 } else if (streq("window_swap", s)) {
1169 *mask = SBSC_MASK_WINDOW_SWAP;
1170 } else if (streq("window_transfer", s)) {
1171 *mask = SBSC_MASK_WINDOW_TRANSFER;
1172 } else if (streq("window_focus", s)) {
1173 *mask = SBSC_MASK_WINDOW_FOCUS;
1174 } else if (streq("window_resize", s)) {
1175 *mask = SBSC_MASK_WINDOW_RESIZE;
1176 } else if (streq("window_move", s)) {
1177 *mask = SBSC_MASK_WINDOW_MOVE;
1178 } else if (streq("window_state", s)) {
1179 *mask = SBSC_MASK_WINDOW_STATE;
1180 } else if (streq("desktop_add", s)) {
1181 *mask = SBSC_MASK_DESKTOP_ADD;
1182 } else if (streq("desktop_rename", s)) {
1183 *mask = SBSC_MASK_DESKTOP_RENAME;
1184 } else if (streq("desktop_remove", s)) {
1185 *mask = SBSC_MASK_DESKTOP_REMOVE;
1186 } else if (streq("desktop_swap", s)) {
1187 *mask = SBSC_MASK_DESKTOP_SWAP;
1188 } else if (streq("desktop_transfer", s)) {
1189 *mask = SBSC_MASK_DESKTOP_TRANSFER;
1190 } else if (streq("desktop_focus", s)) {
1191 *mask = SBSC_MASK_DESKTOP_FOCUS;
1192 } else if (streq("desktop_layout", s)) {
1193 *mask = SBSC_MASK_DESKTOP_LAYOUT;
1194 } else if (streq("desktop_state", s)) {
1195 *mask = SBSC_MASK_DESKTOP_STATE;
1196 } else if (streq("monitor_add", s)) {
1197 *mask = SBSC_MASK_MONITOR_ADD;
1198 } else if (streq("monitor_rename", s)) {
1199 *mask = SBSC_MASK_MONITOR_RENAME;
1200 } else if (streq("monitor_remove", s)) {
1201 *mask = SBSC_MASK_MONITOR_REMOVE;
1202 } else if (streq("monitor_focus", s)) {
1203 *mask = SBSC_MASK_MONITOR_FOCUS;
1204 } else if (streq("monitor_resize", s)) {
1205 *mask = SBSC_MASK_MONITOR_RESIZE;
1206 } else if (streq("report", s)) {
1207 *mask = SBSC_MASK_REPORT;
1214 bool parse_bool(char *value, bool *b)
1216 if (streq("true", value) || streq("on", value)) {
1219 } else if (streq("false", value) || streq("off", value)) {
1226 bool parse_layout(char *s, layout_t *l)
1228 if (streq("monocle", s)) {
1229 *l = LAYOUT_MONOCLE;
1231 } else if (streq("tiled", s)) {
1238 bool parse_direction(char *s, direction_t *d)
1240 if (streq("right", s)) {
1243 } else if (streq("down", s)) {
1246 } else if (streq("left", s)) {
1249 } else if (streq("up", s)) {
1256 bool parse_cycle_direction(char *s, cycle_dir_t *d)
1258 if (streq("next", s)) {
1261 } else if (streq("prev", s)) {
1268 bool parse_circulate_direction(char *s, circulate_dir_t *d)
1270 if (streq("forward", s)) {
1271 *d = CIRCULATE_FORWARD;
1273 } else if (streq("backward", s)) {
1274 *d = CIRCULATE_BACKWARD;
1280 bool parse_history_direction(char *s, history_dir_t *d)
1282 if (streq("older", s)) {
1285 } else if (streq("newer", s)) {
1293 bool parse_flip(char *s, flip_t *f)
1295 if (streq("horizontal", s)) {
1296 *f = FLIP_HORIZONTAL;
1298 } else if (streq("vertical", s)) {
1305 bool parse_pointer_action(char *s, pointer_action_t *a)
1307 if (streq("move", s)) {
1310 } else if (streq("resize_corner", s)) {
1311 *a = ACTION_RESIZE_CORNER;
1313 } else if (streq("resize_side", s)) {
1314 *a = ACTION_RESIZE_SIDE;
1316 } else if (streq("focus", s)) {
1323 bool parse_child_polarity(char *s, child_polarity_t *p)
1325 if (streq("first_child", s)) {
1328 } else if (streq("second_child", s)) {
1335 bool parse_degree(char *s, int *d)
1342 if ((i % 90) != 0) {
1350 bool parse_window_id(char *s, long int *i)
1354 long int ret = strtol(s, &end, 0);
1355 if (errno != 0 || *end != '\0')
1362 bool parse_bool_declaration(char *s, char **key, bool *value, alter_state_t *state)
1364 *key = strtok(s, EQL_TOK);
1365 char *v = strtok(NULL, EQL_TOK);
1367 *state = ALTER_TOGGLE;
1370 if (parse_bool(v, value)) {
1380 bool parse_index(char *s, int *i)
1383 if (sscanf(s, "^%i", &idx) != 1 || idx < 1)