refactor(bluetooth): remove interval and timer thread

The timer thread was always reading the same value from Rfkill state.
This commit is contained in:
Aleksei Bavshin 2021-02-02 20:10:27 -08:00
parent ecc32ddd18
commit 52dd3d2446
No known key found for this signature in database
GPG Key ID: 4F071603387A382A
3 changed files with 1 additions and 16 deletions

View File

@ -2,7 +2,6 @@
#include "ALabel.hpp" #include "ALabel.hpp"
#include "util/rfkill.hpp" #include "util/rfkill.hpp"
#include "util/sleeper_thread.hpp"
namespace waybar::modules { namespace waybar::modules {
@ -13,8 +12,7 @@ class Bluetooth : public ALabel {
auto update() -> void; auto update() -> void;
private: private:
util::SleeperThread thread_; util::Rfkill rfkill_;
util::Rfkill rfkill_;
}; };
} // namespace waybar::modules } // namespace waybar::modules

View File

@ -12,11 +12,6 @@ The *bluetooth* module displays information about the status of the device's blu
Addressed by *bluetooth* Addressed by *bluetooth*
*interval*: ++
typeof: integer ++
default: 60 ++
The interval in which the bluetooth state gets updated.
*format*: ++ *format*: ++
typeof: string ++ typeof: string ++
default: *{icon}* ++ default: *{icon}* ++
@ -88,7 +83,6 @@ Addressed by *bluetooth*
"bluetooth": { "bluetooth": {
"format": "{icon}", "format": "{icon}",
"format-alt": "bluetooth: {status}", "format-alt": "bluetooth: {status}",
"interval": 30,
"format-icons": { "format-icons": {
"enabled": "", "enabled": "",
"disabled": "" "disabled": ""

View File

@ -5,13 +5,6 @@
waybar::modules::Bluetooth::Bluetooth(const std::string& id, const Json::Value& config) waybar::modules::Bluetooth::Bluetooth(const std::string& id, const Json::Value& config)
: ALabel(config, "bluetooth", id, "{icon}", 10), rfkill_{RFKILL_TYPE_BLUETOOTH} { : ALabel(config, "bluetooth", id, "{icon}", 10), rfkill_{RFKILL_TYPE_BLUETOOTH} {
rfkill_.on_update.connect(sigc::hide(sigc::mem_fun(*this, &Bluetooth::update))); rfkill_.on_update.connect(sigc::hide(sigc::mem_fun(*this, &Bluetooth::update)));
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());
thread_.sleep_until(timeout - diff);
dp.emit();
};
} }
auto waybar::modules::Bluetooth::update() -> void { auto waybar::modules::Bluetooth::update() -> void {