ipc: add shutdown event
This commit is contained in:
parent
f078f7fdfa
commit
e8b179e313
4 changed files with 21 additions and 2 deletions
|
@ -27,8 +27,9 @@ enum ipc_command_type {
|
||||||
IPC_EVENT_WINDOW = ((1<<31) | 3),
|
IPC_EVENT_WINDOW = ((1<<31) | 3),
|
||||||
IPC_EVENT_BARCONFIG_UPDATE = ((1<<31) | 4),
|
IPC_EVENT_BARCONFIG_UPDATE = ((1<<31) | 4),
|
||||||
IPC_EVENT_BINDING = ((1<<31) | 5),
|
IPC_EVENT_BINDING = ((1<<31) | 5),
|
||||||
IPC_EVENT_MODIFIER = ((1<<31) | 6),
|
IPC_EVENT_SHUTDOWN = ((1<<31) | 6),
|
||||||
IPC_EVENT_INPUT = ((1<<31) | 7),
|
IPC_EVENT_MODIFIER = ((1<<31) | 16),
|
||||||
|
IPC_EVENT_INPUT = ((1<<31) | 17),
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -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_window(struct sway_container *window, const char *change);
|
||||||
void ipc_event_barconfig_update(struct bar_config *bar);
|
void ipc_event_barconfig_update(struct bar_config *bar);
|
||||||
void ipc_event_mode(const char *mode, bool pango);
|
void ipc_event_mode(const char *mode, bool pango);
|
||||||
|
void ipc_event_shutdown(const char *reason);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -353,6 +353,20 @@ void ipc_event_mode(const char *mode, bool pango) {
|
||||||
json_object_put(obj);
|
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) {
|
int ipc_client_handle_writable(int client_fd, uint32_t mask, void *data) {
|
||||||
struct ipc_client *client = 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);
|
client->subscribed_events |= event_mask(IPC_EVENT_BARCONFIG_UPDATE);
|
||||||
} else if (strcmp(event_type, "mode") == 0) {
|
} else if (strcmp(event_type, "mode") == 0) {
|
||||||
client->subscribed_events |= event_mask(IPC_EVENT_MODE);
|
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) {
|
} else if (strcmp(event_type, "window") == 0) {
|
||||||
client->subscribed_events |= event_mask(IPC_EVENT_WINDOW);
|
client->subscribed_events |= event_mask(IPC_EVENT_WINDOW);
|
||||||
} else if (strcmp(event_type, "modifier") == 0) {
|
} else if (strcmp(event_type, "modifier") == 0) {
|
||||||
|
|
|
@ -36,6 +36,7 @@ struct sway_server server;
|
||||||
void sway_terminate(int exit_code) {
|
void sway_terminate(int exit_code) {
|
||||||
terminate_request = true;
|
terminate_request = true;
|
||||||
exit_value = exit_code;
|
exit_value = exit_code;
|
||||||
|
ipc_event_shutdown("exit");
|
||||||
wl_display_terminate(server.wl_display);
|
wl_display_terminate(server.wl_display);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue