From 60fa5e9f67823591dda6d07896972cd68a4431b9 Mon Sep 17 00:00:00 2001 From: Sasha Moak Date: Sat, 26 Nov 2022 11:35:45 -0800 Subject: [PATCH] fix: wireplumber module when used with a bluetooth device This fixes #1811 by falling back to `node.description` if `node.nick` is not available. This can happen for bluetooth devices that do not have a `node.nick`. --- src/modules/wireplumber.cpp | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/modules/wireplumber.cpp b/src/modules/wireplumber.cpp index 6ebf748..9a12a9b 100644 --- a/src/modules/wireplumber.cpp +++ b/src/modules/wireplumber.cpp @@ -54,17 +54,25 @@ uint32_t waybar::modules::Wireplumber::getDefaultNodeId(waybar::modules::Wireplu } void waybar::modules::Wireplumber::updateNodeName(waybar::modules::Wireplumber* self) { - auto proxy = static_cast(wp_object_manager_lookup( - self->om_, WP_TYPE_GLOBAL_PROXY, WP_CONSTRAINT_TYPE_PW_GLOBAL_PROPERTY, "object.id", "=u", - self->node_id_, NULL)); + auto proxy = static_cast( + wp_object_manager_lookup(self->om_, WP_TYPE_GLOBAL_PROXY, WP_CONSTRAINT_TYPE_G_PROPERTY, + "bound-id", "=u", self->node_id_, NULL)); if (!proxy) { throw std::runtime_error(fmt::format("Object '{}' not found\n", self->node_id_)); } - g_autoptr(WpProperties) properties = wp_pipewire_object_get_properties(proxy); + g_autoptr(WpProperties) properties = + WP_IS_PIPEWIRE_OBJECT(proxy) ? wp_pipewire_object_get_properties(WP_PIPEWIRE_OBJECT(proxy)) + : wp_properties_new_empty(); + g_autoptr(WpProperties) global_p = wp_global_proxy_get_global_properties(WP_GLOBAL_PROXY(proxy)); properties = wp_properties_ensure_unique_owner(properties); - self->node_name_ = wp_properties_get(properties, "node.nick"); + wp_properties_add(properties, global_p); + wp_properties_set(properties, "object.id", NULL); + auto nick = wp_properties_get(properties, "node.nick"); + auto description = wp_properties_get(properties, "node.description"); + + self->node_name_ = nick ? nick : description; } void waybar::modules::Wireplumber::updateVolume(waybar::modules::Wireplumber* self) { @@ -120,6 +128,7 @@ void waybar::modules::Wireplumber::activatePlugins() { void waybar::modules::Wireplumber::prepare() { wp_object_manager_add_interest(om_, WP_TYPE_NODE, NULL); + wp_object_manager_add_interest(om_, WP_TYPE_GLOBAL_PROXY, NULL); wp_object_manager_request_object_features(om_, WP_TYPE_GLOBAL_PROXY, WP_PIPEWIRE_OBJECT_FEATURES_MINIMAL); }