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