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)
73 n->client->border_width = 0;
75 n->client->border_width = d->border_width;
78 if (!n->client->fullscreen) {
79 if (!n->client->floating) {
81 if (d->layout == LAYOUT_TILED)
83 else if (d->layout == LAYOUT_MONOCLE)
87 int wg = (gapless_monocle && d->layout == LAYOUT_MONOCLE ? 0 : d->window_gap);
88 int bleed = wg + 2 * n->client->border_width;
89 r.width = (bleed < r.width ? r.width - bleed : 1);
90 r.height = (bleed < r.height ? r.height - bleed : 1);
91 n->client->tiled_rectangle = r;
93 /* floating clients */
94 r = n->client->floating_rectangle;
97 /* fullscreen clients */
101 window_move_resize(n->client->window, r.x, r.y, r.width, r.height);
102 window_border_width(n->client->window, n->client->border_width);
103 window_draw_border(n, n == d->focus, m == mon);
106 xcb_rectangle_t first_rect;
107 xcb_rectangle_t second_rect;
109 if (n->first_child->vacant || n->second_child->vacant) {
110 first_rect = second_rect = rect;
113 if (n->split_type == TYPE_VERTICAL) {
114 fence = rect.width * n->split_ratio;
115 first_rect = (xcb_rectangle_t) {rect.x, rect.y, fence, rect.height};
116 second_rect = (xcb_rectangle_t) {rect.x + fence, rect.y, rect.width - fence, rect.height};
117 } else if (n->split_type == TYPE_HORIZONTAL) {
118 fence = rect.height * n->split_ratio;
119 first_rect = (xcb_rectangle_t) {rect.x, rect.y, rect.width, fence};
120 second_rect = (xcb_rectangle_t) {rect.x, rect.y + fence, rect.width, rect.height - fence};
124 apply_layout(m, d, n->first_child, first_rect, root_rect);
125 apply_layout(m, d, n->second_child, second_rect, root_rect);
129 void insert_node(monitor_t *m, desktop_t *d, node_t *n, node_t *f)
131 if (d == NULL || n == NULL)
134 PRINTF("insert node %X\n", n->client->window);
136 /* n: new leaf node */
137 /* c: new container node */
138 /* f: focus or insertion anchor */
139 /* p: parent of focus */
140 /* g: grand parent of focus */
147 if (is_visible(d, n))
150 node_t *c = make_node();
151 node_t *p = f->parent;
152 if (p != NULL && f->split_mode == MODE_AUTOMATIC
153 && (p->first_child->vacant || p->second_child->vacant)) {
158 c->birth_rotation = f->birth_rotation;
159 switch (f->split_mode) {
164 if (m->rectangle.width > m->rectangle.height)
165 c->split_type = TYPE_VERTICAL;
167 c->split_type = TYPE_HORIZONTAL;
171 node_t *g = p->parent;
174 if (is_first_child(p))
181 c->split_type = p->split_type;
182 c->split_ratio = p->split_ratio;
185 if (is_first_child(f)) {
194 if (!is_floating(n->client))
196 n->birth_rotation = rot;
201 if (is_first_child(f))
206 c->split_ratio = f->split_ratio;
209 f->birth_rotation = 0;
210 switch (f->split_dir) {
212 c->split_type = TYPE_VERTICAL;
217 c->split_type = TYPE_VERTICAL;
222 c->split_type = TYPE_HORIZONTAL;
227 c->split_type = TYPE_HORIZONTAL;
234 f->split_mode = MODE_AUTOMATIC;
238 update_vacant_state(p);
240 if (n->client->sticky)
245 void pseudo_focus(desktop_t *d, node_t *n)
252 void focus_node(monitor_t *m, desktop_t *d, node_t *n)
254 if (mon->desk != d || n == NULL)
257 if (m->num_sticky > 0 && d != m->desk) {
258 node_t *a = first_extrema(m->desk->root);
259 sticky_still = false;
261 node_t *b = next_leaf(a, m->desk->root);
262 if (a->client->sticky)
263 transfer_node(m, m->desk, a, m, d, d->focus);
267 if (n == NULL && d->focus != NULL && is_visible(d, d->focus))
271 if (n != NULL && d->focus != NULL && n != d->focus && d->focus->client->fullscreen) {
272 set_fullscreen(d->focus, false);
277 for (desktop_t *cd = mon->desk_head; cd != NULL; cd = cd->next)
278 window_draw_border(cd->focus, true, false);
279 for (desktop_t *cd = m->desk_head; cd != NULL; cd = cd->next)
281 window_draw_border(cd->focus, true, true);
283 window_draw_border(n, true, true);
287 window_draw_border(d->focus, false, true);
288 window_draw_border(n, true, true);
295 history_add(m, d, NULL);
296 ewmh_update_active_window();
300 PRINTF("focus node %X\n", n->client->window);
302 n->client->urgent = false;
304 if (!is_visible(d, n))
305 tag_node(m, d, n, d, n->client->tags_field | d->tags_field);
306 history_add(m, d, n);
309 if (focus_follows_pointer) {
310 xcb_window_t win = XCB_NONE;
311 query_pointer(&win, NULL);
312 if (win != n->client->window)
313 enable_motion_recorder();
315 disable_motion_recorder();
318 ewmh_update_active_window();
321 void update_current(void)
323 focus_node(mon, mon->desk, mon->desk->focus);
326 node_t *make_node(void)
328 node_t *n = malloc(sizeof(node_t));
329 n->parent = n->first_child = n->second_child = NULL;
330 n->split_ratio = split_ratio;
331 n->split_mode = MODE_AUTOMATIC;
332 n->split_type = TYPE_VERTICAL;
333 n->birth_rotation = 0;
339 client_t *make_client(xcb_window_t win)
341 client_t *c = malloc(sizeof(client_t));
342 snprintf(c->class_name, sizeof(c->class_name), "%s", MISSING_VALUE);
343 c->border_width = BORDER_WIDTH;
345 c->floating = c->transient = c->fullscreen = c->locked = c->sticky = c->urgent = false;
346 c->icccm_focus = false;
347 xcb_icccm_get_wm_protocols_reply_t protocols;
348 if (xcb_icccm_get_wm_protocols_reply(dpy, xcb_icccm_get_wm_protocols(dpy, win, ewmh->WM_PROTOCOLS), &protocols, NULL) == 1) {
349 if (has_proto(WM_TAKE_FOCUS, &protocols))
350 c->icccm_focus = true;
351 xcb_icccm_get_wm_protocols_reply_wipe(&protocols);
354 xcb_ewmh_get_atoms_reply_t wm_state;
355 if (xcb_ewmh_get_wm_state_reply(ewmh, xcb_ewmh_get_wm_state(ewmh, win), &wm_state, NULL) == 1) {
356 for (unsigned int i = 0; i < wm_state.atoms_len && i < MAX_STATE; i++)
357 ewmh_wm_state_add(c, wm_state.atoms[i]);
358 xcb_ewmh_get_atoms_reply_wipe(&wm_state);
363 bool is_visible(desktop_t *d, node_t *n)
365 return (d->tags_field & n->client->tags_field) != 0;
368 bool is_leaf(node_t *n)
370 return (n != NULL && n->first_child == NULL && n->second_child == NULL);
373 bool is_tiled(client_t *c)
377 return (!c->floating && !c->fullscreen);
380 bool is_floating(client_t *c)
384 return (c->floating && !c->fullscreen);
387 bool is_first_child(node_t *n)
389 return (n != NULL && n->parent != NULL && n->parent->first_child == n);
392 bool is_second_child(node_t *n)
394 return (n != NULL && n->parent != NULL && n->parent->second_child == n);
397 void change_split_ratio(node_t *n, value_change_t chg)
399 n->split_ratio = pow(n->split_ratio,
400 (chg == CHANGE_INCREASE ? (1 / growth_factor) : growth_factor));
403 void reset_mode(coordinates_t *loc)
405 if (loc->node != NULL) {
406 loc->node->split_mode = MODE_AUTOMATIC;
407 window_draw_border(loc->node, loc->desktop->focus == loc->node, mon == loc->monitor);
408 } else if (loc->desktop != NULL) {
409 for (node_t *a = first_extrema(loc->desktop->root); a != NULL; a = next_leaf(a, loc->desktop->root)) {
410 a->split_mode = MODE_AUTOMATIC;
411 window_draw_border(a, loc->desktop->focus == a, mon == loc->monitor);
416 node_t *brother_tree(node_t *n)
418 if (n == NULL || n->parent == NULL)
420 if (is_first_child(n))
421 return n->parent->second_child;
423 return n->parent->first_child;
426 node_t *closest_visible(desktop_t *d, node_t *n)
430 node_t *prev = prev_leaf(n, d->root);
431 node_t *next = next_leaf(n, d->root);
432 while (prev != NULL || next != NULL) {
434 if (is_visible(d, prev))
437 prev = prev_leaf(prev, d->root);
440 if (is_visible(d, next))
443 next = next_leaf(next, d->root);
449 node_t *first_extrema(node_t *n)
453 else if (n->first_child == NULL)
456 return first_extrema(n->first_child);
459 node_t *second_extrema(node_t *n)
463 else if (n->second_child == NULL)
466 return second_extrema(n->second_child);
469 node_t *next_leaf(node_t *n, node_t *r)
474 while (is_second_child(p) && p != r)
478 return first_extrema(p->parent->second_child);
481 node_t *prev_leaf(node_t *n, node_t *r)
486 while (is_first_child(p) && p != r)
490 return second_extrema(p->parent->first_child);
493 node_t *next_visible_leaf(desktop_t *d, node_t *n, node_t *r)
495 node_t *next = next_leaf(n, r);
496 if (next == NULL || is_visible(d, next))
499 return next_visible_leaf(d, next, r);
502 node_t *prev_visible_leaf(desktop_t *d, node_t *n, node_t *r)
504 node_t *prev = prev_leaf(n, r);
505 if (prev == NULL || is_visible(d, prev))
508 return prev_visible_leaf(d, prev, r);
511 /* bool is_adjacent(node_t *a, node_t *r) */
513 /* node_t *f = r->parent; */
515 /* bool first_child = is_first_child(r); */
516 /* while (p != r) { */
517 /* if (p->parent->split_type == f->split_type && is_first_child(p) == first_child) */
524 /* Returns true if *b* is adjacent to *a* in the direction *dir* */
525 bool is_adjacent(node_t *a, node_t *b, direction_t dir)
529 return (a->rectangle.x + a->rectangle.width) == b->rectangle.x;
532 return (a->rectangle.y + a->rectangle.height) == b->rectangle.y;
535 return (b->rectangle.x + b->rectangle.width) == a->rectangle.x;
538 return (b->rectangle.y + b->rectangle.height) == a->rectangle.y;
544 node_t *find_fence(node_t *n, direction_t dir)
554 if ((dir == DIR_UP && p->split_type == TYPE_HORIZONTAL && p->rectangle.y < n->rectangle.y)
555 || (dir == DIR_LEFT && p->split_type == TYPE_VERTICAL && p->rectangle.x < n->rectangle.x)
556 || (dir == DIR_DOWN && p->split_type == TYPE_HORIZONTAL && (p->rectangle.y + p->rectangle.height) > (n->rectangle.y + n->rectangle.height))
557 || (dir == DIR_RIGHT && p->split_type == TYPE_VERTICAL && (p->rectangle.x + p->rectangle.width) > (n->rectangle.x + n->rectangle.width)))
566 node_t *nearest_neighbor(monitor_t *m, desktop_t *d, node_t *n, direction_t dir, client_select_t sel)
568 if (n == NULL || n->client->fullscreen
569 || (d->layout == LAYOUT_MONOCLE && is_tiled(n->client)))
572 node_t *nearest = NULL;
573 if (history_aware_focus)
574 nearest = nearest_from_history(m, d, n, dir, sel);
576 nearest = nearest_from_distance(m, d, n, dir, sel);
580 node_t *nearest_from_history(monitor_t *m, desktop_t *d, node_t *n, direction_t dir, client_select_t sel)
582 if (n == NULL || !is_tiled(n->client))
585 node_t *target = find_fence(n, dir);
588 if (dir == DIR_UP || dir == DIR_LEFT)
589 target = target->first_child;
590 else if (dir == DIR_DOWN || dir == DIR_RIGHT)
591 target = target->second_child;
593 node_t *nearest = NULL;
594 int min_rank = INT_MAX;
595 coordinates_t ref = {m, d, n};
597 for (node_t *a = first_extrema(target); a != NULL; a = next_leaf(a, target)) {
598 if (a->vacant || !is_adjacent(n, a, dir) || a == n)
600 coordinates_t loc = {m, d, a};
601 if (!node_matches(&loc, &ref, sel))
604 int rank = history_rank(d, a);
605 if (rank >= 0 && rank < min_rank) {
614 node_t *nearest_from_distance(monitor_t *m, desktop_t *d, node_t *n, direction_t dir, client_select_t sel)
619 node_t *target = NULL;
621 if (is_tiled(n->client)) {
622 target = find_fence(n, dir);
625 if (dir == DIR_UP || dir == DIR_LEFT)
626 target = target->first_child;
627 else if (dir == DIR_DOWN || dir == DIR_RIGHT)
628 target = target->second_child;
633 node_t *nearest = NULL;
637 get_side_handle(n->client, dir, &pt);
638 get_opposite(dir, &dir2);
640 coordinates_t ref = {m, d, n};
642 for (node_t *a = first_extrema(target); a != NULL; a = next_leaf(a, target)) {
643 coordinates_t loc = {m, d, a};
646 !node_matches(&loc, &ref, sel) ||
647 is_tiled(a->client) != is_tiled(n->client) ||
648 (is_tiled(a->client) && !is_adjacent(n, a, dir)))
651 get_side_handle(a->client, dir2, &pt2);
652 double ds2 = distance(pt, pt2);
662 void get_opposite(direction_t src, direction_t *dst)
680 int tiled_area(node_t *n)
684 xcb_rectangle_t rect = n->client->tiled_rectangle;
685 return rect.width * rect.height;
688 node_t *find_biggest(monitor_t *m, desktop_t *d, node_t *n, client_select_t sel)
694 int r_area = tiled_area(r);
695 coordinates_t ref = {m, d, n};
697 for (node_t *f = first_extrema(d->root); f != NULL; f = next_leaf(f, d->root)) {
698 coordinates_t loc = {m, d, f};
699 if (!is_visible(d, f) || !is_tiled(f->client) || !node_matches(&loc, &ref, sel))
701 int f_area = tiled_area(f);
705 } else if (f_area > r_area) {
714 void move_fence(node_t *n, direction_t dir, fence_move_t mov)
719 if ((mov == MOVE_PUSH && (dir == DIR_RIGHT || dir == DIR_DOWN))
720 || (mov == MOVE_PULL && (dir == DIR_LEFT || dir == DIR_UP)))
721 change_split_ratio(n, CHANGE_INCREASE);
723 change_split_ratio(n, CHANGE_DECREASE);
726 void rotate_tree(node_t *n, int deg)
728 if (n == NULL || is_leaf(n) || deg == 0)
733 if ((deg == 90 && n->split_type == TYPE_HORIZONTAL)
734 || (deg == 270 && n->split_type == TYPE_VERTICAL)
736 tmp = n->first_child;
737 n->first_child = n->second_child;
738 n->second_child = tmp;
739 n->split_ratio = 1.0 - n->split_ratio;
743 if (n->split_type == TYPE_HORIZONTAL)
744 n->split_type = TYPE_VERTICAL;
745 else if (n->split_type == TYPE_VERTICAL)
746 n->split_type = TYPE_HORIZONTAL;
749 rotate_tree(n->first_child, deg);
750 rotate_tree(n->second_child, deg);
753 void rotate_brother(node_t *n)
755 rotate_tree(brother_tree(n), n->birth_rotation);
758 void unrotate_tree(node_t *n, int rot)
762 rotate_tree(n, 360 - rot);
765 void unrotate_brother(node_t *n)
767 unrotate_tree(brother_tree(n), n->birth_rotation);
770 void flip_tree(node_t *n, flip_t flp)
772 if (n == NULL || is_leaf(n))
777 if ((flp == FLIP_HORIZONTAL && n->split_type == TYPE_HORIZONTAL)
778 || (flp == FLIP_VERTICAL && n->split_type == TYPE_VERTICAL)) {
779 tmp = n->first_child;
780 n->first_child = n->second_child;
781 n->second_child = tmp;
782 n->split_ratio = 1.0 - n->split_ratio;
785 flip_tree(n->first_child, flp);
786 flip_tree(n->second_child, flp);
789 int balance_tree(node_t *n)
791 if (n == NULL || n->vacant) {
793 } else if (is_leaf(n)) {
796 int b1 = balance_tree(n->first_child);
797 int b2 = balance_tree(n->second_child);
799 if (b1 > 0 && b2 > 0)
800 n->split_ratio = (double) b1 / b;
805 void unlink_node(monitor_t *m, desktop_t *d, node_t *n)
807 if (d == NULL || n == NULL)
810 PRINTF("unlink node %X\n", n->client->window);
812 node_t *p = n->parent;
819 d->focus = history_get_node(d, n);
820 if (d->focus == NULL)
821 d->focus = closest_visible(d, n);
825 node_t *g = p->parent;
827 if (is_first_child(n)) {
830 unrotate_tree(b, n->birth_rotation);
834 unrotate_tree(b, n->birth_rotation);
840 if (is_first_child(p))
848 b->birth_rotation = p->birth_rotation;
851 update_vacant_state(b->parent);
853 if (n->client->sticky)
858 void remove_node(monitor_t *m, desktop_t *d, node_t *n)
863 PRINTF("remove node %X\n", n->client->window);
865 bool focused = (n == mon->desk->focus);
866 unlink_node(m, d, n);
867 history_remove(d, n);
868 remove_stack_node(n);
873 ewmh_update_client_list();
879 void destroy_tree(node_t *n)
883 node_t *first_tree = n->first_child;
884 node_t *second_tree = n->second_child;
885 if (n->client != NULL)
888 destroy_tree(first_tree);
889 destroy_tree(second_tree);
892 bool swap_nodes(monitor_t *m1, desktop_t *d1, node_t *n1, monitor_t *m2, desktop_t *d2, node_t *n2)
894 if (n1 == NULL || n2 == NULL || n1 == n2 || (d1 != d2 && (n1->client->sticky || n2->client->sticky)))
897 PRINTF("swap nodes %X %X", n1->client->window, n2->client->window);
899 node_t *pn1 = n1->parent;
900 node_t *pn2 = n2->parent;
901 bool n1_first_child = is_first_child(n1);
902 bool n2_first_child = is_first_child(n2);
903 int br1 = n1->birth_rotation;
904 int br2 = n2->birth_rotation;
908 pn1->first_child = n2;
910 pn1->second_child = n2;
915 pn2->first_child = n1;
917 pn2->second_child = n1;
922 n1->birth_rotation = br2;
923 n2->birth_rotation = br1;
925 if (n1->vacant != n2->vacant) {
926 update_vacant_state(n1->parent);
927 update_vacant_state(n2->parent);
941 fit_monitor(m1, n2->client);
942 fit_monitor(m2, n1->client);
945 ewmh_set_wm_desktop(n1, d2);
946 ewmh_set_wm_desktop(n2, d1);
947 history_swap_nodes(m1, d1, n1, m2, d2, n2);
949 if (m1->desk != d1 && m2->desk == d2) {
950 window_show(n1->client->window);
951 window_hide(n2->client->window);
952 } else if (m1->desk == d1 && m2->desk != d2) {
953 window_hide(n1->client->window);
954 window_show(n2->client->window);
957 tag_node(m1, d1, n2, d2, n2->client->tags_field);
958 tag_node(m2, d2, n1, d1, n1->client->tags_field);
960 update_input_focus();
966 bool transfer_node(monitor_t *ms, desktop_t *ds, node_t *ns, monitor_t *md, desktop_t *dd, node_t *nd)
968 if (ns == NULL || ns == nd || (sticky_still && ns->client->sticky))
971 PRINTF("transfer node %X\n", ns->client->window);
973 bool focused = (ns == mon->desk->focus);
974 bool active = (ns == ds->focus);
979 unlink_node(ms, ds, ns);
980 insert_node(md, dd, ns, nd);
983 fit_monitor(md, ns->client);
986 ewmh_set_wm_desktop(ns, dd);
987 if (!ns->client->sticky) {
988 if (ds == ms->desk && dd != md->desk)
989 window_hide(ns->client->window);
990 else if (ds != ms->desk && dd == md->desk)
991 window_show(ns->client->window);
995 history_transfer_node(md, dd, ns);
1000 focus_node(md, dd, ns);
1002 pseudo_focus(dd, ns);
1006 else if (ns == mon->desk->focus)
1007 update_input_focus();
1010 tag_node(md, dd, ns, ds, ns->client->tags_field);
1018 node_t *closest_node(monitor_t *m, desktop_t *d, node_t *n, cycle_dir_t dir, client_select_t sel)
1023 node_t *f = (dir == CYCLE_PREV ? prev_leaf(n, d->root) : next_leaf(n, d->root));
1025 f = (dir == CYCLE_PREV ? second_extrema(d->root) : first_extrema(d->root));
1027 coordinates_t ref = {m, d, n};
1029 coordinates_t loc = {m, d, f};
1030 if (node_matches(&loc, &ref, sel))
1032 f = (dir == CYCLE_PREV ? prev_leaf(f, d->root) : next_leaf(f, d->root));
1034 f = (dir == CYCLE_PREV ? second_extrema(d->root) : first_extrema(d->root));
1039 void circulate_leaves(monitor_t *m, desktop_t *d, circulate_dir_t dir)
1041 if (d == NULL || d->root == NULL || d->focus == NULL || is_leaf(d->root))
1043 node_t *p = d->focus->parent;
1044 bool focus_first_child = is_first_child(d->focus);
1045 node_t *head, *tail;
1046 for (head = first_extrema(d->root); head != NULL && !is_visible(d, head); head = next_leaf(head, d->root))
1048 for (tail = second_extrema(d->root); tail != NULL && !is_visible(d, tail); tail = prev_leaf(tail, d->root))
1052 if (dir == CIRCULATE_FORWARD)
1053 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))
1054 swap_nodes(m, d, f, m, d, s);
1056 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))
1057 swap_nodes(m, d, f, m, d, s);
1058 if (focus_first_child)
1059 focus_node(m, d, p->first_child);
1061 focus_node(m, d, p->second_child);
1064 void update_vacant_state(node_t *n)
1069 PUTS("update vacant state");
1071 /* n is not a leaf */
1075 p->vacant = (p->first_child->vacant && p->second_child->vacant);