]> git.lizzy.rs Git - bspwm.git/blobdiff - tree.c
Remove window borders whenever possible
[bspwm.git] / tree.c
diff --git a/tree.c b/tree.c
index 3d5327b57339519093eaa659a663291dc561a182..1a32782195ff75e72cd876d097e6da026b592b02 100644 (file)
--- a/tree.c
+++ b/tree.c
@@ -6,7 +6,7 @@
 #include <xcb/xcb_event.h>
 #include "settings.h"
 #include "helpers.h"
-#include "utils.h"
+#include "misc.h"
 #include "window.h"
 #include "types.h"
 #include "bspwm.h"
@@ -167,6 +167,34 @@ void rotate_tree(node_t *n, rotate_t rot)
     rotate_tree(n->second_child, rot);
 }
 
+void magnetise_tree(node_t *n, corner_t corner)
+{
+    if (n == NULL || is_leaf(n)) 
+        return;
+
+    PUTS("magnetise tree");
+
+    switch (n->split_type) {
+        case TYPE_HORIZONTAL:
+            if (corner == TOP_LEFT || corner == TOP_RIGHT)
+                change_split_ratio(n, CHANGE_DECREASE);
+            else
+                change_split_ratio(n, CHANGE_INCREASE);
+            break;
+        case TYPE_VERTICAL:
+            if (corner == TOP_LEFT || corner == BOTTOM_LEFT)
+                change_split_ratio(n, CHANGE_DECREASE);
+            else
+                change_split_ratio(n, CHANGE_INCREASE);
+            break;
+        default:
+            break;
+    }
+
+    magnetise_tree(n->first_child, corner);
+    magnetise_tree(n->second_child, corner);
+}
+
 void dump_tree(desktop_t *d, node_t *n, char *rsp, int depth)
 {
     if (n == NULL)
@@ -178,11 +206,8 @@ void dump_tree(desktop_t *d, node_t *n, char *rsp, int depth)
         strcat(rsp, "  ");
 
     if (is_leaf(n))
-        /* sprintf(line, "0x%X [%i %i %u %u]", n->client->window, n->rectangle.x, n->rectangle.y, n->rectangle.width, n->rectangle.height); */ 
-        /* sprintf(line, "C %X [%i %i %u %u] (%s%s) [%i %i %u %u]", n->client->window, n->rectangle.x, n->rectangle.y, n->rectangle.width, n->rectangle.height, (n->client->floating ? "f" : "-"), (n->client->transient ? "t" : "-"), n->client->floating_rectangle.x, n->client->floating_rectangle.y, n->client->floating_rectangle.width, n->client->floating_rectangle.height); */ 
-        sprintf(line, "C %X %s%s%s%s%s", n->client->window, (n->client->floating ? "f" : "-"), (n->client->transient ? "t" : "-"), (n->client->fullscreen ? "F" : "-"), (n->client->urgent ? "u" : "-"), (n->client->locked ? "l" : "-")); 
+        sprintf(line, "%s %X %s%s%s%s%s", n->client->class_name, n->client->window, (n->client->floating ? "f" : "-"), (n->client->transient ? "t" : "-"), (n->client->fullscreen ? "F" : "-"), (n->client->urgent ? "u" : "-"), (n->client->locked ? "l" : "-")); 
     else
-        /* sprintf(line, "%s %.2f [%i %i %u %u]", (n->split_type == TYPE_HORIZONTAL ? "H" : "V"), n->split_ratio, n->rectangle.x, n->rectangle.y, n->rectangle.width, n->rectangle.height); */
         sprintf(line, "%s %.2f", (n->split_type == TYPE_HORIZONTAL ? "H" : "V"), n->split_ratio);
 
     strcat(rsp, line);
@@ -236,13 +261,19 @@ void apply_layout(desktop_t *d, node_t *n, xcb_rectangle_t rect)
     if (is_leaf(n)) {
         if (n->client->fullscreen)
             return;
+
+        if (n == d->root || (d->layout == LAYOUT_MONOCLE && !is_floating(n->client)))
+            n->client->border_width = 0;
+        else
+            n->client->border_width = border_width;
+
         xcb_rectangle_t r;
         if (is_tiled(n->client)) {
             if (d->layout == LAYOUT_TILED)
                 r = rect;
             else if (d->layout == LAYOUT_MONOCLE)
                 r = root_rect;
-            int bleed = window_gap + 2 * border_width;
+            int bleed = window_gap + 2 * n->client->border_width;
             r.width = (bleed < r.width ? r.width - bleed : 1);
             r.height = (bleed < r.height ? r.height - bleed : 1);
             n->client->tiled_rectangle = r;
@@ -251,7 +282,7 @@ void apply_layout(desktop_t *d, node_t *n, xcb_rectangle_t rect)
         }
 
         window_move_resize(n->client->window, r.x, r.y, r.width, r.height);
-        window_border_width(n->client->window, border_width);
+        window_border_width(n->client->window, n->client->border_width);
         window_draw_border(n, n == d->focus);
 
         if (d->layout == LAYOUT_MONOCLE && n == d->focus)
@@ -297,13 +328,16 @@ void insert_node(desktop_t *d, node_t *n)
         node_t *dad = make_node();
         node_t *fopar = focus->parent;
         n->parent = dad;
-        dad->born_as = split_mode;
+        n->born_as = split_mode;
         switch (split_mode) {
             case MODE_AUTOMATIC:
                 if (fopar == NULL) {
                     dad->first_child = n;
                     dad->second_child = focus;
-                    dad->split_type = TYPE_VERTICAL;
+                    if (focus->rectangle.width > focus->rectangle.height)
+                        dad->split_type = TYPE_VERTICAL;
+                    else
+                        dad->split_type = TYPE_HORIZONTAL;
                     focus->parent = dad;
                     d->root = dad;
                 } else {
@@ -368,6 +402,8 @@ void insert_node(desktop_t *d, node_t *n)
                 split_mode = MODE_AUTOMATIC;
                 break;
         }
+        if (focus->vacant)
+            update_vacant_state(fopar);
     }
 }
 
@@ -426,13 +462,14 @@ void unlink_node(desktop_t *d, node_t *n)
     } else {
         node_t *b;
         node_t *g = p->parent;
-        if (is_first_child(n)) {
+        bool n_first_child = is_first_child(n);
+        if (n_first_child) {
             b = p->second_child;
-            if (b->born_as == MODE_AUTOMATIC)
+            if (n->born_as == MODE_AUTOMATIC)
                 rotate_tree(b, ROTATE_COUNTER_CLOCKWISE);
         } else {
             b = p->first_child;
-            if (b->born_as == MODE_AUTOMATIC)
+            if (n->born_as == MODE_AUTOMATIC)
                 rotate_tree(b, ROTATE_CLOCKWISE);
         }
         b->parent = g;
@@ -448,13 +485,17 @@ void unlink_node(desktop_t *d, node_t *n)
         n->parent = NULL;
         free(p);
 
-        if (n == d->focus) {
-            if (d->last_focus != NULL && d->last_focus != n)
+        if (n == d->last_focus) {
+            d->last_focus = NULL;
+        } else if (n == d->focus) {
+            if (d->last_focus != NULL)
                 d->focus = d->last_focus;
             else
-                d->focus = (is_first_child(b) ? second_extrema(b) : first_extrema(b));
+                d->focus = (n_first_child ? first_extrema(b) : second_extrema(b));
             d->last_focus = NULL;
         }
+
+        update_vacant_state(b->parent);
     }
 }
 
@@ -543,7 +584,6 @@ void select_desktop(desktop_t *d)
     node_t *n = first_extrema(d->root);
 
     while (n != NULL) {
-        /* xcb_map_window(dpy, n->client->window); */
         window_show(n->client->window);
         n = next_leaf(n);
     }
@@ -564,9 +604,9 @@ void select_desktop(desktop_t *d)
 
 void cycle_desktop(cycle_dir_t dir)
 {
-    if (dir == DIR_NEXT)
+    if (dir == CYCLE_NEXT)
         select_desktop((desk->next == NULL ? desk_head : desk->next));
-    else if (dir == DIR_PREV)
+    else if (dir == CYCLE_PREV)
         select_desktop((desk->prev == NULL ? desk_tail : desk->prev));
 }
 
@@ -577,19 +617,21 @@ void cycle_leaf(desktop_t *d, node_t *n, cycle_dir_t dir, skip_client_t skip)
 
     PUTS("cycle leaf");
 
-    node_t *f = (dir == DIR_PREV ? prev_leaf(n) : next_leaf(n));
+    node_t *f = (dir == CYCLE_PREV ? prev_leaf(n) : next_leaf(n));
     if (f == NULL)
-        f = (dir == DIR_PREV ? second_extrema(d->root) : first_extrema(d->root));
+        f = (dir == CYCLE_PREV ? second_extrema(d->root) : first_extrema(d->root));
 
     while (f != n) {
         bool tiled = is_tiled(f->client);
-        if (skip == SKIP_NONE || (skip == SKIP_TILED && !tiled) || (skip == SKIP_FLOATING && tiled)) {
+        if (skip == SKIP_NONE || (skip == SKIP_TILED && !tiled) || (skip == SKIP_FLOATING && tiled)
+                || (skip == SKIP_CLASS_DIFFER && strcmp(f->client->class_name, n->client->class_name) == 0)
+                || (skip == SKIP_CLASS_EQUAL && strcmp(f->client->class_name, n->client->class_name) != 0)) {
             focus_node(d, f, true);
             return;
         }
-        f = (dir == DIR_PREV ? prev_leaf(f) : next_leaf(f));
+        f = (dir == CYCLE_PREV ? prev_leaf(f) : next_leaf(f));
         if (f == NULL)
-            f = (dir == DIR_PREV ? second_extrema(d->root) : first_extrema(d->root));
+            f = (dir == CYCLE_PREV ? second_extrema(d->root) : first_extrema(d->root));
     }
 }