aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/container.h5
-rw-r--r--sway/commands.c8
-rw-r--r--sway/container.c10
-rw-r--r--sway/main.c8
4 files changed, 24 insertions, 7 deletions
diff --git a/include/container.h b/include/container.h
index d76160de..d5126e74 100644
--- a/include/container.h
+++ b/include/container.h
@@ -260,4 +260,9 @@ void add_gaps(swayc_t *view, void *amount);
260 */ 260 */
261void update_visibility(swayc_t *container); 261void update_visibility(swayc_t *container);
262 262
263/**
264 * Close all child views of container
265 */
266void close_views(swayc_t *container);
267
263#endif 268#endif
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
321static void kill_views(swayc_t *container, void *data) {
322 if (container->type == C_VIEW) {
323 wlc_view_close(container->handle);
324 }
325}
326
327static struct cmd_results *cmd_exit(int argc, char **argv) { 321static 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
800static void close_view(swayc_t *container, void *data) {
801 if (container->type == C_VIEW) {
802 wlc_view_close(container->handle);
803 }
804}
805
806void 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
29void sig_handler(int signal) {
30 close_views(&root_container);
31 sway_terminate();
32}
33
29static void wlc_log_handler(enum wlc_log_type type, const char *str) { 34static 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