]> git.lizzy.rs Git - bspwm.git/blobdiff - messages.c
Reset stacking client list whenever appropriate
[bspwm.git] / messages.c
index c6e933e895af07b9f03d7fc8c6be25127b356fc5..dac53436251ae2226f6fb95af8b5273b38ef6700 100644 (file)
@@ -55,7 +55,7 @@ void process_message(char *msg, char *rsp)
     } else if (strcmp(cmd, "close") == 0) {
         window_close(mon->desk->focus);
     } else if (strcmp(cmd, "kill") == 0) {
-        window_kill(mon->desk, mon->desk->focus);
+        window_kill(mon, mon->desk, mon->desk->focus);
     } else if (strcmp(cmd, "rotate") == 0) {
         char *deg = strtok(NULL, TOK_SEP);
         if (deg != NULL) {
@@ -118,10 +118,18 @@ void process_message(char *msg, char *rsp)
         char *dir = strtok(NULL, TOK_SEP);
         if (dir != NULL) {
             direction_t d;
-            if (parse_direction(dir, &d))
-                swap_nodes(mon->desk->focus, focus_by_distance ? nearest_neighbor(mon->desk, mon->desk->focus, d) : find_neighbor(mon->desk->focus, d));
+            if (parse_direction(dir, &d)) {
+                node_t *n = nearest_neighbor(mon->desk, mon->desk->focus, d);
+                if (n != NULL) {
+                    swap_nodes(mon->desk->focus, n);
+                    arrange(mon, mon->desk);
+                } else if (monitor_focus_fallback) {
+                    monitor_t *m = nearest_monitor(d);
+                    if (m != NULL)
+                        transfer_node(mon, mon->desk, m, m->desk, mon->desk->focus);
+                }
+            }
         }
-        arrange(mon, mon->desk);
     } else if (strcmp(cmd, "toggle_fullscreen") == 0) {
         toggle_fullscreen(mon->desk, mon->desk->focus);
         arrange(mon, mon->desk);
@@ -156,8 +164,12 @@ void process_message(char *msg, char *rsp)
                 sscanf(value, "%lf", &mon->desk->focus->split_ratio) == 1)
             window_draw_border(mon->desk->focus, true, true);
     } else if (strcmp(cmd, "cancel") == 0) {
-        split_mode = MODE_AUTOMATIC;
-        window_draw_border(mon->desk->focus, true, true);
+        if (mon->desk->focus == NULL)
+            return;
+        char *opt = strtok(NULL, TOK_SEP);
+        cancel_option_t o;
+        if (parse_cancel_option(opt, &o))
+            reset_mode(mon->desk, mon->desk->focus, o);
     } else if (strcmp(cmd, "presel") == 0) {
         if (mon->desk->focus == NULL || !is_tiled(mon->desk->focus->client) || mon->desk->layout != LAYOUT_TILED)
             return;
@@ -165,8 +177,8 @@ void process_message(char *msg, char *rsp)
         if (dir != NULL) {
             direction_t d;
             if (parse_direction(dir, &d)) {
-                split_mode = MODE_MANUAL;
-                split_dir = d;
+                mon->desk->focus->split_mode = MODE_MANUAL;
+                mon->desk->focus->split_dir = d;
                 char *rat = strtok(NULL, TOK_SEP);
                 if (rat != NULL)
                     sscanf(rat, "%lf", &mon->desk->focus->split_ratio);
@@ -178,10 +190,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 (value != NULL && 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) {
@@ -275,6 +299,16 @@ void process_message(char *msg, char *rsp)
                 focus_node(m, m->desk, m->desk->focus);
             }
         }
+    } else if (strcmp(cmd, "focus_monitor") == 0) {
+        char *dir = strtok(NULL, TOK_SEP);
+        if (dir != NULL) {
+            direction_t d;
+            if (parse_direction(dir, &d)) {
+                monitor_t *m = nearest_monitor(d);
+                if (m != NULL)
+                    focus_node(m, m->desk, m->desk->focus);
+            }
+        }
     } else if (strcmp(cmd, "use") == 0) {
         char *name = strtok(NULL, TOK_SEP);
         if (name != NULL) {
@@ -433,18 +467,18 @@ void process_message(char *msg, char *rsp)
             }
         }
     } else if (strcmp(cmd, "focus") == 0) {
-        if (mon->desk->focus == NULL || mon->desk->focus->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);
-                focus_node(mon, mon->desk, n);
+                node_t *n = nearest_neighbor(mon->desk, mon->desk->focus, d);
+                if (n != NULL) {
+                    focus_node(mon, mon->desk, n);
+                } else if (monitor_focus_fallback) {
+                    monitor_t *m = nearest_monitor(d);
+                    if (m != NULL)
+                        focus_node(m, m->desk, m->desk->focus);
+                }
             }
         }
     } else if (strcmp(cmd, "put_status") == 0) {
@@ -538,6 +572,11 @@ void set_setting(char *name, char *value, char *rsp)
         if (parse_bool(value, &b))
             pointer_follows_monitor = b;
         return;
+    } else if (strcmp(name, "monitor_focus_fallback") == 0) {
+        bool b;
+        if (parse_bool(value, &b))
+            monitor_focus_fallback = b;
+        return;
     } else if (strcmp(name, "adaptative_raise") == 0) {
         bool b;
         if (parse_bool(value, &b))
@@ -558,6 +597,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();
@@ -615,6 +659,8 @@ void get_setting(char *name, char* rsp)
         snprintf(rsp, BUFSIZ, "%s", BOOLSTR(focus_follows_pointer));
     else if (strcmp(name, "pointer_follows_monitor") == 0)
         snprintf(rsp, BUFSIZ, "%s", BOOLSTR(pointer_follows_monitor));
+    else if (strcmp(name, "monitor_focus_fallback") == 0)
+        snprintf(rsp, BUFSIZ, "%s", BOOLSTR(monitor_focus_fallback));
     else if (strcmp(name, "adaptative_raise") == 0)
         snprintf(rsp, BUFSIZ, "%s", BOOLSTR(adaptative_raise));
     else if (strcmp(name, "apply_shadow_property") == 0)
@@ -623,6 +669,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
@@ -779,6 +827,18 @@ bool parse_swap_option(char *s, swap_option_t *o)
     return false;
 }
 
+bool parse_cancel_option(char *s, cancel_option_t *o)
+{
+    if (s == NULL) {
+        *o = CANCEL_OPTION_FOCUSED;
+        return true;
+    } else if (strcmp(s, "--all") == 0) {
+        *o = CANCEL_OPTION_ALL;
+        return true;
+    }
+    return false;
+}
+
 bool parse_rotate(char *s, rotate_t *r)
 {
     if (strcmp(s, "clockwise") == 0) {