summaryrefslogtreecommitdiffstats
path: root/sway/ipc-json.c
diff options
context:
space:
mode:
Diffstat (limited to 'sway/ipc-json.c')
-rw-r--r--sway/ipc-json.c68
1 files changed, 50 insertions, 18 deletions
diff --git a/sway/ipc-json.c b/sway/ipc-json.c
index 31de53f0..94768aa4 100644
--- a/sway/ipc-json.c
+++ b/sway/ipc-json.c
@@ -138,7 +138,6 @@ static void ipc_json_describe_workspace(swayc_t *workspace, json_object *object)
138 138
139 json_object_object_add(object, "num", json_object_new_int(num)); 139 json_object_object_add(object, "num", json_object_new_int(num));
140 json_object_object_add(object, "output", (workspace->parent) ? json_object_new_string(workspace->parent->name) : NULL); 140 json_object_object_add(object, "output", (workspace->parent) ? json_object_new_string(workspace->parent->name) : NULL);
141 json_object_object_add(object, "urgent", json_object_new_boolean(false));
142 json_object_object_add(object, "type", json_object_new_string("workspace")); 141 json_object_object_add(object, "type", json_object_new_string("workspace"));
143 json_object_object_add(object, "layout", (strcmp(layout, "null") == 0) ? NULL : json_object_new_string(layout)); 142 json_object_object_add(object, "layout", (strcmp(layout, "null") == 0) ? NULL : json_object_new_string(layout));
144} 143}
@@ -156,7 +155,6 @@ static const char *ipc_json_get_scratchpad_state(swayc_t *c) {
156 155
157static void ipc_json_describe_view(swayc_t *c, json_object *object) { 156static void ipc_json_describe_view(swayc_t *c, json_object *object) {
158 json_object *props = json_object_new_object(); 157 json_object *props = json_object_new_object();
159 float percent = ipc_json_child_percentage(c);
160 const char *layout = (c->parent->type == C_CONTAINER) ? 158 const char *layout = (c->parent->type == C_CONTAINER) ?
161 ipc_json_layout_description(c->parent->layout) : "none"; 159 ipc_json_layout_description(c->parent->layout) : "none";
162 const char *last_layout = (c->parent->type == C_CONTAINER) ? 160 const char *last_layout = (c->parent->type == C_CONTAINER) ?
@@ -167,9 +165,6 @@ static void ipc_json_describe_view(swayc_t *c, json_object *object) {
167 165
168 json_object_object_add(object, "scratchpad_state", 166 json_object_object_add(object, "scratchpad_state",
169 json_object_new_string(ipc_json_get_scratchpad_state(c))); 167 json_object_new_string(ipc_json_get_scratchpad_state(c)));
170 json_object_object_add(object, "percent", (percent > 0) ? json_object_new_double(percent) : NULL);
171 // TODO: make urgency actually work once Sway supports it
172 json_object_object_add(object, "urgent", json_object_new_boolean(false));
173 json_object_object_add(object, "layout", 168 json_object_object_add(object, "layout",
174 (strcmp(layout, "null") == 0) ? NULL : json_object_new_string(layout)); 169 (strcmp(layout, "null") == 0) ? NULL : json_object_new_string(layout));
175 json_object_object_add(object, "last_split_layout", 170 json_object_object_add(object, "last_split_layout",
@@ -177,17 +172,8 @@ static void ipc_json_describe_view(swayc_t *c, json_object *object) {
177 json_object_object_add(object, "workspace_layout", 172 json_object_object_add(object, "workspace_layout",
178 json_object_new_string(ipc_json_layout_description(swayc_parent_by_type(c, C_WORKSPACE)->workspace_layout))); 173 json_object_new_string(ipc_json_layout_description(swayc_parent_by_type(c, C_WORKSPACE)->workspace_layout)));
179 174
180 json_object_object_add(object, "border", json_object_new_string(ipc_json_border_description(c)));
181 json_object_object_add(object, "current_border_width", json_object_new_int(c->border_thickness));
182
183 json_object_object_add(object, "rect", ipc_json_create_rect(c));
184 json_object_object_add(object, "deco_rect", ipc_json_create_rect_from_geometry(c->title_bar_geometry));
185 json_object_object_add(object, "geometry", ipc_json_create_rect_from_geometry(c->cached_geometry));
186 json_object_object_add(object, "window_rect", ipc_json_create_rect_from_geometry(c->actual_geometry));
187
188 json_object_object_add(object, "name", (c->name) ? json_object_new_string(c->name) : NULL); 175 json_object_object_add(object, "name", (c->name) ? json_object_new_string(c->name) : NULL);
189 176
190 json_object_object_add(object, "window", json_object_new_int(c->handle)); // for the sake of i3 compat
191 json_object_object_add(props, "class", c->class ? json_object_new_string(c->class) : 177 json_object_object_add(props, "class", c->class ? json_object_new_string(c->class) :
192 c->app_id ? json_object_new_string(c->app_id) : NULL); 178 c->app_id ? json_object_new_string(c->app_id) : NULL);
193 json_object_object_add(props, "instance", c->instance ? json_object_new_string(c->instance) : 179 json_object_object_add(props, "instance", c->instance ? json_object_new_string(c->instance) :
@@ -205,7 +191,14 @@ static void ipc_json_describe_view(swayc_t *c, json_object *object) {
205 json_object_object_add(object, "app_id", c->app_id ? json_object_new_string(c->app_id) : NULL); 191 json_object_object_add(object, "app_id", c->app_id ? json_object_new_string(c->app_id) : NULL);
206} 192}
207 193
194static void ipc_json_describe_root(swayc_t *c, json_object *object) {
195 json_object_object_add(object, "type", json_object_new_string("root"));
196 json_object_object_add(object, "layout", json_object_new_string("splith"));
197}
198
208json_object *ipc_json_describe_container(swayc_t *c) { 199json_object *ipc_json_describe_container(swayc_t *c) {
200 float percent = ipc_json_child_percentage(c);
201
209 if (!(sway_assert(c, "Container must not be null."))) { 202 if (!(sway_assert(c, "Container must not be null."))) {
210 return NULL; 203 return NULL;
211 } 204 }
@@ -218,9 +211,19 @@ json_object *ipc_json_describe_container(swayc_t *c) {
218 json_object_object_add(object, "visible", json_object_new_boolean(c->visible)); 211 json_object_object_add(object, "visible", json_object_new_boolean(c->visible));
219 json_object_object_add(object, "focused", json_object_new_boolean(c == current_focus)); 212 json_object_object_add(object, "focused", json_object_new_boolean(c == current_focus));
220 213
214 json_object_object_add(object, "border", json_object_new_string(ipc_json_border_description(c)));
215 json_object_object_add(object, "window_rect", ipc_json_create_rect_from_geometry(c->actual_geometry));
216 json_object_object_add(object, "deco_rect", ipc_json_create_rect_from_geometry(c->title_bar_geometry));
217 json_object_object_add(object, "geometry", ipc_json_create_rect_from_geometry(c->cached_geometry));
218 json_object_object_add(object, "percent", (percent > 0) ? json_object_new_double(percent) : NULL);
219 json_object_object_add(object, "window", json_object_new_int(c->handle)); // for the sake of i3 compat
220 // TODO: make urgency actually work once Sway supports it
221 json_object_object_add(object, "urgent", json_object_new_boolean(false));
222 json_object_object_add(object, "current_border_width", json_object_new_int(c->border_thickness));
223
221 switch (c->type) { 224 switch (c->type) {
222 case C_ROOT: 225 case C_ROOT:
223 json_object_object_add(object, "type", json_object_new_string("root")); 226 ipc_json_describe_root(c, object);
224 break; 227 break;
225 228
226 case C_OUTPUT: 229 case C_OUTPUT:
@@ -451,21 +454,50 @@ json_object *ipc_json_describe_container_recursive(swayc_t *c) {
451 int i; 454 int i;
452 455
453 json_object *floating = json_object_new_array(); 456 json_object *floating = json_object_new_array();
454 if (c->type != C_VIEW && c->floating && c->floating->length > 0) { 457 if (c->type != C_VIEW && c->floating) {
455 for (i = 0; i < c->floating->length; ++i) { 458 for (i = 0; i < c->floating->length; ++i) {
456 json_object_array_add(floating, ipc_json_describe_container_recursive(c->floating->items[i])); 459 swayc_t *item = c->floating->items[i];
460 json_object_array_add(floating, ipc_json_describe_container_recursive(item));
457 } 461 }
458 } 462 }
459 json_object_object_add(object, "floating_nodes", floating); 463 json_object_object_add(object, "floating_nodes", floating);
460 464
461 json_object *children = json_object_new_array(); 465 json_object *children = json_object_new_array();
462 if (c->type != C_VIEW && c->children && c->children->length > 0) { 466 if (c->type != C_VIEW && c->children) {
463 for (i = 0; i < c->children->length; ++i) { 467 for (i = 0; i < c->children->length; ++i) {
464 json_object_array_add(children, ipc_json_describe_container_recursive(c->children->items[i])); 468 json_object_array_add(children, ipc_json_describe_container_recursive(c->children->items[i]));
465 } 469 }
466 } 470 }
467 json_object_object_add(object, "nodes", children); 471 json_object_object_add(object, "nodes", children);
468 472
473 json_object *focus = json_object_new_array();
474 if (c->type != C_VIEW) {
475 if (c->focused) {
476 json_object_array_add(focus, json_object_new_double(c->focused->id));
477 }
478 if (c->floating) {
479 for (i = 0; i < c->floating->length; ++i) {
480 swayc_t *item = c->floating->items[i];
481 if (item == c->focused) {
482 continue;
483 }
484
485 json_object_array_add(focus, json_object_new_double(item->id));
486 }
487 }
488 if (c->children) {
489 for (i = 0; i < c->children->length; ++i) {
490 swayc_t *item = c->children->items[i];
491 if (item == c->focused) {
492 continue;
493 }
494
495 json_object_array_add(focus, json_object_new_double(item->id));
496 }
497 }
498 }
499 json_object_object_add(object, "focus", focus);
500
469 if (c->type == C_ROOT) { 501 if (c->type == C_ROOT) {
470 json_object *scratchpad_json = json_object_new_array(); 502 json_object *scratchpad_json = json_object_new_array();
471 if (scratchpad->length > 0) { 503 if (scratchpad->length > 0) {