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