]> git.lizzy.rs Git - bspwm.git/blobdiff - src/tree.c
bspwm: port rounded corners patch to latest version
[bspwm.git] / src / tree.c
index 728f72d9cfe086b14265f6111caea12085266c96..c3f84703b0e27db35656d3f1b80123a67d8f77ab 100644 (file)
@@ -83,13 +83,16 @@ void apply_layout(monitor_t *m, desktop_t *d, node_t *n, xcb_rectangle_t rect, x
        }
 
        if (is_leaf(n)) {
+        unsigned int br = 0;
 
                if (n->client == NULL) {
                        return;
                }
 
                unsigned int bw;
+               bool the_only_window = !m->prev && !m->next && d->root->client;
                if ((borderless_monocle && d->layout == LAYOUT_MONOCLE && IS_TILED(n->client))
+                   || (borderless_singleton && the_only_window)
                    || n->client->state == STATE_FULLSCREEN) {
                        bw = 0;
                } else {
@@ -117,9 +120,12 @@ void apply_layout(monitor_t *m, desktop_t *d, node_t *n, xcb_rectangle_t rect, x
                                }
                        }
                        n->client->tiled_rectangle = r;
+            if (!gapless_monocle || 1 != LAYOUT_MONOCLE)
+                br = n->client->border_radius;
                /* floating clients */
                } else if (s == STATE_FLOATING) {
                        r = n->client->floating_rectangle;
+            br = n->client->border_radius;
                /* fullscreen clients */
                } else {
                        r = m->rectangle;
@@ -130,12 +136,15 @@ void apply_layout(monitor_t *m, desktop_t *d, node_t *n, xcb_rectangle_t rect, x
 
                if (!rect_eq(r, cr)) {
                        window_move_resize(n->id, r.x, r.y, r.width, r.height);
+            window_rounded_border(n);
                        if (!grabbing) {
                                put_status(SBSC_MASK_NODE_GEOMETRY, "node_geometry 0x%08X 0x%08X 0x%08X %ux%u+%i+%i\n", m->id, d->id, n->id, r.width, r.height, r.x, r.y);
                        }
                }
 
                window_border_width(n->id, bw);
+        window_border_radius(n->client, br);
+        window_rounded_border(n);
 
        } else {
                xcb_rectangle_t first_rect;
@@ -188,6 +197,17 @@ presel_t *make_presel(void)
        return p;
 }
 
+void set_type(node_t *n, split_type_t typ)
+{
+       if (n == NULL) {
+               return;
+       }
+
+       n->split_type = typ;
+       update_constraints(n);
+       rebuild_constraints_towards_root(n);
+}
+
 void set_ratio(node_t *n, double rat)
 {
        if (n == NULL) {
@@ -444,6 +464,7 @@ void insert_receptacle(monitor_t *m, desktop_t *d, node_t *n)
 {
        node_t *r = make_node(XCB_NONE);
        insert_node(m, d, r, n);
+       put_status(SBSC_MASK_NODE_ADD, "node_add 0x%08X 0x%08X 0x%08X 0x%08X\n", m->id, d->id, n != NULL ? n->id : 0, r->id);
 
        if (single_monocle && d->layout == LAYOUT_MONOCLE && tiled_count(d->root, true) > 1) {
                set_layout(m, d, d->user_layout, false);
@@ -607,9 +628,36 @@ bool focus_node(monitor_t *m, desktop_t *d, node_t *n)
 
        draw_border(n, true, true);
 
-       focus_desktop(m, d);
+       bool desk_changed = (m != mon || m->desk != d);
+       bool has_input_focus = false;
+
+       if (mon != m) {
+               mon = m;
+
+               if (pointer_follows_monitor) {
+                       center_pointer(m->rectangle);
+               }
+
+               put_status(SBSC_MASK_MONITOR_FOCUS, "monitor_focus 0x%08X\n", m->id);
+       }
+
+       if (m->desk != d) {
+               show_desktop(d);
+               set_input_focus(n);
+               has_input_focus = true;
+               hide_desktop(m->desk);
+               m->desk = d;
+       }
+
+       if (desk_changed) {
+               ewmh_update_current_desktop();
+               put_status(SBSC_MASK_DESKTOP_FOCUS, "desktop_focus 0x%08X 0x%08X\n", m->id, d->id);
+       }
 
        d->focus = n;
+       if (!has_input_focus) {
+               set_input_focus(n);
+       }
        ewmh_update_active_window();
        history_add(m, d, n, true);
 
@@ -625,7 +673,6 @@ bool focus_node(monitor_t *m, desktop_t *d, node_t *n)
        put_status(SBSC_MASK_NODE_FOCUS, "node_focus 0x%08X 0x%08X 0x%08X\n", m->id, d->id, n->id);
 
        stack(d, n, true);
-       set_input_focus(n);
 
        if (pointer_follows_focus) {
                center_pointer(get_rectangle(m, d, n));
@@ -703,8 +750,10 @@ client_t *make_client(void)
        snprintf(c->class_name, sizeof(c->class_name), "%s", MISSING_VALUE);
        snprintf(c->instance_name, sizeof(c->instance_name), "%s", MISSING_VALUE);
        c->border_width = border_width;
+       c->border_radius = border_radius;
        c->urgent = false;
        c->shown = false;
+    c->sets_own_shape = false;
        c->wm_flags = 0;
        c->icccm_props.input_hint = true;
        c->icccm_props.take_focus = false;
@@ -839,6 +888,48 @@ node_t *first_focusable_leaf(node_t *n)
        return NULL;
 }
 
+node_t *next_node(node_t *n)
+{
+       if (n == NULL) {
+               return NULL;
+       }
+
+       if (n->second_child != NULL) {
+               return first_extrema(n->second_child);
+       } else {
+               node_t *p = n;
+               while (is_second_child(p)) {
+                       p = p->parent;
+               }
+               if (is_first_child(p)) {
+                       return p->parent;
+               } else {
+                       return NULL;
+               }
+       }
+}
+
+node_t *prev_node(node_t *n)
+{
+       if (n == NULL) {
+               return NULL;
+       }
+
+       if (n->first_child != NULL) {
+               return second_extrema(n->first_child);
+       } else {
+               node_t *p = n;
+               while (is_first_child(p)) {
+                       p = p->parent;
+               }
+               if (is_second_child(p)) {
+                       return p->parent;
+               } else {
+                       return NULL;
+               }
+       }
+}
+
 node_t *next_leaf(node_t *n, node_t *r)
 {
        if (n == NULL) {
@@ -1095,7 +1186,7 @@ void find_by_area(area_peak_t ap, coordinates_t *ref, coordinates_t *dst, node_s
                for (desktop_t *d = m->desk_head; d != NULL; d = d->next) {
                        for (node_t *f = first_extrema(d->root); f != NULL; f = next_leaf(f, d->root)) {
                                coordinates_t loc = {m, d, f};
-                               if (f->client == NULL || f->vacant || !node_matches(&loc, ref, sel)) {
+                               if (f->vacant || !node_matches(&loc, ref, sel)) {
                                        continue;
                                }
                                unsigned int f_area = node_area(d, f);
@@ -1111,7 +1202,8 @@ void find_by_area(area_peak_t ap, coordinates_t *ref, coordinates_t *dst, node_s
 void rotate_tree(node_t *n, int deg)
 {
        rotate_tree_rec(n, deg);
-       rebuild_constraints(n);
+       rebuild_constraints_from_leaves(n);
+       rebuild_constraints_towards_root(n);
 }
 
 void rotate_tree_rec(node_t *n, int deg)
@@ -1249,6 +1341,7 @@ void unlink_node(monitor_t *m, desktop_t *d, node_t *n)
 
                history_remove(d, p, false);
                cancel_presel(m, d, p);
+
                if (p->sticky) {
                        m->sticky_count--;
                }
@@ -1321,13 +1414,16 @@ void kill_node(monitor_t *m, desktop_t *d, node_t *n)
                return;
        }
 
-       for (node_t *f = first_extrema(n); f != NULL; f = next_leaf(f, n)) {
-               if (f->client != NULL) {
-                       xcb_kill_client(dpy, f->id);
+       if (IS_RECEPTACLE(n)) {
+               put_status(SBSC_MASK_NODE_REMOVE, "node_remove 0x%08X 0x%08X 0x%08X\n", m->id, d->id, n->id);
+               remove_node(m, d, n);
+       } else {
+               for (node_t *f = first_extrema(n); f != NULL; f = next_leaf(f, n)) {
+                       if (f->client != NULL) {
+                               xcb_kill_client(dpy, f->id);
+                       }
                }
        }
-
-       remove_node(m, d, n);
 }
 
 void remove_node(monitor_t *m, desktop_t *d, node_t *n)
@@ -1340,7 +1436,7 @@ void remove_node(monitor_t *m, desktop_t *d, node_t *n)
        history_remove(d, n, true);
        remove_stack_node(n);
        cancel_presel_in(m, d, n);
-       if (m->sticky_count > 0) {
+       if (m->sticky_count > 0 && d == m->desk) {
                m->sticky_count -= sticky_count(n);
        }
        clients_count -= clients_count_in(n);
@@ -1497,14 +1593,22 @@ bool swap_nodes(monitor_t *m1, desktop_t *d1, node_t *n1, monitor_t *m2, desktop
                        draw_border(n1, is_descendant(n1, d2->focus), (m2 == mon));
                }
        } else {
-               draw_border(n1, is_descendant(n1, d2->focus), (m2 == mon));
-               draw_border(n2, is_descendant(n2, d1->focus), (m1 == mon));
+               if (!n1_held_focus) {
+                       draw_border(n1, is_descendant(n1, d2->focus), (m2 == mon));
+               }
+               if (!n2_held_focus) {
+                       draw_border(n2, is_descendant(n2, d1->focus), (m1 == mon));
+               }
        }
 
        arrange(m1, d1);
 
        if (d1 != d2) {
                arrange(m2, d2);
+       } else {
+               if (pointer_follows_focus && (n1_held_focus || n2_held_focus)) {
+                       center_pointer(get_rectangle(m1, d1, d1->focus));
+               }
        }
 
        return true;
@@ -1516,7 +1620,8 @@ bool transfer_node(monitor_t *ms, desktop_t *ds, node_t *ns, monitor_t *md, desk
                return false;
        }
 
-       if (sticky_still && ms->sticky_count > 0 && sticky_count(ns) > 0 && dd != md->desk) {
+       unsigned int sc = (ms->sticky_count > 0 && ds == ms->desk) ? sticky_count(ns) : 0;
+       if (sticky_still && sc > 0 && dd != md->desk) {
                return false;
        }
 
@@ -1538,6 +1643,8 @@ 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);
                }
+               ms->sticky_count -= sc;
+               md->sticky_count += sc;
        }
 
        if (ds != dd) {
@@ -1614,7 +1721,7 @@ bool find_closest_node(coordinates_t *ref, coordinates_t *dst, cycle_dir_t dir,
        monitor_t *m = ref->monitor;
        desktop_t *d = ref->desktop;
        node_t *n = ref->node;
-       n = (dir == CYCLE_PREV ? prev_leaf(n, d->root) : next_leaf(n, d->root));
+       n = (dir == CYCLE_PREV ? prev_node(n) : next_node(n));
 
 #define HANDLE_BOUNDARIES(m, d, n)  \
        while (n == NULL) { \
@@ -1635,11 +1742,11 @@ bool find_closest_node(coordinates_t *ref, coordinates_t *dst, cycle_dir_t dir,
 
        while (n != ref->node) {
                coordinates_t loc = {m, d, n};
-               if (n->client != NULL && !n->hidden && node_matches(&loc, ref, sel)) {
+               if (node_matches(&loc, ref, sel)) {
                        *dst = loc;
                        return true;
                }
-               n = (dir == CYCLE_PREV ? prev_leaf(n, d->root) : next_leaf(n, d->root));
+               n = (dir == CYCLE_PREV ? prev_node(n) : next_node(n));
                HANDLE_BOUNDARIES(m, d, n);
                if (ref->node == NULL && d == ref->desktop) {
                        break;
@@ -1830,7 +1937,9 @@ void set_floating(monitor_t *m, desktop_t *d, node_t *n, bool value)
        }
 
        cancel_presel(m, d, n);
-       set_vacant(m, d, n, value);
+       if (!n->hidden) {
+               set_vacant(m, d, n, value);
+       }
 
        if (!value && d->focus == n) {
                neutralize_occluding_windows(m, d, n);
@@ -1848,7 +1957,9 @@ void set_fullscreen(monitor_t *m, desktop_t *d, node_t *n, bool value)
        client_t *c = n->client;
 
        cancel_presel(m, d, n);
-       set_vacant(m, d, n, value);
+       if (!n->hidden) {
+               set_vacant(m, d, n, value);
+       }
 
        if (value) {
                c->wm_flags |= WM_FLAG_FULLSCREEN;
@@ -1880,17 +1991,32 @@ void neutralize_occluding_windows(monitor_t *m, desktop_t *d, node_t *n)
        }
 }
 
-void rebuild_constraints(node_t *n)
+void rebuild_constraints_from_leaves(node_t *n)
 {
        if (n == NULL || is_leaf(n)) {
                return;
        } else {
-               rebuild_constraints(n->first_child);
-               rebuild_constraints(n->second_child);
+               rebuild_constraints_from_leaves(n->first_child);
+               rebuild_constraints_from_leaves(n->second_child);
                update_constraints(n);
        }
 }
 
+void rebuild_constraints_towards_root(node_t *n)
+{
+       if (n == NULL) {
+               return;
+       }
+
+       node_t *p = n->parent;
+
+       if (p != NULL) {
+               update_constraints(p);
+       }
+
+       rebuild_constraints_towards_root(p);
+}
+
 void update_constraints(node_t *n)
 {
        if (n == NULL || is_leaf(n)) {