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("pseudo_tiled", key)) {
208 set_pseudo_tiled(trg.node, (a == ALTER_SET ? b : !trg.node->client->pseudo_tiled));
210 } else if (streq("floating", key)) {
211 set_floating(trg.node, (a == ALTER_SET ? b : !trg.node->client->floating));
213 } else if (streq("locked", key)) {
214 set_locked(trg.monitor, trg.desktop, trg.node, (a == ALTER_SET ? b : !trg.node->client->locked));
215 } else if (streq("sticky", key)) {
216 set_sticky(trg.monitor, trg.desktop, trg.node, (a == ALTER_SET ? b : !trg.node->client->sticky));
217 } else if (streq("private", key)) {
218 set_private(trg.monitor, trg.desktop, trg.node, (a == ALTER_SET ? b : !trg.node->client->private));
222 } else if (streq("-p", *args) || streq("--presel", *args)) {
224 if (num < 1 || !is_tiled(trg.node->client)
225 || trg.desktop->layout != LAYOUT_TILED)
227 if (streq("cancel", *args)) {
231 if (parse_direction(*args, &dir)) {
232 double rat = trg.node->split_ratio;
233 if (num > 1 && *(args + 1)[0] != OPT_CHR) {
235 if (sscanf(*args, "%lf", &rat) != 1 || rat <= 0 || rat >= 1)
238 if (auto_cancel && trg.node->split_mode == MODE_MANUAL
239 && dir == trg.node->split_dir
240 && rat == trg.node->split_ratio) {
243 trg.node->split_mode = MODE_MANUAL;
244 trg.node->split_dir = dir;
245 trg.node->split_ratio = rat;
247 window_draw_border(trg.node, trg.desktop->focus == trg.node, mon == trg.monitor);
252 } else if (streq("-e", *args) || streq("--edge", *args)) {
257 if (!parse_direction(*args, &dir))
259 node_t *n = find_fence(trg.node, dir);
264 if (parse_fence_move(*args, &fmo)) {
265 move_fence(n, dir, fmo);
267 if ((*args)[0] == '+' || (*args)[0] == '-') {
269 if (sscanf(*args, "%i", &pix) == 1) {
270 int max = (n->split_type == TYPE_HORIZONTAL ? n->rectangle.height : n->rectangle.width);
271 double rat = ((max * n->split_ratio) + pix) / max;
272 if (rat > 0 && rat < 1)
273 n->split_ratio = rat;
281 if (sscanf(*args, "%lf", &rat) == 1 && rat > 0 && rat < 1)
282 n->split_ratio = rat;
288 } else if (streq("-r", *args) || streq("--ratio", *args)) {
293 if (sscanf(*args, "%lf", &rat) == 1 && rat > 0 && rat < 1) {
294 trg.node->split_ratio = rat;
295 window_draw_border(trg.node, trg.desktop->focus == trg.node, mon == trg.monitor);
299 } else if (streq("-R", *args) || streq("--rotate", *args)) {
304 if (!parse_direction(*args, &dir))
306 node_t *n = find_fence(trg.node, dir);
311 if (parse_degree(*args, °)) {
317 } else if (streq("-c", *args) || streq("--close", *args)) {
320 window_close(trg.node);
321 } else if (streq("-k", *args) || streq("--kill", *args)) {
324 window_kill(trg.monitor, trg.desktop, trg.node);
334 arrange(trg.monitor, trg.desktop);
339 bool cmd_desktop(char **args, int num)
344 coordinates_t ref = {mon, mon->desk, NULL};
345 coordinates_t trg = ref;
347 if ((*args)[0] != OPT_CHR) {
348 if (desktop_from_desc(*args, &ref, &trg))
357 if (streq("-f", *args) || streq("--focus", *args)) {
358 coordinates_t dst = trg;
359 if (num > 1 && *(args + 1)[0] != OPT_CHR) {
361 if (!desktop_from_desc(*args, &trg, &dst))
364 if (auto_alternate && dst.desktop == mon->desk) {
365 desktop_select_t sel = {DESKTOP_STATUS_ALL, false, false};
366 history_find_desktop(HISTORY_OLDER, &trg, &dst, sel);
368 focus_node(dst.monitor, dst.desktop, dst.desktop->focus);
369 } else if (streq("-m", *args) || streq("--to-monitor", *args)) {
371 if (num < 1 || trg.monitor->desk_head == trg.monitor->desk_tail)
374 if (monitor_from_desc(*args, &trg, &dst)) {
375 transfer_desktop(trg.monitor, dst.monitor, trg.desktop);
376 trg.monitor = dst.monitor;
381 } else if (streq("-s", *args) || streq("--swap", *args)) {
386 if (desktop_from_desc(*args, &trg, &dst) && trg.monitor == dst.monitor)
387 swap_desktops(trg.monitor, trg.desktop, dst.monitor, dst.desktop);
390 } else if (streq("-l", *args) || streq("--layout", *args)) {
396 if (parse_cycle_direction(*args, &cyc))
397 change_layout(trg.monitor, trg.desktop, (trg.desktop->layout + 1) % 2);
398 else if (parse_layout(*args, &lyt))
399 change_layout(trg.monitor, trg.desktop, lyt);
402 } else if (streq("-n", *args) || streq("--rename", *args)) {
406 snprintf(trg.desktop->name, sizeof(trg.desktop->name), "%s", *args);
407 ewmh_update_desktop_names();
409 } else if (streq("-r", *args) || streq("--remove", *args)) {
410 if (trg.desktop->root == NULL
411 && trg.monitor->desk_head != trg.monitor->desk_tail) {
412 remove_desktop(trg.monitor, trg.desktop);
413 show_desktop(trg.monitor->desk);
419 } else if (streq("-c", *args) || streq("--cancel-presel", *args)) {
421 } else if (streq("-F", *args) || streq("--flip", *args)) {
426 if (parse_flip(*args, &flp)) {
427 flip_tree(trg.desktop->root, flp);
432 } else if (streq("-R", *args) || streq("--rotate", *args)) {
437 if (parse_degree(*args, °)) {
438 rotate_tree(trg.desktop->root, deg);
443 } else if (streq("-B", *args) || streq("--balance", *args)) {
444 balance_tree(trg.desktop->root);
446 } else if (streq("-C", *args) || streq("--circulate", *args)) {
451 if (parse_circulate_direction(*args, &cir)) {
452 circulate_leaves(trg.monitor, trg.desktop, cir);
457 } else if (streq("-t", *args) || streq("--toggle", *args)) {
461 char *key = strtok(*args, EQL_TOK);
462 char *val = strtok(NULL, EQL_TOK);
468 if (parse_bool(val, &b))
473 if (streq("floating", key))
474 trg.desktop->floating = (a == ALTER_SET ? b : !trg.desktop->floating);
484 arrange(trg.monitor, trg.desktop);
489 bool cmd_monitor(char **args, int num)
494 coordinates_t ref = {mon, NULL, NULL};
495 coordinates_t trg = ref;
497 if ((*args)[0] != OPT_CHR) {
498 if (monitor_from_desc(*args, &ref, &trg))
505 if (streq("-f", *args) || streq("--focus", *args)) {
506 coordinates_t dst = trg;
507 if (num > 1 && *(args + 1)[0] != OPT_CHR) {
509 if (!monitor_from_desc(*args, &trg, &dst))
512 if (auto_alternate && dst.monitor == mon) {
513 desktop_select_t sel = {DESKTOP_STATUS_ALL, false, false};
514 history_find_monitor(HISTORY_OLDER, &trg, &dst, sel);
516 focus_node(dst.monitor, dst.monitor->desk, dst.monitor->desk->focus);
517 } else if (streq("-d", *args) || streq("--reset-desktops", *args)) {
521 desktop_t *d = trg.monitor->desk_head;
522 while (num > 0 && d != NULL) {
523 snprintf(d->name, sizeof(d->name), "%s", *args);
529 add_desktop(trg.monitor, make_desktop(*args));
533 desktop_t *next = d->next;
535 focus_node(trg.monitor, d->prev, d->prev->focus);
536 merge_desktops(trg.monitor, d, mon, mon->desk);
537 remove_desktop(trg.monitor, d);
540 } else if (streq("-a", *args) || streq("--add-desktops", *args)) {
545 add_desktop(trg.monitor, make_desktop(*args));
548 } else if (streq("-r", *args) || streq("--remove-desktops", *args)) {
554 if (locate_desktop(*args, &dst) && dst.monitor->desk_head != dst.monitor->desk_tail && dst.desktop->root == NULL) {
555 remove_desktop(dst.monitor, dst.desktop);
556 show_desktop(dst.monitor->desk);
560 } else if (streq("-o", *args) || streq("--order-desktops", *args)) {
564 desktop_t *d = trg.monitor->desk_head;
565 while (d != NULL && num > 0) {
566 desktop_t *next = d->next;
568 if (locate_desktop(*args, &dst) && dst.monitor == trg.monitor) {
569 swap_desktops(trg.monitor, d, dst.monitor, dst.desktop);
570 if (next == dst.desktop)
576 } else if (streq("-n", *args) || streq("--rename", *args)) {
580 snprintf(trg.monitor->name, sizeof(trg.monitor->name), "%s", *args);
582 } else if (streq("-s", *args) || streq("--swap", *args)) {
587 if (monitor_from_desc(*args, &trg, &dst))
588 swap_monitors(trg.monitor, dst.monitor);
600 bool cmd_query(char **args, int num, char *rsp)
602 coordinates_t ref = {mon, mon->desk, mon->desk->focus};
603 coordinates_t trg = {NULL, NULL, NULL};
604 domain_t dom = DOMAIN_TREE;
608 if (streq("-T", *args) || streq("--tree", *args)) {
609 dom = DOMAIN_TREE, d++;
610 } else if (streq("-M", *args) || streq("--monitors", *args)) {
611 dom = DOMAIN_MONITOR, d++;
612 } else if (streq("-D", *args) || streq("--desktops", *args)) {
613 dom = DOMAIN_DESKTOP, d++;
614 } else if (streq("-W", *args) || streq("--windows", *args)) {
615 dom = DOMAIN_WINDOW, d++;
616 } else if (streq("-H", *args) || streq("--history", *args)) {
617 dom = DOMAIN_HISTORY, d++;
618 } else if (streq("-S", *args) || streq("--stack", *args)) {
619 dom = DOMAIN_STACK, d++;
620 } else if (streq("-m", *args) || streq("--monitor", *args)) {
621 trg.monitor = ref.monitor;
622 if (num > 1 && *(args + 1)[0] != OPT_CHR) {
624 if (!monitor_from_desc(*args, &ref, &trg))
628 } else if (streq("-d", *args) || streq("--desktop", *args)) {
629 trg.monitor = ref.monitor;
630 trg.desktop = ref.desktop;
631 if (num > 1 && *(args + 1)[0] != OPT_CHR) {
633 if (!desktop_from_desc(*args, &ref, &trg))
637 } else if (streq("-w", *args) || streq("--window", *args)) {
639 if (num > 1 && *(args + 1)[0] != OPT_CHR) {
641 if (!node_from_desc(*args, &ref, &trg))
654 if (dom == DOMAIN_HISTORY)
655 query_history(trg, rsp);
656 else if (dom == DOMAIN_STACK)
658 else if (dom == DOMAIN_WINDOW)
659 query_windows(trg, rsp);
661 query_monitors(trg, dom, rsp);
666 bool cmd_rule(char **args, int num, char *rsp)
671 if (streq("-a", *args) || streq("--add", *args)) {
675 rule_t *rule = make_rule();
676 snprintf(rule->cause, sizeof(rule->cause), "%s", *args);
680 if (streq("-o", *args) || streq("--one-shot", *args)) {
681 rule->one_shot = true;
683 for (size_t j = 0; i < sizeof(rule->effect) && j < strlen(*args); i++, j++)
684 rule->effect[i] = (*args)[j];
685 if (num > 1 && i < sizeof(rule->effect))
686 rule->effect[i++] = ' ';
690 rule->effect[MIN(i, sizeof(rule->effect) - 1)] = '\0';
692 } else if (streq("-r", *args) || streq("--remove", *args)) {
698 if (parse_index(*args, &idx))
699 remove_rule_by_index(idx - 1);
700 else if (streq("tail", *args))
701 remove_rule(rule_tail);
702 else if (streq("head", *args))
703 remove_rule(rule_head);
705 remove_rule_by_cause(*args);
708 } else if (streq("-l", *args) || streq("--list", *args)) {
710 list_rules(num > 0 ? *args : NULL, rsp);
720 bool cmd_pointer(char **args, int num)
725 if (streq("-t", *args) || streq("--track", *args)) {
730 if (sscanf(*args, "%i", &x) == 1 && sscanf(*(args + 1), "%i", &y) == 1)
734 } else if (streq("-g", *args) || streq("--grab", *args)) {
738 pointer_action_t pac;
739 if (parse_pointer_action(*args, &pac))
743 } else if (streq("-u", *args) || streq("--ungrab", *args)) {
754 bool cmd_restore(char **args, int num)
759 if (streq("-T", *args) || streq("--tree", *args)) {
764 } else if (streq("-H", *args) || streq("--history", *args)) {
768 restore_history(*args);
769 } else if (streq("-S", *args) || streq("--stack", *args)) {
773 restore_stack(*args);
783 bool cmd_control(char **args, int num, char *rsp)
788 if (streq("--adopt-orphans", *args)) {
790 } else if (streq("--put-status", *args)) {
792 } else if (streq("--toggle-visibility", *args)) {
794 } else if (streq("--subscribe", *args)) {
795 snprintf(rsp, BUFSIZ, "%c", MESSAGE_SUBSCRIBE);
796 } else if (streq("--record-history", *args)) {
801 if (parse_bool(*args, &b))
814 bool cmd_config(char **args, int num, char *rsp)
818 coordinates_t ref = {mon, mon->desk, mon->desk->focus};
819 coordinates_t trg = {NULL, NULL, NULL};
820 if ((*args)[0] == OPT_CHR) {
821 if (streq("-d", *args) || streq("--desktop", *args)) {
825 if (!desktop_from_desc(*args, &ref, &trg))
827 } else if (streq("-m", *args) || streq("--monitor", *args)) {
831 if (!monitor_from_desc(*args, &ref, &trg))
839 return set_setting(trg, *args, *(args + 1));
841 return get_setting(trg, *args, rsp);
846 bool cmd_quit(char **args, int num)
848 if (num > 0 && sscanf(*args, "%i", &exit_status) != 1)
854 bool set_setting(coordinates_t loc, char *name, char *value)
856 #define DESKSET(k, v) \
857 if (loc.desktop != NULL) \
858 loc.desktop->k = v; \
859 else if (loc.monitor != NULL) \
860 for (desktop_t *d = loc.monitor->desk_head; d != NULL; d = d->next) \
863 for (monitor_t *m = mon_head; m != NULL; m = m->next) \
864 for (desktop_t *d = m->desk_head; d != NULL; d = d->next) \
866 if (streq("border_width", name)) {
868 if (sscanf(value, "%u", &bw) != 1)
870 DESKSET(border_width, bw)
871 } else if (streq("top_padding", name)) {
873 if (sscanf(value, "%i", &tp) != 1)
875 DESKSET(top_padding, tp)
876 } else if (streq("right_padding", name)) {
878 if (sscanf(value, "%i", &rp) != 1)
880 DESKSET(right_padding, rp)
881 } else if (streq("bottom_padding", name)) {
883 if (sscanf(value, "%i", &bp) != 1)
885 DESKSET(bottom_padding, bp)
886 } else if (streq("left_padding", name)) {
888 if (sscanf(value, "%i", &lp) != 1)
890 DESKSET(left_padding, lp)
891 } else if (streq("window_gap", name)) {
893 if (sscanf(value, "%i", &wg) != 1)
895 DESKSET(window_gap, wg)
898 } else if (streq(#s, name)) { \
899 return snprintf(s, sizeof(s), "%s", value) >= 0;
900 SETSTR(external_rules_command)
901 SETSTR(status_prefix)
903 } else if (streq("split_ratio", name)) {
905 if (sscanf(value, "%lf", &r) == 1 && r > 0 && r < 1)
910 } else if (streq("growth_factor", name)) {
912 if (sscanf(value, "%lf", &g) == 1 && g > 1)
917 #define SETCOLOR(s) \
918 } else if (streq(#s, name)) { \
919 snprintf(s, sizeof(s), "%s", value);
920 SETCOLOR(focused_border_color)
921 SETCOLOR(active_border_color)
922 SETCOLOR(normal_border_color)
923 SETCOLOR(presel_border_color)
924 SETCOLOR(focused_locked_border_color)
925 SETCOLOR(active_locked_border_color)
926 SETCOLOR(normal_locked_border_color)
927 SETCOLOR(focused_sticky_border_color)
928 SETCOLOR(active_sticky_border_color)
929 SETCOLOR(normal_sticky_border_color)
930 SETCOLOR(focused_private_border_color)
931 SETCOLOR(active_private_border_color)
932 SETCOLOR(normal_private_border_color)
933 SETCOLOR(urgent_border_color)
935 } else if (streq("focus_follows_pointer", name)) {
937 if (parse_bool(value, &b) && b != focus_follows_pointer) {
938 focus_follows_pointer = b;
939 for (monitor_t *m = mon_head; m != NULL; m = m->next)
940 for (desktop_t *d = m->desk_head; d != NULL; d = d->next)
941 for (node_t *n = first_extrema(d->root); n != NULL; n = next_leaf(n, d->root)) {
942 uint32_t values[] = {CLIENT_EVENT_MASK | (focus_follows_pointer ? XCB_EVENT_MASK_ENTER_WINDOW : 0)};
943 xcb_change_window_attributes(dpy, n->client->window, XCB_CW_EVENT_MASK, values);
945 if (focus_follows_pointer) {
946 for (monitor_t *m = mon_head; m != NULL; m = m->next)
947 window_show(m->root);
948 enable_motion_recorder();
950 for (monitor_t *m = mon_head; m != NULL; m = m->next)
951 window_hide(m->root);
952 disable_motion_recorder();
959 } else if (streq(#s, name)) { \
960 if (!parse_bool(value, &s)) \
962 SETBOOL(borderless_monocle)
963 SETBOOL(gapless_monocle)
964 SETBOOL(pointer_follows_monitor)
965 SETBOOL(apply_floating_atom)
966 SETBOOL(auto_alternate)
968 SETBOOL(history_aware_focus)
969 SETBOOL(ignore_ewmh_focus)
970 SETBOOL(remove_disabled_monitor)
976 for (monitor_t *m = mon_head; m != NULL; m = m->next)
977 for (desktop_t *d = m->desk_head; d != NULL; d = d->next)
983 bool get_setting(coordinates_t loc, char *name, char* rsp)
985 if (streq("split_ratio", name))
986 snprintf(rsp, BUFSIZ, "%lf", split_ratio);
987 else if (streq("growth_factor", name))
988 snprintf(rsp, BUFSIZ, "%lf", growth_factor);
989 else if (streq("window_gap", name))
990 if (loc.desktop == NULL)
993 snprintf(rsp, BUFSIZ, "%i", loc.desktop->window_gap);
994 else if (streq("border_width", name))
995 if (loc.desktop == NULL)
998 snprintf(rsp, BUFSIZ, "%u", loc.desktop->border_width);
999 else if (streq("external_rules_command", name))
1000 snprintf(rsp, BUFSIZ, "%s", external_rules_command);
1001 else if (streq("status_prefix", name))
1002 snprintf(rsp, BUFSIZ, "%s", status_prefix);
1003 #define DESKGET(k) \
1004 else if (streq(#k, name)) \
1005 if (loc.desktop == NULL) \
1008 snprintf(rsp, BUFSIZ, "%i", loc.desktop->k);
1009 DESKGET(top_padding)
1010 DESKGET(right_padding)
1011 DESKGET(bottom_padding)
1012 DESKGET(left_padding)
1014 #define GETCOLOR(s) \
1015 else if (streq(#s, name)) \
1016 snprintf(rsp, BUFSIZ, "%s", s);
1017 GETCOLOR(focused_border_color)
1018 GETCOLOR(active_border_color)
1019 GETCOLOR(normal_border_color)
1020 GETCOLOR(presel_border_color)
1021 GETCOLOR(focused_locked_border_color)
1022 GETCOLOR(active_locked_border_color)
1023 GETCOLOR(normal_locked_border_color)
1024 GETCOLOR(focused_sticky_border_color)
1025 GETCOLOR(active_sticky_border_color)
1026 GETCOLOR(normal_sticky_border_color)
1027 GETCOLOR(urgent_border_color)
1029 #define GETBOOL(s) \
1030 else if (streq(#s, name)) \
1031 snprintf(rsp, BUFSIZ, "%s", BOOLSTR(s));
1032 GETBOOL(borderless_monocle)
1033 GETBOOL(gapless_monocle)
1034 GETBOOL(focus_follows_pointer)
1035 GETBOOL(pointer_follows_monitor)
1036 GETBOOL(apply_floating_atom)
1037 GETBOOL(auto_alternate)
1038 GETBOOL(auto_cancel)
1039 GETBOOL(history_aware_focus)
1040 GETBOOL(ignore_ewmh_focus)
1041 GETBOOL(remove_disabled_monitor)
1048 bool parse_bool(char *value, bool *b)
1050 if (streq("true", value) || streq("on", value)) {
1053 } else if (streq("false", value) || streq("off", value)) {
1060 bool parse_layout(char *s, layout_t *l)
1062 if (streq("monocle", s)) {
1063 *l = LAYOUT_MONOCLE;
1065 } else if (streq("tiled", s)) {
1072 bool parse_direction(char *s, direction_t *d)
1074 if (streq("right", s)) {
1077 } else if (streq("down", s)) {
1080 } else if (streq("left", s)) {
1083 } else if (streq("up", s)) {
1090 bool parse_cycle_direction(char *s, cycle_dir_t *d)
1092 if (streq("next", s)) {
1095 } else if (streq("prev", s)) {
1102 bool parse_circulate_direction(char *s, circulate_dir_t *d)
1104 if (streq("forward", s)) {
1105 *d = CIRCULATE_FORWARD;
1107 } else if (streq("backward", s)) {
1108 *d = CIRCULATE_BACKWARD;
1114 bool parse_history_direction(char *s, history_dir_t *d)
1116 if (streq("older", s)) {
1119 } else if (streq("newer", s)) {
1127 bool parse_flip(char *s, flip_t *f)
1129 if (streq("horizontal", s)) {
1130 *f = FLIP_HORIZONTAL;
1132 } else if (streq("vertical", s)) {
1139 bool parse_fence_move(char *s, fence_move_t *m)
1141 if (streq("push", s)) {
1144 } else if (streq("pull", s)) {
1151 bool parse_pointer_action(char *s, pointer_action_t *a)
1153 if (streq("move", s)) {
1156 } else if (streq("resize_corner", s)) {
1157 *a = ACTION_RESIZE_CORNER;
1159 } else if (streq("resize_side", s)) {
1160 *a = ACTION_RESIZE_SIDE;
1162 } else if (streq("focus", s)) {
1169 bool parse_degree(char *s, int *d)
1176 if ((i % 90) != 0) {
1184 bool parse_window_id(char *s, long int *i)
1188 long int ret = strtol(s, &end, 0);
1189 if (errno != 0 || *end != '\0')
1196 bool parse_bool_declaration(char *s, char **key, bool *value, alter_state_t *state)
1198 *key = strtok(s, EQL_TOK);
1199 char *v = strtok(NULL, EQL_TOK);
1201 *state = ALTER_TOGGLE;
1204 if (parse_bool(v, value)) {
1214 bool parse_index(char *s, int *i)
1217 if (sscanf(s, "^%i", &idx) != 1 || idx < 1)