]> git.lizzy.rs Git - bspwm.git/blobdiff - messages.c
Reset stacking client list whenever appropriate
[bspwm.git] / messages.c
index 2675a3cd1186e15ccac543b704f6af099b1ce5a2..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);
@@ -190,7 +202,7 @@ void process_message(char *msg, char *rsp)
             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)
+                if (value != NULL && sscanf(value, "%lf", &n->split_ratio) == 1)
                     arrange(mon, mon->desk);
             }
         }
@@ -287,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) {
@@ -445,24 +467,18 @@ void process_message(char *msg, char *rsp)
             }
         }
     } else if (strcmp(cmd, "focus") == 0) {
-        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 = 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);
-                    }
+                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);
                 }
-                focus_node(mon, mon->desk, n);
             }
         }
     } else if (strcmp(cmd, "put_status") == 0) {
@@ -556,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))
@@ -638,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)
@@ -804,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) {