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