From c60a8e9836d72de69c9a02ddb4dd832912a8d706 Mon Sep 17 00:00:00 2001 From: Erik Reider <35975961+ErikReider@users.noreply.github.com> Date: Tue, 31 Oct 2023 08:46:21 +0100 Subject: [PATCH] free pipewire listeners on proxy destruction --- include/util/pipewire/privacy_node_info.hpp | 8 ++++++-- src/util/pipewire_backend.cpp | 19 +++++++++++++++++-- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/include/util/pipewire/privacy_node_info.hpp b/include/util/pipewire/privacy_node_info.hpp index 1c523f97..cd50e3a0 100644 --- a/include/util/pipewire/privacy_node_info.hpp +++ b/include/util/pipewire/privacy_node_info.hpp @@ -29,7 +29,8 @@ class PrivacyNodeInfo { std::string pipewire_access_portal_app_id; std::string application_icon_name; - struct spa_hook node_listener; + struct spa_hook object_listener; + struct spa_hook proxy_listener; bool changed = false; @@ -37,7 +38,10 @@ class PrivacyNodeInfo { PrivacyNodeInfo(uint32_t id_, void *data_) : id(id_), data(data_) {} - ~PrivacyNodeInfo() { spa_hook_remove(&node_listener); } + ~PrivacyNodeInfo() { + spa_hook_remove(&object_listener); + spa_hook_remove(&proxy_listener); + } std::string get_name() { const std::vector names{&application_name, &node_name}; diff --git a/src/util/pipewire_backend.cpp b/src/util/pipewire_backend.cpp index 47f4dc4f..627d62f9 100644 --- a/src/util/pipewire_backend.cpp +++ b/src/util/pipewire_backend.cpp @@ -1,5 +1,7 @@ #include "util/pipewire/pipewire_backend.hpp" +#include "util/pipewire/privacy_node_info.hpp" + namespace waybar::util::PipewireBackend { // TODO: Refresh on suspend wake @@ -58,9 +60,21 @@ static const struct pw_node_events node_events = { .info = get_node_info, }; +static void proxy_destroy(void *data) { + PrivacyNodeInfo *node = (PrivacyNodeInfo *)data; + + spa_hook_remove(&node->proxy_listener); + spa_hook_remove(&node->object_listener); +} + +static const struct pw_proxy_events proxy_events = { + .version = PW_VERSION_PROXY_EVENTS, + .destroy = proxy_destroy, +}; + static void registry_event_global(void *_data, uint32_t id, uint32_t permissions, const char *type, uint32_t version, const struct spa_dict *props) { - if (strcmp(type, PW_TYPE_INTERFACE_Node) != 0) return; + if (!props || strcmp(type, PW_TYPE_INTERFACE_Node) != 0) return; PipewireBackend *backend = static_cast(_data); struct pw_proxy *proxy = (pw_proxy *)pw_registry_bind(backend->registry, id, type, version, 0); @@ -73,7 +87,8 @@ static void registry_event_global(void *_data, uint32_t id, uint32_t permissions p_node_info = new PrivacyNodeInfo(id, backend); } backend->mutex_.unlock(); - pw_proxy_add_object_listener(proxy, &p_node_info->node_listener, &node_events, p_node_info); + pw_proxy_add_listener(proxy, &p_node_info->proxy_listener, &proxy_events, p_node_info); + pw_proxy_add_object_listener(proxy, &p_node_info->object_listener, &node_events, p_node_info); } }