Issue 1226/1497: Replace sleep_until with sleep_for to prevent clock from getting stuck with system time adjustment

This commit is contained in:
Rene D. Obermueller 2022-03-31 08:35:14 +02:00
parent 54b1df69a9
commit e5d05baba3
2 changed files with 2 additions and 8 deletions

View File

@ -74,10 +74,7 @@ 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<std::chrono::seconds>(now + interval_);
auto diff = std::chrono::seconds(timeout.time_since_epoch().count() % interval_.count());
thread_.sleep_until(timeout - diff);
thread_.sleep_for(interval_);
};
}

View File

@ -6,10 +6,7 @@ waybar::modules::Clock::Clock(const std::string& id, const Json::Value& config)
: ALabel(config, "clock", id, "{:%H:%M}", 60) {
thread_ = [this] {
dp.emit();
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);
thread_.sleep_for(interval_);
};
}