Also store/load window_rect when restarting

This commit is contained in:
Michael Stapelberg 2010-11-28 17:20:29 +01:00
parent 871da48b56
commit 4f1260ffe8
2 changed files with 32 additions and 20 deletions

View File

@ -155,6 +155,20 @@ IPC_HANDLER(command) {
I3_IPC_REPLY_TYPE_COMMAND, strlen(reply));
}
static void dump_rect(yajl_gen gen, const char *name, Rect r) {
ystr(name);
y(map_open);
ystr("x");
y(integer, r.x);
ystr("y");
y(integer, r.y);
ystr("width");
y(integer, r.width);
ystr("height");
y(integer, r.height);
y(map_close);
}
void dump_node(yajl_gen gen, struct Con *con, bool inplace_restart) {
y(map_open);
ystr("id");
@ -178,17 +192,8 @@ void dump_node(yajl_gen gen, struct Con *con, bool inplace_restart) {
ystr("border");
y(integer, con->border_style);
ystr("rect");
y(map_open);
ystr("x");
y(integer, con->rect.x);
ystr("y");
y(integer, con->rect.y);
ystr("width");
y(integer, con->rect.width);
ystr("height");
y(integer, con->rect.height);
y(map_close);
dump_rect(gen, "rect", con->rect);
dump_rect(gen, "window_rect", con->window_rect);
ystr("name");
ystr(con->name);

View File

@ -15,6 +15,7 @@ static Con *json_node;
static Con *to_focus;
static bool parsing_swallows;
static bool parsing_rect;
static bool parsing_window_rect;
struct Match *current_swallow;
static int json_start_map(void *ctx) {
@ -25,7 +26,7 @@ static int json_start_map(void *ctx) {
match_init(current_swallow);
TAILQ_INSERT_TAIL(&(json_node->swallow_head), current_swallow, matches);
} else {
if (!parsing_rect)
if (!parsing_rect && !parsing_window_rect)
json_node = con_new(json_node);
}
return 1;
@ -33,10 +34,12 @@ static int json_start_map(void *ctx) {
static int json_end_map(void *ctx) {
LOG("end of map\n");
if (!parsing_swallows && !parsing_rect)
if (!parsing_swallows && !parsing_rect && !parsing_window_rect)
json_node = json_node->parent;
if (parsing_rect)
parsing_rect = false;
if (parsing_window_rect)
parsing_window_rect = false;
return 1;
}
@ -56,6 +59,8 @@ static int json_key(void *ctx, const unsigned char *val, unsigned int len) {
}
if (strcasecmp(last_key, "rect") == 0)
parsing_rect = true;
if (strcasecmp(last_key, "window_rect") == 0)
parsing_window_rect = true;
return 1;
}
@ -99,19 +104,19 @@ static int json_int(void *ctx, long val) {
to_focus = json_node;
}
if (parsing_rect) {
if (parsing_rect || parsing_window_rect) {
Rect *r = (parsing_rect ? &(json_node->rect) : &(json_node->window_rect));
if (strcasecmp(last_key, "x") == 0)
json_node->rect.x = val;
r->x = val;
else if (strcasecmp(last_key, "y") == 0)
json_node->rect.y = val;
r->y = val;
else if (strcasecmp(last_key, "width") == 0)
json_node->rect.width = val;
r->width = val;
else if (strcasecmp(last_key, "height") == 0)
json_node->rect.height = val;
r->height = val;
else printf("WARNING: unknown key %s in rect\n", last_key);
printf("rect now: (%d, %d, %d, %d)\n",
json_node->rect.x, json_node->rect.y,
json_node->rect.width, json_node->rect.height);
r->x, r->y, r->width, r->height);
}
if (parsing_swallows) {
if (strcasecmp(last_key, "id") == 0) {
@ -159,6 +164,8 @@ void tree_append_json(const char *filename) {
yajl_status stat;
json_node = focused;
to_focus = NULL;
parsing_rect = false;
parsing_window_rect = false;
setlocale(LC_NUMERIC, "C");
stat = yajl_parse(hand, (const unsigned char*)buf, n);
if (stat != yajl_status_ok &&