From ede27eabc53dc926aa1932c2a58c06def1000f86 Mon Sep 17 00:00:00 2001 From: Mikkel Oscar Lyderik Date: Fri, 18 Dec 2015 17:43:03 +0100 Subject: Reload swaybar/swaybg on config reload. This works by tracking the pids of the child processes in the related output container and terminating the processes and spawning new ones on a config reload. Should solve: #347 --- include/config.h | 2 ++ include/container.h | 6 ++++++ 2 files changed, 8 insertions(+) (limited to 'include') diff --git a/include/config.h b/include/config.h index 32562908..1f25a0cd 100644 --- a/include/config.h +++ b/include/config.h @@ -184,6 +184,8 @@ int sway_mouse_binding_cmp(const void *a, const void *b); int sway_mouse_binding_cmp_buttons(const void *a, const void *b); void free_sway_mouse_binding(struct sway_mouse_binding *smb); +void load_swaybars(swayc_t *output, int output_idx); + /** * Allocate and initialize default bar configuration. */ diff --git a/include/container.h b/include/container.h index 9a67a689..d76160de 100644 --- a/include/container.h +++ b/include/container.h @@ -1,5 +1,6 @@ #ifndef _SWAY_CONTAINER_H #define _SWAY_CONTAINER_H +#include #include typedef struct sway_container swayc_t; @@ -81,6 +82,11 @@ struct sway_container { char *class; char *app_id; + // Used by output containers to keep track of swaybar/swaybg child + // processes. + list_t *bar_pids; + pid_t bg_pid; + int gaps; list_t *children; -- cgit v1.2.3-70-g09d2 From 90ff36cab8657272b6727af69bab49dba463d6ba Mon Sep 17 00:00:00 2001 From: Mikkel Oscar Lyderik Date: Fri, 18 Dec 2015 18:02:39 +0100 Subject: Terminate children when freeing output container --- include/config.h | 2 ++ sway/config.c | 20 ++++++++++++-------- sway/container.c | 4 ++++ 3 files changed, 18 insertions(+), 8 deletions(-) (limited to 'include') diff --git a/include/config.h b/include/config.h index 1f25a0cd..b89ad553 100644 --- a/include/config.h +++ b/include/config.h @@ -185,6 +185,8 @@ int sway_mouse_binding_cmp_buttons(const void *a, const void *b); void free_sway_mouse_binding(struct sway_mouse_binding *smb); void load_swaybars(swayc_t *output, int output_idx); +void terminate_swaybars(list_t *pids); +void terminate_swaybg(pid_t pid); /** * Allocate and initialize default bar configuration. diff --git a/sway/config.c b/sway/config.c index 23fe5388..928d35a8 100644 --- a/sway/config.c +++ b/sway/config.c @@ -389,7 +389,7 @@ static void invoke_swaybar(swayc_t *output, struct bar_config *bar, int output_i list_add(output->bar_pids, pid); } -static void terminate_swaybars(list_t *pids) { +void terminate_swaybars(list_t *pids) { int i, ret; pid_t *pid; for (i = 0; i < pids->length; ++i) { @@ -411,6 +411,16 @@ static void terminate_swaybars(list_t *pids) { } } +void terminate_swaybg(pid_t pid) { + int ret = kill(pid, SIGTERM); + if (ret != 0) { + sway_log(L_ERROR, "Unable to terminate swaybg [pid: %d]", pid); + } else { + int status; + waitpid(pid, &status, 0); + } +} + void load_swaybars(swayc_t *output, int output_idx) { // Check for bars list_t *bars = create_list(); @@ -496,13 +506,7 @@ void apply_output_config(struct output_config *oc, swayc_t *output) { if (oc && oc->background) { if (output->bg_pid != 0) { - int ret = kill(output->bg_pid, SIGTERM); - if (ret != 0) { - sway_log(L_ERROR, "Unable to terminate swaybg [pid: %d]", output->bg_pid); - } else { - int status; - waitpid(output->bg_pid, &status, 0); - } + terminate_swaybg(output->bg_pid); } sway_log(L_DEBUG, "Setting background for output %d to %s", output_i, oc->background); diff --git a/sway/container.c b/sway/container.c index 395eb04d..b85d2114 100644 --- a/sway/container.c +++ b/sway/container.c @@ -61,8 +61,12 @@ static void free_swayc(swayc_t *cont) { free(cont->app_id); } if (cont->bar_pids) { + terminate_swaybars(cont->bar_pids); free_flat_list(cont->bar_pids); } + if (cont->bg_pid != 0) { + terminate_swaybg(cont->bg_pid); + } free(cont); } -- cgit v1.2.3-70-g09d2