7 #include <xcb/xcb_event.h>
16 bool is_leaf(node_t *n)
18 return (n != NULL && n->first_child == NULL && n->second_child == NULL);
21 bool is_tiled(client_t *c)
25 return (!c->floating && !c->transient && !c->fullscreen);
28 bool is_floating(client_t *c)
32 return (c->floating && !c->fullscreen);
35 bool is_first_child(node_t *n)
37 return (n != NULL && n->parent != NULL && n->parent->first_child == n);
40 bool is_second_child(node_t *n)
42 return (n != NULL && n->parent != NULL && n->parent->second_child == n);
45 void change_split_ratio(node_t *n, value_change_t chg) {
46 n->split_ratio = pow(n->split_ratio, (chg == CHANGE_INCREASE ? INC_EXP : DEC_EXP));
49 node_t *first_extrema(node_t *n)
53 else if (n->first_child == NULL)
56 return first_extrema(n->first_child);
59 node_t *second_extrema(node_t *n)
63 else if (n->second_child == NULL)
66 return second_extrema(n->second_child);
69 node_t *next_leaf(node_t *n)
74 while (is_second_child(p))
76 if (p->parent == NULL)
78 return first_extrema(p->parent->second_child);
81 node_t *prev_leaf(node_t *n)
86 while (is_first_child(p))
88 if (p->parent == NULL)
90 return second_extrema(p->parent->first_child);
93 node_t *find_fence(node_t *n, direction_t dir)
103 if ((dir == DIR_UP && p->split_type == TYPE_HORIZONTAL && p->rectangle.y < n->rectangle.y)
104 || (dir == DIR_LEFT && p->split_type == TYPE_VERTICAL && p->rectangle.x < n->rectangle.x)
105 || (dir == DIR_DOWN && p->split_type == TYPE_HORIZONTAL && (p->rectangle.y + p->rectangle.height) > (n->rectangle.y + n->rectangle.height))
106 || (dir == DIR_RIGHT && p->split_type == TYPE_VERTICAL && (p->rectangle.x + p->rectangle.width) > (n->rectangle.x + n->rectangle.width)))
114 node_t *find_neighbor(node_t *n, direction_t dir)
116 node_t *fence = find_fence(n, dir);
121 if (dir == DIR_UP || dir == DIR_LEFT)
122 return second_extrema(fence->first_child);
123 else if (dir == DIR_DOWN || dir == DIR_RIGHT)
124 return first_extrema(fence->second_child);
129 void move_fence(node_t *n, direction_t dir, fence_move_t mov)
131 node_t *fence = find_fence(n, dir);
136 if ((mov == MOVE_PUSH && (dir == DIR_RIGHT || dir == DIR_DOWN))
137 || (mov == MOVE_PULL && (dir == DIR_LEFT || dir == DIR_UP)))
138 change_split_ratio(fence, CHANGE_INCREASE);
140 change_split_ratio(fence, CHANGE_DECREASE);
143 unsigned int distance_to_fence(xcb_point_t pt, node_t *fence)
145 xcb_rectangle_t rect = fence->rectangle;
146 if (fence->split_type == TYPE_VERTICAL) {
147 int fx = rect.x + fence->split_ratio * rect.width - window_gap / 2;
148 return ABS(pt.x - fx);
150 int fy = rect.y + fence->split_ratio * rect.height - window_gap / 2;
151 return ABS(pt.y - fy);
155 fence_distance_t nearest_fence(xcb_point_t pt, node_t *tree)
158 if (tree == NULL || is_leaf(tree)) {
162 fd.distance = distance_to_fence(pt, tree);
163 fence_distance_t first_fd = nearest_fence(pt, tree->first_child);
164 fence_distance_t second_fd = nearest_fence(pt, tree->second_child);
165 if (first_fd.fence != NULL && fd.distance > first_fd.distance) {
166 fd.fence = first_fd.fence;
167 fd.distance = first_fd.distance;
169 if (second_fd.fence != NULL && fd.distance > second_fd.distance) {
170 fd.fence = second_fd.fence;
171 fd.distance = second_fd.distance;
177 void rotate_tree(node_t *n, rotate_t rot)
179 if (n == NULL || is_leaf(n))
184 if ((rot == ROTATE_CLOCKWISE && n->split_type == TYPE_HORIZONTAL)
185 || (rot == ROTATE_COUNTER_CLOCKWISE && n->split_type == TYPE_VERTICAL)
186 || rot == ROTATE_FULL_CYCLE) {
187 tmp = n->first_child;
188 n->first_child = n->second_child;
189 n->second_child = tmp;
190 n->split_ratio = 1.0 - n->split_ratio;
193 if (rot != ROTATE_FULL_CYCLE) {
194 if (n->split_type == TYPE_HORIZONTAL)
195 n->split_type = TYPE_VERTICAL;
196 else if (n->split_type == TYPE_VERTICAL)
197 n->split_type = TYPE_HORIZONTAL;
200 rotate_tree(n->first_child, rot);
201 rotate_tree(n->second_child, rot);
204 void flip_tree(node_t *n, flip_t flp)
206 if (n == NULL || is_leaf(n))
211 if ((flp == FLIP_HORIZONTAL && n->split_type == TYPE_HORIZONTAL)
212 || (flp == FLIP_VERTICAL && n->split_type == TYPE_VERTICAL)) {
213 tmp = n->first_child;
214 n->first_child = n->second_child;
215 n->second_child = tmp;
216 n->split_ratio = 1.0 - n->split_ratio;
219 flip_tree(n->first_child, flp);
220 flip_tree(n->second_child, flp);
223 void arrange(monitor_t *m, desktop_t *d)
225 PRINTF("arrange %s%s%s\n", (num_monitors > 1 ? m->name : ""), (num_monitors > 1 ? " " : ""), d->name);
227 xcb_rectangle_t rect = m->rectangle;
228 int wg = (gapless_monocle && d->layout == LAYOUT_MONOCLE ? 0 : window_gap);
229 rect.x += m->left_padding + wg;
230 rect.y += m->top_padding + wg;
231 rect.width -= m->left_padding + m->right_padding + wg;
232 rect.height -= m->top_padding + m->bottom_padding + wg;
233 if (focus_follows_pointer)
234 save_pointer_position(&last_pointer_position);
235 apply_layout(m, d, d->root, rect, rect);
238 void apply_layout(monitor_t *m, desktop_t *d, node_t *n, xcb_rectangle_t rect, xcb_rectangle_t root_rect)
246 if (n->client->fullscreen)
249 if (is_floating(n->client) && n->client->border_width != border_width) {
250 int ds = 2 * (border_width - n->client->border_width);
251 n->client->floating_rectangle.width += ds;
252 n->client->floating_rectangle.height += ds;
255 if (borderless_monocle && is_tiled(n->client) && d->layout == LAYOUT_MONOCLE)
256 n->client->border_width = 0;
258 n->client->border_width = border_width;
261 if (is_tiled(n->client)) {
262 if (d->layout == LAYOUT_TILED)
264 else if (d->layout == LAYOUT_MONOCLE)
266 int wg = (gapless_monocle && d->layout == LAYOUT_MONOCLE ? 0 : window_gap);
267 int bleed = wg + 2 * n->client->border_width;
268 r.width = (bleed < r.width ? r.width - bleed : 1);
269 r.height = (bleed < r.height ? r.height - bleed : 1);
270 n->client->tiled_rectangle = r;
272 r = n->client->floating_rectangle;
275 window_move_resize(n->client->window, r.x, r.y, r.width, r.height);
276 window_border_width(n->client->window, n->client->border_width);
277 window_draw_border(n, n == d->focus, m == mon);
280 xcb_rectangle_t first_rect;
281 xcb_rectangle_t second_rect;
283 if (n->first_child->vacant || n->second_child->vacant) {
284 first_rect = second_rect = rect;
287 if (n->split_type == TYPE_VERTICAL) {
288 fence = rect.width * n->split_ratio;
289 first_rect = (xcb_rectangle_t) {rect.x, rect.y, fence, rect.height};
290 second_rect = (xcb_rectangle_t) {rect.x + fence, rect.y, rect.width - fence, rect.height};
292 } else if (n->split_type == TYPE_HORIZONTAL) {
293 fence = rect.height * n->split_ratio;
294 first_rect = (xcb_rectangle_t) {rect.x, rect.y, rect.width, fence};
295 second_rect = (xcb_rectangle_t) {rect.x, rect.y + fence, rect.width, rect.height - fence};
299 apply_layout(m, d, n->first_child, first_rect, root_rect);
300 apply_layout(m, d, n->second_child, second_rect, root_rect);
304 void insert_node(monitor_t *m, desktop_t *d, node_t *n)
306 if (d == NULL || n == NULL)
309 PRINTF("insert node %X\n", n->client->window);
311 node_t *focus = d->focus;
316 node_t *dad = make_node();
317 node_t *fopar = focus->parent;
319 n->client->born_as = split_mode;
320 switch (split_mode) {
323 dad->first_child = n;
324 dad->second_child = focus;
325 if (m->rectangle.width > m->rectangle.height)
326 dad->split_type = TYPE_VERTICAL;
328 dad->split_type = TYPE_HORIZONTAL;
332 node_t *grandpa = fopar->parent;
333 dad->parent = grandpa;
334 if (grandpa != NULL) {
335 if (is_first_child(fopar))
336 grandpa->first_child = dad;
338 grandpa->second_child = dad;
342 dad->split_type = fopar->split_type;
343 dad->split_ratio = fopar->split_ratio;
345 if (is_first_child(focus)) {
346 dad->first_child = n;
347 dad->second_child = fopar;
348 rotate_tree(fopar, ROTATE_CLOCKWISE);
350 dad->first_child = fopar;
351 dad->second_child = n;
352 rotate_tree(fopar, ROTATE_COUNTER_CLOCKWISE);
358 if (is_first_child(focus))
359 fopar->first_child = dad;
361 fopar->second_child = dad;
363 dad->split_ratio = focus->split_ratio;
368 dad->split_type = TYPE_VERTICAL;
369 dad->first_child = n;
370 dad->second_child = focus;
373 dad->split_type = TYPE_VERTICAL;
374 dad->first_child = focus;
375 dad->second_child = n;
378 dad->split_type = TYPE_HORIZONTAL;
379 dad->first_child = n;
380 dad->second_child = focus;
383 dad->split_type = TYPE_HORIZONTAL;
384 dad->first_child = focus;
385 dad->second_child = n;
388 if (d->root == focus)
390 split_mode = MODE_AUTOMATIC;
394 update_vacant_state(fopar);
398 void focus_node(monitor_t *m, desktop_t *d, node_t *n, bool is_mapped)
403 PRINTF("focus node %X\n", n->client->window);
405 split_mode = MODE_AUTOMATIC;
406 n->client->urgent = false;
410 for (desktop_t *cd = mon->desk_head; cd != NULL; cd = cd->next)
411 window_draw_border(cd->focus, true, false);
412 for (desktop_t *cd = m->desk_head; cd != NULL; cd = cd->next)
414 window_draw_border(cd->focus, true, true);
416 window_draw_border(n, true, true);
419 window_draw_border(d->focus, false, true);
420 window_draw_border(n, true, true);
422 xcb_set_input_focus(dpy, XCB_INPUT_FOCUS_POINTER_ROOT, n->client->window, XCB_CURRENT_TIME);
425 if (focus_follows_pointer) {
426 save_pointer_position(&last_pointer_position);
427 if (n != mon->desk->focus) {
428 if (last_focused_window != XCB_NONE) {
429 uint32_t values[] = {CLIENT_EVENT_MASK_FFP};
430 xcb_change_window_attributes(dpy, last_focused_window, XCB_CW_EVENT_MASK, values);
432 uint32_t values[] = {CLIENT_EVENT_MASK};
433 xcb_change_window_attributes(dpy, n->client->window, XCB_CW_EVENT_MASK, values);
434 last_focused_window = n->client->window;
438 if (!is_tiled(n->client)) {
439 if (!adaptative_raise || !might_cover(d, n))
440 window_raise(n->client->window);
442 window_pseudo_raise(d, n->client->window);
446 d->last_focus = d->focus;
450 ewmh_update_active_window();
454 void update_current(void)
456 if (mon->desk->focus == NULL)
457 ewmh_update_active_window();
459 focus_node(mon, mon->desk, mon->desk->focus, true);
463 void unlink_node(desktop_t *d, node_t *n)
465 if (d == NULL || n == NULL)
468 PRINTF("unlink node %X\n", n->client->window);
470 node_t *p = n->parent;
475 d->last_focus = NULL;
478 node_t *g = p->parent;
479 bool n_first_child = is_first_child(n);
482 if (n->client->born_as == MODE_AUTOMATIC)
483 rotate_tree(b, ROTATE_COUNTER_CLOCKWISE);
486 if (n->client->born_as == MODE_AUTOMATIC)
487 rotate_tree(b, ROTATE_CLOCKWISE);
491 if (is_first_child(p))
502 if (n == d->last_focus) {
503 d->last_focus = NULL;
504 } else if (n == d->focus) {
505 if (d->last_focus != NULL)
506 d->focus = d->last_focus;
508 d->focus = (n_first_child ? first_extrema(b) : second_extrema(b));
509 d->last_focus = NULL;
512 update_vacant_state(b->parent);
516 void remove_node(desktop_t *d, node_t *n)
518 if (d == NULL || n == NULL)
521 PRINTF("remove node %X\n", n->client->window);
528 ewmh_update_client_list();
534 void destroy_tree(node_t *n)
538 node_t *first_tree = n->first_child;
539 node_t *second_tree = n->second_child;
540 if (n->client != NULL)
543 destroy_tree(first_tree);
544 destroy_tree(second_tree);
547 void swap_nodes(node_t *n1, node_t *n2)
549 if (n1 == NULL || n2 == NULL || n1 == n2)
554 /* (n1 and n2 are leaves) */
555 node_t *pn1 = n1->parent;
556 node_t *pn2 = n2->parent;
557 bool n1_first_child = is_first_child(n1);
558 bool n2_first_child = is_first_child(n2);
562 pn1->first_child = n2;
564 pn1->second_child = n2;
569 pn2->first_child = n1;
571 pn2->second_child = n1;
577 if (n1->vacant != n2->vacant) {
578 update_vacant_state(n1->parent);
579 update_vacant_state(n2->parent);
583 void transfer_node(monitor_t *ms, desktop_t *ds, monitor_t *md, desktop_t *dd, node_t *n)
585 if (n == NULL || ds == NULL || dd == NULL || ms == NULL || md == NULL || (ms == md && dd == ds))
588 PRINTF("transfer node %X\n", n->client->window);
591 insert_node(md, dd, n);
592 ewmh_set_wm_desktop(n, dd);
594 if (ds == ms->desk && dd != md->desk) {
595 window_hide(n->client->window);
598 fit_monitor(md, n->client);
600 if (n->client->fullscreen)
601 window_move_resize(n->client->window, md->rectangle.x, md->rectangle.y, md->rectangle.width, md->rectangle.height);
603 if (ds != ms->desk && dd == md->desk) {
604 window_show(n->client->window);
605 focus_node(md, dd, n, true);
607 focus_node(md, dd, n, false);
610 if (ds == ms->desk || dd == md->desk)
614 void select_monitor(monitor_t *m)
616 if (m == NULL || mon == m)
619 PRINTF("select monitor %s\n", m->name);
621 focus_node(m, m->desk, m->desk->focus, true);
626 ewmh_update_current_desktop();
630 void select_desktop(desktop_t *d)
632 if (d == NULL || d == mon->desk)
635 PRINTF("select desktop %s\n", d->name);
638 node_t *n = first_extrema(d->root);
641 window_show(n->client->window);
645 n = first_extrema(mon->desk->root);
648 window_hide(n->client->window);
653 mon->last_desk = mon->desk;
657 ewmh_update_current_desktop();
661 void cycle_monitor(cycle_dir_t dir)
663 if (dir == CYCLE_NEXT)
664 select_monitor((mon->next == NULL ? mon_head : mon->next));
665 else if (dir == CYCLE_PREV)
666 select_monitor((mon->prev == NULL ? mon_tail : mon->prev));
669 void cycle_desktop(monitor_t *m, desktop_t *d, cycle_dir_t dir, skip_desktop_t skip)
671 desktop_t *f = (dir == CYCLE_PREV ? d->prev : d->next);
673 f = (dir == CYCLE_PREV ? m->desk_tail : m->desk_head);
676 if (skip == DESKTOP_SKIP_NONE
677 || (skip == DESKTOP_SKIP_FREE && f->root != NULL)
678 || (skip == DESKTOP_SKIP_OCCUPIED && f->root == NULL)) {
682 f = (dir == CYCLE_PREV ? f->prev : f->next);
684 f = (dir == CYCLE_PREV ? m->desk_tail : m->desk_head);
688 void cycle_leaf(monitor_t *m, desktop_t *d, node_t *n, cycle_dir_t dir, skip_client_t skip)
695 node_t *f = (dir == CYCLE_PREV ? prev_leaf(n) : next_leaf(n));
697 f = (dir == CYCLE_PREV ? second_extrema(d->root) : first_extrema(d->root));
700 bool tiled = is_tiled(f->client);
701 if (skip == CLIENT_SKIP_NONE || (skip == CLIENT_SKIP_TILED && !tiled) || (skip == CLIENT_SKIP_FLOATING && tiled)
702 || (skip == CLIENT_SKIP_CLASS_DIFFER && strcmp(f->client->class_name, n->client->class_name) == 0)
703 || (skip == CLIENT_SKIP_CLASS_EQUAL && strcmp(f->client->class_name, n->client->class_name) != 0)) {
704 focus_node(m, d, f, true);
707 f = (dir == CYCLE_PREV ? prev_leaf(f) : next_leaf(f));
709 f = (dir == CYCLE_PREV ? second_extrema(d->root) : first_extrema(d->root));
713 void nearest_leaf(monitor_t *m, desktop_t *d, node_t *n, nearest_arg_t dir, skip_client_t skip)
718 PUTS("nearest leaf");
722 for (node_t *f = first_extrema(d->root); f != NULL; f = next_leaf(f))
723 if (skip == CLIENT_SKIP_NONE || (skip == CLIENT_SKIP_TILED && !is_tiled(f->client)) || (skip == CLIENT_SKIP_FLOATING && is_tiled(f->client))
724 || (skip == CLIENT_SKIP_CLASS_DIFFER && strcmp(f->client->class_name, n->client->class_name) == 0)
725 || (skip == CLIENT_SKIP_CLASS_EQUAL && strcmp(f->client->class_name, n->client->class_name) != 0))
726 if ((dir == NEAREST_OLDER
727 && (f->client->uid < n->client->uid)
728 && (x == NULL || f->client->uid > x->client->uid))
729 || (dir == NEAREST_NEWER
730 && (f->client->uid > n->client->uid)
731 && (x == NULL || f->client->uid < x->client->uid)))
734 focus_node(m, d, x, true);
737 void circulate_leaves(monitor_t *m, desktop_t *d, circulate_dir_t dir) {
738 if (d == NULL || d->root == NULL || is_leaf(d->root))
740 node_t *par = d->focus->parent;
741 bool focus_first_child = is_first_child(d->focus);
742 if (dir == CIRCULATE_FORWARD)
743 for (node_t *s = second_extrema(d->root), *f = prev_leaf(s); f != NULL; s = prev_leaf(f), f = prev_leaf(s))
746 for (node_t *f = first_extrema(d->root), *s = next_leaf(f); s != NULL; f = next_leaf(s), s = next_leaf(f))
748 if (focus_first_child)
749 focus_node(m, d, par->first_child, true);
751 focus_node(m, d, par->second_child, true);
754 void update_vacant_state(node_t *n)
759 PUTS("update vacant state");
761 /* n is not a leaf */
765 p->vacant = (p->first_child->vacant && p->second_child->vacant);
770 void fit_monitor(monitor_t *m, client_t *c)
772 xcb_rectangle_t crect = c->floating_rectangle;
773 xcb_rectangle_t mrect = m->rectangle;
774 while (crect.x < mrect.x)
775 crect.x += mrect.width;
776 while (crect.x > (mrect.x + mrect.width - 1))
777 crect.x -= mrect.width;
778 while (crect.y < mrect.y)
779 crect.y += mrect.height;
780 while (crect.y > (mrect.y + mrect.height - 1))
781 crect.y -= mrect.height;
782 c->floating_rectangle = crect;
785 void put_status(void)
787 if (status_fifo == NULL)
790 for (monitor_t *m = mon_head; m != NULL; m = m->next) {
791 fprintf(status_fifo, "%c%s:", (mon == m ? 'M' : 'm'), m->name);
792 for (desktop_t *d = m->desk_head; d != NULL; d = d->next, urgent = false) {
793 for (node_t *n = first_extrema(d->root); n != NULL && !urgent; n = next_leaf(n))
794 urgent |= n->client->urgent;
795 fprintf(status_fifo, "%c%c%s:", (m->desk == d ? 'D' : (d->root != NULL ? 'd' : '_')), (urgent ? '!' : '_'), d->name);
798 fprintf(status_fifo, "L%s:W%X\n", (mon->desk->layout == LAYOUT_TILED ? "tiled" : "monocle"), (mon->desk->focus == NULL ? 0 : mon->desk->focus->client->window));
802 void list_monitors(list_option_t opt, char *rsp)
805 for (monitor_t *m = mon_head; m != NULL; m = m->next) {
806 snprintf(line, sizeof(line), "%s %ux%u%+i%+i", m->name, m->rectangle.width, m->rectangle.height, m->rectangle.x, m->rectangle.y);
807 strncat(rsp, line, REMLEN(rsp));
809 strncat(rsp, " #\n", REMLEN(rsp));
810 else if (m == last_mon)
811 strncat(rsp, " ~\n", REMLEN(rsp));
813 strncat(rsp, "\n", REMLEN(rsp));
814 if (opt == LIST_OPTION_VERBOSE)
815 list_desktops(m, opt, 1, rsp);
819 void list_desktops(monitor_t *m, list_option_t opt, unsigned int depth, char *rsp)
822 for (desktop_t *d = m->desk_head; d != NULL; d = d->next) {
823 for (unsigned int i = 0; i < depth; i++)
824 strncat(rsp, " ", REMLEN(rsp));
825 snprintf(line, sizeof(line), "%s %c", d->name, (d->layout == LAYOUT_TILED ? 'T' : 'M'));
826 strncat(rsp, line, REMLEN(rsp));
828 strncat(rsp, " @\n", REMLEN(rsp));
829 else if (d == m->last_desk)
830 strncat(rsp, " ~\n", REMLEN(rsp));
832 strncat(rsp, "\n", REMLEN(rsp));
833 if (opt == LIST_OPTION_VERBOSE)
834 list(d, d->root, rsp, depth + 1);
838 void list(desktop_t *d, node_t *n, char *rsp, unsigned int depth)
845 for (unsigned int i = 0; i < depth; i++)
846 strncat(rsp, " ", REMLEN(rsp));
849 client_t *c = n->client;
850 snprintf(line, sizeof(line), "%c %s %X %u %u %ux%u%+i%+i %c%c%c%c%c", (c->born_as == MODE_AUTOMATIC ? 'a' : 'm'), c->class_name, c->window, c->uid, c->border_width, c->floating_rectangle.width, c->floating_rectangle.height, c->floating_rectangle.x, c->floating_rectangle.y, (c->floating ? 'f' : '-'), (c->transient ? 't' : '-'), (c->fullscreen ? 'F' : '-'), (c->urgent ? 'u' : '-'), (c->locked ? 'l' : '-'));
852 snprintf(line, sizeof(line), "%c %.2f", (n->split_type == TYPE_HORIZONTAL ? 'H' : 'V'), n->split_ratio);
855 strncat(rsp, line, REMLEN(rsp));
858 strncat(rsp, " *\n", REMLEN(rsp));
859 else if (n == d->last_focus)
860 strncat(rsp, " ~\n", REMLEN(rsp));
862 strncat(rsp, "\n", REMLEN(rsp));
864 list(d, n->first_child, rsp, depth + 1);
865 list(d, n->second_child, rsp, depth + 1);
868 void restore(char *file_path)
870 if (file_path == NULL)
873 FILE *snapshot = fopen(file_path, "r");
874 if (snapshot == NULL) {
875 warn("restore: can't open file\n");
884 unsigned int level, last_level = 0, max_uid = 0;
885 bool aborted = false;
887 while (!aborted && fgets(line, sizeof(line), snapshot) != NULL) {
888 unsigned int len = strlen(line);
890 while (level < strlen(line) && isspace(line[level]))
898 switch (line[len - 2]) {
906 } else if (level == 2) {
912 while (i > 0 && !isupper(line[i]))
915 d->layout = LAYOUT_MONOCLE;
916 else if (line[i] == 'T')
917 d->layout = LAYOUT_TILED;
919 switch (line[len - 2]) {
928 node_t *birth = make_node();
933 if (level > last_level) {
934 n->first_child = birth;
938 } while (n != NULL && n->second_child != NULL);
940 warn("restore: file is malformed\n");
943 n->second_child = birth;
949 if (isupper(line[level])) {
951 sscanf(line + level, "%c %lf", &st, &n->split_ratio);
953 n->split_type = TYPE_HORIZONTAL;
955 n->split_type = TYPE_VERTICAL;
957 client_t *c = make_client(XCB_NONE);
959 char ba, floating, transient, fullscreen, urgent, locked;
960 sscanf(line + level, "%c %s %X %u %u %hux%hu%hi%hi %c%c%c%c%c", &ba, c->class_name, &c->window, &c->uid, &c->border_width, &c->floating_rectangle.width, &c->floating_rectangle.height, &c->floating_rectangle.x, &c->floating_rectangle.y, &floating, &transient, &fullscreen, &urgent, &locked);
962 c->born_as = MODE_AUTOMATIC;
964 c->born_as = MODE_MANUAL;
965 c->floating = (floating == '-' ? false : true);
966 c->transient = (transient == '-' ? false : true);
967 c->fullscreen = (fullscreen == '-' ? false : true);
968 c->urgent = (urgent == '-' ? false : true);
969 c->locked = (locked == '-' ? false : true);
970 if (c->uid > max_uid)
974 switch (line[len - 2]) {
988 client_uid = max_uid + 1;
989 for (monitor_t *m = mon_head; m != NULL; m = m->next)
990 for (desktop_t *d = m->desk_head; d != NULL; d = d->next)
991 for (node_t *n = first_extrema(d->root); n != NULL; n = next_leaf(n)) {
992 uint32_t values[] = {(focus_follows_pointer ? CLIENT_EVENT_MASK_FFP : CLIENT_EVENT_MASK)};
993 xcb_change_window_attributes(dpy, n->client->window, XCB_CW_EVENT_MASK, values);
994 if (n->client->floating) {
996 update_vacant_state(n->parent);