From 08ee337e4dfa83f0e952a9d01728e617a2445938 Mon Sep 17 00:00:00 2001 From: Marius Vlad Date: Wed, 13 Oct 2021 17:54:03 +0300 Subject: [PATCH] screen-share: Add a compositor destroy listener Trivial fix to clean itself on compositor tear-down. While at it properly free the command string. Fixes #298 Signed-off-by: Marius Vlad --- compositor/screen-share.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/compositor/screen-share.c b/compositor/screen-share.c index c79bc3c4..60f25556 100644 --- a/compositor/screen-share.c +++ b/compositor/screen-share.c @@ -115,9 +115,7 @@ struct ss_shm_buffer { struct screen_share { struct weston_compositor *compositor; - /* XXX: missing compositor destroy listener - * https://gitlab.freedesktop.org/wayland/weston/issues/298 - */ + struct wl_listener compositor_destroy_listener; char *command; }; @@ -1164,6 +1162,18 @@ share_output_binding(struct weston_keyboard *keyboard, weston_output_share(output, ss->command); } +static void +compositor_destroy_listener(struct wl_listener *listener, void *data) +{ + struct screen_share *ss = + wl_container_of(listener, ss, compositor_destroy_listener); + + wl_list_remove(&ss->compositor_destroy_listener.link); + + free(ss->command); + free(ss); +} + WL_EXPORT int wet_module_init(struct weston_compositor *compositor, int *argc, char *argv[]) @@ -1179,11 +1189,16 @@ wet_module_init(struct weston_compositor *compositor, return -1; ss->compositor = compositor; + wl_list_init(&ss->compositor_destroy_listener.link); + + ss->compositor_destroy_listener.notify = compositor_destroy_listener; + wl_signal_add(&compositor->destroy_signal, &ss->compositor_destroy_listener); + config = wet_get_config(compositor); section = weston_config_get_section(config, "screen-share", NULL, NULL); - weston_config_section_get_string(section, "command", &ss->command, ""); + weston_config_section_get_string(section, "command", &ss->command, NULL); weston_compositor_add_key_binding(compositor, KEY_S, MODIFIER_CTRL | MODIFIER_ALT,