8 bool parse_bool(char *value, bool *b)
10 if (streq("true", value) || streq("on", value)) {
13 } else if (streq("false", value) || streq("off", value)) {
20 bool parse_split_type(char *s, split_type_t *t)
22 if (streq("horizontal", s)) {
25 } else if (streq("vertical", s)) {
32 bool parse_split_mode(char *s, split_mode_t *m)
34 if (streq("automatic", s)) {
37 } else if (streq("vertical", s)) {
44 bool parse_layout(char *s, layout_t *l)
46 if (streq("monocle", s)) {
49 } else if (streq("tiled", s)) {
56 bool parse_client_state(char *s, client_state_t *t)
58 if (streq("tiled", s)) {
61 } else if (streq("pseudo_tiled", s)) {
62 *t = STATE_PSEUDO_TILED;
64 } else if (streq("floating", s)) {
67 } else if (streq("fullscreen", s)) {
68 *t = STATE_FULLSCREEN;
74 bool parse_stack_layer(char *s, stack_layer_t *l)
76 if (streq("below", s)) {
79 } else if (streq("normal", s)) {
82 } else if (streq("above", s)) {
89 bool parse_direction(char *s, direction_t *d)
91 if (streq("north", s)) {
94 } else if (streq("west", s)) {
97 } else if (streq("south", s)) {
100 } else if (streq("east", s)) {
107 bool parse_cycle_direction(char *s, cycle_dir_t *d)
109 if (streq("next", s)) {
112 } else if (streq("prev", s)) {
119 bool parse_circulate_direction(char *s, circulate_dir_t *d)
121 if (streq("forward", s)) {
122 *d = CIRCULATE_FORWARD;
124 } else if (streq("backward", s)) {
125 *d = CIRCULATE_BACKWARD;
131 bool parse_history_direction(char *s, history_dir_t *d)
133 if (streq("older", s)) {
136 } else if (streq("newer", s)) {
144 bool parse_flip(char *s, flip_t *f)
146 if (streq("horizontal", s)) {
147 *f = FLIP_HORIZONTAL;
149 } else if (streq("vertical", s)) {
156 bool parse_resize_handle(char *s, resize_handle_t *h)
158 if (streq("left", s)) {
161 } else if (streq("top", s)) {
164 } else if (streq("right", s)) {
167 } else if (streq("bottom", s)) {
170 } else if (streq("top_left", s)) {
171 *h = HANDLE_TOP_LEFT;
173 } else if (streq("top_right", s)) {
174 *h = HANDLE_TOP_RIGHT;
176 } else if (streq("bottom_right", s)) {
177 *h = HANDLE_BOTTOM_RIGHT;
179 } else if (streq("bottom_left", s)) {
180 *h = HANDLE_BOTTOM_LEFT;
186 bool parse_modifier_mask(char *s, uint16_t *m)
188 if (strcmp(s, "shift") == 0) {
189 *m = XCB_MOD_MASK_SHIFT;
191 } else if (strcmp(s, "control") == 0) {
192 *m = XCB_MOD_MASK_CONTROL;
194 } else if (strcmp(s, "lock") == 0) {
195 *m = XCB_MOD_MASK_LOCK;
197 } else if (strcmp(s, "mod1") == 0) {
200 } else if (strcmp(s, "mod2") == 0) {
203 } else if (strcmp(s, "mod3") == 0) {
206 } else if (strcmp(s, "mod4") == 0) {
209 } else if (strcmp(s, "mod5") == 0) {
216 bool parse_button_index(char *s, int8_t *b)
218 if (strcmp(s, "any") == 0) {
219 *b = XCB_BUTTON_INDEX_ANY;
221 } else if (strcmp(s, "button1") == 0) {
222 *b = XCB_BUTTON_INDEX_1;
224 } else if (strcmp(s, "button2") == 0) {
225 *b = XCB_BUTTON_INDEX_2;
227 } else if (strcmp(s, "button3") == 0) {
228 *b = XCB_BUTTON_INDEX_3;
230 } else if (strcmp(s, "none") == 0) {
237 bool parse_pointer_action(char *s, pointer_action_t *a)
239 if (streq("move", s)) {
242 } else if (streq("resize_corner", s)) {
243 *a = ACTION_RESIZE_CORNER;
245 } else if (streq("resize_side", s)) {
246 *a = ACTION_RESIZE_SIDE;
248 } else if (streq("focus", s)) {
251 } else if (streq("none", s)) {
258 bool parse_child_polarity(char *s, child_polarity_t *p)
260 if (streq("first_child", s)) {
263 } else if (streq("second_child", s)) {
270 bool parse_automatic_scheme(char *s, automatic_scheme_t *a)
272 if (streq("longest_side", s)) {
273 *a = SCHEME_LONGEST_SIDE;
275 } else if (streq("alternate", s)) {
276 *a = SCHEME_ALTERNATE;
278 } else if (streq("spiral", s)) {
285 bool parse_state_transition(char *s, state_transition_t *m)
287 if (streq("none", s)) {
290 } else if (streq("all", s)) {
291 *m = STATE_TRANSITION_ENTER | STATE_TRANSITION_EXIT;
294 state_transition_t w = 0;
295 char *x = copy_string(s, strlen(s));
296 char *key = strtok(x, ",");
297 while (key != NULL) {
298 if (streq("enter", key)) {
299 w |= STATE_TRANSITION_ENTER;
300 } else if (streq("exit", key)) {
301 w |= STATE_TRANSITION_EXIT;
306 key = strtok(NULL, ",");
319 bool parse_tightness(char *s, tightness_t *t)
321 if (streq("high", s)) {
324 } else if (streq("low", s)) {
331 bool parse_degree(char *s, int *d)
346 bool parse_id(char *s, uint32_t *id)
350 uint32_t v = strtol(s, &end, 0);
351 if (errno != 0 || *end != '\0') {
358 bool parse_bool_declaration(char *s, char **key, bool *value, alter_state_t *state)
360 *key = strtok(s, EQL_TOK);
361 char *v = strtok(NULL, EQL_TOK);
363 *state = ALTER_TOGGLE;
366 if (parse_bool(v, value)) {
376 bool parse_index(char *s, uint16_t *idx)
378 return (sscanf(s, "^%hu", idx) == 1);
381 bool parse_rectangle(char *s, xcb_rectangle_t *r)
385 if (sscanf(s, "%hux%hu+%hi+%hi", &w, &h, &x, &y) != 4) {
395 bool parse_subscriber_mask(char *s, subscriber_mask_t *mask)
397 if (streq("all", s)) {
398 *mask = SBSC_MASK_ALL;
399 } else if (streq("node", s)) {
400 *mask = SBSC_MASK_NODE;
401 } else if (streq("desktop", s)) {
402 *mask = SBSC_MASK_DESKTOP;
403 } else if (streq("monitor", s)) {
404 *mask = SBSC_MASK_MONITOR;
405 } else if (streq("pointer_action", s)) {
406 *mask = SBSC_MASK_POINTER_ACTION;
407 } else if (streq("node_add", s)) {
408 *mask = SBSC_MASK_NODE_ADD;
409 } else if (streq("node_remove", s)) {
410 *mask = SBSC_MASK_NODE_REMOVE;
411 } else if (streq("node_swap", s)) {
412 *mask = SBSC_MASK_NODE_SWAP;
413 } else if (streq("node_transfer", s)) {
414 *mask = SBSC_MASK_NODE_TRANSFER;
415 } else if (streq("node_focus", s)) {
416 *mask = SBSC_MASK_NODE_FOCUS;
417 } else if (streq("node_presel", s)) {
418 *mask = SBSC_MASK_NODE_PRESEL;
419 } else if (streq("node_stack", s)) {
420 *mask = SBSC_MASK_NODE_STACK;
421 } else if (streq("node_activate", s)) {
422 *mask = SBSC_MASK_NODE_ACTIVATE;
423 } else if (streq("node_geometry", s)) {
424 *mask = SBSC_MASK_NODE_GEOMETRY;
425 } else if (streq("node_state", s)) {
426 *mask = SBSC_MASK_NODE_STATE;
427 } else if (streq("node_flag", s)) {
428 *mask = SBSC_MASK_NODE_FLAG;
429 } else if (streq("node_layer", s)) {
430 *mask = SBSC_MASK_NODE_LAYER;
431 } else if (streq("desktop_add", s)) {
432 *mask = SBSC_MASK_DESKTOP_ADD;
433 } else if (streq("desktop_rename", s)) {
434 *mask = SBSC_MASK_DESKTOP_RENAME;
435 } else if (streq("desktop_remove", s)) {
436 *mask = SBSC_MASK_DESKTOP_REMOVE;
437 } else if (streq("desktop_swap", s)) {
438 *mask = SBSC_MASK_DESKTOP_SWAP;
439 } else if (streq("desktop_transfer", s)) {
440 *mask = SBSC_MASK_DESKTOP_TRANSFER;
441 } else if (streq("desktop_focus", s)) {
442 *mask = SBSC_MASK_DESKTOP_FOCUS;
443 } else if (streq("desktop_activate", s)) {
444 *mask = SBSC_MASK_DESKTOP_ACTIVATE;
445 } else if (streq("desktop_layout", s)) {
446 *mask = SBSC_MASK_DESKTOP_LAYOUT;
447 } else if (streq("monitor_add", s)) {
448 *mask = SBSC_MASK_MONITOR_ADD;
449 } else if (streq("monitor_rename", s)) {
450 *mask = SBSC_MASK_MONITOR_RENAME;
451 } else if (streq("monitor_remove", s)) {
452 *mask = SBSC_MASK_MONITOR_REMOVE;
453 } else if (streq("monitor_swap", s)) {
454 *mask = SBSC_MASK_MONITOR_SWAP;
455 } else if (streq("monitor_focus", s)) {
456 *mask = SBSC_MASK_MONITOR_FOCUS;
457 } else if (streq("monitor_geometry", s)) {
458 *mask = SBSC_MASK_MONITOR_GEOMETRY;
459 } else if (streq("report", s)) {
460 *mask = SBSC_MASK_REPORT;
469 } else if (streq(#k, tok)) { \
470 sel->k = OPTION_TRUE; \
471 } else if (streq("!" #k, tok)) { \
472 sel->k = OPTION_FALSE;
474 bool parse_monitor_modifiers(char *desc, monitor_select_t *sel)
477 while ((tok = strrchr(desc, CAT_CHR)) != NULL) {
480 if (streq("occupied", tok)) {
481 sel->occupied = OPTION_TRUE;
482 } else if (streq("!occupied", tok)) {
483 sel->occupied = OPTION_FALSE;
492 bool parse_desktop_modifiers(char *desc, desktop_select_t *sel)
495 while ((tok = strrchr(desc, CAT_CHR)) != NULL) {
498 if (streq("occupied", tok)) {
499 sel->occupied = OPTION_TRUE;
500 } else if (streq("!occupied", tok)) {
501 sel->occupied = OPTION_FALSE;
509 GET_MOD(user_monocle)
518 bool parse_node_modifiers(char *desc, node_select_t *sel)
521 while ((tok = strrchr(desc, CAT_CHR)) != NULL) {
524 if (streq("tiled", tok)) {
525 sel->tiled = OPTION_TRUE;
526 } else if (streq("!tiled", tok)) {
527 sel->tiled = OPTION_FALSE;
534 GET_MOD(pseudo_tiled)
544 GET_MOD(descendant_of)