Add format-bluetooth support to wireplumber module

This commit is contained in:
winkelnp
2025-08-11 17:34:50 +01:00
parent 41de8964f1
commit e355b40c66
+32 -12
View File
@@ -14,16 +14,16 @@ waybar::modules::Wireplumber::Wireplumber(const std::string& id, const Json::Val
mixer_api_(nullptr), mixer_api_(nullptr),
def_nodes_api_(nullptr), def_nodes_api_(nullptr),
default_node_name_(nullptr), default_node_name_(nullptr),
default_source_name_(nullptr),
pending_plugins_(0), pending_plugins_(0),
muted_(false), muted_(false),
source_muted_(false),
volume_(0.0), volume_(0.0),
source_volume_(0.0),
min_step_(0.0), min_step_(0.0),
node_id_(0), node_id_(0),
type_(nullptr),
source_node_id_(0), source_node_id_(0),
type_(nullptr) { source_muted_(false),
source_volume_(0.0),
default_source_name_(nullptr) {
waybar::modules::Wireplumber::modules.push_back(this); waybar::modules::Wireplumber::modules.push_back(this);
wp_init(WP_INIT_PIPEWIRE); wp_init(WP_INIT_PIPEWIRE);
@@ -418,10 +418,33 @@ void waybar::modules::Wireplumber::asyncLoadRequiredApiModules() {
auto waybar::modules::Wireplumber::update() -> void { auto waybar::modules::Wireplumber::update() -> void {
auto format = format_; auto format = format_;
std::string tooltipFormat; std::string tooltipFormat;
std::string format_name = "format";
// Handle sink bluetooth state
const std::string name = default_node_name_ != nullptr ? default_node_name_ : "";
auto bt = name.find("bluez") != std::string::npos || name.find("a2dp-sink") != std::string::npos;
if (bt) {
// format =
// config_["format-bluetooth"].isString() ? config_["format-bluetooth"].asString() : format;
format_name += "-bluetooth";
label_.get_style_context()->add_class("bluetooth");
} else {
label_.get_style_context()->remove_class("bluetooth");
}
// Handle sink mute state // Handle sink mute state
if (muted_) { if (muted_) {
format = config_["format-muted"].isString() ? config_["format-muted"].asString() : format; // if (bt)
// format = config_["format-bluetooth-muted"].isString()
// ? config_["format-bluetooth-muted"].asString()
// : format;
// else
// format = config_["format-muted"].isString() ? config_["format-muted"].asString() : format;
// Check muted bluetooth format exists, otherwise fall back to default muted format.
if (format_name != "format" && !config_[format_name + "-muted"].isString())
format_name = "format";
format_name += "-muted";
label_.get_style_context()->add_class("muted"); label_.get_style_context()->add_class("muted");
label_.get_style_context()->add_class("sink-muted"); label_.get_style_context()->add_class("sink-muted");
} else { } else {
@@ -441,13 +464,10 @@ auto waybar::modules::Wireplumber::update() -> void {
// Get the state and apply state-specific format if available // Get the state and apply state-specific format if available
auto state = getState(vol); auto state = getState(vol);
if (!state.empty()) { if (!state.empty() && config_[format_name + "-" + state].isString())
std::string format_name = muted_ ? "format-muted" : "format"; format = config_[format_name + "-" + state].asString();
std::string state_format_name = format_name + "-" + state; else if (config_[format_name].isString())
if (config_[state_format_name].isString()) { format = config_[format_name].asString();
format = config_[state_format_name].asString();
}
}
// Prepare source format string (similar to PulseAudio) // Prepare source format string (similar to PulseAudio)
std::string format_source = "{volume}%"; std::string format_source = "{volume}%";