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.
39 void arrange(monitor_t *m, desktop_t *d)
44 PRINTF("arrange %s %s\n", m->name, d->name);
46 xcb_rectangle_t rect = m->rectangle;
47 int wg = (gapless_monocle && d->layout == LAYOUT_MONOCLE ? 0 : d->window_gap);
48 rect.x += m->left_padding + wg;
49 rect.y += m->top_padding + wg;
50 rect.width -= m->left_padding + m->right_padding + wg;
51 rect.height -= m->top_padding + m->bottom_padding + wg;
52 apply_layout(m, d, d->root, rect, rect);
55 void apply_layout(monitor_t *m, desktop_t *d, node_t *n, xcb_rectangle_t rect, xcb_rectangle_t root_rect)
64 if ((borderless_monocle && is_tiled(n->client) && d->layout == LAYOUT_MONOCLE)
65 || n->client->fullscreen
67 n->client->border_width = 0;
69 n->client->border_width = d->border_width;
72 if (!n->client->fullscreen) {
73 if (!n->client->floating) {
75 if (d->layout == LAYOUT_TILED)
77 else if (d->layout == LAYOUT_MONOCLE)
81 int wg = (gapless_monocle && d->layout == LAYOUT_MONOCLE ? 0 : d->window_gap);
82 int bleed = wg + 2 * n->client->border_width;
83 r.width = (bleed < r.width ? r.width - bleed : 1);
84 r.height = (bleed < r.height ? r.height - bleed : 1);
85 n->client->tiled_rectangle = r;
87 /* floating clients */
88 r = n->client->floating_rectangle;
91 /* fullscreen clients */
95 window_move_resize(n->client->window, r.x, r.y, r.width, r.height);
96 window_border_width(n->client->window, n->client->border_width);
97 window_draw_border(n, d->focus == n, m == mon);
100 xcb_rectangle_t first_rect;
101 xcb_rectangle_t second_rect;
103 if (n->first_child->vacant || n->second_child->vacant) {
104 first_rect = second_rect = rect;
107 if (n->split_type == TYPE_VERTICAL) {
108 fence = rect.width * n->split_ratio;
109 first_rect = (xcb_rectangle_t) {rect.x, rect.y, fence, rect.height};
110 second_rect = (xcb_rectangle_t) {rect.x + fence, rect.y, rect.width - fence, rect.height};
111 } else if (n->split_type == TYPE_HORIZONTAL) {
112 fence = rect.height * n->split_ratio;
113 first_rect = (xcb_rectangle_t) {rect.x, rect.y, rect.width, fence};
114 second_rect = (xcb_rectangle_t) {rect.x, rect.y + fence, rect.width, rect.height - fence};
118 apply_layout(m, d, n->first_child, first_rect, root_rect);
119 apply_layout(m, d, n->second_child, second_rect, root_rect);
123 void insert_node(monitor_t *m, desktop_t *d, node_t *n, node_t *f)
125 if (d == NULL || n == NULL)
128 PRINTF("insert node %X\n", n->client->window);
130 /* n: new leaf node */
131 /* c: new container node */
132 /* f: focus or insertion anchor */
133 /* p: parent of focus */
134 /* g: grand parent of focus */
142 node_t *c = make_node();
143 node_t *p = f->parent;
144 if (p != NULL && f->split_mode == MODE_AUTOMATIC
145 && (p->first_child->vacant || p->second_child->vacant)) {
149 if (((f->client != NULL && f->client->private) || (p != NULL && p->privacy_level > 0))
150 && f->split_mode == MODE_AUTOMATIC) {
151 node_t *closest = NULL;
152 node_t *public = NULL;
153 closest_public(d, f, &closest, &public);
154 if (public != NULL) {
158 if (closest != NULL) {
162 f->split_mode = MODE_MANUAL;
163 xcb_rectangle_t rect = f->client->tiled_rectangle;
164 f->split_dir = (rect.width >= rect.height ? DIR_LEFT : DIR_UP);
165 if (f->client->private) {
166 get_opposite(f->split_dir, &f->split_dir);
167 update_privacy_level(f, false);
172 c->birth_rotation = f->birth_rotation;
173 switch (f->split_mode) {
178 if (m->rectangle.width > m->rectangle.height)
179 c->split_type = TYPE_VERTICAL;
181 c->split_type = TYPE_HORIZONTAL;
185 node_t *g = p->parent;
188 if (is_first_child(p))
195 c->split_type = p->split_type;
196 c->split_ratio = p->split_ratio;
199 if (is_first_child(f)) {
208 if (!is_floating(n->client))
210 n->birth_rotation = rot;
215 if (is_first_child(f))
220 c->split_ratio = f->split_ratio;
223 f->birth_rotation = 0;
224 switch (f->split_dir) {
226 c->split_type = TYPE_VERTICAL;
231 c->split_type = TYPE_VERTICAL;
236 c->split_type = TYPE_HORIZONTAL;
241 c->split_type = TYPE_HORIZONTAL;
248 f->split_mode = MODE_AUTOMATIC;
252 update_vacant_state(p);
253 if (f->client != NULL && f->client->private)
254 update_privacy_level(f, true);
256 if (n->client->private)
257 update_privacy_level(n, true);
258 if (d->focus == NULL)
260 if (n->client->sticky)
265 void pseudo_focus(desktop_t *d, node_t *n)
269 stack(n, STACK_ABOVE);
272 void focus_node(monitor_t *m, desktop_t *d, node_t *n)
274 if (mon->desk != d || n == NULL)
277 if (m->num_sticky > 0 && d != m->desk) {
278 node_t *a = first_extrema(m->desk->root);
279 sticky_still = false;
281 node_t *b = next_leaf(a, m->desk->root);
282 if (a->client->sticky)
283 transfer_node(m, m->desk, a, m, d, d->focus);
287 if (n == NULL && d->focus != NULL)
291 if (n != NULL && d->focus != NULL && n != d->focus && d->focus->client->fullscreen) {
292 set_fullscreen(d->focus, false);
297 for (desktop_t *cd = mon->desk_head; cd != NULL; cd = cd->next)
298 window_draw_border(cd->focus, true, false);
299 for (desktop_t *cd = m->desk_head; cd != NULL; cd = cd->next)
301 window_draw_border(cd->focus, true, true);
303 window_draw_border(n, true, true);
307 window_draw_border(d->focus, false, true);
308 window_draw_border(n, true, true);
315 history_add(m, d, NULL);
316 ewmh_update_active_window();
320 PRINTF("focus node %X\n", n->client->window);
322 n->client->urgent = false;
324 history_add(m, d, n);
327 if (focus_follows_pointer) {
328 xcb_window_t win = XCB_NONE;
329 query_pointer(&win, NULL);
330 if (win != n->client->window)
331 enable_motion_recorder();
333 disable_motion_recorder();
336 ewmh_update_active_window();
339 void update_current(void)
341 focus_node(mon, mon->desk, mon->desk->focus);
344 node_t *make_node(void)
346 node_t *n = malloc(sizeof(node_t));
347 n->parent = n->first_child = n->second_child = NULL;
348 n->split_ratio = split_ratio;
349 n->split_mode = MODE_AUTOMATIC;
350 n->split_type = TYPE_VERTICAL;
351 n->birth_rotation = 0;
352 n->privacy_level = 0;
358 client_t *make_client(xcb_window_t win)
360 client_t *c = malloc(sizeof(client_t));
361 snprintf(c->class_name, sizeof(c->class_name), "%s", MISSING_VALUE);
362 c->border_width = BORDER_WIDTH;
364 c->floating = c->transient = c->fullscreen = c->locked = c->sticky = c->urgent = false;
365 c->frame = c->private = c->icccm_focus = false;
366 xcb_icccm_get_wm_protocols_reply_t protocols;
367 if (xcb_icccm_get_wm_protocols_reply(dpy, xcb_icccm_get_wm_protocols(dpy, win, ewmh->WM_PROTOCOLS), &protocols, NULL) == 1) {
368 if (has_proto(WM_TAKE_FOCUS, &protocols))
369 c->icccm_focus = true;
370 xcb_icccm_get_wm_protocols_reply_wipe(&protocols);
373 xcb_ewmh_get_atoms_reply_t wm_state;
374 if (xcb_ewmh_get_wm_state_reply(ewmh, xcb_ewmh_get_wm_state(ewmh, win), &wm_state, NULL) == 1) {
375 for (unsigned int i = 0; i < wm_state.atoms_len && i < MAX_STATE; i++)
376 ewmh_wm_state_add(c, wm_state.atoms[i]);
377 xcb_ewmh_get_atoms_reply_wipe(&wm_state);
382 bool is_leaf(node_t *n)
384 return (n != NULL && n->first_child == NULL && n->second_child == NULL);
387 bool is_tiled(client_t *c)
391 return (!c->floating && !c->fullscreen);
394 bool is_floating(client_t *c)
398 return (c->floating && !c->fullscreen);
401 bool is_first_child(node_t *n)
403 return (n != NULL && n->parent != NULL && n->parent->first_child == n);
406 bool is_second_child(node_t *n)
408 return (n != NULL && n->parent != NULL && n->parent->second_child == n);
411 void change_split_ratio(node_t *n, value_change_t chg)
413 n->split_ratio = pow(n->split_ratio,
414 (chg == CHANGE_INCREASE ? (1 / growth_factor) : growth_factor));
417 void reset_mode(coordinates_t *loc)
419 if (loc->node != NULL) {
420 loc->node->split_mode = MODE_AUTOMATIC;
421 window_draw_border(loc->node, loc->desktop->focus == loc->node, mon == loc->monitor);
422 } else if (loc->desktop != NULL) {
423 for (node_t *a = first_extrema(loc->desktop->root); a != NULL; a = next_leaf(a, loc->desktop->root)) {
424 a->split_mode = MODE_AUTOMATIC;
425 window_draw_border(a, loc->desktop->focus == a, mon == loc->monitor);
430 node_t *brother_tree(node_t *n)
432 if (n == NULL || n->parent == NULL)
434 if (is_first_child(n))
435 return n->parent->second_child;
437 return n->parent->first_child;
440 void closest_public(desktop_t *d, node_t *n, node_t **closest, node_t **public)
444 node_t *prev = prev_leaf(n, d->root);
445 node_t *next = next_leaf(n, d->root);
446 while (prev != NULL || next != NULL) {
447 #define TESTLOOP(n) \
449 if (is_tiled(n->client)) { \
450 if (n->privacy_level == 0) { \
451 if (n->parent == NULL || n->parent->privacy_level == 0) { \
454 } else if (*closest == NULL) { \
459 n = n##_leaf(n, d->root); \
467 node_t *first_extrema(node_t *n)
471 else if (n->first_child == NULL)
474 return first_extrema(n->first_child);
477 node_t *second_extrema(node_t *n)
481 else if (n->second_child == NULL)
484 return second_extrema(n->second_child);
487 node_t *next_leaf(node_t *n, node_t *r)
492 while (is_second_child(p) && p != r)
496 return first_extrema(p->parent->second_child);
499 node_t *prev_leaf(node_t *n, node_t *r)
504 while (is_first_child(p) && p != r)
508 return second_extrema(p->parent->first_child);
511 node_t *next_tiled_leaf(desktop_t *d, node_t *n, node_t *r)
513 node_t *next = next_leaf(n, r);
514 if (next == NULL || is_tiled(next->client))
517 return next_tiled_leaf(d, next, r);
520 node_t *prev_tiled_leaf(desktop_t *d, node_t *n, node_t *r)
522 node_t *prev = prev_leaf(n, r);
523 if (prev == NULL || is_tiled(prev->client))
526 return prev_tiled_leaf(d, prev, r);
529 /* bool is_adjacent(node_t *a, node_t *r) */
531 /* node_t *f = r->parent; */
533 /* bool first_child = is_first_child(r); */
534 /* while (p != r) { */
535 /* if (p->parent->split_type == f->split_type && is_first_child(p) == first_child) */
542 /* Returns true if *b* is adjacent to *a* in the direction *dir* */
543 bool is_adjacent(node_t *a, node_t *b, direction_t dir)
547 return (a->rectangle.x + a->rectangle.width) == b->rectangle.x;
550 return (a->rectangle.y + a->rectangle.height) == b->rectangle.y;
553 return (b->rectangle.x + b->rectangle.width) == a->rectangle.x;
556 return (b->rectangle.y + b->rectangle.height) == a->rectangle.y;
562 node_t *find_fence(node_t *n, direction_t dir)
572 if ((dir == DIR_UP && p->split_type == TYPE_HORIZONTAL && p->rectangle.y < n->rectangle.y)
573 || (dir == DIR_LEFT && p->split_type == TYPE_VERTICAL && p->rectangle.x < n->rectangle.x)
574 || (dir == DIR_DOWN && p->split_type == TYPE_HORIZONTAL && (p->rectangle.y + p->rectangle.height) > (n->rectangle.y + n->rectangle.height))
575 || (dir == DIR_RIGHT && p->split_type == TYPE_VERTICAL && (p->rectangle.x + p->rectangle.width) > (n->rectangle.x + n->rectangle.width)))
583 node_t *nearest_neighbor(monitor_t *m, desktop_t *d, node_t *n, direction_t dir, client_select_t sel)
585 if (n == NULL || n->client->fullscreen
586 || (d->layout == LAYOUT_MONOCLE && is_tiled(n->client)))
589 node_t *nearest = NULL;
590 if (history_aware_focus)
591 nearest = nearest_from_history(m, d, n, dir, sel);
593 nearest = nearest_from_distance(m, d, n, dir, sel);
597 node_t *nearest_from_history(monitor_t *m, desktop_t *d, node_t *n, direction_t dir, client_select_t sel)
599 if (n == NULL || !is_tiled(n->client))
602 node_t *target = find_fence(n, dir);
605 if (dir == DIR_UP || dir == DIR_LEFT)
606 target = target->first_child;
607 else if (dir == DIR_DOWN || dir == DIR_RIGHT)
608 target = target->second_child;
610 node_t *nearest = NULL;
611 int min_rank = INT_MAX;
612 coordinates_t ref = {m, d, n};
614 for (node_t *a = first_extrema(target); a != NULL; a = next_leaf(a, target)) {
615 if (a->vacant || !is_adjacent(n, a, dir) || a == n)
617 coordinates_t loc = {m, d, a};
618 if (!node_matches(&loc, &ref, sel))
621 int rank = history_rank(d, a);
622 if (rank >= 0 && rank < min_rank) {
631 node_t *nearest_from_distance(monitor_t *m, desktop_t *d, node_t *n, direction_t dir, client_select_t sel)
636 node_t *target = NULL;
638 if (is_tiled(n->client)) {
639 target = find_fence(n, dir);
642 if (dir == DIR_UP || dir == DIR_LEFT)
643 target = target->first_child;
644 else if (dir == DIR_DOWN || dir == DIR_RIGHT)
645 target = target->second_child;
650 node_t *nearest = NULL;
654 get_side_handle(n->client, dir, &pt);
655 get_opposite(dir, &dir2);
657 coordinates_t ref = {m, d, n};
659 for (node_t *a = first_extrema(target); a != NULL; a = next_leaf(a, target)) {
660 coordinates_t loc = {m, d, a};
662 !node_matches(&loc, &ref, sel) ||
663 is_tiled(a->client) != is_tiled(n->client) ||
664 (is_tiled(a->client) && !is_adjacent(n, a, dir)))
667 get_side_handle(a->client, dir2, &pt2);
668 double ds2 = distance(pt, pt2);
678 void get_opposite(direction_t src, direction_t *dst)
696 int tiled_area(node_t *n)
700 xcb_rectangle_t rect = n->client->tiled_rectangle;
701 return rect.width * rect.height;
704 node_t *find_biggest(monitor_t *m, desktop_t *d, node_t *n, client_select_t sel)
710 int r_area = tiled_area(r);
711 coordinates_t ref = {m, d, n};
713 for (node_t *f = first_extrema(d->root); f != NULL; f = next_leaf(f, d->root)) {
714 coordinates_t loc = {m, d, f};
715 if (!is_tiled(f->client) || !node_matches(&loc, &ref, sel))
717 int f_area = tiled_area(f);
721 } else if (f_area > r_area) {
730 void move_fence(node_t *n, direction_t dir, fence_move_t mov)
735 if ((mov == MOVE_PUSH && (dir == DIR_RIGHT || dir == DIR_DOWN))
736 || (mov == MOVE_PULL && (dir == DIR_LEFT || dir == DIR_UP)))
737 change_split_ratio(n, CHANGE_INCREASE);
739 change_split_ratio(n, CHANGE_DECREASE);
742 void rotate_tree(node_t *n, int deg)
744 if (n == NULL || is_leaf(n) || deg == 0)
749 if ((deg == 90 && n->split_type == TYPE_HORIZONTAL)
750 || (deg == 270 && n->split_type == TYPE_VERTICAL)
752 tmp = n->first_child;
753 n->first_child = n->second_child;
754 n->second_child = tmp;
755 n->split_ratio = 1.0 - n->split_ratio;
759 if (n->split_type == TYPE_HORIZONTAL)
760 n->split_type = TYPE_VERTICAL;
761 else if (n->split_type == TYPE_VERTICAL)
762 n->split_type = TYPE_HORIZONTAL;
765 rotate_tree(n->first_child, deg);
766 rotate_tree(n->second_child, deg);
769 void rotate_brother(node_t *n)
771 rotate_tree(brother_tree(n), n->birth_rotation);
774 void unrotate_tree(node_t *n, int rot)
778 rotate_tree(n, 360 - rot);
781 void unrotate_brother(node_t *n)
783 unrotate_tree(brother_tree(n), n->birth_rotation);
786 void flip_tree(node_t *n, flip_t flp)
788 if (n == NULL || is_leaf(n))
793 if ((flp == FLIP_HORIZONTAL && n->split_type == TYPE_HORIZONTAL)
794 || (flp == FLIP_VERTICAL && n->split_type == TYPE_VERTICAL)) {
795 tmp = n->first_child;
796 n->first_child = n->second_child;
797 n->second_child = tmp;
798 n->split_ratio = 1.0 - n->split_ratio;
801 flip_tree(n->first_child, flp);
802 flip_tree(n->second_child, flp);
805 int balance_tree(node_t *n)
807 if (n == NULL || n->vacant) {
809 } else if (is_leaf(n)) {
812 int b1 = balance_tree(n->first_child);
813 int b2 = balance_tree(n->second_child);
815 if (b1 > 0 && b2 > 0)
816 n->split_ratio = (double) b1 / b;
821 void unlink_node(monitor_t *m, desktop_t *d, node_t *n)
823 if (d == NULL || n == NULL)
826 PRINTF("unlink node %X\n", n->client->window);
828 node_t *p = n->parent;
835 d->focus = history_get_node(d, n);
836 if (d->focus == NULL)
837 d->focus = first_extrema(d->root);
840 if (n->client->private)
841 update_privacy_level(n, false);
844 node_t *g = p->parent;
846 if (is_first_child(n)) {
849 unrotate_tree(b, n->birth_rotation);
853 unrotate_tree(b, n->birth_rotation);
859 if (is_first_child(p))
867 b->birth_rotation = p->birth_rotation;
870 update_vacant_state(b->parent);
872 if (n->client->sticky)
877 void remove_node(monitor_t *m, desktop_t *d, node_t *n)
882 PRINTF("remove node %X\n", n->client->window);
884 bool focused = (n == mon->desk->focus);
885 unlink_node(m, d, n);
886 history_remove(d, n);
887 remove_stack_node(n);
892 ewmh_update_client_list();
898 void destroy_tree(node_t *n)
902 node_t *first_tree = n->first_child;
903 node_t *second_tree = n->second_child;
904 if (n->client != NULL)
907 destroy_tree(first_tree);
908 destroy_tree(second_tree);
911 bool swap_nodes(monitor_t *m1, desktop_t *d1, node_t *n1, monitor_t *m2, desktop_t *d2, node_t *n2)
913 if (n1 == NULL || n2 == NULL || n1 == n2 || (d1 != d2 && (n1->client->sticky || n2->client->sticky)))
916 PRINTF("swap nodes %X %X", n1->client->window, n2->client->window);
918 node_t *pn1 = n1->parent;
919 node_t *pn2 = n2->parent;
920 bool n1_first_child = is_first_child(n1);
921 bool n2_first_child = is_first_child(n2);
922 int br1 = n1->birth_rotation;
923 int br2 = n2->birth_rotation;
924 int pl1 = n1->privacy_level;
925 int pl2 = n2->privacy_level;
929 pn1->first_child = n2;
931 pn1->second_child = n2;
936 pn2->first_child = n1;
938 pn2->second_child = n1;
943 n1->birth_rotation = br2;
944 n2->birth_rotation = br1;
945 n1->privacy_level = pl2;
946 n2->privacy_level = pl1;
948 if (n1->vacant != n2->vacant) {
949 update_vacant_state(n1->parent);
950 update_vacant_state(n2->parent);
953 if (n1->client->private != n2->client->private) {
954 n1->client->private = !n1->client->private;
955 n2->client->private = !n2->client->private;
969 translate_client(m2, m1, n2->client);
970 translate_client(m1, m2, n1->client);
973 ewmh_set_wm_desktop(n1, d2);
974 ewmh_set_wm_desktop(n2, d1);
975 history_swap_nodes(m1, d1, n1, m2, d2, n2);
977 if (m1->desk != d1 && m2->desk == d2) {
978 window_show(n1->client->window);
979 window_hide(n2->client->window);
980 } else if (m1->desk == d1 && m2->desk != d2) {
981 window_hide(n1->client->window);
982 window_show(n2->client->window);
985 update_input_focus();
991 bool transfer_node(monitor_t *ms, desktop_t *ds, node_t *ns, monitor_t *md, desktop_t *dd, node_t *nd)
993 if (ns == NULL || ns == nd || (sticky_still && ns->client->sticky))
996 PRINTF("transfer node %X\n", ns->client->window);
998 bool focused = (ns == mon->desk->focus);
999 bool active = (ns == ds->focus);
1002 clear_input_focus();
1004 unlink_node(ms, ds, ns);
1005 insert_node(md, dd, ns, nd);
1008 translate_client(ms, md, ns->client);
1011 ewmh_set_wm_desktop(ns, dd);
1012 if (!ns->client->sticky) {
1013 if (ds == ms->desk && dd != md->desk)
1014 window_hide(ns->client->window);
1015 else if (ds != ms->desk && dd == md->desk)
1016 window_show(ns->client->window);
1018 if (ns->client->fullscreen && dd->focus != ns)
1019 set_fullscreen(ns, false);
1022 history_transfer_node(md, dd, ns);
1023 stack(ns, STACK_BELOW);
1027 focus_node(md, dd, ns);
1029 pseudo_focus(dd, ns);
1033 else if (ns == mon->desk->focus)
1034 update_input_focus();
1044 node_t *closest_node(monitor_t *m, desktop_t *d, node_t *n, cycle_dir_t dir, client_select_t sel)
1049 node_t *f = (dir == CYCLE_PREV ? prev_leaf(n, d->root) : next_leaf(n, d->root));
1051 f = (dir == CYCLE_PREV ? second_extrema(d->root) : first_extrema(d->root));
1053 coordinates_t ref = {m, d, n};
1055 coordinates_t loc = {m, d, f};
1056 if (node_matches(&loc, &ref, sel))
1058 f = (dir == CYCLE_PREV ? prev_leaf(f, d->root) : next_leaf(f, d->root));
1060 f = (dir == CYCLE_PREV ? second_extrema(d->root) : first_extrema(d->root));
1065 void circulate_leaves(monitor_t *m, desktop_t *d, circulate_dir_t dir)
1067 if (d == NULL || d->root == NULL || d->focus == NULL || is_leaf(d->root))
1069 node_t *p = d->focus->parent;
1070 bool focus_first_child = is_first_child(d->focus);
1071 if (dir == CIRCULATE_FORWARD)
1072 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))
1073 swap_nodes(m, d, f, m, d, s);
1075 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))
1076 swap_nodes(m, d, f, m, d, s);
1077 if (focus_first_child)
1078 focus_node(m, d, p->first_child);
1080 focus_node(m, d, p->second_child);
1083 void update_vacant_state(node_t *n)
1088 PUTS("update vacant state");
1090 /* n is not a leaf */
1094 p->vacant = (p->first_child->vacant && p->second_child->vacant);
1099 void update_privacy_level(node_t *n, bool value)
1101 int v = (value ? 1 : -1);
1102 for (node_t *p = n; p != NULL; p = p->parent)
1103 p->privacy_level += v;