]> git.lizzy.rs Git - bspwm.git/blobdiff - tree.c
Don't try to print pointers as strings
[bspwm.git] / tree.c
diff --git a/tree.c b/tree.c
index 74b641e77c5168c5619061e8a8e6503087b61a46..f30343678bbfdbdd3eee5a525c4794d8c651e490 100644 (file)
--- a/tree.c
+++ b/tree.c
@@ -33,6 +33,7 @@
 #include "history.h"
 #include "monitor.h"
 #include "query.h"
+#include "geometry.h"
 #include "subscribe.h"
 #include "settings.h"
 #include "stack.h"
@@ -45,22 +46,31 @@ void arrange(monitor_t *m, desktop_t *d)
                return;
        }
 
-       layout_t set_layout = d->layout;
+       layout_t last_layout = d->layout;
 
        if (single_monocle && tiled_count(d->root) == 1) {
                d->layout = LAYOUT_MONOCLE;
        }
 
        xcb_rectangle_t rect = m->rectangle;
-       int wg = (gapless_monocle && d->layout == LAYOUT_MONOCLE ? 0 : d->window_gap);
-       rect.x += m->left_padding + d->left_padding + wg;
-       rect.y += m->top_padding + d->top_padding + wg;
-       rect.width -= m->left_padding + d->left_padding + d->right_padding + m->right_padding + wg;
-       rect.height -= m->top_padding + d->top_padding + d->bottom_padding + m->bottom_padding + wg;
+
+       if (!paddingless_monocle || d->layout != LAYOUT_MONOCLE) {
+               rect.x += m->left_padding + d->left_padding;
+               rect.y += m->top_padding + d->top_padding;
+               rect.width -= m->left_padding + d->left_padding + d->right_padding + m->right_padding;
+               rect.height -= m->top_padding + d->top_padding + d->bottom_padding + m->bottom_padding;
+       }
+
+       if (!gapless_monocle || d->layout != LAYOUT_MONOCLE) {
+               rect.x += d->window_gap;
+               rect.y += d->window_gap;
+               rect.width -= d->window_gap;
+               rect.height -= d->window_gap;
+       }
 
        apply_layout(m, d, d->root, rect, rect);
 
-       d->layout = set_layout;
+       d->layout = last_layout;
 }
 
 void apply_layout(monitor_t *m, desktop_t *d, node_t *n, xcb_rectangle_t rect, xcb_rectangle_t root_rect)
@@ -93,6 +103,7 @@ void apply_layout(monitor_t *m, desktop_t *d, node_t *n, xcb_rectangle_t rect, x
                }
 
                xcb_rectangle_t r;
+               xcb_rectangle_t cr = get_rectangle(d, n);
                client_state_t s = n->client->state;
                if (s == STATE_TILED || s == STATE_PSEUDO_TILED) {
                        int wg = (gapless_monocle && d->layout == LAYOUT_MONOCLE ? 0 : d->window_gap);
@@ -122,12 +133,15 @@ void apply_layout(monitor_t *m, desktop_t *d, node_t *n, xcb_rectangle_t rect, x
                        r = m->rectangle;
                }
 
-               window_move_resize(n->id, r.x, r.y, r.width, r.height);
+               if (!rect_eq(r, cr)) {
+                       window_move_resize(n->id, r.x, r.y, r.width, r.height);
+                       if (frozen_pointer->action == ACTION_NONE) {
+                               put_status(SBSC_MASK_NODE_GEOMETRY, "node_geometry %s %s 0x%X %ux%u+%i+%i\n", m->name, d->name, n->id, r.width, r.height, r.x, r.y);
+                       }
+               }
+
                window_border_width(n->id, bw);
 
-               if (frozen_pointer->action == ACTION_NONE) {
-                       put_status(SBSC_MASK_NODE_GEOMETRY, "node_geometry %s %s 0x%X %ux%u+%i+%i\n", m->name, d->name, n->id, r.width, r.height, r.x, r.y);
-               }
        } else {
                xcb_rectangle_t first_rect;
                xcb_rectangle_t second_rect;
@@ -209,7 +223,7 @@ node_t *find_public(desktop_t *d)
                if (n->vacant) {
                        continue;
                }
-               unsigned int n_area = node_area(NULL, d, n);
+               unsigned int n_area = node_area(d, n);
                if (n_area > b_manual_area && (n->presel != NULL || !n->private)) {
                        b_manual = n;
                        b_manual_area = n_area;
@@ -255,7 +269,7 @@ node_t *insert_node(monitor_t *m, desktop_t *d, node_t *n, node_t *f)
                                p = f->parent;
                        }
                        if (f->presel == NULL && (f->private || private_count(f->parent) > 0)) {
-                               xcb_rectangle_t rect = get_rectangle(m, d, f);
+                               xcb_rectangle_t rect = get_rectangle(d, f);
                                presel_dir(m, d, f, (rect.width >= rect.height ? DIR_EAST : DIR_SOUTH));
                        }
                }
@@ -488,7 +502,7 @@ void focus_node(monitor_t *m, desktop_t *d, node_t *n)
        }
 
        if (pointer_follows_focus) {
-               center_pointer(get_rectangle(m, d, n));
+               center_pointer(get_rectangle(d, n));
        }
 }
 
@@ -907,10 +921,10 @@ node_t *nearest_from_distance(monitor_t *m, desktop_t *d, node_t *n, direction_t
        }
 
        node_t *nearest = NULL;
-       direction_t dir2;
+       direction_t dir2 = DIR_NORTH;
        xcb_point_t pt;
        xcb_point_t pt2;
-       get_side_handle(m, d, n, dir, &pt);
+       get_side_handle(d, n, dir, &pt);
        get_opposite(dir, &dir2);
        double ds = DBL_MAX;
        coordinates_t ref = {m, d, n};
@@ -924,7 +938,7 @@ node_t *nearest_from_distance(monitor_t *m, desktop_t *d, node_t *n, direction_t
                        continue;
                }
 
-               get_side_handle(m, d, a, dir2, &pt2);
+               get_side_handle(d, a, dir2, &pt2);
                double ds2 = distance(pt, pt2);
                if (ds2 < ds) {
                        ds = ds2;
@@ -953,13 +967,12 @@ void get_opposite(direction_t src, direction_t *dst)
        }
 }
 
-unsigned int node_area(monitor_t *m, desktop_t *d, node_t *n)
+unsigned int node_area(desktop_t *d, node_t *n)
 {
        if (n == NULL) {
                return 0;
        }
-       xcb_rectangle_t rect = get_rectangle(m, d, n);
-       return rect.width * rect.height;
+       return area(get_rectangle(d, n));
 }
 
 int tiled_count(node_t *n)
@@ -991,7 +1004,7 @@ node_t *find_biggest(monitor_t *m, desktop_t *d, node_t *n, node_select_t sel)
                if (f->vacant || !node_matches(&loc, &ref, sel)) {
                        continue;
                }
-               unsigned int f_area = node_area(m, d, f);
+               unsigned int f_area = node_area(d, f);
                if (f_area > b_area) {
                        b = f;
                        b_area = f_area;
@@ -1165,6 +1178,7 @@ void remove_node(monitor_t *m, desktop_t *d, node_t *n)
        free(n);
 
        ewmh_update_client_list(false);
+       ewmh_update_client_list(true);
 
        if (d->focus != last_focus) {
                if (d == mon->desk) {
@@ -1671,23 +1685,18 @@ bool contains(xcb_rectangle_t a, xcb_rectangle_t b)
                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)
+xcb_rectangle_t get_rectangle(desktop_t *d, node_t *n)
 {
        client_t *c = n->client;
        if (c != NULL) {
-               switch (c->state) {
-                       case STATE_TILED:
-                       case STATE_PSEUDO_TILED:
-                               return c->tiled_rectangle;
-                               break;
-                       case STATE_FLOATING:
-                               return c->floating_rectangle;
-                               break;
-                       case STATE_FULLSCREEN:
-                       default:
-                               return m != NULL ? m->rectangle : (xcb_rectangle_t) {0, 0, screen_width, screen_height};
-                               break;
-                }
+               xcb_get_geometry_reply_t *g = xcb_get_geometry_reply(dpy, xcb_get_geometry(dpy, n->id), NULL);
+               if (g != NULL) {
+                       xcb_rectangle_t rect = (xcb_rectangle_t) {g->x, g->y, g->width, g->height};
+                       free(g);
+                       return rect;
+               } else {
+                       return (xcb_rectangle_t) {0, 0, screen_width, screen_height};
+               }
        } else {
                int wg = (d == NULL ? 0 : (gapless_monocle && d->layout == LAYOUT_MONOCLE ? 0 : d->window_gap));
                xcb_rectangle_t rect = n->rectangle;
@@ -1697,9 +1706,9 @@ xcb_rectangle_t get_rectangle(monitor_t *m, desktop_t *d, node_t *n)
        }
 }
 
-void get_side_handle(monitor_t *m, desktop_t *d, node_t *n, direction_t dir, xcb_point_t *pt)
+void get_side_handle(desktop_t *d, node_t *n, direction_t dir, xcb_point_t *pt)
 {
-       xcb_rectangle_t rect = get_rectangle(m, d, n);
+       xcb_rectangle_t rect = get_rectangle(d, n);
 
        switch (dir) {
                case DIR_EAST: