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