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:
Aleksei Bavshin
2021-02-02 19:17:06 -08:00
parent 40f4dc9ecf
commit 38c29fc242
6 changed files with 64 additions and 67 deletions

View File

@ -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{};