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,11 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include <fmt/format.h>
|
||||
#include "ALabel.hpp"
|
||||
|
||||
#include <fmt/chrono.h>
|
||||
#include "util/sleeper_thread.hpp"
|
||||
#include <fmt/format.h>
|
||||
|
||||
#include "ALabel.hpp"
|
||||
#include "util/rfkill.hpp"
|
||||
#include "util/sleeper_thread.hpp"
|
||||
|
||||
namespace waybar::modules {
|
||||
|
||||
@ -16,11 +16,9 @@ class Bluetooth : public ALabel {
|
||||
auto update() -> void;
|
||||
|
||||
private:
|
||||
std::string status_;
|
||||
util::SleeperThread thread_;
|
||||
util::SleeperThread intervall_thread_;
|
||||
|
||||
util::Rfkill rfkill_;
|
||||
std::string status_;
|
||||
util::SleeperThread thread_;
|
||||
util::Rfkill rfkill_;
|
||||
};
|
||||
|
||||
} // namespace waybar::modules
|
||||
|
@ -75,8 +75,6 @@ class Network : public ALabel {
|
||||
util::SleeperThread thread_;
|
||||
util::SleeperThread thread_timer_;
|
||||
#ifdef WANT_RFKILL
|
||||
util::SleeperThread thread_rfkill_;
|
||||
|
||||
util::Rfkill rfkill_;
|
||||
#endif
|
||||
};
|
||||
|
@ -1,19 +1,26 @@
|
||||
#pragma once
|
||||
|
||||
#include <glibmm/iochannel.h>
|
||||
#include <linux/rfkill.h>
|
||||
#include <sigc++/signal.h>
|
||||
#include <sigc++/trackable.h>
|
||||
|
||||
namespace waybar::util {
|
||||
|
||||
class Rfkill {
|
||||
class Rfkill : public sigc::trackable {
|
||||
public:
|
||||
Rfkill(enum rfkill_type rfkill_type);
|
||||
~Rfkill() = default;
|
||||
void waitForEvent();
|
||||
~Rfkill();
|
||||
bool getState() const;
|
||||
|
||||
sigc::signal<void(struct rfkill_event&)> on_update;
|
||||
|
||||
private:
|
||||
enum rfkill_type rfkill_type_;
|
||||
int state_ = 0;
|
||||
bool state_ = false;
|
||||
int fd_ = -1;
|
||||
|
||||
bool on_event(Glib::IOCondition cond);
|
||||
};
|
||||
|
||||
} // namespace waybar::util
|
||||
|
Reference in New Issue
Block a user