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