diff options
-rw-r--r-- | sway/ipc-json.c | 72 |
1 files changed, 39 insertions, 33 deletions
diff --git a/sway/ipc-json.c b/sway/ipc-json.c index fceee84d..cfc6dfcf 100644 --- a/sway/ipc-json.c +++ b/sway/ipc-json.c | |||
@@ -23,6 +23,20 @@ | |||
23 | static const int i3_output_id = INT32_MAX; | 23 | static const int i3_output_id = INT32_MAX; |
24 | static const int i3_scratch_id = INT32_MAX - 1; | 24 | static const int i3_scratch_id = INT32_MAX - 1; |
25 | 25 | ||
26 | static const char *ipc_json_node_type_description(enum sway_node_type node_type) { | ||
27 | switch (node_type) { | ||
28 | case N_ROOT: | ||
29 | return "root"; | ||
30 | case N_OUTPUT: | ||
31 | return "output"; | ||
32 | case N_WORKSPACE: | ||
33 | return "workspace"; | ||
34 | case N_CONTAINER: | ||
35 | return "con"; | ||
36 | } | ||
37 | return "none"; | ||
38 | } | ||
39 | |||
26 | static const char *ipc_json_layout_description(enum sway_container_layout l) { | 40 | static const char *ipc_json_layout_description(enum sway_container_layout l) { |
27 | switch (l) { | 41 | switch (l) { |
28 | case L_VERT: | 42 | case L_VERT: |
@@ -189,16 +203,22 @@ static json_object *ipc_json_create_empty_rect(void) { | |||
189 | return ipc_json_create_rect(&empty); | 203 | return ipc_json_create_rect(&empty); |
190 | } | 204 | } |
191 | 205 | ||
192 | static json_object *ipc_json_create_node(int id, char *name, | 206 | static json_object *ipc_json_create_node(int id, const char* type, char *name, |
193 | bool focused, json_object *focus, struct wlr_box *box) { | 207 | bool focused, json_object *focus, struct wlr_box *box) { |
194 | json_object *object = json_object_new_object(); | 208 | json_object *object = json_object_new_object(); |
195 | 209 | ||
196 | json_object_object_add(object, "id", json_object_new_int(id)); | 210 | json_object_object_add(object, "id", json_object_new_int(id)); |
197 | json_object_object_add(object, "name", | 211 | json_object_object_add(object, "type", json_object_new_string(type)); |
198 | name ? json_object_new_string(name) : NULL); | 212 | json_object_object_add(object, "orientation", |
199 | json_object_object_add(object, "rect", ipc_json_create_rect(box)); | 213 | json_object_new_string( |
214 | ipc_json_orientation_description(L_HORIZ))); | ||
215 | json_object_object_add(object, "percent", NULL); | ||
216 | json_object_object_add(object, "urgent", json_object_new_boolean(false)); | ||
217 | json_object_object_add(object, "marks", json_object_new_array()); | ||
200 | json_object_object_add(object, "focused", json_object_new_boolean(focused)); | 218 | json_object_object_add(object, "focused", json_object_new_boolean(focused)); |
201 | json_object_object_add(object, "focus", focus); | 219 | json_object_object_add(object, "layout", |
220 | json_object_new_string( | ||
221 | ipc_json_layout_description(L_HORIZ))); | ||
202 | 222 | ||
203 | // set default values to be compatible with i3 | 223 | // set default values to be compatible with i3 |
204 | json_object_object_add(object, "border", | 224 | json_object_object_add(object, "border", |
@@ -206,35 +226,25 @@ static json_object *ipc_json_create_node(int id, char *name, | |||
206 | ipc_json_border_description(B_NONE))); | 226 | ipc_json_border_description(B_NONE))); |
207 | json_object_object_add(object, "current_border_width", | 227 | json_object_object_add(object, "current_border_width", |
208 | json_object_new_int(0)); | 228 | json_object_new_int(0)); |
209 | json_object_object_add(object, "layout", | 229 | json_object_object_add(object, "rect", ipc_json_create_rect(box)); |
210 | json_object_new_string( | ||
211 | ipc_json_layout_description(L_HORIZ))); | ||
212 | json_object_object_add(object, "orientation", | ||
213 | json_object_new_string( | ||
214 | ipc_json_orientation_description(L_HORIZ))); | ||
215 | json_object_object_add(object, "percent", NULL); | ||
216 | json_object_object_add(object, "window_rect", ipc_json_create_empty_rect()); | ||
217 | json_object_object_add(object, "deco_rect", ipc_json_create_empty_rect()); | 230 | json_object_object_add(object, "deco_rect", ipc_json_create_empty_rect()); |
231 | json_object_object_add(object, "window_rect", ipc_json_create_empty_rect()); | ||
218 | json_object_object_add(object, "geometry", ipc_json_create_empty_rect()); | 232 | json_object_object_add(object, "geometry", ipc_json_create_empty_rect()); |
233 | json_object_object_add(object, "name", | ||
234 | name ? json_object_new_string(name) : NULL); | ||
219 | json_object_object_add(object, "window", NULL); | 235 | json_object_object_add(object, "window", NULL); |
220 | json_object_object_add(object, "urgent", json_object_new_boolean(false)); | ||
221 | json_object_object_add(object, "marks", json_object_new_array()); | ||
222 | json_object_object_add(object, "fullscreen_mode", json_object_new_int(0)); | ||
223 | json_object_object_add(object, "nodes", json_object_new_array()); | 236 | json_object_object_add(object, "nodes", json_object_new_array()); |
224 | json_object_object_add(object, "floating_nodes", json_object_new_array()); | 237 | json_object_object_add(object, "floating_nodes", json_object_new_array()); |
238 | json_object_object_add(object, "focus", focus); | ||
239 | json_object_object_add(object, "fullscreen_mode", json_object_new_int(0)); | ||
225 | json_object_object_add(object, "sticky", json_object_new_boolean(false)); | 240 | json_object_object_add(object, "sticky", json_object_new_boolean(false)); |
226 | 241 | ||
227 | return object; | 242 | return object; |
228 | } | 243 | } |
229 | 244 | ||
230 | static void ipc_json_describe_root(struct sway_root *root, json_object *object) { | ||
231 | json_object_object_add(object, "type", json_object_new_string("root")); | ||
232 | } | ||
233 | |||
234 | static void ipc_json_describe_output(struct sway_output *output, | 245 | static void ipc_json_describe_output(struct sway_output *output, |
235 | json_object *object) { | 246 | json_object *object) { |
236 | struct wlr_output *wlr_output = output->wlr_output; | 247 | struct wlr_output *wlr_output = output->wlr_output; |
237 | json_object_object_add(object, "type", json_object_new_string("output")); | ||
238 | json_object_object_add(object, "active", json_object_new_boolean(true)); | 248 | json_object_object_add(object, "active", json_object_new_boolean(true)); |
239 | json_object_object_add(object, "dpms", | 249 | json_object_object_add(object, "dpms", |
240 | json_object_new_boolean(wlr_output->enabled)); | 250 | json_object_new_boolean(wlr_output->enabled)); |
@@ -369,11 +379,9 @@ static json_object *ipc_json_describe_scratchpad_output(void) { | |||
369 | json_object_new_int(container->node.id)); | 379 | json_object_new_int(container->node.id)); |
370 | } | 380 | } |
371 | 381 | ||
372 | json_object *workspace = ipc_json_create_node(i3_scratch_id, | 382 | json_object *workspace = ipc_json_create_node(i3_scratch_id, "workspace", |
373 | "__i3_scratch", false, workspace_focus, &box); | 383 | "__i3_scratch", false, workspace_focus, &box); |
374 | json_object_object_add(workspace, "fullscreen_mode", json_object_new_int(1)); | 384 | json_object_object_add(workspace, "fullscreen_mode", json_object_new_int(1)); |
375 | json_object_object_add(workspace, "type", | ||
376 | json_object_new_string("workspace")); | ||
377 | 385 | ||
378 | // List all hidden scratchpad containers as floating nodes | 386 | // List all hidden scratchpad containers as floating nodes |
379 | json_object *floating_array = json_object_new_array(); | 387 | json_object *floating_array = json_object_new_array(); |
@@ -390,10 +398,8 @@ static json_object *ipc_json_describe_scratchpad_output(void) { | |||
390 | json_object *output_focus = json_object_new_array(); | 398 | json_object *output_focus = json_object_new_array(); |
391 | json_object_array_add(output_focus, json_object_new_int(i3_scratch_id)); | 399 | json_object_array_add(output_focus, json_object_new_int(i3_scratch_id)); |
392 | 400 | ||
393 | json_object *output = ipc_json_create_node(i3_output_id, | 401 | json_object *output = ipc_json_create_node(i3_output_id, "output", |
394 | "__i3", false, output_focus, &box); | 402 | "__i3", false, output_focus, &box); |
395 | json_object_object_add(output, "type", | ||
396 | json_object_new_string("output")); | ||
397 | json_object_object_add(output, "layout", | 403 | json_object_object_add(output, "layout", |
398 | json_object_new_string("output")); | 404 | json_object_new_string("output")); |
399 | 405 | ||
@@ -423,7 +429,6 @@ static void ipc_json_describe_workspace(struct sway_workspace *workspace, | |||
423 | json_object_object_add(object, "fullscreen_mode", json_object_new_int(1)); | 429 | json_object_object_add(object, "fullscreen_mode", json_object_new_int(1)); |
424 | json_object_object_add(object, "output", workspace->output ? | 430 | json_object_object_add(object, "output", workspace->output ? |
425 | json_object_new_string(workspace->output->wlr_output->name) : NULL); | 431 | json_object_new_string(workspace->output->wlr_output->name) : NULL); |
426 | json_object_object_add(object, "type", json_object_new_string("workspace")); | ||
427 | json_object_object_add(object, "urgent", | 432 | json_object_object_add(object, "urgent", |
428 | json_object_new_boolean(workspace->urgent)); | 433 | json_object_new_boolean(workspace->urgent)); |
429 | json_object_object_add(object, "representation", workspace->representation ? | 434 | json_object_object_add(object, "representation", workspace->representation ? |
@@ -583,8 +588,10 @@ static void ipc_json_describe_view(struct sway_container *c, json_object *object | |||
583 | static void ipc_json_describe_container(struct sway_container *c, json_object *object) { | 588 | static void ipc_json_describe_container(struct sway_container *c, json_object *object) { |
584 | json_object_object_add(object, "name", | 589 | json_object_object_add(object, "name", |
585 | c->title ? json_object_new_string(c->title) : NULL); | 590 | c->title ? json_object_new_string(c->title) : NULL); |
586 | json_object_object_add(object, "type", | 591 | if (container_is_floating(c)) { |
587 | json_object_new_string(container_is_floating(c) ? "floating_con" : "con")); | 592 | json_object_object_add(object, "type", |
593 | json_object_new_string("floating_con")); | ||
594 | } | ||
588 | 595 | ||
589 | json_object_object_add(object, "layout", | 596 | json_object_object_add(object, "layout", |
590 | json_object_new_string( | 597 | json_object_new_string( |
@@ -692,12 +699,11 @@ json_object *ipc_json_describe_node(struct sway_node *node) { | |||
692 | }; | 699 | }; |
693 | seat_for_each_node(seat, focus_inactive_children_iterator, &data); | 700 | seat_for_each_node(seat, focus_inactive_children_iterator, &data); |
694 | 701 | ||
695 | json_object *object = ipc_json_create_node( | 702 | json_object *object = ipc_json_create_node((int)node->id, |
696 | (int)node->id, name, focused, focus, &box); | 703 | ipc_json_node_type_description(node->type), name, focused, focus, &box); |
697 | 704 | ||
698 | switch (node->type) { | 705 | switch (node->type) { |
699 | case N_ROOT: | 706 | case N_ROOT: |
700 | ipc_json_describe_root(root, object); | ||
701 | break; | 707 | break; |
702 | case N_OUTPUT: | 708 | case N_OUTPUT: |
703 | ipc_json_describe_output(node->sway_output, object); | 709 | ipc_json_describe_output(node->sway_output, object); |