]> git.lizzy.rs Git - bspwm.git/blob - messages.c
New message: 'restore_history'
[bspwm.git] / messages.c
1 #include <stdio.h>
2 #include <string.h>
3 #include <stdlib.h>
4 #include "settings.h"
5 #include "messages.h"
6 #include "common.h"
7 #include "types.h"
8 #include "bspwm.h"
9 #include "ewmh.h"
10 #include "helpers.h"
11 #include "window.h"
12 #include "events.h"
13 #include "tree.h"
14 #include "rules.h"
15
16 void process_message(char *msg, char *rsp)
17 {
18     char *cmd = strtok(msg, TOK_SEP);
19
20     if (cmd == NULL)
21         return;
22
23     if (strcmp(cmd, "get") == 0) {
24         char *name = strtok(NULL, TOK_SEP);
25         get_setting(name, rsp);
26         return;
27     } else if (strcmp(cmd, "set") == 0) {
28         char *name = strtok(NULL, TOK_SEP);
29         char *value = strtok(NULL, TOK_SEP);
30         set_setting(name, value, rsp);
31         return;
32     } else if (strcmp(cmd, "list") == 0) {
33         char *name = strtok(NULL, TOK_SEP);
34         if (name != NULL) {
35             desktop_location_t loc;
36             if (locate_desktop(name, &loc))
37                 list(loc.desktop, loc.desktop->root, rsp, 0);
38         } else {
39             list(mon->desk, mon->desk->root, rsp, 0);
40         }
41         return;
42     } else if (strcmp(cmd, "list_monitors") == 0) {
43         char *arg = strtok(NULL, TOK_SEP);
44         list_option_t opt;
45         if (parse_list_option(arg, &opt))
46             list_monitors(opt, rsp);
47         return;
48     } else if (strcmp(cmd, "list_desktops") == 0) {
49         char *arg = strtok(NULL, TOK_SEP);
50         list_option_t opt;
51         if (parse_list_option(arg, &opt))
52             list_desktops(mon, opt, 0, rsp);
53         return;
54     } else if (strcmp(cmd, "list_windows") == 0) {
55         list_windows(rsp);
56         return;
57     } else if (strcmp(cmd, "list_history") == 0) {
58         list_history(rsp);
59         return;
60     } else if (strcmp(cmd, "list_rules") == 0) {
61         list_rules(rsp);
62         return;
63     } else if (strcmp(cmd, "close") == 0) {
64         window_close(mon->desk->focus);
65         return;
66     } else if (strcmp(cmd, "kill") == 0) {
67         window_kill(mon->desk, mon->desk->focus);
68     } else if (strcmp(cmd, "rotate") == 0) {
69         char *deg = strtok(NULL, TOK_SEP);
70         if (deg != NULL) {
71             rotate_t r;
72             if (parse_rotate(deg, &r))
73                 rotate_tree(mon->desk->root, r);
74         }
75     } else if (strcmp(cmd, "flip") == 0) {
76         char *flp = strtok(NULL, TOK_SEP);
77         if (flp != NULL) {
78             flip_t f;
79             if (parse_flip(flp, &f))
80                 flip_tree(mon->desk->root, f);
81         }
82     } else if (strcmp(cmd, "balance") == 0) {
83         balance_tree(mon->desk->root);
84     } else if (strcmp(cmd, "grab_pointer") == 0) {
85         char *pac = strtok(NULL, TOK_SEP);
86         if (pac != NULL) {
87             pointer_action_t a;
88             if (parse_pointer_action(pac, &a))
89                 grab_pointer(a);
90         }
91     } else if (strcmp(cmd, "track_pointer") == 0) {
92         char *arg1 = strtok(NULL, TOK_SEP);
93         if (arg1 == NULL)
94             return;
95         char *arg2 = strtok(NULL, TOK_SEP);
96         if (arg2 == NULL)
97             return;
98         int root_x, root_y;
99         if (sscanf(arg1, "%i", &root_x) == 1 && sscanf(arg2, "%i", &root_y) == 1)
100             track_pointer(root_x, root_y);
101         return;
102     } else if (strcmp(cmd, "ungrab_pointer") == 0) {
103         ungrab_pointer();
104     } else if (strcmp(cmd, "layout") == 0) {
105         char *lyt = strtok(NULL, TOK_SEP);
106         if (lyt != NULL) {
107             layout_t y;
108             if (parse_layout(lyt, &y)) {
109                 char *name = strtok(NULL, TOK_SEP);
110                 if (name == NULL) {
111                     mon->desk->layout = y;
112                 } else {
113                     desktop_location_t loc;
114                     do {
115                         if (locate_desktop(name, &loc))
116                             loc.desktop->layout = y;
117                     } while ((name = strtok(NULL, TOK_SEP)) != NULL);
118                 }
119             }
120         }
121         put_status();
122     } else if (strcmp(cmd, "cycle_layout") == 0) {
123         if (mon->desk->layout == LAYOUT_MONOCLE)
124             mon->desk->layout = LAYOUT_TILED;
125         else
126             mon->desk->layout = LAYOUT_MONOCLE;
127         put_status();
128     } else if (strcmp(cmd, "shift") == 0) {
129         char *dir = strtok(NULL, TOK_SEP);
130         if (dir != NULL) {
131             direction_t d;
132             if (parse_direction(dir, &d))
133                 swap_nodes(mon->desk->focus, focus_by_distance ? nearest_neighbor(mon->desk, mon->desk->focus, d) : find_neighbor(mon->desk->focus, d));
134         }
135     } else if (strcmp(cmd, "toggle_fullscreen") == 0) {
136         if (mon->desk->focus != NULL)
137             toggle_fullscreen(mon, mon->desk->focus->client);
138     } else if (strcmp(cmd, "toggle_floating") == 0) {
139         split_mode = MODE_AUTOMATIC;
140         toggle_floating(mon->desk->focus);
141     } else if (strcmp(cmd, "toggle_locked") == 0) {
142         if (mon->desk->focus != NULL)
143             toggle_locked(mon->desk->focus->client);
144     } else if (strcmp(cmd, "toggle_visibility") == 0) {
145         toggle_visibility();
146     } else if (strcmp(cmd, "pad") == 0) {
147         char *name = strtok(NULL, TOK_SEP);
148         if (name != NULL) {
149             monitor_t *m = find_monitor(name);
150             if (m != NULL) {
151                 char args[BUFSIZ] = {0}, *s;
152                 while ((s = strtok(NULL, TOK_SEP)) != NULL) {
153                     strncat(args, s, REMLEN(args));
154                     strncat(args, TOK_SEP, REMLEN(args));
155                 }
156                 if (strlen(args) > 0) {
157                     sscanf(args, "%i %i %i %i", &m->top_padding, &m->right_padding, &m->bottom_padding, &m->left_padding);
158                     arrange(m, m->desk);
159                 } else {
160                     snprintf(rsp, BUFSIZ, "%i %i %i %i\n", m->top_padding, m->right_padding, m->bottom_padding, m->left_padding);
161                 }
162             }
163         }
164         return;
165     } else if (strcmp(cmd, "ratio") == 0) {
166         char *value = strtok(NULL, TOK_SEP);
167         if (value != NULL && mon->desk->focus != NULL)
168             sscanf(value, "%lf", &mon->desk->focus->split_ratio);
169     } else if (strcmp(cmd, "cancel") == 0) {
170         split_mode = MODE_AUTOMATIC;
171         window_draw_border(mon->desk->focus, true, true);
172         return;
173     } else if (strcmp(cmd, "presel") == 0) {
174         if (mon->desk->focus == NULL || !is_tiled(mon->desk->focus->client) || mon->desk->layout != LAYOUT_TILED)
175             return;
176         char *dir = strtok(NULL, TOK_SEP);
177         if (dir != NULL) {
178             direction_t d;
179             if (parse_direction(dir, &d)) {
180                 split_mode = MODE_MANUAL;
181                 split_dir = d;
182                 char *rat = strtok(NULL, TOK_SEP);
183                 if (rat != NULL)
184                     sscanf(rat, "%lf", &mon->desk->focus->split_ratio);
185                 window_draw_border(mon->desk->focus, true, true);
186             }
187         }
188         return;
189     } else if (strcmp(cmd, "push") == 0 || strcmp(cmd, "pull") == 0) {
190         char *dir = strtok(NULL, TOK_SEP);
191         if (dir != NULL) {
192             fence_move_t m;
193             direction_t d;
194             if (parse_fence_move(cmd, &m) && parse_direction(dir, &d)) {
195                 move_fence(mon->desk->focus, d, m);
196             }
197         }
198     } else if (strcmp(cmd, "drop_to_monitor") == 0) {
199         char *dir = strtok(NULL, TOK_SEP);
200         if (dir != NULL) {
201             cycle_dir_t d;
202             if (parse_cycle_direction(dir, &d)) {
203                 monitor_t *m;
204                 if (d == CYCLE_NEXT)
205                     m = ((mon->next == NULL ? mon_head : mon->next));
206                 else
207                     m = ((mon->prev == NULL ? mon_tail : mon->prev));
208                 transfer_node(mon, mon->desk, m, m->desk, mon->desk->focus);
209                 arrange(m, m->desk);
210                 char *opt = strtok(NULL, TOK_SEP);
211                 send_option_t o;
212                 if (parse_send_option(opt, &o) && o == SEND_OPTION_FOLLOW)
213                     select_monitor(m);
214             }
215         }
216     } else if (strcmp(cmd, "send_to_monitor") == 0) {
217         char *name = strtok(NULL, TOK_SEP);
218         if (name != NULL) {
219             monitor_t *m = find_monitor(name);
220             if (m != NULL && m != mon) {
221                 transfer_node(mon, mon->desk, m, m->desk, mon->desk->focus);
222                 arrange(m, m->desk);
223                 char *opt = strtok(NULL, TOK_SEP);
224                 send_option_t o;
225                 if (parse_send_option(opt, &o) && o == SEND_OPTION_FOLLOW)
226                     select_monitor(m);
227             }
228         }
229     } else if (strcmp(cmd, "drop_to") == 0) {
230         char *dir = strtok(NULL, TOK_SEP);
231         if (dir != NULL) {
232             cycle_dir_t c;
233             if (parse_cycle_direction(dir, &c)) {
234                 desktop_t *d;
235                 if (c == CYCLE_NEXT)
236                     d = ((mon->desk->next == NULL ? mon->desk_head : mon->desk->next));
237                 else
238                     d = ((mon->desk->prev == NULL ? mon->desk_tail : mon->desk->prev));
239                 transfer_node(mon, mon->desk, mon, d, mon->desk->focus);
240                 char *opt = strtok(NULL, TOK_SEP);
241                 send_option_t o;
242                 if (parse_send_option(opt, &o) && o == SEND_OPTION_FOLLOW)
243                     select_desktop(d);
244             }
245         }
246     } else if (strcmp(cmd, "send_to") == 0) {
247         char *name = strtok(NULL, TOK_SEP);
248         if (name != NULL) {
249             desktop_location_t loc;
250             if (locate_desktop(name, &loc)) {
251                 transfer_node(mon, mon->desk, loc.monitor, loc.desktop, mon->desk->focus);
252                 if (mon != loc.monitor && loc.monitor->desk == loc.desktop)
253                     arrange(loc.monitor, loc.desktop);
254                 char *opt = strtok(NULL, TOK_SEP);
255                 send_option_t o;
256                 if (parse_send_option(opt, &o) && o == SEND_OPTION_FOLLOW) {
257                     select_monitor(loc.monitor);
258                     select_desktop(loc.desktop);
259                 }
260             }
261         }
262     } else if (strcmp(cmd, "rename_monitor") == 0) {
263         char *cur_name = strtok(NULL, TOK_SEP);
264         if (cur_name != NULL) {
265             monitor_t *m = find_monitor(cur_name);
266             if (m != NULL) {
267                 char *new_name = strtok(NULL, TOK_SEP);
268                 if (new_name != NULL) {
269                     strncpy(m->name, new_name, sizeof(m->name));
270                     put_status();
271                 }
272             }
273         }
274     } else if (strcmp(cmd, "rename") == 0) {
275         char *cur_name = strtok(NULL, TOK_SEP);
276         if (cur_name != NULL) {
277             desktop_location_t loc;
278             if (locate_desktop(cur_name, &loc)) {
279                 char *new_name = strtok(NULL, TOK_SEP);
280                 if (new_name != NULL) {
281                     strncpy(loc.desktop->name, new_name, sizeof(loc.desktop->name));
282                     ewmh_update_desktop_names();
283                     put_status();
284                 }
285             }
286         }
287     } else if (strcmp(cmd, "use_monitor") == 0) {
288         char *name = strtok(NULL, TOK_SEP);
289         if (name != NULL) {
290             monitor_t *m = find_monitor(name);
291             if (m != NULL)
292                 select_monitor(m);
293         }
294     } else if (strcmp(cmd, "use") == 0) {
295         char *name = strtok(NULL, TOK_SEP);
296         if (name != NULL) {
297             desktop_location_t loc;
298             if (locate_desktop(name, &loc)) {
299                 if (auto_alternate && loc.desktop == mon->desk) {
300                     select_desktop(mon->last_desk);
301                 } else {
302                     select_monitor(loc.monitor);
303                     select_desktop(loc.desktop);
304                 }
305             }
306         }
307     } else if (strcmp(cmd, "cycle_monitor") == 0) {
308         char *dir = strtok(NULL, TOK_SEP);
309         if (dir != NULL) {
310             cycle_dir_t d;
311             if (parse_cycle_direction(dir, &d))
312                 cycle_monitor(d);
313         }
314     } else if (strcmp(cmd, "cycle_desktop") == 0) {
315         char *dir = strtok(NULL, TOK_SEP);
316         if (dir != NULL) {
317             cycle_dir_t d;
318             if (parse_cycle_direction(dir, &d)) {
319                 skip_desktop_t k;
320                 char *skip = strtok(NULL, TOK_SEP);
321                 if (parse_skip_desktop(skip, &k))
322                     cycle_desktop(mon, mon->desk, d, k);
323             }
324         }
325     } else if (strcmp(cmd, "cycle") == 0) {
326         if (mon->desk->focus != NULL && mon->desk->focus->client->fullscreen)
327             return;
328         char *dir = strtok(NULL, TOK_SEP);
329         if (dir != NULL) {
330             cycle_dir_t d;
331             if (parse_cycle_direction(dir, &d)) {
332                 skip_client_t k;
333                 char *skip = strtok(NULL, TOK_SEP);
334                 if (parse_skip_client(skip, &k))
335                     cycle_leaf(mon, mon->desk, mon->desk->focus, d, k);
336             }
337         }
338         return;
339     } else if (strcmp(cmd, "nearest") == 0) {
340         if (mon->desk->focus != NULL && mon->desk->focus->client->fullscreen)
341             return;
342         char *arg = strtok(NULL, TOK_SEP);
343         if (arg != NULL) {
344             nearest_arg_t a;
345             if (parse_nearest_argument(arg, &a)) {
346                 skip_client_t k;
347                 char *skip = strtok(NULL, TOK_SEP);
348                 if (parse_skip_client(skip, &k))
349                     nearest_leaf(mon, mon->desk, mon->desk->focus, a, k);
350             }
351         }
352         return;
353     } else if (strcmp(cmd, "circulate") == 0) {
354         if (mon->desk->layout == LAYOUT_MONOCLE
355                 || (mon->desk->focus != NULL && !is_tiled(mon->desk->focus->client)))
356             return;
357         char *dir = strtok(NULL, TOK_SEP);
358         if (dir != NULL) {
359             circulate_dir_t d;
360             if (parse_circulate_direction(dir, &d))
361                 circulate_leaves(mon, mon->desk, d);
362         }
363     } else if (strcmp(cmd, "rule") == 0) {
364         char *name = strtok(NULL, TOK_SEP);
365         if (name != NULL) {
366             rule_t *rule = make_rule();
367             strncpy(rule->cause.name, name, sizeof(rule->cause.name));
368             char *arg = strtok(NULL, TOK_SEP);
369             while (arg != NULL) {
370                 if (strcmp(arg, "floating") == 0) {
371                     rule->effect.floating = true;
372                 } else if (strcmp(arg, "follow") == 0) {
373                     rule->effect.follow = true;
374                 } else {
375                     desktop_location_t loc;
376                     if (locate_desktop(arg, &loc)) {
377                         rule->effect.monitor = loc.monitor;
378                         rule->effect.desktop = loc.desktop;
379                     }
380                 }
381                 arg = strtok(NULL, TOK_SEP);
382             }
383             add_rule(rule);
384         }
385         return;
386     } else if (strcmp(cmd, "remove_rule") == 0) {
387         char *arg;
388         unsigned int uid;
389         while ((arg = strtok(NULL, TOK_SEP)) != NULL)
390             if (sscanf(arg, "%X", &uid) > 0)
391                 remove_rule_by_uid(uid);
392         return;
393     } else if (strcmp(cmd, "swap") == 0) {
394         char *arg;
395         swap_arg_t a;
396         if ((arg = strtok(NULL, TOK_SEP)) != NULL) {
397             if (parse_swap_argument(arg, &a)) {
398                 node_t *n = find_by_area(mon->desk, a);
399                 swap_nodes(mon->desk->focus, n);
400             }
401         } else {
402             swap_nodes(mon->desk->focus, history_get(mon->desk->history, 1));
403         }
404     } else if (strcmp(cmd, "alternate") == 0) {
405         focus_node(mon, mon->desk, history_get(mon->desk->history, 1), true);
406         return;
407     } else if (strcmp(cmd, "alternate_desktop") == 0) {
408         select_desktop(mon->last_desk);
409     } else if (strcmp(cmd, "alternate_monitor") == 0) {
410         select_monitor(last_mon);
411     } else if (strcmp(cmd, "add_in") == 0) {
412         char *name = strtok(NULL, TOK_SEP);
413         if (name != NULL) {
414             monitor_t *m = find_monitor(name);
415             if (m != NULL)
416                 for (name = strtok(NULL, TOK_SEP); name != NULL; name = strtok(NULL, TOK_SEP))
417                     add_desktop(m, name);
418         }
419         return;
420     } else if (strcmp(cmd, "add") == 0) {
421         for (char *name = strtok(NULL, TOK_SEP); name != NULL; name = strtok(NULL, TOK_SEP))
422             add_desktop(mon, name);
423         return;
424     } else if (strcmp(cmd, "focus") == 0) {
425         if (mon->desk->focus != NULL && mon->desk->focus->client->fullscreen)
426             return;
427         char *dir = strtok(NULL, TOK_SEP);
428         if (dir != NULL) {
429             direction_t d;
430             if (parse_direction(dir, &d)) {
431                 node_t *n;
432                 if (focus_by_distance)
433                     n = nearest_neighbor(mon->desk, mon->desk->focus, d);
434                 else
435                     n = find_neighbor(mon->desk->focus, d);
436                 focus_node(mon, mon->desk, n, true);
437             }
438         }
439         if (mon->desk->layout == LAYOUT_TILED)
440             return;
441     } else if (strcmp(cmd, "put_status") == 0) {
442         put_status();
443     } else if (strcmp(cmd, "adopt_orphans") == 0) {
444         adopt_orphans();
445     } else if (strcmp(cmd, "restore_layout") == 0) {
446         char *arg = strtok(NULL, TOK_SEP);
447         restore_layout(arg);
448     } else if (strcmp(cmd, "restore_history") == 0) {
449         char *arg = strtok(NULL, TOK_SEP);
450         restore_history(arg);
451     } else if (strcmp(cmd, "quit") == 0) {
452         char *arg = strtok(NULL, TOK_SEP);
453         if (arg != NULL)
454             sscanf(arg, "%i", &exit_status);
455         quit();
456         return;
457     } else {
458         snprintf(rsp, BUFSIZ, "unknown command: %s", cmd);
459         return;
460     }
461
462     arrange(mon, mon->desk);
463 }
464
465 void set_setting(char *name, char *value, char *rsp)
466 {
467     if (name == NULL || value == NULL)
468         return;
469
470     if (strcmp(name, "border_width") == 0) {
471         sscanf(value, "%u", &border_width);
472     } else if (strcmp(name, "window_gap") == 0) {
473         sscanf(value, "%i", &window_gap);
474     } else if (strcmp(name, "split_ratio") == 0) {
475         sscanf(value, "%lf", &split_ratio);
476     } else if (strcmp(name, "left_padding") == 0) {
477         sscanf(value, "%i", &mon->left_padding);
478     } else if (strcmp(name, "right_padding") == 0) {
479         sscanf(value, "%i", &mon->right_padding);
480     } else if (strcmp(name, "top_padding") == 0) {
481         sscanf(value, "%i", &mon->top_padding);
482     } else if (strcmp(name, "bottom_padding") == 0) {
483         sscanf(value, "%i", &mon->bottom_padding);
484     } else if (strcmp(name, "focused_border_color") == 0) {
485         strncpy(focused_border_color, value, sizeof(focused_border_color));
486         focused_border_color_pxl = get_color(focused_border_color);
487     } else if (strcmp(name, "active_border_color") == 0) {
488         strncpy(active_border_color, value, sizeof(active_border_color));
489         active_border_color_pxl = get_color(active_border_color);
490     } else if (strcmp(name, "normal_border_color") == 0) {
491         strncpy(normal_border_color, value, sizeof(normal_border_color));
492         normal_border_color_pxl = get_color(normal_border_color);
493     } else if (strcmp(name, "presel_border_color") == 0) {
494         strncpy(presel_border_color, value, sizeof(presel_border_color));
495         presel_border_color_pxl = get_color(presel_border_color);
496     } else if (strcmp(name, "focused_locked_border_color") == 0) {
497         strncpy(focused_locked_border_color, value, sizeof(focused_locked_border_color));
498         focused_locked_border_color_pxl = get_color(focused_locked_border_color);
499     } else if (strcmp(name, "active_locked_border_color") == 0) {
500         strncpy(active_locked_border_color, value, sizeof(active_locked_border_color));
501         active_locked_border_color_pxl = get_color(active_locked_border_color);
502     } else if (strcmp(name, "normal_locked_border_color") == 0) {
503         strncpy(normal_locked_border_color, value, sizeof(normal_locked_border_color));
504         normal_locked_border_color_pxl = get_color(normal_locked_border_color);
505     } else if (strcmp(name, "urgent_border_color") == 0) {
506         strncpy(urgent_border_color, value, sizeof(urgent_border_color));
507         urgent_border_color_pxl = get_color(urgent_border_color);
508     } else if (strcmp(name, "borderless_monocle") == 0) {
509         bool b;
510         if (parse_bool(value, &b))
511             borderless_monocle = b;
512     } else if (strcmp(name, "gapless_monocle") == 0) {
513         bool b;
514         if (parse_bool(value, &b))
515             gapless_monocle = b;
516     } else if (strcmp(name, "focus_follows_pointer") == 0) {
517         bool b;
518         if (parse_bool(value, &b) && b != focus_follows_pointer) {
519             uint32_t values[] = {(focus_follows_pointer ? CLIENT_EVENT_MASK : CLIENT_EVENT_MASK_FFP)};
520             for (monitor_t *m = mon_head; m != NULL; m = m->next)
521                 for (desktop_t *d = m->desk_head; d != NULL; d = d->next)
522                     for (node_t *n = first_extrema(d->root); n != NULL; n = next_leaf(n, d->root))
523                         xcb_change_window_attributes(dpy, n->client->window, XCB_CW_EVENT_MASK, values);
524             if (focus_follows_pointer)
525                 disable_motion_recorder();
526             else
527                 enable_motion_recorder();
528             focus_follows_pointer = b;
529         }
530     } else if (strcmp(name, "adaptative_raise") == 0) {
531         bool b;
532         if (parse_bool(value, &b))
533             adaptative_raise = b;
534     } else if (strcmp(name, "apply_shadow_property") == 0) {
535         bool b;
536         if (parse_bool(value, &b))
537             apply_shadow_property = b;
538     } else if (strcmp(name, "auto_alternate") == 0) {
539         bool b;
540         if (parse_bool(value, &b))
541             auto_alternate = b;
542     } else if (strcmp(name, "focus_by_distance") == 0) {
543         bool b;
544         if (parse_bool(value, &b))
545             focus_by_distance = b;
546     } else if (strcmp(name, "wm_name") == 0) {
547         strncpy(wm_name, value, sizeof(wm_name));
548         ewmh_update_wm_name();
549         return;
550     } else {
551         snprintf(rsp, BUFSIZ, "unknown setting: %s", name);
552         return;
553     }
554
555     arrange(mon, mon->desk);
556 }
557
558 void get_setting(char *name, char* rsp)
559 {
560     if (name == NULL)
561         return;
562
563     if (strcmp(name, "border_width") == 0)
564         snprintf(rsp, BUFSIZ, "%u", border_width);
565     else if (strcmp(name, "window_gap") == 0)
566         snprintf(rsp, BUFSIZ, "%i", window_gap);
567     else if (strcmp(name, "split_ratio") == 0)
568         snprintf(rsp, BUFSIZ, "%lf", split_ratio);
569     else if (strcmp(name, "left_padding") == 0)
570         snprintf(rsp, BUFSIZ, "%i", mon->left_padding);
571     else if (strcmp(name, "right_padding") == 0)
572         snprintf(rsp, BUFSIZ, "%i", mon->right_padding);
573     else if (strcmp(name, "top_padding") == 0)
574         snprintf(rsp, BUFSIZ, "%i", mon->top_padding);
575     else if (strcmp(name, "bottom_padding") == 0)
576         snprintf(rsp, BUFSIZ, "%i", mon->bottom_padding);
577     else if (strcmp(name, "focused_border_color") == 0)
578         snprintf(rsp, BUFSIZ, "%s (%06X)", focused_border_color, focused_border_color_pxl);
579     else if (strcmp(name, "active_border_color") == 0)
580         snprintf(rsp, BUFSIZ, "%s (%06X)", active_border_color, active_border_color_pxl);
581     else if (strcmp(name, "normal_border_color") == 0)
582         snprintf(rsp, BUFSIZ, "%s (%06X)", normal_border_color, normal_border_color_pxl);
583     else if (strcmp(name, "presel_border_color") == 0)
584         snprintf(rsp, BUFSIZ, "%s (%06X)", presel_border_color, presel_border_color_pxl);
585     else if (strcmp(name, "focused_locked_border_color") == 0)
586         snprintf(rsp, BUFSIZ, "%s (%06X)", focused_locked_border_color, focused_locked_border_color_pxl);
587     else if (strcmp(name, "active_locked_border_color") == 0)
588         snprintf(rsp, BUFSIZ, "%s (%06X)", active_locked_border_color, active_locked_border_color_pxl);
589     else if (strcmp(name, "normal_locked_border_color") == 0)
590         snprintf(rsp, BUFSIZ, "%s (%06X)", normal_locked_border_color, normal_locked_border_color_pxl);
591     else if (strcmp(name, "urgent_border_color") == 0)
592         snprintf(rsp, BUFSIZ, "%s (%06X)", urgent_border_color, urgent_border_color_pxl);
593     else if (strcmp(name, "borderless_monocle") == 0)
594         snprintf(rsp, BUFSIZ, "%s", BOOLSTR(borderless_monocle));
595     else if (strcmp(name, "gapless_monocle") == 0)
596         snprintf(rsp, BUFSIZ, "%s", BOOLSTR(gapless_monocle));
597     else if (strcmp(name, "focus_follows_pointer") == 0)
598         snprintf(rsp, BUFSIZ, "%s", BOOLSTR(focus_follows_pointer));
599     else if (strcmp(name, "adaptative_raise") == 0)
600         snprintf(rsp, BUFSIZ, "%s", BOOLSTR(adaptative_raise));
601     else if (strcmp(name, "apply_shadow_property") == 0)
602         snprintf(rsp, BUFSIZ, "%s", BOOLSTR(apply_shadow_property));
603     else if (strcmp(name, "auto_alternate") == 0)
604         snprintf(rsp, BUFSIZ, "%s", BOOLSTR(auto_alternate));
605     else if (strcmp(name, "focus_by_distance") == 0)
606         snprintf(rsp, BUFSIZ, "%s", BOOLSTR(focus_by_distance));
607     else if (strcmp(name, "wm_name") == 0)
608         snprintf(rsp, BUFSIZ, "%s", wm_name);
609     else
610         snprintf(rsp, BUFSIZ, "unknown setting: %s", name);
611 }
612
613 bool parse_bool(char *value, bool *b)
614 {
615     if (strcmp(value, "true") == 0) {
616         *b = true;
617         return true;
618     } else if (strcmp(value, "false") == 0) {
619         *b = false;
620         return true;
621     }
622     return false;
623 }
624
625 bool parse_layout(char *s, layout_t *l)
626 {
627     if (strcmp(s, "monocle") == 0) {
628         *l = LAYOUT_MONOCLE;
629         return true;
630     } else if (strcmp(s, "tiled") == 0) {
631         *l = LAYOUT_TILED;
632         return true;
633     }
634     return false;
635 }
636
637 bool parse_direction(char *s, direction_t *d)
638 {
639     if (strcmp(s, "up") == 0) {
640         *d = DIR_UP;
641         return true;
642     } else if (strcmp(s, "down") == 0) {
643         *d = DIR_DOWN;
644         return true;
645     } else if (strcmp(s, "left") == 0) {
646         *d = DIR_LEFT;
647         return true;
648     } else if (strcmp(s, "right") == 0) {
649         *d = DIR_RIGHT;
650         return true;
651     }
652     return false;
653 }
654
655 bool parse_nearest_argument(char *s, nearest_arg_t *a)
656 {
657     if (strcmp(s, "older") == 0) {
658         *a = NEAREST_OLDER;
659         return true;
660     } else if (strcmp(s, "newer") == 0) {
661         *a = NEAREST_NEWER;
662         return true;
663     }
664     return false;
665 }
666
667 bool parse_swap_argument(char *s, swap_arg_t *a)
668 {
669     if (strcmp(s, "biggest") == 0) {
670         *a = SWAP_BIGGEST;
671         return true;
672     } else if (strcmp(s, "smallest") == 0) {
673         *a = SWAP_SMALLEST;
674         return true;
675     }
676     return false;
677 }
678
679 bool parse_cycle_direction(char *s, cycle_dir_t *d)
680 {
681     if (strcmp(s, "prev") == 0) {
682         *d = CYCLE_PREV;
683         return true;
684     } else if (strcmp(s, "next") == 0) {
685         *d = CYCLE_NEXT;
686         return true;
687     }
688     return false;
689 }
690
691 bool parse_circulate_direction(char *s, circulate_dir_t *d)
692 {
693     if (strcmp(s, "forward") == 0) {
694         *d = CIRCULATE_FORWARD;
695         return true;
696     } else if (strcmp(s, "backward") == 0) {
697         *d = CIRCULATE_BACKWARD;
698         return true;
699     }
700     return false;
701 }
702
703 bool parse_skip_client(char *s, skip_client_t *k)
704 {
705     if (s == NULL) {
706         *k = CLIENT_SKIP_NONE;
707         return true;
708     } else if (strcmp(s, "--skip-floating") == 0) {
709         *k = CLIENT_SKIP_FLOATING;
710         return true;
711     } else if (strcmp(s, "--skip-tiled") == 0) {
712         *k = CLIENT_SKIP_TILED;
713         return true;
714     } else if (strcmp(s, "--skip-class-equal") == 0) {
715         *k = CLIENT_SKIP_CLASS_EQUAL;
716         return true;
717     } else if (strcmp(s, "--skip-class-differ") == 0) {
718         *k = CLIENT_SKIP_CLASS_DIFFER;
719         return true;
720     }
721     return false;
722 }
723
724 bool parse_skip_desktop(char *s, skip_desktop_t *k)
725 {
726     if (s == NULL) {
727         *k = DESKTOP_SKIP_NONE;
728         return true;
729     } else if (strcmp(s, "--skip-free") == 0) {
730         *k = DESKTOP_SKIP_FREE;
731         return true;
732     } else if (strcmp(s, "--skip-occupied") == 0) {
733         *k = DESKTOP_SKIP_OCCUPIED;
734         return true;
735     }
736     return false;
737 }
738
739 bool parse_list_option(char *s, list_option_t *o)
740 {
741     if (s == NULL || strcmp(s, "--verbose") == 0) {
742         *o = LIST_OPTION_VERBOSE;
743         return true;
744     } else if (strcmp(s, "--quiet") == 0) {
745         *o = LIST_OPTION_QUIET;
746         return true;
747     }
748     return false;
749 }
750
751 bool parse_send_option(char *s, send_option_t *o)
752 {
753     if (s == NULL) {
754         *o = SEND_OPTION_DONT_FOLLOW;
755         return true;
756     } else if (strcmp(s, "--follow") == 0) {
757         *o = SEND_OPTION_FOLLOW;
758         return true;
759     }
760     return false;
761 }
762
763 bool parse_rotate(char *s, rotate_t *r)
764 {
765     if (strcmp(s, "clockwise") == 0) {
766         *r = ROTATE_CLOCKWISE;
767         return true;
768     } else if (strcmp(s, "counter_clockwise") == 0) {
769         *r = ROTATE_COUNTER_CLOCKWISE;
770         return true;
771     } else if (strcmp(s, "full_cycle") == 0) {
772         *r = ROTATE_FULL_CYCLE;
773         return true;
774     }
775     return false;
776 }
777
778 bool parse_flip(char *s, flip_t *f)
779 {
780     if (strcmp(s, "horizontal") == 0) {
781         *f = FLIP_HORIZONTAL;
782         return true;
783     } else if (strcmp(s, "vertical") == 0) {
784         *f = FLIP_VERTICAL;
785         return true;
786     }
787     return false;
788 }
789
790 bool parse_fence_move(char *s, fence_move_t *m)
791 {
792     if (strcmp(s, "push") == 0) {
793         *m = MOVE_PUSH;
794         return true;
795     } else if (strcmp(s, "pull") == 0) {
796         *m = MOVE_PULL;
797         return true;
798     }
799     return false;
800 }
801
802 bool parse_pointer_action(char *s, pointer_action_t *a)
803 {
804     if (strcmp(s, "move") == 0) {
805         *a = ACTION_MOVE;
806         return true;
807     } else if (strcmp(s, "resize_corner") == 0) {
808         *a = ACTION_RESIZE_CORNER;
809         return true;
810     } else if (strcmp(s, "resize_side") == 0) {
811         *a = ACTION_RESIZE_SIDE;
812         return true;
813     } else if (strcmp(s, "focus") == 0) {
814         *a = ACTION_FOCUS;
815         return true;
816     }
817     return false;
818 }