]> git.lizzy.rs Git - bspwm.git/blob - messages.c
3acc9c2a02524bba4f8115f3501c326ca05b3f91
[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                 if (auto_alternate && m == mon && last_mon != NULL) {
293                     select_monitor(last_mon);
294                     select_desktop(last_mon->desk);
295                 } else {
296                     select_monitor(m);
297                     select_desktop(m->desk);
298                 }
299             }
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));
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);
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_layout") == 0) {
453         char *arg = strtok(NULL, TOK_SEP);
454         restore_layout(arg);
455     } else if (strcmp(cmd, "restore_history") == 0) {
456         char *arg = strtok(NULL, TOK_SEP);
457         restore_history(arg);
458     } else if (strcmp(cmd, "quit") == 0) {
459         char *arg = strtok(NULL, TOK_SEP);
460         if (arg != NULL)
461             sscanf(arg, "%i", &exit_status);
462         quit();
463         return;
464     } else {
465         snprintf(rsp, BUFSIZ, "unknown command: %s", cmd);
466         return;
467     }
468
469     arrange(mon, mon->desk);
470 }
471
472 void set_setting(char *name, char *value, char *rsp)
473 {
474     if (name == NULL || value == NULL)
475         return;
476
477     if (strcmp(name, "border_width") == 0) {
478         sscanf(value, "%u", &border_width);
479     } else if (strcmp(name, "window_gap") == 0) {
480         sscanf(value, "%i", &window_gap);
481     } else if (strcmp(name, "split_ratio") == 0) {
482         sscanf(value, "%lf", &split_ratio);
483     } else if (strcmp(name, "left_padding") == 0) {
484         sscanf(value, "%i", &mon->left_padding);
485     } else if (strcmp(name, "right_padding") == 0) {
486         sscanf(value, "%i", &mon->right_padding);
487     } else if (strcmp(name, "top_padding") == 0) {
488         sscanf(value, "%i", &mon->top_padding);
489     } else if (strcmp(name, "bottom_padding") == 0) {
490         sscanf(value, "%i", &mon->bottom_padding);
491     } else if (strcmp(name, "focused_border_color") == 0) {
492         strncpy(focused_border_color, value, sizeof(focused_border_color));
493         focused_border_color_pxl = get_color(focused_border_color);
494     } else if (strcmp(name, "active_border_color") == 0) {
495         strncpy(active_border_color, value, sizeof(active_border_color));
496         active_border_color_pxl = get_color(active_border_color);
497     } else if (strcmp(name, "normal_border_color") == 0) {
498         strncpy(normal_border_color, value, sizeof(normal_border_color));
499         normal_border_color_pxl = get_color(normal_border_color);
500     } else if (strcmp(name, "presel_border_color") == 0) {
501         strncpy(presel_border_color, value, sizeof(presel_border_color));
502         presel_border_color_pxl = get_color(presel_border_color);
503     } else if (strcmp(name, "focused_locked_border_color") == 0) {
504         strncpy(focused_locked_border_color, value, sizeof(focused_locked_border_color));
505         focused_locked_border_color_pxl = get_color(focused_locked_border_color);
506     } else if (strcmp(name, "active_locked_border_color") == 0) {
507         strncpy(active_locked_border_color, value, sizeof(active_locked_border_color));
508         active_locked_border_color_pxl = get_color(active_locked_border_color);
509     } else if (strcmp(name, "normal_locked_border_color") == 0) {
510         strncpy(normal_locked_border_color, value, sizeof(normal_locked_border_color));
511         normal_locked_border_color_pxl = get_color(normal_locked_border_color);
512     } else if (strcmp(name, "urgent_border_color") == 0) {
513         strncpy(urgent_border_color, value, sizeof(urgent_border_color));
514         urgent_border_color_pxl = get_color(urgent_border_color);
515     } else if (strcmp(name, "borderless_monocle") == 0) {
516         bool b;
517         if (parse_bool(value, &b))
518             borderless_monocle = b;
519     } else if (strcmp(name, "gapless_monocle") == 0) {
520         bool b;
521         if (parse_bool(value, &b))
522             gapless_monocle = b;
523     } else if (strcmp(name, "focus_follows_pointer") == 0) {
524         bool b;
525         if (parse_bool(value, &b) && b != focus_follows_pointer) {
526             uint32_t values[] = {(focus_follows_pointer ? CLIENT_EVENT_MASK : CLIENT_EVENT_MASK_FFP)};
527             for (monitor_t *m = mon_head; m != NULL; m = m->next)
528                 for (desktop_t *d = m->desk_head; d != NULL; d = d->next)
529                     for (node_t *n = first_extrema(d->root); n != NULL; n = next_leaf(n, d->root))
530                         xcb_change_window_attributes(dpy, n->client->window, XCB_CW_EVENT_MASK, values);
531             if (focus_follows_pointer)
532                 disable_motion_recorder();
533             else
534                 enable_motion_recorder();
535             focus_follows_pointer = b;
536         }
537     } else if (strcmp(name, "adaptative_raise") == 0) {
538         bool b;
539         if (parse_bool(value, &b))
540             adaptative_raise = b;
541     } else if (strcmp(name, "apply_shadow_property") == 0) {
542         bool b;
543         if (parse_bool(value, &b))
544             apply_shadow_property = b;
545     } else if (strcmp(name, "auto_alternate") == 0) {
546         bool b;
547         if (parse_bool(value, &b))
548             auto_alternate = b;
549     } else if (strcmp(name, "focus_by_distance") == 0) {
550         bool b;
551         if (parse_bool(value, &b))
552             focus_by_distance = b;
553     } else if (strcmp(name, "wm_name") == 0) {
554         strncpy(wm_name, value, sizeof(wm_name));
555         ewmh_update_wm_name();
556         return;
557     } else {
558         snprintf(rsp, BUFSIZ, "unknown setting: %s", name);
559         return;
560     }
561
562     arrange(mon, mon->desk);
563 }
564
565 void get_setting(char *name, char* rsp)
566 {
567     if (name == NULL)
568         return;
569
570     if (strcmp(name, "border_width") == 0)
571         snprintf(rsp, BUFSIZ, "%u", border_width);
572     else if (strcmp(name, "window_gap") == 0)
573         snprintf(rsp, BUFSIZ, "%i", window_gap);
574     else if (strcmp(name, "split_ratio") == 0)
575         snprintf(rsp, BUFSIZ, "%lf", split_ratio);
576     else if (strcmp(name, "left_padding") == 0)
577         snprintf(rsp, BUFSIZ, "%i", mon->left_padding);
578     else if (strcmp(name, "right_padding") == 0)
579         snprintf(rsp, BUFSIZ, "%i", mon->right_padding);
580     else if (strcmp(name, "top_padding") == 0)
581         snprintf(rsp, BUFSIZ, "%i", mon->top_padding);
582     else if (strcmp(name, "bottom_padding") == 0)
583         snprintf(rsp, BUFSIZ, "%i", mon->bottom_padding);
584     else if (strcmp(name, "focused_border_color") == 0)
585         snprintf(rsp, BUFSIZ, "%s (%06X)", focused_border_color, focused_border_color_pxl);
586     else if (strcmp(name, "active_border_color") == 0)
587         snprintf(rsp, BUFSIZ, "%s (%06X)", active_border_color, active_border_color_pxl);
588     else if (strcmp(name, "normal_border_color") == 0)
589         snprintf(rsp, BUFSIZ, "%s (%06X)", normal_border_color, normal_border_color_pxl);
590     else if (strcmp(name, "presel_border_color") == 0)
591         snprintf(rsp, BUFSIZ, "%s (%06X)", presel_border_color, presel_border_color_pxl);
592     else if (strcmp(name, "focused_locked_border_color") == 0)
593         snprintf(rsp, BUFSIZ, "%s (%06X)", focused_locked_border_color, focused_locked_border_color_pxl);
594     else if (strcmp(name, "active_locked_border_color") == 0)
595         snprintf(rsp, BUFSIZ, "%s (%06X)", active_locked_border_color, active_locked_border_color_pxl);
596     else if (strcmp(name, "normal_locked_border_color") == 0)
597         snprintf(rsp, BUFSIZ, "%s (%06X)", normal_locked_border_color, normal_locked_border_color_pxl);
598     else if (strcmp(name, "urgent_border_color") == 0)
599         snprintf(rsp, BUFSIZ, "%s (%06X)", urgent_border_color, urgent_border_color_pxl);
600     else if (strcmp(name, "borderless_monocle") == 0)
601         snprintf(rsp, BUFSIZ, "%s", BOOLSTR(borderless_monocle));
602     else if (strcmp(name, "gapless_monocle") == 0)
603         snprintf(rsp, BUFSIZ, "%s", BOOLSTR(gapless_monocle));
604     else if (strcmp(name, "focus_follows_pointer") == 0)
605         snprintf(rsp, BUFSIZ, "%s", BOOLSTR(focus_follows_pointer));
606     else if (strcmp(name, "adaptative_raise") == 0)
607         snprintf(rsp, BUFSIZ, "%s", BOOLSTR(adaptative_raise));
608     else if (strcmp(name, "apply_shadow_property") == 0)
609         snprintf(rsp, BUFSIZ, "%s", BOOLSTR(apply_shadow_property));
610     else if (strcmp(name, "auto_alternate") == 0)
611         snprintf(rsp, BUFSIZ, "%s", BOOLSTR(auto_alternate));
612     else if (strcmp(name, "focus_by_distance") == 0)
613         snprintf(rsp, BUFSIZ, "%s", BOOLSTR(focus_by_distance));
614     else if (strcmp(name, "wm_name") == 0)
615         snprintf(rsp, BUFSIZ, "%s", wm_name);
616     else
617         snprintf(rsp, BUFSIZ, "unknown setting: %s", name);
618 }
619
620 bool parse_bool(char *value, bool *b)
621 {
622     if (strcmp(value, "true") == 0) {
623         *b = true;
624         return true;
625     } else if (strcmp(value, "false") == 0) {
626         *b = false;
627         return true;
628     }
629     return false;
630 }
631
632 bool parse_layout(char *s, layout_t *l)
633 {
634     if (strcmp(s, "monocle") == 0) {
635         *l = LAYOUT_MONOCLE;
636         return true;
637     } else if (strcmp(s, "tiled") == 0) {
638         *l = LAYOUT_TILED;
639         return true;
640     }
641     return false;
642 }
643
644 bool parse_direction(char *s, direction_t *d)
645 {
646     if (strcmp(s, "up") == 0) {
647         *d = DIR_UP;
648         return true;
649     } else if (strcmp(s, "down") == 0) {
650         *d = DIR_DOWN;
651         return true;
652     } else if (strcmp(s, "left") == 0) {
653         *d = DIR_LEFT;
654         return true;
655     } else if (strcmp(s, "right") == 0) {
656         *d = DIR_RIGHT;
657         return true;
658     }
659     return false;
660 }
661
662 bool parse_nearest_argument(char *s, nearest_arg_t *a)
663 {
664     if (strcmp(s, "older") == 0) {
665         *a = NEAREST_OLDER;
666         return true;
667     } else if (strcmp(s, "newer") == 0) {
668         *a = NEAREST_NEWER;
669         return true;
670     }
671     return false;
672 }
673
674 bool parse_swap_argument(char *s, swap_arg_t *a)
675 {
676     if (strcmp(s, "biggest") == 0) {
677         *a = SWAP_BIGGEST;
678         return true;
679     } else if (strcmp(s, "smallest") == 0) {
680         *a = SWAP_SMALLEST;
681         return true;
682     }
683     return false;
684 }
685
686 bool parse_cycle_direction(char *s, cycle_dir_t *d)
687 {
688     if (strcmp(s, "prev") == 0) {
689         *d = CYCLE_PREV;
690         return true;
691     } else if (strcmp(s, "next") == 0) {
692         *d = CYCLE_NEXT;
693         return true;
694     }
695     return false;
696 }
697
698 bool parse_circulate_direction(char *s, circulate_dir_t *d)
699 {
700     if (strcmp(s, "forward") == 0) {
701         *d = CIRCULATE_FORWARD;
702         return true;
703     } else if (strcmp(s, "backward") == 0) {
704         *d = CIRCULATE_BACKWARD;
705         return true;
706     }
707     return false;
708 }
709
710 bool parse_skip_client(char *s, skip_client_t *k)
711 {
712     if (s == NULL) {
713         *k = CLIENT_SKIP_NONE;
714         return true;
715     } else if (strcmp(s, "--skip-floating") == 0) {
716         *k = CLIENT_SKIP_FLOATING;
717         return true;
718     } else if (strcmp(s, "--skip-tiled") == 0) {
719         *k = CLIENT_SKIP_TILED;
720         return true;
721     } else if (strcmp(s, "--skip-class-equal") == 0) {
722         *k = CLIENT_SKIP_CLASS_EQUAL;
723         return true;
724     } else if (strcmp(s, "--skip-class-differ") == 0) {
725         *k = CLIENT_SKIP_CLASS_DIFFER;
726         return true;
727     }
728     return false;
729 }
730
731 bool parse_skip_desktop(char *s, skip_desktop_t *k)
732 {
733     if (s == NULL) {
734         *k = DESKTOP_SKIP_NONE;
735         return true;
736     } else if (strcmp(s, "--skip-free") == 0) {
737         *k = DESKTOP_SKIP_FREE;
738         return true;
739     } else if (strcmp(s, "--skip-occupied") == 0) {
740         *k = DESKTOP_SKIP_OCCUPIED;
741         return true;
742     }
743     return false;
744 }
745
746 bool parse_list_option(char *s, list_option_t *o)
747 {
748     if (s == NULL || strcmp(s, "--verbose") == 0) {
749         *o = LIST_OPTION_VERBOSE;
750         return true;
751     } else if (strcmp(s, "--quiet") == 0) {
752         *o = LIST_OPTION_QUIET;
753         return true;
754     }
755     return false;
756 }
757
758 bool parse_send_option(char *s, send_option_t *o)
759 {
760     if (s == NULL) {
761         *o = SEND_OPTION_DONT_FOLLOW;
762         return true;
763     } else if (strcmp(s, "--follow") == 0) {
764         *o = SEND_OPTION_FOLLOW;
765         return true;
766     }
767     return false;
768 }
769
770 bool parse_rotate(char *s, rotate_t *r)
771 {
772     if (strcmp(s, "clockwise") == 0) {
773         *r = ROTATE_CLOCKWISE;
774         return true;
775     } else if (strcmp(s, "counter_clockwise") == 0) {
776         *r = ROTATE_COUNTER_CLOCKWISE;
777         return true;
778     } else if (strcmp(s, "full_cycle") == 0) {
779         *r = ROTATE_FULL_CYCLE;
780         return true;
781     }
782     return false;
783 }
784
785 bool parse_flip(char *s, flip_t *f)
786 {
787     if (strcmp(s, "horizontal") == 0) {
788         *f = FLIP_HORIZONTAL;
789         return true;
790     } else if (strcmp(s, "vertical") == 0) {
791         *f = FLIP_VERTICAL;
792         return true;
793     }
794     return false;
795 }
796
797 bool parse_fence_move(char *s, fence_move_t *m)
798 {
799     if (strcmp(s, "push") == 0) {
800         *m = MOVE_PUSH;
801         return true;
802     } else if (strcmp(s, "pull") == 0) {
803         *m = MOVE_PULL;
804         return true;
805     }
806     return false;
807 }
808
809 bool parse_pointer_action(char *s, pointer_action_t *a)
810 {
811     if (strcmp(s, "move") == 0) {
812         *a = ACTION_MOVE;
813         return true;
814     } else if (strcmp(s, "resize_corner") == 0) {
815         *a = ACTION_RESIZE_CORNER;
816         return true;
817     } else if (strcmp(s, "resize_side") == 0) {
818         *a = ACTION_RESIZE_SIDE;
819         return true;
820     } else if (strcmp(s, "focus") == 0) {
821         *a = ACTION_FOCUS;
822         return true;
823     }
824     return false;
825 }