2012-08-12 06:18:43 -04:00
|
|
|
#undef I3__FILE__
|
|
|
|
#define I3__FILE__ "load_layout.c"
|
2010-08-15 06:18:27 -04:00
|
|
|
/*
|
|
|
|
* vim:ts=4:sw=4:expandtab
|
|
|
|
*
|
2011-10-22 18:40:02 -04:00
|
|
|
* i3 - an improved dynamic tiling window manager
|
2012-01-21 13:35:15 -05:00
|
|
|
* © 2009-2012 Michael Stapelberg and contributors (see also: LICENSE)
|
2011-10-22 18:40:02 -04:00
|
|
|
*
|
|
|
|
* load_layout.c: Restore (parts of) the layout, for example after an inplace
|
|
|
|
* restart.
|
|
|
|
*
|
2010-08-15 06:18:27 -04:00
|
|
|
*/
|
2011-10-22 18:40:02 -04:00
|
|
|
#include "all.h"
|
|
|
|
|
2010-03-27 10:25:51 -04:00
|
|
|
#include <yajl/yajl_common.h>
|
|
|
|
#include <yajl/yajl_gen.h>
|
|
|
|
#include <yajl/yajl_parse.h>
|
2011-04-27 13:52:53 -04:00
|
|
|
#include <yajl/yajl_version.h>
|
2010-03-27 10:25:51 -04:00
|
|
|
|
|
|
|
/* TODO: refactor the whole parsing thing */
|
|
|
|
|
|
|
|
static char *last_key;
|
|
|
|
static Con *json_node;
|
2010-11-28 08:27:44 -05:00
|
|
|
static Con *to_focus;
|
2010-03-27 10:25:51 -04:00
|
|
|
static bool parsing_swallows;
|
|
|
|
static bool parsing_rect;
|
2010-11-28 11:20:29 -05:00
|
|
|
static bool parsing_window_rect;
|
2011-02-20 21:01:55 -05:00
|
|
|
static bool parsing_geometry;
|
2012-01-21 13:35:15 -05:00
|
|
|
static bool parsing_focus;
|
2010-03-27 10:25:51 -04:00
|
|
|
struct Match *current_swallow;
|
|
|
|
|
2012-01-21 13:35:15 -05: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 =
|
|
|
|
TAILQ_HEAD_INITIALIZER(focus_mappings);
|
|
|
|
|
2010-03-27 10:25:51 -04:00
|
|
|
static int json_start_map(void *ctx) {
|
2010-11-29 15:46:00 -05:00
|
|
|
LOG("start of map, last_key = %s\n", last_key);
|
2010-03-27 10:25:51 -04:00
|
|
|
if (parsing_swallows) {
|
2011-02-28 14:44:23 -05:00
|
|
|
LOG("creating new swallow\n");
|
2010-08-15 06:18:27 -04:00
|
|
|
current_swallow = smalloc(sizeof(Match));
|
|
|
|
match_init(current_swallow);
|
2010-03-27 10:25:51 -04:00
|
|
|
TAILQ_INSERT_TAIL(&(json_node->swallow_head), current_swallow, matches);
|
|
|
|
} else {
|
2011-02-20 21:01:55 -05:00
|
|
|
if (!parsing_rect && !parsing_window_rect && !parsing_geometry) {
|
2010-11-29 15:46:00 -05:00
|
|
|
if (last_key && strcasecmp(last_key, "floating_nodes") == 0) {
|
2011-02-28 14:44:23 -05:00
|
|
|
DLOG("New floating_node\n");
|
2010-11-29 15:46:00 -05:00
|
|
|
Con *ws = con_get_workspace(json_node);
|
2011-06-02 11:21:38 -04:00
|
|
|
json_node = con_new(NULL, NULL);
|
2010-11-29 15:46:00 -05:00
|
|
|
json_node->parent = ws;
|
2011-02-28 14:44:23 -05:00
|
|
|
DLOG("Parent is workspace = %p\n", ws);
|
2010-11-29 15:46:00 -05:00
|
|
|
} else {
|
2010-12-27 16:28:59 -05:00
|
|
|
Con *parent = json_node;
|
2011-06-02 11:21:38 -04:00
|
|
|
json_node = con_new(NULL, NULL);
|
2010-12-27 16:28:59 -05:00
|
|
|
json_node->parent = parent;
|
2010-11-29 15:46:00 -05:00
|
|
|
}
|
|
|
|
}
|
2010-03-27 10:25:51 -04:00
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int json_end_map(void *ctx) {
|
|
|
|
LOG("end of map\n");
|
2011-02-20 21:01:55 -05:00
|
|
|
if (!parsing_swallows && !parsing_rect && !parsing_window_rect && !parsing_geometry) {
|
2010-12-27 16:28:59 -05:00
|
|
|
LOG("attaching\n");
|
2011-05-12 01:22:17 -04:00
|
|
|
con_attach(json_node, json_node->parent, true);
|
2010-03-27 10:25:51 -04:00
|
|
|
json_node = json_node->parent;
|
2010-12-27 16:28:59 -05:00
|
|
|
}
|
2010-03-27 10:25:51 -04:00
|
|
|
if (parsing_rect)
|
|
|
|
parsing_rect = false;
|
2010-11-28 11:20:29 -05:00
|
|
|
if (parsing_window_rect)
|
|
|
|
parsing_window_rect = false;
|
2011-02-20 21:01:55 -05:00
|
|
|
if (parsing_geometry)
|
|
|
|
parsing_geometry = false;
|
2010-03-27 10:25:51 -04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int json_end_array(void *ctx) {
|
|
|
|
LOG("end of array\n");
|
|
|
|
parsing_swallows = false;
|
2012-01-21 13:35:15 -05:00
|
|
|
if (parsing_focus) {
|
|
|
|
/* Clear the list of focus mappings */
|
|
|
|
struct focus_mapping *mapping;
|
|
|
|
TAILQ_FOREACH_REVERSE(mapping, &focus_mappings, focus_mappings_head, focus_mappings) {
|
|
|
|
LOG("focus (reverse) %d\n", mapping->old_id);
|
|
|
|
Con *con;
|
|
|
|
TAILQ_FOREACH(con, &(json_node->focus_head), focused) {
|
|
|
|
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 10:25:51 -04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2011-04-27 13:52:53 -04:00
|
|
|
#if YAJL_MAJOR < 2
|
2010-03-27 10:25:51 -04:00
|
|
|
static int json_key(void *ctx, const unsigned char *val, unsigned int len) {
|
2011-04-27 13:52:53 -04:00
|
|
|
#else
|
|
|
|
static int json_key(void *ctx, const unsigned char *val, size_t len) {
|
|
|
|
#endif
|
|
|
|
LOG("key: %.*s\n", (int)len, val);
|
2010-03-27 10:25:51 -04:00
|
|
|
FREE(last_key);
|
|
|
|
last_key = scalloc((len+1) * sizeof(char));
|
|
|
|
memcpy(last_key, val, len);
|
2012-01-21 13:35:15 -05:00
|
|
|
if (strcasecmp(last_key, "swallows") == 0)
|
2010-03-27 10:25:51 -04:00
|
|
|
parsing_swallows = true;
|
2012-01-21 13:35:15 -05:00
|
|
|
|
2010-03-27 10:25:51 -04:00
|
|
|
if (strcasecmp(last_key, "rect") == 0)
|
|
|
|
parsing_rect = true;
|
2012-01-21 13:35:15 -05:00
|
|
|
|
2010-11-28 11:20:29 -05:00
|
|
|
if (strcasecmp(last_key, "window_rect") == 0)
|
|
|
|
parsing_window_rect = true;
|
2012-01-21 13:35:15 -05:00
|
|
|
|
2011-02-20 21:01:55 -05:00
|
|
|
if (strcasecmp(last_key, "geometry") == 0)
|
|
|
|
parsing_geometry = true;
|
2012-01-21 13:35:15 -05:00
|
|
|
|
|
|
|
if (strcasecmp(last_key, "focus") == 0)
|
|
|
|
parsing_focus = true;
|
|
|
|
|
2010-03-27 10:25:51 -04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2011-04-27 13:52:53 -04:00
|
|
|
#if YAJL_MAJOR >= 2
|
|
|
|
static int json_string(void *ctx, const unsigned char *val, size_t len) {
|
|
|
|
#else
|
2010-03-27 10:25:51 -04:00
|
|
|
static int json_string(void *ctx, const unsigned char *val, unsigned int len) {
|
2011-04-27 13:52:53 -04:00
|
|
|
#endif
|
2012-08-05 10:34:38 -04:00
|
|
|
LOG("string: %.*s for key %s\n", (int)len, val, last_key);
|
2010-03-27 10:25:51 -04:00
|
|
|
if (parsing_swallows) {
|
|
|
|
/* TODO: the other swallowing keys */
|
|
|
|
if (strcasecmp(last_key, "class") == 0) {
|
|
|
|
current_swallow->class = scalloc((len+1) * sizeof(char));
|
|
|
|
memcpy(current_swallow->class, val, len);
|
|
|
|
}
|
|
|
|
LOG("unhandled yet: swallow\n");
|
|
|
|
} else {
|
|
|
|
if (strcasecmp(last_key, "name") == 0) {
|
|
|
|
json_node->name = scalloc((len+1) * sizeof(char));
|
|
|
|
memcpy(json_node->name, val, len);
|
2010-09-01 12:11:01 -04:00
|
|
|
} else if (strcasecmp(last_key, "sticky_group") == 0) {
|
|
|
|
json_node->sticky_group = scalloc((len+1) * sizeof(char));
|
|
|
|
memcpy(json_node->sticky_group, val, len);
|
|
|
|
LOG("sticky_group of this container is %s\n", json_node->sticky_group);
|
2011-01-21 16:58:22 -05: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-03 21:04:00 -04: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 16:58:22 -05:00
|
|
|
char *buf = NULL;
|
2011-10-23 08:16:56 -04: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-03 21:04:00 -04:00
|
|
|
if (strcasecmp(buf, "none") == 0 ||
|
|
|
|
strcasecmp(buf, "horizontal") == 0)
|
|
|
|
json_node->last_split_layout = L_SPLITH;
|
2011-01-21 16:58:22 -05: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-03 21:04:00 -04:00
|
|
|
json_node->last_split_layout = L_SPLITV;
|
2011-01-21 16:58:22 -05:00
|
|
|
else LOG("Unhandled orientation: %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-03 21:04:00 -04:00
|
|
|
|
|
|
|
/* What used to be an implicit check whether orientation !=
|
|
|
|
* NO_ORIENTATION is now a proper separate flag. */
|
|
|
|
if (strcasecmp(buf, "none") != 0)
|
|
|
|
json_node->split = true;
|
2011-01-21 16:58:22 -05:00
|
|
|
free(buf);
|
2011-05-11 14:45:56 -04:00
|
|
|
} else if (strcasecmp(last_key, "border") == 0) {
|
|
|
|
char *buf = NULL;
|
2011-10-23 08:16:56 -04:00
|
|
|
sasprintf(&buf, "%.*s", (int)len, val);
|
2011-05-11 14:45:56 -04:00
|
|
|
if (strcasecmp(buf, "none") == 0)
|
|
|
|
json_node->border_style = BS_NONE;
|
|
|
|
else if (strcasecmp(buf, "1pixel") == 0)
|
|
|
|
json_node->border_style = BS_1PIXEL;
|
|
|
|
else if (strcasecmp(buf, "normal") == 0)
|
|
|
|
json_node->border_style = BS_NORMAL;
|
|
|
|
else LOG("Unhandled \"border\": %s\n", buf);
|
|
|
|
free(buf);
|
2011-06-02 11:12:18 -04:00
|
|
|
} else if (strcasecmp(last_key, "layout") == 0) {
|
|
|
|
char *buf = NULL;
|
2011-10-23 08:16:56 -04:00
|
|
|
sasprintf(&buf, "%.*s", (int)len, val);
|
2011-06-02 11:12:18 -04: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-03 21:04:00 -04:00
|
|
|
/* This set above when we read "orientation". */
|
|
|
|
json_node->layout = json_node->last_split_layout;
|
2011-06-02 11:12:18 -04:00
|
|
|
else if (strcasecmp(buf, "stacked") == 0)
|
|
|
|
json_node->layout = L_STACKED;
|
|
|
|
else if (strcasecmp(buf, "tabbed") == 0)
|
|
|
|
json_node->layout = L_TABBED;
|
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-03 21:04:00 -04:00
|
|
|
else if (strcasecmp(buf, "dockarea") == 0) {
|
2011-06-02 11:12:18 -04:00
|
|
|
json_node->layout = L_DOCKAREA;
|
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-03 21:04:00 -04:00
|
|
|
/* Necessary for migrating from older versions of i3. */
|
|
|
|
json_node->split = false;
|
|
|
|
} else if (strcasecmp(buf, "output") == 0)
|
2011-06-02 11:12:18 -04: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-03 21:04:00 -04:00
|
|
|
else if (strcasecmp(buf, "splith") == 0)
|
|
|
|
json_node->layout = L_SPLITH;
|
|
|
|
else if (strcasecmp(buf, "splitv") == 0)
|
|
|
|
json_node->layout = L_SPLITV;
|
2011-06-02 11:12:18 -04:00
|
|
|
else LOG("Unhandled \"layout\": %s\n", buf);
|
|
|
|
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-03 21:04:00 -04: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;
|
|
|
|
else LOG("Unhandled \"last_splitlayout\": %s\n", buf);
|
|
|
|
free(buf);
|
2011-08-07 12:42:23 -04:00
|
|
|
} else if (strcasecmp(last_key, "mark") == 0) {
|
|
|
|
char *buf = NULL;
|
2011-10-23 08:16:56 -04:00
|
|
|
sasprintf(&buf, "%.*s", (int)len, val);
|
2011-08-07 12:42:23 -04:00
|
|
|
json_node->mark = buf;
|
2012-01-05 16:39:18 -05: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 10:25:51 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2011-04-27 13:52:53 -04:00
|
|
|
#if YAJL_MAJOR >= 2
|
|
|
|
static int json_int(void *ctx, long long val) {
|
2011-08-04 17:34:23 -04:00
|
|
|
LOG("int %lld for key %s\n", val, last_key);
|
2011-04-27 13:52:53 -04:00
|
|
|
#else
|
2010-03-27 10:25:51 -04:00
|
|
|
static int json_int(void *ctx, long val) {
|
2011-08-04 17:34:23 -04:00
|
|
|
LOG("int %ld for key %s\n", val, last_key);
|
2011-04-27 13:52:53 -04:00
|
|
|
#endif
|
2012-01-21 13:35:15 -05:00
|
|
|
if (strcasecmp(last_key, "type") == 0)
|
2010-03-27 10:25:51 -04:00
|
|
|
json_node->type = val;
|
2012-01-21 13:35:15 -05:00
|
|
|
|
|
|
|
if (strcasecmp(last_key, "fullscreen_mode") == 0)
|
2010-03-27 10:25:51 -04:00
|
|
|
json_node->fullscreen_mode = val;
|
2012-01-21 13:35:15 -05:00
|
|
|
|
2010-12-27 16:28:59 -05:00
|
|
|
if (strcasecmp(last_key, "num") == 0)
|
|
|
|
json_node->num = val;
|
|
|
|
|
2012-01-21 13:35:15 -05: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-20 21:01:55 -05: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);
|
|
|
|
else r = &(json_node->geometry);
|
2010-03-27 10:25:51 -04:00
|
|
|
if (strcasecmp(last_key, "x") == 0)
|
2010-11-28 11:20:29 -05:00
|
|
|
r->x = val;
|
2010-03-27 10:25:51 -04:00
|
|
|
else if (strcasecmp(last_key, "y") == 0)
|
2010-11-28 11:20:29 -05:00
|
|
|
r->y = val;
|
2010-03-27 10:25:51 -04:00
|
|
|
else if (strcasecmp(last_key, "width") == 0)
|
2010-11-28 11:20:29 -05:00
|
|
|
r->width = val;
|
2010-03-27 10:25:51 -04:00
|
|
|
else if (strcasecmp(last_key, "height") == 0)
|
2010-11-28 11:20:29 -05:00
|
|
|
r->height = val;
|
2010-03-27 10:25:51 -04:00
|
|
|
else printf("WARNING: unknown key %s in rect\n", last_key);
|
|
|
|
printf("rect now: (%d, %d, %d, %d)\n",
|
2010-11-28 11:20:29 -05:00
|
|
|
r->x, r->y, r->width, r->height);
|
2010-03-27 10:25:51 -04:00
|
|
|
}
|
|
|
|
if (parsing_swallows) {
|
|
|
|
if (strcasecmp(last_key, "id") == 0) {
|
|
|
|
current_swallow->id = val;
|
|
|
|
}
|
2010-08-15 06:18:27 -04:00
|
|
|
if (strcasecmp(last_key, "dock") == 0) {
|
2011-02-20 21:01:55 -05:00
|
|
|
current_swallow->dock = val;
|
|
|
|
}
|
|
|
|
if (strcasecmp(last_key, "insert_where") == 0) {
|
|
|
|
current_swallow->insert_where = val;
|
2010-08-15 06:18:27 -04:00
|
|
|
}
|
2010-03-27 10:25:51 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2011-08-04 16:58:19 -04: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;
|
|
|
|
}
|
|
|
|
|
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-03 21:04:00 -04:00
|
|
|
if (strcasecmp(last_key, "split") == 0)
|
|
|
|
json_node->split = val;
|
|
|
|
|
2012-01-21 13:35:15 -05:00
|
|
|
if (parsing_swallows) {
|
|
|
|
if (strcasecmp(last_key, "restart_mode") == 0)
|
|
|
|
current_swallow->restart_mode = val;
|
|
|
|
}
|
|
|
|
|
2011-08-04 16:58:19 -04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2010-03-27 10:25:51 -04: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;
|
|
|
|
}
|
|
|
|
|
|
|
|
void tree_append_json(const char *filename) {
|
|
|
|
/* TODO: percent of other windows are not correctly fixed at the moment */
|
|
|
|
FILE *f;
|
|
|
|
if ((f = fopen(filename, "r")) == NULL) {
|
|
|
|
LOG("Cannot open file\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
char *buf = malloc(65535); /* TODO */
|
|
|
|
int n = fread(buf, 1, 65535, f);
|
|
|
|
LOG("read %d bytes\n", n);
|
|
|
|
yajl_gen g;
|
|
|
|
yajl_handle hand;
|
|
|
|
yajl_callbacks callbacks;
|
|
|
|
memset(&callbacks, '\0', sizeof(yajl_callbacks));
|
|
|
|
callbacks.yajl_start_map = json_start_map;
|
|
|
|
callbacks.yajl_end_map = json_end_map;
|
|
|
|
callbacks.yajl_end_array = json_end_array;
|
|
|
|
callbacks.yajl_string = json_string;
|
|
|
|
callbacks.yajl_map_key = json_key;
|
|
|
|
callbacks.yajl_integer = json_int;
|
|
|
|
callbacks.yajl_double = json_double;
|
2011-08-04 16:58:19 -04:00
|
|
|
callbacks.yajl_boolean = json_bool;
|
2011-04-27 13:52:53 -04:00
|
|
|
#if YAJL_MAJOR >= 2
|
|
|
|
g = yajl_gen_alloc(NULL);
|
|
|
|
hand = yajl_alloc(&callbacks, NULL, (void*)g);
|
|
|
|
#else
|
2010-03-27 10:25:51 -04:00
|
|
|
g = yajl_gen_alloc(NULL, NULL);
|
|
|
|
hand = yajl_alloc(&callbacks, NULL, NULL, (void*)g);
|
2011-04-27 13:52:53 -04:00
|
|
|
#endif
|
2010-03-27 10:25:51 -04:00
|
|
|
yajl_status stat;
|
|
|
|
json_node = focused;
|
2010-11-28 08:27:44 -05:00
|
|
|
to_focus = NULL;
|
2010-11-28 11:20:29 -05:00
|
|
|
parsing_rect = false;
|
|
|
|
parsing_window_rect = false;
|
2011-02-20 21:01:55 -05:00
|
|
|
parsing_geometry = false;
|
2010-03-27 10:25:51 -04:00
|
|
|
setlocale(LC_NUMERIC, "C");
|
|
|
|
stat = yajl_parse(hand, (const unsigned char*)buf, n);
|
2011-04-27 13:52:53 -04:00
|
|
|
if (stat != yajl_status_ok)
|
2010-03-27 10:25:51 -04:00
|
|
|
{
|
|
|
|
unsigned char * str = yajl_get_error(hand, 1, (const unsigned char*)buf, n);
|
2011-02-01 09:43:59 -05:00
|
|
|
fprintf(stderr, "%s\n", (const char *) str);
|
2010-03-27 10:25:51 -04:00
|
|
|
yajl_free_error(hand, str);
|
|
|
|
}
|
|
|
|
|
|
|
|
setlocale(LC_NUMERIC, "");
|
2011-04-27 13:52:53 -04:00
|
|
|
#if YAJL_MAJOR >= 2
|
|
|
|
yajl_complete_parse(hand);
|
|
|
|
#else
|
2010-03-27 10:25:51 -04:00
|
|
|
yajl_parse_complete(hand);
|
2011-04-27 13:52:53 -04:00
|
|
|
#endif
|
2010-03-27 10:25:51 -04:00
|
|
|
|
|
|
|
fclose(f);
|
2010-11-28 08:27:44 -05:00
|
|
|
if (to_focus)
|
|
|
|
con_focus(to_focus);
|
2010-03-27 10:25:51 -04:00
|
|
|
}
|