2020-01-21 17:04:54 +01:00
|
|
|
#include "modules/bluetooth.hpp"
|
2020-01-22 11:37:47 +01:00
|
|
|
|
2020-01-21 17:04:54 +01:00
|
|
|
waybar::modules::Bluetooth::Bluetooth(const std::string& id, const Json::Value& config)
|
2020-01-26 05:34:31 +01:00
|
|
|
: ALabel(config, "bluetooth", id, "{icon}", 10),
|
2020-01-23 17:17:29 +01:00
|
|
|
status_("disabled"),
|
2020-01-26 05:34:31 +01:00
|
|
|
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-22 11:37:47 +01:00
|
|
|
thread_ = [this] {
|
2020-01-26 05:34:31 +01:00
|
|
|
auto now = std::chrono::system_clock::now();
|
|
|
|
auto timeout = std::chrono::floor<std::chrono::seconds>(now + interval_);
|
|
|
|
auto diff = std::chrono::seconds(timeout.time_since_epoch().count() % interval_.count());
|
|
|
|
thread_.sleep_until(timeout - diff);
|
|
|
|
dp.emit();
|
|
|
|
};
|
2020-01-21 17:04:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
auto waybar::modules::Bluetooth::update() -> void {
|
2020-01-23 17:17:29 +01:00
|
|
|
if (rfkill_.getState()) {
|
2020-01-22 11:37:47 +01:00
|
|
|
status_ = "disabled";
|
2020-01-21 17:04:54 +01:00
|
|
|
} else {
|
2020-01-22 11:37:47 +01:00
|
|
|
status_ = "enabled";
|
2020-01-21 17:04:54 +01:00
|
|
|
}
|
|
|
|
|
2020-01-22 11:37:47 +01:00
|
|
|
label_.set_markup(
|
2020-01-26 05:34:31 +01:00
|
|
|
fmt::format(
|
|
|
|
format_,
|
|
|
|
fmt::arg("status", status_),
|
|
|
|
fmt::arg("icon", getIcon(0, status_))));
|
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();
|
|
|
|
auto tooltip_text = fmt::format(tooltip_format, status_);
|
|
|
|
label_.set_tooltip_text(tooltip_text);
|
|
|
|
} else {
|
|
|
|
label_.set_tooltip_text(status_);
|
|
|
|
}
|
|
|
|
}
|
2020-01-21 17:04:54 +01:00
|
|
|
}
|