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  const Rect zero = {0, 0, 0, 0};
146  if (memcmp(&(json_node->rect), &zero, sizeof(Rect)) == 0) {
147  DLOG("Geometry not set, combining children\n");
148  Con *child;
149  TAILQ_FOREACH(child, &(json_node->nodes_head), nodes) {
150  DLOG("child geometry: %d x %d\n", child->geometry.width, child->geometry.height);
151  json_node->rect.width += child->geometry.width;
153  }
154  }
155 
157  }
158 
159  if (num_marks > 0) {
160  for (int i = 0; i < num_marks; i++) {
161  Con *con = marks[i].con_to_be_marked;
162  char *mark = marks[i].mark;
163  con_mark(con, mark, MM_ADD);
164  free(mark);
165  }
166 
167  FREE(marks);
168  num_marks = 0;
169  }
170 
171  LOG("attaching\n");
173  LOG("Creating window\n");
176  incomplete--;
177  DLOG("incomplete = %d\n", incomplete);
178  }
179 
181  /* We parsed an empty swallow definition. This is an invalid layout
182  * definition, hence we reject it. */
183  ELOG("Layout file is invalid: found an empty swallow definition.\n");
184  return 0;
185  }
186 
187  parsing_gaps = false;
188  parsing_rect = false;
189  parsing_deco_rect = false;
190  parsing_window_rect = false;
191  parsing_geometry = false;
192  return 1;
193 }
194 
195 static int json_end_array(void *ctx) {
196  LOG("end of array\n");
199  }
200  if (parsing_swallows) {
201  parsing_swallows = false;
202  }
203  if (parsing_marks) {
204  parsing_marks = false;
205  }
206 
207  if (parsing_focus) {
208  /* Clear the list of focus mappings */
209  struct focus_mapping *mapping;
210  TAILQ_FOREACH_REVERSE(mapping, &focus_mappings, focus_mappings_head, focus_mappings) {
211  LOG("focus (reverse) %d\n", mapping->old_id);
212  Con *con;
214  if (con->old_id != mapping->old_id)
215  continue;
216  LOG("got it! %p\n", con);
217  /* Move this entry to the top of the focus list. */
220  break;
221  }
222  }
223  while (!TAILQ_EMPTY(&focus_mappings)) {
224  mapping = TAILQ_FIRST(&focus_mappings);
226  free(mapping);
227  }
228  parsing_focus = false;
229  }
230  return 1;
231 }
232 
233 static int json_key(void *ctx, const unsigned char *val, size_t len) {
234  LOG("key: %.*s\n", (int)len, val);
235  FREE(last_key);
236  last_key = scalloc(len + 1, 1);
237  memcpy(last_key, val, len);
238  if (strcasecmp(last_key, "swallows") == 0)
239  parsing_swallows = true;
240 
241  if (strcasecmp(last_key, "gaps") == 0)
242  parsing_gaps = true;
243 
244  if (strcasecmp(last_key, "rect") == 0)
245  parsing_rect = true;
246 
247  if (strcasecmp(last_key, "deco_rect") == 0)
248  parsing_deco_rect = true;
249 
250  if (strcasecmp(last_key, "window_rect") == 0)
251  parsing_window_rect = true;
252 
253  if (strcasecmp(last_key, "geometry") == 0)
254  parsing_geometry = true;
255 
256  if (strcasecmp(last_key, "focus") == 0)
257  parsing_focus = true;
258 
259  if (strcasecmp(last_key, "marks") == 0) {
260  num_marks = 0;
261  parsing_marks = true;
262  }
263 
264  return 1;
265 }
266 
267 static int json_string(void *ctx, const unsigned char *val, size_t len) {
268  LOG("string: %.*s for key %s\n", (int)len, val, last_key);
269  if (parsing_swallows) {
270  char *sval;
271  sasprintf(&sval, "%.*s", len, val);
272  if (strcasecmp(last_key, "class") == 0) {
274  swallow_is_empty = false;
275  } else if (strcasecmp(last_key, "instance") == 0) {
277  swallow_is_empty = false;
278  } else if (strcasecmp(last_key, "window_role") == 0) {
280  swallow_is_empty = false;
281  } else if (strcasecmp(last_key, "title") == 0) {
283  swallow_is_empty = false;
284  } else {
285  ELOG("swallow key %s unknown\n", last_key);
286  }
287  free(sval);
288  } else if (parsing_marks) {
289  char *mark;
290  sasprintf(&mark, "%.*s", (int)len, val);
291 
292  marks = srealloc(marks, (++num_marks) * sizeof(struct pending_marks));
293  marks[num_marks - 1].mark = sstrdup(mark);
295  } else {
296  if (strcasecmp(last_key, "name") == 0) {
297  json_node->name = scalloc(len + 1, 1);
298  memcpy(json_node->name, val, len);
299  } else if (strcasecmp(last_key, "title_format") == 0) {
300  json_node->title_format = scalloc(len + 1, 1);
301  memcpy(json_node->title_format, val, len);
302  } else if (strcasecmp(last_key, "sticky_group") == 0) {
303  json_node->sticky_group = scalloc(len + 1, 1);
304  memcpy(json_node->sticky_group, val, len);
305  LOG("sticky_group of this container is %s\n", json_node->sticky_group);
306  } else if (strcasecmp(last_key, "orientation") == 0) {
307  /* Upgrade path from older versions of i3 (doing an inplace restart
308  * to a newer version):
309  * "orientation" is dumped before "layout". Therefore, we store
310  * whether the orientation was horizontal or vertical in the
311  * last_split_layout. When we then encounter layout == "default",
312  * we will use the last_split_layout as layout instead. */
313  char *buf = NULL;
314  sasprintf(&buf, "%.*s", (int)len, val);
315  if (strcasecmp(buf, "none") == 0 ||
316  strcasecmp(buf, "horizontal") == 0)
318  else if (strcasecmp(buf, "vertical") == 0)
320  else
321  LOG("Unhandled orientation: %s\n", buf);
322  free(buf);
323  } else if (strcasecmp(last_key, "border") == 0) {
324  char *buf = NULL;
325  sasprintf(&buf, "%.*s", (int)len, val);
326  if (strcasecmp(buf, "none") == 0)
328  else if (strcasecmp(buf, "1pixel") == 0) {
331  } else if (strcasecmp(buf, "pixel") == 0)
333  else if (strcasecmp(buf, "normal") == 0)
335  else
336  LOG("Unhandled \"border\": %s\n", buf);
337  free(buf);
338  } else if (strcasecmp(last_key, "type") == 0) {
339  char *buf = NULL;
340  sasprintf(&buf, "%.*s", (int)len, val);
341  if (strcasecmp(buf, "root") == 0)
342  json_node->type = CT_ROOT;
343  else if (strcasecmp(buf, "output") == 0)
344  json_node->type = CT_OUTPUT;
345  else if (strcasecmp(buf, "con") == 0)
346  json_node->type = CT_CON;
347  else if (strcasecmp(buf, "floating_con") == 0)
348  json_node->type = CT_FLOATING_CON;
349  else if (strcasecmp(buf, "workspace") == 0)
350  json_node->type = CT_WORKSPACE;
351  else if (strcasecmp(buf, "dockarea") == 0)
352  json_node->type = CT_DOCKAREA;
353  else
354  LOG("Unhandled \"type\": %s\n", buf);
355  free(buf);
356  } else if (strcasecmp(last_key, "layout") == 0) {
357  char *buf = NULL;
358  sasprintf(&buf, "%.*s", (int)len, val);
359  if (strcasecmp(buf, "default") == 0)
360  /* This set above when we read "orientation". */
362  else if (strcasecmp(buf, "stacked") == 0)
364  else if (strcasecmp(buf, "tabbed") == 0)
366  else if (strcasecmp(buf, "dockarea") == 0)
368  else if (strcasecmp(buf, "output") == 0)
370  else if (strcasecmp(buf, "splith") == 0)
372  else if (strcasecmp(buf, "splitv") == 0)
374  else
375  LOG("Unhandled \"layout\": %s\n", buf);
376  free(buf);
377  } else if (strcasecmp(last_key, "workspace_layout") == 0) {
378  char *buf = NULL;
379  sasprintf(&buf, "%.*s", (int)len, val);
380  if (strcasecmp(buf, "default") == 0)
382  else if (strcasecmp(buf, "stacked") == 0)
384  else if (strcasecmp(buf, "tabbed") == 0)
386  else
387  LOG("Unhandled \"workspace_layout\": %s\n", buf);
388  free(buf);
389  } else if (strcasecmp(last_key, "last_split_layout") == 0) {
390  char *buf = NULL;
391  sasprintf(&buf, "%.*s", (int)len, val);
392  if (strcasecmp(buf, "splith") == 0)
394  else if (strcasecmp(buf, "splitv") == 0)
396  else
397  LOG("Unhandled \"last_splitlayout\": %s\n", buf);
398  free(buf);
399  } else if (strcasecmp(last_key, "mark") == 0) {
400  DLOG("Found deprecated key \"mark\".\n");
401 
402  char *buf = NULL;
403  sasprintf(&buf, "%.*s", (int)len, val);
404 
406  } else if (strcasecmp(last_key, "floating") == 0) {
407  char *buf = NULL;
408  sasprintf(&buf, "%.*s", (int)len, val);
409  if (strcasecmp(buf, "auto_off") == 0)
410  json_node->floating = FLOATING_AUTO_OFF;
411  else if (strcasecmp(buf, "auto_on") == 0)
412  json_node->floating = FLOATING_AUTO_ON;
413  else if (strcasecmp(buf, "user_off") == 0)
414  json_node->floating = FLOATING_USER_OFF;
415  else if (strcasecmp(buf, "user_on") == 0)
416  json_node->floating = FLOATING_USER_ON;
417  free(buf);
418  } else if (strcasecmp(last_key, "scratchpad_state") == 0) {
419  char *buf = NULL;
420  sasprintf(&buf, "%.*s", (int)len, val);
421  if (strcasecmp(buf, "none") == 0)
422  json_node->scratchpad_state = SCRATCHPAD_NONE;
423  else if (strcasecmp(buf, "fresh") == 0)
424  json_node->scratchpad_state = SCRATCHPAD_FRESH;
425  else if (strcasecmp(buf, "changed") == 0)
426  json_node->scratchpad_state = SCRATCHPAD_CHANGED;
427  free(buf);
428  } else if (strcasecmp(last_key, "previous_workspace_name") == 0) {
430  previous_workspace_name = sstrndup((const char *)val, len);
431  }
432  }
433  return 1;
434 }
435 
436 static int json_int(void *ctx, long long val) {
437  LOG("int %lld for key %s\n", val, last_key);
438  /* For backwards compatibility with i3 < 4.8 */
439  if (strcasecmp(last_key, "type") == 0)
440  json_node->type = val;
441 
442  if (strcasecmp(last_key, "fullscreen_mode") == 0)
443  json_node->fullscreen_mode = val;
444 
445  if (strcasecmp(last_key, "num") == 0)
446  json_node->num = val;
447 
448  if (strcasecmp(last_key, "current_border_width") == 0)
450 
451  if (strcasecmp(last_key, "depth") == 0)
452  json_node->depth = val;
453 
454  if (!parsing_swallows && strcasecmp(last_key, "id") == 0)
455  json_node->old_id = val;
456 
457  if (parsing_focus) {
458  struct focus_mapping *focus_mapping = scalloc(1, sizeof(struct focus_mapping));
459  focus_mapping->old_id = val;
461  }
462 
464  Rect *r;
465  if (parsing_rect)
466  r = &(json_node->rect);
467  else if (parsing_window_rect)
468  r = &(json_node->window_rect);
469  else
470  r = &(json_node->geometry);
471  if (strcasecmp(last_key, "x") == 0)
472  r->x = val;
473  else if (strcasecmp(last_key, "y") == 0)
474  r->y = val;
475  else if (strcasecmp(last_key, "width") == 0)
476  r->width = val;
477  else if (strcasecmp(last_key, "height") == 0)
478  r->height = val;
479  else
480  ELOG("WARNING: unknown key %s in rect\n", last_key);
481  DLOG("rect now: (%d, %d, %d, %d)\n",
482  r->x, r->y, r->width, r->height);
483  }
484  if (parsing_swallows) {
485  if (strcasecmp(last_key, "id") == 0) {
486  current_swallow->id = val;
487  swallow_is_empty = false;
488  }
489  if (strcasecmp(last_key, "dock") == 0) {
490  current_swallow->dock = val;
491  swallow_is_empty = false;
492  }
493  if (strcasecmp(last_key, "insert_where") == 0) {
495  swallow_is_empty = false;
496  }
497  }
498  if (parsing_gaps) {
499  if (strcasecmp(last_key, "inner") == 0)
500  json_node->gaps.inner = val;
501  else if (strcasecmp(last_key, "top") == 0)
502  json_node->gaps.top = val;
503  else if (strcasecmp(last_key, "right") == 0)
504  json_node->gaps.right = val;
505  else if (strcasecmp(last_key, "bottom") == 0)
506  json_node->gaps.bottom = val;
507  else if (strcasecmp(last_key, "left") == 0)
508  json_node->gaps.left = val;
509  }
510 
511  return 1;
512 }
513 
514 static int json_bool(void *ctx, int val) {
515  LOG("bool %d for key %s\n", val, last_key);
516  if (strcasecmp(last_key, "focused") == 0 && val) {
518  }
519 
520  if (strcasecmp(last_key, "sticky") == 0)
521  json_node->sticky = val;
522 
523  if (parsing_swallows) {
524  if (strcasecmp(last_key, "restart_mode") == 0) {
526  swallow_is_empty = false;
527  }
528  }
529 
530  return 1;
531 }
532 
533 static int json_double(void *ctx, double val) {
534  LOG("double %f for key %s\n", val, last_key);
535  if (strcasecmp(last_key, "percent") == 0) {
536  json_node->percent = val;
537  }
538  return 1;
539 }
540 
542 static int content_level;
543 
545  content_level++;
546  return 1;
547 }
548 
550  content_level--;
551  return 1;
552 }
553 
554 static int json_determine_content_string(void *ctx, const unsigned char *val, size_t len) {
555  if (strcasecmp(last_key, "type") != 0 || content_level > 1)
556  return 1;
557 
558  DLOG("string = %.*s, last_key = %s\n", (int)len, val, last_key);
559  if (strncasecmp((const char *)val, "workspace", len) == 0)
561  return 0;
562 }
563 
564 /*
565  * Returns true if the provided JSON could be parsed by yajl.
566  *
567  */
568 bool json_validate(const char *buf, const size_t len) {
569  bool valid = true;
570  yajl_handle hand = yajl_alloc(NULL, NULL, NULL);
571  /* Allowing comments allows for more user-friendly layout files. */
572  yajl_config(hand, yajl_allow_comments, true);
573  /* Allow multiple values, i.e. multiple nodes to attach */
574  yajl_config(hand, yajl_allow_multiple_values, true);
575 
576  setlocale(LC_NUMERIC, "C");
577  if (yajl_parse(hand, (const unsigned char *)buf, len) != yajl_status_ok) {
578  unsigned char *str = yajl_get_error(hand, 1, (const unsigned char *)buf, len);
579  ELOG("JSON parsing error: %s\n", str);
580  yajl_free_error(hand, str);
581  valid = false;
582  }
583  setlocale(LC_NUMERIC, "");
584 
585  yajl_complete_parse(hand);
586  yajl_free(hand);
587 
588  return valid;
589 }
590 
591 /* Parses the given JSON file until it encounters the first “type” property to
592  * determine whether the file contains workspaces or regular containers, which
593  * is important to know when deciding where (and how) to append the contents.
594  * */
595 json_content_t json_determine_content(const char *buf, const size_t len) {
596  // We default to JSON_CONTENT_CON because it is legal to not include
597  // “"type": "con"” in the JSON files for better readability.
599  content_level = 0;
600  static yajl_callbacks callbacks = {
601  .yajl_string = json_determine_content_string,
602  .yajl_map_key = json_key,
603  .yajl_start_array = json_determine_content_deeper,
604  .yajl_start_map = json_determine_content_deeper,
605  .yajl_end_map = json_determine_content_shallower,
606  .yajl_end_array = json_determine_content_shallower,
607  };
608  yajl_handle hand = yajl_alloc(&callbacks, NULL, NULL);
609  /* Allowing comments allows for more user-friendly layout files. */
610  yajl_config(hand, yajl_allow_comments, true);
611  /* Allow multiple values, i.e. multiple nodes to attach */
612  yajl_config(hand, yajl_allow_multiple_values, true);
613  setlocale(LC_NUMERIC, "C");
614  const yajl_status stat = yajl_parse(hand, (const unsigned char *)buf, len);
615  if (stat != yajl_status_ok && stat != yajl_status_client_canceled) {
616  unsigned char *str = yajl_get_error(hand, 1, (const unsigned char *)buf, len);
617  ELOG("JSON parsing error: %s\n", str);
618  yajl_free_error(hand, str);
619  }
620 
621  setlocale(LC_NUMERIC, "");
622  yajl_complete_parse(hand);
623  yajl_free(hand);
624 
625  return content_result;
626 }
627 
628 void tree_append_json(Con *con, const char *buf, const size_t len, char **errormsg) {
629  static yajl_callbacks callbacks = {
630  .yajl_boolean = json_bool,
631  .yajl_integer = json_int,
632  .yajl_double = json_double,
633  .yajl_string = json_string,
634  .yajl_start_map = json_start_map,
635  .yajl_map_key = json_key,
636  .yajl_end_map = json_end_map,
637  .yajl_end_array = json_end_array,
638  };
639  yajl_handle hand = yajl_alloc(&callbacks, NULL, NULL);
640  /* Allowing comments allows for more user-friendly layout files. */
641  yajl_config(hand, yajl_allow_comments, true);
642  /* Allow multiple values, i.e. multiple nodes to attach */
643  yajl_config(hand, yajl_allow_multiple_values, true);
644  /* We don't need to validate that the input is valid UTF8 here.
645  * tree_append_json is called in two cases:
646  * 1. With the append_layout command. json_validate is called first and will
647  * fail on invalid UTF8 characters so we don't need to recheck.
648  * 2. With an in-place restart. The rest of the codebase should be
649  * responsible for producing valid UTF8 JSON output. If not,
650  * tree_append_json will just preserve invalid UTF8 strings in the tree
651  * instead of failing to parse the layout file which could lead to
652  * problems like in #3156.
653  * Either way, disabling UTF8 validation slightly speeds up yajl. */
654  yajl_config(hand, yajl_dont_validate_strings, true);
655  json_node = con;
656  to_focus = NULL;
657  parsing_gaps = false;
658  incomplete = 0;
659  parsing_swallows = false;
660  parsing_rect = false;
661  parsing_deco_rect = false;
662  parsing_window_rect = false;
663  parsing_geometry = false;
664  parsing_focus = false;
665  parsing_marks = false;
666  setlocale(LC_NUMERIC, "C");
667  const yajl_status stat = yajl_parse(hand, (const unsigned char *)buf, len);
668  if (stat != yajl_status_ok) {
669  unsigned char *str = yajl_get_error(hand, 1, (const unsigned char *)buf, len);
670  ELOG("JSON parsing error: %s\n", str);
671  if (errormsg != NULL)
672  *errormsg = sstrdup((const char *)str);
673  yajl_free_error(hand, str);
674  while (incomplete-- > 0) {
675  Con *parent = json_node->parent;
676  DLOG("freeing incomplete container %p\n", json_node);
677  if (json_node == to_focus) {
678  to_focus = NULL;
679  }
681  json_node = parent;
682  }
683  }
684 
685  /* In case not all containers were restored, we need to fix the
686  * percentages, otherwise i3 will crash immediately when rendering the
687  * next time. */
688  con_fix_percent(con);
689 
690  setlocale(LC_NUMERIC, "");
691  yajl_complete_parse(hand);
692  yajl_free(hand);
693 
694  if (to_focus) {
696  }
697 }
void con_free(Con *con)
Frees the specified container.
Definition: con.c:79
void con_fix_percent(Con *con)
Updates the percent attribute of the children of the given container.
Definition: con.c:950
struct regex * instance
Definition: data.h:528
#define FREE(pointer)
Definition: util.h:47
enum Con::@20 type
int left
Definition: data.h:151
Stores a rectangle, for example the size of a window, the child window etc.
Definition: data.h:175
layout_t workspace_layout
Definition: data.h:746
json_content_t
Definition: load_layout.h:15
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...
int right
Definition: data.h:149
void floating_check_size(Con *floating_con, bool prefer_height)
Called when a floating window is created or resized.
Definition: floating.c:73
enum Con::@21 floating
floating? (= not in tiling layout) This cannot be simply a bool because we want to keep track of whet...
void * srealloc(void *ptr, size_t size)
Safe-wrapper around realloc which exits if realloc returns NULL (meaning that there is no more memory...
uint32_t y
Definition: data.h:177
static int content_level
Definition: load_layout.c:542
Definition: data.h:96
static bool parsing_focus
Definition: load_layout.c:30
struct Match * current_swallow
Definition: load_layout.c:32
uint32_t width
Definition: data.h:178
int max(int a, int b)
Definition: util.c:31
#define DLOG(fmt,...)
Definition: libi3.h:104
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:568
void * smalloc(size_t size)
Safe-wrapper around malloc which exits if malloc returns NULL (meaning that there is no more memory a...
int inner
Definition: data.h:147
#define TAILQ_EMPTY(head)
Definition: queue.h:344
static TAILQ_HEAD(focus_mappings_head, focus_mapping)
Definition: load_layout.c:54
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...
static int json_key(void *ctx, const unsigned char *val, size_t len)
Definition: load_layout.c:233
static json_content_t content_result
Definition: load_layout.c:541
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
static bool parsing_swallows
Definition: load_layout.c:25
void match_free(Match *match)
Frees the given match.
Definition: match.c:257
Con * con_to_be_marked
Definition: load_layout.c:42
uint16_t depth
Definition: data.h:793
static bool parsing_geometry
Definition: load_layout.c:29
static bool parsing_window_rect
Definition: load_layout.c:28
struct regex * class
Definition: data.h:527
static bool parsing_marks
Definition: load_layout.c:31
layout_t last_split_layout
Definition: data.h:746
void x_con_init(Con *con)
Initializes the X11 part for the given container.
Definition: x.c:133
static int json_string(void *ctx, const unsigned char *val, size_t len)
Definition: load_layout.c:267
#define TAILQ_FOREACH_REVERSE(var, head, headname, field)
Definition: queue.h:352
int current_border_width
Definition: data.h:702
fullscreen_mode_t fullscreen_mode
Definition: data.h:725
xcb_window_t id
Definition: data.h:546
#define TAILQ_INSERT_HEAD(head, elm, field)
Definition: queue.h:366
void con_mark(Con *con, const char *mark, mark_mode_t mode)
Assigns a mark to the container.
Definition: con.c:708
static int num_marks
Definition: load_layout.c:34
static int json_end_map(void *ctx)
Definition: load_layout.c:89
gaps_t gaps
Only applicable for containers of type CT_WORKSPACE.
Definition: data.h:666
#define TAILQ_REMOVE(head, elm, field)
Definition: queue.h:402
struct Rect rect
Definition: data.h:672
static bool parsing_deco_rect
Definition: load_layout.c:27
nodes_head
Definition: data.h:717
static int json_determine_content_shallower(void *ctx)
Definition: load_layout.c:549
static bool parsing_gaps
Definition: load_layout.c:24
char * name
Definition: data.h:682
#define TAILQ_FIRST(head)
Definition: queue.h:336
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 * con_get_workspace(Con *con)
Gets the workspace container this node is on.
Definition: con.c:418
static bool swallow_is_empty
Definition: load_layout.c:33
long ws_name_to_number(const char *name)
Parses the workspace name as a number.
Definition: util.c:102
static Con * to_focus
Definition: load_layout.c:23
struct Con * parent
Definition: data.h:668
static int json_determine_content_string(void *ctx, const unsigned char *val, size_t len)
Definition: load_layout.c:554
focus_head
Definition: data.h:720
enum Con::@22 scratchpad_state
swallow_head
Definition: data.h:723
json_content_t json_determine_content(const char *buf, const size_t len)
Definition: load_layout.c:595
#define TAILQ_ENTRY(type)
Definition: queue.h:327
struct pending_marks * marks
char * sstrdup(const char *str)
Safe-wrapper around strdup which exits if malloc returns NULL (meaning that there is no more memory a...
bool con_is_split(Con *con)
Returns true if a container should be considered split.
Definition: con.c:326
Definition: data.h:63
int top
Definition: data.h:148
Definition: data.h:108
struct regex * title
Definition: data.h:525
#define LOG(fmt,...)
Definition: libi3.h:94
bool restart_mode
Definition: data.h:571
A "match" is a data structure which acts like a mask or expression to match certain windows or not.
Definition: data.h:521
enum Match::@17 insert_where
char * title_format
The format with which the window's name should be displayed.
Definition: data.h:685
Definition: data.h:107
Definition: data.h:64
struct regex * window_role
Definition: data.h:530
struct Con * focused
Definition: tree.c:13
static xcb_cursor_context_t * ctx
Definition: xcursor.c:19
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
struct Rect window_rect
Definition: data.h:675
static int json_int(void *ctx, long long val)
Definition: load_layout.c:436
Definition: data.h:106
static bool parsing_rect
Definition: load_layout.c:26
#define ELOG(fmt,...)
Definition: libi3.h:99
Definition: data.h:65
static char * last_key
Definition: load_layout.c:20
static int json_determine_content_deeper(void *ctx)
Definition: load_layout.c:544
bool sticky
Definition: data.h:730
static int json_end_array(void *ctx)
Definition: load_layout.c:195
Definition: data.h:104
double percent
Definition: data.h:698
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
char * sticky_group
Definition: data.h:690
static int json_double(void *ctx, double val)
Definition: load_layout.c:533
border_style_t border_style
Definition: data.h:747
int num
the workspace number, if this Con is of type CT_WORKSPACE and the workspace is not a named workspace ...
Definition: data.h:663
void con_attach(Con *con, Con *parent, bool ignore_focus)
Attaches the given container to the given parent.
Definition: con.c:198
A 'Con' represents everything from the X11 root window down to a single X11 window.
Definition: data.h:633
static int incomplete
Definition: load_layout.c:21
int old_id
Definition: data.h:790
void con_activate(Con *con)
Sets input focus to the given container and raises it to the top.
Definition: con.c:263
int bottom
Definition: data.h:150
uint32_t height
Definition: data.h:179
static int json_bool(void *ctx, int val)
Definition: load_layout.c:514
void match_init(Match *match)
Initializes the Match data structure.
Definition: match.c:26
void tree_append_json(Con *con, const char *buf, const size_t len, char **errormsg)
Definition: load_layout.c:628
layout_t layout
Definition: data.h:746
struct Rect geometry
the geometry this window requested when getting mapped
Definition: data.h:680
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
#define TAILQ_HEAD_INITIALIZER(head)
Definition: queue.h:324
#define TAILQ_INSERT_TAIL(head, elm, field)
Definition: queue.h:376
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:347
uint32_t x
Definition: data.h:176
static Con * json_node
Definition: load_layout.c:22
enum Match::@15 dock