]> git.sur5r.net Git - i3/i3/blob - src/load_layout.c
Merge branch 'next' into master
[i3/i3] / src / load_layout.c
1 #undef I3__FILE__
2 #define I3__FILE__ "load_layout.c"
3 /*
4  * vim:ts=4:sw=4:expandtab
5  *
6  * i3 - an improved dynamic tiling window manager
7  * © 2009 Michael Stapelberg and contributors (see also: LICENSE)
8  *
9  * load_layout.c: Restore (parts of) the layout, for example after an inplace
10  *                restart.
11  *
12  */
13 #include "all.h"
14
15 #include <yajl/yajl_common.h>
16 #include <yajl/yajl_gen.h>
17 #include <yajl/yajl_parse.h>
18 #include <yajl/yajl_version.h>
19
20 /* TODO: refactor the whole parsing thing */
21
22 static char *last_key;
23 static Con *json_node;
24 static Con *to_focus;
25 static bool parsing_swallows;
26 static bool parsing_rect;
27 static bool parsing_deco_rect;
28 static bool parsing_window_rect;
29 static bool parsing_geometry;
30 static bool parsing_focus;
31 struct Match *current_swallow;
32
33 /* This list is used for reordering the focus stack after parsing the 'focus'
34  * array. */
35 struct focus_mapping {
36     int old_id;
37     TAILQ_ENTRY(focus_mapping) focus_mappings;
38 };
39
40 static TAILQ_HEAD(focus_mappings_head, focus_mapping) focus_mappings =
41     TAILQ_HEAD_INITIALIZER(focus_mappings);
42
43 static int json_start_map(void *ctx) {
44     LOG("start of map, last_key = %s\n", last_key);
45     if (parsing_swallows) {
46         LOG("creating new swallow\n");
47         current_swallow = smalloc(sizeof(Match));
48         match_init(current_swallow);
49         TAILQ_INSERT_TAIL(&(json_node->swallow_head), current_swallow, matches);
50     } else {
51         if (!parsing_rect && !parsing_deco_rect && !parsing_window_rect && !parsing_geometry) {
52             if (last_key && strcasecmp(last_key, "floating_nodes") == 0) {
53                 DLOG("New floating_node\n");
54                 Con *ws = con_get_workspace(json_node);
55                 json_node = con_new_skeleton(NULL, NULL);
56                 json_node->name = NULL;
57                 json_node->parent = ws;
58                 DLOG("Parent is workspace = %p\n", ws);
59             } else {
60                 Con *parent = json_node;
61                 json_node = con_new_skeleton(NULL, NULL);
62                 json_node->name = NULL;
63                 json_node->parent = parent;
64             }
65         }
66     }
67     return 1;
68 }
69
70 static int json_end_map(void *ctx) {
71     LOG("end of map\n");
72     if (!parsing_swallows && !parsing_rect && !parsing_deco_rect && !parsing_window_rect && !parsing_geometry) {
73         /* Set a few default values to simplify manually crafted layout files. */
74         if (json_node->layout == L_DEFAULT) {
75             DLOG("Setting layout = L_SPLITH\n");
76             json_node->layout = L_SPLITH;
77         }
78
79         /* Sanity check: swallow criteria don’t make any sense on a split
80          * container. */
81         if (con_is_split(json_node) > 0 && !TAILQ_EMPTY(&(json_node->swallow_head))) {
82             DLOG("sanity check: removing swallows specification from split container\n");
83             while (!TAILQ_EMPTY(&(json_node->swallow_head))) {
84                 Match *match = TAILQ_FIRST(&(json_node->swallow_head));
85                 TAILQ_REMOVE(&(json_node->swallow_head), match, matches);
86                 match_free(match);
87             }
88         }
89
90         if (json_node->type == CT_WORKSPACE) {
91             /* Ensure the workspace has a name. */
92             DLOG("Attaching workspace. name = %s\n", json_node->name);
93             if (json_node->name == NULL || strcmp(json_node->name, "") == 0) {
94                 json_node->name = sstrdup("unnamed");
95             }
96
97             /* Prevent name clashes when appending a workspace, e.g. when the
98              * user tries to restore a workspace called “1” but already has a
99              * workspace called “1”. */
100             Con *output;
101             Con *workspace = NULL;
102             TAILQ_FOREACH(output, &(croot->nodes_head), nodes)
103             GREP_FIRST(workspace, output_get_content(output), !strcasecmp(child->name, json_node->name));
104             char *base = sstrdup(json_node->name);
105             int cnt = 1;
106             while (workspace != NULL) {
107                 FREE(json_node->name);
108                 sasprintf(&(json_node->name), "%s_%d", base, cnt++);
109                 workspace = NULL;
110                 TAILQ_FOREACH(output, &(croot->nodes_head), nodes)
111                 GREP_FIRST(workspace, output_get_content(output), !strcasecmp(child->name, json_node->name));
112             }
113             free(base);
114
115             /* Set num accordingly so that i3bar will properly sort it. */
116             json_node->num = ws_name_to_number(json_node->name);
117         }
118
119         // When appending JSON layout files that only contain the workspace
120         // _contents_, we might not have an upfront signal that the
121         // container we’re currently parsing is a floating container (like
122         // the “floating_nodes” key of the workspace container itself).
123         // That’s why we make sure the con is attached at the right place
124         // in the hierarchy in case it’s floating.
125         if (json_node->type == CT_FLOATING_CON) {
126             DLOG("fixing parent which currently is %p / %s\n", json_node->parent, json_node->parent->name);
127             json_node->parent = con_get_workspace(json_node->parent);
128
129             // Also set a size if none was supplied, otherwise the placeholder
130             // window cannot be created as X11 requests with width=0 or
131             // height=0 are invalid.
132             const Rect zero = {0, 0, 0, 0};
133             if (memcmp(&(json_node->rect), &zero, sizeof(Rect)) == 0) {
134                 DLOG("Geometry not set, combining children\n");
135                 Con *child;
136                 TAILQ_FOREACH(child, &(json_node->nodes_head), nodes) {
137                     DLOG("child geometry: %d x %d\n", child->geometry.width, child->geometry.height);
138                     json_node->rect.width += child->geometry.width;
139                     json_node->rect.height = max(json_node->rect.height, child->geometry.height);
140                 }
141             }
142
143             floating_check_size(json_node);
144         }
145
146         LOG("attaching\n");
147         con_attach(json_node, json_node->parent, true);
148         LOG("Creating window\n");
149         x_con_init(json_node, json_node->depth);
150         json_node = json_node->parent;
151     }
152
153     parsing_rect = false;
154     parsing_deco_rect = false;
155     parsing_window_rect = false;
156     parsing_geometry = false;
157     return 1;
158 }
159
160 static int json_end_array(void *ctx) {
161     LOG("end of array\n");
162     if (!parsing_swallows && !parsing_focus) {
163         con_fix_percent(json_node);
164     }
165     if (parsing_swallows) {
166         parsing_swallows = false;
167     }
168     if (parsing_focus) {
169         /* Clear the list of focus mappings */
170         struct focus_mapping *mapping;
171         TAILQ_FOREACH_REVERSE(mapping, &focus_mappings, focus_mappings_head, focus_mappings) {
172             LOG("focus (reverse) %d\n", mapping->old_id);
173             Con *con;
174             TAILQ_FOREACH(con, &(json_node->focus_head), focused) {
175                 if (con->old_id != mapping->old_id)
176                     continue;
177                 LOG("got it! %p\n", con);
178                 /* Move this entry to the top of the focus list. */
179                 TAILQ_REMOVE(&(json_node->focus_head), con, focused);
180                 TAILQ_INSERT_HEAD(&(json_node->focus_head), con, focused);
181                 break;
182             }
183         }
184         while (!TAILQ_EMPTY(&focus_mappings)) {
185             mapping = TAILQ_FIRST(&focus_mappings);
186             TAILQ_REMOVE(&focus_mappings, mapping, focus_mappings);
187             free(mapping);
188         }
189         parsing_focus = false;
190     }
191     return 1;
192 }
193
194 static int json_key(void *ctx, const unsigned char *val, size_t len) {
195     LOG("key: %.*s\n", (int)len, val);
196     FREE(last_key);
197     last_key = scalloc(len + 1, 1);
198     memcpy(last_key, val, len);
199     if (strcasecmp(last_key, "swallows") == 0)
200         parsing_swallows = true;
201
202     if (strcasecmp(last_key, "rect") == 0)
203         parsing_rect = true;
204
205     if (strcasecmp(last_key, "deco_rect") == 0)
206         parsing_deco_rect = true;
207
208     if (strcasecmp(last_key, "window_rect") == 0)
209         parsing_window_rect = true;
210
211     if (strcasecmp(last_key, "geometry") == 0)
212         parsing_geometry = true;
213
214     if (strcasecmp(last_key, "focus") == 0)
215         parsing_focus = true;
216
217     return 1;
218 }
219
220 static int json_string(void *ctx, const unsigned char *val, size_t len) {
221     LOG("string: %.*s for key %s\n", (int)len, val, last_key);
222     if (parsing_swallows) {
223         char *sval;
224         sasprintf(&sval, "%.*s", len, val);
225         if (strcasecmp(last_key, "class") == 0) {
226             current_swallow->class = regex_new(sval);
227         } else if (strcasecmp(last_key, "instance") == 0) {
228             current_swallow->instance = regex_new(sval);
229         } else if (strcasecmp(last_key, "window_role") == 0) {
230             current_swallow->window_role = regex_new(sval);
231         } else if (strcasecmp(last_key, "title") == 0) {
232             current_swallow->title = regex_new(sval);
233         } else {
234             ELOG("swallow key %s unknown\n", last_key);
235         }
236         free(sval);
237     } else {
238         if (strcasecmp(last_key, "name") == 0) {
239             json_node->name = scalloc(len + 1, 1);
240             memcpy(json_node->name, val, len);
241         } else if (strcasecmp(last_key, "sticky_group") == 0) {
242             json_node->sticky_group = scalloc(len + 1, 1);
243             memcpy(json_node->sticky_group, val, len);
244             LOG("sticky_group of this container is %s\n", json_node->sticky_group);
245         } else if (strcasecmp(last_key, "orientation") == 0) {
246             /* Upgrade path from older versions of i3 (doing an inplace restart
247              * to a newer version):
248              * "orientation" is dumped before "layout". Therefore, we store
249              * whether the orientation was horizontal or vertical in the
250              * last_split_layout. When we then encounter layout == "default",
251              * we will use the last_split_layout as layout instead. */
252             char *buf = NULL;
253             sasprintf(&buf, "%.*s", (int)len, val);
254             if (strcasecmp(buf, "none") == 0 ||
255                 strcasecmp(buf, "horizontal") == 0)
256                 json_node->last_split_layout = L_SPLITH;
257             else if (strcasecmp(buf, "vertical") == 0)
258                 json_node->last_split_layout = L_SPLITV;
259             else
260                 LOG("Unhandled orientation: %s\n", buf);
261             free(buf);
262         } else if (strcasecmp(last_key, "border") == 0) {
263             char *buf = NULL;
264             sasprintf(&buf, "%.*s", (int)len, val);
265             if (strcasecmp(buf, "none") == 0)
266                 json_node->border_style = BS_NONE;
267             else if (strcasecmp(buf, "1pixel") == 0) {
268                 json_node->border_style = BS_PIXEL;
269                 json_node->current_border_width = 1;
270             } else if (strcasecmp(buf, "pixel") == 0)
271                 json_node->border_style = BS_PIXEL;
272             else if (strcasecmp(buf, "normal") == 0)
273                 json_node->border_style = BS_NORMAL;
274             else
275                 LOG("Unhandled \"border\": %s\n", buf);
276             free(buf);
277         } else if (strcasecmp(last_key, "type") == 0) {
278             char *buf = NULL;
279             sasprintf(&buf, "%.*s", (int)len, val);
280             if (strcasecmp(buf, "root") == 0)
281                 json_node->type = CT_ROOT;
282             else if (strcasecmp(buf, "output") == 0)
283                 json_node->type = CT_OUTPUT;
284             else if (strcasecmp(buf, "con") == 0)
285                 json_node->type = CT_CON;
286             else if (strcasecmp(buf, "floating_con") == 0)
287                 json_node->type = CT_FLOATING_CON;
288             else if (strcasecmp(buf, "workspace") == 0)
289                 json_node->type = CT_WORKSPACE;
290             else if (strcasecmp(buf, "dockarea") == 0)
291                 json_node->type = CT_DOCKAREA;
292             else
293                 LOG("Unhandled \"type\": %s\n", buf);
294             free(buf);
295         } else if (strcasecmp(last_key, "layout") == 0) {
296             char *buf = NULL;
297             sasprintf(&buf, "%.*s", (int)len, val);
298             if (strcasecmp(buf, "default") == 0)
299                 /* This set above when we read "orientation". */
300                 json_node->layout = json_node->last_split_layout;
301             else if (strcasecmp(buf, "stacked") == 0)
302                 json_node->layout = L_STACKED;
303             else if (strcasecmp(buf, "tabbed") == 0)
304                 json_node->layout = L_TABBED;
305             else if (strcasecmp(buf, "dockarea") == 0)
306                 json_node->layout = L_DOCKAREA;
307             else if (strcasecmp(buf, "output") == 0)
308                 json_node->layout = L_OUTPUT;
309             else if (strcasecmp(buf, "splith") == 0)
310                 json_node->layout = L_SPLITH;
311             else if (strcasecmp(buf, "splitv") == 0)
312                 json_node->layout = L_SPLITV;
313             else
314                 LOG("Unhandled \"layout\": %s\n", buf);
315             free(buf);
316         } else if (strcasecmp(last_key, "workspace_layout") == 0) {
317             char *buf = NULL;
318             sasprintf(&buf, "%.*s", (int)len, val);
319             if (strcasecmp(buf, "default") == 0)
320                 json_node->workspace_layout = L_DEFAULT;
321             else if (strcasecmp(buf, "stacked") == 0)
322                 json_node->workspace_layout = L_STACKED;
323             else if (strcasecmp(buf, "tabbed") == 0)
324                 json_node->workspace_layout = L_TABBED;
325             else
326                 LOG("Unhandled \"workspace_layout\": %s\n", buf);
327             free(buf);
328         } else if (strcasecmp(last_key, "last_split_layout") == 0) {
329             char *buf = NULL;
330             sasprintf(&buf, "%.*s", (int)len, val);
331             if (strcasecmp(buf, "splith") == 0)
332                 json_node->last_split_layout = L_SPLITH;
333             else if (strcasecmp(buf, "splitv") == 0)
334                 json_node->last_split_layout = L_SPLITV;
335             else
336                 LOG("Unhandled \"last_splitlayout\": %s\n", buf);
337             free(buf);
338         } else if (strcasecmp(last_key, "mark") == 0) {
339             char *buf = NULL;
340             sasprintf(&buf, "%.*s", (int)len, val);
341
342             /* We unmark any containers using this mark to avoid duplicates. */
343             con_unmark(buf);
344
345             json_node->mark = buf;
346         } else if (strcasecmp(last_key, "floating") == 0) {
347             char *buf = NULL;
348             sasprintf(&buf, "%.*s", (int)len, val);
349             if (strcasecmp(buf, "auto_off") == 0)
350                 json_node->floating = FLOATING_AUTO_OFF;
351             else if (strcasecmp(buf, "auto_on") == 0)
352                 json_node->floating = FLOATING_AUTO_ON;
353             else if (strcasecmp(buf, "user_off") == 0)
354                 json_node->floating = FLOATING_USER_OFF;
355             else if (strcasecmp(buf, "user_on") == 0)
356                 json_node->floating = FLOATING_USER_ON;
357             free(buf);
358         } else if (strcasecmp(last_key, "scratchpad_state") == 0) {
359             char *buf = NULL;
360             sasprintf(&buf, "%.*s", (int)len, val);
361             if (strcasecmp(buf, "none") == 0)
362                 json_node->scratchpad_state = SCRATCHPAD_NONE;
363             else if (strcasecmp(buf, "fresh") == 0)
364                 json_node->scratchpad_state = SCRATCHPAD_FRESH;
365             else if (strcasecmp(buf, "changed") == 0)
366                 json_node->scratchpad_state = SCRATCHPAD_CHANGED;
367             free(buf);
368         }
369     }
370     return 1;
371 }
372
373 static int json_int(void *ctx, long long val) {
374     LOG("int %lld for key %s\n", val, last_key);
375     /* For backwards compatibility with i3 < 4.8 */
376     if (strcasecmp(last_key, "type") == 0)
377         json_node->type = val;
378
379     if (strcasecmp(last_key, "fullscreen_mode") == 0)
380         json_node->fullscreen_mode = val;
381
382     if (strcasecmp(last_key, "num") == 0)
383         json_node->num = val;
384
385     if (strcasecmp(last_key, "current_border_width") == 0)
386         json_node->current_border_width = val;
387
388     if (strcasecmp(last_key, "depth") == 0)
389         json_node->depth = val;
390
391     if (!parsing_swallows && strcasecmp(last_key, "id") == 0)
392         json_node->old_id = val;
393
394     if (parsing_focus) {
395         struct focus_mapping *focus_mapping = scalloc(1, sizeof(struct focus_mapping));
396         focus_mapping->old_id = val;
397         TAILQ_INSERT_TAIL(&focus_mappings, focus_mapping, focus_mappings);
398     }
399
400     if (parsing_rect || parsing_window_rect || parsing_geometry) {
401         Rect *r;
402         if (parsing_rect)
403             r = &(json_node->rect);
404         else if (parsing_window_rect)
405             r = &(json_node->window_rect);
406         else
407             r = &(json_node->geometry);
408         if (strcasecmp(last_key, "x") == 0)
409             r->x = val;
410         else if (strcasecmp(last_key, "y") == 0)
411             r->y = val;
412         else if (strcasecmp(last_key, "width") == 0)
413             r->width = val;
414         else if (strcasecmp(last_key, "height") == 0)
415             r->height = val;
416         else
417             ELOG("WARNING: unknown key %s in rect\n", last_key);
418         DLOG("rect now: (%d, %d, %d, %d)\n",
419              r->x, r->y, r->width, r->height);
420     }
421     if (parsing_swallows) {
422         if (strcasecmp(last_key, "id") == 0) {
423             current_swallow->id = val;
424         }
425         if (strcasecmp(last_key, "dock") == 0) {
426             current_swallow->dock = val;
427         }
428         if (strcasecmp(last_key, "insert_where") == 0) {
429             current_swallow->insert_where = val;
430         }
431     }
432
433     return 1;
434 }
435
436 static int json_bool(void *ctx, int val) {
437     LOG("bool %d for key %s\n", val, last_key);
438     if (strcasecmp(last_key, "focused") == 0 && val) {
439         to_focus = json_node;
440     }
441
442     if (strcasecmp(last_key, "sticky") == 0)
443         json_node->sticky = val;
444
445     if (parsing_swallows) {
446         if (strcasecmp(last_key, "restart_mode") == 0)
447             current_swallow->restart_mode = val;
448     }
449
450     return 1;
451 }
452
453 static int json_double(void *ctx, double val) {
454     LOG("double %f for key %s\n", val, last_key);
455     if (strcasecmp(last_key, "percent") == 0) {
456         json_node->percent = val;
457     }
458     return 1;
459 }
460
461 static json_content_t content_result;
462 static int content_level;
463
464 static int json_determine_content_deeper(void *ctx) {
465     content_level++;
466     return 1;
467 }
468
469 static int json_determine_content_shallower(void *ctx) {
470     content_level--;
471     return 1;
472 }
473
474 static int json_determine_content_string(void *ctx, const unsigned char *val, size_t len) {
475     if (strcasecmp(last_key, "type") != 0 || content_level > 1)
476         return 1;
477
478     DLOG("string = %.*s, last_key = %s\n", (int)len, val, last_key);
479     if (strncasecmp((const char *)val, "workspace", len) == 0)
480         content_result = JSON_CONTENT_WORKSPACE;
481     return 0;
482 }
483
484 /* Parses the given JSON file until it encounters the first “type” property to
485  * determine whether the file contains workspaces or regular containers, which
486  * is important to know when deciding where (and how) to append the contents.
487  * */
488 json_content_t json_determine_content(const char *filename) {
489     FILE *f;
490     if ((f = fopen(filename, "r")) == NULL) {
491         ELOG("Cannot open file \"%s\"\n", filename);
492         return JSON_CONTENT_UNKNOWN;
493     }
494     struct stat stbuf;
495     if (fstat(fileno(f), &stbuf) != 0) {
496         ELOG("Cannot fstat() \"%s\"\n", filename);
497         fclose(f);
498         return JSON_CONTENT_UNKNOWN;
499     }
500     char *buf = smalloc(stbuf.st_size);
501     int n = fread(buf, 1, stbuf.st_size, f);
502     if (n != stbuf.st_size) {
503         ELOG("File \"%s\" could not be read entirely, not loading.\n", filename);
504         fclose(f);
505         return JSON_CONTENT_UNKNOWN;
506     }
507     DLOG("read %d bytes\n", n);
508     // We default to JSON_CONTENT_CON because it is legal to not include
509     // “"type": "con"” in the JSON files for better readability.
510     content_result = JSON_CONTENT_CON;
511     content_level = 0;
512     yajl_gen g;
513     yajl_handle hand;
514     static yajl_callbacks callbacks = {
515         .yajl_string = json_determine_content_string,
516         .yajl_map_key = json_key,
517         .yajl_start_array = json_determine_content_deeper,
518         .yajl_start_map = json_determine_content_deeper,
519         .yajl_end_map = json_determine_content_shallower,
520         .yajl_end_array = json_determine_content_shallower,
521     };
522     g = yajl_gen_alloc(NULL);
523     hand = yajl_alloc(&callbacks, NULL, (void *)g);
524     /* Allowing comments allows for more user-friendly layout files. */
525     yajl_config(hand, yajl_allow_comments, true);
526     /* Allow multiple values, i.e. multiple nodes to attach */
527     yajl_config(hand, yajl_allow_multiple_values, true);
528     yajl_status stat;
529     setlocale(LC_NUMERIC, "C");
530     stat = yajl_parse(hand, (const unsigned char *)buf, n);
531     if (stat != yajl_status_ok && stat != yajl_status_client_canceled) {
532         unsigned char *str = yajl_get_error(hand, 1, (const unsigned char *)buf, n);
533         ELOG("JSON parsing error: %s\n", str);
534         yajl_free_error(hand, str);
535     }
536
537     setlocale(LC_NUMERIC, "");
538     yajl_complete_parse(hand);
539
540     fclose(f);
541
542     return content_result;
543 }
544
545 void tree_append_json(Con *con, const char *filename, char **errormsg) {
546     FILE *f;
547     if ((f = fopen(filename, "r")) == NULL) {
548         ELOG("Cannot open file \"%s\"\n", filename);
549         return;
550     }
551     struct stat stbuf;
552     if (fstat(fileno(f), &stbuf) != 0) {
553         ELOG("Cannot fstat() \"%s\"\n", filename);
554         fclose(f);
555         return;
556     }
557     char *buf = smalloc(stbuf.st_size);
558     int n = fread(buf, 1, stbuf.st_size, f);
559     if (n != stbuf.st_size) {
560         ELOG("File \"%s\" could not be read entirely, not loading.\n", filename);
561         fclose(f);
562         return;
563     }
564     DLOG("read %d bytes\n", n);
565     yajl_gen g;
566     yajl_handle hand;
567     static yajl_callbacks callbacks = {
568         .yajl_boolean = json_bool,
569         .yajl_integer = json_int,
570         .yajl_double = json_double,
571         .yajl_string = json_string,
572         .yajl_start_map = json_start_map,
573         .yajl_map_key = json_key,
574         .yajl_end_map = json_end_map,
575         .yajl_end_array = json_end_array,
576     };
577     g = yajl_gen_alloc(NULL);
578     hand = yajl_alloc(&callbacks, NULL, (void *)g);
579     /* Allowing comments allows for more user-friendly layout files. */
580     yajl_config(hand, yajl_allow_comments, true);
581     /* Allow multiple values, i.e. multiple nodes to attach */
582     yajl_config(hand, yajl_allow_multiple_values, true);
583     yajl_status stat;
584     json_node = con;
585     to_focus = NULL;
586     parsing_swallows = false;
587     parsing_rect = false;
588     parsing_deco_rect = false;
589     parsing_window_rect = false;
590     parsing_geometry = false;
591     parsing_focus = false;
592     setlocale(LC_NUMERIC, "C");
593     stat = yajl_parse(hand, (const unsigned char *)buf, n);
594     if (stat != yajl_status_ok) {
595         unsigned char *str = yajl_get_error(hand, 1, (const unsigned char *)buf, n);
596         ELOG("JSON parsing error: %s\n", str);
597         if (errormsg != NULL)
598             *errormsg = sstrdup((const char *)str);
599         yajl_free_error(hand, str);
600     }
601
602     /* In case not all containers were restored, we need to fix the
603      * percentages, otherwise i3 will crash immediately when rendering the
604      * next time. */
605     con_fix_percent(con);
606
607     setlocale(LC_NUMERIC, "");
608     yajl_complete_parse(hand);
609
610     fclose(f);
611     if (to_focus)
612         con_focus(to_focus);
613 }