2020-01-21 17:04:54 +01:00
|
|
|
#include "modules/bluetooth.hpp"
|
2020-01-22 11:37:47 +01:00
|
|
|
|
2021-02-03 05:01:01 +01:00
|
|
|
#include <fmt/format.h>
|
|
|
|
|
2020-01-21 17:04:54 +01:00
|
|
|
waybar::modules::Bluetooth::Bluetooth(const std::string& id, const Json::Value& config)
|
2021-02-03 05:01:01 +01:00
|
|
|
: ALabel(config, "bluetooth", id, "{icon}", 10), rfkill_{RFKILL_TYPE_BLUETOOTH} {
|
2021-02-03 04:17:06 +01:00
|
|
|
rfkill_.on_update.connect(sigc::hide(sigc::mem_fun(*this, &Bluetooth::update)));
|
2020-01-21 17:04:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
auto waybar::modules::Bluetooth::update() -> void {
|
2021-02-03 05:01:01 +01:00
|
|
|
std::string status = rfkill_.getState() ? "disabled" : "enabled";
|
2020-01-21 17:04:54 +01:00
|
|
|
|
2020-01-22 11:37:47 +01:00
|
|
|
label_.set_markup(
|
2021-02-03 05:01:01 +01:00
|
|
|
fmt::format(format_, fmt::arg("status", status), fmt::arg("icon", getIcon(0, status))));
|
2022-04-12 10:26:21 +02:00
|
|
|
if (status == "disabled") {
|
|
|
|
label_.get_style_context()->add_class("disabled");
|
|
|
|
} else {
|
|
|
|
label_.get_style_context()->remove_class("disabled");
|
|
|
|
}
|
2020-01-21 17:04:54 +01:00
|
|
|
|
2020-01-26 05:34:31 +01:00
|
|
|
if (tooltipEnabled()) {
|
|
|
|
if (config_["tooltip-format"].isString()) {
|
|
|
|
auto tooltip_format = config_["tooltip-format"].asString();
|
2021-04-30 14:23:49 +02:00
|
|
|
auto tooltip_text = fmt::format(tooltip_format, status, fmt::arg("status", status));
|
2020-01-26 05:34:31 +01:00
|
|
|
label_.set_tooltip_text(tooltip_text);
|
|
|
|
} else {
|
2021-02-03 05:01:01 +01:00
|
|
|
label_.set_tooltip_text(status);
|
2020-01-26 05:34:31 +01:00
|
|
|
}
|
|
|
|
}
|
2020-01-21 17:04:54 +01:00
|
|
|
}
|