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