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.
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)
64 if ((borderless_monocle && is_tiled(n->client) &&
65 !n->client->pseudo_tiled &&
66 d->layout == LAYOUT_MONOCLE) ||
67 n->client->fullscreen)
70 bw = n->client->border_width;
73 if (!n->client->fullscreen) {
74 if (!n->client->floating) {
75 int wg = (gapless_monocle && d->layout == LAYOUT_MONOCLE ? 0 : d->window_gap);
76 if (n->client->pseudo_tiled) {
77 /* pseudo-tiled clients */
78 r = n->client->floating_rectangle;
79 if (center_pseudo_tiled) {
80 r.x = rect.x - bw + (rect.width - wg - r.width) / 2;
81 r.y = rect.y - bw + (rect.height - wg - r.height) / 2;
89 int bleed = wg + 2 * bw;
90 r.width = (bleed < r.width ? r.width - bleed : 1);
91 r.height = (bleed < r.height ? r.height - bleed : 1);
93 n->client->tiled_rectangle = r;
95 /* floating clients */
96 r = n->client->floating_rectangle;
99 /* fullscreen clients */
103 window_move_resize(n->client->window, r.x, r.y, r.width, r.height);
104 window_border_width(n->client->window, bw);
105 window_draw_border(n, d->focus == n, m == mon);
107 if (pointer_follows_focus && mon->desk->focus == n && frozen_pointer->action == ACTION_NONE) {
112 xcb_rectangle_t first_rect;
113 xcb_rectangle_t second_rect;
115 if (d->layout == LAYOUT_MONOCLE || n->first_child->vacant || n->second_child->vacant) {
116 first_rect = second_rect = rect;
119 if (n->split_type == TYPE_VERTICAL) {
120 fence = rect.width * n->split_ratio;
121 first_rect = (xcb_rectangle_t) {rect.x, rect.y, fence, rect.height};
122 second_rect = (xcb_rectangle_t) {rect.x + fence, rect.y, rect.width - fence, rect.height};
124 fence = rect.height * n->split_ratio;
125 first_rect = (xcb_rectangle_t) {rect.x, rect.y, rect.width, fence};
126 second_rect = (xcb_rectangle_t) {rect.x, rect.y + fence, rect.width, rect.height - fence};
130 apply_layout(m, d, n->first_child, first_rect, root_rect);
131 apply_layout(m, d, n->second_child, second_rect, root_rect);
135 void insert_node(monitor_t *m, desktop_t *d, node_t *n, node_t *f)
137 if (d == NULL || n == NULL)
140 PRINTF("insert node %X\n", n->client->window);
142 /* n: new leaf node */
143 /* c: new container node */
144 /* f: focus or insertion anchor */
145 /* p: parent of focus */
146 /* g: grand parent of focus */
154 node_t *c = make_node();
155 node_t *p = f->parent;
156 if ((f->client->private ||
157 (p != NULL && p->privacy_level > 0)) &&
158 f->split_mode == MODE_AUTOMATIC) {
159 node_t *closest = NULL;
160 node_t *public = NULL;
161 closest_public(d, f, &closest, &public);
162 if (public != NULL) {
166 if (closest != NULL) {
170 f->split_mode = MODE_MANUAL;
171 xcb_rectangle_t rect = f->client->tiled_rectangle;
172 f->split_dir = (rect.width >= rect.height ? DIR_LEFT : DIR_UP);
173 if (f->client->private) {
174 get_opposite(f->split_dir, &f->split_dir);
175 update_privacy_level(f, false);
179 if (p != NULL && f->split_mode == MODE_AUTOMATIC &&
180 (p->first_child->vacant || p->second_child->vacant)) {
185 c->birth_rotation = f->birth_rotation;
186 switch (f->split_mode) {
189 if (initial_polarity == FIRST_CHILD) {
196 if (m->rectangle.width > m->rectangle.height)
197 c->split_type = TYPE_VERTICAL;
199 c->split_type = TYPE_HORIZONTAL;
203 node_t *g = p->parent;
206 if (is_first_child(p))
213 c->split_type = p->split_type;
214 c->split_ratio = p->split_ratio;
217 if (is_first_child(f)) {
226 if (!is_floating(n->client))
228 n->birth_rotation = rot;
233 if (is_first_child(f))
238 c->split_ratio = f->split_ratio;
241 f->birth_rotation = 0;
242 switch (f->split_dir) {
244 c->split_type = TYPE_VERTICAL;
249 c->split_type = TYPE_VERTICAL;
254 c->split_type = TYPE_HORIZONTAL;
259 c->split_type = TYPE_HORIZONTAL;
266 f->split_mode = MODE_AUTOMATIC;
270 update_vacant_state(f->parent);
271 if (f->client != NULL && f->client->private)
272 update_privacy_level(f, true);
274 if (n->client->private)
275 update_privacy_level(n, true);
276 if (d->focus == NULL)
278 if (n->client->sticky)
283 void pseudo_focus(monitor_t *m, desktop_t *d, node_t *n)
286 stack(n, STACK_ABOVE);
288 window_draw_border(d->focus, false, m == mon);
289 window_draw_border(n, true, m == mon);
295 void focus_node(monitor_t *m, desktop_t *d, node_t *n)
297 if (mon->desk != d || n == NULL)
300 if (m->num_sticky > 0 && d != m->desk) {
301 node_t *a = first_extrema(m->desk->root);
302 sticky_still = false;
304 node_t *b = next_leaf(a, m->desk->root);
305 if (a->client->sticky)
306 transfer_node(m, m->desk, a, m, d, d->focus);
310 if (n == NULL && d->focus != NULL)
315 if (d->focus != NULL && n != d->focus && d->focus->client->fullscreen) {
316 set_fullscreen(d->focus, false);
319 if (n->client->urgent) {
320 n->client->urgent = false;
326 for (desktop_t *cd = mon->desk_head; cd != NULL; cd = cd->next)
327 window_draw_border(cd->focus, true, false);
328 for (desktop_t *cd = m->desk_head; cd != NULL; cd = cd->next)
330 window_draw_border(cd->focus, true, true);
332 window_draw_border(n, true, true);
336 window_draw_border(d->focus, false, true);
337 window_draw_border(n, true, true);
345 history_add(m, d, NULL);
346 ewmh_update_active_window();
349 stack(n, STACK_ABOVE);
352 PRINTF("focus node %X\n", n->client->window);
354 history_add(m, d, n);
357 if (focus_follows_pointer) {
358 xcb_window_t win = XCB_NONE;
359 query_pointer(&win, NULL);
360 if (win != n->client->window)
361 enable_motion_recorder();
363 disable_motion_recorder();
366 if (pointer_follows_focus) {
367 center_pointer(get_rectangle(n->client));
370 ewmh_update_active_window();
373 void update_current(void)
375 focus_node(mon, mon->desk, mon->desk->focus);
378 node_t *make_node(void)
380 node_t *n = malloc(sizeof(node_t));
381 n->parent = n->first_child = n->second_child = NULL;
382 n->split_ratio = split_ratio;
383 n->split_mode = MODE_AUTOMATIC;
384 n->split_type = TYPE_VERTICAL;
385 n->birth_rotation = 0;
386 n->privacy_level = 0;
392 client_t *make_client(xcb_window_t win, unsigned int border_width)
394 client_t *c = malloc(sizeof(client_t));
396 snprintf(c->class_name, sizeof(c->class_name), "%s", MISSING_VALUE);
397 snprintf(c->instance_name, sizeof(c->instance_name), "%s", MISSING_VALUE);
398 c->border_width = border_width;
399 c->pseudo_tiled = c->floating = c->fullscreen = false;
400 c->locked = c->sticky = c->urgent = c->private = c->icccm_focus = false;
401 xcb_icccm_get_wm_protocols_reply_t protocols;
402 if (xcb_icccm_get_wm_protocols_reply(dpy, xcb_icccm_get_wm_protocols(dpy, win, ewmh->WM_PROTOCOLS), &protocols, NULL) == 1) {
403 if (has_proto(WM_TAKE_FOCUS, &protocols))
404 c->icccm_focus = true;
405 xcb_icccm_get_wm_protocols_reply_wipe(&protocols);
408 xcb_ewmh_get_atoms_reply_t wm_state;
409 if (xcb_ewmh_get_wm_state_reply(ewmh, xcb_ewmh_get_wm_state(ewmh, win), &wm_state, NULL) == 1) {
410 for (unsigned int i = 0; i < wm_state.atoms_len && i < MAX_STATE; i++)
411 ewmh_wm_state_add(c, wm_state.atoms[i]);
412 xcb_ewmh_get_atoms_reply_wipe(&wm_state);
417 bool is_leaf(node_t *n)
419 return (n != NULL && n->first_child == NULL && n->second_child == NULL);
422 bool is_tiled(client_t *c)
426 return (!c->floating && !c->fullscreen);
429 bool is_floating(client_t *c)
433 return (c->floating && !c->fullscreen);
436 bool is_first_child(node_t *n)
438 return (n != NULL && n->parent != NULL && n->parent->first_child == n);
441 bool is_second_child(node_t *n)
443 return (n != NULL && n->parent != NULL && n->parent->second_child == n);
446 void reset_mode(coordinates_t *loc)
448 if (loc->node != NULL) {
449 loc->node->split_mode = MODE_AUTOMATIC;
450 window_draw_border(loc->node, loc->desktop->focus == loc->node, mon == loc->monitor);
451 } else if (loc->desktop != NULL) {
452 for (node_t *a = first_extrema(loc->desktop->root); a != NULL; a = next_leaf(a, loc->desktop->root)) {
453 a->split_mode = MODE_AUTOMATIC;
454 window_draw_border(a, loc->desktop->focus == a, mon == loc->monitor);
459 node_t *brother_tree(node_t *n)
461 if (n == NULL || n->parent == NULL)
463 if (is_first_child(n))
464 return n->parent->second_child;
466 return n->parent->first_child;
469 void closest_public(desktop_t *d, node_t *n, node_t **closest, node_t **public)
473 node_t *prev = prev_leaf(n, d->root);
474 node_t *next = next_leaf(n, d->root);
475 while (prev != NULL || next != NULL) {
476 #define TESTLOOP(n) \
478 if (is_tiled(n->client)) { \
479 if (n->privacy_level == 0) { \
480 if (n->parent == NULL || n->parent->privacy_level == 0) { \
483 } else if (*closest == NULL) { \
488 n = n##_leaf(n, d->root); \
496 node_t *first_extrema(node_t *n)
500 else if (n->first_child == NULL)
503 return first_extrema(n->first_child);
506 node_t *second_extrema(node_t *n)
510 else if (n->second_child == NULL)
513 return second_extrema(n->second_child);
516 node_t *next_leaf(node_t *n, node_t *r)
521 while (is_second_child(p) && p != r)
525 return first_extrema(p->parent->second_child);
528 node_t *prev_leaf(node_t *n, node_t *r)
533 while (is_first_child(p) && p != r)
537 return second_extrema(p->parent->first_child);
540 node_t *next_tiled_leaf(desktop_t *d, node_t *n, node_t *r)
542 node_t *next = next_leaf(n, r);
543 if (next == NULL || is_tiled(next->client))
546 return next_tiled_leaf(d, next, r);
549 node_t *prev_tiled_leaf(desktop_t *d, node_t *n, node_t *r)
551 node_t *prev = prev_leaf(n, r);
552 if (prev == NULL || is_tiled(prev->client))
555 return prev_tiled_leaf(d, prev, r);
558 /* bool is_adjacent(node_t *a, node_t *r) */
560 /* node_t *f = r->parent; */
562 /* bool first_child = is_first_child(r); */
563 /* while (p != r) { */
564 /* if (p->parent->split_type == f->split_type && is_first_child(p) == first_child) */
571 /* Returns true if *b* is adjacent to *a* in the direction *dir* */
572 bool is_adjacent(node_t *a, node_t *b, direction_t dir)
576 return (a->rectangle.x + a->rectangle.width) == b->rectangle.x;
579 return (a->rectangle.y + a->rectangle.height) == b->rectangle.y;
582 return (b->rectangle.x + b->rectangle.width) == a->rectangle.x;
585 return (b->rectangle.y + b->rectangle.height) == a->rectangle.y;
591 node_t *find_fence(node_t *n, direction_t dir)
601 if ((dir == DIR_UP && p->split_type == TYPE_HORIZONTAL && p->rectangle.y < n->rectangle.y) ||
602 (dir == DIR_LEFT && p->split_type == TYPE_VERTICAL && p->rectangle.x < n->rectangle.x) ||
603 (dir == DIR_DOWN && p->split_type == TYPE_HORIZONTAL && (p->rectangle.y + p->rectangle.height) > (n->rectangle.y + n->rectangle.height)) ||
604 (dir == DIR_RIGHT && p->split_type == TYPE_VERTICAL && (p->rectangle.x + p->rectangle.width) > (n->rectangle.x + n->rectangle.width)))
612 node_t *nearest_neighbor(monitor_t *m, desktop_t *d, node_t *n, direction_t dir, client_select_t sel)
614 if (n == NULL || n->client->fullscreen ||
615 (d->layout == LAYOUT_MONOCLE && is_tiled(n->client)))
618 node_t *nearest = NULL;
619 if (history_aware_focus)
620 nearest = nearest_from_history(m, d, n, dir, sel);
621 if (nearest == NULL) {
622 if (focus_by_distance) {
623 nearest = nearest_from_distance(m, d, n, dir, sel);
625 nearest = nearest_from_tree(m, d, n, dir, sel);
631 node_t *nearest_from_tree(monitor_t *m, desktop_t *d, node_t *n, direction_t dir, client_select_t sel)
636 node_t *fence = find_fence(n, dir);
641 node_t *nearest = NULL;
643 if (dir == DIR_UP || dir == DIR_LEFT)
644 nearest = second_extrema(fence->first_child);
645 else if (dir == DIR_DOWN || dir == DIR_RIGHT)
646 nearest = first_extrema(fence->second_child);
648 coordinates_t ref = {m, d, n};
649 coordinates_t loc = {m, d, nearest};
651 if (node_matches(&loc, &ref, sel))
657 node_t *nearest_from_history(monitor_t *m, desktop_t *d, node_t *n, direction_t dir, client_select_t sel)
659 if (n == NULL || !is_tiled(n->client))
662 node_t *target = find_fence(n, dir);
665 if (dir == DIR_UP || dir == DIR_LEFT)
666 target = target->first_child;
667 else if (dir == DIR_DOWN || dir == DIR_RIGHT)
668 target = target->second_child;
670 node_t *nearest = NULL;
671 int min_rank = INT_MAX;
672 coordinates_t ref = {m, d, n};
674 for (node_t *a = first_extrema(target); a != NULL; a = next_leaf(a, target)) {
675 if (a->vacant || !is_adjacent(n, a, dir) || a == n)
677 coordinates_t loc = {m, d, a};
678 if (!node_matches(&loc, &ref, sel))
681 int rank = history_rank(d, a);
682 if (rank >= 0 && rank < min_rank) {
691 node_t *nearest_from_distance(monitor_t *m, desktop_t *d, node_t *n, direction_t dir, client_select_t sel)
696 node_t *target = NULL;
698 if (is_tiled(n->client)) {
699 target = find_fence(n, dir);
702 if (dir == DIR_UP || dir == DIR_LEFT)
703 target = target->first_child;
704 else if (dir == DIR_DOWN || dir == DIR_RIGHT)
705 target = target->second_child;
710 node_t *nearest = NULL;
714 get_side_handle(n->client, dir, &pt);
715 get_opposite(dir, &dir2);
717 coordinates_t ref = {m, d, n};
719 for (node_t *a = first_extrema(target); a != NULL; a = next_leaf(a, target)) {
720 coordinates_t loc = {m, d, a};
722 !node_matches(&loc, &ref, sel) ||
723 is_tiled(a->client) != is_tiled(n->client) ||
724 (is_tiled(a->client) && !is_adjacent(n, a, dir)))
727 get_side_handle(a->client, dir2, &pt2);
728 double ds2 = distance(pt, pt2);
738 void get_opposite(direction_t src, direction_t *dst)
756 int tiled_area(node_t *n)
760 xcb_rectangle_t rect = n->client->tiled_rectangle;
761 return rect.width * rect.height;
764 node_t *find_biggest(monitor_t *m, desktop_t *d, node_t *n, client_select_t sel)
770 int r_area = tiled_area(r);
771 coordinates_t ref = {m, d, n};
773 for (node_t *f = first_extrema(d->root); f != NULL; f = next_leaf(f, d->root)) {
774 coordinates_t loc = {m, d, f};
775 if (!is_tiled(f->client) || !node_matches(&loc, &ref, sel))
777 int f_area = tiled_area(f);
781 } else if (f_area > r_area) {
790 void rotate_tree(node_t *n, int deg)
792 if (n == NULL || is_leaf(n) || deg == 0)
797 if ((deg == 90 && n->split_type == TYPE_HORIZONTAL) ||
798 (deg == 270 && n->split_type == TYPE_VERTICAL) ||
800 tmp = n->first_child;
801 n->first_child = n->second_child;
802 n->second_child = tmp;
803 n->split_ratio = 1.0 - n->split_ratio;
807 if (n->split_type == TYPE_HORIZONTAL)
808 n->split_type = TYPE_VERTICAL;
809 else if (n->split_type == TYPE_VERTICAL)
810 n->split_type = TYPE_HORIZONTAL;
813 rotate_tree(n->first_child, deg);
814 rotate_tree(n->second_child, deg);
817 void rotate_brother(node_t *n)
819 rotate_tree(brother_tree(n), n->birth_rotation);
822 void unrotate_tree(node_t *n, int rot)
826 rotate_tree(n, 360 - rot);
829 void unrotate_brother(node_t *n)
831 unrotate_tree(brother_tree(n), n->birth_rotation);
834 void flip_tree(node_t *n, flip_t flp)
836 if (n == NULL || is_leaf(n))
841 if ((flp == FLIP_HORIZONTAL && n->split_type == TYPE_HORIZONTAL) ||
842 (flp == FLIP_VERTICAL && n->split_type == TYPE_VERTICAL)) {
843 tmp = n->first_child;
844 n->first_child = n->second_child;
845 n->second_child = tmp;
846 n->split_ratio = 1.0 - n->split_ratio;
849 flip_tree(n->first_child, flp);
850 flip_tree(n->second_child, flp);
853 void equalize_tree(node_t *n)
855 if (n == NULL || n->vacant) {
858 n->split_ratio = split_ratio;
859 equalize_tree(n->first_child);
860 equalize_tree(n->second_child);
864 int balance_tree(node_t *n)
866 if (n == NULL || n->vacant) {
868 } else if (is_leaf(n)) {
871 int b1 = balance_tree(n->first_child);
872 int b2 = balance_tree(n->second_child);
874 if (b1 > 0 && b2 > 0)
875 n->split_ratio = (double) b1 / b;
880 void unlink_node(monitor_t *m, desktop_t *d, node_t *n)
882 if (d == NULL || n == NULL)
885 PRINTF("unlink node %X\n", n->client->window);
887 node_t *p = n->parent;
893 if (n->client->private)
894 update_privacy_level(n, false);
897 node_t *g = p->parent;
899 if (is_first_child(n)) {
902 unrotate_tree(b, n->birth_rotation);
906 unrotate_tree(b, n->birth_rotation);
912 if (is_first_child(p))
920 b->birth_rotation = p->birth_rotation;
923 update_vacant_state(b->parent);
926 d->focus = history_get_node(d, n);
927 // fallback to the first extrema (`n` is not reachable)
928 if (d->focus == NULL)
929 d->focus = first_extrema(d->root);
932 if (n->client->sticky)
937 void remove_node(monitor_t *m, desktop_t *d, node_t *n)
942 PRINTF("remove node %X\n", n->client->window);
944 bool focused = (n == mon->desk->focus);
945 unlink_node(m, d, n);
946 history_remove(d, n);
947 remove_stack_node(n);
952 ewmh_update_client_list();
958 void destroy_tree(node_t *n)
962 node_t *first_tree = n->first_child;
963 node_t *second_tree = n->second_child;
964 if (n->client != NULL) {
969 destroy_tree(first_tree);
970 destroy_tree(second_tree);
973 bool swap_nodes(monitor_t *m1, desktop_t *d1, node_t *n1, monitor_t *m2, desktop_t *d2, node_t *n2)
975 if (n1 == NULL || n2 == NULL ||n1 == n2 ||
976 (d1 != d2 && (n1->client->sticky || n2->client->sticky)))
979 PRINTF("swap nodes %X %X\n", n1->client->window, n2->client->window);
981 node_t *pn1 = n1->parent;
982 node_t *pn2 = n2->parent;
983 bool n1_first_child = is_first_child(n1);
984 bool n2_first_child = is_first_child(n2);
985 int br1 = n1->birth_rotation;
986 int br2 = n2->birth_rotation;
987 int pl1 = n1->privacy_level;
988 int pl2 = n2->privacy_level;
992 pn1->first_child = n2;
994 pn1->second_child = n2;
999 pn2->first_child = n1;
1001 pn2->second_child = n1;
1006 n1->birth_rotation = br2;
1007 n2->birth_rotation = br1;
1008 n1->privacy_level = pl2;
1009 n2->privacy_level = pl1;
1011 if (n1->vacant != n2->vacant) {
1012 update_vacant_state(n1->parent);
1013 update_vacant_state(n2->parent);
1016 if (n1->client->private != n2->client->private) {
1017 n1->client->private = !n1->client->private;
1018 n2->client->private = !n2->client->private;
1024 if (d1->focus == n1)
1028 if (d2->focus == n2)
1032 translate_client(m2, m1, n2->client);
1033 translate_client(m1, m2, n1->client);
1036 ewmh_set_wm_desktop(n1, d2);
1037 ewmh_set_wm_desktop(n2, d1);
1038 history_swap_nodes(m1, d1, n1, m2, d2, n2);
1040 if (m1->desk != d1 && m2->desk == d2) {
1041 window_show(n1->client->window);
1042 window_hide(n2->client->window);
1043 } else if (m1->desk == d1 && m2->desk != d2) {
1044 window_hide(n1->client->window);
1045 window_show(n2->client->window);
1048 update_input_focus();
1054 bool transfer_node(monitor_t *ms, desktop_t *ds, node_t *ns, monitor_t *md, desktop_t *dd, node_t *nd)
1056 if (ns == NULL || ns == nd || (sticky_still && ns->client->sticky))
1059 PRINTF("transfer node %X\n", ns->client->window);
1061 bool focused = (ns == mon->desk->focus);
1062 bool active = (ns == ds->focus);
1065 clear_input_focus();
1067 unlink_node(ms, ds, ns);
1068 insert_node(md, dd, ns, nd);
1071 translate_client(ms, md, ns->client);
1074 ewmh_set_wm_desktop(ns, dd);
1075 if (!ns->client->sticky) {
1076 if (ds == ms->desk && dd != md->desk)
1077 window_hide(ns->client->window);
1078 else if (ds != ms->desk && dd == md->desk)
1079 window_show(ns->client->window);
1081 if (ns->client->fullscreen && dd->focus != ns)
1082 set_fullscreen(ns, false);
1085 history_transfer_node(md, dd, ns);
1086 stack(ns, STACK_BELOW);
1090 focus_node(md, dd, ns);
1092 pseudo_focus(md, dd, ns);
1096 else if (ns == mon->desk->focus)
1097 update_input_focus();
1107 node_t *closest_node(monitor_t *m, desktop_t *d, node_t *n, cycle_dir_t dir, client_select_t sel)
1112 node_t *f = (dir == CYCLE_PREV ? prev_leaf(n, d->root) : next_leaf(n, d->root));
1114 f = (dir == CYCLE_PREV ? second_extrema(d->root) : first_extrema(d->root));
1116 coordinates_t ref = {m, d, n};
1118 coordinates_t loc = {m, d, f};
1119 if (node_matches(&loc, &ref, sel))
1121 f = (dir == CYCLE_PREV ? prev_leaf(f, d->root) : next_leaf(f, d->root));
1123 f = (dir == CYCLE_PREV ? second_extrema(d->root) : first_extrema(d->root));
1128 void circulate_leaves(monitor_t *m, desktop_t *d, circulate_dir_t dir)
1130 if (d == NULL || d->root == NULL || d->focus == NULL || is_leaf(d->root))
1132 node_t *p = d->focus->parent;
1133 bool focus_first_child = is_first_child(d->focus);
1134 if (dir == CIRCULATE_FORWARD)
1135 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))
1136 swap_nodes(m, d, f, m, d, s);
1138 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))
1139 swap_nodes(m, d, f, m, d, s);
1140 if (focus_first_child)
1141 focus_node(m, d, p->first_child);
1143 focus_node(m, d, p->second_child);
1146 void update_vacant_state(node_t *n)
1151 PUTS("update vacant state");
1153 /* n is not a leaf */
1157 p->vacant = (p->first_child->vacant && p->second_child->vacant);
1162 void update_privacy_level(node_t *n, bool value)
1164 int v = (value ? 1 : -1);
1165 for (node_t *p = n; p != NULL; p = p->parent)
1166 p->privacy_level += v;