From fd7c4bacbda311a8966a7f273dec16ce0ca45205 Mon Sep 17 00:00:00 2001 From: lbonn Date: Sun, 8 Oct 2017 00:00:53 +0200 Subject: [PATCH] ipc/tree: populate `focus` fields Ids of children, by order of focus --- sway/ipc-json.c | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/sway/ipc-json.c b/sway/ipc-json.c index 775fcc24..94768aa4 100644 --- a/sway/ipc-json.c +++ b/sway/ipc-json.c @@ -454,21 +454,50 @@ json_object *ipc_json_describe_container_recursive(swayc_t *c) { int i; json_object *floating = json_object_new_array(); - if (c->type != C_VIEW && c->floating && c->floating->length > 0) { + if (c->type != C_VIEW && c->floating) { for (i = 0; i < c->floating->length; ++i) { - json_object_array_add(floating, ipc_json_describe_container_recursive(c->floating->items[i])); + swayc_t *item = c->floating->items[i]; + json_object_array_add(floating, ipc_json_describe_container_recursive(item)); } } json_object_object_add(object, "floating_nodes", floating); json_object *children = json_object_new_array(); - if (c->type != C_VIEW && c->children && c->children->length > 0) { + if (c->type != C_VIEW && c->children) { for (i = 0; i < c->children->length; ++i) { json_object_array_add(children, ipc_json_describe_container_recursive(c->children->items[i])); } } json_object_object_add(object, "nodes", children); + json_object *focus = json_object_new_array(); + if (c->type != C_VIEW) { + if (c->focused) { + json_object_array_add(focus, json_object_new_double(c->focused->id)); + } + if (c->floating) { + for (i = 0; i < c->floating->length; ++i) { + swayc_t *item = c->floating->items[i]; + if (item == c->focused) { + continue; + } + + json_object_array_add(focus, json_object_new_double(item->id)); + } + } + if (c->children) { + for (i = 0; i < c->children->length; ++i) { + swayc_t *item = c->children->items[i]; + if (item == c->focused) { + continue; + } + + json_object_array_add(focus, json_object_new_double(item->id)); + } + } + } + json_object_object_add(object, "focus", focus); + if (c->type == C_ROOT) { json_object *scratchpad_json = json_object_new_array(); if (scratchpad->length > 0) {