diff --git a/src/modules/clock.cpp b/src/modules/clock.cpp index bb4da21..69fdebb 100644 --- a/src/modules/clock.cpp +++ b/src/modules/clock.cpp @@ -75,9 +75,10 @@ waybar::modules::Clock::Clock(const std::string& id, const Json::Value& config) thread_ = [this] { dp.emit(); auto now = std::chrono::system_clock::now(); - auto timeout = std::chrono::floor(now + interval_); - auto diff = std::chrono::seconds(timeout.time_since_epoch().count() % interval_.count()); - thread_.sleep_until(timeout - diff); + /* difference with projected wakeup time */ + auto diff = now.time_since_epoch() % interval_; + /* sleep until the next projected time */ + thread_.sleep_for(interval_ - diff); }; } diff --git a/src/modules/simpleclock.cpp b/src/modules/simpleclock.cpp index f4a4ec4..27c7ac7 100644 --- a/src/modules/simpleclock.cpp +++ b/src/modules/simpleclock.cpp @@ -7,9 +7,10 @@ waybar::modules::Clock::Clock(const std::string& id, const Json::Value& config) thread_ = [this] { dp.emit(); auto now = std::chrono::system_clock::now(); - auto timeout = std::chrono::floor(now + interval_); - auto diff = std::chrono::seconds(timeout.time_since_epoch().count() % interval_.count()); - thread_.sleep_until(timeout - diff); + /* difference with projected wakeup time */ + auto diff = now.time_since_epoch() % interval_; + /* sleep until the next projected time */ + thread_.sleep_for(interval_ - diff); }; }