2012-08-12 12:18:43 +02:00
|
|
|
|
#undef I3__FILE__
|
|
|
|
|
#define I3__FILE__ "load_layout.c"
|
2010-08-15 12:18:27 +02:00
|
|
|
|
/*
|
|
|
|
|
* vim:ts=4:sw=4:expandtab
|
|
|
|
|
*
|
2011-10-23 00:40:02 +02:00
|
|
|
|
* i3 - an improved dynamic tiling window manager
|
2012-01-21 19:35:15 +01:00
|
|
|
|
* © 2009-2012 Michael Stapelberg and contributors (see also: LICENSE)
|
2011-10-23 00:40:02 +02:00
|
|
|
|
*
|
|
|
|
|
* load_layout.c: Restore (parts of) the layout, for example after an inplace
|
|
|
|
|
* restart.
|
|
|
|
|
*
|
2010-08-15 12:18:27 +02:00
|
|
|
|
*/
|
2011-10-23 00:40:02 +02:00
|
|
|
|
#include "all.h"
|
|
|
|
|
|
2010-03-27 15:25:51 +01:00
|
|
|
|
#include <yajl/yajl_common.h>
|
|
|
|
|
#include <yajl/yajl_gen.h>
|
|
|
|
|
#include <yajl/yajl_parse.h>
|
2011-04-27 19:52:53 +02:00
|
|
|
|
#include <yajl/yajl_version.h>
|
2010-03-27 15:25:51 +01:00
|
|
|
|
|
|
|
|
|
/* TODO: refactor the whole parsing thing */
|
|
|
|
|
|
|
|
|
|
static char *last_key;
|
|
|
|
|
static Con *json_node;
|
2010-11-28 14:27:44 +01:00
|
|
|
|
static Con *to_focus;
|
2010-03-27 15:25:51 +01:00
|
|
|
|
static bool parsing_swallows;
|
|
|
|
|
static bool parsing_rect;
|
2014-11-16 22:05:51 +01:00
|
|
|
|
static bool parsing_deco_rect;
|
2010-11-28 17:20:29 +01:00
|
|
|
|
static bool parsing_window_rect;
|
2011-02-21 03:01:55 +01:00
|
|
|
|
static bool parsing_geometry;
|
2012-01-21 19:35:15 +01:00
|
|
|
|
static bool parsing_focus;
|
2010-03-27 15:25:51 +01:00
|
|
|
|
struct Match *current_swallow;
|
|
|
|
|
|
2012-01-21 19:35:15 +01:00
|
|
|
|
/* This list is used for reordering the focus stack after parsing the 'focus'
|
|
|
|
|
* array. */
|
|
|
|
|
struct focus_mapping {
|
|
|
|
|
int old_id;
|
|
|
|
|
TAILQ_ENTRY(focus_mapping) focus_mappings;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static TAILQ_HEAD(focus_mappings_head, focus_mapping) focus_mappings =
|
2014-06-15 19:07:02 +02:00
|
|
|
|
TAILQ_HEAD_INITIALIZER(focus_mappings);
|
2012-01-21 19:35:15 +01:00
|
|
|
|
|
2010-03-27 15:25:51 +01:00
|
|
|
|
static int json_start_map(void *ctx) {
|
2010-11-29 21:46:00 +01:00
|
|
|
|
LOG("start of map, last_key = %s\n", last_key);
|
2010-03-27 15:25:51 +01:00
|
|
|
|
if (parsing_swallows) {
|
2011-02-28 20:44:23 +01:00
|
|
|
|
LOG("creating new swallow\n");
|
2010-08-15 12:18:27 +02:00
|
|
|
|
current_swallow = smalloc(sizeof(Match));
|
|
|
|
|
match_init(current_swallow);
|
2010-03-27 15:25:51 +01:00
|
|
|
|
TAILQ_INSERT_TAIL(&(json_node->swallow_head), current_swallow, matches);
|
|
|
|
|
} else {
|
2014-11-16 22:05:51 +01:00
|
|
|
|
if (!parsing_rect && !parsing_deco_rect && !parsing_window_rect && !parsing_geometry) {
|
2010-11-29 21:46:00 +01:00
|
|
|
|
if (last_key && strcasecmp(last_key, "floating_nodes") == 0) {
|
2011-02-28 20:44:23 +01:00
|
|
|
|
DLOG("New floating_node\n");
|
2010-11-29 21:46:00 +01:00
|
|
|
|
Con *ws = con_get_workspace(json_node);
|
2013-03-15 15:40:26 +01:00
|
|
|
|
json_node = con_new_skeleton(NULL, NULL);
|
2014-07-15 10:15:04 +02:00
|
|
|
|
json_node->name = NULL;
|
2010-11-29 21:46:00 +01:00
|
|
|
|
json_node->parent = ws;
|
2011-02-28 20:44:23 +01:00
|
|
|
|
DLOG("Parent is workspace = %p\n", ws);
|
2010-11-29 21:46:00 +01:00
|
|
|
|
} else {
|
2010-12-27 22:28:59 +01:00
|
|
|
|
Con *parent = json_node;
|
2013-03-15 15:40:26 +01:00
|
|
|
|
json_node = con_new_skeleton(NULL, NULL);
|
2014-07-15 10:15:04 +02:00
|
|
|
|
json_node->name = NULL;
|
2010-12-27 22:28:59 +01:00
|
|
|
|
json_node->parent = parent;
|
2010-11-29 21:46:00 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
2010-03-27 15:25:51 +01:00
|
|
|
|
}
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int json_end_map(void *ctx) {
|
|
|
|
|
LOG("end of map\n");
|
2014-11-16 22:05:51 +01:00
|
|
|
|
if (!parsing_swallows && !parsing_rect && !parsing_deco_rect && !parsing_window_rect && !parsing_geometry) {
|
2013-12-14 10:41:03 +01:00
|
|
|
|
/* Set a few default values to simplify manually crafted layout files. */
|
|
|
|
|
if (json_node->layout == L_DEFAULT) {
|
|
|
|
|
DLOG("Setting layout = L_SPLITH\n");
|
|
|
|
|
json_node->layout = L_SPLITH;
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-05 20:25:47 +01:00
|
|
|
|
/* Sanity check: swallow criteria don’t make any sense on a split
|
|
|
|
|
* container. */
|
|
|
|
|
if (con_is_split(json_node) > 0 && !TAILQ_EMPTY(&(json_node->swallow_head))) {
|
|
|
|
|
DLOG("sanity check: removing swallows specification from split container\n");
|
|
|
|
|
while (!TAILQ_EMPTY(&(json_node->swallow_head))) {
|
|
|
|
|
Match *match = TAILQ_FIRST(&(json_node->swallow_head));
|
|
|
|
|
TAILQ_REMOVE(&(json_node->swallow_head), match, matches);
|
|
|
|
|
match_free(match);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-15 10:15:04 +02:00
|
|
|
|
if (json_node->type == CT_WORKSPACE) {
|
|
|
|
|
/* Ensure the workspace has a name. */
|
|
|
|
|
DLOG("Attaching workspace. name = %s\n", json_node->name);
|
|
|
|
|
if (json_node->name == NULL || strcmp(json_node->name, "") == 0) {
|
|
|
|
|
json_node->name = sstrdup("unnamed");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Prevent name clashes when appending a workspace, e.g. when the
|
|
|
|
|
* user tries to restore a workspace called “1” but already has a
|
|
|
|
|
* workspace called “1”. */
|
|
|
|
|
Con *output;
|
|
|
|
|
Con *workspace = NULL;
|
2014-07-15 10:35:52 +02:00
|
|
|
|
TAILQ_FOREACH(output, &(croot->nodes_head), nodes)
|
|
|
|
|
GREP_FIRST(workspace, output_get_content(output), !strcasecmp(child->name, json_node->name));
|
2014-07-15 10:15:04 +02:00
|
|
|
|
char *base = sstrdup(json_node->name);
|
|
|
|
|
int cnt = 1;
|
|
|
|
|
while (workspace != NULL) {
|
|
|
|
|
FREE(json_node->name);
|
2015-03-24 13:57:06 +01:00
|
|
|
|
sasprintf(&(json_node->name), "%s_%d", base, cnt++);
|
2014-07-15 10:15:04 +02:00
|
|
|
|
workspace = NULL;
|
2014-07-15 10:35:52 +02:00
|
|
|
|
TAILQ_FOREACH(output, &(croot->nodes_head), nodes)
|
|
|
|
|
GREP_FIRST(workspace, output_get_content(output), !strcasecmp(child->name, json_node->name));
|
2014-07-15 10:15:04 +02:00
|
|
|
|
}
|
|
|
|
|
free(base);
|
|
|
|
|
|
|
|
|
|
/* Set num accordingly so that i3bar will properly sort it. */
|
|
|
|
|
json_node->num = ws_name_to_number(json_node->name);
|
|
|
|
|
}
|
|
|
|
|
|
2010-12-27 22:28:59 +01:00
|
|
|
|
LOG("attaching\n");
|
2011-05-12 07:22:17 +02:00
|
|
|
|
con_attach(json_node, json_node->parent, true);
|
2013-03-15 15:40:26 +01:00
|
|
|
|
LOG("Creating window\n");
|
|
|
|
|
x_con_init(json_node, json_node->depth);
|
2010-03-27 15:25:51 +01:00
|
|
|
|
json_node = json_node->parent;
|
2010-12-27 22:28:59 +01:00
|
|
|
|
}
|
2014-11-16 22:05:51 +01:00
|
|
|
|
|
|
|
|
|
parsing_rect = false;
|
|
|
|
|
parsing_deco_rect = false;
|
|
|
|
|
parsing_window_rect = false;
|
|
|
|
|
parsing_geometry = false;
|
2010-03-27 15:25:51 +01:00
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int json_end_array(void *ctx) {
|
|
|
|
|
LOG("end of array\n");
|
2014-01-04 21:30:51 +01:00
|
|
|
|
if (!parsing_swallows && !parsing_focus) {
|
|
|
|
|
con_fix_percent(json_node);
|
|
|
|
|
}
|
|
|
|
|
if (parsing_swallows) {
|
|
|
|
|
parsing_swallows = false;
|
|
|
|
|
}
|
2012-01-21 19:35:15 +01:00
|
|
|
|
if (parsing_focus) {
|
|
|
|
|
/* Clear the list of focus mappings */
|
|
|
|
|
struct focus_mapping *mapping;
|
2014-06-19 11:20:32 +02:00
|
|
|
|
TAILQ_FOREACH_REVERSE(mapping, &focus_mappings, focus_mappings_head, focus_mappings) {
|
2012-01-21 19:35:15 +01:00
|
|
|
|
LOG("focus (reverse) %d\n", mapping->old_id);
|
|
|
|
|
Con *con;
|
2014-06-19 11:20:32 +02:00
|
|
|
|
TAILQ_FOREACH(con, &(json_node->focus_head), focused) {
|
2012-01-21 19:35:15 +01:00
|
|
|
|
if (con->old_id != mapping->old_id)
|
|
|
|
|
continue;
|
|
|
|
|
LOG("got it! %p\n", con);
|
|
|
|
|
/* Move this entry to the top of the focus list. */
|
|
|
|
|
TAILQ_REMOVE(&(json_node->focus_head), con, focused);
|
|
|
|
|
TAILQ_INSERT_HEAD(&(json_node->focus_head), con, focused);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
while (!TAILQ_EMPTY(&focus_mappings)) {
|
|
|
|
|
mapping = TAILQ_FIRST(&focus_mappings);
|
|
|
|
|
TAILQ_REMOVE(&focus_mappings, mapping, focus_mappings);
|
|
|
|
|
free(mapping);
|
|
|
|
|
}
|
|
|
|
|
parsing_focus = false;
|
|
|
|
|
}
|
2010-03-27 15:25:51 +01:00
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-27 19:52:53 +02:00
|
|
|
|
static int json_key(void *ctx, const unsigned char *val, size_t len) {
|
|
|
|
|
LOG("key: %.*s\n", (int)len, val);
|
2010-03-27 15:25:51 +01:00
|
|
|
|
FREE(last_key);
|
2014-06-15 19:07:02 +02:00
|
|
|
|
last_key = scalloc((len + 1) * sizeof(char));
|
2010-03-27 15:25:51 +01:00
|
|
|
|
memcpy(last_key, val, len);
|
2012-01-21 19:35:15 +01:00
|
|
|
|
if (strcasecmp(last_key, "swallows") == 0)
|
2010-03-27 15:25:51 +01:00
|
|
|
|
parsing_swallows = true;
|
2012-01-21 19:35:15 +01:00
|
|
|
|
|
2010-03-27 15:25:51 +01:00
|
|
|
|
if (strcasecmp(last_key, "rect") == 0)
|
|
|
|
|
parsing_rect = true;
|
2012-01-21 19:35:15 +01:00
|
|
|
|
|
2014-11-16 22:05:51 +01:00
|
|
|
|
if (strcasecmp(last_key, "deco_rect") == 0)
|
|
|
|
|
parsing_deco_rect = true;
|
|
|
|
|
|
2010-11-28 17:20:29 +01:00
|
|
|
|
if (strcasecmp(last_key, "window_rect") == 0)
|
|
|
|
|
parsing_window_rect = true;
|
2012-01-21 19:35:15 +01:00
|
|
|
|
|
2011-02-21 03:01:55 +01:00
|
|
|
|
if (strcasecmp(last_key, "geometry") == 0)
|
|
|
|
|
parsing_geometry = true;
|
2012-01-21 19:35:15 +01:00
|
|
|
|
|
|
|
|
|
if (strcasecmp(last_key, "focus") == 0)
|
|
|
|
|
parsing_focus = true;
|
|
|
|
|
|
2010-03-27 15:25:51 +01:00
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-27 19:52:53 +02:00
|
|
|
|
static int json_string(void *ctx, const unsigned char *val, size_t len) {
|
2012-08-05 16:34:38 +02:00
|
|
|
|
LOG("string: %.*s for key %s\n", (int)len, val, last_key);
|
2010-03-27 15:25:51 +01:00
|
|
|
|
if (parsing_swallows) {
|
2013-12-14 11:44:06 +01:00
|
|
|
|
char *sval;
|
|
|
|
|
sasprintf(&sval, "%.*s", len, val);
|
2010-03-27 15:25:51 +01:00
|
|
|
|
if (strcasecmp(last_key, "class") == 0) {
|
2013-12-14 10:41:44 +01:00
|
|
|
|
current_swallow->class = regex_new(sval);
|
2013-12-14 11:44:06 +01:00
|
|
|
|
} else if (strcasecmp(last_key, "instance") == 0) {
|
|
|
|
|
current_swallow->instance = regex_new(sval);
|
|
|
|
|
} else if (strcasecmp(last_key, "window_role") == 0) {
|
2013-12-15 11:25:58 +01:00
|
|
|
|
current_swallow->window_role = regex_new(sval);
|
2013-12-14 11:44:06 +01:00
|
|
|
|
} else if (strcasecmp(last_key, "title") == 0) {
|
|
|
|
|
current_swallow->title = regex_new(sval);
|
2013-12-14 10:41:44 +01:00
|
|
|
|
} else {
|
|
|
|
|
ELOG("swallow key %s unknown\n", last_key);
|
2010-03-27 15:25:51 +01:00
|
|
|
|
}
|
2013-12-14 11:44:06 +01:00
|
|
|
|
free(sval);
|
2010-03-27 15:25:51 +01:00
|
|
|
|
} else {
|
|
|
|
|
if (strcasecmp(last_key, "name") == 0) {
|
2014-06-15 19:07:02 +02:00
|
|
|
|
json_node->name = scalloc((len + 1) * sizeof(char));
|
2010-03-27 15:25:51 +01:00
|
|
|
|
memcpy(json_node->name, val, len);
|
2010-09-01 18:11:01 +02:00
|
|
|
|
} else if (strcasecmp(last_key, "sticky_group") == 0) {
|
2014-06-15 19:07:02 +02:00
|
|
|
|
json_node->sticky_group = scalloc((len + 1) * sizeof(char));
|
2010-09-01 18:11:01 +02:00
|
|
|
|
memcpy(json_node->sticky_group, val, len);
|
|
|
|
|
LOG("sticky_group of this container is %s\n", json_node->sticky_group);
|
2011-01-21 22:58:22 +01:00
|
|
|
|
} else if (strcasecmp(last_key, "orientation") == 0) {
|
Introduce splith/splitv layouts, remove orientation
With this commit, the "default" layout is replaced by the splith and
splitv layouts. splith is equivalent to default with orientation
horizontal and splitv is equivalent to default with orientation
vertical.
The "split h" and "split v" commands continue to work as before, they
split the current container and you will end up in a split container
with layout splith (after "split h") or splitv (after "split v").
To change a splith container into a splitv container, use either "layout
splitv" or "layout toggle split". The latter command is used in the
default config as mod+l (previously "layout default"). In case you have
"layout default" in your config file, it is recommended to just replace
it by "layout toggle split", which will work as "layout default" did
before when pressing it once, but toggle between horizontal/vertical
when pressing it repeatedly.
The rationale behind this commit is that it’s cleaner to have all
parameters that influence how windows are rendered in the layout itself
rather than having a special parameter in combination with only one
layout. This enables us to change existing split containers in all cases
without breaking existing features (see ticket #464). Also, users should
feel more confident about whether they are actually splitting or just
changing an existing split container now.
As a nice side-effect, this commit brings back the "layout toggle"
feature we once had in i3 version 3 (see the userguide).
AFAIK, it is safe to use in-place restart to upgrade into versions
after this commit (switching to an older version will break your layout,
though).
Fixes #464
2012-08-04 03:04:00 +02:00
|
|
|
|
/* Upgrade path from older versions of i3 (doing an inplace restart
|
|
|
|
|
* to a newer version):
|
|
|
|
|
* "orientation" is dumped before "layout". Therefore, we store
|
|
|
|
|
* whether the orientation was horizontal or vertical in the
|
|
|
|
|
* last_split_layout. When we then encounter layout == "default",
|
|
|
|
|
* we will use the last_split_layout as layout instead. */
|
2011-01-21 22:58:22 +01:00
|
|
|
|
char *buf = NULL;
|
2011-10-23 14:16:56 +02:00
|
|
|
|
sasprintf(&buf, "%.*s", (int)len, val);
|
Introduce splith/splitv layouts, remove orientation
With this commit, the "default" layout is replaced by the splith and
splitv layouts. splith is equivalent to default with orientation
horizontal and splitv is equivalent to default with orientation
vertical.
The "split h" and "split v" commands continue to work as before, they
split the current container and you will end up in a split container
with layout splith (after "split h") or splitv (after "split v").
To change a splith container into a splitv container, use either "layout
splitv" or "layout toggle split". The latter command is used in the
default config as mod+l (previously "layout default"). In case you have
"layout default" in your config file, it is recommended to just replace
it by "layout toggle split", which will work as "layout default" did
before when pressing it once, but toggle between horizontal/vertical
when pressing it repeatedly.
The rationale behind this commit is that it’s cleaner to have all
parameters that influence how windows are rendered in the layout itself
rather than having a special parameter in combination with only one
layout. This enables us to change existing split containers in all cases
without breaking existing features (see ticket #464). Also, users should
feel more confident about whether they are actually splitting or just
changing an existing split container now.
As a nice side-effect, this commit brings back the "layout toggle"
feature we once had in i3 version 3 (see the userguide).
AFAIK, it is safe to use in-place restart to upgrade into versions
after this commit (switching to an older version will break your layout,
though).
Fixes #464
2012-08-04 03:04:00 +02:00
|
|
|
|
if (strcasecmp(buf, "none") == 0 ||
|
|
|
|
|
strcasecmp(buf, "horizontal") == 0)
|
|
|
|
|
json_node->last_split_layout = L_SPLITH;
|
2011-01-21 22:58:22 +01:00
|
|
|
|
else if (strcasecmp(buf, "vertical") == 0)
|
Introduce splith/splitv layouts, remove orientation
With this commit, the "default" layout is replaced by the splith and
splitv layouts. splith is equivalent to default with orientation
horizontal and splitv is equivalent to default with orientation
vertical.
The "split h" and "split v" commands continue to work as before, they
split the current container and you will end up in a split container
with layout splith (after "split h") or splitv (after "split v").
To change a splith container into a splitv container, use either "layout
splitv" or "layout toggle split". The latter command is used in the
default config as mod+l (previously "layout default"). In case you have
"layout default" in your config file, it is recommended to just replace
it by "layout toggle split", which will work as "layout default" did
before when pressing it once, but toggle between horizontal/vertical
when pressing it repeatedly.
The rationale behind this commit is that it’s cleaner to have all
parameters that influence how windows are rendered in the layout itself
rather than having a special parameter in combination with only one
layout. This enables us to change existing split containers in all cases
without breaking existing features (see ticket #464). Also, users should
feel more confident about whether they are actually splitting or just
changing an existing split container now.
As a nice side-effect, this commit brings back the "layout toggle"
feature we once had in i3 version 3 (see the userguide).
AFAIK, it is safe to use in-place restart to upgrade into versions
after this commit (switching to an older version will break your layout,
though).
Fixes #464
2012-08-04 03:04:00 +02:00
|
|
|
|
json_node->last_split_layout = L_SPLITV;
|
2014-06-15 19:07:02 +02:00
|
|
|
|
else
|
|
|
|
|
LOG("Unhandled orientation: %s\n", buf);
|
2011-01-21 22:58:22 +01:00
|
|
|
|
free(buf);
|
2011-05-11 20:45:56 +02:00
|
|
|
|
} else if (strcasecmp(last_key, "border") == 0) {
|
|
|
|
|
char *buf = NULL;
|
2011-10-23 14:16:56 +02:00
|
|
|
|
sasprintf(&buf, "%.*s", (int)len, val);
|
2011-05-11 20:45:56 +02:00
|
|
|
|
if (strcasecmp(buf, "none") == 0)
|
|
|
|
|
json_node->border_style = BS_NONE;
|
2012-09-24 01:14:00 +02:00
|
|
|
|
else if (strcasecmp(buf, "1pixel") == 0) {
|
|
|
|
|
json_node->border_style = BS_PIXEL;
|
|
|
|
|
json_node->current_border_width = 1;
|
|
|
|
|
} else if (strcasecmp(buf, "pixel") == 0)
|
|
|
|
|
json_node->border_style = BS_PIXEL;
|
2011-05-11 20:45:56 +02:00
|
|
|
|
else if (strcasecmp(buf, "normal") == 0)
|
|
|
|
|
json_node->border_style = BS_NORMAL;
|
2014-06-15 19:07:02 +02:00
|
|
|
|
else
|
|
|
|
|
LOG("Unhandled \"border\": %s\n", buf);
|
2011-05-11 20:45:56 +02:00
|
|
|
|
free(buf);
|
2013-12-14 14:50:44 +01:00
|
|
|
|
} else if (strcasecmp(last_key, "type") == 0) {
|
|
|
|
|
char *buf = NULL;
|
|
|
|
|
sasprintf(&buf, "%.*s", (int)len, val);
|
|
|
|
|
if (strcasecmp(buf, "root") == 0)
|
|
|
|
|
json_node->type = CT_ROOT;
|
|
|
|
|
else if (strcasecmp(buf, "output") == 0)
|
|
|
|
|
json_node->type = CT_OUTPUT;
|
|
|
|
|
else if (strcasecmp(buf, "con") == 0)
|
|
|
|
|
json_node->type = CT_CON;
|
|
|
|
|
else if (strcasecmp(buf, "floating_con") == 0)
|
|
|
|
|
json_node->type = CT_FLOATING_CON;
|
|
|
|
|
else if (strcasecmp(buf, "workspace") == 0)
|
|
|
|
|
json_node->type = CT_WORKSPACE;
|
|
|
|
|
else if (strcasecmp(buf, "dockarea") == 0)
|
|
|
|
|
json_node->type = CT_DOCKAREA;
|
2014-06-15 19:07:02 +02:00
|
|
|
|
else
|
|
|
|
|
LOG("Unhandled \"type\": %s\n", buf);
|
2013-12-14 14:50:44 +01:00
|
|
|
|
free(buf);
|
2011-06-02 17:12:18 +02:00
|
|
|
|
} else if (strcasecmp(last_key, "layout") == 0) {
|
|
|
|
|
char *buf = NULL;
|
2011-10-23 14:16:56 +02:00
|
|
|
|
sasprintf(&buf, "%.*s", (int)len, val);
|
2011-06-02 17:12:18 +02:00
|
|
|
|
if (strcasecmp(buf, "default") == 0)
|
Introduce splith/splitv layouts, remove orientation
With this commit, the "default" layout is replaced by the splith and
splitv layouts. splith is equivalent to default with orientation
horizontal and splitv is equivalent to default with orientation
vertical.
The "split h" and "split v" commands continue to work as before, they
split the current container and you will end up in a split container
with layout splith (after "split h") or splitv (after "split v").
To change a splith container into a splitv container, use either "layout
splitv" or "layout toggle split". The latter command is used in the
default config as mod+l (previously "layout default"). In case you have
"layout default" in your config file, it is recommended to just replace
it by "layout toggle split", which will work as "layout default" did
before when pressing it once, but toggle between horizontal/vertical
when pressing it repeatedly.
The rationale behind this commit is that it’s cleaner to have all
parameters that influence how windows are rendered in the layout itself
rather than having a special parameter in combination with only one
layout. This enables us to change existing split containers in all cases
without breaking existing features (see ticket #464). Also, users should
feel more confident about whether they are actually splitting or just
changing an existing split container now.
As a nice side-effect, this commit brings back the "layout toggle"
feature we once had in i3 version 3 (see the userguide).
AFAIK, it is safe to use in-place restart to upgrade into versions
after this commit (switching to an older version will break your layout,
though).
Fixes #464
2012-08-04 03:04:00 +02:00
|
|
|
|
/* This set above when we read "orientation". */
|
|
|
|
|
json_node->layout = json_node->last_split_layout;
|
2011-06-02 17:12:18 +02:00
|
|
|
|
else if (strcasecmp(buf, "stacked") == 0)
|
|
|
|
|
json_node->layout = L_STACKED;
|
|
|
|
|
else if (strcasecmp(buf, "tabbed") == 0)
|
|
|
|
|
json_node->layout = L_TABBED;
|
2012-10-03 19:10:48 +02:00
|
|
|
|
else if (strcasecmp(buf, "dockarea") == 0)
|
2011-06-02 17:12:18 +02:00
|
|
|
|
json_node->layout = L_DOCKAREA;
|
2012-10-03 19:10:48 +02:00
|
|
|
|
else if (strcasecmp(buf, "output") == 0)
|
2011-06-02 17:12:18 +02:00
|
|
|
|
json_node->layout = L_OUTPUT;
|
Introduce splith/splitv layouts, remove orientation
With this commit, the "default" layout is replaced by the splith and
splitv layouts. splith is equivalent to default with orientation
horizontal and splitv is equivalent to default with orientation
vertical.
The "split h" and "split v" commands continue to work as before, they
split the current container and you will end up in a split container
with layout splith (after "split h") or splitv (after "split v").
To change a splith container into a splitv container, use either "layout
splitv" or "layout toggle split". The latter command is used in the
default config as mod+l (previously "layout default"). In case you have
"layout default" in your config file, it is recommended to just replace
it by "layout toggle split", which will work as "layout default" did
before when pressing it once, but toggle between horizontal/vertical
when pressing it repeatedly.
The rationale behind this commit is that it’s cleaner to have all
parameters that influence how windows are rendered in the layout itself
rather than having a special parameter in combination with only one
layout. This enables us to change existing split containers in all cases
without breaking existing features (see ticket #464). Also, users should
feel more confident about whether they are actually splitting or just
changing an existing split container now.
As a nice side-effect, this commit brings back the "layout toggle"
feature we once had in i3 version 3 (see the userguide).
AFAIK, it is safe to use in-place restart to upgrade into versions
after this commit (switching to an older version will break your layout,
though).
Fixes #464
2012-08-04 03:04:00 +02:00
|
|
|
|
else if (strcasecmp(buf, "splith") == 0)
|
|
|
|
|
json_node->layout = L_SPLITH;
|
|
|
|
|
else if (strcasecmp(buf, "splitv") == 0)
|
|
|
|
|
json_node->layout = L_SPLITV;
|
2014-06-15 19:07:02 +02:00
|
|
|
|
else
|
|
|
|
|
LOG("Unhandled \"layout\": %s\n", buf);
|
2011-06-02 17:12:18 +02:00
|
|
|
|
free(buf);
|
2012-09-16 22:53:41 +02:00
|
|
|
|
} else if (strcasecmp(last_key, "workspace_layout") == 0) {
|
|
|
|
|
char *buf = NULL;
|
|
|
|
|
sasprintf(&buf, "%.*s", (int)len, val);
|
|
|
|
|
if (strcasecmp(buf, "default") == 0)
|
|
|
|
|
json_node->workspace_layout = L_DEFAULT;
|
|
|
|
|
else if (strcasecmp(buf, "stacked") == 0)
|
|
|
|
|
json_node->workspace_layout = L_STACKED;
|
|
|
|
|
else if (strcasecmp(buf, "tabbed") == 0)
|
|
|
|
|
json_node->workspace_layout = L_TABBED;
|
2014-06-15 19:07:02 +02:00
|
|
|
|
else
|
|
|
|
|
LOG("Unhandled \"workspace_layout\": %s\n", buf);
|
2012-09-16 22:53:41 +02:00
|
|
|
|
free(buf);
|
Introduce splith/splitv layouts, remove orientation
With this commit, the "default" layout is replaced by the splith and
splitv layouts. splith is equivalent to default with orientation
horizontal and splitv is equivalent to default with orientation
vertical.
The "split h" and "split v" commands continue to work as before, they
split the current container and you will end up in a split container
with layout splith (after "split h") or splitv (after "split v").
To change a splith container into a splitv container, use either "layout
splitv" or "layout toggle split". The latter command is used in the
default config as mod+l (previously "layout default"). In case you have
"layout default" in your config file, it is recommended to just replace
it by "layout toggle split", which will work as "layout default" did
before when pressing it once, but toggle between horizontal/vertical
when pressing it repeatedly.
The rationale behind this commit is that it’s cleaner to have all
parameters that influence how windows are rendered in the layout itself
rather than having a special parameter in combination with only one
layout. This enables us to change existing split containers in all cases
without breaking existing features (see ticket #464). Also, users should
feel more confident about whether they are actually splitting or just
changing an existing split container now.
As a nice side-effect, this commit brings back the "layout toggle"
feature we once had in i3 version 3 (see the userguide).
AFAIK, it is safe to use in-place restart to upgrade into versions
after this commit (switching to an older version will break your layout,
though).
Fixes #464
2012-08-04 03:04:00 +02:00
|
|
|
|
} else if (strcasecmp(last_key, "last_split_layout") == 0) {
|
|
|
|
|
char *buf = NULL;
|
|
|
|
|
sasprintf(&buf, "%.*s", (int)len, val);
|
|
|
|
|
if (strcasecmp(buf, "splith") == 0)
|
|
|
|
|
json_node->last_split_layout = L_SPLITH;
|
|
|
|
|
else if (strcasecmp(buf, "splitv") == 0)
|
|
|
|
|
json_node->last_split_layout = L_SPLITV;
|
2014-06-15 19:07:02 +02:00
|
|
|
|
else
|
|
|
|
|
LOG("Unhandled \"last_splitlayout\": %s\n", buf);
|
Introduce splith/splitv layouts, remove orientation
With this commit, the "default" layout is replaced by the splith and
splitv layouts. splith is equivalent to default with orientation
horizontal and splitv is equivalent to default with orientation
vertical.
The "split h" and "split v" commands continue to work as before, they
split the current container and you will end up in a split container
with layout splith (after "split h") or splitv (after "split v").
To change a splith container into a splitv container, use either "layout
splitv" or "layout toggle split". The latter command is used in the
default config as mod+l (previously "layout default"). In case you have
"layout default" in your config file, it is recommended to just replace
it by "layout toggle split", which will work as "layout default" did
before when pressing it once, but toggle between horizontal/vertical
when pressing it repeatedly.
The rationale behind this commit is that it’s cleaner to have all
parameters that influence how windows are rendered in the layout itself
rather than having a special parameter in combination with only one
layout. This enables us to change existing split containers in all cases
without breaking existing features (see ticket #464). Also, users should
feel more confident about whether they are actually splitting or just
changing an existing split container now.
As a nice side-effect, this commit brings back the "layout toggle"
feature we once had in i3 version 3 (see the userguide).
AFAIK, it is safe to use in-place restart to upgrade into versions
after this commit (switching to an older version will break your layout,
though).
Fixes #464
2012-08-04 03:04:00 +02:00
|
|
|
|
free(buf);
|
2011-08-07 18:42:23 +02:00
|
|
|
|
} else if (strcasecmp(last_key, "mark") == 0) {
|
|
|
|
|
char *buf = NULL;
|
2011-10-23 14:16:56 +02:00
|
|
|
|
sasprintf(&buf, "%.*s", (int)len, val);
|
2011-08-07 18:42:23 +02:00
|
|
|
|
json_node->mark = buf;
|
2012-01-05 22:39:18 +01:00
|
|
|
|
} else if (strcasecmp(last_key, "floating") == 0) {
|
|
|
|
|
char *buf = NULL;
|
|
|
|
|
sasprintf(&buf, "%.*s", (int)len, val);
|
|
|
|
|
if (strcasecmp(buf, "auto_off") == 0)
|
|
|
|
|
json_node->floating = FLOATING_AUTO_OFF;
|
|
|
|
|
else if (strcasecmp(buf, "auto_on") == 0)
|
|
|
|
|
json_node->floating = FLOATING_AUTO_ON;
|
|
|
|
|
else if (strcasecmp(buf, "user_off") == 0)
|
|
|
|
|
json_node->floating = FLOATING_USER_OFF;
|
|
|
|
|
else if (strcasecmp(buf, "user_on") == 0)
|
|
|
|
|
json_node->floating = FLOATING_USER_ON;
|
|
|
|
|
free(buf);
|
|
|
|
|
} else if (strcasecmp(last_key, "scratchpad_state") == 0) {
|
|
|
|
|
char *buf = NULL;
|
|
|
|
|
sasprintf(&buf, "%.*s", (int)len, val);
|
|
|
|
|
if (strcasecmp(buf, "none") == 0)
|
|
|
|
|
json_node->scratchpad_state = SCRATCHPAD_NONE;
|
|
|
|
|
else if (strcasecmp(buf, "fresh") == 0)
|
|
|
|
|
json_node->scratchpad_state = SCRATCHPAD_FRESH;
|
|
|
|
|
else if (strcasecmp(buf, "changed") == 0)
|
|
|
|
|
json_node->scratchpad_state = SCRATCHPAD_CHANGED;
|
|
|
|
|
free(buf);
|
2010-03-27 15:25:51 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-27 19:52:53 +02:00
|
|
|
|
static int json_int(void *ctx, long long val) {
|
2011-08-04 23:34:23 +02:00
|
|
|
|
LOG("int %lld for key %s\n", val, last_key);
|
2013-12-14 14:50:44 +01:00
|
|
|
|
/* For backwards compatibility with i3 < 4.8 */
|
2012-01-21 19:35:15 +01:00
|
|
|
|
if (strcasecmp(last_key, "type") == 0)
|
2010-03-27 15:25:51 +01:00
|
|
|
|
json_node->type = val;
|
2012-01-21 19:35:15 +01:00
|
|
|
|
|
|
|
|
|
if (strcasecmp(last_key, "fullscreen_mode") == 0)
|
2010-03-27 15:25:51 +01:00
|
|
|
|
json_node->fullscreen_mode = val;
|
2012-01-21 19:35:15 +01:00
|
|
|
|
|
2010-12-27 22:28:59 +01:00
|
|
|
|
if (strcasecmp(last_key, "num") == 0)
|
|
|
|
|
json_node->num = val;
|
|
|
|
|
|
2012-09-24 01:14:00 +02:00
|
|
|
|
if (strcasecmp(last_key, "current_border_width") == 0)
|
|
|
|
|
json_node->current_border_width = val;
|
|
|
|
|
|
2013-03-15 15:40:26 +01:00
|
|
|
|
if (strcasecmp(last_key, "depth") == 0)
|
|
|
|
|
json_node->depth = val;
|
|
|
|
|
|
2012-01-21 19:35:15 +01:00
|
|
|
|
if (!parsing_swallows && strcasecmp(last_key, "id") == 0)
|
|
|
|
|
json_node->old_id = val;
|
|
|
|
|
|
|
|
|
|
if (parsing_focus) {
|
|
|
|
|
struct focus_mapping *focus_mapping = scalloc(sizeof(struct focus_mapping));
|
|
|
|
|
focus_mapping->old_id = val;
|
|
|
|
|
TAILQ_INSERT_TAIL(&focus_mappings, focus_mapping, focus_mappings);
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-21 03:01:55 +01:00
|
|
|
|
if (parsing_rect || parsing_window_rect || parsing_geometry) {
|
|
|
|
|
Rect *r;
|
|
|
|
|
if (parsing_rect)
|
|
|
|
|
r = &(json_node->rect);
|
|
|
|
|
else if (parsing_window_rect)
|
|
|
|
|
r = &(json_node->window_rect);
|
2014-06-15 19:07:02 +02:00
|
|
|
|
else
|
|
|
|
|
r = &(json_node->geometry);
|
2010-03-27 15:25:51 +01:00
|
|
|
|
if (strcasecmp(last_key, "x") == 0)
|
2010-11-28 17:20:29 +01:00
|
|
|
|
r->x = val;
|
2010-03-27 15:25:51 +01:00
|
|
|
|
else if (strcasecmp(last_key, "y") == 0)
|
2010-11-28 17:20:29 +01:00
|
|
|
|
r->y = val;
|
2010-03-27 15:25:51 +01:00
|
|
|
|
else if (strcasecmp(last_key, "width") == 0)
|
2010-11-28 17:20:29 +01:00
|
|
|
|
r->width = val;
|
2010-03-27 15:25:51 +01:00
|
|
|
|
else if (strcasecmp(last_key, "height") == 0)
|
2010-11-28 17:20:29 +01:00
|
|
|
|
r->height = val;
|
2014-06-15 19:07:02 +02:00
|
|
|
|
else
|
|
|
|
|
ELOG("WARNING: unknown key %s in rect\n", last_key);
|
2013-12-14 16:28:54 +01:00
|
|
|
|
DLOG("rect now: (%d, %d, %d, %d)\n",
|
2014-06-15 19:07:02 +02:00
|
|
|
|
r->x, r->y, r->width, r->height);
|
2010-03-27 15:25:51 +01:00
|
|
|
|
}
|
|
|
|
|
if (parsing_swallows) {
|
|
|
|
|
if (strcasecmp(last_key, "id") == 0) {
|
|
|
|
|
current_swallow->id = val;
|
|
|
|
|
}
|
2010-08-15 12:18:27 +02:00
|
|
|
|
if (strcasecmp(last_key, "dock") == 0) {
|
2011-02-21 03:01:55 +01:00
|
|
|
|
current_swallow->dock = val;
|
|
|
|
|
}
|
|
|
|
|
if (strcasecmp(last_key, "insert_where") == 0) {
|
|
|
|
|
current_swallow->insert_where = val;
|
2010-08-15 12:18:27 +02:00
|
|
|
|
}
|
2010-03-27 15:25:51 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-04 22:58:19 +02:00
|
|
|
|
static int json_bool(void *ctx, int val) {
|
|
|
|
|
LOG("bool %d for key %s\n", val, last_key);
|
|
|
|
|
if (strcasecmp(last_key, "focused") == 0 && val) {
|
|
|
|
|
to_focus = json_node;
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-21 19:35:15 +01:00
|
|
|
|
if (parsing_swallows) {
|
|
|
|
|
if (strcasecmp(last_key, "restart_mode") == 0)
|
|
|
|
|
current_swallow->restart_mode = val;
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-04 22:58:19 +02:00
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-27 15:25:51 +01:00
|
|
|
|
static int json_double(void *ctx, double val) {
|
|
|
|
|
LOG("double %f for key %s\n", val, last_key);
|
|
|
|
|
if (strcasecmp(last_key, "percent") == 0) {
|
|
|
|
|
json_node->percent = val;
|
|
|
|
|
}
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-15 10:15:04 +02:00
|
|
|
|
static json_content_t content_result;
|
2015-01-31 22:40:55 +01:00
|
|
|
|
static int content_level;
|
|
|
|
|
|
|
|
|
|
static int json_determine_content_deeper(void *ctx) {
|
|
|
|
|
content_level++;
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int json_determine_content_shallower(void *ctx) {
|
|
|
|
|
content_level--;
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
2014-07-15 10:15:04 +02:00
|
|
|
|
|
|
|
|
|
static int json_determine_content_string(void *ctx, const unsigned char *val, size_t len) {
|
2015-01-31 22:40:55 +01:00
|
|
|
|
if (strcasecmp(last_key, "type") != 0 || content_level > 1)
|
2014-07-15 10:15:04 +02:00
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
|
|
DLOG("string = %.*s, last_key = %s\n", (int)len, val, last_key);
|
|
|
|
|
if (strncasecmp((const char *)val, "workspace", len) == 0)
|
|
|
|
|
content_result = JSON_CONTENT_WORKSPACE;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Parses the given JSON file until it encounters the first “type” property to
|
|
|
|
|
* determine whether the file contains workspaces or regular containers, which
|
|
|
|
|
* is important to know when deciding where (and how) to append the contents.
|
|
|
|
|
* */
|
|
|
|
|
json_content_t json_determine_content(const char *filename) {
|
|
|
|
|
FILE *f;
|
|
|
|
|
if ((f = fopen(filename, "r")) == NULL) {
|
|
|
|
|
ELOG("Cannot open file \"%s\"\n", filename);
|
|
|
|
|
return JSON_CONTENT_UNKNOWN;
|
|
|
|
|
}
|
|
|
|
|
struct stat stbuf;
|
|
|
|
|
if (fstat(fileno(f), &stbuf) != 0) {
|
|
|
|
|
ELOG("Cannot fstat() \"%s\"\n", filename);
|
|
|
|
|
fclose(f);
|
|
|
|
|
return JSON_CONTENT_UNKNOWN;
|
|
|
|
|
}
|
|
|
|
|
char *buf = smalloc(stbuf.st_size);
|
|
|
|
|
int n = fread(buf, 1, stbuf.st_size, f);
|
|
|
|
|
if (n != stbuf.st_size) {
|
|
|
|
|
ELOG("File \"%s\" could not be read entirely, not loading.\n", filename);
|
|
|
|
|
fclose(f);
|
|
|
|
|
return JSON_CONTENT_UNKNOWN;
|
|
|
|
|
}
|
|
|
|
|
DLOG("read %d bytes\n", n);
|
|
|
|
|
// We default to JSON_CONTENT_CON because it is legal to not include
|
|
|
|
|
// “"type": "con"” in the JSON files for better readability.
|
|
|
|
|
content_result = JSON_CONTENT_CON;
|
2015-01-31 22:40:55 +01:00
|
|
|
|
content_level = 0;
|
2014-07-15 10:15:04 +02:00
|
|
|
|
yajl_gen g;
|
|
|
|
|
yajl_handle hand;
|
|
|
|
|
static yajl_callbacks callbacks = {
|
|
|
|
|
.yajl_string = json_determine_content_string,
|
|
|
|
|
.yajl_map_key = json_key,
|
2015-01-31 22:40:55 +01:00
|
|
|
|
.yajl_start_array = json_determine_content_deeper,
|
|
|
|
|
.yajl_start_map = json_determine_content_deeper,
|
|
|
|
|
.yajl_end_map = json_determine_content_shallower,
|
|
|
|
|
.yajl_end_array = json_determine_content_shallower,
|
2014-07-15 10:15:04 +02:00
|
|
|
|
};
|
|
|
|
|
g = yajl_gen_alloc(NULL);
|
|
|
|
|
hand = yajl_alloc(&callbacks, NULL, (void *)g);
|
|
|
|
|
/* Allowing comments allows for more user-friendly layout files. */
|
|
|
|
|
yajl_config(hand, yajl_allow_comments, true);
|
|
|
|
|
/* Allow multiple values, i.e. multiple nodes to attach */
|
|
|
|
|
yajl_config(hand, yajl_allow_multiple_values, true);
|
|
|
|
|
yajl_status stat;
|
|
|
|
|
setlocale(LC_NUMERIC, "C");
|
|
|
|
|
stat = yajl_parse(hand, (const unsigned char *)buf, n);
|
|
|
|
|
if (stat != yajl_status_ok && stat != yajl_status_client_canceled) {
|
|
|
|
|
unsigned char *str = yajl_get_error(hand, 1, (const unsigned char *)buf, n);
|
|
|
|
|
ELOG("JSON parsing error: %s\n", str);
|
|
|
|
|
yajl_free_error(hand, str);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setlocale(LC_NUMERIC, "");
|
|
|
|
|
yajl_complete_parse(hand);
|
|
|
|
|
|
|
|
|
|
fclose(f);
|
|
|
|
|
|
|
|
|
|
return content_result;
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-18 20:30:27 +02:00
|
|
|
|
void tree_append_json(Con *con, const char *filename, char **errormsg) {
|
2010-03-27 15:25:51 +01:00
|
|
|
|
FILE *f;
|
|
|
|
|
if ((f = fopen(filename, "r")) == NULL) {
|
2014-07-15 10:15:04 +02:00
|
|
|
|
ELOG("Cannot open file \"%s\"\n", filename);
|
2012-09-21 16:47:43 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
struct stat stbuf;
|
|
|
|
|
if (fstat(fileno(f), &stbuf) != 0) {
|
2014-07-15 10:15:04 +02:00
|
|
|
|
ELOG("Cannot fstat() \"%s\"\n", filename);
|
2012-09-21 16:47:43 +02:00
|
|
|
|
fclose(f);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
char *buf = smalloc(stbuf.st_size);
|
|
|
|
|
int n = fread(buf, 1, stbuf.st_size, f);
|
|
|
|
|
if (n != stbuf.st_size) {
|
2014-07-15 10:15:04 +02:00
|
|
|
|
ELOG("File \"%s\" could not be read entirely, not loading.\n", filename);
|
2012-09-21 16:47:43 +02:00
|
|
|
|
fclose(f);
|
2010-03-27 15:25:51 +01:00
|
|
|
|
return;
|
|
|
|
|
}
|
2014-07-15 10:15:04 +02:00
|
|
|
|
DLOG("read %d bytes\n", n);
|
2010-03-27 15:25:51 +01:00
|
|
|
|
yajl_gen g;
|
|
|
|
|
yajl_handle hand;
|
2014-01-01 17:19:55 +01:00
|
|
|
|
static yajl_callbacks callbacks = {
|
|
|
|
|
.yajl_boolean = json_bool,
|
|
|
|
|
.yajl_integer = json_int,
|
|
|
|
|
.yajl_double = json_double,
|
|
|
|
|
.yajl_string = json_string,
|
|
|
|
|
.yajl_start_map = json_start_map,
|
|
|
|
|
.yajl_map_key = json_key,
|
|
|
|
|
.yajl_end_map = json_end_map,
|
|
|
|
|
.yajl_end_array = json_end_array,
|
|
|
|
|
};
|
2011-04-27 19:52:53 +02:00
|
|
|
|
g = yajl_gen_alloc(NULL);
|
2014-06-15 19:07:02 +02:00
|
|
|
|
hand = yajl_alloc(&callbacks, NULL, (void *)g);
|
2013-12-14 10:43:49 +01:00
|
|
|
|
/* Allowing comments allows for more user-friendly layout files. */
|
|
|
|
|
yajl_config(hand, yajl_allow_comments, true);
|
2013-12-14 16:25:54 +01:00
|
|
|
|
/* Allow multiple values, i.e. multiple nodes to attach */
|
|
|
|
|
yajl_config(hand, yajl_allow_multiple_values, true);
|
2010-03-27 15:25:51 +01:00
|
|
|
|
yajl_status stat;
|
2014-04-18 20:30:27 +02:00
|
|
|
|
json_node = con;
|
2010-11-28 14:27:44 +01:00
|
|
|
|
to_focus = NULL;
|
2014-01-04 21:23:12 +01:00
|
|
|
|
parsing_swallows = false;
|
2010-11-28 17:20:29 +01:00
|
|
|
|
parsing_rect = false;
|
2014-11-16 22:05:51 +01:00
|
|
|
|
parsing_deco_rect = false;
|
2010-11-28 17:20:29 +01:00
|
|
|
|
parsing_window_rect = false;
|
2011-02-21 03:01:55 +01:00
|
|
|
|
parsing_geometry = false;
|
2014-01-04 21:23:12 +01:00
|
|
|
|
parsing_focus = false;
|
2010-03-27 15:25:51 +01:00
|
|
|
|
setlocale(LC_NUMERIC, "C");
|
2014-06-15 19:07:02 +02:00
|
|
|
|
stat = yajl_parse(hand, (const unsigned char *)buf, n);
|
|
|
|
|
if (stat != yajl_status_ok) {
|
|
|
|
|
unsigned char *str = yajl_get_error(hand, 1, (const unsigned char *)buf, n);
|
2013-12-14 16:28:54 +01:00
|
|
|
|
ELOG("JSON parsing error: %s\n", str);
|
2014-01-04 21:39:13 +01:00
|
|
|
|
if (errormsg != NULL)
|
2014-06-15 19:07:02 +02:00
|
|
|
|
*errormsg = sstrdup((const char *)str);
|
2010-03-27 15:25:51 +01:00
|
|
|
|
yajl_free_error(hand, str);
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-04 21:59:41 +01:00
|
|
|
|
/* In case not all containers were restored, we need to fix the
|
|
|
|
|
* percentages, otherwise i3 will crash immediately when rendering the
|
|
|
|
|
* next time. */
|
2014-04-18 20:30:27 +02:00
|
|
|
|
con_fix_percent(con);
|
2014-01-04 21:59:41 +01:00
|
|
|
|
|
2010-03-27 15:25:51 +01:00
|
|
|
|
setlocale(LC_NUMERIC, "");
|
2011-04-27 19:52:53 +02:00
|
|
|
|
yajl_complete_parse(hand);
|
2010-03-27 15:25:51 +01:00
|
|
|
|
|
|
|
|
|
fclose(f);
|
2010-11-28 14:27:44 +01:00
|
|
|
|
if (to_focus)
|
|
|
|
|
con_focus(to_focus);
|
2010-03-27 15:25:51 +01:00
|
|
|
|
}
|