1 /* * Copyright (c) 2012-2013 Bastien Dejean
4 * Redistribution and use in source and binary forms, with or without modification,
5 * are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright notice, this
8 * list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright notice,
10 * this list of conditions and the following disclaimer in the documentation and/or
11 * other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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 ON
20 * 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.
40 void arrange(monitor_t *m, desktop_t *d)
45 PRINTF("arrange %s %s\n", m->name, d->name);
47 xcb_rectangle_t rect = m->rectangle;
48 int wg = (gapless_monocle && d->layout == LAYOUT_MONOCLE ? 0 : d->window_gap);
49 rect.x += m->left_padding + wg;
50 rect.y += m->top_padding + wg;
51 rect.width -= m->left_padding + m->right_padding + wg;
52 rect.height -= m->top_padding + m->bottom_padding + wg;
53 apply_layout(m, d, d->root, rect, rect);
56 void apply_layout(monitor_t *m, desktop_t *d, node_t *n, xcb_rectangle_t rect, xcb_rectangle_t root_rect)
65 if (is_floating(n->client) && n->client->border_width != d->border_width) {
66 int ds = 2 * (d->border_width - n->client->border_width);
67 n->client->floating_rectangle.width += ds;
68 n->client->floating_rectangle.height += ds;
71 if ((borderless_monocle && is_tiled(n->client) && d->layout == LAYOUT_MONOCLE)
72 || n->client->fullscreen
74 n->client->border_width = 0;
76 n->client->border_width = d->border_width;
79 if (!n->client->fullscreen) {
80 if (!n->client->floating) {
82 if (d->layout == LAYOUT_TILED)
84 else if (d->layout == LAYOUT_MONOCLE)
88 int wg = (gapless_monocle && d->layout == LAYOUT_MONOCLE ? 0 : d->window_gap);
89 int bleed = wg + 2 * n->client->border_width;
90 r.width = (bleed < r.width ? r.width - bleed : 1);
91 r.height = (bleed < r.height ? r.height - bleed : 1);
92 n->client->tiled_rectangle = r;
94 /* floating clients */
95 r = n->client->floating_rectangle;
98 /* fullscreen clients */
102 window_move_resize(n->client->window, r.x, r.y, r.width, r.height);
103 window_border_width(n->client->window, n->client->border_width);
104 window_draw_border(n, d->focus == n, m == mon);
107 xcb_rectangle_t first_rect;
108 xcb_rectangle_t second_rect;
110 if (n->first_child->vacant || n->second_child->vacant) {
111 first_rect = second_rect = rect;
114 if (n->split_type == TYPE_VERTICAL) {
115 fence = rect.width * n->split_ratio;
116 first_rect = (xcb_rectangle_t) {rect.x, rect.y, fence, rect.height};
117 second_rect = (xcb_rectangle_t) {rect.x + fence, rect.y, rect.width - fence, rect.height};
118 } else if (n->split_type == TYPE_HORIZONTAL) {
119 fence = rect.height * n->split_ratio;
120 first_rect = (xcb_rectangle_t) {rect.x, rect.y, rect.width, fence};
121 second_rect = (xcb_rectangle_t) {rect.x, rect.y + fence, rect.width, rect.height - fence};
125 apply_layout(m, d, n->first_child, first_rect, root_rect);
126 apply_layout(m, d, n->second_child, second_rect, root_rect);
130 void insert_node(monitor_t *m, desktop_t *d, node_t *n, node_t *f)
132 if (d == NULL || n == NULL)
135 PRINTF("insert node %X\n", n->client->window);
137 /* n: new leaf node */
138 /* c: new container node */
139 /* f: focus or insertion anchor */
140 /* p: parent of focus */
141 /* g: grand parent of focus */
149 node_t *c = make_node();
150 node_t *p = f->parent;
151 if (p != NULL && f->split_mode == MODE_AUTOMATIC
152 && (p->first_child->vacant || p->second_child->vacant)) {
157 c->birth_rotation = f->birth_rotation;
158 switch (f->split_mode) {
163 if (m->rectangle.width > m->rectangle.height)
164 c->split_type = TYPE_VERTICAL;
166 c->split_type = TYPE_HORIZONTAL;
170 node_t *g = p->parent;
173 if (is_first_child(p))
180 c->split_type = p->split_type;
181 c->split_ratio = p->split_ratio;
184 if (is_first_child(f)) {
193 if (!is_floating(n->client))
195 n->birth_rotation = rot;
200 if (is_first_child(f))
205 c->split_ratio = f->split_ratio;
208 f->birth_rotation = 0;
209 switch (f->split_dir) {
211 c->split_type = TYPE_VERTICAL;
216 c->split_type = TYPE_VERTICAL;
221 c->split_type = TYPE_HORIZONTAL;
226 c->split_type = TYPE_HORIZONTAL;
233 f->split_mode = MODE_AUTOMATIC;
237 update_vacant_state(p);
239 if (d->focus == NULL && is_visible(d, n))
241 if (n->client->sticky)
246 void pseudo_focus(desktop_t *d, node_t *n)
253 void focus_node(monitor_t *m, desktop_t *d, node_t *n)
255 if (mon->desk != d || n == NULL)
258 if (m->num_sticky > 0 && d != m->desk) {
259 node_t *a = first_extrema(m->desk->root);
260 sticky_still = false;
262 node_t *b = next_leaf(a, m->desk->root);
263 if (a->client->sticky)
264 transfer_node(m, m->desk, a, m, d, d->focus);
268 if (n == NULL && d->focus != NULL && is_visible(d, d->focus))
272 if (n != NULL && d->focus != NULL && n != d->focus && d->focus->client->fullscreen) {
273 set_fullscreen(d->focus, false);
278 for (desktop_t *cd = mon->desk_head; cd != NULL; cd = cd->next)
279 window_draw_border(cd->focus, true, false);
280 for (desktop_t *cd = m->desk_head; cd != NULL; cd = cd->next)
282 window_draw_border(cd->focus, true, true);
284 window_draw_border(n, true, true);
288 window_draw_border(d->focus, false, true);
289 window_draw_border(n, true, true);
296 history_add(m, d, NULL);
297 ewmh_update_active_window();
301 PRINTF("focus node %X\n", n->client->window);
303 n->client->urgent = false;
305 if (!is_visible(d, n))
306 tag_node(m, d, n, d, n->client->tags_field | d->tags_field);
307 history_add(m, d, n);
310 if (focus_follows_pointer) {
311 xcb_window_t win = XCB_NONE;
312 query_pointer(&win, NULL);
313 if (win != n->client->window)
314 enable_motion_recorder();
316 disable_motion_recorder();
319 ewmh_update_active_window();
322 void update_current(void)
324 focus_node(mon, mon->desk, mon->desk->focus);
327 node_t *make_node(void)
329 node_t *n = malloc(sizeof(node_t));
330 n->parent = n->first_child = n->second_child = NULL;
331 n->split_ratio = split_ratio;
332 n->split_mode = MODE_AUTOMATIC;
333 n->split_type = TYPE_VERTICAL;
334 n->birth_rotation = 0;
340 client_t *make_client(xcb_window_t win)
342 client_t *c = malloc(sizeof(client_t));
343 snprintf(c->class_name, sizeof(c->class_name), "%s", MISSING_VALUE);
344 c->border_width = BORDER_WIDTH;
346 c->floating = c->transient = c->fullscreen = c->locked = c->sticky = c->urgent = false;
347 c->frame = c->icccm_focus = false;
348 xcb_icccm_get_wm_protocols_reply_t protocols;
349 if (xcb_icccm_get_wm_protocols_reply(dpy, xcb_icccm_get_wm_protocols(dpy, win, ewmh->WM_PROTOCOLS), &protocols, NULL) == 1) {
350 if (has_proto(WM_TAKE_FOCUS, &protocols))
351 c->icccm_focus = true;
352 xcb_icccm_get_wm_protocols_reply_wipe(&protocols);
355 xcb_ewmh_get_atoms_reply_t wm_state;
356 if (xcb_ewmh_get_wm_state_reply(ewmh, xcb_ewmh_get_wm_state(ewmh, win), &wm_state, NULL) == 1) {
357 for (unsigned int i = 0; i < wm_state.atoms_len && i < MAX_STATE; i++)
358 ewmh_wm_state_add(c, wm_state.atoms[i]);
359 xcb_ewmh_get_atoms_reply_wipe(&wm_state);
364 bool is_visible(desktop_t *d, node_t *n)
366 return (d->tags_field & n->client->tags_field) != 0;
369 bool is_leaf(node_t *n)
371 return (n != NULL && n->first_child == NULL && n->second_child == NULL);
374 bool is_tiled(client_t *c)
378 return (!c->floating && !c->fullscreen);
381 bool is_floating(client_t *c)
385 return (c->floating && !c->fullscreen);
388 bool is_first_child(node_t *n)
390 return (n != NULL && n->parent != NULL && n->parent->first_child == n);
393 bool is_second_child(node_t *n)
395 return (n != NULL && n->parent != NULL && n->parent->second_child == n);
398 void change_split_ratio(node_t *n, value_change_t chg)
400 n->split_ratio = pow(n->split_ratio,
401 (chg == CHANGE_INCREASE ? (1 / growth_factor) : growth_factor));
404 void reset_mode(coordinates_t *loc)
406 if (loc->node != NULL) {
407 loc->node->split_mode = MODE_AUTOMATIC;
408 window_draw_border(loc->node, loc->desktop->focus == loc->node, mon == loc->monitor);
409 } else if (loc->desktop != NULL) {
410 for (node_t *a = first_extrema(loc->desktop->root); a != NULL; a = next_leaf(a, loc->desktop->root)) {
411 a->split_mode = MODE_AUTOMATIC;
412 window_draw_border(a, loc->desktop->focus == a, mon == loc->monitor);
417 node_t *brother_tree(node_t *n)
419 if (n == NULL || n->parent == NULL)
421 if (is_first_child(n))
422 return n->parent->second_child;
424 return n->parent->first_child;
427 node_t *closest_visible(desktop_t *d, node_t *n)
431 node_t *prev = prev_leaf(n, d->root);
432 node_t *next = next_leaf(n, d->root);
433 while (prev != NULL || next != NULL) {
435 if (is_visible(d, prev))
438 prev = prev_leaf(prev, d->root);
441 if (is_visible(d, next))
444 next = next_leaf(next, d->root);
450 node_t *first_extrema(node_t *n)
454 else if (n->first_child == NULL)
457 return first_extrema(n->first_child);
460 node_t *second_extrema(node_t *n)
464 else if (n->second_child == NULL)
467 return second_extrema(n->second_child);
470 node_t *next_leaf(node_t *n, node_t *r)
475 while (is_second_child(p) && p != r)
479 return first_extrema(p->parent->second_child);
482 node_t *prev_leaf(node_t *n, node_t *r)
487 while (is_first_child(p) && p != r)
491 return second_extrema(p->parent->first_child);
494 node_t *next_visible_leaf(desktop_t *d, node_t *n, node_t *r)
496 node_t *next = next_leaf(n, r);
497 if (next == NULL || is_visible(d, next))
500 return next_visible_leaf(d, next, r);
503 node_t *prev_visible_leaf(desktop_t *d, node_t *n, node_t *r)
505 node_t *prev = prev_leaf(n, r);
506 if (prev == NULL || is_visible(d, prev))
509 return prev_visible_leaf(d, prev, r);
512 /* bool is_adjacent(node_t *a, node_t *r) */
514 /* node_t *f = r->parent; */
516 /* bool first_child = is_first_child(r); */
517 /* while (p != r) { */
518 /* if (p->parent->split_type == f->split_type && is_first_child(p) == first_child) */
525 /* Returns true if *b* is adjacent to *a* in the direction *dir* */
526 bool is_adjacent(node_t *a, node_t *b, direction_t dir)
530 return (a->rectangle.x + a->rectangle.width) == b->rectangle.x;
533 return (a->rectangle.y + a->rectangle.height) == b->rectangle.y;
536 return (b->rectangle.x + b->rectangle.width) == a->rectangle.x;
539 return (b->rectangle.y + b->rectangle.height) == a->rectangle.y;
545 node_t *find_fence(node_t *n, direction_t dir)
555 if ((dir == DIR_UP && p->split_type == TYPE_HORIZONTAL && p->rectangle.y < n->rectangle.y)
556 || (dir == DIR_LEFT && p->split_type == TYPE_VERTICAL && p->rectangle.x < n->rectangle.x)
557 || (dir == DIR_DOWN && p->split_type == TYPE_HORIZONTAL && (p->rectangle.y + p->rectangle.height) > (n->rectangle.y + n->rectangle.height))
558 || (dir == DIR_RIGHT && p->split_type == TYPE_VERTICAL && (p->rectangle.x + p->rectangle.width) > (n->rectangle.x + n->rectangle.width)))
567 node_t *nearest_neighbor(monitor_t *m, desktop_t *d, node_t *n, direction_t dir, client_select_t sel)
569 if (n == NULL || n->client->fullscreen
570 || (d->layout == LAYOUT_MONOCLE && is_tiled(n->client)))
573 node_t *nearest = NULL;
574 if (history_aware_focus)
575 nearest = nearest_from_history(m, d, n, dir, sel);
577 nearest = nearest_from_distance(m, d, n, dir, sel);
581 node_t *nearest_from_history(monitor_t *m, desktop_t *d, node_t *n, direction_t dir, client_select_t sel)
583 if (n == NULL || !is_tiled(n->client))
586 node_t *target = find_fence(n, dir);
589 if (dir == DIR_UP || dir == DIR_LEFT)
590 target = target->first_child;
591 else if (dir == DIR_DOWN || dir == DIR_RIGHT)
592 target = target->second_child;
594 node_t *nearest = NULL;
595 int min_rank = INT_MAX;
596 coordinates_t ref = {m, d, n};
598 for (node_t *a = first_extrema(target); a != NULL; a = next_leaf(a, target)) {
599 if (a->vacant || !is_adjacent(n, a, dir) || a == n)
601 coordinates_t loc = {m, d, a};
602 if (!node_matches(&loc, &ref, sel))
605 int rank = history_rank(d, a);
606 if (rank >= 0 && rank < min_rank) {
615 node_t *nearest_from_distance(monitor_t *m, desktop_t *d, node_t *n, direction_t dir, client_select_t sel)
620 node_t *target = NULL;
622 if (is_tiled(n->client)) {
623 target = find_fence(n, dir);
626 if (dir == DIR_UP || dir == DIR_LEFT)
627 target = target->first_child;
628 else if (dir == DIR_DOWN || dir == DIR_RIGHT)
629 target = target->second_child;
634 node_t *nearest = NULL;
638 get_side_handle(n->client, dir, &pt);
639 get_opposite(dir, &dir2);
641 coordinates_t ref = {m, d, n};
643 for (node_t *a = first_extrema(target); a != NULL; a = next_leaf(a, target)) {
644 coordinates_t loc = {m, d, a};
647 !node_matches(&loc, &ref, sel) ||
648 is_tiled(a->client) != is_tiled(n->client) ||
649 (is_tiled(a->client) && !is_adjacent(n, a, dir)))
652 get_side_handle(a->client, dir2, &pt2);
653 double ds2 = distance(pt, pt2);
663 void get_opposite(direction_t src, direction_t *dst)
681 int tiled_area(node_t *n)
685 xcb_rectangle_t rect = n->client->tiled_rectangle;
686 return rect.width * rect.height;
689 node_t *find_biggest(monitor_t *m, desktop_t *d, node_t *n, client_select_t sel)
695 int r_area = tiled_area(r);
696 coordinates_t ref = {m, d, n};
698 for (node_t *f = first_extrema(d->root); f != NULL; f = next_leaf(f, d->root)) {
699 coordinates_t loc = {m, d, f};
700 if (!is_visible(d, f) || !is_tiled(f->client) || !node_matches(&loc, &ref, sel))
702 int f_area = tiled_area(f);
706 } else if (f_area > r_area) {
715 void move_fence(node_t *n, direction_t dir, fence_move_t mov)
720 if ((mov == MOVE_PUSH && (dir == DIR_RIGHT || dir == DIR_DOWN))
721 || (mov == MOVE_PULL && (dir == DIR_LEFT || dir == DIR_UP)))
722 change_split_ratio(n, CHANGE_INCREASE);
724 change_split_ratio(n, CHANGE_DECREASE);
727 void rotate_tree(node_t *n, int deg)
729 if (n == NULL || is_leaf(n) || deg == 0)
734 if ((deg == 90 && n->split_type == TYPE_HORIZONTAL)
735 || (deg == 270 && n->split_type == TYPE_VERTICAL)
737 tmp = n->first_child;
738 n->first_child = n->second_child;
739 n->second_child = tmp;
740 n->split_ratio = 1.0 - n->split_ratio;
744 if (n->split_type == TYPE_HORIZONTAL)
745 n->split_type = TYPE_VERTICAL;
746 else if (n->split_type == TYPE_VERTICAL)
747 n->split_type = TYPE_HORIZONTAL;
750 rotate_tree(n->first_child, deg);
751 rotate_tree(n->second_child, deg);
754 void rotate_brother(node_t *n)
756 rotate_tree(brother_tree(n), n->birth_rotation);
759 void unrotate_tree(node_t *n, int rot)
763 rotate_tree(n, 360 - rot);
766 void unrotate_brother(node_t *n)
768 unrotate_tree(brother_tree(n), n->birth_rotation);
771 void flip_tree(node_t *n, flip_t flp)
773 if (n == NULL || is_leaf(n))
778 if ((flp == FLIP_HORIZONTAL && n->split_type == TYPE_HORIZONTAL)
779 || (flp == FLIP_VERTICAL && n->split_type == TYPE_VERTICAL)) {
780 tmp = n->first_child;
781 n->first_child = n->second_child;
782 n->second_child = tmp;
783 n->split_ratio = 1.0 - n->split_ratio;
786 flip_tree(n->first_child, flp);
787 flip_tree(n->second_child, flp);
790 int balance_tree(node_t *n)
792 if (n == NULL || n->vacant) {
794 } else if (is_leaf(n)) {
797 int b1 = balance_tree(n->first_child);
798 int b2 = balance_tree(n->second_child);
800 if (b1 > 0 && b2 > 0)
801 n->split_ratio = (double) b1 / b;
806 void unlink_node(monitor_t *m, desktop_t *d, node_t *n)
808 if (d == NULL || n == NULL)
811 PRINTF("unlink node %X\n", n->client->window);
813 node_t *p = n->parent;
820 d->focus = history_get_node(d, n);
821 if (d->focus == NULL)
822 d->focus = closest_visible(d, n);
826 node_t *g = p->parent;
828 if (is_first_child(n)) {
831 unrotate_tree(b, n->birth_rotation);
835 unrotate_tree(b, n->birth_rotation);
841 if (is_first_child(p))
849 b->birth_rotation = p->birth_rotation;
852 update_vacant_state(b->parent);
854 if (n->client->sticky)
859 void remove_node(monitor_t *m, desktop_t *d, node_t *n)
864 PRINTF("remove node %X\n", n->client->window);
866 bool focused = (n == mon->desk->focus);
867 unlink_node(m, d, n);
868 history_remove(d, n);
869 remove_stack_node(n);
874 ewmh_update_client_list();
880 void destroy_tree(node_t *n)
884 node_t *first_tree = n->first_child;
885 node_t *second_tree = n->second_child;
886 if (n->client != NULL)
889 destroy_tree(first_tree);
890 destroy_tree(second_tree);
893 bool swap_nodes(monitor_t *m1, desktop_t *d1, node_t *n1, monitor_t *m2, desktop_t *d2, node_t *n2)
895 if (n1 == NULL || n2 == NULL || n1 == n2 || (d1 != d2 && (n1->client->sticky || n2->client->sticky)))
898 PRINTF("swap nodes %X %X", n1->client->window, n2->client->window);
900 node_t *pn1 = n1->parent;
901 node_t *pn2 = n2->parent;
902 bool n1_first_child = is_first_child(n1);
903 bool n2_first_child = is_first_child(n2);
904 int br1 = n1->birth_rotation;
905 int br2 = n2->birth_rotation;
909 pn1->first_child = n2;
911 pn1->second_child = n2;
916 pn2->first_child = n1;
918 pn2->second_child = n1;
923 n1->birth_rotation = br2;
924 n2->birth_rotation = br1;
926 if (n1->vacant != n2->vacant) {
927 update_vacant_state(n1->parent);
928 update_vacant_state(n2->parent);
942 fit_monitor(m1, n2->client);
943 fit_monitor(m2, n1->client);
946 ewmh_set_wm_desktop(n1, d2);
947 ewmh_set_wm_desktop(n2, d1);
948 history_swap_nodes(m1, d1, n1, m2, d2, n2);
950 if (m1->desk != d1 && m2->desk == d2) {
951 window_show(n1->client->window);
952 window_hide(n2->client->window);
953 } else if (m1->desk == d1 && m2->desk != d2) {
954 window_hide(n1->client->window);
955 window_show(n2->client->window);
958 tag_node(m1, d1, n2, d2, n2->client->tags_field);
959 tag_node(m2, d2, n1, d1, n1->client->tags_field);
961 update_input_focus();
967 bool transfer_node(monitor_t *ms, desktop_t *ds, node_t *ns, monitor_t *md, desktop_t *dd, node_t *nd)
969 if (ns == NULL || ns == nd || (sticky_still && ns->client->sticky))
972 PRINTF("transfer node %X\n", ns->client->window);
974 bool focused = (ns == mon->desk->focus);
975 bool active = (ns == ds->focus);
980 unlink_node(ms, ds, ns);
981 insert_node(md, dd, ns, nd);
984 fit_monitor(md, ns->client);
987 ewmh_set_wm_desktop(ns, dd);
988 if (!ns->client->sticky) {
989 if (ds == ms->desk && dd != md->desk)
990 window_hide(ns->client->window);
991 else if (ds != ms->desk && dd == md->desk)
992 window_show(ns->client->window);
996 history_transfer_node(md, dd, ns);
1001 focus_node(md, dd, ns);
1003 pseudo_focus(dd, ns);
1007 else if (ns == mon->desk->focus)
1008 update_input_focus();
1011 tag_node(md, dd, ns, ds, ns->client->tags_field);
1019 node_t *closest_node(monitor_t *m, desktop_t *d, node_t *n, cycle_dir_t dir, client_select_t sel)
1024 node_t *f = (dir == CYCLE_PREV ? prev_leaf(n, d->root) : next_leaf(n, d->root));
1026 f = (dir == CYCLE_PREV ? second_extrema(d->root) : first_extrema(d->root));
1028 coordinates_t ref = {m, d, n};
1030 coordinates_t loc = {m, d, f};
1031 if (node_matches(&loc, &ref, sel))
1033 f = (dir == CYCLE_PREV ? prev_leaf(f, d->root) : next_leaf(f, d->root));
1035 f = (dir == CYCLE_PREV ? second_extrema(d->root) : first_extrema(d->root));
1040 void circulate_leaves(monitor_t *m, desktop_t *d, circulate_dir_t dir)
1042 if (d == NULL || d->root == NULL || d->focus == NULL || is_leaf(d->root))
1044 node_t *p = d->focus->parent;
1045 bool focus_first_child = is_first_child(d->focus);
1046 node_t *head, *tail;
1047 for (head = first_extrema(d->root); head != NULL && !is_visible(d, head); head = next_leaf(head, d->root))
1049 for (tail = second_extrema(d->root); tail != NULL && !is_visible(d, tail); tail = prev_leaf(tail, d->root))
1053 if (dir == CIRCULATE_FORWARD)
1054 for (node_t *s = tail, *f = prev_visible_leaf(d, s, d->root); f != NULL; s = prev_visible_leaf(d, f, d->root), f = prev_visible_leaf(d, s, d->root))
1055 swap_nodes(m, d, f, m, d, s);
1057 for (node_t *f = head, *s = next_visible_leaf(d, f, d->root); s != NULL; f = next_visible_leaf(d, s, d->root), s = next_visible_leaf(d, f, d->root))
1058 swap_nodes(m, d, f, m, d, s);
1059 if (focus_first_child)
1060 focus_node(m, d, p->first_child);
1062 focus_node(m, d, p->second_child);
1065 void update_vacant_state(node_t *n)
1070 PUTS("update vacant state");
1072 /* n is not a leaf */
1076 p->vacant = (p->first_child->vacant && p->second_child->vacant);