diff options
author | Simon Ser <contact@emersion.fr> | 2022-05-26 21:14:34 +0200 |
---|---|---|
committer | Simon Zeni <simon@bl4ckb0ne.ca> | 2022-05-26 15:42:56 -0400 |
commit | f0d57da315ecbc44a444f76a7a8cde4045009453 (patch) | |
tree | 0ce377fa8959da913caef5497ab6e1362c1d8373 /sway/ipc-json.c | |
parent | 42b61ab27a6077e2089246513d6f66d20f536dd8 (diff) |
De-duplicate IPC output descriptions
Diffstat (limited to 'sway/ipc-json.c')
-rw-r--r-- | sway/ipc-json.c | 62 |
1 files changed, 32 insertions, 30 deletions
diff --git a/sway/ipc-json.c b/sway/ipc-json.c index 8357ae04..06121d62 100644 --- a/sway/ipc-json.c +++ b/sway/ipc-json.c @@ -245,20 +245,42 @@ static json_object *ipc_json_create_node(int id, const char* type, char *name, static void ipc_json_describe_output(struct sway_output *output, json_object *object) { struct wlr_output *wlr_output = output->wlr_output; - json_object_object_add(object, "active", json_object_new_boolean(true)); - json_object_object_add(object, "dpms", - json_object_new_boolean(wlr_output->enabled)); + json_object_object_add(object, "primary", json_object_new_boolean(false)); - json_object_object_add(object, "layout", json_object_new_string("output")); - json_object_object_add(object, "orientation", - json_object_new_string( - ipc_json_orientation_description(L_NONE))); json_object_object_add(object, "make", json_object_new_string(wlr_output->make)); json_object_object_add(object, "model", json_object_new_string(wlr_output->model)); json_object_object_add(object, "serial", json_object_new_string(wlr_output->serial)); + + json_object *modes_array = json_object_new_array(); + struct wlr_output_mode *mode; + wl_list_for_each(mode, &wlr_output->modes, link) { + json_object *mode_object = json_object_new_object(); + json_object_object_add(mode_object, "width", + json_object_new_int(mode->width)); + json_object_object_add(mode_object, "height", + json_object_new_int(mode->height)); + json_object_object_add(mode_object, "refresh", + json_object_new_int(mode->refresh)); + json_object_array_add(modes_array, mode_object); + } + json_object_object_add(object, "modes", modes_array); +} + +static void ipc_json_describe_enabled_output(struct sway_output *output, + json_object *object) { + ipc_json_describe_output(output, object); + + struct wlr_output *wlr_output = output->wlr_output; + json_object_object_add(object, "active", json_object_new_boolean(true)); + json_object_object_add(object, "dpms", + json_object_new_boolean(wlr_output->enabled)); + json_object_object_add(object, "layout", json_object_new_string("output")); + json_object_object_add(object, "orientation", + json_object_new_string( + ipc_json_orientation_description(L_NONE))); json_object_object_add(object, "scale", json_object_new_double(wlr_output->scale)); json_object_object_add(object, "scale_filter", @@ -325,33 +347,13 @@ json_object *ipc_json_describe_disabled_output(struct sway_output *output) { json_object *object = json_object_new_object(); + ipc_json_describe_output(output, object); + json_object_object_add(object, "type", json_object_new_string("output")); json_object_object_add(object, "name", json_object_new_string(wlr_output->name)); json_object_object_add(object, "active", json_object_new_boolean(false)); json_object_object_add(object, "dpms", json_object_new_boolean(false)); - json_object_object_add(object, "primary", json_object_new_boolean(false)); - json_object_object_add(object, "make", - json_object_new_string(wlr_output->make)); - json_object_object_add(object, "model", - json_object_new_string(wlr_output->model)); - json_object_object_add(object, "serial", - json_object_new_string(wlr_output->serial)); - - json_object *modes_array = json_object_new_array(); - struct wlr_output_mode *mode; - wl_list_for_each(mode, &wlr_output->modes, link) { - json_object *mode_object = json_object_new_object(); - json_object_object_add(mode_object, "width", - json_object_new_int(mode->width)); - json_object_object_add(mode_object, "height", - json_object_new_int(mode->height)); - json_object_object_add(mode_object, "refresh", - json_object_new_int(mode->refresh)); - json_object_array_add(modes_array, mode_object); - } - - json_object_object_add(object, "modes", modes_array); json_object_object_add(object, "current_workspace", NULL); @@ -706,7 +708,7 @@ json_object *ipc_json_describe_node(struct sway_node *node) { case N_ROOT: break; case N_OUTPUT: - ipc_json_describe_output(node->sway_output, object); + ipc_json_describe_enabled_output(node->sway_output, object); break; case N_CONTAINER: ipc_json_describe_container(node->sway_container, object); |