Skip to content

Commit

Permalink
feat: use interval thread until got inotify event
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexays committed Oct 25, 2018
1 parent 7f1f217 commit 9fae5ef
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/modules/battery.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class Battery : public ALabel {
void worker();

util::SleeperThread thread_;
util::SleeperThread threadTimer_;
std::vector<fs::path> batteries_;
int fd_;
};
Expand Down
6 changes: 6 additions & 0 deletions src/modules/battery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,18 @@ void waybar::modules::Battery::worker()
{
// Trigger first values
update();
uint32_t interval = config_["interval"] ? config_["interval"].asUInt() : 60;
threadTimer_ = [this, interval] {
thread_.sleep_for(chrono::seconds(interval));
dp.emit();
};
thread_ = [this] {
struct inotify_event event = {0};
int nbytes = read(fd_, &event, sizeof(event));
if (nbytes != sizeof(event)) {
return;
}
threadTimer_.stop();
dp.emit();
};
}
Expand Down

0 comments on commit 9fae5ef

Please sign in to comment.