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("spiral", s)) {
282 bool parse_removal_adjustment(char *s, removal_adjustment_t *r)
284 if (streq("longest_side", s)) {
285 *r = ADJUSTMENT_LONGEST_SIDE;
287 } else if (streq("none", s)) {
288 *r = ADJUSTMENT_NONE;
294 bool parse_state_transition(char *s, state_transition_t *m)
296 if (streq("none", s)) {
299 } else if (streq("all", s)) {
300 *m = STATE_TRANSITION_ENTER | STATE_TRANSITION_EXIT;
303 state_transition_t w = 0;
304 char *x = copy_string(s, strlen(s));
305 char *key = strtok(x, ",");
306 while (key != NULL) {
307 if (streq("enter", key)) {
308 w |= STATE_TRANSITION_ENTER;
309 } else if (streq("exit", key)) {
310 w |= STATE_TRANSITION_EXIT;
315 key = strtok(NULL, ",");
328 bool parse_tightness(char *s, tightness_t *t)
330 if (streq("high", s)) {
333 } else if (streq("low", s)) {
340 bool parse_degree(char *s, int *d)
355 bool parse_id(char *s, uint32_t *id)
359 uint32_t v = strtol(s, &end, 0);
360 if (errno != 0 || *end != '\0') {
367 bool parse_bool_declaration(char *s, char **key, bool *value, alter_state_t *state)
369 *key = strtok(s, EQL_TOK);
370 char *v = strtok(NULL, EQL_TOK);
372 *state = ALTER_TOGGLE;
375 if (parse_bool(v, value)) {
385 bool parse_index(char *s, uint16_t *idx)
387 return (sscanf(s, "^%hu", idx) == 1);
390 bool parse_rectangle(char *s, xcb_rectangle_t *r)
394 if (sscanf(s, "%hux%hu+%hi+%hi", &w, &h, &x, &y) != 4) {
404 bool parse_subscriber_mask(char *s, subscriber_mask_t *mask)
406 if (streq("all", s)) {
407 *mask = SBSC_MASK_ALL;
408 } else if (streq("node", s)) {
409 *mask = SBSC_MASK_NODE;
410 } else if (streq("desktop", s)) {
411 *mask = SBSC_MASK_DESKTOP;
412 } else if (streq("monitor", s)) {
413 *mask = SBSC_MASK_MONITOR;
414 } else if (streq("pointer_action", s)) {
415 *mask = SBSC_MASK_POINTER_ACTION;
416 } else if (streq("node_add", s)) {
417 *mask = SBSC_MASK_NODE_ADD;
418 } else if (streq("node_remove", s)) {
419 *mask = SBSC_MASK_NODE_REMOVE;
420 } else if (streq("node_swap", s)) {
421 *mask = SBSC_MASK_NODE_SWAP;
422 } else if (streq("node_transfer", s)) {
423 *mask = SBSC_MASK_NODE_TRANSFER;
424 } else if (streq("node_focus", s)) {
425 *mask = SBSC_MASK_NODE_FOCUS;
426 } else if (streq("node_presel", s)) {
427 *mask = SBSC_MASK_NODE_PRESEL;
428 } else if (streq("node_stack", s)) {
429 *mask = SBSC_MASK_NODE_STACK;
430 } else if (streq("node_activate", s)) {
431 *mask = SBSC_MASK_NODE_ACTIVATE;
432 } else if (streq("node_geometry", s)) {
433 *mask = SBSC_MASK_NODE_GEOMETRY;
434 } else if (streq("node_state", s)) {
435 *mask = SBSC_MASK_NODE_STATE;
436 } else if (streq("node_flag", s)) {
437 *mask = SBSC_MASK_NODE_FLAG;
438 } else if (streq("node_layer", s)) {
439 *mask = SBSC_MASK_NODE_LAYER;
440 } else if (streq("desktop_add", s)) {
441 *mask = SBSC_MASK_DESKTOP_ADD;
442 } else if (streq("desktop_rename", s)) {
443 *mask = SBSC_MASK_DESKTOP_RENAME;
444 } else if (streq("desktop_remove", s)) {
445 *mask = SBSC_MASK_DESKTOP_REMOVE;
446 } else if (streq("desktop_swap", s)) {
447 *mask = SBSC_MASK_DESKTOP_SWAP;
448 } else if (streq("desktop_transfer", s)) {
449 *mask = SBSC_MASK_DESKTOP_TRANSFER;
450 } else if (streq("desktop_focus", s)) {
451 *mask = SBSC_MASK_DESKTOP_FOCUS;
452 } else if (streq("desktop_activate", s)) {
453 *mask = SBSC_MASK_DESKTOP_ACTIVATE;
454 } else if (streq("desktop_layout", s)) {
455 *mask = SBSC_MASK_DESKTOP_LAYOUT;
456 } else if (streq("monitor_add", s)) {
457 *mask = SBSC_MASK_MONITOR_ADD;
458 } else if (streq("monitor_rename", s)) {
459 *mask = SBSC_MASK_MONITOR_RENAME;
460 } else if (streq("monitor_remove", s)) {
461 *mask = SBSC_MASK_MONITOR_REMOVE;
462 } else if (streq("monitor_swap", s)) {
463 *mask = SBSC_MASK_MONITOR_SWAP;
464 } else if (streq("monitor_focus", s)) {
465 *mask = SBSC_MASK_MONITOR_FOCUS;
466 } else if (streq("monitor_geometry", s)) {
467 *mask = SBSC_MASK_MONITOR_GEOMETRY;
468 } else if (streq("report", s)) {
469 *mask = SBSC_MASK_REPORT;
478 } else if (streq(#k, tok)) { \
479 sel->k = OPTION_TRUE; \
480 } else if (streq("!" #k, tok)) { \
481 sel->k = OPTION_FALSE;
483 bool parse_monitor_modifiers(char *desc, monitor_select_t *sel)
486 while ((tok = strrchr(desc, CAT_CHR)) != NULL) {
489 if (streq("occupied", tok)) {
490 sel->occupied = OPTION_TRUE;
491 } else if (streq("!occupied", tok)) {
492 sel->occupied = OPTION_FALSE;
501 bool parse_desktop_modifiers(char *desc, desktop_select_t *sel)
504 while ((tok = strrchr(desc, CAT_CHR)) != NULL) {
507 if (streq("occupied", tok)) {
508 sel->occupied = OPTION_TRUE;
509 } else if (streq("!occupied", tok)) {
510 sel->occupied = OPTION_FALSE;
522 bool parse_node_modifiers(char *desc, node_select_t *sel)
525 while ((tok = strrchr(desc, CAT_CHR)) != NULL) {
528 if (streq("tiled", tok)) {
529 sel->tiled = OPTION_TRUE;
530 } else if (streq("!tiled", tok)) {
531 sel->tiled = OPTION_FALSE;
538 GET_MOD(pseudo_tiled)
548 GET_MOD(descendant_of)