Issue 1226/1497: align updates with times divisible by interval

This commit is contained in:
Rene D. Obermueller 2022-03-31 17:14:29 +02:00
parent e5d05baba3
commit 4e3f91d237
2 changed files with 10 additions and 2 deletions

View File

@ -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);
};
}

View File

@ -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);
};
}