1 /* Copyright (c) 2012-2014, 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.
24 * The views and conclusions contained in the software and documentation are those
25 * of the authors and should not be interpreted as representing official policies,
26 * either expressed or implied, of the FreeBSD Project.
42 void restore_tree(char *file_path)
44 if (file_path == NULL)
47 FILE *snapshot = fopen(file_path, "r");
48 if (snapshot == NULL) {
49 warn("Restore tree: can't open file\n");
61 unsigned int level, last_level = 0;
63 while (fgets(line, sizeof(line), snapshot) != NULL) {
64 unsigned int len = strlen(line);
67 while (level < len && isspace(line[level]))
71 int x, y, top, right, bottom, left;
75 sscanf(line + level, "%s %ux%u%i%i %i,%i,%i,%i %c", name, &w, &h, &x, &y,
76 &top, &right, &bottom, &left, &end);
77 m = find_monitor(name);
80 m->rectangle = (xcb_rectangle_t) {x, y, w, h};
82 m->right_padding = right;
83 m->bottom_padding = bottom;
84 m->left_padding = left;
87 } else if (level == 2) {
90 int wg, top, right, bottom, left;
92 char floating, layout = 0, end = 0;
95 sscanf(line + level, "%s %u %i %i,%i,%i,%i %c %c %c", name,
96 &bw, &wg, &top, &right, &bottom, &left, &layout, &floating, &end);
97 locate_desktop(name, &loc);
101 d->border_width = bw;
103 d->top_padding = top;
104 d->right_padding = right;
105 d->bottom_padding = bottom;
106 d->left_padding = left;
108 d->layout = LAYOUT_MONOCLE;
109 else if (layout == 'T')
110 d->layout = LAYOUT_TILED;
111 d->floating = (floating == '-' ? false : true);
115 if (m == NULL || d == NULL)
117 node_t *birth = make_node();
121 } else if (n != NULL) {
122 if (level > last_level) {
123 n->first_child = birth;
127 } while (n != NULL && n->second_child != NULL);
130 n->second_child = birth;
136 if (isupper(line[level])) {
138 sscanf(line + level, "%c %c %lf", &st, &br, &n->split_ratio);
140 n->split_type = TYPE_HORIZONTAL;
142 n->split_type = TYPE_VERTICAL;
144 client_t *c = make_client(XCB_NONE);
146 char floating, pseudo_tiled, fullscreen, urgent, locked, sticky, private, sd, sm, end = 0;
147 sscanf(line + level, "%c %s %s %X %u %hux%hu%hi%hi %c %c%c%c%c%c%c%c%c %c", &br,
148 c->class_name, c->instance_name, &c->window, &c->border_width,
149 &c->floating_rectangle.width, &c->floating_rectangle.height,
150 &c->floating_rectangle.x, &c->floating_rectangle.y,
151 &sd, &floating, &pseudo_tiled, &fullscreen, &urgent,
152 &locked, &sticky, &private, &sm, &end);
153 c->floating = (floating == '-' ? false : true);
154 c->pseudo_tiled = (pseudo_tiled == '-' ? false : true);
155 c->fullscreen = (fullscreen == '-' ? false : true);
156 c->urgent = (urgent == '-' ? false : true);
157 c->locked = (locked == '-' ? false : true);
158 c->sticky = (sticky == '-' ? false : true);
159 c->private = (private == '-' ? false : true);
160 n->split_mode = (sm == '-' ? MODE_AUTOMATIC : MODE_MANUAL);
162 n->split_dir = DIR_UP;
164 n->split_dir = DIR_RIGHT;
166 n->split_dir = DIR_DOWN;
168 n->split_dir = DIR_LEFT;
176 n->birth_rotation = 90;
178 n->birth_rotation = 270;
180 n->birth_rotation = 0;
187 for (monitor_t *m = mon_head; m != NULL; m = m->next)
188 for (desktop_t *d = m->desk_head; d != NULL; d = d->next)
189 for (node_t *n = first_extrema(d->root); n != NULL; n = next_leaf(n, d->root)) {
190 uint32_t values[] = {CLIENT_EVENT_MASK | (focus_follows_pointer ? XCB_EVENT_MASK_ENTER_WINDOW : 0)};
191 xcb_change_window_attributes(dpy, n->client->window, XCB_CW_EVENT_MASK, values);
192 if (n->client->floating) {
194 update_vacant_state(n->parent);
196 if (n->client->private)
197 update_privacy_level(n, true);
199 ewmh_update_current_desktop();
202 void restore_history(char *file_path)
204 if (file_path == NULL)
207 FILE *snapshot = fopen(file_path, "r");
208 if (snapshot == NULL) {
209 warn("Restore history: can't open '%s'.\n", file_path);
213 PUTS("restore history");
220 while (fgets(line, sizeof(line), snapshot) != NULL) {
221 if (sscanf(line, "%s %s %X", mnm, dnm, &win) == 3) {
223 if (win != XCB_NONE && !locate_window(win, &loc)) {
224 warn("Can't locate window 0x%X.\n", win);
227 node_t *n = (win == XCB_NONE ? NULL : loc.node);
228 if (!locate_desktop(dnm, &loc)) {
229 warn("Can't locate desktop '%s'.\n", dnm);
232 desktop_t *d = loc.desktop;
233 if (!locate_monitor(mnm, &loc)) {
234 warn("Can't locate monitor '%s'.\n", mnm);
237 monitor_t *m = loc.monitor;
238 history_add(m, d, n);
240 warn("Can't parse history entry: '%s'\n", line);
247 void restore_stack(char *file_path)
249 if (file_path == NULL)
252 FILE *snapshot = fopen(file_path, "r");
253 if (snapshot == NULL) {
254 warn("Restore stack: can't open '%s'.\n", file_path);
258 PUTS("restore stack");
263 while (fgets(line, sizeof(line), snapshot) != NULL) {
264 if (sscanf(line, "%X", &win) == 1) {
266 if (locate_window(win, &loc))
267 stack_insert_after(stack_tail, loc.node);
269 warn("Can't locate window 0x%X.\n", win);
271 warn("Can't parse stack entry: '%s'\n", line);