Skip to content

Commit

Permalink
refactor(bluetooth): remove interval and timer thread
Browse files Browse the repository at this point in the history
The timer thread was always reading the same value from Rfkill state.
  • Loading branch information
alebastr committed Feb 3, 2021
1 parent 00fad4d commit 2ac336a
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 16 deletions.
4 changes: 1 addition & 3 deletions include/modules/bluetooth.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#include "ALabel.hpp"
#include "util/rfkill.hpp"
#include "util/sleeper_thread.hpp"

namespace waybar::modules {

Expand All @@ -13,8 +12,7 @@ class Bluetooth : public ALabel {
auto update() -> void;

private:
util::SleeperThread thread_;
util::Rfkill rfkill_;
util::Rfkill rfkill_;
};

} // namespace waybar::modules
6 changes: 0 additions & 6 deletions man/waybar-bluetooth.5.scd
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ The *bluetooth* module displays information about the status of the device's blu

Addressed by *bluetooth*

*interval*: ++
typeof: integer ++
default: 60 ++
The interval in which the bluetooth state gets updated.

*format*: ++
typeof: string ++
default: *{icon}* ++
Expand Down Expand Up @@ -88,7 +83,6 @@ Addressed by *bluetooth*
"bluetooth": {
"format": "{icon}",
"format-alt": "bluetooth: {status}",
"interval": 30,
"format-icons": {
"enabled": "",
"disabled": ""
Expand Down
7 changes: 0 additions & 7 deletions src/modules/bluetooth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,6 @@
waybar::modules::Bluetooth::Bluetooth(const std::string& id, const Json::Value& config)
: ALabel(config, "bluetooth", id, "{icon}", 10), rfkill_{RFKILL_TYPE_BLUETOOTH} {
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 {
Expand Down

0 comments on commit 2ac336a

Please sign in to comment.