]> git.lizzy.rs Git - bspwm.git/blobdiff - src/tree.c
Add automatic insertion scheme: alternate
[bspwm.git] / src / tree.c
index 14ee95cae68dbba4ea4eb83ecee29afacf0b5f48..bf5d3965f8e6ebe49f447d2dd496e769c10d79dc 100644 (file)
@@ -84,13 +84,6 @@ void apply_layout(monitor_t *m, desktop_t *d, node_t *n, layout_t l, xcb_rectang
 
        n->rectangle = rect;
 
-       if (pointer_follows_focus && mon->desk->focus == n) {
-               xcb_rectangle_t r = rect;
-               r.width -= d->window_gap;
-               r.height -= d->window_gap;
-               center_pointer(r);
-       }
-
        if (n->presel != NULL) {
                draw_presel_feedback(m, d, n);
        }
@@ -160,9 +153,6 @@ void apply_layout(monitor_t *m, desktop_t *d, node_t *n, layout_t l, xcb_rectang
                        first_rect = second_rect = rect;
                } else {
                        unsigned int fence;
-                       if (auto_split_type) {
-                               n->split_type = n->rectangle.width > n->rectangle.height ? TYPE_VERTICAL : TYPE_HORIZONTAL;
-                       }
                        if (n->split_type == TYPE_VERTICAL) {
                                fence = rect.width * n->split_ratio;
                                if ((n->first_child->constraints.min_width + n->second_child->constraints.min_width) <= rect.width) {
@@ -339,7 +329,8 @@ node_t *insert_node(monitor_t *m, desktop_t *d, node_t *n, node_t *f)
                }
                n->parent = c;
                if (f->presel == NULL) {
-                       if (p == NULL || automatic_scheme == SCHEME_LONGEST_SIDE || (f->client != NULL && IS_TILED(f->client) && tiled_count(d->root, true) == 1)) {
+                       bool single_tiled = f->client != NULL && IS_TILED(f->client) && tiled_count(d->root, true) == 1;
+                       if (p == NULL || automatic_scheme != SCHEME_SPIRAL || single_tiled) {
                                if (p != NULL) {
                                        if (is_first_child(f)) {
                                                p->first_child = c;
@@ -358,10 +349,18 @@ node_t *insert_node(monitor_t *m, desktop_t *d, node_t *n, node_t *f)
                                        c->first_child = f;
                                        c->second_child = n;
                                }
-                               if (f->rectangle.width > f->rectangle.height) {
-                                       c->split_type = TYPE_VERTICAL;
+                               if (p == NULL || automatic_scheme == SCHEME_LONGEST_SIDE || single_tiled) {
+                                       if (f->rectangle.width > f->rectangle.height) {
+                                               c->split_type = TYPE_VERTICAL;
+                                       } else {
+                                               c->split_type = TYPE_HORIZONTAL;
+                                       }
                                } else {
-                                       c->split_type = TYPE_HORIZONTAL;
+                                       if (p->split_type == TYPE_HORIZONTAL) {
+                                               c->split_type = TYPE_VERTICAL;
+                                       } else {
+                                               c->split_type = TYPE_HORIZONTAL;
+                                       }
                                }
                        } else {
                                node_t *g = p->parent;
@@ -493,21 +492,21 @@ bool activate_node(monitor_t *m, desktop_t *d, node_t *n)
        return true;
 }
 
-void transfer_sticky_nodes(monitor_t *m, desktop_t *ds, desktop_t *dd, node_t *n)
+void transfer_sticky_nodes(monitor_t *ms, desktop_t *ds, monitor_t *md, desktop_t *dd, node_t *n)
 {
        if (n == NULL) {
                return;
        } else if (n->sticky) {
                sticky_still = false;
-               transfer_node(m, ds, n, m, dd, dd->focus, false);
+               transfer_node(ms, ds, n, md, dd, dd->focus, false);
                sticky_still = true;
        } else {
                /* we need references to the children because n might be freed after
                 * the first recursive call */
                node_t *first_child = n->first_child;
                node_t *second_child = n->second_child;
-               transfer_sticky_nodes(m, ds, dd, first_child);
-               transfer_sticky_nodes(m, ds, dd, second_child);
+               transfer_sticky_nodes(ms, ds, md, dd, first_child);
+               transfer_sticky_nodes(ms, ds, md, dd, second_child);
        }
 }
 
@@ -561,12 +560,12 @@ bool focus_node(monitor_t *m, desktop_t *d, node_t *n)
                clear_input_focus();
        }
 
-       if (m->sticky_count > 0 && d != m->desk) {
+       if (m->sticky_count > 0 && m->desk != NULL && d != m->desk) {
                if (guess && m->desk->focus != NULL && m->desk->focus->sticky) {
                        n = m->desk->focus;
                }
 
-               transfer_sticky_nodes(m, m->desk, d, m->desk->root);
+               transfer_sticky_nodes(m, m->desk, m, d, m->desk->root);
 
                if (n == NULL && d->focus != NULL) {
                        n = d->focus;
@@ -636,7 +635,7 @@ bool focus_node(monitor_t *m, desktop_t *d, node_t *n)
 
 void hide_node(desktop_t *d, node_t *n)
 {
-       if (n == NULL) {
+       if (n == NULL || (!hide_sticky && n->sticky)) {
                return;
        } else {
                if (!n->hidden) {
@@ -1211,6 +1210,24 @@ void unlink_node(monitor_t *m, desktop_t *d, node_t *n)
                        d->root = b;
                }
 
+               if (!n->vacant && removal_adjustment) {
+                       if (automatic_scheme == SCHEME_LONGEST_SIDE || g == NULL) {
+                               if (p != NULL) {
+                                       if (p->rectangle.width > p->rectangle.height) {
+                                               b->split_type = TYPE_VERTICAL;
+                                       } else {
+                                               b->split_type = TYPE_HORIZONTAL;
+                                       }
+                               }
+                       } else if (automatic_scheme == SCHEME_ALTERNATE) {
+                               if (g->split_type == TYPE_HORIZONTAL) {
+                                       b->split_type = TYPE_VERTICAL;
+                               } else {
+                                       b->split_type = TYPE_HORIZONTAL;
+                               }
+                       }
+               }
+
                free(p);
                n->parent = NULL;
 
@@ -1446,11 +1463,6 @@ bool transfer_node(monitor_t *ms, desktop_t *ds, node_t *ns, monitor_t *md, desk
                if (ns->client == NULL || monitor_from_client(ns->client) != md) {
                        adapt_geometry(&ms->rectangle, &md->rectangle, ns);
                }
-
-               if (ms->sticky_count > 0 && sticky_count(ns) > 0) {
-                       ms->sticky_count -= sticky_count(ns);
-                       md->sticky_count += sticky_count(ns);
-               }
        }
 
        if (ds != dd) {
@@ -1996,13 +2008,6 @@ void set_urgent(monitor_t *m, desktop_t *d, node_t *n, bool value)
        put_status(SBSC_MASK_REPORT);
 }
 
-/* Returns true if a contains b */
-bool contains(xcb_rectangle_t a, xcb_rectangle_t b)
-{
-       return (a.x <= b.x && (a.x + a.width) >= (b.x + b.width) &&
-               a.y <= b.y && (a.y + a.height) >= (b.y + b.height));
-}
-
 xcb_rectangle_t get_rectangle(monitor_t *m, desktop_t *d, node_t *n)
 {
        if (n == NULL) {