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_pointer_action(char *s, pointer_action_t *a)
218 if (streq("move", s)) {
221 } else if (streq("resize_corner", s)) {
222 *a = ACTION_RESIZE_CORNER;
224 } else if (streq("resize_side", s)) {
225 *a = ACTION_RESIZE_SIDE;
227 } else if (streq("focus", s)) {
234 bool parse_child_polarity(char *s, child_polarity_t *p)
236 if (streq("first_child", s)) {
239 } else if (streq("second_child", s)) {
246 bool parse_degree(char *s, int *d)
261 bool parse_id(char *s, uint32_t *id)
265 uint32_t v = strtol(s, &end, 0);
266 if (errno != 0 || *end != '\0') {
273 bool parse_bool_declaration(char *s, char **key, bool *value, alter_state_t *state)
275 *key = strtok(s, EQL_TOK);
276 char *v = strtok(NULL, EQL_TOK);
278 *state = ALTER_TOGGLE;
281 if (parse_bool(v, value)) {
291 bool parse_index(char *s, uint16_t *idx)
293 return (sscanf(s, "^%hu", idx) == 1);
296 bool parse_rectangle(char *s, xcb_rectangle_t *r)
300 if (sscanf(s, "%hux%hu+%hi+%hi", &w, &h, &x, &y) != 4) {
310 bool parse_subscriber_mask(char *s, subscriber_mask_t *mask)
312 if (streq("all", s)) {
313 *mask = SBSC_MASK_ALL;
314 } else if (streq("node", s)) {
315 *mask = SBSC_MASK_NODE;
316 } else if (streq("desktop", s)) {
317 *mask = SBSC_MASK_DESKTOP;
318 } else if (streq("monitor", s)) {
319 *mask = SBSC_MASK_MONITOR;
320 } else if (streq("node_manage", s)) {
321 *mask = SBSC_MASK_NODE_MANAGE;
322 } else if (streq("node_unmanage", s)) {
323 *mask = SBSC_MASK_NODE_UNMANAGE;
324 } else if (streq("node_swap", s)) {
325 *mask = SBSC_MASK_NODE_SWAP;
326 } else if (streq("node_transfer", s)) {
327 *mask = SBSC_MASK_NODE_TRANSFER;
328 } else if (streq("node_focus", s)) {
329 *mask = SBSC_MASK_NODE_FOCUS;
330 } else if (streq("node_presel", s)) {
331 *mask = SBSC_MASK_NODE_PRESEL;
332 } else if (streq("node_stack", s)) {
333 *mask = SBSC_MASK_NODE_STACK;
334 } else if (streq("node_activate", s)) {
335 *mask = SBSC_MASK_NODE_ACTIVATE;
336 } else if (streq("node_geometry", s)) {
337 *mask = SBSC_MASK_NODE_GEOMETRY;
338 } else if (streq("node_state", s)) {
339 *mask = SBSC_MASK_NODE_STATE;
340 } else if (streq("node_flag", s)) {
341 *mask = SBSC_MASK_NODE_FLAG;
342 } else if (streq("node_layer", s)) {
343 *mask = SBSC_MASK_NODE_LAYER;
344 } else if (streq("desktop_add", s)) {
345 *mask = SBSC_MASK_DESKTOP_ADD;
346 } else if (streq("desktop_rename", s)) {
347 *mask = SBSC_MASK_DESKTOP_RENAME;
348 } else if (streq("desktop_remove", s)) {
349 *mask = SBSC_MASK_DESKTOP_REMOVE;
350 } else if (streq("desktop_swap", s)) {
351 *mask = SBSC_MASK_DESKTOP_SWAP;
352 } else if (streq("desktop_transfer", s)) {
353 *mask = SBSC_MASK_DESKTOP_TRANSFER;
354 } else if (streq("desktop_focus", s)) {
355 *mask = SBSC_MASK_DESKTOP_FOCUS;
356 } else if (streq("desktop_activate", s)) {
357 *mask = SBSC_MASK_DESKTOP_ACTIVATE;
358 } else if (streq("desktop_layout", s)) {
359 *mask = SBSC_MASK_DESKTOP_LAYOUT;
360 } else if (streq("monitor_add", s)) {
361 *mask = SBSC_MASK_MONITOR_ADD;
362 } else if (streq("monitor_rename", s)) {
363 *mask = SBSC_MASK_MONITOR_RENAME;
364 } else if (streq("monitor_remove", s)) {
365 *mask = SBSC_MASK_MONITOR_REMOVE;
366 } else if (streq("monitor_swap", s)) {
367 *mask = SBSC_MASK_MONITOR_SWAP;
368 } else if (streq("monitor_focus", s)) {
369 *mask = SBSC_MASK_MONITOR_FOCUS;
370 } else if (streq("monitor_geometry", s)) {
371 *mask = SBSC_MASK_MONITOR_GEOMETRY;
372 } else if (streq("report", s)) {
373 *mask = SBSC_MASK_REPORT;
382 } else if (streq(#k, tok)) { \
383 sel->k = OPTION_TRUE; \
384 } else if (streq("!" #k, tok)) { \
385 sel->k = OPTION_FALSE;
387 bool parse_monitor_modifiers(char *desc, monitor_select_t *sel)
390 while ((tok = strrchr(desc, CAT_CHR)) != NULL) {
393 if (streq("occupied", tok)) {
394 sel->occupied = OPTION_TRUE;
395 } else if (streq("!occupied", tok)) {
396 sel->occupied = OPTION_FALSE;
405 bool parse_desktop_modifiers(char *desc, desktop_select_t *sel)
408 while ((tok = strrchr(desc, CAT_CHR)) != NULL) {
411 if (streq("occupied", tok)) {
412 sel->occupied = OPTION_TRUE;
413 } else if (streq("!occupied", tok)) {
414 sel->occupied = OPTION_FALSE;
426 bool parse_node_modifiers(char *desc, node_select_t *sel)
429 while ((tok = strrchr(desc, CAT_CHR)) != NULL) {
432 if (streq("tiled", tok)) {
433 sel->tiled = OPTION_TRUE;
434 } else if (streq("!tiled", tok)) {
435 sel->tiled = OPTION_FALSE;
441 GET_MOD(pseudo_tiled)