bluetooth module working

This commit is contained in:
Marc 2020-01-22 11:37:47 +01:00
parent f0dbd8b78d
commit 89cb9673d4
5 changed files with 36 additions and 20 deletions

View File

@ -3,6 +3,9 @@
#include <fmt/format.h>
#include "ALabel.hpp"
#include <fmt/chrono.h>
#include "util/sleeper_thread.hpp"
namespace waybar::modules {
class Bluetooth : public ALabel {
@ -12,7 +15,8 @@ class Bluetooth : public ALabel {
auto update() -> void;
private:
;
std::string status_;
util::SleeperThread thread_;
};
} // namespace waybar::modules

View File

@ -2,7 +2,7 @@
#include <linux/rfkill.h>
namespace waybar::util {
namespace waybar::util::rfkill {
bool isDisabled(enum rfkill_type rfkill_type);

View File

@ -2,28 +2,40 @@
#include "util/rfkill.hpp"
#include <linux/rfkill.h>
#include <time.h>
waybar::modules::Bluetooth::Bluetooth(const std::string& id, const Json::Value& config)
: ALabel(config, "bluetooth", id, "{status}", 10) {
dp.emit();
: ALabel(config, "bluetooth", id, "{status}", 10),
status_("disabled") {
thread_ = [this] {
dp.emit();
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 {
auto text = "enabled";
if (waybar::util::isDisabled(RFKILL_TYPE_BLUETOOTH)) {
text = "disabled";
status_ = "enabled";
if (waybar::util::rfkill::isDisabled(RFKILL_TYPE_BLUETOOTH)) {
status_ = "disabled";
} else {
text = "enabled";
status_ = "enabled";
}
label_.set_markup(text);
label_.set_markup(
fmt::format(format_, fmt::arg("status", status_), fmt::arg("icon", getIcon(0, status_))));
label_.get_style_context()->add_class(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(text);
}
}
//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(text);
//}
//}
}

View File

@ -223,7 +223,7 @@ void waybar::modules::Network::worker() {
const std::string waybar::modules::Network::getNetworkState() const {
if (ifid_ == -1) {
if (waybar::util::isDisabled(RFKILL_TYPE_WLAN))
if (waybar::util::rfkill::isDisabled(RFKILL_TYPE_WLAN))
return "disabled";
return "disconnected";
}

View File

@ -5,7 +5,7 @@
#include <fcntl.h>
#include <cerrno>
bool waybar::util::isDisabled(enum rfkill_type rfkill_type) {
bool waybar::util::rfkill::isDisabled(enum rfkill_type rfkill_type) {
struct rfkill_event event;
ssize_t len;
int fd;