mirror of
https://github.com/rad4day/Waybar.git
synced 2023-12-21 10:22:59 +01:00
bluetooth module handles rfkill events instantly
This commit is contained in:
@ -1,25 +1,23 @@
|
||||
#include "modules/bluetooth.hpp"
|
||||
#include "util/rfkill.hpp"
|
||||
#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),
|
||||
status_("disabled") {
|
||||
status_("disabled"),
|
||||
rfkill_(*(new waybar::util::Rfkill(RFKILL_TYPE_BLUETOOTH))) {
|
||||
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);
|
||||
rfkill_.waitForEvent();
|
||||
};
|
||||
//dp.emit();
|
||||
}
|
||||
|
||||
auto waybar::modules::Bluetooth::update() -> void {
|
||||
status_ = "enabled";
|
||||
if (waybar::util::rfkill::isDisabled(RFKILL_TYPE_BLUETOOTH)) {
|
||||
if (rfkill_.getState()) {
|
||||
status_ = "disabled";
|
||||
} else {
|
||||
status_ = "enabled";
|
||||
@ -35,7 +33,7 @@ auto waybar::modules::Bluetooth::update() -> void {
|
||||
////auto tooltip_text = fmt::format(tooltip_format, localtime);
|
||||
//label_.set_tooltip_text(tooltip_text);
|
||||
//} else {
|
||||
//label_.set_tooltip_text(text);
|
||||
//label_.set_tooltip_text(status_);
|
||||
//}
|
||||
//}
|
||||
}
|
||||
|
@ -87,7 +87,9 @@ waybar::modules::Network::Network(const std::string &id, const Json::Value &conf
|
||||
cidr_(-1),
|
||||
signal_strength_dbm_(0),
|
||||
signal_strength_(0),
|
||||
frequency_(0) {
|
||||
frequency_(0),
|
||||
rfkill_(*(new waybar::util::Rfkill(RFKILL_TYPE_WLAN))) {
|
||||
|
||||
auto down_octets = read_netstat(BANDWIDTH_CATEGORY, BANDWIDTH_DOWN_TOTAL_KEY);
|
||||
auto up_octets = read_netstat(BANDWIDTH_CATEGORY, BANDWIDTH_UP_TOTAL_KEY);
|
||||
if (down_octets) {
|
||||
@ -224,7 +226,7 @@ void waybar::modules::Network::worker() {
|
||||
|
||||
const std::string waybar::modules::Network::getNetworkState() const {
|
||||
if (ifid_ == -1) {
|
||||
if (waybar::util::rfkill::isDisabled(RFKILL_TYPE_WLAN))
|
||||
if (rfkill_.isDisabled())
|
||||
return "disabled";
|
||||
return "disconnected";
|
||||
}
|
||||
|
Reference in New Issue
Block a user