aboutsummaryrefslogtreecommitdiff
path: root/sway
diff options
context:
space:
mode:
authorIan Fan <ianfan0@gmail.com>2018-07-13 16:58:45 +0100
committerIan Fan <ianfan0@gmail.com>2018-08-01 16:57:14 +0100
commite8b179e313632c150ff7775f4f740296465cb58a (patch)
tree923ad08e8bd5b658283e5c39507b6e649b2f9777 /sway
parentf078f7fdfa8c1b2549178b8137c6731c2fff6d3f (diff)
ipc: add shutdown event
Diffstat (limited to 'sway')
-rw-r--r--sway/ipc-server.c16
-rw-r--r--sway/main.c1
2 files changed, 17 insertions, 0 deletions
diff --git a/sway/ipc-server.c b/sway/ipc-server.c
index be703915..72031e24 100644
--- a/sway/ipc-server.c
+++ b/sway/ipc-server.c
@@ -353,6 +353,20 @@ void ipc_event_mode(const char *mode, bool pango) {
json_object_put(obj);
}
+void ipc_event_shutdown(const char *reason) {
+ if (!ipc_has_event_listeners(IPC_EVENT_SHUTDOWN)) {
+ return;
+ }
+ wlr_log(WLR_DEBUG, "Sending shutdown::%s event", reason);
+
+ json_object *json = json_object_new_object();
+ json_object_object_add(json, "change", json_object_new_string(reason));
+
+ const char *json_string = json_object_to_json_string(json);
+ ipc_send_event(json_string, IPC_EVENT_SHUTDOWN);
+ json_object_put(json);
+}
+
int ipc_client_handle_writable(int client_fd, uint32_t mask, void *data) {
struct ipc_client *client = data;
@@ -549,6 +563,8 @@ void ipc_client_handle_command(struct ipc_client *client) {
client->subscribed_events |= event_mask(IPC_EVENT_BARCONFIG_UPDATE);
} else if (strcmp(event_type, "mode") == 0) {
client->subscribed_events |= event_mask(IPC_EVENT_MODE);
+ } else if (strcmp(event_type, "shutdown") == 0) {
+ client->subscribed_events |= event_mask(IPC_EVENT_SHUTDOWN);
} else if (strcmp(event_type, "window") == 0) {
client->subscribed_events |= event_mask(IPC_EVENT_WINDOW);
} else if (strcmp(event_type, "modifier") == 0) {
diff --git a/sway/main.c b/sway/main.c
index a20f1dac..477ffa5a 100644
--- a/sway/main.c
+++ b/sway/main.c
@@ -36,6 +36,7 @@ struct sway_server server;
void sway_terminate(int exit_code) {
terminate_request = true;
exit_value = exit_code;
+ ipc_event_shutdown("exit");
wl_display_terminate(server.wl_display);
}