summaryrefslogtreecommitdiffstats
path: root/sway
diff options
context:
space:
mode:
authorLibravatar Zandr Martin <zandrmartin@gmail.com>2016-07-05 07:23:44 -0500
committerLibravatar Zandr Martin <zandrmartin@gmail.com>2016-07-05 07:23:44 -0500
commitc65d6e6e95ec379c358e5c8705cc95cf563809d0 (patch)
tree5f0ca86e9b495f01b9a983049332d0b47fe9ea82 /sway
parentMerge pull request #738 from deklov/panel-as-shell-02 (diff)
downloadsway-c65d6e6e95ec379c358e5c8705cc95cf563809d0.tar.gz
sway-c65d6e6e95ec379c358e5c8705cc95cf563809d0.tar.zst
sway-c65d6e6e95ec379c358e5c8705cc95cf563809d0.zip
get_tree json fixes
- null pointer check against container names - use actual json null values instead of "null" strings - add "visible" property to all containers
Diffstat (limited to 'sway')
-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) {
110static void ipc_json_describe_workspace(swayc_t *workspace, json_object *object) { 110static void ipc_json_describe_workspace(swayc_t *workspace, json_object *object) {
111 int num = (isdigit(workspace->name[0])) ? atoi(workspace->name) : -1; 111 int num = (isdigit(workspace->name[0])) ? atoi(workspace->name) : -1;
112 bool focused = root_container.focused == workspace->parent && workspace->parent->focused == workspace; 112 bool focused = root_container.focused == workspace->parent && workspace->parent->focused == workspace;
113 const char *layout = ipc_json_layout_description(workspace);
113 114
114 json_object_object_add(object, "num", json_object_new_int(num)); 115 json_object_object_add(object, "num", json_object_new_int(num));
115 json_object_object_add(object, "visible", json_object_new_boolean(workspace->visible));
116 json_object_object_add(object, "focused", json_object_new_boolean(focused)); 116 json_object_object_add(object, "focused", json_object_new_boolean(focused));
117 json_object_object_add(object, "output", json_object_new_string((workspace->parent) ? workspace->parent->name : "null")); 117 json_object_object_add(object, "output", (workspace->parent) ? json_object_new_string(workspace->parent->name) : NULL);
118 json_object_object_add(object, "urgent", json_object_new_boolean(false)); 118 json_object_object_add(object, "urgent", json_object_new_boolean(false));
119 json_object_object_add(object, "type", json_object_new_string("workspace")); 119 json_object_object_add(object, "type", json_object_new_string("workspace"));
120 json_object_object_add(object, "layout", json_object_new_string(ipc_json_layout_description(workspace))); 120 json_object_object_add(object, "layout", (strcmp(layout, "null") == 0) ? NULL : json_object_new_string(layout));
121} 121}
122 122
123static void ipc_json_describe_view(swayc_t *view, json_object *object) { 123static void ipc_json_describe_view(swayc_t *view, json_object *object) {
124 float percent = ipc_json_child_percentage(view); 124 float percent = ipc_json_child_percentage(view);
125 const char *layout = ipc_json_layout_description(view);
125 126
126 json_object_object_add(object, "border", json_object_new_string(ipc_json_border_description(view))); 127 json_object_object_add(object, "border", json_object_new_string(ipc_json_border_description(view)));
127 json_object_object_add(object, "current_border_width", json_object_new_int(view->border_thickness)); 128 json_object_object_add(object, "current_border_width", json_object_new_int(view->border_thickness));
128 json_object_object_add(object, "percent", (percent > 0) ? json_object_new_double(percent) : json_object_new_string("null")); 129 json_object_object_add(object, "percent", (percent > 0) ? json_object_new_double(percent) : NULL);
129 // TODO: make urgency actually work once Sway supports it 130 // TODO: make urgency actually work once Sway supports it
130 json_object_object_add(object, "urgent", json_object_new_boolean(false)); 131 json_object_object_add(object, "urgent", json_object_new_boolean(false));
131 json_object_object_add(object, "focused", json_object_new_boolean(view->is_focused)); 132 json_object_object_add(object, "focused", json_object_new_boolean(view->is_focused));
132 json_object_object_add(object, "type", json_object_new_string((view->is_floating) ? "floating_con" : "con")); 133 json_object_object_add(object, "type", json_object_new_string((view->is_floating) ? "floating_con" : "con"));
133 json_object_object_add(object, "layout", json_object_new_string(ipc_json_layout_description(view))); 134 json_object_object_add(object, "layout", (strcmp(layout, "null") == 0) ? NULL : json_object_new_string(layout));
134 135
135 if (view->class) { 136 if (view->class) {
136 json_object_object_add(object, "class", json_object_new_string(view->class)); 137 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) {
149 json_object *object = json_object_new_object(); 150 json_object *object = json_object_new_object();
150 151
151 json_object_object_add(object, "id", json_object_new_int((int64_t)&c)); 152 json_object_object_add(object, "id", json_object_new_int((int64_t)&c));
152 json_object_object_add(object, "name", json_object_new_string(c->name)); 153 json_object_object_add(object, "name", (c->name) ? json_object_new_string(c->name) : NULL);
153 json_object_object_add(object, "rect", ipc_json_create_rect(c)); 154 json_object_object_add(object, "rect", ipc_json_create_rect(c));
155 json_object_object_add(object, "visible", json_object_new_boolean(c->visible));
154 156
155 switch (c->type) { 157 switch (c->type) {
156 case C_ROOT: 158 case C_ROOT:
@@ -288,29 +290,31 @@ json_object *ipc_json_describe_container_recursive(swayc_t *c) {
288 json_object *object = ipc_json_describe_container(c); 290 json_object *object = ipc_json_describe_container(c);
289 int i; 291 int i;
290 292
291 json_object *floating = json_object_new_array(); 293 if (c->type != C_VIEW) {
292 if (c->floating && c->floating->length > 0) { 294 json_object *floating = json_object_new_array();
293 for (i = 0; i < c->floating->length; ++i) { 295 if (c->floating && c->floating->length > 0) {
294 json_object_array_add(floating, ipc_json_describe_container_recursive(c->floating->items[i])); 296 for (i = 0; i < c->floating->length; ++i) {
297 json_object_array_add(floating, ipc_json_describe_container_recursive(c->floating->items[i]));
298 }
295 } 299 }
296 } 300 json_object_object_add(object, "floating_nodes", floating);
297 json_object_object_add(object, "floating_nodes", floating);
298 301
299 json_object *children = json_object_new_array(); 302 json_object *children = json_object_new_array();
300 if (c->children && c->children->length > 0) { 303 if (c->children && c->children->length > 0) {
301 for (i = 0; i < c->children->length; ++i) { 304 for (i = 0; i < c->children->length; ++i) {
302 json_object_array_add(children, ipc_json_describe_container_recursive(c->children->items[i])); 305 json_object_array_add(children, ipc_json_describe_container_recursive(c->children->items[i]));
306 }
303 } 307 }
304 } 308 json_object_object_add(object, "nodes", children);
305 json_object_object_add(object, "nodes", children);
306 309
307 json_object *unmanaged = json_object_new_array(); 310 json_object *unmanaged = json_object_new_array();
308 if (c->unmanaged && c->unmanaged->length > 0) { 311 if (c->unmanaged && c->unmanaged->length > 0) {
309 for (i = 0; i < c->unmanaged->length; ++i) { 312 for (i = 0; i < c->unmanaged->length; ++i) {
310 json_object_array_add(unmanaged, ipc_json_describe_container_recursive(c->unmanaged->items[i])); 313 json_object_array_add(unmanaged, ipc_json_describe_container_recursive(c->unmanaged->items[i]));
314 }
311 } 315 }
316 json_object_object_add(object, "unmanaged_nodes", unmanaged);
312 } 317 }
313 json_object_object_add(object, "unmanaged_nodes", unmanaged);
314 318
315 if (c->type == C_ROOT) { 319 if (c->type == C_ROOT) {
316 json_object *scratchpad_json = json_object_new_array(); 320 json_object *scratchpad_json = json_object_new_array();