1 /* * Copyright (c) 2012-2013 Bastien Dejean
4 * Redistribution and use in source and binary forms, with or without modification,
5 * are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright notice, this
8 * list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright notice,
10 * this list of conditions and the following disclaimer in the documentation and/or
11 * other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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 ON
20 * 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.
43 bool handle_message(char *msg, int msg_len, char *rsp)
47 char **args = malloc(cap * sizeof(char *));
51 for (int i = 0, j = 0; i < msg_len; i++) {
53 args[num++] = msg + j;
58 char **new = realloc(args, cap * sizeof(char *));
73 char **args_orig = args;
74 bool ret = process_message(args, num, rsp);
79 bool process_message(char **args, int num, char *rsp)
81 if (streq("window", *args)) {
82 return cmd_window(++args, --num);
83 } else if (streq("desktop", *args)) {
84 return cmd_desktop(++args, --num);
85 } else if (streq("monitor", *args)) {
86 return cmd_monitor(++args, --num);
87 } else if (streq("query", *args)) {
88 return cmd_query(++args, --num, rsp);
89 } else if (streq("restore", *args)) {
90 return cmd_restore(++args, --num);
91 } else if (streq("control", *args)) {
92 return cmd_control(++args, --num, rsp);
93 } else if (streq("rule", *args)) {
94 return cmd_rule(++args, --num, rsp);
95 } else if (streq("pointer", *args)) {
96 return cmd_pointer(++args, --num);
97 } else if (streq("config", *args)) {
98 return cmd_config(++args, --num, rsp);
99 } else if (streq("quit", *args)) {
100 return cmd_quit(++args, --num);
106 bool cmd_window(char **args, int num)
111 coordinates_t ref = {mon, mon->desk, mon->desk->focus};
112 coordinates_t trg = ref;
114 if ((*args)[0] != OPT_CHR) {
115 if (node_from_desc(*args, &ref, &trg))
121 if (trg.node == NULL)
127 if (streq("-f", *args) || streq("--focus", *args)) {
128 coordinates_t dst = trg;
129 if (num > 1 && *(args + 1)[0] != OPT_CHR) {
131 if (!node_from_desc(*args, &trg, &dst))
134 focus_node(dst.monitor, dst.desktop, dst.node);
135 } else if (streq("-d", *args) || streq("--to-desktop", *args)) {
138 if (desktop_from_desc(*args, &trg, &dst)) {
139 if (transfer_node(trg.monitor, trg.desktop, trg.node, dst.monitor, dst.desktop, dst.desktop->focus)) {
140 trg.monitor = dst.monitor;
141 trg.desktop = dst.desktop;
146 } else if (streq("-m", *args) || streq("--to-monitor", *args)) {
151 if (monitor_from_desc(*args, &trg, &dst)) {
152 if (transfer_node(trg.monitor, trg.desktop, trg.node, dst.monitor, dst.monitor->desk, dst.monitor->desk->focus)) {
153 trg.monitor = dst.monitor;
154 trg.desktop = dst.monitor->desk;
159 } else if (streq("-w", *args) || streq("--to-window", *args)) {
164 if (node_from_desc(*args, &trg, &dst)) {
165 if (transfer_node(trg.monitor, trg.desktop, trg.node, dst.monitor, dst.desktop, dst.node)) {
166 trg.monitor = dst.monitor;
167 trg.desktop = dst.desktop;
172 } else if (streq("-s", *args) || streq("--swap", *args)) {
177 if (node_from_desc(*args, &trg, &dst)) {
178 if (swap_nodes(trg.monitor, trg.desktop, trg.node, dst.monitor, dst.desktop, dst.node)) {
179 if (trg.desktop != dst.desktop)
180 arrange(trg.monitor, trg.desktop);
181 trg.monitor = dst.monitor;
182 trg.desktop = dst.desktop;
188 } else if (streq("-t", *args) || streq("--toggle", *args)) {
192 char *key = strtok(*args, EQL_TOK);
193 char *val = strtok(NULL, EQL_TOK);
199 if (parse_bool(val, &b))
204 if (streq("fullscreen", key)) {
205 set_fullscreen(trg.node, (a == ALTER_SET ? b : !trg.node->client->fullscreen));
207 } else if (streq("floating", key)) {
208 set_floating(trg.node, (a == ALTER_SET ? b : !trg.node->client->floating));
210 } else if (streq("locked", key)) {
211 set_locked(trg.monitor, trg.desktop, trg.node, (a == ALTER_SET ? b : !trg.node->client->locked));
212 } else if (streq("sticky", key)) {
213 set_sticky(trg.monitor, trg.desktop, trg.node, (a == ALTER_SET ? b : !trg.node->client->sticky));
214 } else if (streq("private", key)) {
215 set_private(trg.monitor, trg.desktop, trg.node, (a == ALTER_SET ? b : !trg.node->client->private));
219 } else if (streq("-p", *args) || streq("--presel", *args)) {
221 if (num < 1 || !is_tiled(trg.node->client)
222 || trg.desktop->layout != LAYOUT_TILED)
224 if (streq("cancel", *args)) {
228 if (parse_direction(*args, &dir)) {
229 double rat = trg.node->split_ratio;
230 if (num > 1 && *(args + 1)[0] != OPT_CHR) {
232 if (sscanf(*args, "%lf", &rat) != 1 || rat <= 0 || rat >= 1)
235 if (auto_cancel && trg.node->split_mode == MODE_MANUAL
236 && dir == trg.node->split_dir
237 && rat == trg.node->split_ratio) {
240 trg.node->split_mode = MODE_MANUAL;
241 trg.node->split_dir = dir;
242 trg.node->split_ratio = rat;
244 window_draw_border(trg.node, trg.desktop->focus == trg.node, mon == trg.monitor);
249 } else if (streq("-e", *args) || streq("--edge", *args)) {
254 if (!parse_direction(*args, &dir))
256 node_t *n = find_fence(trg.node, dir);
261 if (parse_fence_move(*args, &fmo)) {
262 move_fence(n, dir, fmo);
264 if ((*args)[0] == '+' || (*args)[0] == '-') {
266 if (sscanf(*args, "%i", &pix) == 1) {
267 int max = (n->split_type == TYPE_HORIZONTAL ? n->rectangle.height : n->rectangle.width);
268 double rat = ((max * n->split_ratio) + pix) / max;
269 if (rat > 0 && rat < 1)
270 n->split_ratio = rat;
279 if (sscanf(*args, "%lf", &rat) == 1 && rat > 0 && rat < 1)
280 n->split_ratio = rat;
286 } else if (streq("-r", *args) || streq("--ratio", *args)) {
291 if (sscanf(*args, "%lf", &rat) == 1 && rat > 0 && rat < 1) {
292 trg.node->split_ratio = rat;
293 window_draw_border(trg.node, trg.desktop->focus == trg.node, mon == trg.monitor);
297 } else if (streq("-R", *args) || streq("--rotate", *args)) {
302 if (!parse_direction(*args, &dir))
304 node_t *n = find_fence(trg.node, dir);
309 if (parse_degree(*args, °)) {
315 } else if (streq("-c", *args) || streq("--close", *args)) {
318 window_close(trg.node);
319 } else if (streq("-k", *args) || streq("--kill", *args)) {
322 window_kill(trg.monitor, trg.desktop, trg.node);
332 arrange(trg.monitor, trg.desktop);
337 bool cmd_desktop(char **args, int num)
342 coordinates_t ref = {mon, mon->desk, NULL};
343 coordinates_t trg = ref;
345 if ((*args)[0] != OPT_CHR) {
346 if (desktop_from_desc(*args, &ref, &trg))
355 if (streq("-f", *args) || streq("--focus", *args)) {
356 coordinates_t dst = trg;
357 if (num > 1 && *(args + 1)[0] != OPT_CHR) {
359 if (!desktop_from_desc(*args, &trg, &dst))
362 if (auto_alternate && dst.desktop == mon->desk) {
363 desktop_select_t sel = {DESKTOP_STATUS_ALL, false, false};
364 history_find_desktop(HISTORY_OLDER, &trg, &dst, sel);
366 focus_node(dst.monitor, dst.desktop, dst.desktop->focus);
367 } else if (streq("-m", *args) || streq("--to-monitor", *args)) {
369 if (num < 1 || trg.monitor->desk_head == trg.monitor->desk_tail)
372 if (monitor_from_desc(*args, &trg, &dst)) {
373 transfer_desktop(trg.monitor, dst.monitor, trg.desktop);
374 trg.monitor = dst.monitor;
379 } else if (streq("-s", *args) || streq("--swap", *args)) {
384 if (desktop_from_desc(*args, &trg, &dst) && trg.monitor == dst.monitor)
385 swap_desktops(trg.monitor, trg.desktop, dst.monitor, dst.desktop);
388 } else if (streq("-l", *args) || streq("--layout", *args)) {
394 if (parse_cycle_direction(*args, &cyc))
395 change_layout(trg.monitor, trg.desktop, (trg.desktop->layout + 1) % 2);
396 else if (parse_layout(*args, &lyt))
397 change_layout(trg.monitor, trg.desktop, lyt);
400 } else if (streq("-n", *args) || streq("--rename", *args)) {
404 snprintf(trg.desktop->name, sizeof(trg.desktop->name), "%s", *args);
405 ewmh_update_desktop_names();
407 } else if (streq("-r", *args) || streq("--remove", *args)) {
408 if (trg.desktop->root == NULL
409 && trg.monitor->desk_head != trg.monitor->desk_tail) {
410 remove_desktop(trg.monitor, trg.desktop);
411 show_desktop(trg.monitor->desk);
417 } else if (streq("-c", *args) || streq("--cancel-presel", *args)) {
419 } else if (streq("-F", *args) || streq("--flip", *args)) {
424 if (parse_flip(*args, &flp)) {
425 flip_tree(trg.desktop->root, flp);
430 } else if (streq("-R", *args) || streq("--rotate", *args)) {
435 if (parse_degree(*args, °)) {
436 rotate_tree(trg.desktop->root, deg);
441 } else if (streq("-B", *args) || streq("--balance", *args)) {
442 balance_tree(trg.desktop->root);
444 } else if (streq("-C", *args) || streq("--circulate", *args)) {
449 if (parse_circulate_direction(*args, &cir)) {
450 circulate_leaves(trg.monitor, trg.desktop, cir);
455 } else if (streq("-t", *args) || streq("--toggle", *args)) {
459 char *key = strtok(*args, EQL_TOK);
460 char *val = strtok(NULL, EQL_TOK);
466 if (parse_bool(val, &b))
471 if (streq("floating", key))
472 trg.desktop->floating = (a == ALTER_SET ? b : !trg.desktop->floating);
482 arrange(trg.monitor, trg.desktop);
487 bool cmd_monitor(char **args, int num)
492 coordinates_t ref = {mon, NULL, NULL};
493 coordinates_t trg = ref;
495 if ((*args)[0] != OPT_CHR) {
496 if (monitor_from_desc(*args, &ref, &trg))
503 if (streq("-f", *args) || streq("--focus", *args)) {
504 coordinates_t dst = trg;
505 if (num > 1 && *(args + 1)[0] != OPT_CHR) {
507 if (!monitor_from_desc(*args, &trg, &dst))
510 if (auto_alternate && dst.monitor == mon) {
511 desktop_select_t sel = {DESKTOP_STATUS_ALL, false, false};
512 history_find_monitor(HISTORY_OLDER, &trg, &dst, sel);
514 focus_node(dst.monitor, dst.monitor->desk, dst.monitor->desk->focus);
515 } else if (streq("-d", *args) || streq("--reset-desktops", *args)) {
519 desktop_t *d = trg.monitor->desk_head;
520 while (num > 0 && d != NULL) {
521 snprintf(d->name, sizeof(d->name), "%s", *args);
527 add_desktop(trg.monitor, make_desktop(*args));
531 desktop_t *next = d->next;
533 focus_node(trg.monitor, d->prev, d->prev->focus);
534 merge_desktops(trg.monitor, d, mon, mon->desk);
535 remove_desktop(trg.monitor, d);
538 } else if (streq("-a", *args) || streq("--add-desktops", *args)) {
543 add_desktop(trg.monitor, make_desktop(*args));
546 } else if (streq("-r", *args) || streq("--remove-desktops", *args)) {
552 if (locate_desktop(*args, &dst) && dst.monitor->desk_head != dst.monitor->desk_tail && dst.desktop->root == NULL) {
553 remove_desktop(dst.monitor, dst.desktop);
554 show_desktop(dst.monitor->desk);
558 } else if (streq("-o", *args) || streq("--order-desktops", *args)) {
562 desktop_t *d = trg.monitor->desk_head;
563 while (d != NULL && num > 0) {
564 desktop_t *next = d->next;
566 if (locate_desktop(*args, &dst) && dst.monitor == trg.monitor) {
567 swap_desktops(trg.monitor, d, dst.monitor, dst.desktop);
568 if (next == dst.desktop)
574 } else if (streq("-n", *args) || streq("--rename", *args)) {
578 snprintf(trg.monitor->name, sizeof(trg.monitor->name), "%s", *args);
580 } else if (streq("-s", *args) || streq("--swap", *args)) {
585 if (monitor_from_desc(*args, &trg, &dst))
586 swap_monitors(trg.monitor, dst.monitor);
598 bool cmd_query(char **args, int num, char *rsp)
600 coordinates_t ref = {mon, mon->desk, mon->desk->focus};
601 coordinates_t trg = {NULL, NULL, NULL};
602 domain_t dom = DOMAIN_TREE;
606 if (streq("-T", *args) || streq("--tree", *args)) {
607 dom = DOMAIN_TREE, d++;
608 } else if (streq("-M", *args) || streq("--monitors", *args)) {
609 dom = DOMAIN_MONITOR, d++;
610 } else if (streq("-D", *args) || streq("--desktops", *args)) {
611 dom = DOMAIN_DESKTOP, d++;
612 } else if (streq("-W", *args) || streq("--windows", *args)) {
613 dom = DOMAIN_WINDOW, d++;
614 } else if (streq("-H", *args) || streq("--history", *args)) {
615 dom = DOMAIN_HISTORY, d++;
616 } else if (streq("-S", *args) || streq("--stack", *args)) {
617 dom = DOMAIN_STACK, d++;
618 } else if (streq("-m", *args) || streq("--monitor", *args)) {
619 trg.monitor = ref.monitor;
620 if (num > 1 && *(args + 1)[0] != OPT_CHR) {
622 if (!monitor_from_desc(*args, &ref, &trg))
626 } else if (streq("-d", *args) || streq("--desktop", *args)) {
627 trg.monitor = ref.monitor;
628 trg.desktop = ref.desktop;
629 if (num > 1 && *(args + 1)[0] != OPT_CHR) {
631 if (!desktop_from_desc(*args, &ref, &trg))
635 } else if (streq("-w", *args) || streq("--window", *args)) {
637 if (num > 1 && *(args + 1)[0] != OPT_CHR) {
639 if (!node_from_desc(*args, &ref, &trg))
652 if (dom == DOMAIN_HISTORY)
653 query_history(trg, rsp);
654 else if (dom == DOMAIN_STACK)
656 else if (dom == DOMAIN_WINDOW)
657 query_windows(trg, rsp);
659 query_monitors(trg, dom, rsp);
664 bool cmd_rule(char **args, int num, char *rsp)
669 if (streq("-a", *args) || streq("--add", *args)) {
673 rule_t *rule = make_rule();
674 snprintf(rule->cause, sizeof(rule->cause), "%s", *args);
678 if (streq("-o", *args) || streq("--one-shot", *args)) {
679 rule->one_shot = true;
681 for (size_t j = 0; i < sizeof(rule->effect) && j < strlen(*args); i++, j++)
682 rule->effect[i] = (*args)[j];
683 if (num > 1 && i < sizeof(rule->effect))
684 rule->effect[i++] = ' ';
688 rule->effect[MIN(i, sizeof(rule->effect) - 1)] = '\0';
690 } else if (streq("-r", *args) || streq("--remove", *args)) {
696 if (parse_index(*args, &idx))
697 remove_rule_by_index(idx - 1);
698 else if (streq("tail", *args))
699 remove_rule(rule_tail);
700 else if (streq("head", *args))
701 remove_rule(rule_head);
703 remove_rule_by_cause(*args);
706 } else if (streq("-l", *args) || streq("--list", *args)) {
708 list_rules(num > 0 ? *args : NULL, rsp);
718 bool cmd_pointer(char **args, int num)
723 if (streq("-t", *args) || streq("--track", *args)) {
728 if (sscanf(*args, "%i", &x) == 1 && sscanf(*(args + 1), "%i", &y) == 1)
732 } else if (streq("-g", *args) || streq("--grab", *args)) {
736 pointer_action_t pac;
737 if (parse_pointer_action(*args, &pac))
741 } else if (streq("-u", *args) || streq("--ungrab", *args)) {
752 bool cmd_restore(char **args, int num)
757 if (streq("-T", *args) || streq("--tree", *args)) {
762 } else if (streq("-H", *args) || streq("--history", *args)) {
766 restore_history(*args);
767 } else if (streq("-S", *args) || streq("--stack", *args)) {
771 restore_stack(*args);
781 bool cmd_control(char **args, int num, char *rsp)
786 if (streq("--adopt-orphans", *args)) {
788 } else if (streq("--put-status", *args)) {
790 } else if (streq("--toggle-visibility", *args)) {
792 } else if (streq("--subscribe", *args)) {
793 snprintf(rsp, BUFSIZ, "%c", MESSAGE_SUBSCRIBE);
794 } else if (streq("--record-history", *args)) {
799 if (parse_bool(*args, &b))
812 bool cmd_config(char **args, int num, char *rsp)
816 coordinates_t ref = {mon, mon->desk, mon->desk->focus};
817 coordinates_t trg = {NULL, NULL, NULL};
818 if ((*args)[0] == OPT_CHR) {
819 if (streq("-d", *args) || streq("--desktop", *args)) {
823 if (!desktop_from_desc(*args, &ref, &trg))
825 } else if (streq("-m", *args) || streq("--monitor", *args)) {
829 if (!monitor_from_desc(*args, &ref, &trg))
837 return set_setting(trg, *args, *(args + 1));
839 return get_setting(trg, *args, rsp);
844 bool cmd_quit(char **args, int num)
846 if (num > 0 && sscanf(*args, "%i", &exit_status) != 1)
852 bool set_setting(coordinates_t loc, char *name, char *value)
854 #define DESKSET(k, v) \
855 if (loc.desktop != NULL) \
856 loc.desktop->k = v; \
857 else if (loc.monitor != NULL) \
858 for (desktop_t *d = loc.monitor->desk_head; d != NULL; d = d->next) \
861 for (monitor_t *m = mon_head; m != NULL; m = m->next) \
862 for (desktop_t *d = m->desk_head; d != NULL; d = d->next) \
864 if (streq("border_width", name)) {
866 if (sscanf(value, "%u", &bw) != 1)
868 DESKSET(border_width, bw)
869 } else if (streq("window_gap", name)) {
871 if (sscanf(value, "%i", &wg) != 1)
873 DESKSET(window_gap, wg)
876 } else if (streq(#k, name)) { \
878 if (sscanf(value, "%i", &v) != 1) \
880 if (loc.monitor != NULL) \
881 loc.monitor->k = v; \
883 for (monitor_t *m = mon_head; m!= NULL; m = m->next) \
886 MONSET(right_padding)
887 MONSET(bottom_padding)
891 } else if (streq(#s, name)) { \
892 return snprintf(s, sizeof(s), "%s", value) >= 0;
893 SETSTR(external_rules_command)
894 SETSTR(status_prefix)
896 } else if (streq("split_ratio", name)) {
898 if (sscanf(value, "%lf", &r) == 1 && r > 0 && r < 1)
903 } else if (streq("growth_factor", name)) {
905 if (sscanf(value, "%lf", &g) == 1 && g > 1)
910 #define SETOPACITY(s) \
911 } else if (streq(#s, name)) { \
913 if (sscanf(value, "%lf", &o) == 1 && o >= 0 && o <= 1) \
917 SETOPACITY(focused_frame_opacity)
918 SETOPACITY(active_frame_opacity)
919 SETOPACITY(normal_frame_opacity)
921 #define SETCOLOR(s) \
922 } else if (streq(#s, name)) { \
923 snprintf(s, sizeof(s), "%s", value);
924 SETCOLOR(focused_border_color)
925 SETCOLOR(active_border_color)
926 SETCOLOR(normal_border_color)
927 SETCOLOR(presel_border_color)
928 SETCOLOR(focused_locked_border_color)
929 SETCOLOR(active_locked_border_color)
930 SETCOLOR(normal_locked_border_color)
931 SETCOLOR(focused_sticky_border_color)
932 SETCOLOR(active_sticky_border_color)
933 SETCOLOR(normal_sticky_border_color)
934 SETCOLOR(focused_private_border_color)
935 SETCOLOR(active_private_border_color)
936 SETCOLOR(normal_private_border_color)
937 SETCOLOR(urgent_border_color)
939 } else if (streq("focus_follows_pointer", name)) {
941 if (parse_bool(value, &b) && b != focus_follows_pointer) {
942 focus_follows_pointer = b;
943 for (monitor_t *m = mon_head; m != NULL; m = m->next)
944 for (desktop_t *d = m->desk_head; d != NULL; d = d->next)
945 for (node_t *n = first_extrema(d->root); n != NULL; n = next_leaf(n, d->root)) {
946 uint32_t values[] = {get_event_mask(n->client)};
947 xcb_change_window_attributes(dpy, n->client->window, XCB_CW_EVENT_MASK, values);
949 if (focus_follows_pointer) {
950 for (monitor_t *m = mon_head; m != NULL; m = m->next)
951 window_show(m->root);
952 enable_motion_recorder();
954 for (monitor_t *m = mon_head; m != NULL; m = m->next)
955 window_hide(m->root);
956 disable_motion_recorder();
963 } else if (streq(#s, name)) { \
964 if (!parse_bool(value, &s)) \
966 SETBOOL(borderless_monocle)
967 SETBOOL(gapless_monocle)
968 SETBOOL(pointer_follows_monitor)
969 SETBOOL(apply_floating_atom)
970 SETBOOL(auto_alternate)
972 SETBOOL(history_aware_focus)
973 SETBOOL(ignore_ewmh_focus)
974 SETBOOL(remove_disabled_monitor)
980 for (monitor_t *m = mon_head; m != NULL; m = m->next)
981 for (desktop_t *d = m->desk_head; d != NULL; d = d->next)
987 bool get_setting(coordinates_t loc, char *name, char* rsp)
989 if (streq("split_ratio", name))
990 snprintf(rsp, BUFSIZ, "%lf", split_ratio);
991 else if (streq("growth_factor", name))
992 snprintf(rsp, BUFSIZ, "%lf", growth_factor);
993 else if (streq("window_gap", name))
994 if (loc.desktop == NULL)
997 snprintf(rsp, BUFSIZ, "%i", loc.desktop->window_gap);
998 else if (streq("border_width", name))
999 if (loc.desktop == NULL)
1002 snprintf(rsp, BUFSIZ, "%u", loc.desktop->border_width);
1003 else if (streq("external_rules_command", name))
1004 snprintf(rsp, BUFSIZ, "%s", external_rules_command);
1005 else if (streq("status_prefix", name))
1006 snprintf(rsp, BUFSIZ, "%s", status_prefix);
1008 else if (streq(#k, name)) \
1009 if (loc.monitor == NULL) \
1012 snprintf(rsp, BUFSIZ, "%i", loc.monitor->k);
1014 MONGET(right_padding)
1015 MONGET(bottom_padding)
1016 MONGET(left_padding)
1018 #define GETOPACITY(s) \
1019 else if (streq(#s, name)) \
1020 snprintf(rsp, BUFSIZ, "%lf", s);
1021 GETOPACITY(focused_frame_opacity)
1022 GETOPACITY(active_frame_opacity)
1023 GETOPACITY(normal_frame_opacity)
1025 #define GETCOLOR(s) \
1026 else if (streq(#s, name)) \
1027 snprintf(rsp, BUFSIZ, "%s", s);
1028 GETCOLOR(focused_border_color)
1029 GETCOLOR(active_border_color)
1030 GETCOLOR(normal_border_color)
1031 GETCOLOR(presel_border_color)
1032 GETCOLOR(focused_locked_border_color)
1033 GETCOLOR(active_locked_border_color)
1034 GETCOLOR(normal_locked_border_color)
1035 GETCOLOR(focused_sticky_border_color)
1036 GETCOLOR(active_sticky_border_color)
1037 GETCOLOR(normal_sticky_border_color)
1038 GETCOLOR(urgent_border_color)
1040 #define GETBOOL(s) \
1041 else if (streq(#s, name)) \
1042 snprintf(rsp, BUFSIZ, "%s", BOOLSTR(s));
1043 GETBOOL(borderless_monocle)
1044 GETBOOL(gapless_monocle)
1045 GETBOOL(focus_follows_pointer)
1046 GETBOOL(pointer_follows_monitor)
1047 GETBOOL(apply_floating_atom)
1048 GETBOOL(auto_alternate)
1049 GETBOOL(auto_cancel)
1050 GETBOOL(history_aware_focus)
1051 GETBOOL(ignore_ewmh_focus)
1052 GETBOOL(remove_disabled_monitor)
1059 bool parse_bool(char *value, bool *b)
1061 if (streq("true", value) || streq("on", value)) {
1064 } else if (streq("false", value) || streq("off", value)) {
1071 bool parse_layout(char *s, layout_t *l)
1073 if (streq("monocle", s)) {
1074 *l = LAYOUT_MONOCLE;
1076 } else if (streq("tiled", s)) {
1083 bool parse_direction(char *s, direction_t *d)
1085 if (streq("right", s)) {
1088 } else if (streq("down", s)) {
1091 } else if (streq("left", s)) {
1094 } else if (streq("up", s)) {
1101 bool parse_cycle_direction(char *s, cycle_dir_t *d)
1103 if (streq("next", s)) {
1106 } else if (streq("prev", s)) {
1113 bool parse_circulate_direction(char *s, circulate_dir_t *d)
1115 if (streq("forward", s)) {
1116 *d = CIRCULATE_FORWARD;
1118 } else if (streq("backward", s)) {
1119 *d = CIRCULATE_BACKWARD;
1125 bool parse_history_direction(char *s, history_dir_t *d)
1127 if (streq("older", s)) {
1130 } else if (streq("newer", s)) {
1138 bool parse_flip(char *s, flip_t *f)
1140 if (streq("horizontal", s)) {
1141 *f = FLIP_HORIZONTAL;
1143 } else if (streq("vertical", s)) {
1150 bool parse_fence_move(char *s, fence_move_t *m)
1152 if (streq("push", s)) {
1155 } else if (streq("pull", s)) {
1162 bool parse_pointer_action(char *s, pointer_action_t *a)
1164 if (streq("move", s)) {
1167 } else if (streq("resize_corner", s)) {
1168 *a = ACTION_RESIZE_CORNER;
1170 } else if (streq("resize_side", s)) {
1171 *a = ACTION_RESIZE_SIDE;
1173 } else if (streq("focus", s)) {
1180 bool parse_degree(char *s, int *d)
1187 if ((i % 90) != 0) {
1195 bool parse_window_id(char *s, long int *i)
1199 long int ret = strtol(s, &end, 0);
1200 if (errno != 0 || *end != '\0')
1207 bool parse_bool_declaration(char *s, char **key, bool *value, alter_state_t *state)
1209 *key = strtok(s, EQL_TOK);
1210 char *v = strtok(NULL, EQL_TOK);
1212 *state = ALTER_TOGGLE;
1215 if (parse_bool(v, value)) {
1225 bool parse_index(char *s, int *i)
1228 if (sscanf(s, "^%i", &idx) != 1 || idx < 1)