diff options
author | 2015-12-29 13:00:35 +0100 | |
---|---|---|
committer | 2015-12-29 13:03:53 +0100 | |
commit | 16b8c2e915fb7972ad5190ae2591b2d71789f477 (patch) | |
tree | 3474e5a04ec25468b0a26112796d8b5a4e0f6021 /sway | |
parent | handlers: geometry_request: Better debug output. (diff) | |
download | sway-16b8c2e915fb7972ad5190ae2591b2d71789f477.tar.gz sway-16b8c2e915fb7972ad5190ae2591b2d71789f477.tar.zst sway-16b8c2e915fb7972ad5190ae2591b2d71789f477.zip |
Handle SIGTERM sent to sway
This makes sway handle and gracefully shut down everything when
receiving a SIGTERM.
Fix #416
Diffstat (limited to 'sway')
-rw-r--r-- | sway/commands.c | 8 | ||||
-rw-r--r-- | sway/container.c | 10 | ||||
-rw-r--r-- | sway/main.c | 8 |
3 files changed, 19 insertions, 7 deletions
diff --git a/sway/commands.c b/sway/commands.c index 0955db38..fe341cd5 100644 --- a/sway/commands.c +++ b/sway/commands.c | |||
@@ -318,12 +318,6 @@ static struct cmd_results *cmd_exec(int argc, char **argv) { | |||
318 | return cmd_exec_always(argc, argv); | 318 | return cmd_exec_always(argc, argv); |
319 | } | 319 | } |
320 | 320 | ||
321 | static void kill_views(swayc_t *container, void *data) { | ||
322 | if (container->type == C_VIEW) { | ||
323 | wlc_view_close(container->handle); | ||
324 | } | ||
325 | } | ||
326 | |||
327 | static struct cmd_results *cmd_exit(int argc, char **argv) { | 321 | static struct cmd_results *cmd_exit(int argc, char **argv) { |
328 | struct cmd_results *error = NULL; | 322 | struct cmd_results *error = NULL; |
329 | if (config->reading) return cmd_results_new(CMD_FAILURE, "exit", "Can't be used in config file."); | 323 | if (config->reading) return cmd_results_new(CMD_FAILURE, "exit", "Can't be used in config file."); |
@@ -331,7 +325,7 @@ static struct cmd_results *cmd_exit(int argc, char **argv) { | |||
331 | return error; | 325 | return error; |
332 | } | 326 | } |
333 | // Close all views | 327 | // Close all views |
334 | container_map(&root_container, kill_views, NULL); | 328 | close_views(&root_container); |
335 | sway_terminate(); | 329 | sway_terminate(); |
336 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | 330 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); |
337 | } | 331 | } |
diff --git a/sway/container.c b/sway/container.c index e6fa4f37..dcf4dcc8 100644 --- a/sway/container.c +++ b/sway/container.c | |||
@@ -796,3 +796,13 @@ void add_gaps(swayc_t *view, void *_data) { | |||
796 | } | 796 | } |
797 | } | 797 | } |
798 | } | 798 | } |
799 | |||
800 | static void close_view(swayc_t *container, void *data) { | ||
801 | if (container->type == C_VIEW) { | ||
802 | wlc_view_close(container->handle); | ||
803 | } | ||
804 | } | ||
805 | |||
806 | void close_views(swayc_t *container) { | ||
807 | container_map(container, close_view, NULL); | ||
808 | } | ||
diff --git a/sway/main.c b/sway/main.c index 382e7ca2..37681f2d 100644 --- a/sway/main.c +++ b/sway/main.c | |||
@@ -26,6 +26,11 @@ void sway_terminate(void) { | |||
26 | wlc_terminate(); | 26 | wlc_terminate(); |
27 | } | 27 | } |
28 | 28 | ||
29 | void sig_handler(int signal) { | ||
30 | close_views(&root_container); | ||
31 | sway_terminate(); | ||
32 | } | ||
33 | |||
29 | static void wlc_log_handler(enum wlc_log_type type, const char *str) { | 34 | static void wlc_log_handler(enum wlc_log_type type, const char *str) { |
30 | if (type == WLC_LOG_ERROR) { | 35 | if (type == WLC_LOG_ERROR) { |
31 | sway_log(L_ERROR, "[wlc] %s", str); | 36 | sway_log(L_ERROR, "[wlc] %s", str); |
@@ -176,6 +181,9 @@ int main(int argc, char **argv) { | |||
176 | } | 181 | } |
177 | register_extensions(); | 182 | register_extensions(); |
178 | 183 | ||
184 | // handle SIGTERM signals | ||
185 | signal(SIGTERM, sig_handler); | ||
186 | |||
179 | #if defined SWAY_GIT_VERSION && defined SWAY_GIT_BRANCH && defined SWAY_VERSION_DATE | 187 | #if defined SWAY_GIT_VERSION && defined SWAY_GIT_BRANCH && defined SWAY_VERSION_DATE |
180 | sway_log(L_INFO, "Starting sway version %s (%s, branch \"%s\")\n", SWAY_GIT_VERSION, SWAY_VERSION_DATE, SWAY_GIT_BRANCH); | 188 | sway_log(L_INFO, "Starting sway version %s (%s, branch \"%s\")\n", SWAY_GIT_VERSION, SWAY_VERSION_DATE, SWAY_GIT_BRANCH); |
181 | #endif | 189 | #endif |