1 /* Copyright (c) 2012, Bastien Dejean
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
7 * 1. Redistributions of source code must retain the above copyright notice, this
8 * list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright notice,
10 * this list of conditions and the following disclaimer in the documentation
11 * and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
17 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
20 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 #include "subscribe.h"
42 void arrange(monitor_t *m, desktop_t *d)
44 if (d->root == NULL) {
48 layout_t l = d->layout;
50 if (single_monocle && tiled_count(d->root) <= 1) {
54 xcb_rectangle_t rect = m->rectangle;
56 if (!paddingless_monocle || l != LAYOUT_MONOCLE) {
57 rect.x += m->padding.left + d->padding.left;
58 rect.y += m->padding.top + d->padding.top;
59 rect.width -= m->padding.left + d->padding.left + d->padding.right + m->padding.right;
60 rect.height -= m->padding.top + d->padding.top + d->padding.bottom + m->padding.bottom;
63 if (!gapless_monocle || l != LAYOUT_MONOCLE) {
64 rect.x += d->window_gap;
65 rect.y += d->window_gap;
66 rect.width -= d->window_gap;
67 rect.height -= d->window_gap;
70 apply_layout(m, d, d->root, l, rect, rect);
73 void apply_layout(monitor_t *m, desktop_t *d, node_t *n, layout_t l, xcb_rectangle_t rect, xcb_rectangle_t root_rect)
81 if (pointer_follows_focus && mon->desk->focus == n) {
82 xcb_rectangle_t r = rect;
83 r.width -= d->window_gap;
84 r.height -= d->window_gap;
88 if (n->presel != NULL) {
89 draw_presel_feedback(m, d, n);
94 if (n->client == NULL) {
99 if ((borderless_monocle && l == LAYOUT_MONOCLE && IS_TILED(n->client))
100 || n->client->state == STATE_FULLSCREEN) {
103 bw = n->client->border_width;
107 xcb_rectangle_t cr = get_window_rectangle(n);
108 client_state_t s = n->client->state;
109 if (s == STATE_TILED || s == STATE_PSEUDO_TILED) {
110 int wg = (gapless_monocle && l == LAYOUT_MONOCLE ? 0 : d->window_gap);
112 if (s == STATE_TILED) {
114 int bleed = wg + 2 * bw;
115 r.width = (bleed < r.width ? r.width - bleed : 1);
116 r.height = (bleed < r.height ? r.height - bleed : 1);
117 /* pseudo-tiled clients */
119 r = n->client->floating_rectangle;
120 if (center_pseudo_tiled) {
121 r.x = rect.x - bw + (rect.width - wg - r.width) / 2;
122 r.y = rect.y - bw + (rect.height - wg - r.height) / 2;
128 n->client->tiled_rectangle = r;
129 /* floating clients */
130 } else if (s == STATE_FLOATING) {
131 r = n->client->floating_rectangle;
132 /* fullscreen clients */
135 n->client->tiled_rectangle = r;
138 apply_size_hints(n->client, &r.width, &r.height);
140 if (!rect_eq(r, cr)) {
141 window_move_resize(n->id, r.x, r.y, r.width, r.height);
143 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);
147 window_border_width(n->id, bw);
150 xcb_rectangle_t first_rect;
151 xcb_rectangle_t second_rect;
153 if (l == LAYOUT_MONOCLE || n->first_child->vacant || n->second_child->vacant) {
154 first_rect = second_rect = rect;
157 if (n->split_type == TYPE_VERTICAL) {
158 fence = rect.width * n->split_ratio;
159 if ((n->first_child->constraints.min_width + n->second_child->constraints.min_width) <= rect.width) {
160 if (fence < n->first_child->constraints.min_width) {
161 fence = n->first_child->constraints.min_width;
162 n->split_ratio = (double) fence / (double) rect.width;
163 } else if (fence > (uint16_t) (rect.width - n->second_child->constraints.min_width)) {
164 fence = (rect.width - n->second_child->constraints.min_width);
165 n->split_ratio = (double) fence / (double) rect.width;
168 first_rect = (xcb_rectangle_t) {rect.x, rect.y, fence, rect.height};
169 second_rect = (xcb_rectangle_t) {rect.x + fence, rect.y, rect.width - fence, rect.height};
171 fence = rect.height * n->split_ratio;
172 if ((n->first_child->constraints.min_height + n->second_child->constraints.min_height) <= rect.height) {
173 if (fence < n->first_child->constraints.min_height) {
174 fence = n->first_child->constraints.min_height;
175 n->split_ratio = (double) fence / (double) rect.height;
176 } else if (fence > (uint16_t) (rect.height - n->second_child->constraints.min_height)) {
177 fence = (rect.height - n->second_child->constraints.min_height);
178 n->split_ratio = (double) fence / (double) rect.height;
181 first_rect = (xcb_rectangle_t) {rect.x, rect.y, rect.width, fence};
182 second_rect = (xcb_rectangle_t) {rect.x, rect.y + fence, rect.width, rect.height - fence};
186 apply_layout(m, d, n->first_child, l, first_rect, root_rect);
187 apply_layout(m, d, n->second_child, l, second_rect, root_rect);
191 presel_t *make_presel(void)
193 presel_t *p = calloc(1, sizeof(presel_t));
194 p->split_dir = DIR_EAST;
195 p->split_ratio = split_ratio;
196 p->feedback = XCB_NONE;
200 void set_ratio(node_t *n, double rat)
206 n->split_ratio = rat;
209 void presel_dir(monitor_t *m, desktop_t *d, node_t *n, direction_t dir)
211 if (n->presel == NULL) {
212 n->presel = make_presel();
215 n->presel->split_dir = dir;
217 put_status(SBSC_MASK_NODE_PRESEL, "node_presel 0x%08X 0x%08X 0x%08X dir %s\n", m->id, d->id, n->id, SPLIT_DIR_STR(dir));
220 void presel_ratio(monitor_t *m, desktop_t *d, node_t *n, double ratio)
222 if (n->presel == NULL) {
223 n->presel = make_presel();
226 n->presel->split_ratio = ratio;
228 put_status(SBSC_MASK_NODE_PRESEL, "node_presel 0x%08X 0x%08X 0x%08X ratio %lf\n", m->id, d->id, n->id, ratio);
231 void cancel_presel(monitor_t *m, desktop_t *d, node_t *n)
233 if (n->presel == NULL) {
237 if (n->presel->feedback != XCB_NONE) {
238 xcb_destroy_window(dpy, n->presel->feedback);
244 put_status(SBSC_MASK_NODE_PRESEL, "node_presel 0x%08X 0x%08X 0x%08X cancel\n", m->id, d->id, n->id);
247 void cancel_presel_in(monitor_t *m, desktop_t *d, node_t *n)
252 cancel_presel(m, d, n);
253 cancel_presel_in(m, d, n->first_child);
254 cancel_presel_in(m, d, n->second_child);
257 node_t *find_public(desktop_t *d)
259 unsigned int b_manual_area = 0;
260 unsigned int b_automatic_area = 0;
261 node_t *b_manual = NULL;
262 node_t *b_automatic = NULL;
263 for (node_t *n = first_extrema(d->root); n != NULL; n = next_leaf(n, d->root)) {
267 unsigned int n_area = node_area(d, n);
268 if (n_area > b_manual_area && (n->presel != NULL || !n->private)) {
270 b_manual_area = n_area;
272 if (n_area > b_automatic_area &&
273 n->presel == NULL && !n->private && private_count(n->parent) == 0) {
275 b_automatic_area = n_area;
278 if (b_automatic != NULL) {
285 node_t *insert_node(monitor_t *m, desktop_t *d, node_t *n, node_t *f)
287 if (d == NULL || n == NULL) {
291 /* n: inserted node */
292 /* c: new internal node */
293 /* f: focus or insertion anchor */
294 /* p: parent of focus */
295 /* g: grand parent of focus */
303 } else if (IS_RECEPTACLE(f) && f->presel == NULL) {
304 node_t *p = f->parent;
306 if (is_first_child(f)) {
318 node_t *c = make_node(XCB_NONE);
319 node_t *p = f->parent;
320 if (f->presel == NULL && (f->private || private_count(f->parent) > 0)) {
321 node_t *k = find_public(d);
326 if (f->presel == NULL && (f->private || private_count(f->parent) > 0)) {
327 xcb_rectangle_t rect = get_rectangle(m, d, f);
328 presel_dir(m, d, f, (rect.width >= rect.height ? DIR_EAST : DIR_SOUTH));
331 if (f->presel == NULL && p != NULL && p->vacant) {
336 c->birth_rotation = f->birth_rotation;
337 if (f->presel == NULL) {
339 if (initial_polarity == FIRST_CHILD) {
346 if (m->rectangle.width > m->rectangle.height) {
347 c->split_type = TYPE_VERTICAL;
349 c->split_type = TYPE_HORIZONTAL;
354 node_t *g = p->parent;
357 if (is_first_child(p)) {
365 c->split_type = p->split_type;
366 c->split_ratio = p->split_ratio;
369 if (is_first_child(f)) {
378 n->birth_rotation = rot;
385 if (is_first_child(f)) {
391 c->split_ratio = f->presel->split_ratio;
394 f->birth_rotation = 0;
395 switch (f->presel->split_dir) {
397 c->split_type = TYPE_VERTICAL;
402 c->split_type = TYPE_VERTICAL;
407 c->split_type = TYPE_HORIZONTAL;
412 c->split_type = TYPE_HORIZONTAL;
420 cancel_presel(m, d, f);
424 propagate_flags_upward(m, d, n);
426 if (d->focus == NULL && is_focusable(n)) {
433 void insert_receptacle(monitor_t *m, desktop_t *d, node_t *n)
435 node_t *r = make_node(XCB_NONE);
436 insert_node(m, d, r, n);
439 bool activate_node(monitor_t *m, desktop_t *d, node_t *n)
441 if (n == NULL && d->root != NULL) {
442 n = history_last_node(d, NULL);
444 n = first_focusable_leaf(d->root);
448 if (d == mon->desk || (n != NULL && !is_focusable(n))) {
453 if (d->focus != NULL && n != d->focus) {
454 neutralize_occluding_windows(m, d, n);
458 for (node_t *f = first_extrema(d->focus); f != NULL; f = next_leaf(f, d->focus)) {
459 if (f->client != NULL && !is_descendant(f, n)) {
460 window_draw_border(f->id, get_border_color(false, (m == mon)));
464 draw_border(n, true, (m == mon));
468 history_add(m, d, n);
470 put_status(SBSC_MASK_REPORT);
476 put_status(SBSC_MASK_NODE_ACTIVATE, "node_activate 0x%08X 0x%08X 0x%08X\n", m->id, d->id, n->id);
481 void transfer_sticky_nodes(monitor_t *m, desktop_t *ds, desktop_t *dd, node_t *n)
485 } else if (n->sticky) {
486 transfer_node(m, ds, n, m, dd, dd->focus, false);
488 /* we need references to the children because n might be freed after
489 * the first recursive call */
490 node_t *first_child = n->first_child;
491 node_t *second_child = n->second_child;
492 transfer_sticky_nodes(m, ds, dd, first_child);
493 transfer_sticky_nodes(m, ds, dd, second_child);
497 bool focus_node(monitor_t *m, desktop_t *d, node_t *n)
500 m = history_last_monitor(NULL);
511 d = history_last_desktop(m, NULL);
521 if (n == NULL && d->root != NULL) {
522 n = history_last_node(d, NULL);
524 n = first_focusable_leaf(d->root);
528 if (n != NULL && !is_focusable(n)) {
532 if ((mon != NULL && mon->desk != d) || n == NULL || n->client == NULL) {
536 if (m->sticky_count > 0 && d != m->desk) {
537 sticky_still = false;
538 transfer_sticky_nodes(m, m->desk, d, m->desk->root);
540 if (n == NULL && d->focus != NULL) {
545 if (d->focus != NULL && n != d->focus) {
546 neutralize_occluding_windows(m, d, n);
549 if (n != NULL && n->client != NULL && n->client->urgent) {
550 set_urgent(m, d, n, false);
555 for (desktop_t *e = mon->desk_head; e != NULL; e = e->next) {
556 draw_border(e->focus, true, false);
559 for (desktop_t *e = m->desk_head; e != NULL; e = e->next) {
563 draw_border(e->focus, true, true);
568 for (node_t *f = first_extrema(d->focus); f != NULL; f = next_leaf(f, d->focus)) {
569 if (f->client != NULL && !is_descendant(f, n)) {
570 window_draw_border(f->id, get_border_color(false, true));
575 draw_border(n, true, true);
580 ewmh_update_active_window();
581 history_add(m, d, n);
583 put_status(SBSC_MASK_REPORT);
586 if (focus_follows_pointer) {
587 update_motion_recorder();
592 put_status(SBSC_MASK_NODE_FOCUS, "node_focus 0x%08X 0x%08X 0x%08X\n", m->id, d->id, n->id);
597 if (pointer_follows_focus) {
598 center_pointer(get_rectangle(m, d, n));
599 } else if (focus_follows_pointer) {
600 update_motion_recorder();
606 void hide_node(desktop_t *d, node_t *n)
612 if (n->presel != NULL && d->layout != LAYOUT_MONOCLE) {
613 window_hide(n->presel->feedback);
615 if (n->client != NULL) {
619 if (n->client != NULL) {
620 n->client->shown = false;
622 hide_node(d, n->first_child);
623 hide_node(d, n->second_child);
627 void show_node(desktop_t *d, node_t *n)
633 if (n->client != NULL) {
636 if (n->presel != NULL && d->layout != LAYOUT_MONOCLE) {
637 window_show(n->presel->feedback);
640 if (n->client != NULL) {
641 n->client->shown = true;
643 show_node(d, n->first_child);
644 show_node(d, n->second_child);
648 node_t *make_node(uint32_t id)
650 if (id == XCB_NONE) {
651 id = xcb_generate_id(dpy);
653 node_t *n = calloc(1, sizeof(node_t));
655 n->parent = n->first_child = n->second_child = NULL;
656 n->vacant = n->hidden = n->sticky = n->private = n->locked = false;
657 n->split_ratio = split_ratio;
658 n->split_type = TYPE_VERTICAL;
659 n->birth_rotation = 0;
660 n->constraints = (constraints_t) {MIN_WIDTH, MIN_HEIGHT};
666 client_t *make_client(void)
668 client_t *c = calloc(1, sizeof(client_t));
669 c->state = c->last_state = STATE_TILED;
670 c->layer = c->last_layer = LAYER_NORMAL;
671 snprintf(c->class_name, sizeof(c->class_name), "%s", MISSING_VALUE);
672 snprintf(c->instance_name, sizeof(c->instance_name), "%s", MISSING_VALUE);
673 c->border_width = border_width;
677 c->icccm_props.input_hint = true;
678 c->icccm_props.take_focus = false;
679 c->icccm_props.delete_window = false;
680 c->size_hints.flags = 0;
684 void initialize_client(node_t *n)
686 xcb_window_t win = n->id;
687 client_t *c = n->client;
688 xcb_icccm_get_wm_protocols_reply_t protos;
689 if (xcb_icccm_get_wm_protocols_reply(dpy, xcb_icccm_get_wm_protocols(dpy, win, ewmh->WM_PROTOCOLS), &protos, NULL) == 1) {
690 for (uint32_t i = 0; i < protos.atoms_len; i++) {
691 if (protos.atoms[i] == WM_TAKE_FOCUS) {
692 c->icccm_props.take_focus = true;
693 } else if (protos.atoms[i] == WM_DELETE_WINDOW) {
694 c->icccm_props.delete_window = true;
697 xcb_icccm_get_wm_protocols_reply_wipe(&protos);
699 xcb_ewmh_get_atoms_reply_t wm_state;
700 if (xcb_ewmh_get_wm_state_reply(ewmh, xcb_ewmh_get_wm_state(ewmh, win), &wm_state, NULL) == 1) {
701 for (unsigned int i = 0; i < wm_state.atoms_len && i < MAX_WM_STATES; i++) {
702 #define HANDLE_WM_STATE(s) \
703 if (wm_state.atoms[i] == ewmh->_NET_WM_STATE_##s) { \
704 c->wm_flags |= WM_FLAG_##s; continue; \
706 HANDLE_WM_STATE(MODAL)
707 HANDLE_WM_STATE(STICKY)
708 HANDLE_WM_STATE(MAXIMIZED_VERT)
709 HANDLE_WM_STATE(MAXIMIZED_HORZ)
710 HANDLE_WM_STATE(SHADED)
711 HANDLE_WM_STATE(SKIP_TASKBAR)
712 HANDLE_WM_STATE(SKIP_PAGER)
713 HANDLE_WM_STATE(HIDDEN)
714 HANDLE_WM_STATE(FULLSCREEN)
715 HANDLE_WM_STATE(ABOVE)
716 HANDLE_WM_STATE(BELOW)
717 HANDLE_WM_STATE(DEMANDS_ATTENTION)
718 #undef HANDLE_WM_STATE
720 xcb_ewmh_get_atoms_reply_wipe(&wm_state);
722 xcb_icccm_wm_hints_t hints;
723 if (xcb_icccm_get_wm_hints_reply(dpy, xcb_icccm_get_wm_hints(dpy, win), &hints, NULL) == 1
724 && (hints.flags & XCB_ICCCM_WM_HINT_INPUT)) {
725 c->icccm_props.input_hint = hints.input;
727 xcb_icccm_get_wm_normal_hints_reply(dpy, xcb_icccm_get_wm_normal_hints(dpy, win), &c->size_hints, NULL);
730 bool is_focusable(node_t *n)
732 for (node_t *f = first_extrema(n); f != NULL; f = next_leaf(f, n)) {
733 if (f->client != NULL && !f->hidden) {
740 bool is_leaf(node_t *n)
742 return (n != NULL && n->first_child == NULL && n->second_child == NULL);
745 bool is_first_child(node_t *n)
747 return (n != NULL && n->parent != NULL && n->parent->first_child == n);
750 bool is_second_child(node_t *n)
752 return (n != NULL && n->parent != NULL && n->parent->second_child == n);
755 unsigned int clients_count_in(node_t *n)
760 return (n->client != NULL ? 1 : 0) +
761 clients_count_in(n->first_child) +
762 clients_count_in(n->second_child);
766 node_t *brother_tree(node_t *n)
768 if (n == NULL || n->parent == NULL) {
771 if (is_first_child(n)) {
772 return n->parent->second_child;
774 return n->parent->first_child;
778 node_t *first_extrema(node_t *n)
782 } else if (n->first_child == NULL) {
785 return first_extrema(n->first_child);
789 node_t *second_extrema(node_t *n)
793 } else if (n->second_child == NULL) {
796 return second_extrema(n->second_child);
800 node_t *first_focusable_leaf(node_t *n)
802 for (node_t *f = first_extrema(n); f != NULL; f = next_leaf(f, n)) {
803 if (f->client != NULL && !f->hidden) {
810 node_t *next_leaf(node_t *n, node_t *r)
816 while (is_second_child(p) && p != r) {
822 return first_extrema(p->parent->second_child);
825 node_t *prev_leaf(node_t *n, node_t *r)
831 while (is_first_child(p) && p != r) {
837 return second_extrema(p->parent->first_child);
840 node_t *next_tiled_leaf(node_t *n, node_t *r)
842 node_t *next = next_leaf(n, r);
843 if (next == NULL || (next->client != NULL && !next->vacant)) {
846 return next_tiled_leaf(next, r);
850 node_t *prev_tiled_leaf(node_t *n, node_t *r)
852 node_t *prev = prev_leaf(n, r);
853 if (prev == NULL || (prev->client != NULL && !prev->vacant)) {
856 return prev_tiled_leaf(prev, r);
860 /* Returns true if *b* is adjacent to *a* in the direction *dir* */
861 bool is_adjacent(node_t *a, node_t *b, direction_t dir)
865 return (a->rectangle.x + a->rectangle.width) == b->rectangle.x;
868 return (a->rectangle.y + a->rectangle.height) == b->rectangle.y;
871 return (b->rectangle.x + b->rectangle.width) == a->rectangle.x;
874 return (b->rectangle.y + b->rectangle.height) == a->rectangle.y;
880 node_t *find_fence(node_t *n, direction_t dir)
891 if ((dir == DIR_NORTH && p->split_type == TYPE_HORIZONTAL && p->rectangle.y < n->rectangle.y) ||
892 (dir == DIR_WEST && p->split_type == TYPE_VERTICAL && p->rectangle.x < n->rectangle.x) ||
893 (dir == DIR_SOUTH && p->split_type == TYPE_HORIZONTAL && (p->rectangle.y + p->rectangle.height) > (n->rectangle.y + n->rectangle.height)) ||
894 (dir == DIR_EAST && p->split_type == TYPE_VERTICAL && (p->rectangle.x + p->rectangle.width) > (n->rectangle.x + n->rectangle.width)))
902 /* returns *true* if *a* is a child of *b* */
903 bool is_child(node_t *a, node_t *b)
905 if (a == NULL || b == NULL) {
908 return (a->parent != NULL && a->parent == b);
911 /* returns *true* if *a* is a descendant of *b* */
912 bool is_descendant(node_t *a, node_t *b)
914 if (a == NULL || b == NULL) {
917 while (a != b && a != NULL) {
923 bool find_by_id(uint32_t id, coordinates_t *loc)
925 for (monitor_t *m = mon_head; m != NULL; m = m->next) {
926 for (desktop_t *d = m->desk_head; d != NULL; d = d->next) {
927 node_t *n = find_by_id_in(d->root, id);
939 node_t *find_by_id_in(node_t *r, uint32_t id)
943 } else if (r->id == id) {
946 node_t *f = find_by_id_in(r->first_child, id);
950 return find_by_id_in(r->second_child, id);
955 /* Based on https://github.com/ntrrgc/right-window */
956 void find_nearest_neighbor(coordinates_t *ref, coordinates_t *dst, direction_t dir, node_select_t sel)
958 xcb_rectangle_t rect = get_rectangle(ref->monitor, ref->desktop, ref->node);
959 double md = UINT32_MAX, mr = UINT32_MAX;
961 for (monitor_t *m = mon_head; m != NULL; m = m->next) {
962 desktop_t *d = m->desk;
963 for (node_t *f = first_extrema(d->root); f != NULL; f = next_leaf(f, d->root)) {
964 coordinates_t loc = {m, d, f};
965 xcb_rectangle_t r = get_rectangle(m, d, f);
966 if (f == ref->node ||
969 is_descendant(f, ref->node) ||
970 !node_matches(&loc, ref, sel) ||
971 !on_dir_side(rect, r, dir)) {
974 uint32_t fd = boundary_distance(rect, r, dir);
975 uint32_t fr = history_rank(f);
976 if (fd < md || (fd == md && fr < mr)) {
985 unsigned int node_area(desktop_t *d, node_t *n)
990 return area(get_rectangle(NULL, d, n));
993 int tiled_count(node_t *n)
999 for (node_t *f = first_extrema(n); f != NULL; f = next_leaf(f, n)) {
1000 if (!f->hidden && f->client != NULL && IS_TILED(f->client)) {
1007 void find_biggest(coordinates_t *ref, coordinates_t *dst, node_select_t sel)
1009 unsigned int b_area = 0;
1011 for (monitor_t *m = mon_head; m != NULL; m = m->next) {
1012 for (desktop_t *d = m->desk_head; d != NULL; d = d->next) {
1013 for (node_t *f = first_extrema(d->root); f != NULL; f = next_leaf(f, d->root)) {
1014 coordinates_t loc = {m, d, f};
1015 if (f->client == NULL || f->vacant || !node_matches(&loc, ref, sel)) {
1018 unsigned int f_area = node_area(d, f);
1019 if (f_area > b_area) {
1028 void rotate_tree(node_t *n, int deg)
1030 rotate_tree_rec(n, deg);
1031 rebuild_constraints(n);
1034 void rotate_tree_rec(node_t *n, int deg)
1036 if (n == NULL || is_leaf(n) || deg == 0) {
1042 if ((deg == 90 && n->split_type == TYPE_HORIZONTAL) ||
1043 (deg == 270 && n->split_type == TYPE_VERTICAL) ||
1045 tmp = n->first_child;
1046 n->first_child = n->second_child;
1047 n->second_child = tmp;
1048 n->split_ratio = 1.0 - n->split_ratio;
1052 if (n->split_type == TYPE_HORIZONTAL) {
1053 n->split_type = TYPE_VERTICAL;
1054 } else if (n->split_type == TYPE_VERTICAL) {
1055 n->split_type = TYPE_HORIZONTAL;
1059 rotate_tree_rec(n->first_child, deg);
1060 rotate_tree_rec(n->second_child, deg);
1063 void rotate_brother(node_t *n)
1065 rotate_tree(brother_tree(n), n->birth_rotation);
1068 void unrotate_tree(node_t *n, int rot)
1073 rotate_tree(n, 360 - rot);
1076 void unrotate_brother(node_t *n)
1078 unrotate_tree(brother_tree(n), n->birth_rotation);
1081 void flip_tree(node_t *n, flip_t flp)
1083 if (n == NULL || is_leaf(n)) {
1089 if ((flp == FLIP_HORIZONTAL && n->split_type == TYPE_HORIZONTAL) ||
1090 (flp == FLIP_VERTICAL && n->split_type == TYPE_VERTICAL)) {
1091 tmp = n->first_child;
1092 n->first_child = n->second_child;
1093 n->second_child = tmp;
1094 n->split_ratio = 1.0 - n->split_ratio;
1097 flip_tree(n->first_child, flp);
1098 flip_tree(n->second_child, flp);
1101 void equalize_tree(node_t *n)
1103 if (n == NULL || n->vacant) {
1106 n->split_ratio = split_ratio;
1107 equalize_tree(n->first_child);
1108 equalize_tree(n->second_child);
1112 int balance_tree(node_t *n)
1114 if (n == NULL || n->vacant) {
1116 } else if (is_leaf(n)) {
1119 int b1 = balance_tree(n->first_child);
1120 int b2 = balance_tree(n->second_child);
1122 if (b1 > 0 && b2 > 0) {
1123 n->split_ratio = (double) b1 / b;
1129 void unlink_node(monitor_t *m, desktop_t *d, node_t *n)
1131 if (d == NULL || n == NULL) {
1135 node_t *p = n->parent;
1141 if (d->focus == p || is_descendant(d->focus, n)) {
1145 history_remove(d, p, false);
1146 cancel_presel(m, d, p);
1151 node_t *b = brother_tree(n);
1152 node_t *g = p->parent;
1155 unrotate_tree(b, n->birth_rotation);
1161 if (is_first_child(p)) {
1164 g->second_child = b;
1170 b->birth_rotation = p->birth_rotation;
1175 propagate_flags_upward(m, d, b);
1179 void close_node(node_t *n)
1183 } else if (n->client != NULL) {
1184 if (n->client->icccm_props.delete_window) {
1185 send_client_message(n->id, ewmh->WM_PROTOCOLS, WM_DELETE_WINDOW);
1187 xcb_kill_client(dpy, n->id);
1190 close_node(n->first_child);
1191 close_node(n->second_child);
1195 void kill_node(monitor_t *m, desktop_t *d, node_t *n)
1201 for (node_t *f = first_extrema(n); f != NULL; f = next_leaf(f, n)) {
1202 if (f->client != NULL) {
1203 xcb_kill_client(dpy, f->id);
1207 remove_node(m, d, n);
1210 void remove_node(monitor_t *m, desktop_t *d, node_t *n)
1216 unlink_node(m, d, n);
1217 history_remove(d, n, true);
1218 remove_stack_node(n);
1219 cancel_presel_in(m, d, n);
1220 if (m->sticky_count > 0) {
1221 m->sticky_count -= sticky_count(n);
1223 clients_count -= clients_count_in(n);
1224 if (is_descendant(grabbed_node, n)) {
1225 grabbed_node = NULL;
1229 ewmh_update_client_list(false);
1230 ewmh_update_client_list(true);
1232 if (mon != NULL && d->focus == NULL) {
1233 if (d == mon->desk) {
1234 focus_node(m, d, NULL);
1236 activate_node(m, d, NULL);
1241 void free_node(node_t *n)
1246 node_t *first_child = n->first_child;
1247 node_t *second_child = n->second_child;
1250 free_node(first_child);
1251 free_node(second_child);
1254 bool swap_nodes(monitor_t *m1, desktop_t *d1, node_t *n1, monitor_t *m2, desktop_t *d2, node_t *n2, bool follow)
1256 if (n1 == NULL || n2 == NULL || n1 == n2 || is_descendant(n1, n2) || is_descendant(n2, n1) ||
1257 (d1 != d2 && ((m1->sticky_count > 0 && sticky_count(n1) > 0) ||
1258 (m2->sticky_count > 0 && sticky_count(n2) > 0)))) {
1262 put_status(SBSC_MASK_NODE_SWAP, "node_swap 0x%08X 0x%08X 0x%08X 0x%08X 0x%08X 0x%08X\n", m1->id, d1->id, n1->id, m2->id, d2->id, n2->id);
1264 node_t *pn1 = n1->parent;
1265 node_t *pn2 = n2->parent;
1266 bool n1_first_child = is_first_child(n1);
1267 bool n2_first_child = is_first_child(n2);
1268 int br1 = n1->birth_rotation;
1269 int br2 = n2->birth_rotation;
1270 bool n1_held_focus = is_descendant(d1->focus, n1);
1271 bool n2_held_focus = is_descendant(d2->focus, n2);
1272 node_t *last_d1_focus = d1->focus;
1273 node_t *last_d2_focus = d2->focus;
1276 if (n1_first_child) {
1277 pn1->first_child = n2;
1279 pn1->second_child = n2;
1284 if (n2_first_child) {
1285 pn2->first_child = n1;
1287 pn2->second_child = n1;
1293 n1->birth_rotation = br2;
1294 n2->birth_rotation = br1;
1296 propagate_flags_upward(m2, d2, n1);
1297 propagate_flags_upward(m1, d1, n2);
1300 if (d1->root == n1) {
1304 if (d2->root == n2) {
1308 if (n1_held_focus) {
1309 d1->focus = n2_held_focus ? last_d2_focus : n2;
1312 if (n2_held_focus) {
1313 d2->focus = n1_held_focus ? last_d1_focus : n1;
1317 adapt_geometry(&m2->rectangle, &m1->rectangle, n2);
1318 adapt_geometry(&m1->rectangle, &m2->rectangle, n1);
1321 ewmh_set_wm_desktop(n1, d2);
1322 ewmh_set_wm_desktop(n2, d1);
1324 history_swap_nodes(m1, d1, n1, m2, d2, n2);
1326 bool d1_was_focused = (d1 == mon->desk);
1327 bool d2_was_focused = (d2 == mon->desk);
1329 if (m1->desk != d1 && m2->desk == d2) {
1331 if (!follow || !d2_was_focused || !n2_held_focus) {
1334 } else if (m1->desk == d1 && m2->desk != d2) {
1335 if (!follow || !d1_was_focused || !n1_held_focus) {
1341 if (n1_held_focus) {
1342 if (d1_was_focused) {
1344 focus_node(m2, d2, last_d1_focus);
1346 focus_node(m1, d1, d1->focus);
1349 activate_node(m1, d1, d1->focus);
1352 draw_border(n2, is_descendant(n2, d1->focus), (m1 == mon));
1355 if (n2_held_focus) {
1356 if (d2_was_focused) {
1358 focus_node(m1, d1, last_d2_focus);
1360 focus_node(m2, d2, d2->focus);
1363 activate_node(m2, d2, d2->focus);
1366 draw_border(n1, is_descendant(n1, d2->focus), (m2 == mon));
1369 draw_border(n1, is_descendant(n1, d2->focus), (m2 == mon));
1370 draw_border(n2, is_descendant(n2, d1->focus), (m1 == mon));
1382 bool transfer_node(monitor_t *ms, desktop_t *ds, node_t *ns, monitor_t *md, desktop_t *dd, node_t *nd, bool follow)
1384 if (ns == NULL || ns == nd || is_child(ns, nd) || is_descendant(nd, ns)) {
1388 if (sticky_still && ds != dd && ms->sticky_count > 0 && sticky_count(ns) > 0) {
1392 put_status(SBSC_MASK_NODE_TRANSFER, "node_transfer 0x%08X 0x%08X 0x%08X 0x%08X 0x%08X 0x%08X\n", ms->id, ds->id, ns->id, md->id, dd->id, nd!=NULL?nd->id:0);
1394 bool held_focus = is_descendant(ds->focus, ns);
1395 /* avoid ending up with a dangling pointer (because of unlink_node) */
1396 node_t *last_ds_focus = is_child(ns, ds->focus) ? NULL : ds->focus;
1397 bool ds_was_focused = (ds == mon->desk);
1399 if (held_focus && ds_was_focused) {
1400 clear_input_focus();
1403 unlink_node(ms, ds, ns);
1404 insert_node(md, dd, ns, nd);
1406 if (md != ms && (ns->client == NULL || monitor_from_client(ns->client) != md)) {
1407 adapt_geometry(&ms->rectangle, &md->rectangle, ns);
1411 ewmh_set_wm_desktop(ns, dd);
1413 if (ds == ms->desk && dd != md->desk) {
1415 } else if (ds != ms->desk && dd == md->desk) {
1421 history_transfer_node(md, dd, ns);
1422 stack(dd, ns, false);
1426 if (ds_was_focused) {
1427 focus_node(ms, ds, last_ds_focus);
1429 activate_node(ms, ds, last_ds_focus);
1432 draw_border(ns, is_descendant(ns, ds->focus), (ms == mon));
1437 if (ds_was_focused) {
1438 focus_node(md, dd, last_ds_focus);
1440 activate_node(ms, ds, ds->focus);
1442 if (ds_was_focused) {
1443 focus_node(ms, ds, ds->focus);
1445 activate_node(ms, ds, ds->focus);
1449 if (!held_focus || !follow || !ds_was_focused) {
1450 if (dd->focus == ns) {
1451 if (dd == mon->desk) {
1452 focus_node(md, dd, held_focus ? last_ds_focus : ns);
1454 activate_node(md, dd, held_focus ? last_ds_focus : ns);
1457 draw_border(ns, is_descendant(ns, dd->focus), (md == mon));
1471 bool find_closest_node(coordinates_t *ref, coordinates_t *dst, cycle_dir_t dir, node_select_t sel)
1473 monitor_t *m = ref->monitor;
1474 desktop_t *d = ref->desktop;
1475 node_t *n = ref->node;
1476 n = (dir == CYCLE_PREV ? prev_leaf(n, d->root) : next_leaf(n, d->root));
1478 #define HANDLE_BOUNDARIES(m, d, n) \
1479 while (n == NULL) { \
1480 d = (dir == CYCLE_PREV ? d->prev : d->next); \
1482 m = (dir == CYCLE_PREV ? m->prev : m->next); \
1484 m = (dir == CYCLE_PREV ? mon_tail : mon_head); \
1486 d = (dir == CYCLE_PREV ? m->desk_tail : m->desk_head); \
1488 n = (dir == CYCLE_PREV ? second_extrema(d->root) : first_extrema(d->root)); \
1489 if (ref->node == NULL && d == ref->desktop) { \
1493 HANDLE_BOUNDARIES(m, d, n);
1495 while (n != ref->node) {
1496 coordinates_t loc = {m, d, n};
1497 if (n->client != NULL && !n->hidden && node_matches(&loc, ref, sel)) {
1501 n = (dir == CYCLE_PREV ? prev_leaf(n, d->root) : next_leaf(n, d->root));
1502 HANDLE_BOUNDARIES(m, d, n);
1504 #undef HANDLE_BOUNDARIES
1508 void circulate_leaves(monitor_t *m, desktop_t *d, node_t *n, circulate_dir_t dir)
1510 if (tiled_count(n) < 2) {
1513 node_t *p = d->focus->parent;
1514 bool focus_first_child = is_first_child(d->focus);
1515 if (dir == CIRCULATE_FORWARD) {
1516 node_t *e = second_extrema(n);
1517 while (e != NULL && (e->client == NULL || !IS_TILED(e->client))) {
1518 e = prev_leaf(e, n);
1520 for (node_t *s = e, *f = prev_tiled_leaf(s, n); f != NULL; s = prev_tiled_leaf(f, n), f = prev_tiled_leaf(s, n)) {
1521 swap_nodes(m, d, f, m, d, s, false);
1524 node_t *e = first_extrema(n);
1525 while (e != NULL && (e->client == NULL || !IS_TILED(e->client))) {
1526 e = next_leaf(e, n);
1528 for (node_t *f = e, *s = next_tiled_leaf(f, n); s != NULL; f = next_tiled_leaf(s, n), s = next_tiled_leaf(f, n)) {
1529 swap_nodes(m, d, f, m, d, s, false);
1533 node_t *f = focus_first_child ? p->first_child : p->second_child;
1535 if (d == mon->desk) {
1536 focus_node(m, d, f);
1538 activate_node(m, d, f);
1544 void set_vacant(monitor_t *m, desktop_t *d, node_t *n, bool value)
1546 if (n->vacant == value) {
1550 propagate_vacant_downward(m, d, n, value);
1551 propagate_vacant_upward(m, d, n);
1554 void set_vacant_local(monitor_t *m, desktop_t *d, node_t *n, bool value)
1556 if (n->vacant == value) {
1563 unrotate_brother(n);
1564 cancel_presel(m, d, n);
1570 void propagate_vacant_downward(monitor_t *m, desktop_t *d, node_t *n, bool value)
1576 set_vacant_local(m, d, n, value);
1578 propagate_vacant_downward(m, d, n->first_child, value);
1579 propagate_vacant_downward(m, d, n->second_child, value);
1582 void propagate_vacant_upward(monitor_t *m, desktop_t *d, node_t *n)
1588 node_t *p = n->parent;
1591 set_vacant_local(m, d, p, (p->first_child->vacant && p->second_child->vacant));
1594 propagate_vacant_upward(m, d, p);
1597 bool set_layer(monitor_t *m, desktop_t *d, node_t *n, stack_layer_t l)
1599 if (n == NULL || n->client == NULL || n->client->layer == l) {
1603 n->client->last_layer = n->client->layer;
1604 n->client->layer = l;
1606 if (l == LAYER_ABOVE) {
1607 n->client->wm_flags |= WM_FLAG_ABOVE;
1608 n->client->wm_flags &= ~WM_FLAG_BELOW;
1609 } else if (l == LAYER_BELOW) {
1610 n->client->wm_flags |= WM_FLAG_BELOW;
1611 n->client->wm_flags &= ~WM_FLAG_ABOVE;
1613 n->client->wm_flags &= ~(WM_FLAG_ABOVE | WM_FLAG_BELOW);
1616 ewmh_wm_state_update(n);
1618 put_status(SBSC_MASK_NODE_LAYER, "node_layer 0x%08X 0x%08X 0x%08X %s\n", m->id, d->id, n->id, LAYER_STR(l));
1620 if (d->focus == n) {
1621 neutralize_occluding_windows(m, d, n);
1624 stack(d, n, (d->focus == n));
1629 bool set_state(monitor_t *m, desktop_t *d, node_t *n, client_state_t s)
1631 if (n == NULL || n->client == NULL || n->client->state == s) {
1635 client_t *c = n->client;
1637 c->last_state = c->state;
1640 switch (c->last_state) {
1642 case STATE_PSEUDO_TILED:
1644 case STATE_FLOATING:
1645 set_floating(m, d, n, false);
1647 case STATE_FULLSCREEN:
1648 set_fullscreen(m, d, n, false);
1652 put_status(SBSC_MASK_NODE_STATE, "node_state 0x%08X 0x%08X 0x%08X %s off\n", m->id, d->id, n->id, STATE_STR(c->last_state));
1656 case STATE_PSEUDO_TILED:
1658 case STATE_FLOATING:
1659 set_floating(m, d, n, true);
1661 case STATE_FULLSCREEN:
1662 set_fullscreen(m, d, n, true);
1666 put_status(SBSC_MASK_NODE_STATE, "node_state 0x%08X 0x%08X 0x%08X %s on\n", m->id, d->id, n->id, STATE_STR(c->state));
1668 if (n == m->desk->focus) {
1669 put_status(SBSC_MASK_REPORT);
1675 void set_floating(monitor_t *m, desktop_t *d, node_t *n, bool value)
1681 cancel_presel(m, d, n);
1682 set_vacant(m, d, n, value);
1684 if (!value && d->focus == n) {
1685 neutralize_occluding_windows(m, d, n);
1688 stack(d, n, (d->focus == n));
1691 void set_fullscreen(monitor_t *m, desktop_t *d, node_t *n, bool value)
1697 client_t *c = n->client;
1699 cancel_presel(m, d, n);
1700 set_vacant(m, d, n, value);
1703 c->wm_flags |= WM_FLAG_FULLSCREEN;
1704 c->last_layer = c->layer;
1705 c->layer = LAYER_ABOVE;
1707 c->wm_flags &= ~WM_FLAG_FULLSCREEN;
1708 c->layer = c->last_layer;
1709 if (d->focus == n) {
1710 neutralize_occluding_windows(m, d, n);
1714 ewmh_wm_state_update(n);
1715 stack(d, n, (d->focus == n));
1718 void neutralize_occluding_windows(monitor_t *m, desktop_t *d, node_t *n)
1720 bool changed = false;
1721 for (node_t *f = first_extrema(n); f != NULL; f = next_leaf(f, n)) {
1722 for (node_t *a = first_extrema(d->root); a != NULL; a = next_leaf(a, d->root)) {
1723 if (a != f && a->client != NULL && f->client != NULL &&
1724 IS_FULLSCREEN(a->client) && stack_cmp(f->client, a->client) < 0) {
1725 set_state(m, d, a, a->client->last_state);
1735 void rebuild_constraints(node_t *n)
1737 if (n == NULL || is_leaf(n)) {
1740 rebuild_constraints(n->first_child);
1741 rebuild_constraints(n->second_child);
1742 update_constraints(n);
1746 void update_constraints(node_t *n)
1748 if (n == NULL || is_leaf(n)) {
1751 if (n->split_type == TYPE_VERTICAL) {
1752 n->constraints.min_width = n->first_child->constraints.min_width + n->second_child->constraints.min_width;
1753 n->constraints.min_height = MAX(n->first_child->constraints.min_height, n->second_child->constraints.min_height);
1755 n->constraints.min_width = MAX(n->first_child->constraints.min_width, n->second_child->constraints.min_width);
1756 n->constraints.min_height = n->first_child->constraints.min_height + n->second_child->constraints.min_height;
1760 void propagate_flags_upward(monitor_t *m, desktop_t *d, node_t *n)
1766 node_t *p = n->parent;
1769 set_vacant_local(m, d, p, (p->first_child->vacant && p->second_child->vacant));
1770 set_hidden_local(m, d, p, (p->first_child->hidden && p->second_child->hidden));
1771 update_constraints(p);
1774 propagate_flags_upward(m, d, p);
1777 void set_hidden(monitor_t *m, desktop_t *d, node_t *n, bool value)
1779 if (n == NULL || n->hidden == value) {
1783 bool held_focus = is_descendant(d->focus, n);
1785 propagate_hidden_downward(m, d, n, value);
1786 propagate_hidden_upward(m, d, n);
1788 put_status(SBSC_MASK_NODE_FLAG, "node_flag 0x%08X 0x%08X 0x%08X hidden %s\n", m->id, d->id, n->id, ON_OFF_STR(value));
1790 if (held_focus || d->focus == NULL) {
1791 if (d->focus != NULL) {
1793 draw_border(n, false, (mon == m));
1795 if (d == mon->desk) {
1796 focus_node(m, d, d->focus);
1798 activate_node(m, d, d->focus);
1803 void set_hidden_local(monitor_t *m, desktop_t *d, node_t *n, bool value)
1805 if (n->hidden == value) {
1811 if (n->client != NULL) {
1812 if (n->client->shown) {
1813 window_set_visibility(n->id, !value);
1816 if (IS_TILED(n->client)) {
1817 set_vacant(m, d, n, value);
1821 n->client->wm_flags |= WM_FLAG_HIDDEN;
1823 n->client->wm_flags &= ~WM_FLAG_HIDDEN;
1826 ewmh_wm_state_update(n);
1830 void propagate_hidden_downward(monitor_t *m, desktop_t *d, node_t *n, bool value)
1836 set_hidden_local(m, d, n, value);
1838 propagate_hidden_downward(m, d, n->first_child, value);
1839 propagate_hidden_downward(m, d, n->second_child, value);
1842 void propagate_hidden_upward(monitor_t *m, desktop_t *d, node_t *n)
1848 node_t *p = n->parent;
1851 set_hidden_local(m, d, p, p->first_child->hidden && p->second_child->hidden);
1854 propagate_hidden_upward(m, d, p);
1857 void set_sticky(monitor_t *m, desktop_t *d, node_t *n, bool value)
1859 if (n == NULL || n->sticky == value) {
1864 transfer_node(m, d, n, m, m->desk, m->desk->focus, false);
1875 if (n->client != NULL) {
1877 n->client->wm_flags |= WM_FLAG_STICKY;
1879 n->client->wm_flags &= ~WM_FLAG_STICKY;
1881 ewmh_wm_state_update(n);
1884 put_status(SBSC_MASK_NODE_FLAG, "node_flag 0x%08X 0x%08X 0x%08X sticky %s\n", m->id, d->id, n->id, ON_OFF_STR(value));
1886 if (n == m->desk->focus) {
1887 put_status(SBSC_MASK_REPORT);
1891 void set_private(monitor_t *m, desktop_t *d, node_t *n, bool value)
1893 if (n == NULL || n->private == value) {
1899 put_status(SBSC_MASK_NODE_FLAG, "node_flag 0x%08X 0x%08X 0x%08X private %s\n", m->id, d->id, n->id, ON_OFF_STR(value));
1901 if (n == m->desk->focus) {
1902 put_status(SBSC_MASK_REPORT);
1906 void set_locked(monitor_t *m, desktop_t *d, node_t *n, bool value)
1908 if (n == NULL || n->locked == value) {
1914 put_status(SBSC_MASK_NODE_FLAG, "node_flag 0x%08X 0x%08X 0x%08X locked %s\n", m->id, d->id, n->id, ON_OFF_STR(value));
1916 if (n == m->desk->focus) {
1917 put_status(SBSC_MASK_REPORT);
1921 void set_urgent(monitor_t *m, desktop_t *d, node_t *n, bool value)
1923 if (value && mon->desk->focus == n) {
1927 n->client->urgent = value;
1930 n->client->wm_flags |= WM_FLAG_DEMANDS_ATTENTION;
1932 n->client->wm_flags &= ~WM_FLAG_DEMANDS_ATTENTION;
1935 ewmh_wm_state_update(n);
1937 put_status(SBSC_MASK_NODE_FLAG, "node_flag 0x%08X 0x%08X 0x%08X urgent %s\n", m->id, d->id, n->id, ON_OFF_STR(value));
1938 put_status(SBSC_MASK_REPORT);
1941 /* Returns true if a contains b */
1942 bool contains(xcb_rectangle_t a, xcb_rectangle_t b)
1944 return (a.x <= b.x && (a.x + a.width) >= (b.x + b.width) &&
1945 a.y <= b.y && (a.y + a.height) >= (b.y + b.height));
1948 xcb_rectangle_t get_rectangle(monitor_t *m, desktop_t *d, node_t *n)
1951 return m->rectangle;
1953 client_t *c = n->client;
1955 if (IS_FLOATING(c)) {
1956 return c->floating_rectangle;
1958 return c->tiled_rectangle;
1961 int wg = (d == NULL ? 0 : (gapless_monocle && IS_MONOCLE(d) ? 0 : d->window_gap));
1962 xcb_rectangle_t rect = n->rectangle;
1969 void listen_enter_notify(node_t *n, bool enable)
1971 uint32_t mask = CLIENT_EVENT_MASK | (enable ? XCB_EVENT_MASK_ENTER_WINDOW : 0);
1972 for (node_t *f = first_extrema(n); f != NULL; f = next_leaf(f, n)) {
1973 if (f->client == NULL) {
1976 xcb_change_window_attributes(dpy, f->id, XCB_CW_EVENT_MASK, &mask);
1977 if (f->presel != NULL) {
1978 xcb_change_window_attributes(dpy, f->presel->feedback, XCB_CW_EVENT_MASK, &mask);
1983 void regenerate_ids_in(node_t *n)
1985 if (n == NULL || n->client != NULL) {
1988 n->id = xcb_generate_id(dpy);
1989 regenerate_ids_in(n->first_child);
1990 regenerate_ids_in(n->second_child);
1993 #define DEF_FLAG_COUNT(flag) \
1994 unsigned int flag##_count(node_t *n) \
1999 return ((n->flag ? 1 : 0) + \
2000 flag##_count(n->first_child) + \
2001 flag##_count(n->second_child)); \
2004 DEF_FLAG_COUNT(sticky)
2005 DEF_FLAG_COUNT(private)
2006 DEF_FLAG_COUNT(locked)
2007 #undef DEF_FLAG_COUNT