11 void restore_tree(char *file_path)
13 if (file_path == NULL)
16 FILE *snapshot = fopen(file_path, "r");
17 if (snapshot == NULL) {
18 warn("Restore: can't open file\n");
29 unsigned int level, last_level = 0;
32 while (fgets(line, sizeof(line), snapshot) != NULL) {
33 unsigned int len = strlen(line);
35 while (level < strlen(line) && isspace(line[level]))
48 switch (line[len - 2]) {
56 } else if (level == 2) {
66 while (i > 0 && !isupper(line[i]))
69 d->layout = LAYOUT_MONOCLE;
70 else if (line[i] == 'T')
71 d->layout = LAYOUT_TILED;
73 switch (line[len - 2]) {
82 node_t *birth = make_node();
86 } else if (n != NULL) {
87 if (level > last_level) {
88 n->first_child = birth;
92 } while (n != NULL && n->second_child != NULL);
94 warn("Restore: malformed file\n");
98 n->second_child = birth;
105 if (isupper(line[level])) {
107 sscanf(line + level, "%c %c %lf", &st, &br, &n->split_ratio);
109 n->split_type = TYPE_HORIZONTAL;
111 n->split_type = TYPE_VERTICAL;
113 client_t *c = make_client(XCB_NONE);
115 char floating, transient, fullscreen, urgent, locked, split_mode;
116 sscanf(line + level, "%c %s %X %u %hux%hu%hi%hi %c%c%c%c%c%c", &br, c->class_name, &c->window, &c->border_width, &c->floating_rectangle.width, &c->floating_rectangle.height, &c->floating_rectangle.x, &c->floating_rectangle.y, &floating, &transient, &fullscreen, &urgent, &locked, &split_mode);
117 c->floating = (floating == '-' ? false : true);
118 c->transient = (transient == '-' ? false : true);
119 c->fullscreen = (fullscreen == '-' ? false : true);
120 c->urgent = (urgent == '-' ? false : true);
121 c->locked = (locked == '-' ? false : true);
122 n->split_mode = (split_mode == '-' ? false : true);
124 if (len >= 2 && line[len - 2] == '*')
128 n->birth_rotation = 90;
130 n->birth_rotation = 270;
132 n->birth_rotation = 0;
140 for (monitor_t *m = mon_head; m != NULL; m = m->next)
141 for (desktop_t *d = m->desk_head; d != NULL; d = d->next)
142 for (node_t *n = first_extrema(d->root); n != NULL; n = next_leaf(n, d->root)) {
143 uint32_t values[] = {(focus_follows_pointer ? CLIENT_EVENT_MASK_FFP : CLIENT_EVENT_MASK)};
144 xcb_change_window_attributes(dpy, n->client->window, XCB_CW_EVENT_MASK, values);
145 if (n->client->floating) {
147 update_vacant_state(n->parent);
150 ewmh_update_current_desktop();
154 void restore_history(char *file_path)
156 if (file_path == NULL)
159 FILE *snapshot = fopen(file_path, "r");
160 if (snapshot == NULL) {
161 warn("Restore history: can't open file\n");
165 PUTS("restore history");
171 while (fgets(line, sizeof(line), snapshot) != NULL) {
172 unsigned int i = strlen(line) - 1;
173 while (i > 0 && isspace(line[i]))
176 while (level < strlen(line) && isspace(line[level]))
180 if (locate_desktop(line + level, &loc))
182 } else if (d != NULL) {
184 if (sscanf(line + level, "%X", &win) == 1) {
186 if (locate_window(win, &loc))
187 history_add(d->history, loc.node);