diff options
-rw-r--r-- | sway/ipc-json.c | 49 |
1 files changed, 33 insertions, 16 deletions
diff --git a/sway/ipc-json.c b/sway/ipc-json.c index 745d129a..fc65b5f2 100644 --- a/sway/ipc-json.c +++ b/sway/ipc-json.c | |||
@@ -79,9 +79,6 @@ static json_object *ipc_json_create_empty_rect(void) { | |||
79 | 79 | ||
80 | static void ipc_json_describe_root(struct sway_root *root, json_object *object) { | 80 | static void ipc_json_describe_root(struct sway_root *root, json_object *object) { |
81 | json_object_object_add(object, "type", json_object_new_string("root")); | 81 | json_object_object_add(object, "type", json_object_new_string("root")); |
82 | json_object_object_add(object, "layout", json_object_new_string("splith")); | ||
83 | json_object_object_add(object, "orientation", | ||
84 | json_object_new_string(ipc_json_orientation_description(L_HORIZ))); | ||
85 | } | 82 | } |
86 | 83 | ||
87 | static const char *ipc_json_get_output_transform(enum wl_output_transform transform) { | 84 | static const char *ipc_json_get_output_transform(enum wl_output_transform transform) { |
@@ -113,6 +110,8 @@ static void ipc_json_describe_output(struct sway_output *output, | |||
113 | json_object_object_add(object, "active", json_object_new_boolean(true)); | 110 | json_object_object_add(object, "active", json_object_new_boolean(true)); |
114 | json_object_object_add(object, "primary", json_object_new_boolean(false)); | 111 | json_object_object_add(object, "primary", json_object_new_boolean(false)); |
115 | json_object_object_add(object, "layout", json_object_new_string("output")); | 112 | json_object_object_add(object, "layout", json_object_new_string("output")); |
113 | json_object_object_add(object, "orientation", | ||
114 | json_object_new_string(ipc_json_orientation_description(L_NONE))); | ||
116 | json_object_object_add(object, "make", | 115 | json_object_object_add(object, "make", |
117 | json_object_new_string(wlr_output->make)); | 116 | json_object_new_string(wlr_output->make)); |
118 | json_object_object_add(object, "model", | 117 | json_object_object_add(object, "model", |
@@ -145,7 +144,6 @@ static void ipc_json_describe_output(struct sway_output *output, | |||
145 | } | 144 | } |
146 | 145 | ||
147 | json_object_object_add(object, "modes", modes_array); | 146 | json_object_object_add(object, "modes", modes_array); |
148 | json_object_object_add(object, "layout", json_object_new_string("output")); | ||
149 | 147 | ||
150 | struct sway_node *parent = node_get_parent(&output->node); | 148 | struct sway_node *parent = node_get_parent(&output->node); |
151 | struct wlr_box parent_box = {0, 0, 0, 0}; | 149 | struct wlr_box parent_box = {0, 0, 0, 0}; |
@@ -154,10 +152,7 @@ static void ipc_json_describe_output(struct sway_output *output, | |||
154 | node_get_box(parent, &parent_box); | 152 | node_get_box(parent, &parent_box); |
155 | } | 153 | } |
156 | 154 | ||
157 | if (parent_box.width == 0 || parent_box.height == 0) { | 155 | if (parent_box.width != 0 && parent_box.height != 0) { |
158 | json_object_object_add(object, "percent", NULL); | ||
159 | } | ||
160 | else { | ||
161 | double percent = (output->width / parent_box.width) | 156 | double percent = (output->width / parent_box.width) |
162 | * (output->height / parent_box.height); | 157 | * (output->height / parent_box.height); |
163 | json_object_object_add(object, "percent", json_object_new_double(percent)); | 158 | json_object_object_add(object, "percent", json_object_new_double(percent)); |
@@ -261,6 +256,16 @@ static void ipc_json_describe_view(struct sway_container *c, json_object *object | |||
261 | } | 256 | } |
262 | 257 | ||
263 | json_object_object_add(object, "deco_rect", ipc_json_create_rect(&deco_box)); | 258 | json_object_object_add(object, "deco_rect", ipc_json_create_rect(&deco_box)); |
259 | |||
260 | struct wlr_box geometry = {0, 0, c->view->natural_width, c->view->natural_height }; | ||
261 | json_object_object_add(object, "geometry", ipc_json_create_rect(&geometry)); | ||
262 | |||
263 | #ifdef HAVE_XWAYLAND | ||
264 | if (c->view->type == SWAY_VIEW_XWAYLAND) { | ||
265 | json_object_object_add(object, "window", | ||
266 | json_object_new_int(view_get_x11_window_id(c->view))); | ||
267 | } | ||
268 | #endif | ||
264 | } | 269 | } |
265 | 270 | ||
266 | static void ipc_json_describe_container(struct sway_container *c, json_object *object) { | 271 | static void ipc_json_describe_container(struct sway_container *c, json_object *object) { |
@@ -277,6 +282,7 @@ static void ipc_json_describe_container(struct sway_container *c, json_object *o | |||
277 | bool urgent = c->view ? | 282 | bool urgent = c->view ? |
278 | view_is_urgent(c->view) : container_has_urgent_child(c); | 283 | view_is_urgent(c->view) : container_has_urgent_child(c); |
279 | json_object_object_add(object, "urgent", json_object_new_boolean(urgent)); | 284 | json_object_object_add(object, "urgent", json_object_new_boolean(urgent)); |
285 | json_object_object_add(object, "sticky", json_object_new_boolean(c->is_sticky)); | ||
280 | 286 | ||
281 | struct sway_node *parent = node_get_parent(&c->node); | 287 | struct sway_node *parent = node_get_parent(&c->node); |
282 | struct wlr_box parent_box = {0, 0, 0, 0}; | 288 | struct wlr_box parent_box = {0, 0, 0, 0}; |
@@ -285,18 +291,12 @@ static void ipc_json_describe_container(struct sway_container *c, json_object *o | |||
285 | node_get_box(parent, &parent_box); | 291 | node_get_box(parent, &parent_box); |
286 | } | 292 | } |
287 | 293 | ||
288 | if (parent_box.width == 0 || parent_box.height == 0) { | 294 | if (parent_box.width != 0 && parent_box.height != 0) { |
289 | json_object_object_add(object, "percent", NULL); | ||
290 | } | ||
291 | else { | ||
292 | double percent = (c->width / parent_box.width) | 295 | double percent = (c->width / parent_box.width) |
293 | * (c->height / parent_box.height); | 296 | * (c->height / parent_box.height); |
294 | json_object_object_add(object, "percent", json_object_new_double(percent)); | 297 | json_object_object_add(object, "percent", json_object_new_double(percent)); |
295 | } | 298 | } |
296 | 299 | ||
297 | json_object_object_add(object, "window_rect", ipc_json_create_empty_rect()); | ||
298 | json_object_object_add(object, "deco_rect", ipc_json_create_empty_rect()); | ||
299 | |||
300 | json_object_object_add(object, "border", | 300 | json_object_object_add(object, "border", |
301 | json_object_new_string(describe_container_border(c->current.border))); | 301 | json_object_new_string(describe_container_border(c->current.border))); |
302 | json_object_object_add(object, "current_border_width", | 302 | json_object_object_add(object, "current_border_width", |
@@ -344,6 +344,23 @@ json_object *ipc_json_describe_node(struct sway_node *node) { | |||
344 | seat_for_each_node(seat, focus_inactive_children_iterator, &data); | 344 | seat_for_each_node(seat, focus_inactive_children_iterator, &data); |
345 | json_object_object_add(object, "focus", focus); | 345 | json_object_object_add(object, "focus", focus); |
346 | 346 | ||
347 | // set default values to be compatible with i3 | ||
348 | json_object_object_add(object, "border", | ||
349 | json_object_new_string(describe_container_border(B_NONE))); | ||
350 | json_object_object_add(object, "current_border_width", json_object_new_int(0)); | ||
351 | json_object_object_add(object, "layout", | ||
352 | json_object_new_string(ipc_json_layout_description(L_HORIZ))); | ||
353 | json_object_object_add(object, "orientation", | ||
354 | json_object_new_string(ipc_json_orientation_description(L_HORIZ))); | ||
355 | json_object_object_add(object, "percent", NULL); | ||
356 | json_object_object_add(object, "window_rect", ipc_json_create_empty_rect()); | ||
357 | json_object_object_add(object, "deco_rect", ipc_json_create_empty_rect()); | ||
358 | json_object_object_add(object, "geometry", ipc_json_create_empty_rect()); | ||
359 | json_object_object_add(object, "window", NULL); | ||
360 | json_object_object_add(object, "urgent", json_object_new_boolean(false)); | ||
361 | json_object_object_add(object, "floating_nodes", json_object_new_array()); | ||
362 | json_object_object_add(object, "sticky", json_object_new_boolean(false)); | ||
363 | |||
347 | switch (node->type) { | 364 | switch (node->type) { |
348 | case N_ROOT: | 365 | case N_ROOT: |
349 | ipc_json_describe_root(root, object); | 366 | ipc_json_describe_root(root, object); |
@@ -352,7 +369,7 @@ json_object *ipc_json_describe_node(struct sway_node *node) { | |||
352 | ipc_json_describe_output(node->sway_output, object); | 369 | ipc_json_describe_output(node->sway_output, object); |
353 | break; | 370 | break; |
354 | case N_CONTAINER: | 371 | case N_CONTAINER: |
355 | ipc_json_describe_view(node->sway_container, object); | 372 | ipc_json_describe_container(node->sway_container, object); |
356 | break; | 373 | break; |
357 | case N_WORKSPACE: | 374 | case N_WORKSPACE: |
358 | ipc_json_describe_workspace(node->sway_workspace, object); | 375 | ipc_json_describe_workspace(node->sway_workspace, object); |