]> git.lizzy.rs Git - bspwm.git/blobdiff - messages.c
New setting: `history_aware_focus`
[bspwm.git] / messages.c
index 3c2767dd3f7cf58c096e3dd60c91b431868c1753..2675a3cd1186e15ccac543b704f6af099b1ce5a2 100644 (file)
@@ -95,29 +95,25 @@ void process_message(char *msg, char *rsp)
     } else if (strcmp(cmd, "layout") == 0) {
         char *lyt = strtok(NULL, TOK_SEP);
         if (lyt != NULL) {
-            layout_t y;
-            if (parse_layout(lyt, &y)) {
+            layout_t l;
+            if (parse_layout(lyt, &l)) {
                 char *name = strtok(NULL, TOK_SEP);
                 if (name == NULL) {
-                    mon->desk->layout = y;
+                    change_layout(mon, mon->desk, l);
                 } else {
                     desktop_location_t loc;
                     do {
                         if (locate_desktop(name, &loc))
-                            loc.desktop->layout = y;
+                            change_layout(loc.monitor, loc.desktop, l);
                     } while ((name = strtok(NULL, TOK_SEP)) != NULL);
                 }
             }
         }
-        put_status();
-        arrange(mon, mon->desk);
     } else if (strcmp(cmd, "cycle_layout") == 0) {
         if (mon->desk->layout == LAYOUT_MONOCLE)
-            mon->desk->layout = LAYOUT_TILED;
+            change_layout(mon, mon->desk, LAYOUT_TILED);
         else
-            mon->desk->layout = LAYOUT_MONOCLE;
-        put_status();
-        arrange(mon, mon->desk);
+            change_layout(mon, mon->desk, LAYOUT_MONOCLE);
     } else if (strcmp(cmd, "shift") == 0) {
         char *dir = strtok(NULL, TOK_SEP);
         if (dir != NULL) {
@@ -127,13 +123,13 @@ void process_message(char *msg, char *rsp)
         }
         arrange(mon, mon->desk);
     } else if (strcmp(cmd, "toggle_fullscreen") == 0) {
-        if (mon->desk->focus != NULL)
-            toggle_fullscreen(mon, mon->desk, mon->desk->focus);
+        toggle_fullscreen(mon->desk, mon->desk->focus);
+        arrange(mon, mon->desk);
     } else if (strcmp(cmd, "toggle_floating") == 0) {
         toggle_floating(mon->desk, mon->desk->focus);
+        arrange(mon, mon->desk);
     } else if (strcmp(cmd, "toggle_locked") == 0) {
-        if (mon->desk->focus != NULL)
-            toggle_locked(mon, mon->desk, mon->desk->focus);
+        toggle_locked(mon, mon->desk, mon->desk->focus);
     } else if (strcmp(cmd, "toggle_visibility") == 0) {
         toggle_visibility();
     } else if (strcmp(cmd, "pad") == 0) {
@@ -182,10 +178,22 @@ void process_message(char *msg, char *rsp)
         if (dir != NULL) {
             fence_move_t m;
             direction_t d;
-            if (parse_fence_move(cmd, &m) && parse_direction(dir, &d))
+            if (parse_fence_move(cmd, &m) && parse_direction(dir, &d)) {
                 move_fence(mon->desk->focus, d, m);
+                arrange(mon, mon->desk);
+            }
+        }
+    } else if (strcmp(cmd, "fence_ratio") == 0) {
+        char *dir = strtok(NULL, TOK_SEP);
+        if (dir != NULL) {
+            direction_t d;
+            node_t *n;
+            if (parse_direction(dir, &d) && (n = find_fence(mon->desk->focus, d)) != NULL) {
+                char *value = strtok(NULL, TOK_SEP);
+                if (sscanf(value, "%lf", &n->split_ratio) == 1)
+                    arrange(mon, mon->desk);
+            }
         }
-        arrange(mon, mon->desk);
     } else if (strcmp(cmd, "drop_to_monitor") == 0) {
         char *dir = strtok(NULL, TOK_SEP);
         if (dir != NULL) {
@@ -378,11 +386,14 @@ void process_message(char *msg, char *rsp)
             if (sscanf(arg, "%X", &uid) > 0)
                 remove_rule_by_uid(uid);
     } else if (strcmp(cmd, "swap") == 0) {
-        node_t *last_focus = history_get(mon->desk->history, 1);
-        swap_nodes(mon->desk->focus, last_focus);
         char *opt = strtok(NULL, TOK_SEP);
         swap_option_t o;
-        if (parse_swap_option(opt, &o) && o == SWAP_OPTION_SWAP_FOCUS)
+        if (!parse_swap_option(opt, &o))
+            return;
+        node_t *last_focus = history_get(mon->desk->history, 1);
+        swap_nodes(mon->desk->focus, last_focus);
+        arrange(mon, mon->desk);
+        if (o == SWAP_OPTION_SWAP_FOCUS)
             focus_node(mon, mon->desk, last_focus);
     } else if (strcmp(cmd, "alternate") == 0) {
         focus_node(mon, mon->desk, history_get(mon->desk->history, 1));
@@ -434,17 +445,23 @@ void process_message(char *msg, char *rsp)
             }
         }
     } else if (strcmp(cmd, "focus") == 0) {
-        if (mon->desk->focus == NULL || mon->desk->focus->client->fullscreen)
+        node_t *f = mon->desk->focus;
+        if (f == NULL || f->client->fullscreen)
             return;
         char *dir = strtok(NULL, TOK_SEP);
         if (dir != NULL) {
             direction_t d;
             if (parse_direction(dir, &d)) {
-                node_t *n;
-                if (focus_by_distance)
-                    n = nearest_neighbor(mon->desk, mon->desk->focus, d);
-                else
-                    n = find_neighbor(mon->desk->focus, d);
+                node_t *n = NULL;
+                if (history_aware_focus)
+                    n = nearest_from_history(mon->desk->history, f, d);
+                if (n == NULL) {
+                    if (focus_by_distance) {
+                        n = nearest_neighbor(mon->desk, f, d);
+                    } else {
+                        n = find_neighbor(f, d);
+                    }
+                }
                 focus_node(mon, mon->desk, n);
             }
         }
@@ -559,6 +576,11 @@ void set_setting(char *name, char *value, char *rsp)
         if (parse_bool(value, &b))
             focus_by_distance = b;
         return;
+    } else if (strcmp(name, "history_aware_focus") == 0) {
+        bool b;
+        if (parse_bool(value, &b))
+            history_aware_focus = b;
+        return;
     } else if (strcmp(name, "wm_name") == 0) {
         strncpy(wm_name, value, sizeof(wm_name));
         ewmh_update_wm_name();
@@ -624,6 +646,8 @@ void get_setting(char *name, char* rsp)
         snprintf(rsp, BUFSIZ, "%s", BOOLSTR(auto_alternate));
     else if (strcmp(name, "focus_by_distance") == 0)
         snprintf(rsp, BUFSIZ, "%s", BOOLSTR(focus_by_distance));
+    else if (strcmp(name, "history_aware_focus") == 0)
+        snprintf(rsp, BUFSIZ, "%s", BOOLSTR(history_aware_focus));
     else if (strcmp(name, "wm_name") == 0)
         snprintf(rsp, BUFSIZ, "%s", wm_name);
     else