diff --git a/include/ipc.h b/include/ipc.h index 0010718b..ffc57d1b 100644 --- a/include/ipc.h +++ b/include/ipc.h @@ -27,8 +27,9 @@ enum ipc_command_type { IPC_EVENT_WINDOW = ((1<<31) | 3), IPC_EVENT_BARCONFIG_UPDATE = ((1<<31) | 4), IPC_EVENT_BINDING = ((1<<31) | 5), - IPC_EVENT_MODIFIER = ((1<<31) | 6), - IPC_EVENT_INPUT = ((1<<31) | 7), + IPC_EVENT_SHUTDOWN = ((1<<31) | 6), + IPC_EVENT_MODIFIER = ((1<<31) | 16), + IPC_EVENT_INPUT = ((1<<31) | 17), }; #endif diff --git a/include/sway/ipc-server.h b/include/sway/ipc-server.h index 6469f097..a11735cf 100644 --- a/include/sway/ipc-server.h +++ b/include/sway/ipc-server.h @@ -16,5 +16,6 @@ void ipc_event_workspace(struct sway_container *old, void ipc_event_window(struct sway_container *window, const char *change); void ipc_event_barconfig_update(struct bar_config *bar); void ipc_event_mode(const char *mode, bool pango); +void ipc_event_shutdown(const char *reason); #endif 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); }