1 /* Copyright (c) 2012-2014, 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.
24 * The views and conclusions contained in the software and documentation are those
25 * of the authors and should not be interpreted as representing official policies,
26 * either expressed or implied, of the FreeBSD Project.
46 #include "subscribe.h"
49 int handle_message(char *msg, int msg_len, FILE *rsp)
53 char **args = malloc(cap * sizeof(char *));
57 for (int i = 0, j = 0; i < msg_len; i++) {
59 args[num++] = msg + j;
64 char **new = realloc(args, cap * sizeof(char *));
79 char **args_orig = args;
80 int ret = process_message(args, num, rsp);
85 int process_message(char **args, int num, FILE *rsp)
87 if (streq("window", *args)) {
88 return cmd_window(++args, --num);
89 } else if (streq("desktop", *args)) {
90 return cmd_desktop(++args, --num);
91 } else if (streq("monitor", *args)) {
92 return cmd_monitor(++args, --num);
93 } else if (streq("query", *args)) {
94 return cmd_query(++args, --num, rsp);
95 } else if (streq("restore", *args)) {
96 return cmd_restore(++args, --num);
97 } else if (streq("control", *args)) {
98 return cmd_control(++args, --num, rsp);
99 } else if (streq("rule", *args)) {
100 return cmd_rule(++args, --num, rsp);
101 } else if (streq("pointer", *args)) {
102 return cmd_pointer(++args, --num);
103 } else if (streq("config", *args)) {
104 return cmd_config(++args, --num, rsp);
105 } else if (streq("quit", *args)) {
106 return cmd_quit(++args, --num);
112 int cmd_window(char **args, int num)
117 coordinates_t ref = {mon, mon->desk, mon->desk->focus};
118 coordinates_t trg = ref;
120 if ((*args)[0] != OPT_CHR) {
121 if (node_from_desc(*args, &ref, &trg))
127 if (trg.node == NULL)
133 if (streq("-f", *args) || streq("--focus", *args)) {
134 coordinates_t dst = trg;
135 if (num > 1 && *(args + 1)[0] != OPT_CHR) {
137 if (!node_from_desc(*args, &trg, &dst))
140 focus_node(dst.monitor, dst.desktop, dst.node);
141 } else if (streq("-d", *args) || streq("--to-desktop", *args)) {
144 if (desktop_from_desc(*args, &trg, &dst)) {
145 if (transfer_node(trg.monitor, trg.desktop, trg.node, dst.monitor, dst.desktop, dst.desktop->focus)) {
146 trg.monitor = dst.monitor;
147 trg.desktop = dst.desktop;
152 } else if (streq("-m", *args) || streq("--to-monitor", *args)) {
157 if (monitor_from_desc(*args, &trg, &dst)) {
158 if (transfer_node(trg.monitor, trg.desktop, trg.node, dst.monitor, dst.monitor->desk, dst.monitor->desk->focus)) {
159 trg.monitor = dst.monitor;
160 trg.desktop = dst.monitor->desk;
165 } else if (streq("-w", *args) || streq("--to-window", *args)) {
170 if (node_from_desc(*args, &trg, &dst)) {
171 if (transfer_node(trg.monitor, trg.desktop, trg.node, dst.monitor, dst.desktop, dst.node)) {
172 trg.monitor = dst.monitor;
173 trg.desktop = dst.desktop;
178 } else if (streq("-s", *args) || streq("--swap", *args)) {
183 if (node_from_desc(*args, &trg, &dst)) {
184 if (swap_nodes(trg.monitor, trg.desktop, trg.node, dst.monitor, dst.desktop, dst.node)) {
185 if (trg.desktop != dst.desktop)
186 arrange(trg.monitor, trg.desktop);
187 trg.monitor = dst.monitor;
188 trg.desktop = dst.desktop;
194 } else if (streq("-t", *args) || streq("--toggle", *args)) {
198 char *key = strtok(*args, EQL_TOK);
199 char *val = strtok(NULL, EQL_TOK);
205 if (parse_bool(val, &b))
210 if (streq("fullscreen", key)) {
211 set_fullscreen(trg.node, (a == ALTER_SET ? b : !trg.node->client->fullscreen));
213 } else if (streq("pseudo_tiled", key)) {
214 set_pseudo_tiled(trg.node, (a == ALTER_SET ? b : !trg.node->client->pseudo_tiled));
216 } else if (streq("floating", key)) {
217 set_floating(trg.node, (a == ALTER_SET ? b : !trg.node->client->floating));
219 } else if (streq("locked", key)) {
220 set_locked(trg.monitor, trg.desktop, trg.node, (a == ALTER_SET ? b : !trg.node->client->locked));
221 } else if (streq("sticky", key)) {
222 set_sticky(trg.monitor, trg.desktop, trg.node, (a == ALTER_SET ? b : !trg.node->client->sticky));
223 } else if (streq("private", key)) {
224 set_private(trg.monitor, trg.desktop, trg.node, (a == ALTER_SET ? b : !trg.node->client->private));
228 } else if (streq("-p", *args) || streq("--presel", *args)) {
232 if (!is_tiled(trg.node->client) ||
233 trg.desktop->layout != LAYOUT_TILED)
235 if (streq("cancel", *args)) {
239 if (parse_direction(*args, &dir)) {
240 double rat = trg.node->split_ratio;
241 if (num > 1 && *(args + 1)[0] != OPT_CHR) {
243 if (sscanf(*args, "%lf", &rat) != 1 || rat <= 0 || rat >= 1)
246 if (auto_cancel && trg.node->split_mode == MODE_MANUAL &&
247 dir == trg.node->split_dir &&
248 rat == trg.node->split_ratio) {
251 trg.node->split_mode = MODE_MANUAL;
252 trg.node->split_dir = dir;
253 trg.node->split_ratio = rat;
255 window_draw_border(trg.node, trg.desktop->focus == trg.node, mon == trg.monitor);
260 } else if (streq("-e", *args) || streq("--edge", *args)) {
265 if (!parse_direction(*args, &dir))
267 node_t *n = find_fence(trg.node, dir);
271 if ((*args)[0] == '+' || (*args)[0] == '-') {
273 if (sscanf(*args, "%i", &pix) == 1) {
274 int max = (n->split_type == TYPE_HORIZONTAL ? n->rectangle.height : n->rectangle.width);
275 double rat = ((max * n->split_ratio) + pix) / max;
276 if (rat > 0 && rat < 1)
277 n->split_ratio = rat;
285 if (sscanf(*args, "%lf", &rat) == 1 && rat > 0 && rat < 1)
286 n->split_ratio = rat;
291 } else if (streq("-r", *args) || streq("--ratio", *args)) {
296 if (sscanf(*args, "%lf", &rat) == 1 && rat > 0 && rat < 1) {
297 trg.node->split_ratio = rat;
298 window_draw_border(trg.node, trg.desktop->focus == trg.node, mon == trg.monitor);
302 } else if (streq("-R", *args) || streq("--rotate", *args)) {
307 if (!parse_direction(*args, &dir))
309 node_t *n = find_fence(trg.node, dir);
314 if (parse_degree(*args, °)) {
320 } else if (streq("-c", *args) || streq("--close", *args)) {
323 window_close(trg.node);
324 } else if (streq("-k", *args) || streq("--kill", *args)) {
327 window_kill(trg.monitor, trg.desktop, trg.node);
337 arrange(trg.monitor, trg.desktop);
342 int cmd_desktop(char **args, int num)
347 coordinates_t ref = {mon, mon->desk, NULL};
348 coordinates_t trg = ref;
350 if ((*args)[0] != OPT_CHR) {
351 if (desktop_from_desc(*args, &ref, &trg))
360 if (streq("-f", *args) || streq("--focus", *args)) {
361 coordinates_t dst = trg;
362 if (num > 1 && *(args + 1)[0] != OPT_CHR) {
364 if (!desktop_from_desc(*args, &trg, &dst))
367 if (auto_alternate && dst.desktop == mon->desk) {
368 desktop_select_t sel = {DESKTOP_STATUS_ALL, false, false};
369 history_find_desktop(HISTORY_OLDER, &trg, &dst, sel);
371 focus_node(dst.monitor, dst.desktop, dst.desktop->focus);
372 } else if (streq("-m", *args) || streq("--to-monitor", *args)) {
376 if (trg.monitor->desk_head == trg.monitor->desk_tail)
379 if (monitor_from_desc(*args, &trg, &dst)) {
380 transfer_desktop(trg.monitor, dst.monitor, trg.desktop);
381 trg.monitor = dst.monitor;
386 } else if (streq("-s", *args) || streq("--swap", *args)) {
391 if (desktop_from_desc(*args, &trg, &dst))
392 swap_desktops(trg.monitor, trg.desktop, dst.monitor, dst.desktop);
395 } else if (streq("-l", *args) || streq("--layout", *args)) {
401 if (parse_cycle_direction(*args, &cyc))
402 change_layout(trg.monitor, trg.desktop, (trg.desktop->layout + 1) % 2);
403 else if (parse_layout(*args, &lyt))
404 change_layout(trg.monitor, trg.desktop, lyt);
407 } else if (streq("-n", *args) || streq("--rename", *args)) {
411 snprintf(trg.desktop->name, sizeof(trg.desktop->name), "%s", *args);
412 ewmh_update_desktop_names();
414 } else if (streq("-r", *args) || streq("--remove", *args)) {
415 if (trg.desktop->root == NULL &&
416 trg.monitor->desk_head != trg.monitor->desk_tail) {
417 remove_desktop(trg.monitor, trg.desktop);
418 show_desktop(trg.monitor->desk);
424 } else if (streq("-c", *args) || streq("--cancel-presel", *args)) {
426 } else if (streq("-F", *args) || streq("--flip", *args)) {
431 if (parse_flip(*args, &flp)) {
432 flip_tree(trg.desktop->root, flp);
437 } else if (streq("-R", *args) || streq("--rotate", *args)) {
442 if (parse_degree(*args, °)) {
443 rotate_tree(trg.desktop->root, deg);
448 } else if (streq("-E", *args) || streq("--equalize", *args)) {
449 equalize_tree(trg.desktop->root);
451 } else if (streq("-B", *args) || streq("--balance", *args)) {
452 balance_tree(trg.desktop->root);
454 } else if (streq("-C", *args) || streq("--circulate", *args)) {
459 if (parse_circulate_direction(*args, &cir)) {
460 circulate_leaves(trg.monitor, trg.desktop, cir);
465 } else if (streq("-t", *args) || streq("--toggle", *args)) {
469 char *key = strtok(*args, EQL_TOK);
470 char *val = strtok(NULL, EQL_TOK);
476 if (parse_bool(val, &b))
481 if (streq("floating", key))
482 trg.desktop->floating = (a == ALTER_SET ? b : !trg.desktop->floating);
492 arrange(trg.monitor, trg.desktop);
497 int cmd_monitor(char **args, int num)
502 coordinates_t ref = {mon, NULL, NULL};
503 coordinates_t trg = ref;
505 if ((*args)[0] != OPT_CHR) {
506 if (monitor_from_desc(*args, &ref, &trg))
513 if (streq("-f", *args) || streq("--focus", *args)) {
514 coordinates_t dst = trg;
515 if (num > 1 && *(args + 1)[0] != OPT_CHR) {
517 if (!monitor_from_desc(*args, &trg, &dst))
520 if (auto_alternate && dst.monitor == mon) {
521 desktop_select_t sel = {DESKTOP_STATUS_ALL, false, false};
522 history_find_monitor(HISTORY_OLDER, &trg, &dst, sel);
524 focus_node(dst.monitor, dst.monitor->desk, dst.monitor->desk->focus);
525 } else if (streq("-d", *args) || streq("--reset-desktops", *args)) {
529 desktop_t *d = trg.monitor->desk_head;
530 while (num > 0 && d != NULL) {
531 snprintf(d->name, sizeof(d->name), "%s", *args);
537 add_desktop(trg.monitor, make_desktop(*args));
541 desktop_t *next = d->next;
543 focus_node(trg.monitor, d->prev, d->prev->focus);
544 merge_desktops(trg.monitor, d, mon, mon->desk);
545 remove_desktop(trg.monitor, d);
548 } else if (streq("-a", *args) || streq("--add-desktops", *args)) {
553 add_desktop(trg.monitor, make_desktop(*args));
556 } else if (streq("-r", *args) || streq("--remove-desktops", *args)) {
562 if (locate_desktop(*args, &dst) && dst.monitor->desk_head != dst.monitor->desk_tail && dst.desktop->root == NULL) {
563 remove_desktop(dst.monitor, dst.desktop);
564 show_desktop(dst.monitor->desk);
568 } else if (streq("-o", *args) || streq("--order-desktops", *args)) {
572 desktop_t *d = trg.monitor->desk_head;
573 while (d != NULL && num > 0) {
574 desktop_t *next = d->next;
576 if (locate_desktop(*args, &dst) && dst.monitor == trg.monitor) {
577 swap_desktops(trg.monitor, d, dst.monitor, dst.desktop);
578 if (next == dst.desktop)
584 } else if (streq("-n", *args) || streq("--rename", *args)) {
588 snprintf(trg.monitor->name, sizeof(trg.monitor->name), "%s", *args);
590 } else if (streq("-s", *args) || streq("--swap", *args)) {
595 if (monitor_from_desc(*args, &trg, &dst))
596 swap_monitors(trg.monitor, dst.monitor);
608 int cmd_query(char **args, int num, FILE *rsp)
610 coordinates_t ref = {mon, mon->desk, mon->desk->focus};
611 coordinates_t trg = {NULL, NULL, NULL};
612 domain_t dom = DOMAIN_TREE;
616 if (streq("-T", *args) || streq("--tree", *args)) {
617 dom = DOMAIN_TREE, d++;
618 } else if (streq("-M", *args) || streq("--monitors", *args)) {
619 dom = DOMAIN_MONITOR, d++;
620 } else if (streq("-D", *args) || streq("--desktops", *args)) {
621 dom = DOMAIN_DESKTOP, d++;
622 } else if (streq("-W", *args) || streq("--windows", *args)) {
623 dom = DOMAIN_WINDOW, d++;
624 } else if (streq("-H", *args) || streq("--history", *args)) {
625 dom = DOMAIN_HISTORY, d++;
626 } else if (streq("-S", *args) || streq("--stack", *args)) {
627 dom = DOMAIN_STACK, d++;
628 } else if (streq("-m", *args) || streq("--monitor", *args)) {
629 trg.monitor = ref.monitor;
630 if (num > 1 && *(args + 1)[0] != OPT_CHR) {
632 if (!monitor_from_desc(*args, &ref, &trg))
636 } else if (streq("-d", *args) || streq("--desktop", *args)) {
637 trg.monitor = ref.monitor;
638 trg.desktop = ref.desktop;
639 if (num > 1 && *(args + 1)[0] != OPT_CHR) {
641 if (!desktop_from_desc(*args, &ref, &trg))
645 } else if (streq("-w", *args) || streq("--window", *args)) {
647 if (num > 1 && *(args + 1)[0] != OPT_CHR) {
649 if (!node_from_desc(*args, &ref, &trg))
662 if (dom == DOMAIN_HISTORY)
663 query_history(trg, rsp);
664 else if (dom == DOMAIN_STACK)
666 else if (dom == DOMAIN_WINDOW)
667 query_windows(trg, rsp);
669 query_monitors(trg, dom, rsp);
674 int cmd_rule(char **args, int num, FILE *rsp)
679 if (streq("-a", *args) || streq("--add", *args)) {
683 rule_t *rule = make_rule();
684 snprintf(rule->cause, sizeof(rule->cause), "%s", *args);
688 if (streq("-o", *args) || streq("--one-shot", *args)) {
689 rule->one_shot = true;
691 for (size_t j = 0; i < sizeof(rule->effect) && j < strlen(*args); i++, j++)
692 rule->effect[i] = (*args)[j];
693 if (num > 1 && i < sizeof(rule->effect))
694 rule->effect[i++] = ' ';
698 rule->effect[MIN(i, sizeof(rule->effect) - 1)] = '\0';
700 } else if (streq("-r", *args) || streq("--remove", *args)) {
706 if (parse_index(*args, &idx))
707 remove_rule_by_index(idx - 1);
708 else if (streq("tail", *args))
709 remove_rule(rule_tail);
710 else if (streq("head", *args))
711 remove_rule(rule_head);
713 remove_rule_by_cause(*args);
716 } else if (streq("-l", *args) || streq("--list", *args)) {
718 list_rules(num > 0 ? *args : NULL, rsp);
728 int cmd_pointer(char **args, int num)
733 if (streq("-t", *args) || streq("--track", *args)) {
738 if (sscanf(*args, "%i", &x) == 1 && sscanf(*(args + 1), "%i", &y) == 1)
743 } else if (streq("-g", *args) || streq("--grab", *args)) {
747 pointer_action_t pac;
748 if (parse_pointer_action(*args, &pac))
752 } else if (streq("-u", *args) || streq("--ungrab", *args)) {
763 int cmd_restore(char **args, int num)
768 if (streq("-T", *args) || streq("--tree", *args)) {
773 } else if (streq("-H", *args) || streq("--history", *args)) {
777 restore_history(*args);
778 } else if (streq("-S", *args) || streq("--stack", *args)) {
782 restore_stack(*args);
792 int cmd_control(char **args, int num, FILE *rsp)
797 if (streq("--adopt-orphans", *args)) {
799 } else if (streq("--toggle-visibility", *args)) {
801 } else if (streq("--subscribe", *args)) {
802 return MSG_SUBSCRIBE;
803 } else if (streq("--get-status", *args)) {
805 } else if (streq("--record-history", *args)) {
810 if (parse_bool(*args, &b))
823 int cmd_config(char **args, int num, FILE *rsp)
827 coordinates_t ref = {mon, mon->desk, mon->desk->focus};
828 coordinates_t trg = {NULL, NULL, NULL};
829 if ((*args)[0] == OPT_CHR) {
830 if (streq("-m", *args) || streq("--monitor", *args)) {
834 if (!monitor_from_desc(*args, &ref, &trg))
836 } else if (streq("-d", *args) || streq("--desktop", *args)) {
840 if (!desktop_from_desc(*args, &ref, &trg))
842 } else if (streq("-w", *args) || streq("--window", *args)) {
846 if (!node_from_desc(*args, &ref, &trg))
854 return set_setting(trg, *args, *(args + 1));
856 return get_setting(trg, *args, rsp);
861 int cmd_quit(char **args, int num)
863 if (num > 0 && sscanf(*args, "%i", &exit_status) != 1)
869 int set_setting(coordinates_t loc, char *name, char *value)
871 #define DESKWINSET(k, v) \
872 if (loc.node != NULL) \
873 loc.node->client->k = v; \
874 else if (loc.desktop != NULL) \
875 loc.desktop->k = v; \
876 else if (loc.monitor != NULL) \
877 for (desktop_t *d = loc.monitor->desk_head; d != NULL; d = d->next) \
880 for (monitor_t *m = mon_head; m != NULL; m = m->next) \
881 for (desktop_t *d = m->desk_head; d != NULL; d = d->next) \
883 if (streq("border_width", name)) {
885 if (sscanf(value, "%u", &bw) != 1)
887 DESKWINSET(border_width, bw)
889 #define DESKSET(k, v) \
890 if (loc.desktop != NULL) \
891 loc.desktop->k = v; \
892 else if (loc.monitor != NULL) \
893 for (desktop_t *d = loc.monitor->desk_head; d != NULL; d = d->next) \
896 for (monitor_t *m = mon_head; m != NULL; m = m->next) \
897 for (desktop_t *d = m->desk_head; d != NULL; d = d->next) \
899 } else if (streq("window_gap", name)) {
901 if (sscanf(value, "%i", &wg) != 1)
903 DESKSET(window_gap, wg)
905 #define MONDESKSET(k, v) \
906 if (loc.desktop != NULL) \
907 loc.desktop->k = v; \
908 else if (loc.monitor != NULL) \
909 loc.monitor->k = v; \
911 for (monitor_t *m = mon_head; m != NULL; m = m->next) \
913 } else if (streq("top_padding", name)) {
915 if (sscanf(value, "%i", &tp) != 1)
917 MONDESKSET(top_padding, tp)
918 } else if (streq("right_padding", name)) {
920 if (sscanf(value, "%i", &rp) != 1)
922 MONDESKSET(right_padding, rp)
923 } else if (streq("bottom_padding", name)) {
925 if (sscanf(value, "%i", &bp) != 1)
927 MONDESKSET(bottom_padding, bp)
928 } else if (streq("left_padding", name)) {
930 if (sscanf(value, "%i", &lp) != 1)
932 MONDESKSET(left_padding, lp)
935 } else if (streq(#s, name)) { \
936 return snprintf(s, sizeof(s), "%s", value) >= 0;
937 SETSTR(external_rules_command)
938 SETSTR(status_prefix)
940 } else if (streq("split_ratio", name)) {
942 if (sscanf(value, "%lf", &r) == 1 && r > 0 && r < 1)
947 #define SETCOLOR(s) \
948 } else if (streq(#s, name)) { \
949 snprintf(s, sizeof(s), "%s", value);
950 SETCOLOR(focused_border_color)
951 SETCOLOR(active_border_color)
952 SETCOLOR(normal_border_color)
953 SETCOLOR(presel_border_color)
954 SETCOLOR(focused_locked_border_color)
955 SETCOLOR(active_locked_border_color)
956 SETCOLOR(normal_locked_border_color)
957 SETCOLOR(focused_sticky_border_color)
958 SETCOLOR(active_sticky_border_color)
959 SETCOLOR(normal_sticky_border_color)
960 SETCOLOR(focused_private_border_color)
961 SETCOLOR(active_private_border_color)
962 SETCOLOR(normal_private_border_color)
963 SETCOLOR(urgent_border_color)
965 } else if (streq("focus_follows_pointer", name)) {
967 if (parse_bool(value, &b) && b != focus_follows_pointer) {
968 focus_follows_pointer = b;
969 for (monitor_t *m = mon_head; m != NULL; m = m->next)
970 for (desktop_t *d = m->desk_head; d != NULL; d = d->next)
971 for (node_t *n = first_extrema(d->root); n != NULL; n = next_leaf(n, d->root)) {
972 uint32_t values[] = {CLIENT_EVENT_MASK | (focus_follows_pointer ? XCB_EVENT_MASK_ENTER_WINDOW : 0)};
973 xcb_change_window_attributes(dpy, n->client->window, XCB_CW_EVENT_MASK, values);
975 if (focus_follows_pointer) {
976 for (monitor_t *m = mon_head; m != NULL; m = m->next)
977 window_show(m->root);
978 enable_motion_recorder();
980 for (monitor_t *m = mon_head; m != NULL; m = m->next)
981 window_hide(m->root);
982 disable_motion_recorder();
989 } else if (streq(#s, name)) { \
990 if (!parse_bool(value, &s)) \
992 SETBOOL(borderless_monocle)
993 SETBOOL(gapless_monocle)
994 SETBOOL(pointer_follows_monitor)
995 SETBOOL(apply_floating_atom)
996 SETBOOL(auto_alternate)
998 SETBOOL(history_aware_focus)
999 SETBOOL(ignore_ewmh_focus)
1000 SETBOOL(remove_disabled_monitor)
1001 SETBOOL(persistent_monitors)
1007 for (monitor_t *m = mon_head; m != NULL; m = m->next)
1008 for (desktop_t *d = m->desk_head; d != NULL; d = d->next)
1014 int get_setting(coordinates_t loc, char *name, FILE* rsp)
1016 if (streq("split_ratio", name))
1017 fprintf(rsp, "%lf", split_ratio);
1018 else if (streq("window_gap", name))
1019 if (loc.desktop == NULL)
1022 fprintf(rsp, "%i", loc.desktop->window_gap);
1023 else if (streq("border_width", name))
1024 if (loc.node != NULL)
1025 fprintf(rsp, "%u", loc.node->client->border_width);
1026 else if (loc.desktop != NULL)
1027 fprintf(rsp, "%u", loc.desktop->border_width);
1030 else if (streq("external_rules_command", name))
1031 fprintf(rsp, "%s", external_rules_command);
1032 else if (streq("status_prefix", name))
1033 fprintf(rsp, "%s", status_prefix);
1034 #define MONDESKGET(k) \
1035 else if (streq(#k, name)) \
1036 if (loc.desktop != NULL) \
1037 fprintf(rsp, "%i", loc.desktop->k); \
1038 else if (loc.monitor != NULL) \
1039 fprintf(rsp, "%i", loc.monitor->k); \
1042 MONDESKGET(top_padding)
1043 MONDESKGET(right_padding)
1044 MONDESKGET(bottom_padding)
1045 MONDESKGET(left_padding)
1047 #define GETCOLOR(s) \
1048 else if (streq(#s, name)) \
1049 fprintf(rsp, "%s", s);
1050 GETCOLOR(focused_border_color)
1051 GETCOLOR(active_border_color)
1052 GETCOLOR(normal_border_color)
1053 GETCOLOR(presel_border_color)
1054 GETCOLOR(focused_locked_border_color)
1055 GETCOLOR(active_locked_border_color)
1056 GETCOLOR(normal_locked_border_color)
1057 GETCOLOR(focused_sticky_border_color)
1058 GETCOLOR(active_sticky_border_color)
1059 GETCOLOR(normal_sticky_border_color)
1060 GETCOLOR(urgent_border_color)
1062 #define GETBOOL(s) \
1063 else if (streq(#s, name)) \
1064 fprintf(rsp, "%s", BOOLSTR(s));
1065 GETBOOL(borderless_monocle)
1066 GETBOOL(gapless_monocle)
1067 GETBOOL(focus_follows_pointer)
1068 GETBOOL(pointer_follows_monitor)
1069 GETBOOL(apply_floating_atom)
1070 GETBOOL(auto_alternate)
1071 GETBOOL(auto_cancel)
1072 GETBOOL(history_aware_focus)
1073 GETBOOL(ignore_ewmh_focus)
1074 GETBOOL(remove_disabled_monitor)
1075 GETBOOL(persistent_monitors)
1082 bool parse_bool(char *value, bool *b)
1084 if (streq("true", value) || streq("on", value)) {
1087 } else if (streq("false", value) || streq("off", value)) {
1094 bool parse_layout(char *s, layout_t *l)
1096 if (streq("monocle", s)) {
1097 *l = LAYOUT_MONOCLE;
1099 } else if (streq("tiled", s)) {
1106 bool parse_direction(char *s, direction_t *d)
1108 if (streq("right", s)) {
1111 } else if (streq("down", s)) {
1114 } else if (streq("left", s)) {
1117 } else if (streq("up", s)) {
1124 bool parse_cycle_direction(char *s, cycle_dir_t *d)
1126 if (streq("next", s)) {
1129 } else if (streq("prev", s)) {
1136 bool parse_circulate_direction(char *s, circulate_dir_t *d)
1138 if (streq("forward", s)) {
1139 *d = CIRCULATE_FORWARD;
1141 } else if (streq("backward", s)) {
1142 *d = CIRCULATE_BACKWARD;
1148 bool parse_history_direction(char *s, history_dir_t *d)
1150 if (streq("older", s)) {
1153 } else if (streq("newer", s)) {
1161 bool parse_flip(char *s, flip_t *f)
1163 if (streq("horizontal", s)) {
1164 *f = FLIP_HORIZONTAL;
1166 } else if (streq("vertical", s)) {
1173 bool parse_pointer_action(char *s, pointer_action_t *a)
1175 if (streq("move", s)) {
1178 } else if (streq("resize_corner", s)) {
1179 *a = ACTION_RESIZE_CORNER;
1181 } else if (streq("resize_side", s)) {
1182 *a = ACTION_RESIZE_SIDE;
1184 } else if (streq("focus", s)) {
1191 bool parse_degree(char *s, int *d)
1198 if ((i % 90) != 0) {
1206 bool parse_window_id(char *s, long int *i)
1210 long int ret = strtol(s, &end, 0);
1211 if (errno != 0 || *end != '\0')
1218 bool parse_bool_declaration(char *s, char **key, bool *value, alter_state_t *state)
1220 *key = strtok(s, EQL_TOK);
1221 char *v = strtok(NULL, EQL_TOK);
1223 *state = ALTER_TOGGLE;
1226 if (parse_bool(v, value)) {
1236 bool parse_index(char *s, int *i)
1239 if (sscanf(s, "^%i", &idx) != 1 || idx < 1)