]> git.lizzy.rs Git - bspwm.git/blobdiff - messages.c
Automatically check for sockets without screen name.
[bspwm.git] / messages.c
index 9913b5a3cd3cd288d8a1305c6baf4c3e46bb1bd4..d859a3f8d91fba99ebee71fb055f92717c200397 100644 (file)
@@ -1,16 +1,15 @@
-/*
- * Copyright (c) 2012-2014, Bastien Dejean
+/* Copyright (c) 2012, Bastien Dejean
  * All rights reserved.
- * 
+ *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are met:
- * 
+ *
  * 1. Redistributions of source code must retain the above copyright notice, this
  *    list of conditions and the following disclaimer.
  * 2. Redistributions in binary form must reproduce the above copyright notice,
  *    this list of conditions and the following disclaimer in the documentation
  *    and/or other materials provided with the distribution.
- * 
+ *
  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- * 
- * The views and conclusions contained in the software and documentation are those
- * of the authors and should not be interpreted as representing official policies,
- * either expressed or implied, of the FreeBSD Project.
  */
 
 #include <errno.h>
 #include "settings.h"
 #include "tree.h"
 #include "window.h"
+#include "common.h"
+#include "subscribe.h"
 #include "messages.h"
 
-bool handle_message(char *msg, int msg_len, char *rsp)
+int handle_message(char *msg, int msg_len, FILE *rsp)
 {
        int cap = INIT_CAP;
        int num = 0;
        char **args = malloc(cap * sizeof(char *));
        if (args == NULL)
-               return false;
+               return MSG_FAILURE;
 
        for (int i = 0, j = 0; i < msg_len; i++) {
                if (msg[i] == 0) {
@@ -63,7 +60,7 @@ bool handle_message(char *msg, int msg_len, char *rsp)
                        char **new = realloc(args, cap * sizeof(char *));
                        if (new == NULL) {
                                free(args);
-                               return false;
+                               return MSG_FAILURE;
                        } else {
                                args = new;
                        }
@@ -72,16 +69,16 @@ bool handle_message(char *msg, int msg_len, char *rsp)
 
        if (num < 1) {
                free(args);
-               return false;
+               return MSG_SYNTAX;
        }
 
        char **args_orig = args;
-       bool ret = process_message(args, num, rsp);
+       int ret = process_message(args, num, rsp);
        free(args_orig);
        return ret;
 }
 
-bool process_message(char **args, int num, char *rsp)
+int process_message(char **args, int num, FILE *rsp)
 {
        if (streq("window", *args)) {
                return cmd_window(++args, --num);
@@ -105,13 +102,13 @@ bool process_message(char **args, int num, char *rsp)
                return cmd_quit(++args, --num);
        }
 
-       return false;
+       return MSG_UNKNOWN;
 }
 
-bool cmd_window(char **args, int num)
+int cmd_window(char **args, int num)
 {
        if (num < 1)
-               return false;
+               return MSG_SYNTAX;
 
        coordinates_t ref = {mon, mon->desk, mon->desk->focus};
        coordinates_t trg = ref;
@@ -120,11 +117,11 @@ bool cmd_window(char **args, int num)
                if (node_from_desc(*args, &ref, &trg))
                        num--, args++;
                else
-                       return false;
+                       return MSG_FAILURE;
        }
 
        if (trg.node == NULL)
-               return false;
+               return MSG_FAILURE;
 
        bool dirty = false;
 
@@ -134,7 +131,7 @@ bool cmd_window(char **args, int num)
                        if (num > 1 && *(args + 1)[0] != OPT_CHR) {
                                num--, args++;
                                if (!node_from_desc(*args, &trg, &dst))
-                                       return false;
+                                       return MSG_FAILURE;
                        }
                        focus_node(dst.monitor, dst.desktop, dst.node);
                } else if (streq("-d", *args) || streq("--to-desktop", *args)) {
@@ -146,12 +143,12 @@ bool cmd_window(char **args, int num)
                                        trg.desktop = dst.desktop;
                                }
                        } else {
-                               return false;
+                               return MSG_FAILURE;
                        }
                } else if (streq("-m", *args) || streq("--to-monitor", *args)) {
                        num--, args++;
                        if (num < 1)
-                               return false;
+                               return MSG_SYNTAX;
                        coordinates_t dst;
                        if (monitor_from_desc(*args, &trg, &dst)) {
                                if (transfer_node(trg.monitor, trg.desktop, trg.node, dst.monitor, dst.monitor->desk, dst.monitor->desk->focus)) {
@@ -159,12 +156,12 @@ bool cmd_window(char **args, int num)
                                        trg.desktop = dst.monitor->desk;
                                }
                        } else {
-                               return false;
+                               return MSG_FAILURE;
                        }
                } else if (streq("-w", *args) || streq("--to-window", *args)) {
                        num--, args++;
                        if (num < 1)
-                               return false;
+                               return MSG_SYNTAX;
                        coordinates_t dst;
                        if (node_from_desc(*args, &trg, &dst)) {
                                if (transfer_node(trg.monitor, trg.desktop, trg.node, dst.monitor, dst.desktop, dst.node)) {
@@ -172,12 +169,12 @@ bool cmd_window(char **args, int num)
                                        trg.desktop = dst.desktop;
                                }
                        } else {
-                               return false;
+                               return MSG_FAILURE;
                        }
                } else if (streq("-s", *args) || streq("--swap", *args)) {
                        num--, args++;
                        if (num < 1)
-                               return false;
+                               return MSG_SYNTAX;
                        coordinates_t dst;
                        if (node_from_desc(*args, &trg, &dst)) {
                                if (swap_nodes(trg.monitor, trg.desktop, trg.node, dst.monitor, dst.desktop, dst.node)) {
@@ -188,12 +185,12 @@ bool cmd_window(char **args, int num)
                                        dirty = true;
                                }
                        } else {
-                               return false;
+                               return MSG_FAILURE;
                        }
                } else if (streq("-t", *args) || streq("--toggle", *args)) {
                        num--, args++;
                        if (num < 1)
-                               return false;
+                               return MSG_SYNTAX;
                        char *key = strtok(*args, EQL_TOK);
                        char *val = strtok(NULL, EQL_TOK);
                        alter_state_t a;
@@ -204,7 +201,7 @@ bool cmd_window(char **args, int num)
                                if (parse_bool(val, &b))
                                        a = ALTER_SET;
                                else
-                                       return false;
+                                       return MSG_FAILURE;
                        }
                        if (streq("fullscreen", key)) {
                                set_fullscreen(trg.node, (a == ALTER_SET ? b : !trg.node->client->fullscreen));
@@ -222,13 +219,15 @@ bool cmd_window(char **args, int num)
                        } else if (streq("private", key)) {
                                set_private(trg.monitor, trg.desktop, trg.node, (a == ALTER_SET ? b : !trg.node->client->private));
                        } else {
-                               return false;
+                               return MSG_FAILURE;
                        }
                } else if (streq("-p", *args) || streq("--presel", *args)) {
                        num--, args++;
-                       if (num < 1 || !is_tiled(trg.node->client)
-                                       || trg.desktop->layout != LAYOUT_TILED)
-                               return false;
+                       if (num < 1)
+                               return MSG_SYNTAX;
+                       if (!is_tiled(trg.node->client) ||
+                           trg.desktop->layout != LAYOUT_TILED)
+                               return MSG_FAILURE;
                        if (streq("cancel", *args)) {
                                reset_mode(&trg);
                        } else {
@@ -238,7 +237,7 @@ bool cmd_window(char **args, int num)
                                        if (num > 1 && *(args + 1)[0] != OPT_CHR) {
                                                num--, args++;
                                                if (sscanf(*args, "%lf", &rat) != 1 || rat <= 0 || rat >= 1)
-                                                       return false;
+                                                       return MSG_FAILURE;
                                        }
                                        if (auto_cancel && trg.node->split_mode == MODE_MANUAL &&
                                            dir == trg.node->split_dir &&
@@ -251,19 +250,21 @@ bool cmd_window(char **args, int num)
                                        }
                                        window_draw_border(trg.node, trg.desktop->focus == trg.node, mon == trg.monitor);
                                } else {
-                                       return false;
+                                       return MSG_FAILURE;
                                }
                        }
                } else if (streq("-e", *args) || streq("--edge", *args)) {
                        num--, args++;
                        if (num < 2)
-                               return false;
+                               return MSG_SYNTAX;
+                       if (!is_tiled(trg.node->client))
+                               return MSG_FAILURE;
                        direction_t dir;
                        if (!parse_direction(*args, &dir))
-                               return false;
+                               return MSG_FAILURE;
                        node_t *n = find_fence(trg.node, dir);
                        if (n == NULL)
-                               return false;
+                               return MSG_FAILURE;
                        num--, args++;
                        if ((*args)[0] == '+' || (*args)[0] == '-') {
                                int pix;
@@ -273,58 +274,58 @@ bool cmd_window(char **args, int num)
                                        if (rat > 0 && rat < 1)
                                                n->split_ratio = rat;
                                        else
-                                               return false;
+                                               return MSG_FAILURE;
                                } else {
-                                       return false;
+                                       return MSG_FAILURE;
                                }
                        } else {
                                double rat;
                                if (sscanf(*args, "%lf", &rat) == 1 && rat > 0 && rat < 1)
                                        n->split_ratio = rat;
                                else
-                                       return false;
+                                       return MSG_FAILURE;
                        }
                        dirty = true;
                } else if (streq("-r", *args) || streq("--ratio", *args)) {
                        num--, args++;
                        if (num < 1)
-                               return false;
+                               return MSG_SYNTAX;
                        double rat;
                        if (sscanf(*args, "%lf", &rat) == 1 && rat > 0 && rat < 1) {
                                trg.node->split_ratio = rat;
                                window_draw_border(trg.node, trg.desktop->focus == trg.node, mon == trg.monitor);
                        } else {
-                               return false;
+                               return MSG_FAILURE;
                        }
                } else if (streq("-R", *args) || streq("--rotate", *args)) {
                        num--, args++;
                        if (num < 2)
-                               return false;
+                               return MSG_SYNTAX;
                        direction_t dir;
                        if (!parse_direction(*args, &dir))
-                               return false;
+                               return MSG_FAILURE;
                        node_t *n = find_fence(trg.node, dir);
                        if (n == NULL)
-                               return false;
+                               return MSG_FAILURE;
                        num--, args++;
                        int deg;
                        if (parse_degree(*args, &deg)) {
                                rotate_tree(n, deg);
                                dirty = true;
                        } else {
-                               return false;
+                               return MSG_FAILURE;
                        }
                } else if (streq("-c", *args) || streq("--close", *args)) {
                        if (num > 1)
-                               return false;
+                               return MSG_SYNTAX;
                        window_close(trg.node);
                } else if (streq("-k", *args) || streq("--kill", *args)) {
                        if (num > 1)
-                               return false;
+                               return MSG_SYNTAX;
                        window_kill(trg.monitor, trg.desktop, trg.node);
                        dirty = true;
                } else {
-                       return false;
+                       return MSG_SYNTAX;
                }
 
                num--, args++;
@@ -333,13 +334,13 @@ bool cmd_window(char **args, int num)
        if (dirty)
                arrange(trg.monitor, trg.desktop);
 
-       return true;
+       return MSG_SUCCESS;
 }
 
-bool cmd_desktop(char **args, int num)
+int cmd_desktop(char **args, int num)
 {
        if (num < 1)
-               return false;
+               return MSG_SYNTAX;
 
        coordinates_t ref = {mon, mon->desk, NULL};
        coordinates_t trg = ref;
@@ -348,7 +349,7 @@ bool cmd_desktop(char **args, int num)
                if (desktop_from_desc(*args, &ref, &trg))
                        num--, args++;
                else
-                       return false;
+                       return MSG_FAILURE;
        }
 
        bool dirty = false;
@@ -359,7 +360,7 @@ bool cmd_desktop(char **args, int num)
                        if (num > 1 && *(args + 1)[0] != OPT_CHR) {
                                num--, args++;
                                if (!desktop_from_desc(*args, &trg, &dst))
-                                       return false;
+                                       return MSG_FAILURE;
                        }
                        if (auto_alternate && dst.desktop == mon->desk) {
                                desktop_select_t sel = {DESKTOP_STATUS_ALL, false, false};
@@ -368,29 +369,31 @@ bool cmd_desktop(char **args, int num)
                        focus_node(dst.monitor, dst.desktop, dst.desktop->focus);
                } else if (streq("-m", *args) || streq("--to-monitor", *args)) {
                        num--, args++;
-                       if (num < 1 || trg.monitor->desk_head == trg.monitor->desk_tail)
-                               return false;
+                       if (num < 1)
+                               return MSG_SYNTAX;
+                       if (trg.monitor->desk_head == trg.monitor->desk_tail)
+                               return MSG_FAILURE;
                        coordinates_t dst;
                        if (monitor_from_desc(*args, &trg, &dst)) {
                                transfer_desktop(trg.monitor, dst.monitor, trg.desktop);
                                trg.monitor = dst.monitor;
                                update_current();
                        } else {
-                               return false;
+                               return MSG_FAILURE;
                        }
                } else if (streq("-s", *args) || streq("--swap", *args)) {
                        num--, args++;
                        if (num < 1)
-                               return false;
+                               return MSG_SYNTAX;
                        coordinates_t dst;
                        if (desktop_from_desc(*args, &trg, &dst))
                                swap_desktops(trg.monitor, trg.desktop, dst.monitor, dst.desktop);
                        else
-                               return false;
+                               return MSG_FAILURE;
                } else if (streq("-l", *args) || streq("--layout", *args)) {
                        num--, args++;
                        if (num < 1)
-                               return false;
+                               return MSG_SYNTAX;
                        layout_t lyt;
                        cycle_dir_t cyc;
                        if (parse_cycle_direction(*args, &cyc))
@@ -398,11 +401,11 @@ bool cmd_desktop(char **args, int num)
                        else if (parse_layout(*args, &lyt))
                                change_layout(trg.monitor, trg.desktop, lyt);
                        else
-                               return false;
+                               return MSG_FAILURE;
                } else if (streq("-n", *args) || streq("--rename", *args)) {
                        num--, args++;
                        if (num < 1)
-                               return false;
+                               return MSG_SYNTAX;
                        snprintf(trg.desktop->name, sizeof(trg.desktop->name), "%s", *args);
                        ewmh_update_desktop_names();
                        put_status();
@@ -412,33 +415,33 @@ bool cmd_desktop(char **args, int num)
                                remove_desktop(trg.monitor, trg.desktop);
                                show_desktop(trg.monitor->desk);
                                update_current();
-                               return true;
+                               return MSG_SUCCESS;
                        } else {
-                               return false;
+                               return MSG_FAILURE;
                        }
                } else if (streq("-c", *args) || streq("--cancel-presel", *args)) {
                        reset_mode(&trg);
                } else if (streq("-F", *args) || streq("--flip", *args)) {
                        num--, args++;
                        if (num < 1)
-                               return false;
+                               return MSG_SYNTAX;
                        flip_t flp;
                        if (parse_flip(*args, &flp)) {
                                flip_tree(trg.desktop->root, flp);
                                dirty = true;
                        } else {
-                               return false;
+                               return MSG_FAILURE;
                        }
                } else if (streq("-R", *args) || streq("--rotate", *args)) {
                        num--, args++;
                        if (num < 1)
-                               return false;
+                               return MSG_SYNTAX;
                        int deg;
                        if (parse_degree(*args, &deg)) {
                                rotate_tree(trg.desktop->root, deg);
                                dirty = true;
                        } else {
-                               return false;
+                               return MSG_FAILURE;
                        }
                } else if (streq("-E", *args) || streq("--equalize", *args)) {
                        equalize_tree(trg.desktop->root);
@@ -449,18 +452,18 @@ bool cmd_desktop(char **args, int num)
                } else if (streq("-C", *args) || streq("--circulate", *args)) {
                        num--, args++;
                        if (num < 1)
-                               return false;
+                               return MSG_SYNTAX;
                        circulate_dir_t cir;
                        if (parse_circulate_direction(*args, &cir)) {
                                circulate_leaves(trg.monitor, trg.desktop, cir);
                                dirty = true;
                        } else {
-                               return false;
+                               return MSG_FAILURE;
                        }
                } else if (streq("-t", *args) || streq("--toggle", *args)) {
                        num--, args++;
                        if (num < 1)
-                               return false;
+                               return MSG_SYNTAX;
                        char *key = strtok(*args, EQL_TOK);
                        char *val = strtok(NULL, EQL_TOK);
                        alter_state_t a;
@@ -471,14 +474,14 @@ bool cmd_desktop(char **args, int num)
                                if (parse_bool(val, &b))
                                        a = ALTER_SET;
                                else
-                                       return false;
+                                       return MSG_FAILURE;
                        }
                        if (streq("floating", key))
                                trg.desktop->floating = (a == ALTER_SET ? b : !trg.desktop->floating);
                        else
-                               return false;
+                               return MSG_FAILURE;
                } else {
-                       return false;
+                       return MSG_SYNTAX;
                }
                num--, args++;
        }
@@ -486,13 +489,13 @@ bool cmd_desktop(char **args, int num)
        if (dirty)
                arrange(trg.monitor, trg.desktop);
 
-       return true;
+       return MSG_SUCCESS;
 }
 
-bool cmd_monitor(char **args, int num)
+int cmd_monitor(char **args, int num)
 {
        if (num < 1)
-               return false;
+               return MSG_SYNTAX;
 
        coordinates_t ref = {mon, NULL, NULL};
        coordinates_t trg = ref;
@@ -501,7 +504,7 @@ bool cmd_monitor(char **args, int num)
                if (monitor_from_desc(*args, &ref, &trg))
                        num--, args++;
                else
-                       return false;
+                       return MSG_FAILURE;
        }
 
        while (num > 0) {
@@ -510,7 +513,7 @@ bool cmd_monitor(char **args, int num)
                        if (num > 1 && *(args + 1)[0] != OPT_CHR) {
                                num--, args++;
                                if (!monitor_from_desc(*args, &trg, &dst))
-                                       return false;
+                                       return MSG_FAILURE;
                        }
                        if (auto_alternate && dst.monitor == mon) {
                                desktop_select_t sel = {DESKTOP_STATUS_ALL, false, false};
@@ -520,10 +523,12 @@ bool cmd_monitor(char **args, int num)
                } else if (streq("-d", *args) || streq("--reset-desktops", *args)) {
                        num--, args++;
                        if (num < 1)
-                               return false;
+                               return MSG_SYNTAX;
                        desktop_t *d = trg.monitor->desk_head;
                        while (num > 0 && d != NULL) {
                                snprintf(d->name, sizeof(d->name), "%s", *args);
+                               initialize_desktop(d);
+                               arrange(trg.monitor, d);
                                d = d->next;
                                num--, args++;
                        }
@@ -543,7 +548,7 @@ bool cmd_monitor(char **args, int num)
                } else if (streq("-a", *args) || streq("--add-desktops", *args)) {
                        num--, args++;
                        if (num < 1)
-                               return false;
+                               return MSG_SYNTAX;
                        while (num > 0) {
                                add_desktop(trg.monitor, make_desktop(*args));
                                num--, args++;
@@ -551,7 +556,7 @@ bool cmd_monitor(char **args, int num)
                } else if (streq("-r", *args) || streq("--remove-desktops", *args)) {
                        num--, args++;
                        if (num < 1)
-                               return false;
+                               return MSG_SYNTAX;
                        while (num > 0) {
                                coordinates_t dst;
                                if (locate_desktop(*args, &dst) && dst.monitor->desk_head != dst.monitor->desk_tail && dst.desktop->root == NULL) {
@@ -563,7 +568,7 @@ bool cmd_monitor(char **args, int num)
                } else if (streq("-o", *args) || streq("--order-desktops", *args)) {
                        num--, args++;
                        if (num < 1)
-                               return false;
+                               return MSG_SYNTAX;
                        desktop_t *d = trg.monitor->desk_head;
                        while (d != NULL && num > 0) {
                                desktop_t *next = d->next;
@@ -579,28 +584,28 @@ bool cmd_monitor(char **args, int num)
                } else if (streq("-n", *args) || streq("--rename", *args)) {
                        num--, args++;
                        if (num < 1)
-                               return false;
+                               return MSG_SYNTAX;
                        snprintf(trg.monitor->name, sizeof(trg.monitor->name), "%s", *args);
                        put_status();
                } else if (streq("-s", *args) || streq("--swap", *args)) {
                        num--, args++;
                        if (num < 1)
-                               return false;
+                               return MSG_SYNTAX;
                        coordinates_t dst;
                        if (monitor_from_desc(*args, &trg, &dst))
                                swap_monitors(trg.monitor, dst.monitor);
                        else
-                               return false;
+                               return MSG_FAILURE;
                } else {
-                       return false;
+                       return MSG_SYNTAX;
                }
                num--, args++;
        }
 
-       return true;
+       return MSG_SUCCESS;
 }
 
-bool cmd_query(char **args, int num, char *rsp)
+int cmd_query(char **args, int num, FILE *rsp)
 {
        coordinates_t ref = {mon, mon->desk, mon->desk->focus};
        coordinates_t trg = {NULL, NULL, NULL};
@@ -625,7 +630,7 @@ bool cmd_query(char **args, int num, char *rsp)
                        if (num > 1 && *(args + 1)[0] != OPT_CHR) {
                                num--, args++;
                                if (!monitor_from_desc(*args, &ref, &trg))
-                                       return false;
+                                       return MSG_FAILURE;
                        }
                        t++;
                } else if (streq("-d", *args) || streq("--desktop", *args)) {
@@ -634,7 +639,7 @@ bool cmd_query(char **args, int num, char *rsp)
                        if (num > 1 && *(args + 1)[0] != OPT_CHR) {
                                num--, args++;
                                if (!desktop_from_desc(*args, &ref, &trg))
-                                       return false;
+                                       return MSG_FAILURE;
                        }
                        t++;
                } else if (streq("-w", *args) || streq("--window", *args)) {
@@ -642,17 +647,17 @@ bool cmd_query(char **args, int num, char *rsp)
                        if (num > 1 && *(args + 1)[0] != OPT_CHR) {
                                num--, args++;
                                if (!node_from_desc(*args, &ref, &trg))
-                                       return false;
+                                       return MSG_FAILURE;
                        }
                        t++;
                } else {
-                       return false;
+                       return MSG_SYNTAX;
                }
                num--, args++;
        }
 
        if (d != 1 || t > 1)
-               return false;
+               return MSG_SYNTAX;
 
        if (dom == DOMAIN_HISTORY)
                query_history(trg, rsp);
@@ -663,18 +668,18 @@ bool cmd_query(char **args, int num, char *rsp)
        else
                query_monitors(trg, dom, rsp);
 
-       return true;
+       return MSG_SUCCESS;
 }
 
-bool cmd_rule(char **args, int num, char *rsp)
+int cmd_rule(char **args, int num, FILE *rsp)
 {
        if (num < 1)
-               return false;
+               return MSG_SYNTAX;
        while (num > 0) {
                if (streq("-a", *args) || streq("--add", *args)) {
                        num--, args++;
                        if (num < 2)
-                               return false;
+                               return MSG_SYNTAX;
                        rule_t *rule = make_rule();
                        snprintf(rule->cause, sizeof(rule->cause), "%s", *args);
                        num--, args++;
@@ -695,7 +700,7 @@ bool cmd_rule(char **args, int num, char *rsp)
                } else if (streq("-r", *args) || streq("--remove", *args)) {
                        num--, args++;
                        if (num < 1)
-                               return false;
+                               return MSG_SYNTAX;
                        int idx;
                        while (num > 0) {
                                if (parse_index(*args, &idx))
@@ -712,129 +717,136 @@ bool cmd_rule(char **args, int num, char *rsp)
                        num--, args++;
                        list_rules(num > 0 ? *args : NULL, rsp);
                } else {
-                       return false;
+                       return MSG_SYNTAX;
                }
                num--, args++;
        }
 
-       return true;
+       return MSG_SUCCESS;
 }
 
-bool cmd_pointer(char **args, int num)
+int cmd_pointer(char **args, int num)
 {
        if (num < 1)
-               return false;
+               return MSG_SYNTAX;
        while (num > 0) {
                if (streq("-t", *args) || streq("--track", *args)) {
                        num--, args++;
                        if (num < 2)
-                               return false;
+                               return MSG_SYNTAX;
                        int x, y;
                        if (sscanf(*args, "%i", &x) == 1 && sscanf(*(args + 1), "%i", &y) == 1)
                                track_pointer(x, y);
                        else
-                               return false;
+                               return MSG_FAILURE;
+                       num--, args++;
                } else if (streq("-g", *args) || streq("--grab", *args)) {
                        num--, args++;
                        if (num < 1)
-                               return false;
+                               return MSG_SYNTAX;
                        pointer_action_t pac;
                        if (parse_pointer_action(*args, &pac))
                                grab_pointer(pac);
                        else
-                               return false;
+                               return MSG_FAILURE;
                } else if (streq("-u", *args) || streq("--ungrab", *args)) {
                        ungrab_pointer();
                } else {
-                       return false;
+                       return MSG_SYNTAX;
                }
                num--, args++;
        }
 
-       return true;
+       return MSG_SUCCESS;
 }
 
-bool cmd_restore(char **args, int num)
+int cmd_restore(char **args, int num)
 {
        if (num < 1)
-               return false;
+               return MSG_SYNTAX;
        while (num > 0) {
                if (streq("-T", *args) || streq("--tree", *args)) {
                        num--, args++;
                        if (num < 1)
-                               return false;
+                               return MSG_SYNTAX;
                        restore_tree(*args);
                } else if (streq("-H", *args) || streq("--history", *args)) {
                        num--, args++;
                        if (num < 1)
-                               return false;
+                               return MSG_SYNTAX;
                        restore_history(*args);
                } else if (streq("-S", *args) || streq("--stack", *args)) {
                        num--, args++;
                        if (num < 1)
-                               return false;
+                               return MSG_SYNTAX;
                        restore_stack(*args);
                } else {
-                       return false;
+                       return MSG_SYNTAX;
                }
                num--, args++;
        }
 
-       return true;
+       return MSG_SUCCESS;
 }
 
-bool cmd_control(char **args, int num, char *rsp)
+int cmd_control(char **args, int num, FILE *rsp)
 {
        if (num < 1)
-               return false;
+               return MSG_SYNTAX;
        while (num > 0) {
                if (streq("--adopt-orphans", *args)) {
                        adopt_orphans();
-               } else if (streq("--put-status", *args)) {
-                       put_status();
                } else if (streq("--toggle-visibility", *args)) {
                        toggle_visibility();
                } else if (streq("--subscribe", *args)) {
-                       snprintf(rsp, BUFSIZ, "%c", MESSAGE_SUBSCRIBE);
+                       return MSG_SUBSCRIBE;
+               } else if (streq("--get-status", *args)) {
+                       print_status(rsp);
                } else if (streq("--record-history", *args)) {
                        num--, args++;
                        if (num < 1)
-                               return false;
+                               return MSG_SYNTAX;
                        bool b;
                        if (parse_bool(*args, &b))
                                record_history = b;
                        else
-                               return false;
+                               return MSG_SYNTAX;
                } else {
-                       return false;
+                       return MSG_SYNTAX;
                }
                num--, args++;
        }
 
-       return true;
+       return MSG_SUCCESS;
 }
 
-bool cmd_config(char **args, int num, char *rsp)
+int cmd_config(char **args, int num, FILE *rsp)
 {
        if (num < 1)
-               return false;
+               return MSG_SYNTAX;
        coordinates_t ref = {mon, mon->desk, mon->desk->focus};
        coordinates_t trg = {NULL, NULL, NULL};
        if ((*args)[0] == OPT_CHR) {
-               if (streq("-d", *args) || streq("--desktop", *args)) {
+               if (streq("-m", *args) || streq("--monitor", *args)) {
                        num--, args++;
                        if (num < 1)
-                               return false;
+                               return MSG_SYNTAX;
+                       if (!monitor_from_desc(*args, &ref, &trg))
+                               return MSG_FAILURE;
+               } else if (streq("-d", *args) || streq("--desktop", *args)) {
+                       num--, args++;
+                       if (num < 1)
+                               return MSG_SYNTAX;
                        if (!desktop_from_desc(*args, &ref, &trg))
-                               return false;
-               } else if (streq("-m", *args) || streq("--monitor", *args)) {
+                               return MSG_FAILURE;
+               } else if (streq("-w", *args) || streq("--window", *args)) {
                        num--, args++;
                        if (num < 1)
-                               return false;
-                       if (!monitor_from_desc(*args, &ref, &trg))
-                               return false;
+                               return MSG_SYNTAX;
+                       if (!node_from_desc(*args, &ref, &trg))
+                               return MSG_FAILURE;
                } else {
-                       return false;
+                       return MSG_SYNTAX;
                }
                num--, args++;
        }
@@ -843,40 +855,49 @@ bool cmd_config(char **args, int num, char *rsp)
        else if (num == 1)
                return get_setting(trg, *args, rsp);
        else
-               return false;
+               return MSG_SYNTAX;
 }
 
-bool cmd_quit(char **args, int num)
+int cmd_quit(char **args, int num)
 {
        if (num > 0 && sscanf(*args, "%i", &exit_status) != 1)
-               return false;
+               return MSG_FAILURE;
        running = false;
-       return true;
+       return MSG_SUCCESS;
 }
 
-bool set_setting(coordinates_t loc, char *name, char *value)
+int set_setting(coordinates_t loc, char *name, char *value)
 {
-#define DESKSET(k, v) \
-               if (loc.desktop != NULL) \
+#define DESKWINDEFSET(k, v) \
+               if (loc.node != NULL) \
+                       loc.node->client->k = v; \
+               else if (loc.desktop != NULL) \
                        loc.desktop->k = v; \
                else if (loc.monitor != NULL) \
                        for (desktop_t *d = loc.monitor->desk_head; d != NULL; d = d->next) \
                                d->k = v; \
                else \
-                       for (monitor_t *m = mon_head; m != NULL; m = m->next) \
-                               for (desktop_t *d = m->desk_head; d != NULL; d = d->next) \
-                                       d->k = v;
+                       k = v;
        if (streq("border_width", name)) {
                unsigned int bw;
                if (sscanf(value, "%u", &bw) != 1)
-                       return false;
-               DESKSET(border_width, bw)
+                       return MSG_FAILURE;
+               DESKWINDEFSET(border_width, bw)
+#undef DESKWINDEFSET
+#define DESKDEFSET(k, v) \
+               if (loc.desktop != NULL) \
+                       loc.desktop->k = v; \
+               else if (loc.monitor != NULL) \
+                       for (desktop_t *d = loc.monitor->desk_head; d != NULL; d = d->next) \
+                               d->k = v; \
+               else \
+                       k = v;
        } else if (streq("window_gap", name)) {
                int wg;
                if (sscanf(value, "%i", &wg) != 1)
-                       return false;
-               DESKSET(window_gap, wg)
-#undef DESKSET
+                       return MSG_FAILURE;
+               DESKDEFSET(window_gap, wg)
+#undef DESKDEFSET
 #define MONDESKSET(k, v) \
                if (loc.desktop != NULL) \
                        loc.desktop->k = v; \
@@ -888,22 +909,22 @@ bool set_setting(coordinates_t loc, char *name, char *value)
        } else if (streq("top_padding", name)) {
                int tp;
                if (sscanf(value, "%i", &tp) != 1)
-                       return false;
+                       return MSG_FAILURE;
                MONDESKSET(top_padding, tp)
        } else if (streq("right_padding", name)) {
                int rp;
                if (sscanf(value, "%i", &rp) != 1)
-                       return false;
+                       return MSG_FAILURE;
                MONDESKSET(right_padding, rp)
        } else if (streq("bottom_padding", name)) {
                int bp;
                if (sscanf(value, "%i", &bp) != 1)
-                       return false;
+                       return MSG_FAILURE;
                MONDESKSET(bottom_padding, bp)
        } else if (streq("left_padding", name)) {
                int lp;
                if (sscanf(value, "%i", &lp) != 1)
-                       return false;
+                       return MSG_FAILURE;
                MONDESKSET(left_padding, lp)
 #undef MONDESKSET
 #define SETSTR(s) \
@@ -917,8 +938,8 @@ bool set_setting(coordinates_t loc, char *name, char *value)
                if (sscanf(value, "%lf", &r) == 1 && r > 0 && r < 1)
                        split_ratio = r;
                else
-                       return false;
-               return true;
+                       return MSG_FAILURE;
+               return MSG_SUCCESS;
 #define SETCOLOR(s) \
        } else if (streq(#s, name)) { \
                snprintf(s, sizeof(s), "%s", value);
@@ -956,61 +977,74 @@ bool set_setting(coordinates_t loc, char *name, char *value)
                                        window_hide(m->root);
                                disable_motion_recorder();
                        }
-                       return true;
+                       return MSG_SUCCESS;
                } else {
-                       return false;
+                       return MSG_FAILURE;
                }
 #define SETBOOL(s) \
        } else if (streq(#s, name)) { \
                if (!parse_bool(value, &s)) \
-                       return false;
+                       return MSG_FAILURE;
                SETBOOL(borderless_monocle)
                SETBOOL(gapless_monocle)
+               SETBOOL(pointer_follows_focus)
                SETBOOL(pointer_follows_monitor)
                SETBOOL(apply_floating_atom)
                SETBOOL(auto_alternate)
                SETBOOL(auto_cancel)
                SETBOOL(history_aware_focus)
+               SETBOOL(focus_by_distance)
                SETBOOL(ignore_ewmh_focus)
-               SETBOOL(remove_disabled_monitor)
 #undef SETBOOL
+#define SETMONBOOL(s) \
+       } else if (streq(#s, name)) { \
+               if (!parse_bool(value, &s)) \
+                       return MSG_FAILURE; \
+               if (s) \
+                       update_monitors();
+               SETMONBOOL(remove_disabled_monitors)
+               SETMONBOOL(remove_unplugged_monitors)
+               SETMONBOOL(merge_overlapping_monitors)
+#undef SETMONBOOL
        } else {
-               return false;
+               return MSG_FAILURE;
        }
 
        for (monitor_t *m = mon_head; m != NULL; m = m->next)
                for (desktop_t *d = m->desk_head; d != NULL; d = d->next)
                        arrange(m, d);
 
-       return true;
+       return MSG_SUCCESS;
 }
 
-bool get_setting(coordinates_t loc, char *name, char* rsp)
+int get_setting(coordinates_t loc, char *name, FILE* rsp)
 {
        if (streq("split_ratio", name))
-               snprintf(rsp, BUFSIZ, "%lf", split_ratio);
+               fprintf(rsp, "%lf", split_ratio);
        else if (streq("window_gap", name))
-               if (loc.desktop == NULL)
-                       return false;
+               if (loc.desktop != NULL)
+                       fprintf(rsp, "%i", loc.desktop->window_gap);
                else
-                       snprintf(rsp, BUFSIZ, "%i", loc.desktop->window_gap);
+                       fprintf(rsp, "%i", window_gap);
        else if (streq("border_width", name))
-               if (loc.desktop == NULL)
-                       return false;
+               if (loc.node != NULL)
+                       fprintf(rsp, "%u", loc.node->client->border_width);
+               else if (loc.desktop != NULL)
+                       fprintf(rsp, "%u", loc.desktop->border_width);
                else
-                       snprintf(rsp, BUFSIZ, "%u", loc.desktop->border_width);
+                       fprintf(rsp, "%u", border_width);
        else if (streq("external_rules_command", name))
-               snprintf(rsp, BUFSIZ, "%s", external_rules_command);
+               fprintf(rsp, "%s", external_rules_command);
        else if (streq("status_prefix", name))
-               snprintf(rsp, BUFSIZ, "%s", status_prefix);
+               fprintf(rsp, "%s", status_prefix);
 #define MONDESKGET(k) \
        else if (streq(#k, name)) \
                if (loc.desktop != NULL) \
-                       snprintf(rsp, BUFSIZ, "%i", loc.desktop->k); \
+                       fprintf(rsp, "%i", loc.desktop->k); \
                else if (loc.monitor != NULL) \
-                       snprintf(rsp, BUFSIZ, "%i", loc.monitor->k); \
+                       fprintf(rsp, "%i", loc.monitor->k); \
                else \
-                       return false;
+                       return MSG_FAILURE;
        MONDESKGET(top_padding)
        MONDESKGET(right_padding)
        MONDESKGET(bottom_padding)
@@ -1018,7 +1052,7 @@ bool get_setting(coordinates_t loc, char *name, char* rsp)
 #undef DESKGET
 #define GETCOLOR(s) \
        else if (streq(#s, name)) \
-               snprintf(rsp, BUFSIZ, "%s", s);
+               fprintf(rsp, "%s", s);
        GETCOLOR(focused_border_color)
        GETCOLOR(active_border_color)
        GETCOLOR(normal_border_color)
@@ -1033,21 +1067,25 @@ bool get_setting(coordinates_t loc, char *name, char* rsp)
 #undef GETCOLOR
 #define GETBOOL(s) \
        else if (streq(#s, name)) \
-               snprintf(rsp, BUFSIZ, "%s", BOOLSTR(s));
+               fprintf(rsp, "%s", BOOLSTR(s));
        GETBOOL(borderless_monocle)
        GETBOOL(gapless_monocle)
        GETBOOL(focus_follows_pointer)
+       GETBOOL(pointer_follows_focus)
        GETBOOL(pointer_follows_monitor)
        GETBOOL(apply_floating_atom)
        GETBOOL(auto_alternate)
        GETBOOL(auto_cancel)
        GETBOOL(history_aware_focus)
+       GETBOOL(focus_by_distance)
        GETBOOL(ignore_ewmh_focus)
-       GETBOOL(remove_disabled_monitor)
+       GETBOOL(remove_disabled_monitors)
+       GETBOOL(remove_unplugged_monitors)
+       GETBOOL(merge_overlapping_monitors)
 #undef GETBOOL
        else
-               return false;
-       return true;
+               return MSG_FAILURE;
+       return MSG_SUCCESS;
 }
 
 bool parse_bool(char *value, bool *b)