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 
19 static char *last_key;
20 static int incomplete;
21 static Con *json_node;
22 static Con *to_focus;
23 static bool parsing_swallows;
24 static bool parsing_rect;
25 static bool parsing_deco_rect;
26 static bool parsing_window_rect;
27 static bool parsing_geometry;
28 static bool parsing_focus;
29 static bool parsing_marks;
31 static bool swallow_is_empty;
32 static int num_marks;
33 /* We need to save each container that needs to be marked if we want to support
34  * marking non-leaf containers. In their case, the end_map for their children is
35  * called before their own end_map, so marking json_node would end up marking
36  * the latest child. We can't just mark containers immediately after we parse a
37  * mark because of #2511. */
38 struct pending_marks {
39  char *mark;
41 } * marks;
42 
43 /* This list is used for reordering the focus stack after parsing the 'focus'
44  * array. */
45 struct focus_mapping {
46  int old_id;
47  TAILQ_ENTRY(focus_mapping) focus_mappings;
48 };
49 
50 static TAILQ_HEAD(focus_mappings_head, focus_mapping) focus_mappings =
51  TAILQ_HEAD_INITIALIZER(focus_mappings);
52 
53 static int json_start_map(void *ctx) {
54  LOG("start of map, last_key = %s\n", last_key);
55  if (parsing_swallows) {
56  LOG("creating new swallow\n");
57  current_swallow = smalloc(sizeof(Match));
59  current_swallow->dock = M_DONTCHECK;
60  TAILQ_INSERT_TAIL(&(json_node->swallow_head), current_swallow, matches);
61  swallow_is_empty = true;
62  } else {
64  if (last_key && strcasecmp(last_key, "floating_nodes") == 0) {
65  DLOG("New floating_node\n");
67  json_node = con_new_skeleton(NULL, NULL);
68  json_node->name = NULL;
69  json_node->parent = ws;
70  DLOG("Parent is workspace = %p\n", ws);
71  } else {
72  Con *parent = json_node;
73  json_node = con_new_skeleton(NULL, NULL);
74  json_node->name = NULL;
75  json_node->parent = parent;
76  }
77  /* json_node is incomplete and should be removed if parsing fails */
78  incomplete++;
79  DLOG("incomplete = %d\n", incomplete);
80  }
81  }
82  return 1;
83 }
84 
85 static int json_end_map(void *ctx) {
86  LOG("end of map\n");
88  /* Set a few default values to simplify manually crafted layout files. */
89  if (json_node->layout == L_DEFAULT) {
90  DLOG("Setting layout = L_SPLITH\n");
92  }
93 
94  /* Sanity check: swallow criteria don’t make any sense on a split
95  * container. */
96  if (con_is_split(json_node) > 0 && !TAILQ_EMPTY(&(json_node->swallow_head))) {
97  DLOG("sanity check: removing swallows specification from split container\n");
98  while (!TAILQ_EMPTY(&(json_node->swallow_head))) {
99  Match *match = TAILQ_FIRST(&(json_node->swallow_head));
100  TAILQ_REMOVE(&(json_node->swallow_head), match, matches);
101  match_free(match);
102  free(match);
103  }
104  }
105 
106  if (json_node->type == CT_WORKSPACE) {
107  /* Ensure the workspace has a name. */
108  DLOG("Attaching workspace. name = %s\n", json_node->name);
109  if (json_node->name == NULL || strcmp(json_node->name, "") == 0) {
110  json_node->name = sstrdup("unnamed");
111  }
112 
113  /* Prevent name clashes when appending a workspace, e.g. when the
114  * user tries to restore a workspace called “1” but already has a
115  * workspace called “1”. */
116  char *base = sstrdup(json_node->name);
117  int cnt = 1;
118  while (get_existing_workspace_by_name(json_node->name) != NULL) {
119  FREE(json_node->name);
120  sasprintf(&(json_node->name), "%s_%d", base, cnt++);
121  }
122  free(base);
123 
124  /* Set num accordingly so that i3bar will properly sort it. */
126  }
127 
128  // When appending JSON layout files that only contain the workspace
129  // _contents_, we might not have an upfront signal that the
130  // container we’re currently parsing is a floating container (like
131  // the “floating_nodes” key of the workspace container itself).
132  // That’s why we make sure the con is attached at the right place
133  // in the hierarchy in case it’s floating.
134  if (json_node->type == CT_FLOATING_CON) {
135  DLOG("fixing parent which currently is %p / %s\n", json_node->parent, json_node->parent->name);
137 
138  // Also set a size if none was supplied, otherwise the placeholder
139  // window cannot be created as X11 requests with width=0 or
140  // height=0 are invalid.
141  if (rect_equals(json_node->rect, (Rect){0, 0, 0, 0})) {
142  DLOG("Geometry not set, combining children\n");
143  Con *child;
144  TAILQ_FOREACH (child, &(json_node->nodes_head), nodes) {
145  DLOG("child geometry: %d x %d\n", child->geometry.width, child->geometry.height);
146  json_node->rect.width += child->geometry.width;
148  }
149  }
150 
152  }
153 
154  if (num_marks > 0) {
155  for (int i = 0; i < num_marks; i++) {
156  Con *con = marks[i].con_to_be_marked;
157  char *mark = marks[i].mark;
158  con_mark(con, mark, MM_ADD);
159  free(mark);
160  }
161 
162  FREE(marks);
163  num_marks = 0;
164  }
165 
166  LOG("attaching\n");
168  LOG("Creating window\n");
170 
171  /* Fix erroneous JSON input regarding floating containers to avoid
172  * crashing, see #3901. */
173  const int old_floating_mode = json_node->floating;
174  if (old_floating_mode >= FLOATING_AUTO_ON && json_node->parent->type != CT_FLOATING_CON) {
175  LOG("Fixing floating node without CT_FLOATING_CON parent\n");
176 
177  /* Force floating_enable to work */
178  json_node->floating = FLOATING_AUTO_OFF;
179  floating_enable(json_node, false);
180  json_node->floating = old_floating_mode;
181  }
182 
184  incomplete--;
185  DLOG("incomplete = %d\n", incomplete);
186  }
187 
189  /* We parsed an empty swallow definition. This is an invalid layout
190  * definition, hence we reject it. */
191  ELOG("Layout file is invalid: found an empty swallow definition.\n");
192  return 0;
193  }
194 
195  parsing_rect = false;
196  parsing_deco_rect = false;
197  parsing_window_rect = false;
198  parsing_geometry = false;
199  return 1;
200 }
201 
202 static int json_end_array(void *ctx) {
203  LOG("end of array\n");
206  }
207  if (parsing_swallows) {
208  parsing_swallows = false;
209  }
210  if (parsing_marks) {
211  parsing_marks = false;
212  }
213 
214  if (parsing_focus) {
215  /* Clear the list of focus mappings */
216  struct focus_mapping *mapping;
217  TAILQ_FOREACH_REVERSE (mapping, &focus_mappings, focus_mappings_head, focus_mappings) {
218  LOG("focus (reverse) %d\n", mapping->old_id);
219  Con *con;
220  TAILQ_FOREACH (con, &(json_node->focus_head), focused) {
221  if (con->old_id != mapping->old_id)
222  continue;
223  LOG("got it! %p\n", con);
224  /* Move this entry to the top of the focus list. */
225  TAILQ_REMOVE(&(json_node->focus_head), con, focused);
226  TAILQ_INSERT_HEAD(&(json_node->focus_head), con, focused);
227  break;
228  }
229  }
230  while (!TAILQ_EMPTY(&focus_mappings)) {
231  mapping = TAILQ_FIRST(&focus_mappings);
232  TAILQ_REMOVE(&focus_mappings, mapping, focus_mappings);
233  free(mapping);
234  }
235  parsing_focus = false;
236  }
237  return 1;
238 }
239 
240 static int json_key(void *ctx, const unsigned char *val, size_t len) {
241  LOG("key: %.*s\n", (int)len, val);
242  FREE(last_key);
243  last_key = scalloc(len + 1, 1);
244  memcpy(last_key, val, len);
245  if (strcasecmp(last_key, "swallows") == 0)
246  parsing_swallows = true;
247 
248  if (strcasecmp(last_key, "rect") == 0)
249  parsing_rect = true;
250 
251  if (strcasecmp(last_key, "deco_rect") == 0)
252  parsing_deco_rect = true;
253 
254  if (strcasecmp(last_key, "window_rect") == 0)
255  parsing_window_rect = true;
256 
257  if (strcasecmp(last_key, "geometry") == 0)
258  parsing_geometry = true;
259 
260  if (strcasecmp(last_key, "focus") == 0)
261  parsing_focus = true;
262 
263  if (strcasecmp(last_key, "marks") == 0) {
264  num_marks = 0;
265  parsing_marks = true;
266  }
267 
268  return 1;
269 }
270 
271 static int json_string(void *ctx, const unsigned char *val, size_t len) {
272  LOG("string: %.*s for key %s\n", (int)len, val, last_key);
273  if (parsing_swallows) {
274  char *sval;
275  sasprintf(&sval, "%.*s", len, val);
276  if (strcasecmp(last_key, "class") == 0) {
278  swallow_is_empty = false;
279  } else if (strcasecmp(last_key, "instance") == 0) {
281  swallow_is_empty = false;
282  } else if (strcasecmp(last_key, "window_role") == 0) {
284  swallow_is_empty = false;
285  } else if (strcasecmp(last_key, "title") == 0) {
287  swallow_is_empty = false;
288  } else if (strcasecmp(last_key, "machine") == 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 
443 static 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)
450  json_node->fullscreen_mode = val;
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, "window_icon_padding") == 0) {
460  }
461 
462  if (strcasecmp(last_key, "depth") == 0)
463  json_node->depth = val;
464 
465  if (!parsing_swallows && strcasecmp(last_key, "id") == 0)
466  json_node->old_id = val;
467 
468  if (parsing_focus) {
469  struct focus_mapping *focus_mapping = scalloc(1, sizeof(struct focus_mapping));
470  focus_mapping->old_id = val;
471  TAILQ_INSERT_TAIL(&focus_mappings, focus_mapping, focus_mappings);
472  }
473 
475  Rect *r;
476  if (parsing_rect)
477  r = &(json_node->rect);
478  else if (parsing_window_rect)
479  r = &(json_node->window_rect);
480  else
481  r = &(json_node->geometry);
482  if (strcasecmp(last_key, "x") == 0)
483  r->x = val;
484  else if (strcasecmp(last_key, "y") == 0)
485  r->y = val;
486  else if (strcasecmp(last_key, "width") == 0)
487  r->width = val;
488  else if (strcasecmp(last_key, "height") == 0)
489  r->height = val;
490  else
491  ELOG("WARNING: unknown key %s in rect\n", last_key);
492  DLOG("rect now: (%d, %d, %d, %d)\n",
493  r->x, r->y, r->width, r->height);
494  }
495  if (parsing_swallows) {
496  if (strcasecmp(last_key, "id") == 0) {
497  current_swallow->id = val;
498  swallow_is_empty = false;
499  }
500  if (strcasecmp(last_key, "dock") == 0) {
501  current_swallow->dock = val;
502  swallow_is_empty = false;
503  }
504  if (strcasecmp(last_key, "insert_where") == 0) {
506  swallow_is_empty = false;
507  }
508  }
509 
510  return 1;
511 }
512 
513 static int json_bool(void *ctx, int val) {
514  LOG("bool %d for key %s\n", val, last_key);
515  if (strcasecmp(last_key, "focused") == 0 && val) {
517  }
518 
519  if (strcasecmp(last_key, "sticky") == 0)
520  json_node->sticky = val;
521 
522  if (parsing_swallows) {
523  if (strcasecmp(last_key, "restart_mode") == 0) {
525  swallow_is_empty = false;
526  }
527  }
528 
529  return 1;
530 }
531 
532 static int json_double(void *ctx, double val) {
533  LOG("double %f for key %s\n", val, last_key);
534  if (strcasecmp(last_key, "percent") == 0) {
535  json_node->percent = val;
536  }
537  return 1;
538 }
539 
541 static int content_level;
542 
544  content_level++;
545  return 1;
546 }
547 
549  content_level--;
550  return 1;
551 }
552 
553 static int json_determine_content_string(void *ctx, const unsigned char *val, size_t len) {
554  if (strcasecmp(last_key, "type") != 0 || content_level > 1)
555  return 1;
556 
557  DLOG("string = %.*s, last_key = %s\n", (int)len, val, last_key);
558  if (strncasecmp((const char *)val, "workspace", len) == 0)
560  return 0;
561 }
562 
563 /*
564  * Returns true if the provided JSON could be parsed by yajl.
565  *
566  */
567 bool json_validate(const char *buf, const size_t len) {
568  bool valid = true;
569  yajl_handle hand = yajl_alloc(NULL, NULL, NULL);
570  /* Allowing comments allows for more user-friendly layout files. */
571  yajl_config(hand, yajl_allow_comments, true);
572  /* Allow multiple values, i.e. multiple nodes to attach */
573  yajl_config(hand, yajl_allow_multiple_values, true);
574 
575  setlocale(LC_NUMERIC, "C");
576  if (yajl_parse(hand, (const unsigned char *)buf, len) != yajl_status_ok) {
577  unsigned char *str = yajl_get_error(hand, 1, (const unsigned char *)buf, len);
578  ELOG("JSON parsing error: %s\n", str);
579  yajl_free_error(hand, str);
580  valid = false;
581  }
582  setlocale(LC_NUMERIC, "");
583 
584  yajl_complete_parse(hand);
585  yajl_free(hand);
586 
587  return valid;
588 }
589 
590 /* Parses the given JSON file until it encounters the first “type” property to
591  * determine whether the file contains workspaces or regular containers, which
592  * is important to know when deciding where (and how) to append the contents.
593  * */
594 json_content_t json_determine_content(const char *buf, const size_t len) {
595  // We default to JSON_CONTENT_CON because it is legal to not include
596  // “"type": "con"” in the JSON files for better readability.
598  content_level = 0;
599  static yajl_callbacks callbacks = {
600  .yajl_string = json_determine_content_string,
601  .yajl_map_key = json_key,
602  .yajl_start_array = json_determine_content_deeper,
603  .yajl_start_map = json_determine_content_deeper,
604  .yajl_end_map = json_determine_content_shallower,
605  .yajl_end_array = json_determine_content_shallower,
606  };
607  yajl_handle hand = yajl_alloc(&callbacks, NULL, NULL);
608  /* Allowing comments allows for more user-friendly layout files. */
609  yajl_config(hand, yajl_allow_comments, true);
610  /* Allow multiple values, i.e. multiple nodes to attach */
611  yajl_config(hand, yajl_allow_multiple_values, true);
612  setlocale(LC_NUMERIC, "C");
613  const yajl_status stat = yajl_parse(hand, (const unsigned char *)buf, len);
614  if (stat != yajl_status_ok && stat != yajl_status_client_canceled) {
615  unsigned char *str = yajl_get_error(hand, 1, (const unsigned char *)buf, len);
616  ELOG("JSON parsing error: %s\n", str);
617  yajl_free_error(hand, str);
618  }
619 
620  setlocale(LC_NUMERIC, "");
621  yajl_complete_parse(hand);
622  yajl_free(hand);
623 
624  return content_result;
625 }
626 
627 void tree_append_json(Con *con, const char *buf, const size_t len, char **errormsg) {
628  static yajl_callbacks callbacks = {
629  .yajl_boolean = json_bool,
630  .yajl_integer = json_int,
631  .yajl_double = json_double,
632  .yajl_string = json_string,
633  .yajl_start_map = json_start_map,
634  .yajl_map_key = json_key,
635  .yajl_end_map = json_end_map,
636  .yajl_end_array = json_end_array,
637  };
638  yajl_handle hand = yajl_alloc(&callbacks, NULL, NULL);
639  /* Allowing comments allows for more user-friendly layout files. */
640  yajl_config(hand, yajl_allow_comments, true);
641  /* Allow multiple values, i.e. multiple nodes to attach */
642  yajl_config(hand, yajl_allow_multiple_values, true);
643  /* We don't need to validate that the input is valid UTF8 here.
644  * tree_append_json is called in two cases:
645  * 1. With the append_layout command. json_validate is called first and will
646  * fail on invalid UTF8 characters so we don't need to recheck.
647  * 2. With an in-place restart. The rest of the codebase should be
648  * responsible for producing valid UTF8 JSON output. If not,
649  * tree_append_json will just preserve invalid UTF8 strings in the tree
650  * instead of failing to parse the layout file which could lead to
651  * problems like in #3156.
652  * Either way, disabling UTF8 validation slightly speeds up yajl. */
653  yajl_config(hand, yajl_dont_validate_strings, true);
654  json_node = con;
655  to_focus = NULL;
656  incomplete = 0;
657  parsing_swallows = false;
658  parsing_rect = false;
659  parsing_deco_rect = false;
660  parsing_window_rect = false;
661  parsing_geometry = false;
662  parsing_focus = false;
663  parsing_marks = false;
664  setlocale(LC_NUMERIC, "C");
665  const yajl_status stat = yajl_parse(hand, (const unsigned char *)buf, len);
666  if (stat != yajl_status_ok) {
667  unsigned char *str = yajl_get_error(hand, 1, (const unsigned char *)buf, len);
668  ELOG("JSON parsing error: %s\n", str);
669  if (errormsg != NULL)
670  *errormsg = sstrdup((const char *)str);
671  yajl_free_error(hand, str);
672  while (incomplete-- > 0) {
673  Con *parent = json_node->parent;
674  DLOG("freeing incomplete container %p\n", json_node);
675  if (json_node == to_focus) {
676  to_focus = NULL;
677  }
679  json_node = parent;
680  }
681  }
682 
683  /* In case not all containers were restored, we need to fix the
684  * percentages, otherwise i3 will crash immediately when rendering the
685  * next time. */
686  con_fix_percent(con);
687 
688  setlocale(LC_NUMERIC, "");
689  yajl_complete_parse(hand);
690  yajl_free(hand);
691 
692  if (to_focus) {
694  }
695 }
Con * con_get_workspace(Con *con)
Gets the workspace container this node is on.
Definition: con.c:477
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
bool con_is_split(Con *con)
Returns true if a container should be considered split.
Definition: con.c:385
void con_mark(Con *con, const char *mark, mark_mode_t mode)
Assigns a mark to the container.
Definition: con.c:768
void con_fix_percent(Con *con)
Updates the percent attribute of the children of the given container.
Definition: con.c:1011
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:226
static bool parsing_focus
Definition: load_layout.c:28
static int content_level
Definition: load_layout.c:541
static int json_end_array(void *ctx)
Definition: load_layout.c:202
static int json_determine_content_deeper(void *ctx)
Definition: load_layout.c:543
static int json_determine_content_string(void *ctx, const unsigned char *val, size_t len)
Definition: load_layout.c:553
static bool parsing_geometry
Definition: load_layout.c:27
static int num_marks
Definition: load_layout.c:32
struct pending_marks * marks
static int incomplete
Definition: load_layout.c:20
static char * last_key
Definition: load_layout.c:19
static json_content_t content_result
Definition: load_layout.c:540
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:567
static Con * json_node
Definition: load_layout.c:21
static bool parsing_deco_rect
Definition: load_layout.c:25
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:513
static bool parsing_rect
Definition: load_layout.c:24
struct Match * current_swallow
Definition: load_layout.c:30
static Con * to_focus
Definition: load_layout.c:22
static int json_end_map(void *ctx)
Definition: load_layout.c:85
static TAILQ_HEAD(focus_mappings_head, focus_mapping)
Definition: load_layout.c:50
json_content_t json_determine_content(const char *buf, const size_t len)
Definition: load_layout.c:594
static int json_double(void *ctx, double val)
Definition: load_layout.c:532
static bool swallow_is_empty
Definition: load_layout.c:31
static int json_key(void *ctx, const unsigned char *val, size_t len)
Definition: load_layout.c:240
static bool parsing_marks
Definition: load_layout.c:29
static bool parsing_swallows
Definition: load_layout.c:23
static int json_string(void *ctx, const unsigned char *val, size_t len)
Definition: load_layout.c:271
static int json_determine_content_shallower(void *ctx)
Definition: load_layout.c:548
static bool parsing_window_rect
Definition: load_layout.c:26
void tree_append_json(Con *con, const char *buf, const size_t len, char **errormsg)
Definition: load_layout.c:627
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:275
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:93
@ L_TABBED
Definition: data.h:94
@ L_DOCKAREA
Definition: data.h:95
@ L_OUTPUT
Definition: data.h:96
@ L_SPLITH
Definition: data.h:98
@ L_SPLITV
Definition: data.h:97
@ L_DEFAULT
Definition: data.h:92
@ MM_ADD
Definition: data.h:86
@ MM_REPLACE
Definition: data.h:85
@ BS_NONE
Definition: data.h:63
@ BS_PIXEL
Definition: data.h:64
@ BS_NORMAL
Definition: data.h:62
char * sstrdup(const char *str)
Safe-wrapper around strdup which exits if malloc returns NULL (meaning that there is no more memory a...
#define DLOG(fmt,...)
Definition: libi3.h:105
#define LOG(fmt,...)
Definition: libi3.h:95
void * smalloc(size_t size)
Safe-wrapper around malloc which exits if malloc returns NULL (meaning that there is no more memory a...
#define ELOG(fmt,...)
Definition: libi3.h:100
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...
void * srealloc(void *ptr, size_t size)
Safe-wrapper around realloc which exits if realloc returns NULL (meaning that there is no more memory...
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 * 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...
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_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:40
Stores a rectangle, for example the size of a window, the child window etc.
Definition: data.h:156
uint32_t height
Definition: data.h:160
uint32_t x
Definition: data.h:157
uint32_t y
Definition: data.h:158
uint32_t width
Definition: data.h:159
A "match" is a data structure which acts like a mask or expression to match certain windows or not.
Definition: data.h:499
struct regex * window_role
Definition: data.h:508
struct regex * title
Definition: data.h:503
struct regex * instance
Definition: data.h:506
struct regex * machine
Definition: data.h:510
bool restart_mode
Definition: data.h:553
enum Match::@15 insert_where
xcb_window_t id
Definition: data.h:524
struct regex * class
Definition: data.h:505
enum Match::@13 dock
A 'Con' represents everything from the X11 root window down to a single X11 window.
Definition: data.h:613
struct Con * parent
Definition: data.h:645
enum Con::@20 scratchpad_state
enum Con::@18 type
layout_t workspace_layout
Definition: data.h:722
double percent
Definition: data.h:679
layout_t last_split_layout
Definition: data.h:722
struct Rect rect
Definition: data.h:649
int current_border_width
Definition: data.h:683
bool sticky
Definition: data.h:706
layout_t layout
Definition: data.h:722
int num
the workspace number, if this Con is of type CT_WORKSPACE and the workspace is not a named workspace ...
Definition: data.h:643
struct Rect window_rect
Definition: data.h:652
int window_icon_padding
Whether the window icon should be displayed, and with what padding.
Definition: data.h:667
int old_id
Definition: data.h:759
char * title_format
The format with which the window's name should be displayed.
Definition: data.h:662
border_style_t border_style
Definition: data.h:723
char * name
Definition: data.h:659
struct Rect geometry
the geometry this window requested when getting mapped
Definition: data.h:657
char * sticky_group
Definition: data.h:672
uint16_t depth
Definition: data.h:762
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:701