i3
load_layout.c
Go to the documentation of this file.
1/*
2 * vim:ts=4:sw=4:expandtab
3 *
4 * i3 - an improved dynamic tiling window manager
5 * © 2009 Michael Stapelberg and contributors (see also: LICENSE)
6 *
7 * load_layout.c: Restore (parts of) the layout, for example after an inplace
8 * restart.
9 *
10 */
11#include "all.h"
12
13#include <locale.h>
14
15#include <yajl/yajl_parse.h>
16
17/* TODO: refactor the whole parsing thing */
18
19static char *last_key;
20static int incomplete;
21static Con *json_node;
22static Con *to_focus;
23static bool parsing_gaps;
24static bool parsing_swallows;
25static bool parsing_rect;
29static bool parsing_geometry;
30static bool parsing_focus;
31static bool parsing_marks;
33static bool swallow_is_empty;
34static int num_marks;
35/* We need to save each container that needs to be marked if we want to support
36 * marking non-leaf containers. In their case, the end_map for their children is
37 * called before their own end_map, so marking json_node would end up marking
38 * the latest child. We can't just mark containers immediately after we parse a
39 * mark because of #2511. */
44
45/* This list is used for reordering the focus stack after parsing the 'focus'
46 * array. */
48 int old_id;
49 TAILQ_ENTRY(focus_mapping) focus_mappings;
50};
51
52static TAILQ_HEAD(focus_mappings_head, focus_mapping) focus_mappings =
53 TAILQ_HEAD_INITIALIZER(focus_mappings);
54
55static int json_start_map(void *ctx) {
56 LOG("start of map, last_key = %s\n", last_key);
57 if (parsing_swallows) {
58 LOG("creating new swallow\n");
59 current_swallow = smalloc(sizeof(Match));
61 current_swallow->dock = M_DONTCHECK;
62 TAILQ_INSERT_TAIL(&(json_node->swallow_head), current_swallow, matches);
63 swallow_is_empty = true;
64 } else {
65 if (!parsing_rect &&
70 !parsing_gaps) {
71 if (last_key && strcasecmp(last_key, "floating_nodes") == 0) {
72 DLOG("New floating_node\n");
74 json_node = con_new_skeleton(NULL, NULL);
75 json_node->name = NULL;
76 json_node->parent = ws;
77 DLOG("Parent is workspace = %p\n", ws);
78 } else {
79 Con *parent = json_node;
80 json_node = con_new_skeleton(NULL, NULL);
81 json_node->name = NULL;
82 json_node->parent = parent;
83 }
84 /* json_node is incomplete and should be removed if parsing fails */
85 incomplete++;
86 DLOG("incomplete = %d\n", incomplete);
87 }
88 }
89 return 1;
90}
91
92static int json_end_map(void *ctx) {
93 LOG("end of map\n");
94 if (!parsing_swallows &&
95 !parsing_rect &&
100 !parsing_gaps) {
101 /* Set a few default values to simplify manually crafted layout files. */
102 if (json_node->layout == L_DEFAULT) {
103 DLOG("Setting layout = L_SPLITH\n");
105 }
106
107 /* Sanity check: swallow criteria don’t make any sense on a split
108 * container. */
109 if (con_is_split(json_node) > 0 && !TAILQ_EMPTY(&(json_node->swallow_head))) {
110 DLOG("sanity check: removing swallows specification from split container\n");
111 while (!TAILQ_EMPTY(&(json_node->swallow_head))) {
112 Match *match = TAILQ_FIRST(&(json_node->swallow_head));
113 TAILQ_REMOVE(&(json_node->swallow_head), match, matches);
114 match_free(match);
115 free(match);
116 }
117 }
118
119 if (json_node->type == CT_WORKSPACE) {
120 /* Ensure the workspace has a name. */
121 DLOG("Attaching workspace. name = %s\n", json_node->name);
122 if (json_node->name == NULL || strcmp(json_node->name, "") == 0) {
123 json_node->name = sstrdup("unnamed");
124 }
125
126 /* Prevent name clashes when appending a workspace, e.g. when the
127 * user tries to restore a workspace called “1” but already has a
128 * workspace called “1”. */
129 char *base = sstrdup(json_node->name);
130 int cnt = 1;
133 sasprintf(&(json_node->name), "%s_%d", base, cnt++);
134 }
135 free(base);
136
137 /* Set num accordingly so that i3bar will properly sort it. */
139 }
140
141 // When appending JSON layout files that only contain the workspace
142 // _contents_, we might not have an upfront signal that the
143 // container we’re currently parsing is a floating container (like
144 // the “floating_nodes” key of the workspace container itself).
145 // That’s why we make sure the con is attached at the right place
146 // in the hierarchy in case it’s floating.
147 if (json_node->type == CT_FLOATING_CON) {
148 DLOG("fixing parent which currently is %p / %s\n", json_node->parent, json_node->parent->name);
150
151 // Also set a size if none was supplied, otherwise the placeholder
152 // window cannot be created as X11 requests with width=0 or
153 // height=0 are invalid.
154 if (rect_equals(json_node->rect, (Rect){0, 0, 0, 0})) {
155 DLOG("Geometry not set, combining children\n");
156 Con *child;
157 TAILQ_FOREACH (child, &(json_node->nodes_head), nodes) {
158 DLOG("child geometry: %d x %d\n", child->geometry.width, child->geometry.height);
159 json_node->rect.width += child->geometry.width;
161 }
162 }
163
165 }
166
167 if (num_marks > 0) {
168 for (int i = 0; i < num_marks; i++) {
169 Con *con = marks[i].con_to_be_marked;
170 char *mark = marks[i].mark;
171 con_mark(con, mark, MM_ADD);
172 free(mark);
173 }
174
175 FREE(marks);
176 num_marks = 0;
177 }
178
179 LOG("attaching\n");
181 LOG("Creating window\n");
183
184 /* Fix erroneous JSON input regarding floating containers to avoid
185 * crashing, see #3901. */
186 const int old_floating_mode = json_node->floating;
187 if (old_floating_mode >= FLOATING_AUTO_ON && json_node->parent->type != CT_FLOATING_CON) {
188 LOG("Fixing floating node without CT_FLOATING_CON parent\n");
189
190 /* Force floating_enable to work */
191 json_node->floating = FLOATING_AUTO_OFF;
193 json_node->floating = old_floating_mode;
194 }
195
197 incomplete--;
198 DLOG("incomplete = %d\n", incomplete);
199 }
200
202 /* We parsed an empty swallow definition. This is an invalid layout
203 * definition, hence we reject it. */
204 ELOG("Layout file is invalid: found an empty swallow definition.\n");
205 return 0;
206 }
207
208 parsing_gaps = false;
209 parsing_rect = false;
211 parsing_deco_rect = false;
212 parsing_window_rect = false;
213 parsing_geometry = false;
214 return 1;
215}
216
217static int json_end_array(void *ctx) {
218 LOG("end of array\n");
221 }
222 if (parsing_swallows) {
223 parsing_swallows = false;
224 }
225 if (parsing_marks) {
226 parsing_marks = false;
227 }
228
229 if (parsing_focus) {
230 /* Clear the list of focus mappings */
231 struct focus_mapping *mapping;
232 TAILQ_FOREACH_REVERSE (mapping, &focus_mappings, focus_mappings_head, focus_mappings) {
233 LOG("focus (reverse) %d\n", mapping->old_id);
234 Con *con;
235 TAILQ_FOREACH (con, &(json_node->focus_head), focused) {
236 if (con->old_id != mapping->old_id)
237 continue;
238 LOG("got it! %p\n", con);
239 /* Move this entry to the top of the focus list. */
240 TAILQ_REMOVE(&(json_node->focus_head), con, focused);
241 TAILQ_INSERT_HEAD(&(json_node->focus_head), con, focused);
242 break;
243 }
244 }
245 while (!TAILQ_EMPTY(&focus_mappings)) {
246 mapping = TAILQ_FIRST(&focus_mappings);
247 TAILQ_REMOVE(&focus_mappings, mapping, focus_mappings);
248 free(mapping);
249 }
250 parsing_focus = false;
251 }
252 return 1;
253}
254
255static int json_key(void *ctx, const unsigned char *val, size_t len) {
256 LOG("key: %.*s\n", (int)len, val);
257 FREE(last_key);
258 last_key = scalloc(len + 1, 1);
259 memcpy(last_key, val, len);
260 if (strcasecmp(last_key, "swallows") == 0)
261 parsing_swallows = true;
262
263 if (strcasecmp(last_key, "gaps") == 0)
264 parsing_gaps = true;
265
266 if (strcasecmp(last_key, "rect") == 0)
267 parsing_rect = true;
268
269 if (strcasecmp(last_key, "actual_deco_rect") == 0)
271
272 if (strcasecmp(last_key, "deco_rect") == 0)
273 parsing_deco_rect = true;
274
275 if (strcasecmp(last_key, "window_rect") == 0)
276 parsing_window_rect = true;
277
278 if (strcasecmp(last_key, "geometry") == 0)
279 parsing_geometry = true;
280
281 if (strcasecmp(last_key, "focus") == 0)
282 parsing_focus = true;
283
284 if (strcasecmp(last_key, "marks") == 0) {
285 num_marks = 0;
286 parsing_marks = true;
287 }
288
289 return 1;
290}
291
292static int json_string(void *ctx, const unsigned char *val, size_t len) {
293 LOG("string: %.*s for key %s\n", (int)len, val, last_key);
294 if (parsing_swallows) {
295 char *sval;
296 sasprintf(&sval, "%.*s", len, val);
297 if (strcasecmp(last_key, "class") == 0) {
299 swallow_is_empty = false;
300 } else if (strcasecmp(last_key, "instance") == 0) {
302 swallow_is_empty = false;
303 } else if (strcasecmp(last_key, "window_role") == 0) {
305 swallow_is_empty = false;
306 } else if (strcasecmp(last_key, "title") == 0) {
308 swallow_is_empty = false;
309 } else if (strcasecmp(last_key, "machine") == 0) {
311 swallow_is_empty = false;
312 } else {
313 ELOG("swallow key %s unknown\n", last_key);
314 }
315 free(sval);
316 } else if (parsing_marks) {
317 char *mark;
318 sasprintf(&mark, "%.*s", (int)len, val);
319
320 marks = srealloc(marks, (++num_marks) * sizeof(struct pending_marks));
321 marks[num_marks - 1].mark = sstrdup(mark);
323 } else {
324 if (strcasecmp(last_key, "name") == 0) {
325 json_node->name = scalloc(len + 1, 1);
326 memcpy(json_node->name, val, len);
327 } else if (strcasecmp(last_key, "title_format") == 0) {
328 json_node->title_format = scalloc(len + 1, 1);
329 memcpy(json_node->title_format, val, len);
330 } else if (strcasecmp(last_key, "sticky_group") == 0) {
331 json_node->sticky_group = scalloc(len + 1, 1);
332 memcpy(json_node->sticky_group, val, len);
333 LOG("sticky_group of this container is %s\n", json_node->sticky_group);
334 } else if (strcasecmp(last_key, "orientation") == 0) {
335 /* Upgrade path from older versions of i3 (doing an inplace restart
336 * to a newer version):
337 * "orientation" is dumped before "layout". Therefore, we store
338 * whether the orientation was horizontal or vertical in the
339 * last_split_layout. When we then encounter layout == "default",
340 * we will use the last_split_layout as layout instead. */
341 char *buf = NULL;
342 sasprintf(&buf, "%.*s", (int)len, val);
343 if (strcasecmp(buf, "none") == 0 ||
344 strcasecmp(buf, "horizontal") == 0)
346 else if (strcasecmp(buf, "vertical") == 0)
348 else
349 LOG("Unhandled orientation: %s\n", buf);
350 free(buf);
351 } else if (strcasecmp(last_key, "border") == 0) {
352 char *buf = NULL;
353 sasprintf(&buf, "%.*s", (int)len, val);
354 if (strcasecmp(buf, "none") == 0) {
356 } else if (strcasecmp(buf, "1pixel") == 0) {
359 } else if (strcasecmp(buf, "pixel") == 0) {
361 } else if (strcasecmp(buf, "normal") == 0) {
363 } else {
364 LOG("Unhandled \"border\": %s\n", buf);
365 }
366 free(buf);
367 } else if (strcasecmp(last_key, "type") == 0) {
368 char *buf = NULL;
369 sasprintf(&buf, "%.*s", (int)len, val);
370 if (strcasecmp(buf, "root") == 0)
371 json_node->type = CT_ROOT;
372 else if (strcasecmp(buf, "output") == 0)
373 json_node->type = CT_OUTPUT;
374 else if (strcasecmp(buf, "con") == 0)
375 json_node->type = CT_CON;
376 else if (strcasecmp(buf, "floating_con") == 0)
377 json_node->type = CT_FLOATING_CON;
378 else if (strcasecmp(buf, "workspace") == 0)
379 json_node->type = CT_WORKSPACE;
380 else if (strcasecmp(buf, "dockarea") == 0)
381 json_node->type = CT_DOCKAREA;
382 else
383 LOG("Unhandled \"type\": %s\n", buf);
384 free(buf);
385 } else if (strcasecmp(last_key, "layout") == 0) {
386 char *buf = NULL;
387 sasprintf(&buf, "%.*s", (int)len, val);
388 if (strcasecmp(buf, "default") == 0)
389 /* This set above when we read "orientation". */
391 else if (strcasecmp(buf, "stacked") == 0)
393 else if (strcasecmp(buf, "tabbed") == 0)
395 else if (strcasecmp(buf, "dockarea") == 0)
397 else if (strcasecmp(buf, "output") == 0)
399 else if (strcasecmp(buf, "splith") == 0)
401 else if (strcasecmp(buf, "splitv") == 0)
403 else
404 LOG("Unhandled \"layout\": %s\n", buf);
405 free(buf);
406 } else if (strcasecmp(last_key, "workspace_layout") == 0) {
407 char *buf = NULL;
408 sasprintf(&buf, "%.*s", (int)len, val);
409 if (strcasecmp(buf, "default") == 0)
411 else if (strcasecmp(buf, "stacked") == 0)
413 else if (strcasecmp(buf, "tabbed") == 0)
415 else
416 LOG("Unhandled \"workspace_layout\": %s\n", buf);
417 free(buf);
418 } else if (strcasecmp(last_key, "last_split_layout") == 0) {
419 char *buf = NULL;
420 sasprintf(&buf, "%.*s", (int)len, val);
421 if (strcasecmp(buf, "splith") == 0)
423 else if (strcasecmp(buf, "splitv") == 0)
425 else
426 LOG("Unhandled \"last_splitlayout\": %s\n", buf);
427 free(buf);
428 } else if (strcasecmp(last_key, "mark") == 0) {
429 DLOG("Found deprecated key \"mark\".\n");
430
431 char *buf = NULL;
432 sasprintf(&buf, "%.*s", (int)len, val);
433
435 } else if (strcasecmp(last_key, "floating") == 0) {
436 char *buf = NULL;
437 sasprintf(&buf, "%.*s", (int)len, val);
438 if (strcasecmp(buf, "auto_off") == 0)
439 json_node->floating = FLOATING_AUTO_OFF;
440 else if (strcasecmp(buf, "auto_on") == 0)
441 json_node->floating = FLOATING_AUTO_ON;
442 else if (strcasecmp(buf, "user_off") == 0)
443 json_node->floating = FLOATING_USER_OFF;
444 else if (strcasecmp(buf, "user_on") == 0)
445 json_node->floating = FLOATING_USER_ON;
446 free(buf);
447 } else if (strcasecmp(last_key, "scratchpad_state") == 0) {
448 char *buf = NULL;
449 sasprintf(&buf, "%.*s", (int)len, val);
450 if (strcasecmp(buf, "none") == 0)
451 json_node->scratchpad_state = SCRATCHPAD_NONE;
452 else if (strcasecmp(buf, "fresh") == 0)
453 json_node->scratchpad_state = SCRATCHPAD_FRESH;
454 else if (strcasecmp(buf, "changed") == 0)
455 json_node->scratchpad_state = SCRATCHPAD_CHANGED;
456 free(buf);
457 } else if (strcasecmp(last_key, "previous_workspace_name") == 0) {
459 previous_workspace_name = sstrndup((const char *)val, len);
460 }
461 }
462 return 1;
463}
464
465static int json_int(void *ctx, long long val) {
466 LOG("int %lld for key %s\n", val, last_key);
467 /* For backwards compatibility with i3 < 4.8 */
468 if (strcasecmp(last_key, "type") == 0)
469 json_node->type = val;
470
471 if (strcasecmp(last_key, "fullscreen_mode") == 0)
473
474 if (strcasecmp(last_key, "num") == 0)
475 json_node->num = val;
476
477 if (strcasecmp(last_key, "current_border_width") == 0)
479
480 if (strcasecmp(last_key, "window_icon_padding") == 0) {
482 }
483
484 if (strcasecmp(last_key, "depth") == 0)
485 json_node->depth = val;
486
487 if (!parsing_swallows && strcasecmp(last_key, "id") == 0)
488 json_node->old_id = val;
489
490 if (parsing_focus) {
491 struct focus_mapping *focus_mapping = scalloc(1, sizeof(struct focus_mapping));
492 focus_mapping->old_id = val;
493 TAILQ_INSERT_TAIL(&focus_mappings, focus_mapping, focus_mappings);
494 }
495
497 Rect *r;
498 if (parsing_rect)
499 r = &(json_node->rect);
500 else if (parsing_window_rect)
501 r = &(json_node->window_rect);
502 else
503 r = &(json_node->geometry);
504 if (strcasecmp(last_key, "x") == 0)
505 r->x = val;
506 else if (strcasecmp(last_key, "y") == 0)
507 r->y = val;
508 else if (strcasecmp(last_key, "width") == 0)
509 r->width = val;
510 else if (strcasecmp(last_key, "height") == 0)
511 r->height = val;
512 else
513 ELOG("WARNING: unknown key %s in rect\n", last_key);
514 DLOG("rect now: (%d, %d, %d, %d)\n",
515 r->x, r->y, r->width, r->height);
516 }
517 if (parsing_swallows) {
518 if (strcasecmp(last_key, "id") == 0) {
519 current_swallow->id = val;
520 swallow_is_empty = false;
521 }
522 if (strcasecmp(last_key, "dock") == 0) {
523 current_swallow->dock = val;
524 swallow_is_empty = false;
525 }
526 if (strcasecmp(last_key, "insert_where") == 0) {
528 swallow_is_empty = false;
529 }
530 }
531 if (parsing_gaps) {
532 if (strcasecmp(last_key, "inner") == 0)
533 json_node->gaps.inner = val;
534 else if (strcasecmp(last_key, "top") == 0)
535 json_node->gaps.top = val;
536 else if (strcasecmp(last_key, "right") == 0)
537 json_node->gaps.right = val;
538 else if (strcasecmp(last_key, "bottom") == 0)
539 json_node->gaps.bottom = val;
540 else if (strcasecmp(last_key, "left") == 0)
541 json_node->gaps.left = val;
542 }
543
544 return 1;
545}
546
547static int json_bool(void *ctx, int val) {
548 LOG("bool %d for key %s\n", val, last_key);
549 if (strcasecmp(last_key, "focused") == 0 && val) {
551 }
552
553 if (strcasecmp(last_key, "sticky") == 0)
554 json_node->sticky = val;
555
556 if (parsing_swallows) {
557 if (strcasecmp(last_key, "restart_mode") == 0) {
559 swallow_is_empty = false;
560 }
561 }
562
563 return 1;
564}
565
566static int json_double(void *ctx, double val) {
567 LOG("double %f for key %s\n", val, last_key);
568 if (strcasecmp(last_key, "percent") == 0) {
569 json_node->percent = val;
570 }
571 return 1;
572}
573
575static int content_level;
576
579 return 1;
580}
581
584 return 1;
585}
586
587static int json_determine_content_string(void *ctx, const unsigned char *val, size_t len) {
588 if (strcasecmp(last_key, "type") != 0 || content_level > 1)
589 return 1;
590
591 DLOG("string = %.*s, last_key = %s\n", (int)len, val, last_key);
592 if (strncasecmp((const char *)val, "workspace", len) == 0)
594 return 0;
595}
596
597/*
598 * Returns true if the provided JSON could be parsed by yajl.
599 *
600 */
601bool json_validate(const char *buf, const size_t len) {
602 bool valid = true;
603 yajl_handle hand = yajl_alloc(NULL, NULL, NULL);
604 /* Allowing comments allows for more user-friendly layout files. */
605 yajl_config(hand, yajl_allow_comments, true);
606 /* Allow multiple values, i.e. multiple nodes to attach */
607 yajl_config(hand, yajl_allow_multiple_values, true);
608
609 setlocale(LC_NUMERIC, "C");
610 if (yajl_parse(hand, (const unsigned char *)buf, len) != yajl_status_ok) {
611 unsigned char *str = yajl_get_error(hand, 1, (const unsigned char *)buf, len);
612 ELOG("JSON parsing error: %s\n", str);
613 yajl_free_error(hand, str);
614 valid = false;
615 }
616 setlocale(LC_NUMERIC, "");
617
618 yajl_complete_parse(hand);
619 yajl_free(hand);
620
621 return valid;
622}
623
624/* Parses the given JSON file until it encounters the first “type” property to
625 * determine whether the file contains workspaces or regular containers, which
626 * is important to know when deciding where (and how) to append the contents.
627 * */
628json_content_t json_determine_content(const char *buf, const size_t len) {
629 // We default to JSON_CONTENT_CON because it is legal to not include
630 // “"type": "con"” in the JSON files for better readability.
632 content_level = 0;
633 static yajl_callbacks callbacks = {
634 .yajl_string = json_determine_content_string,
635 .yajl_map_key = json_key,
636 .yajl_start_array = json_determine_content_deeper,
637 .yajl_start_map = json_determine_content_deeper,
638 .yajl_end_map = json_determine_content_shallower,
639 .yajl_end_array = json_determine_content_shallower,
640 };
641 yajl_handle hand = yajl_alloc(&callbacks, NULL, NULL);
642 /* Allowing comments allows for more user-friendly layout files. */
643 yajl_config(hand, yajl_allow_comments, true);
644 /* Allow multiple values, i.e. multiple nodes to attach */
645 yajl_config(hand, yajl_allow_multiple_values, true);
646 setlocale(LC_NUMERIC, "C");
647 const yajl_status stat = yajl_parse(hand, (const unsigned char *)buf, len);
648 if (stat != yajl_status_ok && stat != yajl_status_client_canceled) {
649 unsigned char *str = yajl_get_error(hand, 1, (const unsigned char *)buf, len);
650 ELOG("JSON parsing error: %s\n", str);
651 yajl_free_error(hand, str);
652 }
653
654 setlocale(LC_NUMERIC, "");
655 yajl_complete_parse(hand);
656 yajl_free(hand);
657
658 return content_result;
659}
660
661void tree_append_json(Con *con, const char *buf, const size_t len, char **errormsg) {
662 static yajl_callbacks callbacks = {
663 .yajl_boolean = json_bool,
664 .yajl_integer = json_int,
665 .yajl_double = json_double,
666 .yajl_string = json_string,
667 .yajl_start_map = json_start_map,
668 .yajl_map_key = json_key,
669 .yajl_end_map = json_end_map,
670 .yajl_end_array = json_end_array,
671 };
672 yajl_handle hand = yajl_alloc(&callbacks, NULL, NULL);
673 /* Allowing comments allows for more user-friendly layout files. */
674 yajl_config(hand, yajl_allow_comments, true);
675 /* Allow multiple values, i.e. multiple nodes to attach */
676 yajl_config(hand, yajl_allow_multiple_values, true);
677 /* We don't need to validate that the input is valid UTF8 here.
678 * tree_append_json is called in two cases:
679 * 1. With the append_layout command. json_validate is called first and will
680 * fail on invalid UTF8 characters so we don't need to recheck.
681 * 2. With an in-place restart. The rest of the codebase should be
682 * responsible for producing valid UTF8 JSON output. If not,
683 * tree_append_json will just preserve invalid UTF8 strings in the tree
684 * instead of failing to parse the layout file which could lead to
685 * problems like in #3156.
686 * Either way, disabling UTF8 validation slightly speeds up yajl. */
687 yajl_config(hand, yajl_dont_validate_strings, true);
688 json_node = con;
689 to_focus = NULL;
690 parsing_gaps = false;
691 incomplete = 0;
692 parsing_swallows = false;
693 parsing_rect = false;
695 parsing_deco_rect = false;
696 parsing_window_rect = false;
697 parsing_geometry = false;
698 parsing_focus = false;
699 parsing_marks = false;
700 setlocale(LC_NUMERIC, "C");
701 const yajl_status stat = yajl_parse(hand, (const unsigned char *)buf, len);
702 if (stat != yajl_status_ok) {
703 unsigned char *str = yajl_get_error(hand, 1, (const unsigned char *)buf, len);
704 ELOG("JSON parsing error: %s\n", str);
705 if (errormsg != NULL)
706 *errormsg = sstrdup((const char *)str);
707 yajl_free_error(hand, str);
708 while (incomplete-- > 0) {
709 Con *parent = json_node->parent;
710 DLOG("freeing incomplete container %p\n", json_node);
711 if (json_node == to_focus) {
712 to_focus = NULL;
713 }
715 json_node = parent;
716 }
717 }
718
719 /* In case not all containers were restored, we need to fix the
720 * percentages, otherwise i3 will crash immediately when rendering the
721 * next time. */
722 con_fix_percent(con);
723
724 setlocale(LC_NUMERIC, "");
725 yajl_complete_parse(hand);
726 yajl_free(hand);
727
728 if (to_focus) {
730 }
731}
Con * con_get_workspace(Con *con)
Gets the workspace container this node is on.
Definition con.c:477
bool con_is_split(Con *con)
Returns true if a container should be considered split.
Definition con.c:385
Con * con_new_skeleton(Con *parent, i3Window *window)
Create a new container (and attach it to the given parent, if not NULL).
Definition con.c:38
void con_mark(Con *con, const char *mark, mark_mode_t mode)
Assigns a mark to the container.
Definition con.c:806
void con_fix_percent(Con *con)
Updates the percent attribute of the children of the given container.
Definition con.c:1047
void con_attach(Con *con, Con *parent, bool ignore_focus)
Attaches the given container to the given parent.
Definition con.c:222
void con_free(Con *con)
Frees the specified container.
Definition con.c:79
void con_activate(Con *con)
Sets input focus to the given container and raises it to the top.
Definition con.c:287
void floating_check_size(Con *floating_con, bool prefer_height)
Called when a floating window is created or resized.
Definition floating.c:75
bool floating_enable(Con *con, bool automatic)
Enables floating mode for the given container by detaching it from its parent, creating a new contain...
Definition floating.c:232
static bool parsing_focus
Definition load_layout.c:30
static int content_level
static int json_end_array(void *ctx)
static int json_determine_content_deeper(void *ctx)
static int json_determine_content_string(void *ctx, const unsigned char *val, size_t len)
static bool parsing_geometry
Definition load_layout.c:29
static int num_marks
Definition load_layout.c:34
struct pending_marks * marks
static bool parsing_gaps
Definition load_layout.c:23
static int incomplete
Definition load_layout.c:20
static char * last_key
Definition load_layout.c:19
static json_content_t content_result
bool json_validate(const char *buf, const size_t len)
Returns true if the provided JSON could be parsed by yajl.
static Con * json_node
Definition load_layout.c:21
static bool parsing_deco_rect
Definition load_layout.c:27
static int json_int(void *ctx, long long val)
static int json_bool(void *ctx, int val)
static bool parsing_rect
Definition load_layout.c:25
struct Match * current_swallow
Definition load_layout.c:32
static Con * to_focus
Definition load_layout.c:22
static int json_end_map(void *ctx)
Definition load_layout.c:92
static bool parsing_actual_deco_rect
Definition load_layout.c:26
json_content_t json_determine_content(const char *buf, const size_t len)
static int json_double(void *ctx, double val)
static bool swallow_is_empty
Definition load_layout.c:33
static int json_key(void *ctx, const unsigned char *val, size_t len)
static bool parsing_marks
Definition load_layout.c:31
static bool parsing_swallows
Definition load_layout.c:24
static int json_string(void *ctx, const unsigned char *val, size_t len)
static int json_determine_content_shallower(void *ctx)
static bool parsing_window_rect
Definition load_layout.c:28
void tree_append_json(Con *con, const char *buf, const size_t len, char **errormsg)
void match_init(Match *match)
Initializes the Match data structure.
Definition match.c:26
void match_free(Match *match)
Frees the given match.
Definition match.c:276
struct regex * regex_new(const char *pattern)
Creates a new 'regex' struct containing the given pattern and a PCRE compiled regular expression.
Definition regex.c:22
struct Con * focused
Definition tree.c:13
int ws_name_to_number(const char *name)
Parses the workspace name as a number.
Definition util.c:109
bool rect_equals(Rect a, Rect b)
Definition util.c:59
int max(int a, int b)
Definition util.c:28
Con * get_existing_workspace_by_name(const char *name)
Returns the workspace with the given name or NULL if such a workspace does not exist.
Definition workspace.c:30
char * previous_workspace_name
Stores a copy of the name of the last used workspace for the workspace back-and-forth switching.
Definition workspace.c:19
void x_con_init(Con *con)
Initializes the X11 part for the given container.
Definition x.c:127
static xcb_cursor_context_t * ctx
Definition xcursor.c:19
@ L_STACKED
Definition data.h:107
@ L_TABBED
Definition data.h:108
@ L_DOCKAREA
Definition data.h:109
@ L_OUTPUT
Definition data.h:110
@ L_SPLITH
Definition data.h:112
@ L_SPLITV
Definition data.h:111
@ L_DEFAULT
Definition data.h:106
@ MM_ADD
Definition data.h:100
@ MM_REPLACE
Definition data.h:99
@ BS_NONE
Definition data.h:66
@ BS_PIXEL
Definition data.h:67
@ BS_NORMAL
Definition data.h:68
#define DLOG(fmt,...)
Definition libi3.h:105
#define LOG(fmt,...)
Definition libi3.h:95
char * sstrdup(const char *str)
Safe-wrapper around strdup which exits if malloc returns NULL (meaning that there is no more memory a...
#define ELOG(fmt,...)
Definition libi3.h:100
void * scalloc(size_t num, size_t size)
Safe-wrapper around calloc which exits if malloc returns NULL (meaning that there is no more memory a...
int sasprintf(char **strp, const char *fmt,...)
Safe-wrapper around asprintf which exits if it returns -1 (meaning that there is no more memory avail...
char * sstrndup(const char *str, size_t size)
Safe-wrapper around strndup which exits if strndup returns NULL (meaning that there is no more memory...
void * srealloc(void *ptr, size_t size)
Safe-wrapper around realloc which exits if realloc returns NULL (meaning that there is no more memory...
void * smalloc(size_t size)
Safe-wrapper around malloc which exits if malloc returns NULL (meaning that there is no more memory a...
json_content_t
Definition load_layout.h:15
@ JSON_CONTENT_CON
Definition load_layout.h:22
@ JSON_CONTENT_WORKSPACE
Definition load_layout.h:27
#define TAILQ_FOREACH(var, head, field)
Definition queue.h:347
#define TAILQ_HEAD(name, type)
Definition queue.h:318
#define TAILQ_INSERT_TAIL(head, elm, field)
Definition queue.h:376
#define TAILQ_FIRST(head)
Definition queue.h:336
#define TAILQ_FOREACH_REVERSE(var, head, headname, field)
Definition queue.h:352
#define TAILQ_REMOVE(head, elm, field)
Definition queue.h:402
#define TAILQ_HEAD_INITIALIZER(head)
Definition queue.h:324
#define TAILQ_EMPTY(head)
Definition queue.h:344
#define TAILQ_INSERT_HEAD(head, elm, field)
Definition queue.h:366
#define TAILQ_ENTRY(type)
Definition queue.h:327
#define FREE(pointer)
Definition util.h:47
Con * con_to_be_marked
Definition load_layout.c:42
int inner
Definition data.h:151
int left
Definition data.h:155
int right
Definition data.h:153
int top
Definition data.h:152
int bottom
Definition data.h:154
Stores a rectangle, for example the size of a window, the child window etc.
Definition data.h:189
uint32_t height
Definition data.h:193
uint32_t x
Definition data.h:190
uint32_t y
Definition data.h:191
uint32_t width
Definition data.h:192
A "match" is a data structure which acts like a mask or expression to match certain windows or not.
Definition data.h:533
struct regex * window_role
Definition data.h:542
struct regex * title
Definition data.h:537
struct regex * instance
Definition data.h:540
struct regex * machine
Definition data.h:544
bool restart_mode
Definition data.h:587
enum Match::@15 insert_where
xcb_window_t id
Definition data.h:558
struct regex * class
Definition data.h:539
enum Match::@13 dock
A 'Con' represents everything from the X11 root window down to a single X11 window.
Definition data.h:647
struct Con * parent
Definition data.h:682
enum Con::@20 scratchpad_state
enum Con::@18 type
layout_t workspace_layout
Definition data.h:759
double percent
Definition data.h:716
layout_t last_split_layout
Definition data.h:759
struct Rect rect
Definition data.h:686
gaps_t gaps
Only applicable for containers of type CT_WORKSPACE.
Definition data.h:680
int current_border_width
Definition data.h:720
bool sticky
Definition data.h:743
border_style_t max_user_border_style
Definition data.h:768
layout_t layout
Definition data.h:759
int num
the workspace number, if this Con is of type CT_WORKSPACE and the workspace is not a named workspace ...
Definition data.h:677
struct Rect window_rect
Definition data.h:689
int window_icon_padding
Whether the window icon should be displayed, and with what padding.
Definition data.h:704
int old_id
Definition data.h:805
char * title_format
The format with which the window's name should be displayed.
Definition data.h:699
border_style_t border_style
Definition data.h:761
char * name
Definition data.h:696
struct Rect geometry
the geometry this window requested when getting mapped
Definition data.h:694
char * sticky_group
Definition data.h:709
uint16_t depth
Definition data.h:808
enum Con::@19 floating
floating? (= not in tiling layout) This cannot be simply a bool because we want to keep track of whet...
fullscreen_mode_t fullscreen_mode
Definition data.h:738