14 void restore_tree(char *file_path)
16 if (file_path == NULL)
19 FILE *snapshot = fopen(file_path, "r");
20 if (snapshot == NULL) {
21 warn("Restore tree: can't open file\n");
34 unsigned int level, last_level = 0;
36 while (fgets(line, sizeof(line), snapshot) != NULL) {
37 unsigned int len = strlen(line);
40 while (level < len && isspace(line[level]))
44 int x, y, left, right, top, bottom;
48 sscanf(line + level, "%s %ux%u%i%i %i,%i,%i,%i %c", name, &w, &h, &x, &y, &top, &right, &bottom, &left, &end);
49 m = find_monitor(name);
52 m->rectangle = (xcb_rectangle_t) {x, y, w, h};
54 m->right_padding = right;
55 m->bottom_padding = bottom;
56 m->left_padding = left;
59 } else if (level == 2) {
64 char layout = 0, end = 0;
67 sscanf(line + level, "%s %u %i %c %c", name, &bw, &wg, &layout, &end);
68 locate_desktop(name, &loc);
75 d->layout = LAYOUT_MONOCLE;
76 else if (layout == 'T')
77 d->layout = LAYOUT_TILED;
82 if (m == NULL || d == NULL)
84 node_t *birth = make_node();
88 } else if (n != NULL) {
89 if (level > last_level) {
90 n->first_child = birth;
94 } while (n != NULL && n->second_child != NULL);
97 n->second_child = birth;
104 if (isupper(line[level])) {
106 sscanf(line + level, "%c %c %lf", &st, &br, &n->split_ratio);
108 n->split_type = TYPE_HORIZONTAL;
110 n->split_type = TYPE_VERTICAL;
112 client_t *c = make_client(XCB_NONE);
114 char floating, transient, fullscreen, urgent, locked, sticky, sd, sm, end = 0;
115 sscanf(line + level, "%c %s %X %u %hux%hu%hi%hi %c %c%c%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, &sd, &floating, &transient, &fullscreen, &urgent, &locked, &sticky, &sm, &end);
116 c->floating = (floating == '-' ? false : true);
117 c->transient = (transient == '-' ? false : true);
118 c->fullscreen = (fullscreen == '-' ? false : true);
119 c->urgent = (urgent == '-' ? false : true);
120 c->locked = (locked == '-' ? false : true);
121 c->sticky = (sticky == '-' ? false : true);
122 n->split_mode = (sm == '-' ? MODE_AUTOMATIC : MODE_MANUAL);
124 n->split_dir = DIR_UP;
126 n->split_dir = DIR_RIGHT;
128 n->split_dir = DIR_DOWN;
130 n->split_dir = DIR_LEFT;
138 n->birth_rotation = 90;
140 n->birth_rotation = 270;
142 n->birth_rotation = 0;
149 for (monitor_t *m = mon_head; m != NULL; m = m->next)
150 for (desktop_t *d = m->desk_head; d != NULL; d = d->next)
151 for (node_t *n = first_extrema(d->root); n != NULL; n = next_leaf(n, d->root)) {
152 uint32_t values[] = {(focus_follows_pointer ? CLIENT_EVENT_MASK_FFP : CLIENT_EVENT_MASK)};
153 xcb_change_window_attributes(dpy, n->client->window, XCB_CW_EVENT_MASK, values);
154 if (n->client->floating) {
156 update_vacant_state(n->parent);
159 ewmh_update_current_desktop();
162 void restore_history(char *file_path)
164 if (file_path == NULL)
167 FILE *snapshot = fopen(file_path, "r");
168 if (snapshot == NULL) {
169 warn("Restore history: can't open '%s'.\n", file_path);
173 PUTS("restore history");
180 while (fgets(line, sizeof(line), snapshot) != NULL) {
181 if (sscanf(line, "%s %s %X", mnm, dnm, &win) == 3) {
183 if (win != XCB_NONE && !locate_window(win, &loc)) {
184 warn("Can't locate window 0x%X.\n", win);
187 node_t *n = (win == XCB_NONE ? NULL : loc.node);
188 if (!locate_desktop(dnm, &loc)) {
189 warn("Can't locate desktop '%s'.\n", dnm);
192 desktop_t *d = loc.desktop;
193 if (!locate_monitor(mnm, &loc)) {
194 warn("Can't locate monitor '%s'.\n", mnm);
197 monitor_t *m = loc.monitor;
198 history_add(m, d, n);
200 warn("Can't parse history entry: '%s'\n", line);
207 void restore_stack(char *file_path)
209 if (file_path == NULL)
212 FILE *snapshot = fopen(file_path, "r");
213 if (snapshot == NULL) {
214 warn("Restore stack: can't open '%s'.\n", file_path);
218 PUTS("restore stack");
223 while (fgets(line, sizeof(line), snapshot) != NULL) {
224 if (sscanf(line, "%X", &win) == 1) {
226 if (win != XCB_NONE && !locate_window(win, &loc)) {
227 warn("Can't locate window 0x%X.\n", win);
230 stack_insert_after(stack_tail, loc.node);
232 warn("Can't parse stack entry: '%s'\n", line);