From 40eb29e7c56b67c2112ead7f048e45220a1c2887 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Wed, 1 Feb 2023 16:19:41 +0100 Subject: [PATCH] ipc: add support for output event For compatibility with i3 [1]. [1]: https://i3wm.org/docs/ipc.html#_output_event --- include/sway/ipc-server.h | 1 + sway/desktop/output.c | 3 +++ sway/ipc-server.c | 14 ++++++++++++++ sway/sway-ipc.7.scd | 17 +++++++++++++++++ 4 files changed, 35 insertions(+) diff --git a/include/sway/ipc-server.h b/include/sway/ipc-server.h index bc4f781a..d4c00942 100644 --- a/include/sway/ipc-server.h +++ b/include/sway/ipc-server.h @@ -21,5 +21,6 @@ void ipc_event_mode(const char *mode, bool pango); void ipc_event_shutdown(const char *reason); void ipc_event_binding(struct sway_binding *binding); void ipc_event_input(const char *change, struct sway_input_device *device); +void ipc_event_output(void); #endif diff --git a/sway/desktop/output.c b/sway/desktop/output.c index 1c209a39..141edb49 100644 --- a/sway/desktop/output.c +++ b/sway/desktop/output.c @@ -20,6 +20,7 @@ #include "sway/desktop/transaction.h" #include "sway/input/input-manager.h" #include "sway/input/seat.h" +#include "sway/ipc-server.h" #include "sway/layers.h" #include "sway/output.h" #include "sway/server.h" @@ -789,6 +790,8 @@ static void update_output_manager_config(struct sway_server *server) { } wlr_output_manager_v1_set_configuration(server->output_manager_v1, config); + + ipc_event_output(); } static void handle_destroy(struct wl_listener *listener, void *data) { diff --git a/sway/ipc-server.c b/sway/ipc-server.c index 51244436..2941ee76 100644 --- a/sway/ipc-server.c +++ b/sway/ipc-server.c @@ -508,6 +508,20 @@ void ipc_event_input(const char *change, struct sway_input_device *device) { json_object_put(json); } +void ipc_event_output(void) { + if (!ipc_has_event_listeners(IPC_EVENT_OUTPUT)) { + return; + } + sway_log(SWAY_DEBUG, "Sending output event"); + + json_object *json = json_object_new_object(); + json_object_object_add(json, "change", json_object_new_string("unspecified")); + + const char *json_string = json_object_to_json_string(json); + ipc_send_event(json_string, IPC_EVENT_OUTPUT); + json_object_put(json); +} + int ipc_client_handle_writable(int client_fd, uint32_t mask, void *data) { struct ipc_client *client = data; diff --git a/sway/sway-ipc.7.scd b/sway/sway-ipc.7.scd index 9121f679..2e903988 100644 --- a/sway/sway-ipc.7.scd +++ b/sway/sway-ipc.7.scd @@ -1445,6 +1445,9 @@ available: : workspace :[ Sent whenever an event involving a workspace occurs such as initialization of a new workspace or a different workspace gains focus +|- 0x80000001 +: output +: Sent when outputs are updated |- 0x80000002 : mode : Sent whenever the binding mode changes @@ -1565,6 +1568,20 @@ The following change types are currently available: } ``` +## 0x80000001. OUTPUT + +Sent whenever an output is added, removed, or its configuration is changed. +The event is a single object with the property _change_, which is a string +containing the reason for the change. Currently, the only value for _change_ is +_unspecified_. + +*Example Event:* +``` +{ + "change": "unspecified" +} +``` + ## 0x80000002. MODE Sent whenever the binding mode changes. The event consists of a single object