]> git.lizzy.rs Git - bspwm.git/blobdiff - messages.c
Handle preselection in pseudo-automatic mode example
[bspwm.git] / messages.c
index da669c405d62c826afe1c0c0f0722185e4eafc09..0aeea4da8ace25fd93c96711e88049745af22018 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\n", 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) {
@@ -529,10 +555,12 @@ int cmd_monitor(char **args, int num)
                        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++;
                        }
-                       put_status();
+                       put_status(SBSC_MASK_REPORT);
                        while (num > 0) {
                                add_desktop(trg.monitor, make_desktop(*args));
                                num--, args++;
@@ -585,8 +613,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)
@@ -799,9 +828,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)
@@ -868,7 +913,7 @@ int cmd_quit(char **args, int num)
 
 int set_setting(coordinates_t loc, char *name, char *value)
 {
-#define DESKWINGLOBSET(k, v) \
+#define DESKWINDEFSET(k, v) \
                if (loc.node != NULL) \
                        loc.node->client->k = v; \
                else if (loc.desktop != NULL) \
@@ -882,9 +927,9 @@ int set_setting(coordinates_t loc, char *name, char *value)
                unsigned int bw;
                if (sscanf(value, "%u", &bw) != 1)
                        return MSG_FAILURE;
-               DESKWINGLOBSET(border_width, bw)
-#undef DESKWINGLOBSET
-#define DESKGLOBSET(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) \
@@ -896,8 +941,8 @@ int set_setting(coordinates_t loc, char *name, char *value)
                int wg;
                if (sscanf(value, "%i", &wg) != 1)
                        return MSG_FAILURE;
-               DESKGLOBSET(window_gap, wg)
-#undef DESKGLOBSET
+               DESKDEFSET(window_gap, wg)
+#undef DESKDEFSET
 #define MONDESKSET(k, v) \
                if (loc.desktop != NULL) \
                        loc.desktop->k = v; \
@@ -929,7 +974,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
@@ -958,6 +1004,13 @@ 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) {
@@ -968,15 +1021,6 @@ int set_setting(coordinates_t loc, char *name, char *value)
                                                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)
-                                       window_show(m->root);
-                               enable_motion_recorder();
-                       } else {
-                               for (monitor_t *m = mon_head; m != NULL; m = m->next)
-                                       window_hide(m->root);
-                               disable_motion_recorder();
-                       }
                        return MSG_SUCCESS;
                } else {
                        return MSG_FAILURE;
@@ -987,16 +1031,26 @@ int set_setting(coordinates_t loc, char *name, char *value)
                        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_monitors)
-               SETBOOL(remove_unplugged_monitors)
-               SETBOOL(merge_overlapping_monitors)
+               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;
        }
@@ -1013,21 +1067,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,12 +1118,15 @@ int get_setting(coordinates_t loc, char *name, FILE* rsp)
        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(center_pseudo_tiled)
        GETBOOL(remove_disabled_monitors)
        GETBOOL(remove_unplugged_monitors)
        GETBOOL(merge_overlapping_monitors)
@@ -1077,6 +1136,44 @@ int get_setting(coordinates_t loc, char *name, FILE* rsp)
        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_urgent", s)) {
+               *mask = SBSC_MASK_WINDOW_URGENT;
+       } else if (streq("window_fullscreen", s)) {
+               *mask = SBSC_MASK_WINDOW_FULLSCREEN;
+       } 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("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("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)) {
@@ -1186,6 +1283,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);