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