GET_TREE: serialize container type into a string

So far, this was blessed for internal use only (by virtue of not being
in the documentation), but we want to expose it for the stored layouts.
This commit is contained in:
Michael Stapelberg
2013-12-14 14:50:44 +01:00
parent 58297f4ab5
commit 6800524f2e
11 changed files with 69 additions and 24 deletions

View File

@ -153,7 +153,30 @@ void dump_node(yajl_gen gen, struct Con *con, bool inplace_restart) {
y(integer, (long int)con);
ystr("type");
y(integer, con->type);
switch (con->type) {
case CT_ROOT:
ystr("root");
break;
case CT_OUTPUT:
ystr("output");
break;
case CT_CON:
ystr("con");
break;
case CT_FLOATING_CON:
ystr("floating_con");
break;
case CT_WORKSPACE:
ystr("workspace");
break;
case CT_DOCKAREA:
ystr("dockarea");
break;
default:
DLOG("About to dump unknown container type=%d. This is a bug.\n", con->type);
assert(false);
break;
}
/* provided for backwards compatibility only. */
ystr("orientation");

View File

@ -203,6 +203,23 @@ static int json_string(void *ctx, const unsigned char *val, unsigned int len) {
json_node->border_style = BS_NORMAL;
else LOG("Unhandled \"border\": %s\n", buf);
free(buf);
} 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;
else LOG("Unhandled \"type\": %s\n", buf);
free(buf);
} else if (strcasecmp(last_key, "layout") == 0) {
char *buf = NULL;
sasprintf(&buf, "%.*s", (int)len, val);
@ -281,6 +298,7 @@ static int json_int(void *ctx, long long val) {
static int json_int(void *ctx, long val) {
LOG("int %ld for key %s\n", val, last_key);
#endif
/* For backwards compatibility with i3 < 4.8 */
if (strcasecmp(last_key, "type") == 0)
json_node->type = val;