diff options
author | 2022-06-09 18:51:15 -0500 | |
---|---|---|
committer | 2022-09-19 07:26:45 -0400 | |
commit | 52f0e3a4d5bc5900df821b82a2c6941f57eaca25 (patch) | |
tree | 973d60e0f2d0d5ad7fe63aa1b38e549987c6d11a | |
parent | sway: Add non-desktop-output type (diff) | |
download | sway-52f0e3a4d5bc5900df821b82a2c6941f57eaca25.tar.gz sway-52f0e3a4d5bc5900df821b82a2c6941f57eaca25.tar.zst sway-52f0e3a4d5bc5900df821b82a2c6941f57eaca25.zip |
sway: add non-desktop outputs to json when running `swaymsg -t get_outputs`
-rw-r--r-- | include/sway/ipc-json.h | 2 | ||||
-rw-r--r-- | sway/ipc-json.c | 27 | ||||
-rw-r--r-- | sway/ipc-server.c | 6 |
3 files changed, 31 insertions, 4 deletions
diff --git a/include/sway/ipc-json.h b/include/sway/ipc-json.h index 6f4ade1a..bc9f4985 100644 --- a/include/sway/ipc-json.h +++ b/include/sway/ipc-json.h | |||
@@ -1,6 +1,7 @@ | |||
1 | #ifndef _SWAY_IPC_JSON_H | 1 | #ifndef _SWAY_IPC_JSON_H |
2 | #define _SWAY_IPC_JSON_H | 2 | #define _SWAY_IPC_JSON_H |
3 | #include <json.h> | 3 | #include <json.h> |
4 | #include "sway/output.h" | ||
4 | #include "sway/tree/container.h" | 5 | #include "sway/tree/container.h" |
5 | #include "sway/input/input-manager.h" | 6 | #include "sway/input/input-manager.h" |
6 | 7 | ||
@@ -9,6 +10,7 @@ json_object *ipc_json_get_version(void); | |||
9 | json_object *ipc_json_get_binding_mode(void); | 10 | json_object *ipc_json_get_binding_mode(void); |
10 | 11 | ||
11 | json_object *ipc_json_describe_disabled_output(struct sway_output *o); | 12 | json_object *ipc_json_describe_disabled_output(struct sway_output *o); |
13 | json_object *ipc_json_describe_non_desktop_output(struct sway_output_non_desktop *o); | ||
12 | json_object *ipc_json_describe_node(struct sway_node *node); | 14 | json_object *ipc_json_describe_node(struct sway_node *node); |
13 | json_object *ipc_json_describe_node_recursive(struct sway_node *node); | 15 | json_object *ipc_json_describe_node_recursive(struct sway_node *node); |
14 | json_object *ipc_json_describe_input(struct sway_input_device *device); | 16 | json_object *ipc_json_describe_input(struct sway_input_device *device); |
diff --git a/sway/ipc-json.c b/sway/ipc-json.c index 63c182f2..763fb3fe 100644 --- a/sway/ipc-json.c +++ b/sway/ipc-json.c | |||
@@ -240,10 +240,7 @@ static json_object *ipc_json_create_node(int id, const char* type, char *name, | |||
240 | return object; | 240 | return object; |
241 | } | 241 | } |
242 | 242 | ||
243 | static void ipc_json_describe_output(struct sway_output *output, | 243 | static void ipc_json_describe_wlr_output(struct wlr_output *wlr_output, json_object *object) { |
244 | json_object *object) { | ||
245 | struct wlr_output *wlr_output = output->wlr_output; | ||
246 | |||
247 | json_object_object_add(object, "primary", json_object_new_boolean(false)); | 244 | json_object_object_add(object, "primary", json_object_new_boolean(false)); |
248 | json_object_object_add(object, "make", | 245 | json_object_object_add(object, "make", |
249 | json_object_new_string(wlr_output->make ? wlr_output->make : "Unknown")); | 246 | json_object_new_string(wlr_output->make ? wlr_output->make : "Unknown")); |
@@ -267,11 +264,17 @@ static void ipc_json_describe_output(struct sway_output *output, | |||
267 | json_object_object_add(object, "modes", modes_array); | 264 | json_object_object_add(object, "modes", modes_array); |
268 | } | 265 | } |
269 | 266 | ||
267 | static void ipc_json_describe_output(struct sway_output *output, | ||
268 | json_object *object) { | ||
269 | ipc_json_describe_wlr_output(output->wlr_output, object); | ||
270 | } | ||
271 | |||
270 | static void ipc_json_describe_enabled_output(struct sway_output *output, | 272 | static void ipc_json_describe_enabled_output(struct sway_output *output, |
271 | json_object *object) { | 273 | json_object *object) { |
272 | ipc_json_describe_output(output, object); | 274 | ipc_json_describe_output(output, object); |
273 | 275 | ||
274 | struct wlr_output *wlr_output = output->wlr_output; | 276 | struct wlr_output *wlr_output = output->wlr_output; |
277 | json_object_object_add(object, "non_desktop", json_object_new_boolean(false)); | ||
275 | json_object_object_add(object, "active", json_object_new_boolean(true)); | 278 | json_object_object_add(object, "active", json_object_new_boolean(true)); |
276 | json_object_object_add(object, "dpms", | 279 | json_object_object_add(object, "dpms", |
277 | json_object_new_boolean(wlr_output->enabled)); | 280 | json_object_new_boolean(wlr_output->enabled)); |
@@ -349,6 +352,7 @@ json_object *ipc_json_describe_disabled_output(struct sway_output *output) { | |||
349 | 352 | ||
350 | ipc_json_describe_output(output, object); | 353 | ipc_json_describe_output(output, object); |
351 | 354 | ||
355 | json_object_object_add(object, "non_desktop", json_object_new_boolean(false)); | ||
352 | json_object_object_add(object, "type", json_object_new_string("output")); | 356 | json_object_object_add(object, "type", json_object_new_string("output")); |
353 | json_object_object_add(object, "name", | 357 | json_object_object_add(object, "name", |
354 | json_object_new_string(wlr_output->name)); | 358 | json_object_new_string(wlr_output->name)); |
@@ -370,6 +374,21 @@ json_object *ipc_json_describe_disabled_output(struct sway_output *output) { | |||
370 | return object; | 374 | return object; |
371 | } | 375 | } |
372 | 376 | ||
377 | json_object *ipc_json_describe_non_desktop_output(struct sway_output_non_desktop *output) { | ||
378 | struct wlr_output *wlr_output = output->wlr_output; | ||
379 | |||
380 | json_object *object = json_object_new_object(); | ||
381 | |||
382 | ipc_json_describe_wlr_output(wlr_output, object); | ||
383 | |||
384 | json_object_object_add(object, "non_desktop", json_object_new_boolean(true)); | ||
385 | json_object_object_add(object, "type", json_object_new_string("output")); | ||
386 | json_object_object_add(object, "name", | ||
387 | json_object_new_string(wlr_output->name)); | ||
388 | |||
389 | return object; | ||
390 | } | ||
391 | |||
373 | static json_object *ipc_json_describe_scratchpad_output(void) { | 392 | static json_object *ipc_json_describe_scratchpad_output(void) { |
374 | struct wlr_box box; | 393 | struct wlr_box box; |
375 | root_get_box(root, &box); | 394 | root_get_box(root, &box); |
diff --git a/sway/ipc-server.c b/sway/ipc-server.c index 3cbf7889..00b01d7d 100644 --- a/sway/ipc-server.c +++ b/sway/ipc-server.c | |||
@@ -685,6 +685,12 @@ void ipc_client_handle_command(struct ipc_client *client, uint32_t payload_lengt | |||
685 | ipc_json_describe_disabled_output(output)); | 685 | ipc_json_describe_disabled_output(output)); |
686 | } | 686 | } |
687 | } | 687 | } |
688 | |||
689 | for (int i = 0; i < root->non_desktop_outputs->length; i++) { | ||
690 | struct sway_output_non_desktop *non_desktop_output = root->non_desktop_outputs->items[i]; | ||
691 | json_object_array_add(outputs, ipc_json_describe_non_desktop_output(non_desktop_output)); | ||
692 | } | ||
693 | |||
688 | const char *json_string = json_object_to_json_string(outputs); | 694 | const char *json_string = json_object_to_json_string(outputs); |
689 | ipc_send_reply(client, payload_type, json_string, | 695 | ipc_send_reply(client, payload_type, json_string, |
690 | (uint32_t)strlen(json_string)); | 696 | (uint32_t)strlen(json_string)); |