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.
38 void arrange(monitor_t *m, desktop_t *d)
43 PRINTF("arrange %s %s\n", m->name, d->name);
45 xcb_rectangle_t rect = m->rectangle;
46 int wg = (gapless_monocle && d->layout == LAYOUT_MONOCLE ? 0 : d->window_gap);
47 rect.x += m->left_padding + d->left_padding + wg;
48 rect.y += m->top_padding + d->top_padding + wg;
49 rect.width -= m->left_padding + d->left_padding + d->right_padding + m->right_padding + wg;
50 rect.height -= m->top_padding + d->top_padding + d->bottom_padding + m->bottom_padding + wg;
51 apply_layout(m, d, d->root, rect, rect);
54 void apply_layout(monitor_t *m, desktop_t *d, node_t *n, xcb_rectangle_t rect, xcb_rectangle_t root_rect)
63 if ((borderless_monocle && is_tiled(n->client) && d->layout == LAYOUT_MONOCLE)
64 || n->client->fullscreen)
65 n->client->border_width = 0;
67 n->client->border_width = d->border_width;
70 if (!n->client->fullscreen) {
71 if (!n->client->floating) {
72 if (n->client->pseudo_tiled) {
73 /* pseudo-tiled clients */
74 r = n->client->floating_rectangle;
75 center_rectangle(&r, rect);
79 int wg = (gapless_monocle && d->layout == LAYOUT_MONOCLE ? 0 : d->window_gap);
80 int bleed = wg + 2 * n->client->border_width;
81 r.width = (bleed < r.width ? r.width - bleed : 1);
82 r.height = (bleed < r.height ? r.height - bleed : 1);
84 n->client->tiled_rectangle = r;
86 /* floating clients */
87 r = n->client->floating_rectangle;
90 /* fullscreen clients */
94 window_move_resize(n->client->window, r.x, r.y, r.width, r.height);
95 window_border_width(n->client->window, n->client->border_width);
96 window_draw_border(n, d->focus == n, m == mon);
99 xcb_rectangle_t first_rect;
100 xcb_rectangle_t second_rect;
102 if (d->layout == LAYOUT_MONOCLE || n->first_child->vacant || n->second_child->vacant) {
103 first_rect = second_rect = rect;
106 if (n->split_type == TYPE_VERTICAL) {
107 fence = rect.width * n->split_ratio;
108 first_rect = (xcb_rectangle_t) {rect.x, rect.y, fence, rect.height};
109 second_rect = (xcb_rectangle_t) {rect.x + fence, rect.y, rect.width - fence, rect.height};
110 } else if (n->split_type == TYPE_HORIZONTAL) {
111 fence = rect.height * n->split_ratio;
112 first_rect = (xcb_rectangle_t) {rect.x, rect.y, rect.width, fence};
113 second_rect = (xcb_rectangle_t) {rect.x, rect.y + fence, rect.width, rect.height - fence};
117 apply_layout(m, d, n->first_child, first_rect, root_rect);
118 apply_layout(m, d, n->second_child, second_rect, root_rect);
122 void insert_node(monitor_t *m, desktop_t *d, node_t *n, node_t *f)
124 if (d == NULL || n == NULL)
127 PRINTF("insert node %X\n", n->client->window);
129 /* n: new leaf node */
130 /* c: new container node */
131 /* f: focus or insertion anchor */
132 /* p: parent of focus */
133 /* g: grand parent of focus */
141 node_t *c = make_node();
142 node_t *p = f->parent;
143 if (p != NULL && f->split_mode == MODE_AUTOMATIC
144 && (p->first_child->vacant || p->second_child->vacant)) {
148 if (((f->client != NULL && f->client->private) || (p != NULL && p->privacy_level > 0))
149 && f->split_mode == MODE_AUTOMATIC) {
150 node_t *closest = NULL;
151 node_t *public = NULL;
152 closest_public(d, f, &closest, &public);
153 if (public != NULL) {
157 if (closest != NULL) {
161 f->split_mode = MODE_MANUAL;
162 xcb_rectangle_t rect = f->client->tiled_rectangle;
163 f->split_dir = (rect.width >= rect.height ? DIR_LEFT : DIR_UP);
164 if (f->client->private) {
165 get_opposite(f->split_dir, &f->split_dir);
166 update_privacy_level(f, false);
171 c->birth_rotation = f->birth_rotation;
172 switch (f->split_mode) {
177 if (m->rectangle.width > m->rectangle.height)
178 c->split_type = TYPE_VERTICAL;
180 c->split_type = TYPE_HORIZONTAL;
184 node_t *g = p->parent;
187 if (is_first_child(p))
194 c->split_type = p->split_type;
195 c->split_ratio = p->split_ratio;
198 if (is_first_child(f)) {
207 if (!is_floating(n->client))
209 n->birth_rotation = rot;
214 if (is_first_child(f))
219 c->split_ratio = f->split_ratio;
222 f->birth_rotation = 0;
223 switch (f->split_dir) {
225 c->split_type = TYPE_VERTICAL;
230 c->split_type = TYPE_VERTICAL;
235 c->split_type = TYPE_HORIZONTAL;
240 c->split_type = TYPE_HORIZONTAL;
247 f->split_mode = MODE_AUTOMATIC;
251 update_vacant_state(f->parent);
252 if (f->client != NULL && f->client->private)
253 update_privacy_level(f, true);
255 if (n->client->private)
256 update_privacy_level(n, true);
257 if (d->focus == NULL)
259 if (n->client->sticky)
264 void pseudo_focus(monitor_t *m, desktop_t *d, node_t *n)
267 stack(n, STACK_ABOVE);
269 window_draw_border(d->focus, false, m == mon);
270 window_draw_border(n, true, m == mon);
276 void focus_node(monitor_t *m, desktop_t *d, node_t *n)
278 if (mon->desk != d || n == NULL)
281 if (m->num_sticky > 0 && d != m->desk) {
282 node_t *a = first_extrema(m->desk->root);
283 sticky_still = false;
285 node_t *b = next_leaf(a, m->desk->root);
286 if (a->client->sticky)
287 transfer_node(m, m->desk, a, m, d, d->focus);
291 if (n == NULL && d->focus != NULL)
295 if (n != NULL && d->focus != NULL && n != d->focus && d->focus->client->fullscreen) {
296 set_fullscreen(d->focus, false);
301 for (desktop_t *cd = mon->desk_head; cd != NULL; cd = cd->next)
302 window_draw_border(cd->focus, true, false);
303 for (desktop_t *cd = m->desk_head; cd != NULL; cd = cd->next)
305 window_draw_border(cd->focus, true, true);
307 window_draw_border(n, true, true);
311 window_draw_border(d->focus, false, true);
312 window_draw_border(n, true, true);
320 history_add(m, d, NULL);
321 ewmh_update_active_window();
324 stack(n, STACK_ABOVE);
327 PRINTF("focus node %X\n", n->client->window);
329 n->client->urgent = false;
331 history_add(m, d, n);
334 if (focus_follows_pointer) {
335 xcb_window_t win = XCB_NONE;
336 query_pointer(&win, NULL);
337 if (win != n->client->window)
338 enable_motion_recorder();
340 disable_motion_recorder();
343 ewmh_update_active_window();
346 void update_current(void)
348 focus_node(mon, mon->desk, mon->desk->focus);
351 node_t *make_node(void)
353 node_t *n = malloc(sizeof(node_t));
354 n->parent = n->first_child = n->second_child = NULL;
355 n->split_ratio = split_ratio;
356 n->split_mode = MODE_AUTOMATIC;
357 n->split_type = TYPE_VERTICAL;
358 n->birth_rotation = 0;
359 n->privacy_level = 0;
365 client_t *make_client(xcb_window_t win)
367 client_t *c = malloc(sizeof(client_t));
369 snprintf(c->class_name, sizeof(c->class_name), "%s", MISSING_VALUE);
370 snprintf(c->instance_name, sizeof(c->instance_name), "%s", MISSING_VALUE);
371 c->border_width = BORDER_WIDTH;
372 c->pseudo_tiled = c->floating = c->fullscreen = false;
373 c->locked = c->sticky = c->urgent = c->private = c->icccm_focus = false;
374 xcb_icccm_get_wm_protocols_reply_t protocols;
375 if (xcb_icccm_get_wm_protocols_reply(dpy, xcb_icccm_get_wm_protocols(dpy, win, ewmh->WM_PROTOCOLS), &protocols, NULL) == 1) {
376 if (has_proto(WM_TAKE_FOCUS, &protocols))
377 c->icccm_focus = true;
378 xcb_icccm_get_wm_protocols_reply_wipe(&protocols);
381 xcb_ewmh_get_atoms_reply_t wm_state;
382 if (xcb_ewmh_get_wm_state_reply(ewmh, xcb_ewmh_get_wm_state(ewmh, win), &wm_state, NULL) == 1) {
383 for (unsigned int i = 0; i < wm_state.atoms_len && i < MAX_STATE; i++)
384 ewmh_wm_state_add(c, wm_state.atoms[i]);
385 xcb_ewmh_get_atoms_reply_wipe(&wm_state);
390 bool is_leaf(node_t *n)
392 return (n != NULL && n->first_child == NULL && n->second_child == NULL);
395 bool is_tiled(client_t *c)
399 return (!c->floating && !c->fullscreen);
402 bool is_floating(client_t *c)
406 return (c->floating && !c->fullscreen);
409 bool is_first_child(node_t *n)
411 return (n != NULL && n->parent != NULL && n->parent->first_child == n);
414 bool is_second_child(node_t *n)
416 return (n != NULL && n->parent != NULL && n->parent->second_child == n);
419 void reset_mode(coordinates_t *loc)
421 if (loc->node != NULL) {
422 loc->node->split_mode = MODE_AUTOMATIC;
423 window_draw_border(loc->node, loc->desktop->focus == loc->node, mon == loc->monitor);
424 } else if (loc->desktop != NULL) {
425 for (node_t *a = first_extrema(loc->desktop->root); a != NULL; a = next_leaf(a, loc->desktop->root)) {
426 a->split_mode = MODE_AUTOMATIC;
427 window_draw_border(a, loc->desktop->focus == a, mon == loc->monitor);
432 node_t *brother_tree(node_t *n)
434 if (n == NULL || n->parent == NULL)
436 if (is_first_child(n))
437 return n->parent->second_child;
439 return n->parent->first_child;
442 void closest_public(desktop_t *d, node_t *n, node_t **closest, node_t **public)
446 node_t *prev = prev_leaf(n, d->root);
447 node_t *next = next_leaf(n, d->root);
448 while (prev != NULL || next != NULL) {
449 #define TESTLOOP(n) \
451 if (is_tiled(n->client)) { \
452 if (n->privacy_level == 0) { \
453 if (n->parent == NULL || n->parent->privacy_level == 0) { \
456 } else if (*closest == NULL) { \
461 n = n##_leaf(n, d->root); \
469 node_t *first_extrema(node_t *n)
473 else if (n->first_child == NULL)
476 return first_extrema(n->first_child);
479 node_t *second_extrema(node_t *n)
483 else if (n->second_child == NULL)
486 return second_extrema(n->second_child);
489 node_t *next_leaf(node_t *n, node_t *r)
494 while (is_second_child(p) && p != r)
498 return first_extrema(p->parent->second_child);
501 node_t *prev_leaf(node_t *n, node_t *r)
506 while (is_first_child(p) && p != r)
510 return second_extrema(p->parent->first_child);
513 node_t *next_tiled_leaf(desktop_t *d, node_t *n, node_t *r)
515 node_t *next = next_leaf(n, r);
516 if (next == NULL || is_tiled(next->client))
519 return next_tiled_leaf(d, next, r);
522 node_t *prev_tiled_leaf(desktop_t *d, node_t *n, node_t *r)
524 node_t *prev = prev_leaf(n, r);
525 if (prev == NULL || is_tiled(prev->client))
528 return prev_tiled_leaf(d, prev, r);
531 /* bool is_adjacent(node_t *a, node_t *r) */
533 /* node_t *f = r->parent; */
535 /* bool first_child = is_first_child(r); */
536 /* while (p != r) { */
537 /* if (p->parent->split_type == f->split_type && is_first_child(p) == first_child) */
544 /* Returns true if *b* is adjacent to *a* in the direction *dir* */
545 bool is_adjacent(node_t *a, node_t *b, direction_t dir)
549 return (a->rectangle.x + a->rectangle.width) == b->rectangle.x;
552 return (a->rectangle.y + a->rectangle.height) == b->rectangle.y;
555 return (b->rectangle.x + b->rectangle.width) == a->rectangle.x;
558 return (b->rectangle.y + b->rectangle.height) == a->rectangle.y;
564 node_t *find_fence(node_t *n, direction_t dir)
574 if ((dir == DIR_UP && p->split_type == TYPE_HORIZONTAL && p->rectangle.y < n->rectangle.y)
575 || (dir == DIR_LEFT && p->split_type == TYPE_VERTICAL && p->rectangle.x < n->rectangle.x)
576 || (dir == DIR_DOWN && p->split_type == TYPE_HORIZONTAL && (p->rectangle.y + p->rectangle.height) > (n->rectangle.y + n->rectangle.height))
577 || (dir == DIR_RIGHT && p->split_type == TYPE_VERTICAL && (p->rectangle.x + p->rectangle.width) > (n->rectangle.x + n->rectangle.width)))
585 node_t *nearest_neighbor(monitor_t *m, desktop_t *d, node_t *n, direction_t dir, client_select_t sel)
587 if (n == NULL || n->client->fullscreen
588 || (d->layout == LAYOUT_MONOCLE && is_tiled(n->client)))
591 node_t *nearest = NULL;
592 if (history_aware_focus)
593 nearest = nearest_from_history(m, d, n, dir, sel);
595 nearest = nearest_from_distance(m, d, n, dir, sel);
599 node_t *nearest_from_history(monitor_t *m, desktop_t *d, node_t *n, direction_t dir, client_select_t sel)
601 if (n == NULL || !is_tiled(n->client))
604 node_t *target = find_fence(n, dir);
607 if (dir == DIR_UP || dir == DIR_LEFT)
608 target = target->first_child;
609 else if (dir == DIR_DOWN || dir == DIR_RIGHT)
610 target = target->second_child;
612 node_t *nearest = NULL;
613 int min_rank = INT_MAX;
614 coordinates_t ref = {m, d, n};
616 for (node_t *a = first_extrema(target); a != NULL; a = next_leaf(a, target)) {
617 if (a->vacant || !is_adjacent(n, a, dir) || a == n)
619 coordinates_t loc = {m, d, a};
620 if (!node_matches(&loc, &ref, sel))
623 int rank = history_rank(d, a);
624 if (rank >= 0 && rank < min_rank) {
633 node_t *nearest_from_distance(monitor_t *m, desktop_t *d, node_t *n, direction_t dir, client_select_t sel)
638 node_t *target = NULL;
640 if (is_tiled(n->client)) {
641 target = find_fence(n, dir);
644 if (dir == DIR_UP || dir == DIR_LEFT)
645 target = target->first_child;
646 else if (dir == DIR_DOWN || dir == DIR_RIGHT)
647 target = target->second_child;
652 node_t *nearest = NULL;
656 get_side_handle(n->client, dir, &pt);
657 get_opposite(dir, &dir2);
659 coordinates_t ref = {m, d, n};
661 for (node_t *a = first_extrema(target); a != NULL; a = next_leaf(a, target)) {
662 coordinates_t loc = {m, d, a};
664 !node_matches(&loc, &ref, sel) ||
665 is_tiled(a->client) != is_tiled(n->client) ||
666 (is_tiled(a->client) && !is_adjacent(n, a, dir)))
669 get_side_handle(a->client, dir2, &pt2);
670 double ds2 = distance(pt, pt2);
680 void get_opposite(direction_t src, direction_t *dst)
698 int tiled_area(node_t *n)
702 xcb_rectangle_t rect = n->client->tiled_rectangle;
703 return rect.width * rect.height;
706 node_t *find_biggest(monitor_t *m, desktop_t *d, node_t *n, client_select_t sel)
712 int r_area = tiled_area(r);
713 coordinates_t ref = {m, d, n};
715 for (node_t *f = first_extrema(d->root); f != NULL; f = next_leaf(f, d->root)) {
716 coordinates_t loc = {m, d, f};
717 if (!is_tiled(f->client) || !node_matches(&loc, &ref, sel))
719 int f_area = tiled_area(f);
723 } else if (f_area > r_area) {
732 void rotate_tree(node_t *n, int deg)
734 if (n == NULL || is_leaf(n) || deg == 0)
739 if ((deg == 90 && n->split_type == TYPE_HORIZONTAL)
740 || (deg == 270 && n->split_type == TYPE_VERTICAL)
742 tmp = n->first_child;
743 n->first_child = n->second_child;
744 n->second_child = tmp;
745 n->split_ratio = 1.0 - n->split_ratio;
749 if (n->split_type == TYPE_HORIZONTAL)
750 n->split_type = TYPE_VERTICAL;
751 else if (n->split_type == TYPE_VERTICAL)
752 n->split_type = TYPE_HORIZONTAL;
755 rotate_tree(n->first_child, deg);
756 rotate_tree(n->second_child, deg);
759 void rotate_brother(node_t *n)
761 rotate_tree(brother_tree(n), n->birth_rotation);
764 void unrotate_tree(node_t *n, int rot)
768 rotate_tree(n, 360 - rot);
771 void unrotate_brother(node_t *n)
773 unrotate_tree(brother_tree(n), n->birth_rotation);
776 void flip_tree(node_t *n, flip_t flp)
778 if (n == NULL || is_leaf(n))
783 if ((flp == FLIP_HORIZONTAL && n->split_type == TYPE_HORIZONTAL)
784 || (flp == FLIP_VERTICAL && n->split_type == TYPE_VERTICAL)) {
785 tmp = n->first_child;
786 n->first_child = n->second_child;
787 n->second_child = tmp;
788 n->split_ratio = 1.0 - n->split_ratio;
791 flip_tree(n->first_child, flp);
792 flip_tree(n->second_child, flp);
795 void equalize_tree(node_t *n)
797 if (n == NULL || n->vacant) {
800 n->split_ratio = split_ratio;
801 equalize_tree(n->first_child);
802 equalize_tree(n->second_child);
806 int balance_tree(node_t *n)
808 if (n == NULL || n->vacant) {
810 } else if (is_leaf(n)) {
813 int b1 = balance_tree(n->first_child);
814 int b2 = balance_tree(n->second_child);
816 if (b1 > 0 && b2 > 0)
817 n->split_ratio = (double) b1 / b;
822 void unlink_node(monitor_t *m, desktop_t *d, node_t *n)
824 if (d == NULL || n == NULL)
827 PRINTF("unlink node %X\n", n->client->window);
829 node_t *p = n->parent;
835 if (n->client->private)
836 update_privacy_level(n, false);
839 node_t *g = p->parent;
841 if (is_first_child(n)) {
844 unrotate_tree(b, n->birth_rotation);
848 unrotate_tree(b, n->birth_rotation);
854 if (is_first_child(p))
862 b->birth_rotation = p->birth_rotation;
865 update_vacant_state(b->parent);
868 d->focus = history_get_node(d, n);
869 // fallback to the first extrema (`n` is not reachable)
870 if (d->focus == NULL)
871 d->focus = first_extrema(d->root);
874 if (n->client->sticky)
879 void remove_node(monitor_t *m, desktop_t *d, node_t *n)
884 PRINTF("remove node %X\n", n->client->window);
886 bool focused = (n == mon->desk->focus);
887 unlink_node(m, d, n);
888 history_remove(d, n);
889 remove_stack_node(n);
894 ewmh_update_client_list();
900 void destroy_tree(node_t *n)
904 node_t *first_tree = n->first_child;
905 node_t *second_tree = n->second_child;
906 if (n->client != NULL) {
911 destroy_tree(first_tree);
912 destroy_tree(second_tree);
915 bool swap_nodes(monitor_t *m1, desktop_t *d1, node_t *n1, monitor_t *m2, desktop_t *d2, node_t *n2)
917 if (n1 == NULL || n2 == NULL || n1 == n2 || (d1 != d2 && (n1->client->sticky || n2->client->sticky)))
920 PRINTF("swap nodes %X %X\n", n1->client->window, n2->client->window);
922 node_t *pn1 = n1->parent;
923 node_t *pn2 = n2->parent;
924 bool n1_first_child = is_first_child(n1);
925 bool n2_first_child = is_first_child(n2);
926 int br1 = n1->birth_rotation;
927 int br2 = n2->birth_rotation;
928 int pl1 = n1->privacy_level;
929 int pl2 = n2->privacy_level;
933 pn1->first_child = n2;
935 pn1->second_child = n2;
940 pn2->first_child = n1;
942 pn2->second_child = n1;
947 n1->birth_rotation = br2;
948 n2->birth_rotation = br1;
949 n1->privacy_level = pl2;
950 n2->privacy_level = pl1;
952 if (n1->vacant != n2->vacant) {
953 update_vacant_state(n1->parent);
954 update_vacant_state(n2->parent);
957 if (n1->client->private != n2->client->private) {
958 n1->client->private = !n1->client->private;
959 n2->client->private = !n2->client->private;
973 translate_client(m2, m1, n2->client);
974 translate_client(m1, m2, n1->client);
977 ewmh_set_wm_desktop(n1, d2);
978 ewmh_set_wm_desktop(n2, d1);
979 history_swap_nodes(m1, d1, n1, m2, d2, n2);
981 if (m1->desk != d1 && m2->desk == d2) {
982 window_show(n1->client->window);
983 window_hide(n2->client->window);
984 } else if (m1->desk == d1 && m2->desk != d2) {
985 window_hide(n1->client->window);
986 window_show(n2->client->window);
989 update_input_focus();
995 bool transfer_node(monitor_t *ms, desktop_t *ds, node_t *ns, monitor_t *md, desktop_t *dd, node_t *nd)
997 if (ns == NULL || ns == nd || (sticky_still && ns->client->sticky))
1000 PRINTF("transfer node %X\n", ns->client->window);
1002 bool focused = (ns == mon->desk->focus);
1003 bool active = (ns == ds->focus);
1006 clear_input_focus();
1008 unlink_node(ms, ds, ns);
1009 insert_node(md, dd, ns, nd);
1012 translate_client(ms, md, ns->client);
1015 ewmh_set_wm_desktop(ns, dd);
1016 if (!ns->client->sticky) {
1017 if (ds == ms->desk && dd != md->desk)
1018 window_hide(ns->client->window);
1019 else if (ds != ms->desk && dd == md->desk)
1020 window_show(ns->client->window);
1022 if (ns->client->fullscreen && dd->focus != ns)
1023 set_fullscreen(ns, false);
1026 history_transfer_node(md, dd, ns);
1027 stack(ns, STACK_BELOW);
1031 focus_node(md, dd, ns);
1033 pseudo_focus(md, dd, ns);
1037 else if (ns == mon->desk->focus)
1038 update_input_focus();
1048 node_t *closest_node(monitor_t *m, desktop_t *d, node_t *n, cycle_dir_t dir, client_select_t sel)
1053 node_t *f = (dir == CYCLE_PREV ? prev_leaf(n, d->root) : next_leaf(n, d->root));
1055 f = (dir == CYCLE_PREV ? second_extrema(d->root) : first_extrema(d->root));
1057 coordinates_t ref = {m, d, n};
1059 coordinates_t loc = {m, d, f};
1060 if (node_matches(&loc, &ref, sel))
1062 f = (dir == CYCLE_PREV ? prev_leaf(f, d->root) : next_leaf(f, d->root));
1064 f = (dir == CYCLE_PREV ? second_extrema(d->root) : first_extrema(d->root));
1069 void circulate_leaves(monitor_t *m, desktop_t *d, circulate_dir_t dir)
1071 if (d == NULL || d->root == NULL || d->focus == NULL || is_leaf(d->root))
1073 node_t *p = d->focus->parent;
1074 bool focus_first_child = is_first_child(d->focus);
1075 if (dir == CIRCULATE_FORWARD)
1076 for (node_t *s = second_extrema(d->root), *f = prev_tiled_leaf(d, s, d->root); f != NULL; s = prev_tiled_leaf(d, f, d->root), f = prev_tiled_leaf(d, s, d->root))
1077 swap_nodes(m, d, f, m, d, s);
1079 for (node_t *f = first_extrema(d->root), *s = next_tiled_leaf(d, f, d->root); s != NULL; f = next_tiled_leaf(d, s, d->root), s = next_tiled_leaf(d, f, d->root))
1080 swap_nodes(m, d, f, m, d, s);
1081 if (focus_first_child)
1082 focus_node(m, d, p->first_child);
1084 focus_node(m, d, p->second_child);
1087 void update_vacant_state(node_t *n)
1092 PUTS("update vacant state");
1094 /* n is not a leaf */
1098 p->vacant = (p->first_child->vacant && p->second_child->vacant);
1103 void update_privacy_level(node_t *n, bool value)
1105 int v = (value ? 1 : -1);
1106 for (node_t *p = n; p != NULL; p = p->parent)
1107 p->privacy_level += v;