]> git.lizzy.rs Git - bspwm.git/blobdiff - messages.c
New setting: leaf_monocle
[bspwm.git] / messages.c
index af98cc0bdcd29ef840f5fc4118cae2d66f907a66..66bcd872e43f892057327616b7dd1a038f690d57 100644 (file)
@@ -1,4 +1,4 @@
-/* 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
  * 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>
@@ -261,6 +257,8 @@ int cmd_window(char **args, int num)
                        num--, args++;
                        if (num < 2)
                                return MSG_SYNTAX;
+                       if (!is_tiled(trg.node->client))
+                               return MSG_FAILURE;
                        direction_t dir;
                        if (!parse_direction(*args, &dir))
                                return MSG_FAILURE;
@@ -392,6 +390,33 @@ int cmd_desktop(char **args, int num)
                                swap_desktops(trg.monitor, trg.desktop, dst.monitor, dst.desktop);
                        else
                                return MSG_FAILURE;
+               } else if (streq("-b", *args) || streq("--bubble", *args)) {
+                       num--, args++;
+                       if (num < 1)
+                               return MSG_SYNTAX;
+                       cycle_dir_t cyc;
+                       if (parse_cycle_direction(*args, &cyc)) {
+                               desktop_t *d = trg.desktop;
+                               if (cyc == CYCLE_PREV) {
+                                       if (d->prev == NULL) {
+                                               while (d->next != NULL) {
+                                                       swap_desktops(trg.monitor, d, trg.monitor, d->next);
+                                               }
+                                       } else {
+                                               swap_desktops(trg.monitor, d, trg.monitor, d->prev);
+                                       }
+                               } else {
+                                       if (d->next == NULL) {
+                                               while (d->prev != NULL) {
+                                                       swap_desktops(trg.monitor, d, trg.monitor, d->prev);
+                                               }
+                                       } else {
+                                               swap_desktops(trg.monitor, d, trg.monitor, d->next);
+                                       }
+                               }
+                       } else {
+                               return MSG_FAILURE;
+                       }
                } else if (streq("-l", *args) || streq("--layout", *args)) {
                        num--, args++;
                        if (num < 1)
@@ -408,9 +433,10 @@ int cmd_desktop(char **args, int num)
                        num--, args++;
                        if (num < 1)
                                return MSG_SYNTAX;
+                       put_status(SBSC_MASK_DESKTOP_RENAME, "desktop_rename %s %s %s\n", trg.monitor->name, trg.desktop->name, *args);
                        snprintf(trg.desktop->name, sizeof(trg.desktop->name), "%s", *args);
                        ewmh_update_desktop_names();
-                       put_status();
+                       put_status(SBSC_MASK_REPORT);
                } else if (streq("-r", *args) || streq("--remove", *args)) {
                        if (trg.desktop->root == NULL &&
                            trg.monitor->desk_head != trg.monitor->desk_tail) {
@@ -528,11 +554,14 @@ int cmd_monitor(char **args, int num)
                                return MSG_SYNTAX;
                        desktop_t *d = trg.monitor->desk_head;
                        while (num > 0 && d != NULL) {
+                               put_status(SBSC_MASK_DESKTOP_RENAME, "desktop_rename %s %s %s\n", trg.monitor->name, d->name, *args);
                                snprintf(d->name, sizeof(d->name), "%s", *args);
+                               initialize_desktop(d);
+                               arrange(trg.monitor, d);
                                d = d->next;
                                num--, args++;
                        }
-                       put_status();
+                       put_status(SBSC_MASK_REPORT);
                        while (num > 0) {
                                add_desktop(trg.monitor, make_desktop(*args));
                                num--, args++;
@@ -585,8 +614,9 @@ int cmd_monitor(char **args, int num)
                        num--, args++;
                        if (num < 1)
                                return MSG_SYNTAX;
+                       put_status(SBSC_MASK_MONITOR_RENAME, "monitor_rename %s %s\n", trg.monitor->name, *args);
                        snprintf(trg.monitor->name, sizeof(trg.monitor->name), "%s", *args);
-                       put_status();
+                       put_status(SBSC_MASK_REPORT);
                } else if (streq("-s", *args) || streq("--swap", *args)) {
                        num--, args++;
                        if (num < 1)
@@ -739,6 +769,7 @@ int cmd_pointer(char **args, int num)
                                track_pointer(x, y);
                        else
                                return MSG_FAILURE;
+                       num--, args++;
                } else if (streq("-g", *args) || streq("--grab", *args)) {
                        num--, args++;
                        if (num < 1)
@@ -798,9 +829,25 @@ int cmd_control(char **args, int num, FILE *rsp)
                } else if (streq("--toggle-visibility", *args)) {
                        toggle_visibility();
                } else if (streq("--subscribe", *args)) {
+                       num--, args++;
+                       int field = 0;
+                       if (num < 1) {
+                               field = SBSC_MASK_REPORT;
+                       } else {
+                               subscriber_mask_t mask;
+                               while (num > 0) {
+                                       if (parse_subscriber_mask(*args, &mask)) {
+                                               field |= mask;
+                                       } else {
+                                               return MSG_SYNTAX;
+                                       }
+                                       num--, args++;
+                               }
+                       }
+                       add_subscriber(rsp, field);
                        return MSG_SUBSCRIBE;
                } else if (streq("--get-status", *args)) {
-                       print_status(rsp);
+                       print_report(rsp);
                } else if (streq("--record-history", *args)) {
                        num--, args++;
                        if (num < 1)
@@ -867,7 +914,7 @@ int cmd_quit(char **args, int num)
 
 int set_setting(coordinates_t loc, char *name, char *value)
 {
-#define DESKWINSET(k, v) \
+#define DESKWINDEFSET(k, v) \
                if (loc.node != NULL) \
                        loc.node->client->k = v; \
                else if (loc.desktop != NULL) \
@@ -876,31 +923,27 @@ int set_setting(coordinates_t loc, char *name, char *value)
                        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 MSG_FAILURE;
-               DESKWINSET(border_width, bw)
-#undef DESKWINSET
-#define DESKSET(k, v) \
+               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 \
-                       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;
        } else if (streq("window_gap", name)) {
                int wg;
                if (sscanf(value, "%i", &wg) != 1)
                        return MSG_FAILURE;
-               DESKSET(window_gap, wg)
-#undef DESKSET
+               DESKDEFSET(window_gap, wg)
+#undef DESKDEFSET
 #define MONDESKSET(k, v) \
                if (loc.desktop != NULL) \
                        loc.desktop->k = v; \
@@ -932,7 +975,8 @@ int set_setting(coordinates_t loc, char *name, char *value)
 #undef MONDESKSET
 #define SETSTR(s) \
        } else if (streq(#s, name)) { \
-               return snprintf(s, sizeof(s), "%s", value) >= 0;
+               if (snprintf(s, sizeof(s), "%s", value) < 0) \
+                       return MSG_FAILURE;
        SETSTR(external_rules_command)
        SETSTR(status_prefix)
 #undef SETSTR
@@ -961,23 +1005,33 @@ int set_setting(coordinates_t loc, char *name, char *value)
        SETCOLOR(normal_private_border_color)
        SETCOLOR(urgent_border_color)
 #undef SETCOLOR
+       } else if (streq("initial_polarity", name)) {
+               child_polarity_t p;
+               if (parse_child_polarity(value, &p)) {
+                       initial_polarity = p;
+               } else {
+                       return MSG_FAILURE;
+               }
        } else if (streq("focus_follows_pointer", name)) {
                bool b;
                if (parse_bool(value, &b) && b != focus_follows_pointer) {
                        focus_follows_pointer = b;
-                       for (monitor_t *m = mon_head; m != NULL; m = m->next)
-                               for (desktop_t *d = m->desk_head; d != NULL; d = d->next)
+                       uint32_t values[] = {CLIENT_EVENT_MASK | (focus_follows_pointer ? XCB_EVENT_MASK_ENTER_WINDOW : 0)};
+                       for (monitor_t *m = mon_head; m != NULL; m = m->next) {
+                               for (desktop_t *d = m->desk_head; d != NULL; d = d->next) {
                                        for (node_t *n = first_extrema(d->root); n != NULL; n = next_leaf(n, d->root)) {
-                                               uint32_t values[] = {CLIENT_EVENT_MASK | (focus_follows_pointer ? XCB_EVENT_MASK_ENTER_WINDOW : 0)};
                                                xcb_change_window_attributes(dpy, n->client->window, XCB_CW_EVENT_MASK, values);
                                        }
+                               }
+                       }
                        if (focus_follows_pointer) {
-                               for (monitor_t *m = mon_head; m != NULL; m = m->next)
+                               for (monitor_t *m = mon_head; m != NULL; m = m->next) {
                                        window_show(m->root);
-                               enable_motion_recorder();
+                               }
                        } else {
-                               for (monitor_t *m = mon_head; m != NULL; m = m->next)
+                               for (monitor_t *m = mon_head; m != NULL; m = m->next) {
                                        window_hide(m->root);
+                               }
                                disable_motion_recorder();
                        }
                        return MSG_SUCCESS;
@@ -990,14 +1044,27 @@ int set_setting(coordinates_t loc, char *name, char *value)
                        return MSG_FAILURE;
                SETBOOL(borderless_monocle)
                SETBOOL(gapless_monocle)
+               SETBOOL(leaf_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)
+               SETBOOL(center_pseudo_tiled)
 #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 MSG_FAILURE;
        }
@@ -1014,21 +1081,23 @@ int get_setting(coordinates_t loc, char *name, FILE* rsp)
        if (streq("split_ratio", name))
                fprintf(rsp, "%lf", split_ratio);
        else if (streq("window_gap", name))
-               if (loc.desktop == NULL)
-                       return MSG_FAILURE;
-               else
+               if (loc.desktop != NULL)
                        fprintf(rsp, "%i", loc.desktop->window_gap);
+               else
+                       fprintf(rsp, "%i", window_gap);
        else if (streq("border_width", name))
                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
-                       return MSG_FAILURE;
+                       fprintf(rsp, "%u", border_width);
        else if (streq("external_rules_command", name))
                fprintf(rsp, "%s", external_rules_command);
        else if (streq("status_prefix", name))
                fprintf(rsp, "%s", status_prefix);
+       else if (streq("initial_polarity", name))
+               fprintf(rsp, "%s", initial_polarity == FIRST_CHILD ? "first_child" : "second_child");
 #define MONDESKGET(k) \
        else if (streq(#k, name)) \
                if (loc.desktop != NULL) \
@@ -1062,20 +1131,86 @@ int get_setting(coordinates_t loc, char *name, FILE* rsp)
                fprintf(rsp, "%s", BOOLSTR(s));
        GETBOOL(borderless_monocle)
        GETBOOL(gapless_monocle)
+       GETBOOL(leaf_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(center_pseudo_tiled)
+       GETBOOL(remove_disabled_monitors)
+       GETBOOL(remove_unplugged_monitors)
+       GETBOOL(merge_overlapping_monitors)
 #undef GETBOOL
        else
                return MSG_FAILURE;
        return MSG_SUCCESS;
 }
 
+bool parse_subscriber_mask(char *s, subscriber_mask_t *mask)
+{
+       if (streq("all", s)) {
+               *mask = SBSC_MASK_ALL;
+       } else if (streq("window", s)) {
+               *mask = SBSC_MASK_WINDOW;
+       } else if (streq("desktop", s)) {
+               *mask = SBSC_MASK_DESKTOP;
+       } else if (streq("monitor", s)) {
+               *mask = SBSC_MASK_MONITOR;
+       } else if (streq("window_manage", s)) {
+               *mask = SBSC_MASK_WINDOW_MANAGE;
+       } else if (streq("window_unmanage", s)) {
+               *mask = SBSC_MASK_WINDOW_UNMANAGE;
+       } else if (streq("window_swap", s)) {
+               *mask = SBSC_MASK_WINDOW_SWAP;
+       } else if (streq("window_transfer", s)) {
+               *mask = SBSC_MASK_WINDOW_TRANSFER;
+       } else if (streq("window_focus", s)) {
+               *mask = SBSC_MASK_WINDOW_FOCUS;
+       } else if (streq("window_resize", s)) {
+               *mask = SBSC_MASK_WINDOW_RESIZE;
+       } else if (streq("window_move", s)) {
+               *mask = SBSC_MASK_WINDOW_MOVE;
+       } else if (streq("window_state", s)) {
+               *mask = SBSC_MASK_WINDOW_STATE;
+       } else if (streq("desktop_add", s)) {
+               *mask = SBSC_MASK_DESKTOP_ADD;
+       } else if (streq("desktop_rename", s)) {
+               *mask = SBSC_MASK_DESKTOP_RENAME;
+       } else if (streq("desktop_remove", s)) {
+               *mask = SBSC_MASK_DESKTOP_REMOVE;
+       } else if (streq("desktop_swap", s)) {
+               *mask = SBSC_MASK_DESKTOP_SWAP;
+       } else if (streq("desktop_transfer", s)) {
+               *mask = SBSC_MASK_DESKTOP_TRANSFER;
+       } else if (streq("desktop_focus", s)) {
+               *mask = SBSC_MASK_DESKTOP_FOCUS;
+       } else if (streq("desktop_layout", s)) {
+               *mask = SBSC_MASK_DESKTOP_LAYOUT;
+       } else if (streq("desktop_state", s)) {
+               *mask = SBSC_MASK_DESKTOP_STATE;
+       } else if (streq("monitor_add", s)) {
+               *mask = SBSC_MASK_MONITOR_ADD;
+       } else if (streq("monitor_rename", s)) {
+               *mask = SBSC_MASK_MONITOR_RENAME;
+       } else if (streq("monitor_remove", s)) {
+               *mask = SBSC_MASK_MONITOR_REMOVE;
+       } else if (streq("monitor_focus", s)) {
+               *mask = SBSC_MASK_MONITOR_FOCUS;
+       } else if (streq("monitor_resize", s)) {
+               *mask = SBSC_MASK_MONITOR_RESIZE;
+       } else if (streq("report", s)) {
+               *mask = SBSC_MASK_REPORT;
+       } else {
+               return false;
+       }
+       return true;
+}
+
 bool parse_bool(char *value, bool *b)
 {
        if (streq("true", value) || streq("on", value)) {
@@ -1185,6 +1320,18 @@ bool parse_pointer_action(char *s, pointer_action_t *a)
        return false;
 }
 
+bool parse_child_polarity(char *s, child_polarity_t *p)
+{
+       if (streq("first_child", s)) {
+               *p = FIRST_CHILD;
+               return true;
+       } else if (streq("second_child", s)) {
+               *p = SECOND_CHILD;
+               return true;
+       }
+       return false;
+}
+
 bool parse_degree(char *s, int *d)
 {
        int i = atoi(s);