1 /* * Copyright (c) 2012-2013 Bastien Dejean
4 * Redistribution and use in source and binary forms, with or without modification,
5 * are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright notice, this
8 * list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright notice,
10 * this list of conditions and the following disclaimer in the documentation and/or
11 * other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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 ON
20 * 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 restore_tree(char *file_path)
40 if (file_path == NULL)
43 FILE *snapshot = fopen(file_path, "r");
44 if (snapshot == NULL) {
45 warn("Restore tree: can't open file\n");
58 unsigned int level, last_level = 0;
60 while (fgets(line, sizeof(line), snapshot) != NULL) {
61 unsigned int len = strlen(line);
64 while (level < len && isspace(line[level]))
68 int x, y, left, right, top, bottom;
72 sscanf(line + level, "%s %ux%u%i%i %i,%i,%i,%i %c", name, &w, &h, &x, &y, &top, &right, &bottom, &left, &end);
73 m = find_monitor(name);
76 m->rectangle = (xcb_rectangle_t) {x, y, w, h};
78 m->right_padding = right;
79 m->bottom_padding = bottom;
80 m->left_padding = left;
83 } else if (level == 2) {
88 char floating, layout = 0, end = 0;
91 sscanf(line + level, "%s %u %i %c %c %c", name, &bw, &wg, &layout, &floating, &end);
92 locate_desktop(name, &loc);
99 d->layout = LAYOUT_MONOCLE;
100 else if (layout == 'T')
101 d->layout = LAYOUT_TILED;
102 d->floating = (floating == '-' ? false : true);
107 if (m == NULL || d == NULL)
109 node_t *birth = make_node();
113 } else if (n != NULL) {
114 if (level > last_level) {
115 n->first_child = birth;
119 } while (n != NULL && n->second_child != NULL);
122 n->second_child = birth;
129 if (isupper(line[level])) {
131 sscanf(line + level, "%c %c %lf", &st, &br, &n->split_ratio);
133 n->split_type = TYPE_HORIZONTAL;
135 n->split_type = TYPE_VERTICAL;
137 client_t *c = make_client(XCB_NONE);
139 char floating, transient, fullscreen, urgent, locked, sticky, frame, private, sd, sm, end = 0;
140 sscanf(line + level, "%c %s %X %u %hux%hu%hi%hi %c %c%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, &frame, &private, &sm, &end);
141 c->floating = (floating == '-' ? false : true);
142 c->transient = (transient == '-' ? false : true);
143 c->fullscreen = (fullscreen == '-' ? false : true);
144 c->urgent = (urgent == '-' ? false : true);
145 c->locked = (locked == '-' ? false : true);
146 c->sticky = (sticky == '-' ? false : true);
147 c->frame = (frame == '-' ? false : true);
148 c->private = (private == '-' ? false : true);
149 n->split_mode = (sm == '-' ? MODE_AUTOMATIC : MODE_MANUAL);
151 n->split_dir = DIR_UP;
153 n->split_dir = DIR_RIGHT;
155 n->split_dir = DIR_DOWN;
157 n->split_dir = DIR_LEFT;
165 n->birth_rotation = 90;
167 n->birth_rotation = 270;
169 n->birth_rotation = 0;
176 for (monitor_t *m = mon_head; m != NULL; m = m->next)
177 for (desktop_t *d = m->desk_head; d != NULL; d = d->next)
178 for (node_t *n = first_extrema(d->root); n != NULL; n = next_leaf(n, d->root)) {
179 uint32_t values[] = {get_event_mask(n->client)};
180 xcb_change_window_attributes(dpy, n->client->window, XCB_CW_EVENT_MASK, values);
181 if (n->client->floating) {
183 update_vacant_state(n->parent);
185 if (n->client->private)
186 update_privacy_level(n, true);
188 ewmh_update_current_desktop();
191 void restore_history(char *file_path)
193 if (file_path == NULL)
196 FILE *snapshot = fopen(file_path, "r");
197 if (snapshot == NULL) {
198 warn("Restore history: can't open '%s'.\n", file_path);
202 PUTS("restore history");
209 while (fgets(line, sizeof(line), snapshot) != NULL) {
210 if (sscanf(line, "%s %s %X", mnm, dnm, &win) == 3) {
212 if (win != XCB_NONE && !locate_window(win, &loc)) {
213 warn("Can't locate window 0x%X.\n", win);
216 node_t *n = (win == XCB_NONE ? NULL : loc.node);
217 if (!locate_desktop(dnm, &loc)) {
218 warn("Can't locate desktop '%s'.\n", dnm);
221 desktop_t *d = loc.desktop;
222 if (!locate_monitor(mnm, &loc)) {
223 warn("Can't locate monitor '%s'.\n", mnm);
226 monitor_t *m = loc.monitor;
227 history_add(m, d, n);
229 warn("Can't parse history entry: '%s'\n", line);
236 void restore_stack(char *file_path)
238 if (file_path == NULL)
241 FILE *snapshot = fopen(file_path, "r");
242 if (snapshot == NULL) {
243 warn("Restore stack: can't open '%s'.\n", file_path);
247 PUTS("restore stack");
252 while (fgets(line, sizeof(line), snapshot) != NULL) {
253 if (sscanf(line, "%X", &win) == 1) {
255 if (locate_window(win, &loc))
256 stack_insert_after(stack_tail, loc.node);
258 warn("Can't locate window 0x%X.\n", win);
260 warn("Can't parse stack entry: '%s'\n", line);