diff --git a/src/modules/clock.cpp b/src/modules/clock.cpp index e99017f9..69fdebb1 100644 --- a/src/modules/clock.cpp +++ b/src/modules/clock.cpp @@ -74,7 +74,11 @@ waybar::modules::Clock::Clock(const std::string& id, const Json::Value& config) thread_ = [this] { dp.emit(); - thread_.sleep_for(interval_); + auto now = std::chrono::system_clock::now(); + /* 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 5abc1de9..27c7ac77 100644 --- a/src/modules/simpleclock.cpp +++ b/src/modules/simpleclock.cpp @@ -6,7 +6,11 @@ waybar::modules::Clock::Clock(const std::string& id, const Json::Value& config) : ALabel(config, "clock", id, "{:%H:%M}", 60) { thread_ = [this] { dp.emit(); - thread_.sleep_for(interval_); + auto now = std::chrono::system_clock::now(); + /* difference with projected wakeup time */ + auto diff = now.time_since_epoch() % interval_; + /* sleep until the next projected time */ + thread_.sleep_for(interval_ - diff); }; }