add man page for bluetooth, fix bluetooth race-condition

This commit is contained in:
Marc
2020-01-26 05:34:31 +01:00
parent e3bf6b968c
commit c045288ce4
8 changed files with 153 additions and 78 deletions

View File

@ -3,20 +3,24 @@
#include <linux/rfkill.h>
#include <time.h>
#include <iostream>
waybar::modules::Bluetooth::Bluetooth(const std::string& id, const Json::Value& config)
: ALabel(config, "bluetooth", id, "{status}", 10),
: ALabel(config, "bluetooth", id, "{icon}", 10),
status_("disabled"),
rfkill_(*(new waybar::util::Rfkill(RFKILL_TYPE_BLUETOOTH))) {
rfkill_{RFKILL_TYPE_BLUETOOTH} {
thread_ = [this] {
dp.emit();
rfkill_.waitForEvent();
};
intervall_thread_ = [this] {
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();
};
}
auto waybar::modules::Bluetooth::update() -> void {
status_ = "enabled";
if (rfkill_.getState()) {
status_ = "disabled";
} else {
@ -24,16 +28,18 @@ auto waybar::modules::Bluetooth::update() -> void {
}
label_.set_markup(
fmt::format(format_, fmt::arg("status", status_), fmt::arg("icon", getIcon(0, status_))));
label_.get_style_context()->add_class(status_);
fmt::format(
format_,
fmt::arg("status", status_),
fmt::arg("icon", getIcon(0, status_))));
//if (tooltipEnabled()) {
//if (config_["tooltip-format"].isString()) {
//auto tooltip_format = config_["tooltip-format"].asString();
////auto tooltip_text = fmt::format(tooltip_format, localtime);
//label_.set_tooltip_text(tooltip_text);
//} else {
//label_.set_tooltip_text(status_);
//}
//}
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_);
}
}
}