From 029f4bd118eb3f1eca69ed3a7128997f077e0512 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Thu, 4 Sep 2025 22:59:52 +0200 Subject: ... --- .../gkleen@sif/shell/quickshell-plugins/Chrono.cpp | 21 +++++++++------------ .../shell/quickshell-plugins/FileSelector.cpp | 5 +++-- 2 files changed, 12 insertions(+), 14 deletions(-) (limited to 'accounts/gkleen@sif/shell') diff --git a/accounts/gkleen@sif/shell/quickshell-plugins/Chrono.cpp b/accounts/gkleen@sif/shell/quickshell-plugins/Chrono.cpp index df0c5781..bc765f21 100644 --- a/accounts/gkleen@sif/shell/quickshell-plugins/Chrono.cpp +++ b/accounts/gkleen@sif/shell/quickshell-plugins/Chrono.cpp @@ -42,9 +42,11 @@ void Chrono::update() { } void Chrono::setTime(const std::chrono::time_point& targetTime) { + using namespace std::chrono_literals; + auto currentTime = std::chrono::system_clock::now(); auto offset = std::chrono::duration_cast(targetTime - currentTime); - this->currentTime = abs(offset.count()) < 500 ? targetTime : currentTime; + this->currentTime = abs(offset) < 500ms ? targetTime : currentTime; switch (this->mPrecision) { case Chrono::Hours: this->currentTime = std::chrono::time_point_cast(this->currentTime); @@ -58,21 +60,16 @@ void Chrono::setTime(const std::chrono::time_point& t void Chrono::schedule(const std::chrono::time_point& targetTime) { auto currentTime = std::chrono::system_clock::now(); auto offset = std::chrono::duration_cast(targetTime - currentTime); - auto nextTime = abs(offset.count()) < 500 ? targetTime : currentTime; - - { - using namespace std::chrono_literals; + auto nextTime = abs(offset) < 500ms ? targetTime : currentTime; - switch (this->mPrecision) { - case Chrono::Hours: nextTime = std::chrono::time_point_cast(nextTime) + 1h; - case Chrono::Minutes: nextTime = std::chrono::time_point_cast(nextTime) + 1min; - case Chrono::Seconds: nextTime = std::chrono::time_point_cast(nextTime) + 1s; - } + switch (this->mPrecision) { + case Chrono::Hours: nextTime = std::chrono::time_point_cast(nextTime) + 1h; + case Chrono::Minutes: nextTime = std::chrono::time_point_cast(nextTime) + 1min; + case Chrono::Seconds: nextTime = std::chrono::time_point_cast(nextTime) + 1s; } this->targetTime = nextTime; - auto delay = std::chrono::duration_cast(nextTime - currentTime); - this->timer.start(delay); + this->timer.start(std::chrono::duration_cast(nextTime - currentTime)); } QString Chrono::format(const QString& fmt) const { diff --git a/accounts/gkleen@sif/shell/quickshell-plugins/FileSelector.cpp b/accounts/gkleen@sif/shell/quickshell-plugins/FileSelector.cpp index a3a35273..d7051d2a 100644 --- a/accounts/gkleen@sif/shell/quickshell-plugins/FileSelector.cpp +++ b/accounts/gkleen@sif/shell/quickshell-plugins/FileSelector.cpp @@ -12,6 +12,7 @@ namespace fs = std::filesystem; FileSelector::FileSelector(QObject* parent): QObject(parent) { QObject::connect(&this->timer, &QTimer::timeout, this, &FileSelector::onTimeout); + this->timer.setTimerType(Qt::PreciseTimer); } QString FileSelector::directory() const { @@ -83,8 +84,8 @@ void FileSelector::onTimeout() { auto currentTime = std::chrono::system_clock::now(); uint64_t currentMinorEpoch = currentTime.time_since_epoch() / (*this->mEpoch / this->mFiles.size()); - auto nextTime = std::chrono::time_point((2 * currentMinorEpoch + 3) * (*this->mEpoch / (this->mFiles.size() * 2))); - this->timer.start(std::chrono::duration_cast(nextTime - currentTime).count()); + auto nextTime = std::chrono::time_point((currentMinorEpoch + 1) * (*this->mEpoch / this->mFiles.size())); + this->timer.start(std::chrono::duration_cast(nextTime - currentTime)); emit this->selectedChanged(); } -- cgit v1.2.3