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)) {
264 if (!is_tiled(trg.node->client))
267 if (!parse_direction(*args, &dir))
269 node_t *n = find_fence(trg.node, dir);
273 if ((*args)[0] == '+' || (*args)[0] == '-') {
275 if (sscanf(*args, "%i", &pix) == 1) {
276 int max = (n->split_type == TYPE_HORIZONTAL ? n->rectangle.height : n->rectangle.width);
277 double rat = ((max * n->split_ratio) + pix) / max;
278 if (rat > 0 && rat < 1)
279 n->split_ratio = rat;
287 if (sscanf(*args, "%lf", &rat) == 1 && rat > 0 && rat < 1)
288 n->split_ratio = rat;
293 } else if (streq("-r", *args) || streq("--ratio", *args)) {
298 if (sscanf(*args, "%lf", &rat) == 1 && rat > 0 && rat < 1) {
299 trg.node->split_ratio = rat;
300 window_draw_border(trg.node, trg.desktop->focus == trg.node, mon == trg.monitor);
304 } else if (streq("-R", *args) || streq("--rotate", *args)) {
309 if (!parse_direction(*args, &dir))
311 node_t *n = find_fence(trg.node, dir);
316 if (parse_degree(*args, °)) {
322 } else if (streq("-c", *args) || streq("--close", *args)) {
325 window_close(trg.node);
326 } else if (streq("-k", *args) || streq("--kill", *args)) {
329 window_kill(trg.monitor, trg.desktop, trg.node);
339 arrange(trg.monitor, trg.desktop);
344 int cmd_desktop(char **args, int num)
349 coordinates_t ref = {mon, mon->desk, NULL};
350 coordinates_t trg = ref;
352 if ((*args)[0] != OPT_CHR) {
353 if (desktop_from_desc(*args, &ref, &trg))
362 if (streq("-f", *args) || streq("--focus", *args)) {
363 coordinates_t dst = trg;
364 if (num > 1 && *(args + 1)[0] != OPT_CHR) {
366 if (!desktop_from_desc(*args, &trg, &dst))
369 if (auto_alternate && dst.desktop == mon->desk) {
370 desktop_select_t sel = {DESKTOP_STATUS_ALL, false, false};
371 history_find_desktop(HISTORY_OLDER, &trg, &dst, sel);
373 focus_node(dst.monitor, dst.desktop, dst.desktop->focus);
374 } else if (streq("-m", *args) || streq("--to-monitor", *args)) {
378 if (trg.monitor->desk_head == trg.monitor->desk_tail)
381 if (monitor_from_desc(*args, &trg, &dst)) {
382 transfer_desktop(trg.monitor, dst.monitor, trg.desktop);
383 trg.monitor = dst.monitor;
388 } else if (streq("-s", *args) || streq("--swap", *args)) {
393 if (desktop_from_desc(*args, &trg, &dst))
394 swap_desktops(trg.monitor, trg.desktop, dst.monitor, dst.desktop);
397 } else if (streq("-l", *args) || streq("--layout", *args)) {
403 if (parse_cycle_direction(*args, &cyc))
404 change_layout(trg.monitor, trg.desktop, (trg.desktop->layout + 1) % 2);
405 else if (parse_layout(*args, &lyt))
406 change_layout(trg.monitor, trg.desktop, lyt);
409 } else if (streq("-n", *args) || streq("--rename", *args)) {
413 snprintf(trg.desktop->name, sizeof(trg.desktop->name), "%s", *args);
414 ewmh_update_desktop_names();
416 } else if (streq("-r", *args) || streq("--remove", *args)) {
417 if (trg.desktop->root == NULL &&
418 trg.monitor->desk_head != trg.monitor->desk_tail) {
419 remove_desktop(trg.monitor, trg.desktop);
420 show_desktop(trg.monitor->desk);
426 } else if (streq("-c", *args) || streq("--cancel-presel", *args)) {
428 } else if (streq("-F", *args) || streq("--flip", *args)) {
433 if (parse_flip(*args, &flp)) {
434 flip_tree(trg.desktop->root, flp);
439 } else if (streq("-R", *args) || streq("--rotate", *args)) {
444 if (parse_degree(*args, °)) {
445 rotate_tree(trg.desktop->root, deg);
450 } else if (streq("-E", *args) || streq("--equalize", *args)) {
451 equalize_tree(trg.desktop->root);
453 } else if (streq("-B", *args) || streq("--balance", *args)) {
454 balance_tree(trg.desktop->root);
456 } else if (streq("-C", *args) || streq("--circulate", *args)) {
461 if (parse_circulate_direction(*args, &cir)) {
462 circulate_leaves(trg.monitor, trg.desktop, cir);
467 } else if (streq("-t", *args) || streq("--toggle", *args)) {
471 char *key = strtok(*args, EQL_TOK);
472 char *val = strtok(NULL, EQL_TOK);
478 if (parse_bool(val, &b))
483 if (streq("floating", key))
484 trg.desktop->floating = (a == ALTER_SET ? b : !trg.desktop->floating);
494 arrange(trg.monitor, trg.desktop);
499 int cmd_monitor(char **args, int num)
504 coordinates_t ref = {mon, NULL, NULL};
505 coordinates_t trg = ref;
507 if ((*args)[0] != OPT_CHR) {
508 if (monitor_from_desc(*args, &ref, &trg))
515 if (streq("-f", *args) || streq("--focus", *args)) {
516 coordinates_t dst = trg;
517 if (num > 1 && *(args + 1)[0] != OPT_CHR) {
519 if (!monitor_from_desc(*args, &trg, &dst))
522 if (auto_alternate && dst.monitor == mon) {
523 desktop_select_t sel = {DESKTOP_STATUS_ALL, false, false};
524 history_find_monitor(HISTORY_OLDER, &trg, &dst, sel);
526 focus_node(dst.monitor, dst.monitor->desk, dst.monitor->desk->focus);
527 } else if (streq("-d", *args) || streq("--reset-desktops", *args)) {
531 desktop_t *d = trg.monitor->desk_head;
532 while (num > 0 && d != NULL) {
533 snprintf(d->name, sizeof(d->name), "%s", *args);
534 initialize_desktop(d);
535 arrange(trg.monitor, d);
541 add_desktop(trg.monitor, make_desktop(*args));
545 desktop_t *next = d->next;
547 focus_node(trg.monitor, d->prev, d->prev->focus);
548 merge_desktops(trg.monitor, d, mon, mon->desk);
549 remove_desktop(trg.monitor, d);
552 } else if (streq("-a", *args) || streq("--add-desktops", *args)) {
557 add_desktop(trg.monitor, make_desktop(*args));
560 } else if (streq("-r", *args) || streq("--remove-desktops", *args)) {
566 if (locate_desktop(*args, &dst) && dst.monitor->desk_head != dst.monitor->desk_tail && dst.desktop->root == NULL) {
567 remove_desktop(dst.monitor, dst.desktop);
568 show_desktop(dst.monitor->desk);
572 } else if (streq("-o", *args) || streq("--order-desktops", *args)) {
576 desktop_t *d = trg.monitor->desk_head;
577 while (d != NULL && num > 0) {
578 desktop_t *next = d->next;
580 if (locate_desktop(*args, &dst) && dst.monitor == trg.monitor) {
581 swap_desktops(trg.monitor, d, dst.monitor, dst.desktop);
582 if (next == dst.desktop)
588 } else if (streq("-n", *args) || streq("--rename", *args)) {
592 snprintf(trg.monitor->name, sizeof(trg.monitor->name), "%s", *args);
594 } else if (streq("-s", *args) || streq("--swap", *args)) {
599 if (monitor_from_desc(*args, &trg, &dst))
600 swap_monitors(trg.monitor, dst.monitor);
612 int cmd_query(char **args, int num, FILE *rsp)
614 coordinates_t ref = {mon, mon->desk, mon->desk->focus};
615 coordinates_t trg = {NULL, NULL, NULL};
616 domain_t dom = DOMAIN_TREE;
620 if (streq("-T", *args) || streq("--tree", *args)) {
621 dom = DOMAIN_TREE, d++;
622 } else if (streq("-M", *args) || streq("--monitors", *args)) {
623 dom = DOMAIN_MONITOR, d++;
624 } else if (streq("-D", *args) || streq("--desktops", *args)) {
625 dom = DOMAIN_DESKTOP, d++;
626 } else if (streq("-W", *args) || streq("--windows", *args)) {
627 dom = DOMAIN_WINDOW, d++;
628 } else if (streq("-H", *args) || streq("--history", *args)) {
629 dom = DOMAIN_HISTORY, d++;
630 } else if (streq("-S", *args) || streq("--stack", *args)) {
631 dom = DOMAIN_STACK, d++;
632 } else if (streq("-m", *args) || streq("--monitor", *args)) {
633 trg.monitor = ref.monitor;
634 if (num > 1 && *(args + 1)[0] != OPT_CHR) {
636 if (!monitor_from_desc(*args, &ref, &trg))
640 } else if (streq("-d", *args) || streq("--desktop", *args)) {
641 trg.monitor = ref.monitor;
642 trg.desktop = ref.desktop;
643 if (num > 1 && *(args + 1)[0] != OPT_CHR) {
645 if (!desktop_from_desc(*args, &ref, &trg))
649 } else if (streq("-w", *args) || streq("--window", *args)) {
651 if (num > 1 && *(args + 1)[0] != OPT_CHR) {
653 if (!node_from_desc(*args, &ref, &trg))
666 if (dom == DOMAIN_HISTORY)
667 query_history(trg, rsp);
668 else if (dom == DOMAIN_STACK)
670 else if (dom == DOMAIN_WINDOW)
671 query_windows(trg, rsp);
673 query_monitors(trg, dom, rsp);
678 int cmd_rule(char **args, int num, FILE *rsp)
683 if (streq("-a", *args) || streq("--add", *args)) {
687 rule_t *rule = make_rule();
688 snprintf(rule->cause, sizeof(rule->cause), "%s", *args);
692 if (streq("-o", *args) || streq("--one-shot", *args)) {
693 rule->one_shot = true;
695 for (size_t j = 0; i < sizeof(rule->effect) && j < strlen(*args); i++, j++)
696 rule->effect[i] = (*args)[j];
697 if (num > 1 && i < sizeof(rule->effect))
698 rule->effect[i++] = ' ';
702 rule->effect[MIN(i, sizeof(rule->effect) - 1)] = '\0';
704 } else if (streq("-r", *args) || streq("--remove", *args)) {
710 if (parse_index(*args, &idx))
711 remove_rule_by_index(idx - 1);
712 else if (streq("tail", *args))
713 remove_rule(rule_tail);
714 else if (streq("head", *args))
715 remove_rule(rule_head);
717 remove_rule_by_cause(*args);
720 } else if (streq("-l", *args) || streq("--list", *args)) {
722 list_rules(num > 0 ? *args : NULL, rsp);
732 int cmd_pointer(char **args, int num)
737 if (streq("-t", *args) || streq("--track", *args)) {
742 if (sscanf(*args, "%i", &x) == 1 && sscanf(*(args + 1), "%i", &y) == 1)
747 } else if (streq("-g", *args) || streq("--grab", *args)) {
751 pointer_action_t pac;
752 if (parse_pointer_action(*args, &pac))
756 } else if (streq("-u", *args) || streq("--ungrab", *args)) {
767 int cmd_restore(char **args, int num)
772 if (streq("-T", *args) || streq("--tree", *args)) {
777 } else if (streq("-H", *args) || streq("--history", *args)) {
781 restore_history(*args);
782 } else if (streq("-S", *args) || streq("--stack", *args)) {
786 restore_stack(*args);
796 int cmd_control(char **args, int num, FILE *rsp)
801 if (streq("--adopt-orphans", *args)) {
803 } else if (streq("--toggle-visibility", *args)) {
805 } else if (streq("--subscribe", *args)) {
806 return MSG_SUBSCRIBE;
807 } else if (streq("--get-status", *args)) {
809 } else if (streq("--record-history", *args)) {
814 if (parse_bool(*args, &b))
827 int cmd_config(char **args, int num, FILE *rsp)
831 coordinates_t ref = {mon, mon->desk, mon->desk->focus};
832 coordinates_t trg = {NULL, NULL, NULL};
833 if ((*args)[0] == OPT_CHR) {
834 if (streq("-m", *args) || streq("--monitor", *args)) {
838 if (!monitor_from_desc(*args, &ref, &trg))
840 } else if (streq("-d", *args) || streq("--desktop", *args)) {
844 if (!desktop_from_desc(*args, &ref, &trg))
846 } else if (streq("-w", *args) || streq("--window", *args)) {
850 if (!node_from_desc(*args, &ref, &trg))
858 return set_setting(trg, *args, *(args + 1));
860 return get_setting(trg, *args, rsp);
865 int cmd_quit(char **args, int num)
867 if (num > 0 && sscanf(*args, "%i", &exit_status) != 1)
873 int set_setting(coordinates_t loc, char *name, char *value)
875 #define DESKWINDEFSET(k, v) \
876 if (loc.node != NULL) \
877 loc.node->client->k = v; \
878 else if (loc.desktop != NULL) \
879 loc.desktop->k = v; \
880 else if (loc.monitor != NULL) \
881 for (desktop_t *d = loc.monitor->desk_head; d != NULL; d = d->next) \
885 if (streq("border_width", name)) {
887 if (sscanf(value, "%u", &bw) != 1)
889 DESKWINDEFSET(border_width, bw)
891 #define DESKDEFSET(k, v) \
892 if (loc.desktop != NULL) \
893 loc.desktop->k = v; \
894 else if (loc.monitor != NULL) \
895 for (desktop_t *d = loc.monitor->desk_head; d != NULL; d = d->next) \
899 } else if (streq("window_gap", name)) {
901 if (sscanf(value, "%i", &wg) != 1)
903 DESKDEFSET(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(focus_by_distance)
1000 SETBOOL(ignore_ewmh_focus)
1002 #define SETMONBOOL(s) \
1003 } else if (streq(#s, name)) { \
1004 if (!parse_bool(value, &s)) \
1005 return MSG_FAILURE; \
1008 SETMONBOOL(remove_disabled_monitors)
1009 SETMONBOOL(remove_unplugged_monitors)
1010 SETMONBOOL(merge_overlapping_monitors)
1016 for (monitor_t *m = mon_head; m != NULL; m = m->next)
1017 for (desktop_t *d = m->desk_head; d != NULL; d = d->next)
1023 int get_setting(coordinates_t loc, char *name, FILE* rsp)
1025 if (streq("split_ratio", name))
1026 fprintf(rsp, "%lf", split_ratio);
1027 else if (streq("window_gap", name))
1028 if (loc.desktop != NULL)
1029 fprintf(rsp, "%i", loc.desktop->window_gap);
1031 fprintf(rsp, "%i", window_gap);
1032 else if (streq("border_width", name))
1033 if (loc.node != NULL)
1034 fprintf(rsp, "%u", loc.node->client->border_width);
1035 else if (loc.desktop != NULL)
1036 fprintf(rsp, "%u", loc.desktop->border_width);
1038 fprintf(rsp, "%u", border_width);
1039 else if (streq("external_rules_command", name))
1040 fprintf(rsp, "%s", external_rules_command);
1041 else if (streq("status_prefix", name))
1042 fprintf(rsp, "%s", status_prefix);
1043 #define MONDESKGET(k) \
1044 else if (streq(#k, name)) \
1045 if (loc.desktop != NULL) \
1046 fprintf(rsp, "%i", loc.desktop->k); \
1047 else if (loc.monitor != NULL) \
1048 fprintf(rsp, "%i", loc.monitor->k); \
1051 MONDESKGET(top_padding)
1052 MONDESKGET(right_padding)
1053 MONDESKGET(bottom_padding)
1054 MONDESKGET(left_padding)
1056 #define GETCOLOR(s) \
1057 else if (streq(#s, name)) \
1058 fprintf(rsp, "%s", s);
1059 GETCOLOR(focused_border_color)
1060 GETCOLOR(active_border_color)
1061 GETCOLOR(normal_border_color)
1062 GETCOLOR(presel_border_color)
1063 GETCOLOR(focused_locked_border_color)
1064 GETCOLOR(active_locked_border_color)
1065 GETCOLOR(normal_locked_border_color)
1066 GETCOLOR(focused_sticky_border_color)
1067 GETCOLOR(active_sticky_border_color)
1068 GETCOLOR(normal_sticky_border_color)
1069 GETCOLOR(urgent_border_color)
1071 #define GETBOOL(s) \
1072 else if (streq(#s, name)) \
1073 fprintf(rsp, "%s", BOOLSTR(s));
1074 GETBOOL(borderless_monocle)
1075 GETBOOL(gapless_monocle)
1076 GETBOOL(focus_follows_pointer)
1077 GETBOOL(pointer_follows_monitor)
1078 GETBOOL(apply_floating_atom)
1079 GETBOOL(auto_alternate)
1080 GETBOOL(auto_cancel)
1081 GETBOOL(history_aware_focus)
1082 GETBOOL(focus_by_distance)
1083 GETBOOL(ignore_ewmh_focus)
1084 GETBOOL(remove_disabled_monitors)
1085 GETBOOL(remove_unplugged_monitors)
1086 GETBOOL(merge_overlapping_monitors)
1093 bool parse_bool(char *value, bool *b)
1095 if (streq("true", value) || streq("on", value)) {
1098 } else if (streq("false", value) || streq("off", value)) {
1105 bool parse_layout(char *s, layout_t *l)
1107 if (streq("monocle", s)) {
1108 *l = LAYOUT_MONOCLE;
1110 } else if (streq("tiled", s)) {
1117 bool parse_direction(char *s, direction_t *d)
1119 if (streq("right", s)) {
1122 } else if (streq("down", s)) {
1125 } else if (streq("left", s)) {
1128 } else if (streq("up", s)) {
1135 bool parse_cycle_direction(char *s, cycle_dir_t *d)
1137 if (streq("next", s)) {
1140 } else if (streq("prev", s)) {
1147 bool parse_circulate_direction(char *s, circulate_dir_t *d)
1149 if (streq("forward", s)) {
1150 *d = CIRCULATE_FORWARD;
1152 } else if (streq("backward", s)) {
1153 *d = CIRCULATE_BACKWARD;
1159 bool parse_history_direction(char *s, history_dir_t *d)
1161 if (streq("older", s)) {
1164 } else if (streq("newer", s)) {
1172 bool parse_flip(char *s, flip_t *f)
1174 if (streq("horizontal", s)) {
1175 *f = FLIP_HORIZONTAL;
1177 } else if (streq("vertical", s)) {
1184 bool parse_pointer_action(char *s, pointer_action_t *a)
1186 if (streq("move", s)) {
1189 } else if (streq("resize_corner", s)) {
1190 *a = ACTION_RESIZE_CORNER;
1192 } else if (streq("resize_side", s)) {
1193 *a = ACTION_RESIZE_SIDE;
1195 } else if (streq("focus", s)) {
1202 bool parse_degree(char *s, int *d)
1209 if ((i % 90) != 0) {
1217 bool parse_window_id(char *s, long int *i)
1221 long int ret = strtol(s, &end, 0);
1222 if (errno != 0 || *end != '\0')
1229 bool parse_bool_declaration(char *s, char **key, bool *value, alter_state_t *state)
1231 *key = strtok(s, EQL_TOK);
1232 char *v = strtok(NULL, EQL_TOK);
1234 *state = ALTER_TOGGLE;
1237 if (parse_bool(v, value)) {
1247 bool parse_index(char *s, int *i)
1250 if (sscanf(s, "^%i", &idx) != 1 || idx < 1)