Fix bluetooth module still being visible if format is empty

pull/2413/head
PucklaJ 2023-08-16 16:30:59 +02:00
parent 22817089db
commit 70bc318a01
1 changed files with 20 additions and 18 deletions

View File

@ -101,11 +101,8 @@ waybar::modules::Bluetooth::Bluetooth(const std::string& id, const Json::Value&
} else { } else {
spdlog::error("findCurController() failed: no bluetooth controller found"); spdlog::error("findCurController() failed: no bluetooth controller found");
} }
event_box_.hide();
update(); update();
return; } else {
}
if (cur_controller_) {
// These calls only make sense if a controller could be found // These calls only make sense if a controller could be found
findConnectedDevices(cur_controller_->path, connected_devices_); findConnectedDevices(cur_controller_->path, connected_devices_);
g_signal_connect(manager_.get(), "interface-proxy-properties-changed", g_signal_connect(manager_.get(), "interface-proxy-properties-changed",
@ -114,11 +111,11 @@ waybar::modules::Bluetooth::Bluetooth(const std::string& id, const Json::Value&
this); this);
g_signal_connect(manager_.get(), "interface-removed", G_CALLBACK(onInterfaceAddedOrRemoved), g_signal_connect(manager_.get(), "interface-removed", G_CALLBACK(onInterfaceAddedOrRemoved),
this); this);
}
#ifdef WANT_RFKILL #ifdef WANT_RFKILL
rfkill_.on_update.connect(sigc::hide(sigc::mem_fun(*this, &Bluetooth::update))); rfkill_.on_update.connect(sigc::hide(sigc::mem_fun(*this, &Bluetooth::update)));
#endif #endif
}
dp.emit(); dp.emit();
} }
@ -196,8 +193,6 @@ auto waybar::modules::Bluetooth::update() -> void {
tooltip_format = config_["tooltip-format"].asString(); tooltip_format = config_["tooltip-format"].asString();
} }
format_.empty() ? event_box_.hide() : event_box_.show();
auto update_style_context = [this](const std::string& style_class, bool in_next_state) { auto update_style_context = [this](const std::string& style_class, bool in_next_state) {
if (in_next_state && !label_.get_style_context()->has_class(style_class)) { if (in_next_state && !label_.get_style_context()->has_class(style_class)) {
label_.get_style_context()->add_class(style_class); label_.get_style_context()->add_class(style_class);
@ -214,16 +209,23 @@ auto waybar::modules::Bluetooth::update() -> void {
update_style_context(state, true); update_style_context(state, true);
state_ = state; state_ = state;
label_.set_markup(fmt::format( if (format_.empty()) {
fmt::runtime(format_), fmt::arg("status", state_), event_box_.hide();
fmt::arg("num_connections", connected_devices_.size()), } else {
fmt::arg("controller_address", cur_controller_ ? cur_controller_->address : "null"), event_box_.show();
fmt::arg("controller_address_type", cur_controller_ ? cur_controller_->address_type : "null"), label_.set_markup(fmt::format(
fmt::arg("controller_alias", cur_controller_ ? cur_controller_->alias : "null"), fmt::runtime(format_), fmt::arg("status", state_),
fmt::arg("device_address", cur_focussed_device_.address), fmt::arg("num_connections", connected_devices_.size()),
fmt::arg("device_address_type", cur_focussed_device_.address_type), fmt::arg("controller_address", cur_controller_ ? cur_controller_->address : "null"),
fmt::arg("device_alias", cur_focussed_device_.alias), fmt::arg("icon", icon_label), fmt::arg("controller_address_type",
fmt::arg("device_battery_percentage", cur_focussed_device_.battery_percentage.value_or(0)))); cur_controller_ ? cur_controller_->address_type : "null"),
fmt::arg("controller_alias", cur_controller_ ? cur_controller_->alias : "null"),
fmt::arg("device_address", cur_focussed_device_.address),
fmt::arg("device_address_type", cur_focussed_device_.address_type),
fmt::arg("device_alias", cur_focussed_device_.alias), fmt::arg("icon", icon_label),
fmt::arg("device_battery_percentage",
cur_focussed_device_.battery_percentage.value_or(0))));
}
if (tooltipEnabled()) { if (tooltipEnabled()) {
bool tooltip_enumerate_connections_ = config_["tooltip-format-enumerate-connected"].isString(); bool tooltip_enumerate_connections_ = config_["tooltip-format-enumerate-connected"].isString();