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.
42 bool handle_message(char *msg, int msg_len, char *rsp)
46 char **args = malloc(cap * sizeof(char *));
50 for (int i = 0, j = 0; i < msg_len; i++) {
52 args[num++] = msg + j;
57 char **new = realloc(args, cap * sizeof(char *));
72 char **args_orig = args;
73 bool ret = process_message(args, num, rsp);
78 bool process_message(char **args, int num, char *rsp)
80 if (streq("window", *args)) {
81 return cmd_window(++args, --num);
82 } else if (streq("desktop", *args)) {
83 return cmd_desktop(++args, --num);
84 } else if (streq("monitor", *args)) {
85 return cmd_monitor(++args, --num);
86 } else if (streq("query", *args)) {
87 return cmd_query(++args, --num, rsp);
88 } else if (streq("restore", *args)) {
89 return cmd_restore(++args, --num);
90 } else if (streq("control", *args)) {
91 return cmd_control(++args, --num);
92 } else if (streq("pointer", *args)) {
93 return cmd_pointer(++args, --num);
94 } else if (streq("config", *args)) {
95 return cmd_config(++args, --num, rsp);
96 } else if (streq("quit", *args)) {
97 return cmd_quit(++args, --num);
103 bool cmd_window(char **args, int num)
108 coordinates_t ref = {mon, mon->desk, mon->desk->focus};
109 coordinates_t trg = ref;
111 if (*args[0] != OPT_CHR) {
112 if (node_from_desc(*args, &ref, &trg))
118 if (trg.node == NULL)
124 if (streq("-f", *args) || streq("--focus", *args)) {
125 coordinates_t dst = trg;
126 if (num > 1 && *(args + 1)[0] != OPT_CHR) {
128 if (!node_from_desc(*args, &trg, &dst))
131 focus_node(dst.monitor, dst.desktop, dst.node);
132 } else if (streq("-d", *args) || streq("--to-desktop", *args)) {
135 if (desktop_from_desc(*args, &trg, &dst)) {
136 if (transfer_node(trg.monitor, trg.desktop, trg.node, dst.monitor, dst.desktop, dst.desktop->focus)) {
137 trg.monitor = dst.monitor;
138 trg.desktop = dst.desktop;
143 } else if (streq("-m", *args) || streq("--to-monitor", *args)) {
148 if (monitor_from_desc(*args, &trg, &dst)) {
149 if (transfer_node(trg.monitor, trg.desktop, trg.node, dst.monitor, dst.monitor->desk, dst.monitor->desk->focus)) {
150 trg.monitor = dst.monitor;
151 trg.desktop = dst.monitor->desk;
156 } else if (streq("-w", *args) || streq("--to-window", *args)) {
161 if (node_from_desc(*args, &trg, &dst)) {
162 if (transfer_node(trg.monitor, trg.desktop, trg.node, dst.monitor, dst.desktop, dst.node)) {
163 trg.monitor = dst.monitor;
164 trg.desktop = dst.desktop;
169 } else if (streq("-s", *args) || streq("--swap", *args)) {
174 if (node_from_desc(*args, &trg, &dst)) {
175 if (swap_nodes(trg.monitor, trg.desktop, trg.node, dst.monitor, dst.desktop, dst.node)) {
176 if (trg.desktop != dst.desktop)
177 arrange(trg.monitor, trg.desktop);
178 trg.monitor = dst.monitor;
179 trg.desktop = dst.desktop;
185 } else if (streq("-t", *args) || streq("--toggle", *args)) {
189 char *key = strtok(*args, EQL_TOK);
190 char *val = strtok(NULL, EQL_TOK);
196 if (parse_bool(val, &b))
201 if (streq("fullscreen", key)) {
202 set_fullscreen(trg.node, (a == ALTER_SET ? b : !trg.node->client->fullscreen));
204 } else if (streq("floating", key)) {
205 set_floating(trg.node, (a == ALTER_SET ? b : !trg.node->client->floating));
207 } else if (streq("locked", key)) {
208 set_locked(trg.monitor, trg.desktop, trg.node, (a == ALTER_SET ? b : !trg.node->client->locked));
209 } else if (streq("sticky", key)) {
210 set_sticky(trg.monitor, trg.desktop, trg.node, (a == ALTER_SET ? b : !trg.node->client->sticky));
211 } else if (streq("private", key)) {
212 set_private(trg.monitor, trg.desktop, trg.node, (a == ALTER_SET ? b : !trg.node->client->private));
216 } else if (streq("-p", *args) || streq("--presel", *args)) {
218 if (num < 1 || !is_tiled(trg.node->client)
219 || trg.desktop->layout != LAYOUT_TILED)
221 if (streq("cancel", *args)) {
225 if (parse_direction(*args, &dir)) {
226 double rat = trg.node->split_ratio;
227 if (num > 1 && *(args + 1)[0] != OPT_CHR) {
229 if (sscanf(*args, "%lf", &rat) != 1 || rat <= 0 || rat >= 1)
232 if (auto_cancel && trg.node->split_mode == MODE_MANUAL
233 && dir == trg.node->split_dir
234 && rat == trg.node->split_ratio) {
237 trg.node->split_mode = MODE_MANUAL;
238 trg.node->split_dir = dir;
239 trg.node->split_ratio = rat;
241 window_draw_border(trg.node, trg.desktop->focus == trg.node, mon == trg.monitor);
246 } else if (streq("-e", *args) || streq("--edge", *args)) {
251 if (!parse_direction(*args, &dir))
253 node_t *n = find_fence(trg.node, dir);
258 if (parse_fence_move(*args, &fmo)) {
259 move_fence(n, dir, fmo);
262 if (sscanf(*args, "%lf", &rat) == 1 && rat > 0 && rat < 1)
263 n->split_ratio = rat;
268 } else if (streq("-r", *args) || streq("--ratio", *args)) {
273 if (sscanf(*args, "%lf", &rat) == 1 && rat > 0 && rat < 1) {
274 trg.node->split_ratio = rat;
275 window_draw_border(trg.node, trg.desktop->focus == trg.node, mon == trg.monitor);
279 } else if (streq("-R", *args) || streq("--rotate", *args)) {
284 if (!parse_direction(*args, &dir))
286 node_t *n = find_fence(trg.node, dir);
291 if (parse_degree(*args, °)) {
297 } else if (streq("-c", *args) || streq("--close", *args)) {
300 window_close(trg.node);
301 } else if (streq("-k", *args) || streq("--kill", *args)) {
304 window_kill(trg.monitor, trg.desktop, trg.node);
314 arrange(trg.monitor, trg.desktop);
319 bool cmd_desktop(char **args, int num)
324 coordinates_t ref = {mon, mon->desk, NULL};
325 coordinates_t trg = ref;
327 if (*args[0] != OPT_CHR) {
328 if (desktop_from_desc(*args, &ref, &trg))
337 if (streq("-f", *args) || streq("--focus", *args)) {
338 coordinates_t dst = trg;
339 if (num > 1 && *(args + 1)[0] != OPT_CHR) {
341 if (!desktop_from_desc(*args, &trg, &dst))
344 if (auto_alternate && dst.desktop == mon->desk) {
345 desktop_select_t sel = {DESKTOP_STATUS_ALL, false, false};
346 history_find_desktop(HISTORY_OLDER, &trg, &dst, sel);
348 focus_node(dst.monitor, dst.desktop, dst.desktop->focus);
349 } else if (streq("-m", *args) || streq("--to-monitor", *args)) {
351 if (num < 1 || trg.monitor->desk_head == trg.monitor->desk_tail)
354 if (monitor_from_desc(*args, &trg, &dst)) {
355 transfer_desktop(trg.monitor, dst.monitor, trg.desktop);
356 trg.monitor = dst.monitor;
361 } else if (streq("-s", *args) || streq("--swap", *args)) {
366 if (desktop_from_desc(*args, &trg, &dst) && trg.monitor == dst.monitor)
367 swap_desktops(trg.monitor, trg.desktop, dst.monitor, dst.desktop);
370 } else if (streq("-l", *args) || streq("--layout", *args)) {
376 if (parse_cycle_direction(*args, &cyc))
377 change_layout(trg.monitor, trg.desktop, (trg.desktop->layout + 1) % 2);
378 else if (parse_layout(*args, &lyt))
379 change_layout(trg.monitor, trg.desktop, lyt);
382 } else if (streq("-n", *args) || streq("--rename", *args)) {
386 snprintf(trg.desktop->name, sizeof(trg.desktop->name), "%s", *args);
387 ewmh_update_desktop_names();
389 } else if (streq("-r", *args) || streq("--remove", *args)) {
390 if (trg.desktop->root == NULL
391 && trg.monitor->desk_head != trg.monitor->desk_tail) {
392 remove_desktop(trg.monitor, trg.desktop);
393 show_desktop(trg.monitor->desk);
399 } else if (streq("-c", *args) || streq("--cancel-presel", *args)) {
401 } else if (streq("-F", *args) || streq("--flip", *args)) {
406 if (parse_flip(*args, &flp)) {
407 flip_tree(trg.desktop->root, flp);
412 } else if (streq("-R", *args) || streq("--rotate", *args)) {
417 if (parse_degree(*args, °)) {
418 rotate_tree(trg.desktop->root, deg);
423 } else if (streq("-B", *args) || streq("--balance", *args)) {
424 balance_tree(trg.desktop->root);
426 } else if (streq("-C", *args) || streq("--circulate", *args)) {
431 if (parse_circulate_direction(*args, &cir)) {
432 circulate_leaves(trg.monitor, trg.desktop, cir);
437 } else if (streq("-t", *args) || streq("--toggle", *args)) {
441 char *key = strtok(*args, EQL_TOK);
442 char *val = strtok(NULL, EQL_TOK);
448 if (parse_bool(val, &b))
453 if (streq("floating", key))
454 trg.desktop->floating = (a == ALTER_SET ? b : !trg.desktop->floating);
464 arrange(trg.monitor, trg.desktop);
469 bool cmd_monitor(char **args, int num)
474 coordinates_t ref = {mon, NULL, NULL};
475 coordinates_t trg = ref;
477 if (*args[0] != OPT_CHR) {
478 if (monitor_from_desc(*args, &ref, &trg))
485 if (streq("-f", *args) || streq("--focus", *args)) {
486 coordinates_t dst = trg;
487 if (num > 1 && *(args + 1)[0] != OPT_CHR) {
489 if (!monitor_from_desc(*args, &trg, &dst))
492 if (auto_alternate && dst.monitor == mon) {
493 desktop_select_t sel = {DESKTOP_STATUS_ALL, false, false};
494 history_find_monitor(HISTORY_OLDER, &trg, &dst, sel);
496 focus_node(dst.monitor, dst.monitor->desk, dst.monitor->desk->focus);
497 } else if (streq("-d", *args) || streq("--reset-desktops", *args)) {
501 desktop_t *d = trg.monitor->desk_head;
502 while (num > 0 && d != NULL) {
503 snprintf(d->name, sizeof(d->name), "%s", *args);
509 add_desktop(trg.monitor, make_desktop(*args));
513 desktop_t *next = d->next;
515 focus_node(trg.monitor, d->prev, d->prev->focus);
516 merge_desktops(trg.monitor, d, mon, mon->desk);
517 remove_desktop(trg.monitor, d);
520 } else if (streq("-a", *args) || streq("--add-desktops", *args)) {
525 add_desktop(trg.monitor, make_desktop(*args));
528 } else if (streq("-r", *args) || streq("--remove-desktops", *args)) {
534 if (locate_desktop(*args, &dst) && dst.monitor->desk_head != dst.monitor->desk_tail && dst.desktop->root == NULL) {
535 remove_desktop(dst.monitor, dst.desktop);
536 show_desktop(dst.monitor->desk);
540 } else if (streq("-n", *args) || streq("--rename", *args)) {
544 snprintf(trg.monitor->name, sizeof(trg.monitor->name), "%s", *args);
546 } else if (streq("-s", *args) || streq("--swap", *args)) {
551 if (monitor_from_desc(*args, &trg, &dst))
552 swap_monitors(trg.monitor, dst.monitor);
564 bool cmd_query(char **args, int num, char *rsp)
566 coordinates_t ref = {mon, mon->desk, mon->desk->focus};
567 coordinates_t trg = {NULL, NULL, NULL};
568 domain_t dom = DOMAIN_TREE;
572 if (streq("-T", *args) || streq("--tree", *args)) {
573 dom = DOMAIN_TREE, d++;
574 } else if (streq("-M", *args) || streq("--monitors", *args)) {
575 dom = DOMAIN_MONITOR, d++;
576 } else if (streq("-D", *args) || streq("--desktops", *args)) {
577 dom = DOMAIN_DESKTOP, d++;
578 } else if (streq("-W", *args) || streq("--windows", *args)) {
579 dom = DOMAIN_WINDOW, d++;
580 } else if (streq("-H", *args) || streq("--history", *args)) {
581 dom = DOMAIN_HISTORY, d++;
582 } else if (streq("-S", *args) || streq("--stack", *args)) {
583 dom = DOMAIN_STACK, d++;
584 } else if (streq("-m", *args) || streq("--monitor", *args)) {
585 trg.monitor = ref.monitor;
586 if (num > 1 && *(args + 1)[0] != OPT_CHR) {
588 if (!monitor_from_desc(*args, &ref, &trg))
592 } else if (streq("-d", *args) || streq("--desktop", *args)) {
593 trg.monitor = ref.monitor;
594 trg.desktop = ref.desktop;
595 if (num > 1 && *(args + 1)[0] != OPT_CHR) {
597 if (!desktop_from_desc(*args, &ref, &trg))
601 } else if (streq("-w", *args) || streq("--window", *args)) {
603 if (num > 1 && *(args + 1)[0] != OPT_CHR) {
605 if (!node_from_desc(*args, &ref, &trg))
618 if (dom == DOMAIN_HISTORY)
619 query_history(trg, rsp);
620 else if (dom == DOMAIN_STACK)
622 else if (dom == DOMAIN_WINDOW)
623 query_windows(trg, rsp);
625 query_monitors(trg, dom, rsp);
630 bool cmd_pointer(char **args, int num)
635 if (streq("-t", *args) || streq("--track", *args)) {
640 if (sscanf(*args, "%i", &x) == 1 && sscanf(*(args + 1), "%i", &y) == 1)
644 } else if (streq("-g", *args) || streq("--grab", *args)) {
648 pointer_action_t pac;
649 if (parse_pointer_action(*args, &pac))
653 } else if (streq("-u", *args) || streq("--ungrab", *args)) {
664 bool cmd_restore(char **args, int num)
669 if (streq("-T", *args) || streq("--tree", *args)) {
674 } else if (streq("-H", *args) || streq("--history", *args)) {
678 restore_history(*args);
679 } else if (streq("-S", *args) || streq("--stack", *args)) {
683 restore_stack(*args);
693 bool cmd_control(char **args, int num)
698 if (streq("--adopt-orphans", *args)) {
700 } else if (streq("--put-status", *args)) {
702 } else if (streq("--toggle-visibility", *args)) {
704 } else if (streq("--record-history", *args)) {
709 if (parse_bool(*args, &b))
722 bool cmd_config(char **args, int num, char *rsp)
726 coordinates_t ref = {mon, mon->desk, mon->desk->focus};
727 coordinates_t trg = {NULL, NULL, NULL};
728 if (*args[0] == OPT_CHR) {
729 if (streq("-d", *args) || streq("--desktop", *args)) {
733 if (!desktop_from_desc(*args, &ref, &trg))
735 } else if (streq("-m", *args) || streq("--monitor", *args)) {
739 if (!monitor_from_desc(*args, &ref, &trg))
747 return set_setting(trg, *args, *(args + 1));
749 return get_setting(trg, *args, rsp);
754 bool cmd_quit(char **args, int num)
756 if (num > 0 && sscanf(*args, "%i", &exit_status) != 1)
762 bool set_setting(coordinates_t loc, char *name, char *value)
764 #define DESKSET(k, v) \
765 if (loc.desktop != NULL) \
766 loc.desktop->k = v; \
767 else if (loc.monitor != NULL) \
768 for (desktop_t *d = loc.monitor->desk_head; d != NULL; d = d->next) \
771 for (monitor_t *m = mon_head; m != NULL; m = m->next) \
772 for (desktop_t *d = m->desk_head; d != NULL; d = d->next) \
774 if (streq("border_width", name)) {
776 if (sscanf(value, "%u", &bw) != 1)
778 DESKSET(border_width, bw)
779 } else if (streq("window_gap", name)) {
781 if (sscanf(value, "%i", &wg) != 1)
783 DESKSET(window_gap, wg)
786 } else if (streq(#k, name)) { \
788 if (sscanf(value, "%i", &v) != 1) \
790 if (loc.monitor != NULL) \
791 loc.monitor->k = v; \
793 for (monitor_t *m = mon_head; m!= NULL; m = m->next) \
796 MONSET(right_padding)
797 MONSET(bottom_padding)
800 } else if (streq("rule_command", name)) {
801 return snprintf(rule_command, sizeof(rule_command), "%s", value) >= 0;
802 } else if (streq("split_ratio", name)) {
804 if (sscanf(value, "%lf", &r) == 1 && r > 0 && r < 1)
809 } else if (streq("growth_factor", name)) {
811 if (sscanf(value, "%lf", &g) == 1 && g > 1)
816 #define SETOPACITY(s) \
817 } else if (streq(#s, name)) { \
819 if (sscanf(value, "%lf", &o) == 1 && o >= 0 && o <= 1) \
823 SETOPACITY(focused_frame_opacity)
824 SETOPACITY(active_frame_opacity)
825 SETOPACITY(normal_frame_opacity)
827 #define SETCOLOR(s) \
828 } else if (streq(#s, name)) { \
829 snprintf(s, sizeof(s), "%s", value);
830 SETCOLOR(focused_border_color)
831 SETCOLOR(active_border_color)
832 SETCOLOR(normal_border_color)
833 SETCOLOR(presel_border_color)
834 SETCOLOR(focused_locked_border_color)
835 SETCOLOR(active_locked_border_color)
836 SETCOLOR(normal_locked_border_color)
837 SETCOLOR(focused_sticky_border_color)
838 SETCOLOR(active_sticky_border_color)
839 SETCOLOR(normal_sticky_border_color)
840 SETCOLOR(focused_private_border_color)
841 SETCOLOR(active_private_border_color)
842 SETCOLOR(normal_private_border_color)
843 SETCOLOR(urgent_border_color)
845 } else if (streq("focus_follows_pointer", name)) {
847 if (parse_bool(value, &b) && b != focus_follows_pointer) {
848 focus_follows_pointer = b;
849 for (monitor_t *m = mon_head; m != NULL; m = m->next)
850 for (desktop_t *d = m->desk_head; d != NULL; d = d->next)
851 for (node_t *n = first_extrema(d->root); n != NULL; n = next_leaf(n, d->root)) {
852 uint32_t values[] = {get_event_mask(n->client)};
853 xcb_change_window_attributes(dpy, n->client->window, XCB_CW_EVENT_MASK, values);
855 if (focus_follows_pointer) {
856 for (monitor_t *m = mon_head; m != NULL; m = m->next)
857 window_show(m->root);
858 enable_motion_recorder();
860 for (monitor_t *m = mon_head; m != NULL; m = m->next)
861 window_hide(m->root);
862 disable_motion_recorder();
869 } else if (streq(#s, name)) { \
870 if (!parse_bool(value, &s)) \
872 SETBOOL(borderless_monocle)
873 SETBOOL(gapless_monocle)
874 SETBOOL(pointer_follows_monitor)
875 SETBOOL(apply_floating_atom)
876 SETBOOL(auto_alternate)
878 SETBOOL(history_aware_focus)
879 SETBOOL(ignore_ewmh_focus)
885 for (monitor_t *m = mon_head; m != NULL; m = m->next)
886 for (desktop_t *d = m->desk_head; d != NULL; d = d->next)
892 bool get_setting(coordinates_t loc, char *name, char* rsp)
894 if (streq("split_ratio", name))
895 snprintf(rsp, BUFSIZ, "%lf", split_ratio);
896 else if (streq("growth_factor", name))
897 snprintf(rsp, BUFSIZ, "%lf", growth_factor);
898 else if (streq("window_gap", name))
899 if (loc.desktop == NULL)
902 snprintf(rsp, BUFSIZ, "%i", loc.desktop->window_gap);
903 else if (streq("border_width", name))
904 if (loc.desktop == NULL)
907 snprintf(rsp, BUFSIZ, "%u", loc.desktop->border_width);
908 else if (streq("rule_command", name))
909 snprintf(rsp, BUFSIZ, "%s", rule_command);
911 else if (streq(#k, name)) \
912 if (loc.monitor == NULL) \
915 snprintf(rsp, BUFSIZ, "%i", loc.monitor->k);
917 MONGET(right_padding)
918 MONGET(bottom_padding)
921 #define GETOPACITY(s) \
922 else if (streq(#s, name)) \
923 snprintf(rsp, BUFSIZ, "%lf", s);
924 GETOPACITY(focused_frame_opacity)
925 GETOPACITY(active_frame_opacity)
926 GETOPACITY(normal_frame_opacity)
928 #define GETCOLOR(s) \
929 else if (streq(#s, name)) \
930 snprintf(rsp, BUFSIZ, "%s", s);
931 GETCOLOR(focused_border_color)
932 GETCOLOR(active_border_color)
933 GETCOLOR(normal_border_color)
934 GETCOLOR(presel_border_color)
935 GETCOLOR(focused_locked_border_color)
936 GETCOLOR(active_locked_border_color)
937 GETCOLOR(normal_locked_border_color)
938 GETCOLOR(focused_sticky_border_color)
939 GETCOLOR(active_sticky_border_color)
940 GETCOLOR(normal_sticky_border_color)
941 GETCOLOR(urgent_border_color)
944 else if (streq(#s, name)) \
945 snprintf(rsp, BUFSIZ, "%s", BOOLSTR(s));
946 GETBOOL(borderless_monocle)
947 GETBOOL(gapless_monocle)
948 GETBOOL(focus_follows_pointer)
949 GETBOOL(pointer_follows_monitor)
950 GETBOOL(apply_floating_atom)
951 GETBOOL(auto_alternate)
953 GETBOOL(history_aware_focus)
954 GETBOOL(ignore_ewmh_focus)
961 bool parse_bool(char *value, bool *b)
963 if (streq("true", value) || streq("on", value)) {
966 } else if (streq("false", value) || streq("off", value)) {
973 bool parse_layout(char *s, layout_t *l)
975 if (streq("monocle", s)) {
978 } else if (streq("tiled", s)) {
985 bool parse_direction(char *s, direction_t *d)
987 if (streq("right", s)) {
990 } else if (streq("down", s)) {
993 } else if (streq("left", s)) {
996 } else if (streq("up", s)) {
1003 bool parse_cycle_direction(char *s, cycle_dir_t *d)
1005 if (streq("next", s)) {
1008 } else if (streq("prev", s)) {
1015 bool parse_circulate_direction(char *s, circulate_dir_t *d)
1017 if (streq("forward", s)) {
1018 *d = CIRCULATE_FORWARD;
1020 } else if (streq("backward", s)) {
1021 *d = CIRCULATE_BACKWARD;
1027 bool parse_history_direction(char *s, history_dir_t *d)
1029 if (streq("older", s)) {
1032 } else if (streq("newer", s)) {
1040 bool parse_flip(char *s, flip_t *f)
1042 if (streq("horizontal", s)) {
1043 *f = FLIP_HORIZONTAL;
1045 } else if (streq("vertical", s)) {
1052 bool parse_fence_move(char *s, fence_move_t *m)
1054 if (streq("push", s)) {
1057 } else if (streq("pull", s)) {
1064 bool parse_pointer_action(char *s, pointer_action_t *a)
1066 if (streq("move", s)) {
1069 } else if (streq("resize_corner", s)) {
1070 *a = ACTION_RESIZE_CORNER;
1072 } else if (streq("resize_side", s)) {
1073 *a = ACTION_RESIZE_SIDE;
1075 } else if (streq("focus", s)) {
1082 bool parse_degree(char *s, int *d)
1089 if ((i % 90) != 0) {
1097 bool parse_window_id(char *s, long int *i)
1101 long int ret = strtol(s, &end, 0);
1102 if (errno != 0 || *end != '\0')
1109 bool parse_bool_declaration(char *s, char **key, bool *value, alter_state_t *state)
1111 *key = strtok(s, EQL_TOK);
1112 char *v = strtok(NULL, EQL_TOK);
1114 *state = ALTER_TOGGLE;
1117 if (parse_bool(v, value)) {
1127 bool parse_index(char *s, int *i)
1130 if (sscanf(s, "^%i", &idx) != 1 || idx < 1)