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.
33 #include "subscribe.h"
39 void arrange(monitor_t *m, desktop_t *d)
44 PRINTF("arrange %s %s\n", m->name, d->name);
46 layout_t set_layout = d->layout;
47 if (leaf_monocle && tiled_count(d) == 1) {
48 d->layout = LAYOUT_MONOCLE;
51 xcb_rectangle_t rect = m->rectangle;
52 int wg = (gapless_monocle && d->layout == LAYOUT_MONOCLE ? 0 : d->window_gap);
53 rect.x += m->left_padding + d->left_padding + wg;
54 rect.y += m->top_padding + d->top_padding + wg;
55 rect.width -= m->left_padding + d->left_padding + d->right_padding + m->right_padding + wg;
56 rect.height -= m->top_padding + d->top_padding + d->bottom_padding + m->bottom_padding + wg;
57 apply_layout(m, d, d->root, rect, rect);
59 d->layout = set_layout;
62 void apply_layout(monitor_t *m, desktop_t *d, node_t *n, xcb_rectangle_t rect, xcb_rectangle_t root_rect)
72 if ((borderless_monocle && n->client->state == STATE_TILED && d->layout == LAYOUT_MONOCLE)
73 || n->client->state == STATE_FULLSCREEN) {
76 bw = n->client->border_width;
80 client_state_t s = n->client->state;
81 if (s == STATE_TILED || s == STATE_PSEUDO_TILED) {
82 int wg = (gapless_monocle && d->layout == LAYOUT_MONOCLE ? 0 : d->window_gap);
84 if (s == STATE_TILED) {
86 int bleed = wg + 2 * bw;
87 r.width = (bleed < r.width ? r.width - bleed : 1);
88 r.height = (bleed < r.height ? r.height - bleed : 1);
89 /* pseudo-tiled clients */
91 r = n->client->floating_rectangle;
92 if (center_pseudo_tiled) {
93 r.x = rect.x - bw + (rect.width - wg - r.width) / 2;
94 r.y = rect.y - bw + (rect.height - wg - r.height) / 2;
100 /* floating clients */
101 } else if (s == STATE_FLOATING) {
102 r = n->client->floating_rectangle;
103 /* fullscreen clients */
108 window_move_resize(n->client->window, r.x, r.y, r.width, r.height);
109 window_border_width(n->client->window, bw);
110 window_draw_border(n, d->focus == n, m == mon);
112 if (pointer_follows_focus && mon->desk->focus == n && frozen_pointer->action == ACTION_NONE) {
117 xcb_rectangle_t first_rect;
118 xcb_rectangle_t second_rect;
120 if (d->layout == LAYOUT_MONOCLE || n->first_child->vacant || n->second_child->vacant) {
121 first_rect = second_rect = rect;
124 if (n->split_type == TYPE_VERTICAL) {
125 fence = rect.width * n->split_ratio;
126 first_rect = (xcb_rectangle_t) {rect.x, rect.y, fence, rect.height};
127 second_rect = (xcb_rectangle_t) {rect.x + fence, rect.y, rect.width - fence, rect.height};
129 fence = rect.height * n->split_ratio;
130 first_rect = (xcb_rectangle_t) {rect.x, rect.y, rect.width, fence};
131 second_rect = (xcb_rectangle_t) {rect.x, rect.y + fence, rect.width, rect.height - fence};
135 apply_layout(m, d, n->first_child, first_rect, root_rect);
136 apply_layout(m, d, n->second_child, second_rect, root_rect);
140 void insert_node(monitor_t *m, desktop_t *d, node_t *n, node_t *f)
142 if (d == NULL || n == NULL)
145 PRINTF("insert node %X\n", n->client->window);
147 /* n: new leaf node */
148 /* c: new container node */
149 /* f: focus or insertion anchor */
150 /* p: parent of focus */
151 /* g: grand parent of focus */
159 node_t *c = make_node();
160 node_t *p = f->parent;
161 if ((f->client->private ||
162 (p != NULL && p->privacy_level > 0)) &&
163 f->split_mode == MODE_AUTOMATIC) {
164 node_t *closest = NULL;
165 node_t *public = NULL;
166 closest_public(d, f, &closest, &public);
167 if (public != NULL) {
171 if (closest != NULL) {
175 f->split_mode = MODE_MANUAL;
176 xcb_rectangle_t rect = f->client->tiled_rectangle;
177 f->split_dir = (rect.width >= rect.height ? DIR_LEFT : DIR_UP);
178 if (f->client->private) {
179 get_opposite(f->split_dir, &f->split_dir);
180 update_privacy_level(f, false);
184 if (p != NULL && f->split_mode == MODE_AUTOMATIC &&
185 (p->first_child->vacant || p->second_child->vacant)) {
190 c->birth_rotation = f->birth_rotation;
191 switch (f->split_mode) {
194 if (initial_polarity == FIRST_CHILD) {
201 if (m->rectangle.width > m->rectangle.height)
202 c->split_type = TYPE_VERTICAL;
204 c->split_type = TYPE_HORIZONTAL;
208 node_t *g = p->parent;
211 if (is_first_child(p))
218 c->split_type = p->split_type;
219 c->split_ratio = p->split_ratio;
222 if (is_first_child(f)) {
231 if (IS_TILED(n->client)) {
234 n->birth_rotation = rot;
239 if (is_first_child(f))
244 c->split_ratio = f->split_ratio;
247 f->birth_rotation = 0;
248 switch (f->split_dir) {
250 c->split_type = TYPE_VERTICAL;
255 c->split_type = TYPE_VERTICAL;
260 c->split_type = TYPE_HORIZONTAL;
265 c->split_type = TYPE_HORIZONTAL;
272 f->split_mode = MODE_AUTOMATIC;
276 update_vacant_state(f->parent);
278 if (f->client != NULL) {
279 if (f->client->private) {
280 update_privacy_level(f, true);
284 if (n->client->private) {
285 update_privacy_level(n, true);
287 if (d->focus == NULL) {
290 if (n->client->sticky) {
293 put_status(SBSC_MASK_REPORT);
296 void pseudo_focus(monitor_t *m, desktop_t *d, node_t *n)
301 window_draw_border(d->focus, false, m == mon);
302 window_draw_border(n, true, m == mon);
308 void focus_node(monitor_t *m, desktop_t *d, node_t *n)
310 if (mon->desk != d || n == NULL)
313 if (m->num_sticky > 0 && d != m->desk) {
314 node_t *a = first_extrema(m->desk->root);
315 sticky_still = false;
317 node_t *b = next_leaf(a, m->desk->root);
318 if (a->client->sticky)
319 transfer_node(m, m->desk, a, m, d, d->focus);
323 if (n == NULL && d->focus != NULL)
328 if (n->client->urgent) {
329 n->client->urgent = false;
330 put_status(SBSC_MASK_REPORT);
332 if (d->focus != NULL && n != d->focus && stack_cmp(n->client, d->focus->client) < 0) {
333 neutralize_obscuring_windows(m, d, n);
338 for (desktop_t *cd = mon->desk_head; cd != NULL; cd = cd->next) {
339 window_draw_border(cd->focus, true, false);
341 for (desktop_t *cd = m->desk_head; cd != NULL; cd = cd->next) {
343 window_draw_border(cd->focus, true, true);
347 window_draw_border(n, true, true);
352 window_draw_border(d->focus, false, true);
353 window_draw_border(n, true, true);
361 history_add(m, d, NULL);
362 ewmh_update_active_window();
368 PRINTF("focus node %X\n", n->client->window);
369 put_status(SBSC_MASK_WINDOW_FOCUS, "window_focus 0x%X\n", n->client->window);
371 history_add(m, d, n);
374 if (focus_follows_pointer) {
375 xcb_window_t win = XCB_NONE;
376 query_pointer(&win, NULL);
377 if (win != n->client->window) {
378 enable_motion_recorder();
380 disable_motion_recorder();
384 if (pointer_follows_focus) {
385 center_pointer(get_rectangle(m, n->client));
388 ewmh_update_active_window();
391 void update_current(void)
393 focus_node(mon, mon->desk, mon->desk->focus);
396 node_t *make_node(void)
398 node_t *n = malloc(sizeof(node_t));
399 n->parent = n->first_child = n->second_child = NULL;
400 n->split_ratio = split_ratio;
401 n->split_mode = MODE_AUTOMATIC;
402 n->split_type = TYPE_VERTICAL;
403 n->birth_rotation = 0;
404 n->privacy_level = 0;
410 client_t *make_client(xcb_window_t win, unsigned int border_width)
412 client_t *c = malloc(sizeof(client_t));
414 c->state = c->last_state = STATE_TILED;
415 c->layer = c->last_layer = LAYER_NORMAL;
416 snprintf(c->class_name, sizeof(c->class_name), "%s", MISSING_VALUE);
417 snprintf(c->instance_name, sizeof(c->instance_name), "%s", MISSING_VALUE);
418 c->border_width = border_width;
419 c->locked = c->sticky = c->urgent = c->private = c->icccm_focus = false;
420 xcb_icccm_get_wm_protocols_reply_t protocols;
421 if (xcb_icccm_get_wm_protocols_reply(dpy, xcb_icccm_get_wm_protocols(dpy, win, ewmh->WM_PROTOCOLS), &protocols, NULL) == 1) {
422 if (has_proto(WM_TAKE_FOCUS, &protocols))
423 c->icccm_focus = true;
424 xcb_icccm_get_wm_protocols_reply_wipe(&protocols);
427 xcb_ewmh_get_atoms_reply_t wm_state;
428 if (xcb_ewmh_get_wm_state_reply(ewmh, xcb_ewmh_get_wm_state(ewmh, win), &wm_state, NULL) == 1) {
429 for (unsigned int i = 0; i < wm_state.atoms_len && i < MAX_STATE; i++)
430 ewmh_wm_state_add(c, wm_state.atoms[i]);
431 xcb_ewmh_get_atoms_reply_wipe(&wm_state);
436 bool is_leaf(node_t *n)
438 return (n != NULL && n->first_child == NULL && n->second_child == NULL);
441 bool is_first_child(node_t *n)
443 return (n != NULL && n->parent != NULL && n->parent->first_child == n);
446 bool is_second_child(node_t *n)
448 return (n != NULL && n->parent != NULL && n->parent->second_child == n);
451 void reset_mode(coordinates_t *loc)
453 if (loc->node != NULL) {
454 loc->node->split_mode = MODE_AUTOMATIC;
455 window_draw_border(loc->node, loc->desktop->focus == loc->node, mon == loc->monitor);
456 } else if (loc->desktop != NULL) {
457 for (node_t *a = first_extrema(loc->desktop->root); a != NULL; a = next_leaf(a, loc->desktop->root)) {
458 a->split_mode = MODE_AUTOMATIC;
459 window_draw_border(a, loc->desktop->focus == a, mon == loc->monitor);
464 node_t *brother_tree(node_t *n)
466 if (n == NULL || n->parent == NULL)
468 if (is_first_child(n))
469 return n->parent->second_child;
471 return n->parent->first_child;
474 void closest_public(desktop_t *d, node_t *n, node_t **closest, node_t **public)
478 node_t *prev = prev_leaf(n, d->root);
479 node_t *next = next_leaf(n, d->root);
480 while (prev != NULL || next != NULL) {
481 #define TESTLOOP(n) \
483 if (IS_TILED(n->client)) { \
484 if (n->privacy_level == 0) { \
485 if (n->parent == NULL || n->parent->privacy_level == 0) { \
488 } else if (*closest == NULL) { \
493 n = n##_leaf(n, d->root); \
501 node_t *first_extrema(node_t *n)
505 else if (n->first_child == NULL)
508 return first_extrema(n->first_child);
511 node_t *second_extrema(node_t *n)
515 else if (n->second_child == NULL)
518 return second_extrema(n->second_child);
521 node_t *next_leaf(node_t *n, node_t *r)
526 while (is_second_child(p) && p != r)
530 return first_extrema(p->parent->second_child);
533 node_t *prev_leaf(node_t *n, node_t *r)
538 while (is_first_child(p) && p != r)
542 return second_extrema(p->parent->first_child);
545 node_t *next_tiled_leaf(desktop_t *d, node_t *n, node_t *r)
547 node_t *next = next_leaf(n, r);
548 if (next == NULL || IS_TILED(next->client))
551 return next_tiled_leaf(d, next, r);
554 node_t *prev_tiled_leaf(desktop_t *d, node_t *n, node_t *r)
556 node_t *prev = prev_leaf(n, r);
557 if (prev == NULL || IS_TILED(prev->client))
560 return prev_tiled_leaf(d, prev, r);
563 /* Returns true if *b* is adjacent to *a* in the direction *dir* */
564 bool is_adjacent(node_t *a, node_t *b, direction_t dir)
568 return (a->rectangle.x + a->rectangle.width) == b->rectangle.x;
571 return (a->rectangle.y + a->rectangle.height) == b->rectangle.y;
574 return (b->rectangle.x + b->rectangle.width) == a->rectangle.x;
577 return (b->rectangle.y + b->rectangle.height) == a->rectangle.y;
583 node_t *find_fence(node_t *n, direction_t dir)
593 if ((dir == DIR_UP && p->split_type == TYPE_HORIZONTAL && p->rectangle.y < n->rectangle.y) ||
594 (dir == DIR_LEFT && p->split_type == TYPE_VERTICAL && p->rectangle.x < n->rectangle.x) ||
595 (dir == DIR_DOWN && p->split_type == TYPE_HORIZONTAL && (p->rectangle.y + p->rectangle.height) > (n->rectangle.y + n->rectangle.height)) ||
596 (dir == DIR_RIGHT && p->split_type == TYPE_VERTICAL && (p->rectangle.x + p->rectangle.width) > (n->rectangle.x + n->rectangle.width)))
604 node_t *nearest_neighbor(monitor_t *m, desktop_t *d, node_t *n, direction_t dir, client_select_t sel)
606 if (n == NULL || IS_FULLSCREEN(n->client) ||
607 (d->layout == LAYOUT_MONOCLE && IS_TILED(n->client)))
610 node_t *nearest = NULL;
611 if (history_aware_focus)
612 nearest = nearest_from_history(m, d, n, dir, sel);
613 if (nearest == NULL) {
614 if (focus_by_distance) {
615 nearest = nearest_from_distance(m, d, n, dir, sel);
617 nearest = nearest_from_tree(m, d, n, dir, sel);
623 node_t *nearest_from_tree(monitor_t *m, desktop_t *d, node_t *n, direction_t dir, client_select_t sel)
629 node_t *fence = find_fence(n, dir);
634 node_t *nearest = NULL;
636 if (dir == DIR_UP || dir == DIR_LEFT) {
637 nearest = second_extrema(fence->first_child);
638 } else if (dir == DIR_DOWN || dir == DIR_RIGHT) {
639 nearest = first_extrema(fence->second_child);
642 coordinates_t ref = {m, d, n};
643 coordinates_t loc = {m, d, nearest};
645 if (node_matches(&loc, &ref, sel)) {
652 node_t *nearest_from_history(monitor_t *m, desktop_t *d, node_t *n, direction_t dir, client_select_t sel)
654 if (n == NULL || !IS_TILED(n->client)) {
658 node_t *target = find_fence(n, dir);
661 if (dir == DIR_UP || dir == DIR_LEFT)
662 target = target->first_child;
663 else if (dir == DIR_DOWN || dir == DIR_RIGHT)
664 target = target->second_child;
666 node_t *nearest = NULL;
667 int min_rank = INT_MAX;
668 coordinates_t ref = {m, d, n};
670 for (node_t *a = first_extrema(target); a != NULL; a = next_leaf(a, target)) {
671 if (a->vacant || !is_adjacent(n, a, dir) || a == n)
673 coordinates_t loc = {m, d, a};
674 if (!node_matches(&loc, &ref, sel))
677 int rank = history_rank(d, a);
678 if (rank >= 0 && rank < min_rank) {
687 node_t *nearest_from_distance(monitor_t *m, desktop_t *d, node_t *n, direction_t dir, client_select_t sel)
692 node_t *target = NULL;
694 if (IS_TILED(n->client)) {
695 target = find_fence(n, dir);
698 if (dir == DIR_UP || dir == DIR_LEFT)
699 target = target->first_child;
700 else if (dir == DIR_DOWN || dir == DIR_RIGHT)
701 target = target->second_child;
706 node_t *nearest = NULL;
710 get_side_handle(n->client, dir, &pt);
711 get_opposite(dir, &dir2);
713 coordinates_t ref = {m, d, n};
715 for (node_t *a = first_extrema(target); a != NULL; a = next_leaf(a, target)) {
716 coordinates_t loc = {m, d, a};
718 !node_matches(&loc, &ref, sel) ||
719 IS_TILED(a->client) != IS_TILED(n->client) ||
720 (IS_TILED(a->client) && !is_adjacent(n, a, dir)))
723 get_side_handle(a->client, dir2, &pt2);
724 double ds2 = distance(pt, pt2);
734 void get_opposite(direction_t src, direction_t *dst)
752 int tiled_area(node_t *n)
756 xcb_rectangle_t rect = n->client->tiled_rectangle;
757 return rect.width * rect.height;
760 int tiled_count(desktop_t *d)
763 for (node_t *f = first_extrema(d->root); f != NULL; f = next_leaf(f, d->root)) {
764 if (IS_TILED(f->client)) {
771 node_t *find_biggest(monitor_t *m, desktop_t *d, node_t *n, client_select_t sel)
777 int r_area = tiled_area(r);
778 coordinates_t ref = {m, d, n};
780 for (node_t *f = first_extrema(d->root); f != NULL; f = next_leaf(f, d->root)) {
781 coordinates_t loc = {m, d, f};
782 if (IS_FLOATING(f->client) || !node_matches(&loc, &ref, sel))
784 int f_area = tiled_area(f);
788 } else if (f_area > r_area) {
797 void rotate_tree(node_t *n, int deg)
799 if (n == NULL || is_leaf(n) || deg == 0)
804 if ((deg == 90 && n->split_type == TYPE_HORIZONTAL) ||
805 (deg == 270 && n->split_type == TYPE_VERTICAL) ||
807 tmp = n->first_child;
808 n->first_child = n->second_child;
809 n->second_child = tmp;
810 n->split_ratio = 1.0 - n->split_ratio;
814 if (n->split_type == TYPE_HORIZONTAL)
815 n->split_type = TYPE_VERTICAL;
816 else if (n->split_type == TYPE_VERTICAL)
817 n->split_type = TYPE_HORIZONTAL;
820 rotate_tree(n->first_child, deg);
821 rotate_tree(n->second_child, deg);
824 void rotate_brother(node_t *n)
826 rotate_tree(brother_tree(n), n->birth_rotation);
829 void unrotate_tree(node_t *n, int rot)
833 rotate_tree(n, 360 - rot);
836 void unrotate_brother(node_t *n)
838 unrotate_tree(brother_tree(n), n->birth_rotation);
841 void flip_tree(node_t *n, flip_t flp)
843 if (n == NULL || is_leaf(n))
848 if ((flp == FLIP_HORIZONTAL && n->split_type == TYPE_HORIZONTAL) ||
849 (flp == FLIP_VERTICAL && n->split_type == TYPE_VERTICAL)) {
850 tmp = n->first_child;
851 n->first_child = n->second_child;
852 n->second_child = tmp;
853 n->split_ratio = 1.0 - n->split_ratio;
856 flip_tree(n->first_child, flp);
857 flip_tree(n->second_child, flp);
860 void equalize_tree(node_t *n)
862 if (n == NULL || n->vacant) {
865 n->split_ratio = split_ratio;
866 equalize_tree(n->first_child);
867 equalize_tree(n->second_child);
871 int balance_tree(node_t *n)
873 if (n == NULL || n->vacant) {
875 } else if (is_leaf(n)) {
878 int b1 = balance_tree(n->first_child);
879 int b2 = balance_tree(n->second_child);
881 if (b1 > 0 && b2 > 0)
882 n->split_ratio = (double) b1 / b;
887 void unlink_node(monitor_t *m, desktop_t *d, node_t *n)
889 if (d == NULL || n == NULL)
892 PRINTF("unlink node %X\n", n->client->window);
894 node_t *p = n->parent;
900 if (n->client->private)
901 update_privacy_level(n, false);
904 node_t *g = p->parent;
906 if (is_first_child(n)) {
909 unrotate_tree(b, n->birth_rotation);
913 unrotate_tree(b, n->birth_rotation);
919 if (is_first_child(p))
927 b->birth_rotation = p->birth_rotation;
930 update_vacant_state(b->parent);
933 d->focus = history_get_node(d, n);
934 // fallback to the first extrema (`n` is not reachable)
935 if (d->focus == NULL)
936 d->focus = first_extrema(d->root);
939 if (n->client->sticky)
941 put_status(SBSC_MASK_REPORT);
944 void remove_node(monitor_t *m, desktop_t *d, node_t *n)
949 PRINTF("remove node %X\n", n->client->window);
951 bool focused = (n == mon->desk->focus);
952 unlink_node(m, d, n);
953 history_remove(d, n);
954 remove_stack_node(n);
959 ewmh_update_client_list();
965 void destroy_tree(node_t *n)
969 node_t *first_tree = n->first_child;
970 node_t *second_tree = n->second_child;
971 if (n->client != NULL) {
976 destroy_tree(first_tree);
977 destroy_tree(second_tree);
980 bool swap_nodes(monitor_t *m1, desktop_t *d1, node_t *n1, monitor_t *m2, desktop_t *d2, node_t *n2)
982 if (n1 == NULL || n2 == NULL ||n1 == n2 ||
983 (d1 != d2 && (n1->client->sticky || n2->client->sticky)))
986 PRINTF("swap nodes %X %X\n", n1->client->window, n2->client->window);
988 node_t *pn1 = n1->parent;
989 node_t *pn2 = n2->parent;
990 bool n1_first_child = is_first_child(n1);
991 bool n2_first_child = is_first_child(n2);
992 int br1 = n1->birth_rotation;
993 int br2 = n2->birth_rotation;
994 int pl1 = n1->privacy_level;
995 int pl2 = n2->privacy_level;
999 pn1->first_child = n2;
1001 pn1->second_child = n2;
1006 pn2->first_child = n1;
1008 pn2->second_child = n1;
1013 n1->birth_rotation = br2;
1014 n2->birth_rotation = br1;
1015 n1->privacy_level = pl2;
1016 n2->privacy_level = pl1;
1018 if (n1->vacant != n2->vacant) {
1019 update_vacant_state(n1->parent);
1020 update_vacant_state(n2->parent);
1023 if (n1->client->private != n2->client->private) {
1024 n1->client->private = !n1->client->private;
1025 n2->client->private = !n2->client->private;
1031 if (d1->focus == n1)
1035 if (d2->focus == n2)
1039 translate_client(m2, m1, n2->client);
1040 translate_client(m1, m2, n1->client);
1043 ewmh_set_wm_desktop(n1, d2);
1044 ewmh_set_wm_desktop(n2, d1);
1045 history_swap_nodes(m1, d1, n1, m2, d2, n2);
1047 if (m1->desk != d1 && m2->desk == d2) {
1048 window_show(n1->client->window);
1049 window_hide(n2->client->window);
1050 } else if (m1->desk == d1 && m2->desk != d2) {
1051 window_hide(n1->client->window);
1052 window_show(n2->client->window);
1055 update_input_focus();
1061 bool transfer_node(monitor_t *ms, desktop_t *ds, node_t *ns, monitor_t *md, desktop_t *dd, node_t *nd)
1063 if (ns == NULL || ns == nd || (sticky_still && ns->client->sticky)) {
1067 PRINTF("transfer node %X\n", ns->client->window);
1068 put_status(SBSC_MASK_WINDOW_TRANSFER, "window_transfer %s %s 0x%X %s %s 0x%X\n", ms->name, ds->name, ns->client->window, md->name, dd->name, nd!=NULL?nd->client->window:0);
1070 bool focused = (ns == mon->desk->focus);
1071 bool active = (ns == ds->focus);
1074 clear_input_focus();
1077 unlink_node(ms, ds, ns);
1078 insert_node(md, dd, ns, nd);
1081 translate_client(ms, md, ns->client);
1085 ewmh_set_wm_desktop(ns, dd);
1086 if (!ns->client->sticky) {
1087 if (ds == ms->desk && dd != md->desk) {
1088 window_hide(ns->client->window);
1089 } else if (ds != ms->desk && dd == md->desk) {
1090 window_show(ns->client->window);
1095 history_transfer_node(md, dd, ns);
1100 focus_node(md, dd, ns);
1101 } else if (active) {
1102 pseudo_focus(md, dd, ns);
1107 } else if (ns == mon->desk->focus) {
1108 update_input_focus();
1121 node_t *closest_node(monitor_t *m, desktop_t *d, node_t *n, cycle_dir_t dir, client_select_t sel)
1126 node_t *f = (dir == CYCLE_PREV ? prev_leaf(n, d->root) : next_leaf(n, d->root));
1128 f = (dir == CYCLE_PREV ? second_extrema(d->root) : first_extrema(d->root));
1130 coordinates_t ref = {m, d, n};
1132 coordinates_t loc = {m, d, f};
1133 if (node_matches(&loc, &ref, sel))
1135 f = (dir == CYCLE_PREV ? prev_leaf(f, d->root) : next_leaf(f, d->root));
1137 f = (dir == CYCLE_PREV ? second_extrema(d->root) : first_extrema(d->root));
1142 void circulate_leaves(monitor_t *m, desktop_t *d, circulate_dir_t dir)
1144 if (d == NULL || d->root == NULL || d->focus == NULL || is_leaf(d->root))
1146 node_t *p = d->focus->parent;
1147 bool focus_first_child = is_first_child(d->focus);
1148 if (dir == CIRCULATE_FORWARD)
1149 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))
1150 swap_nodes(m, d, f, m, d, s);
1152 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))
1153 swap_nodes(m, d, f, m, d, s);
1154 if (focus_first_child)
1155 focus_node(m, d, p->first_child);
1157 focus_node(m, d, p->second_child);
1160 void update_vacant_state(node_t *n)
1165 PUTS("update vacant state");
1167 /* n is not a leaf */
1171 p->vacant = (p->first_child->vacant && p->second_child->vacant);
1176 void update_privacy_level(node_t *n, bool value)
1178 int v = (value ? 1 : -1);
1179 for (node_t *p = n; p != NULL; p = p->parent)
1180 p->privacy_level += v;