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