From 7d947fdb952c07c5dce5a0ae6b602f02cb274736 Mon Sep 17 00:00:00 2001 From: Zandr Martin Date: Wed, 21 Sep 2016 21:05:09 -0500 Subject: [PATCH] add unique IDs to containers --- include/sway/container.h | 7 +++++++ sway/container.c | 4 ++++ sway/ipc-json.c | 3 +-- sway/layout.c | 1 + 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/include/sway/container.h b/include/sway/container.h index 215c0b07..67b747a0 100644 --- a/include/sway/container.h +++ b/include/sway/container.h @@ -2,6 +2,7 @@ #define _SWAY_CONTAINER_H #include #include +#include #include "list.h" @@ -58,6 +59,12 @@ struct sway_container { */ wlc_handle handle; + /** + * A unique ID to identify this container. Primarily used in the + * get_tree JSON output. + */ + size_t id; + enum swayc_types type; enum swayc_layouts layout; enum swayc_layouts prev_layout; diff --git a/sway/container.c b/sway/container.c index 561dcba6..73b627ec 100644 --- a/sway/container.c +++ b/sway/container.c @@ -18,8 +18,12 @@ #define ASSERT_NONNULL(PTR) \ sway_assert (PTR, #PTR "must be non-null") + static swayc_t *new_swayc(enum swayc_types type) { + // next id starts at 1 because 0 is assigned to root_container in layout.c + static size_t next_id = 1; swayc_t *c = calloc(1, sizeof(swayc_t)); + c->id = next_id++; c->handle = -1; c->gaps = -1; c->layout = L_NONE; diff --git a/sway/ipc-json.c b/sway/ipc-json.c index 1ca7f9ce..e08b3c60 100644 --- a/sway/ipc-json.c +++ b/sway/ipc-json.c @@ -161,7 +161,6 @@ static void ipc_json_describe_view(swayc_t *c, json_object *object) { ipc_json_layout_description(c->parent->prev_layout) : "none"; wlc_handle parent = wlc_view_get_parent(c->handle); - json_object_object_add(object, "id", json_object_new_int(c->handle)); json_object_object_add(object, "type", json_object_new_string((c->is_floating) ? "floating_con" : "con")); json_object_object_add(object, "scratchpad_state", @@ -211,7 +210,7 @@ json_object *ipc_json_describe_container(swayc_t *c) { json_object *object = json_object_new_object(); - json_object_object_add(object, "id", json_object_new_int((uintptr_t)&c)); + json_object_object_add(object, "id", json_object_new_int((int)c->id)); json_object_object_add(object, "name", (c->name) ? json_object_new_string(c->name) : NULL); json_object_object_add(object, "rect", ipc_json_create_rect(c)); json_object_object_add(object, "visible", json_object_new_boolean(c->visible)); diff --git a/sway/layout.c b/sway/layout.c index 7802c412..6012af66 100644 --- a/sway/layout.c +++ b/sway/layout.c @@ -22,6 +22,7 @@ int min_sane_h = 60; int min_sane_w = 100; void init_layout(void) { + root_container.id = 0; // normally assigned in new_swayc() root_container.type = C_ROOT; root_container.layout = L_NONE; root_container.name = strdup("root");