mirror of
https://github.com/rad4day/Waybar.git
synced 2023-12-21 10:22:59 +01:00
refactor(rfkill): poll rfkill events from Glib main loop
Open rfkill device only once per module. Remove rfkill threads and use `Glib::signal_io` as a more efficient way to poll the rfkill device. Handle runtime errors from rfkill and stop polling of the device instead of crashing waybar.
This commit is contained in:
@ -1,17 +1,11 @@
|
||||
#include "modules/bluetooth.hpp"
|
||||
#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, "{icon}", 10),
|
||||
status_("disabled"),
|
||||
rfkill_{RFKILL_TYPE_BLUETOOTH} {
|
||||
rfkill_.on_update.connect(sigc::hide(sigc::mem_fun(*this, &Bluetooth::update)));
|
||||
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());
|
||||
|
@ -212,18 +212,15 @@ void waybar::modules::Network::worker() {
|
||||
thread_timer_.sleep_for(interval_);
|
||||
};
|
||||
#ifdef WANT_RFKILL
|
||||
thread_rfkill_ = [this] {
|
||||
rfkill_.waitForEvent();
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
if (ifid_ > 0) {
|
||||
getInfo();
|
||||
dp.emit();
|
||||
}
|
||||
rfkill_.on_update.connect([this](auto &) {
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
if (ifid_ > 0) {
|
||||
getInfo();
|
||||
dp.emit();
|
||||
}
|
||||
};
|
||||
});
|
||||
#else
|
||||
spdlog::warn("Waybar has been built without rfkill support.");
|
||||
spdlog::warn("Waybar has been built without rfkill support.");
|
||||
#endif
|
||||
thread_ = [this] {
|
||||
std::array<struct epoll_event, EPOLL_MAX> events{};
|
||||
|
Reference in New Issue
Block a user