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