aboutsummaryrefslogtreecommitdiff
path: root/sway/ipc-json.c
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2016-07-05 08:32:10 -0400
committerGitHub <noreply@github.com>2016-07-05 08:32:10 -0400
commit840b0c1bcde11631539bfe538d4897162e4b5d37 (patch)
tree5f0ca86e9b495f01b9a983049332d0b47fe9ea82 /sway/ipc-json.c
parent58804a044f782a397302173deb1416e47b3c3357 (diff)
parentc65d6e6e95ec379c358e5c8705cc95cf563809d0 (diff)
Merge pull request #740 from zandrmartin/json-fixes
get_tree json fixes
Diffstat (limited to 'sway/ipc-json.c')
-rw-r--r--sway/ipc-json.c50
1 files changed, 27 insertions, 23 deletions
diff --git a/sway/ipc-json.c b/sway/ipc-json.c
index 69412023..7edc30f7 100644
--- a/sway/ipc-json.c
+++ b/sway/ipc-json.c
@@ -110,27 +110,28 @@ static void ipc_json_describe_output(swayc_t *output, json_object *object) {
static void ipc_json_describe_workspace(swayc_t *workspace, json_object *object) {
int num = (isdigit(workspace->name[0])) ? atoi(workspace->name) : -1;
bool focused = root_container.focused == workspace->parent && workspace->parent->focused == workspace;
+ const char *layout = ipc_json_layout_description(workspace);
json_object_object_add(object, "num", json_object_new_int(num));
- json_object_object_add(object, "visible", json_object_new_boolean(workspace->visible));
json_object_object_add(object, "focused", json_object_new_boolean(focused));
- json_object_object_add(object, "output", json_object_new_string((workspace->parent) ? workspace->parent->name : "null"));
+ json_object_object_add(object, "output", (workspace->parent) ? json_object_new_string(workspace->parent->name) : NULL);
json_object_object_add(object, "urgent", json_object_new_boolean(false));
json_object_object_add(object, "type", json_object_new_string("workspace"));
- json_object_object_add(object, "layout", json_object_new_string(ipc_json_layout_description(workspace)));
+ json_object_object_add(object, "layout", (strcmp(layout, "null") == 0) ? NULL : json_object_new_string(layout));
}
static void ipc_json_describe_view(swayc_t *view, json_object *object) {
float percent = ipc_json_child_percentage(view);
+ const char *layout = ipc_json_layout_description(view);
json_object_object_add(object, "border", json_object_new_string(ipc_json_border_description(view)));
json_object_object_add(object, "current_border_width", json_object_new_int(view->border_thickness));
- json_object_object_add(object, "percent", (percent > 0) ? json_object_new_double(percent) : json_object_new_string("null"));
+ json_object_object_add(object, "percent", (percent > 0) ? json_object_new_double(percent) : NULL);
// TODO: make urgency actually work once Sway supports it
json_object_object_add(object, "urgent", json_object_new_boolean(false));
json_object_object_add(object, "focused", json_object_new_boolean(view->is_focused));
json_object_object_add(object, "type", json_object_new_string((view->is_floating) ? "floating_con" : "con"));
- json_object_object_add(object, "layout", json_object_new_string(ipc_json_layout_description(view)));
+ json_object_object_add(object, "layout", (strcmp(layout, "null") == 0) ? NULL : json_object_new_string(layout));
if (view->class) {
json_object_object_add(object, "class", json_object_new_string(view->class));
@@ -149,8 +150,9 @@ 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((int64_t)&c));
- json_object_object_add(object, "name", json_object_new_string(c->name));
+ 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));
switch (c->type) {
case C_ROOT:
@@ -288,29 +290,31 @@ json_object *ipc_json_describe_container_recursive(swayc_t *c) {
json_object *object = ipc_json_describe_container(c);
int i;
- json_object *floating = json_object_new_array();
- if (c->floating && c->floating->length > 0) {
- for (i = 0; i < c->floating->length; ++i) {
- json_object_array_add(floating, ipc_json_describe_container_recursive(c->floating->items[i]));
+ if (c->type != C_VIEW) {
+ json_object *floating = json_object_new_array();
+ if (c->floating && c->floating->length > 0) {
+ for (i = 0; i < c->floating->length; ++i) {
+ json_object_array_add(floating, ipc_json_describe_container_recursive(c->floating->items[i]));
+ }
}
- }
- json_object_object_add(object, "floating_nodes", floating);
+ json_object_object_add(object, "floating_nodes", floating);
- json_object *children = json_object_new_array();
- if (c->children && c->children->length > 0) {
- for (i = 0; i < c->children->length; ++i) {
- json_object_array_add(children, ipc_json_describe_container_recursive(c->children->items[i]));
+ json_object *children = json_object_new_array();
+ if (c->children && c->children->length > 0) {
+ 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_object_add(object, "nodes", children);
- json_object *unmanaged = json_object_new_array();
- if (c->unmanaged && c->unmanaged->length > 0) {
- for (i = 0; i < c->unmanaged->length; ++i) {
- json_object_array_add(unmanaged, ipc_json_describe_container_recursive(c->unmanaged->items[i]));
+ json_object *unmanaged = json_object_new_array();
+ if (c->unmanaged && c->unmanaged->length > 0) {
+ for (i = 0; i < c->unmanaged->length; ++i) {
+ json_object_array_add(unmanaged, ipc_json_describe_container_recursive(c->unmanaged->items[i]));
+ }
}
+ json_object_object_add(object, "unmanaged_nodes", unmanaged);
}
- json_object_object_add(object, "unmanaged_nodes", unmanaged);
if (c->type == C_ROOT) {
json_object *scratchpad_json = json_object_new_array();