free pipewire listeners on proxy destruction

pull/2612/head
Erik Reider 2023-10-31 08:46:21 +01:00
parent c4226f3745
commit c60a8e9836
2 changed files with 23 additions and 4 deletions

View File

@ -29,7 +29,8 @@ class PrivacyNodeInfo {
std::string pipewire_access_portal_app_id; std::string pipewire_access_portal_app_id;
std::string application_icon_name; std::string application_icon_name;
struct spa_hook node_listener; struct spa_hook object_listener;
struct spa_hook proxy_listener;
bool changed = false; bool changed = false;
@ -37,7 +38,10 @@ class PrivacyNodeInfo {
PrivacyNodeInfo(uint32_t id_, void *data_) : id(id_), data(data_) {} 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() { std::string get_name() {
const std::vector<std::string *> names{&application_name, &node_name}; const std::vector<std::string *> names{&application_name, &node_name};

View File

@ -1,5 +1,7 @@
#include "util/pipewire/pipewire_backend.hpp" #include "util/pipewire/pipewire_backend.hpp"
#include "util/pipewire/privacy_node_info.hpp"
namespace waybar::util::PipewireBackend { namespace waybar::util::PipewireBackend {
// TODO: Refresh on suspend wake // TODO: Refresh on suspend wake
@ -58,9 +60,21 @@ static const struct pw_node_events node_events = {
.info = get_node_info, .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, static void registry_event_global(void *_data, uint32_t id, uint32_t permissions, const char *type,
uint32_t version, const struct spa_dict *props) { 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<PipewireBackend *>(_data); PipewireBackend *backend = static_cast<PipewireBackend *>(_data);
struct pw_proxy *proxy = (pw_proxy *)pw_registry_bind(backend->registry, id, type, version, 0); 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); p_node_info = new PrivacyNodeInfo(id, backend);
} }
backend->mutex_.unlock(); 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);
} }
} }