2020-01-21 16:04:54 +00:00
|
|
|
#include "modules/bluetooth.hpp"
|
|
|
|
#include "util/rfkill.hpp"
|
|
|
|
#include <linux/rfkill.h>
|
2020-01-22 10:37:47 +00:00
|
|
|
#include <time.h>
|
|
|
|
|
2020-01-23 16:17:29 +00:00
|
|
|
#include <iostream>
|
|
|
|
|
2020-01-21 16:04:54 +00:00
|
|
|
waybar::modules::Bluetooth::Bluetooth(const std::string& id, const Json::Value& config)
|
2020-01-22 10:37:47 +00:00
|
|
|
: ALabel(config, "bluetooth", id, "{status}", 10),
|
2020-01-23 16:17:29 +00:00
|
|
|
status_("disabled"),
|
|
|
|
rfkill_(*(new waybar::util::Rfkill(RFKILL_TYPE_BLUETOOTH))) {
|
2020-01-22 10:37:47 +00:00
|
|
|
thread_ = [this] {
|
|
|
|
dp.emit();
|
2020-01-23 16:17:29 +00:00
|
|
|
rfkill_.waitForEvent();
|
2020-01-22 10:37:47 +00:00
|
|
|
};
|
2020-01-21 16:04:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
auto waybar::modules::Bluetooth::update() -> void {
|
2020-01-22 10:37:47 +00:00
|
|
|
status_ = "enabled";
|
2020-01-23 16:17:29 +00:00
|
|
|
if (rfkill_.getState()) {
|
2020-01-22 10:37:47 +00:00
|
|
|
status_ = "disabled";
|
2020-01-21 16:04:54 +00:00
|
|
|
} else {
|
2020-01-22 10:37:47 +00:00
|
|
|
status_ = "enabled";
|
2020-01-21 16:04:54 +00:00
|
|
|
}
|
|
|
|
|
2020-01-22 10:37:47 +00:00
|
|
|
label_.set_markup(
|
|
|
|
fmt::format(format_, fmt::arg("status", status_), fmt::arg("icon", getIcon(0, status_))));
|
|
|
|
label_.get_style_context()->add_class(status_);
|
2020-01-21 16:04:54 +00:00
|
|
|
|
2020-01-22 10:37:47 +00:00
|
|
|
//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 {
|
2020-01-23 16:17:29 +00:00
|
|
|
//label_.set_tooltip_text(status_);
|
2020-01-22 10:37:47 +00:00
|
|
|
//}
|
|
|
|
//}
|
2020-01-21 16:04:54 +00:00
|
|
|
}
|