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