diff options
author | Gregor Kleen <gkleen@yggdrasil.li> | 2025-09-04 22:59:52 +0200 |
---|---|---|
committer | Gregor Kleen <gkleen@yggdrasil.li> | 2025-09-04 22:59:52 +0200 |
commit | 029f4bd118eb3f1eca69ed3a7128997f077e0512 (patch) | |
tree | 1bb6a27689d7925ac3bab28787c7bd6ef4711f2b | |
parent | c21b32b7f8e784d93ff77e0ad22188cefd352819 (diff) | |
download | nixos-029f4bd118eb3f1eca69ed3a7128997f077e0512.tar nixos-029f4bd118eb3f1eca69ed3a7128997f077e0512.tar.gz nixos-029f4bd118eb3f1eca69ed3a7128997f077e0512.tar.bz2 nixos-029f4bd118eb3f1eca69ed3a7128997f077e0512.tar.xz nixos-029f4bd118eb3f1eca69ed3a7128997f077e0512.zip |
...
-rw-r--r-- | accounts/gkleen@sif/shell/quickshell-plugins/Chrono.cpp | 21 | ||||
-rw-r--r-- | accounts/gkleen@sif/shell/quickshell-plugins/FileSelector.cpp | 5 |
2 files changed, 12 insertions, 14 deletions
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() { | |||
42 | } | 42 | } |
43 | 43 | ||
44 | void Chrono::setTime(const std::chrono::time_point<std::chrono::system_clock>& targetTime) { | 44 | void Chrono::setTime(const std::chrono::time_point<std::chrono::system_clock>& targetTime) { |
45 | using namespace std::chrono_literals; | ||
46 | |||
45 | auto currentTime = std::chrono::system_clock::now(); | 47 | auto currentTime = std::chrono::system_clock::now(); |
46 | auto offset = std::chrono::duration_cast<std::chrono::milliseconds>(targetTime - currentTime); | 48 | auto offset = std::chrono::duration_cast<std::chrono::milliseconds>(targetTime - currentTime); |
47 | this->currentTime = abs(offset.count()) < 500 ? targetTime : currentTime; | 49 | this->currentTime = abs(offset) < 500ms ? targetTime : currentTime; |
48 | 50 | ||
49 | switch (this->mPrecision) { | 51 | switch (this->mPrecision) { |
50 | case Chrono::Hours: this->currentTime = std::chrono::time_point_cast<std::chrono::hours>(this->currentTime); | 52 | case Chrono::Hours: this->currentTime = std::chrono::time_point_cast<std::chrono::hours>(this->currentTime); |
@@ -58,21 +60,16 @@ void Chrono::setTime(const std::chrono::time_point<std::chrono::system_clock>& t | |||
58 | void Chrono::schedule(const std::chrono::time_point<std::chrono::system_clock>& targetTime) { | 60 | void Chrono::schedule(const std::chrono::time_point<std::chrono::system_clock>& targetTime) { |
59 | auto currentTime = std::chrono::system_clock::now(); | 61 | auto currentTime = std::chrono::system_clock::now(); |
60 | auto offset = std::chrono::duration_cast<std::chrono::milliseconds>(targetTime - currentTime); | 62 | auto offset = std::chrono::duration_cast<std::chrono::milliseconds>(targetTime - currentTime); |
61 | auto nextTime = abs(offset.count()) < 500 ? targetTime : currentTime; | 63 | auto nextTime = abs(offset) < 500ms ? targetTime : currentTime; |
62 | |||
63 | { | ||
64 | using namespace std::chrono_literals; | ||
65 | 64 | ||
66 | switch (this->mPrecision) { | 65 | switch (this->mPrecision) { |
67 | case Chrono::Hours: nextTime = std::chrono::time_point_cast<std::chrono::hours>(nextTime) + 1h; | 66 | case Chrono::Hours: nextTime = std::chrono::time_point_cast<std::chrono::hours>(nextTime) + 1h; |
68 | case Chrono::Minutes: nextTime = std::chrono::time_point_cast<std::chrono::minutes>(nextTime) + 1min; | 67 | case Chrono::Minutes: nextTime = std::chrono::time_point_cast<std::chrono::minutes>(nextTime) + 1min; |
69 | case Chrono::Seconds: nextTime = std::chrono::time_point_cast<std::chrono::seconds>(nextTime) + 1s; | 68 | case Chrono::Seconds: nextTime = std::chrono::time_point_cast<std::chrono::seconds>(nextTime) + 1s; |
70 | } | ||
71 | } | 69 | } |
72 | 70 | ||
73 | this->targetTime = nextTime; | 71 | this->targetTime = nextTime; |
74 | auto delay = std::chrono::duration_cast<std::chrono::milliseconds>(nextTime - currentTime); | 72 | this->timer.start(std::chrono::duration_cast<std::chrono::milliseconds>(nextTime - currentTime)); |
75 | this->timer.start(delay); | ||
76 | } | 73 | } |
77 | 74 | ||
78 | QString Chrono::format(const QString& fmt) const { | 75 | 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; | |||
12 | 12 | ||
13 | FileSelector::FileSelector(QObject* parent): QObject(parent) { | 13 | FileSelector::FileSelector(QObject* parent): QObject(parent) { |
14 | QObject::connect(&this->timer, &QTimer::timeout, this, &FileSelector::onTimeout); | 14 | QObject::connect(&this->timer, &QTimer::timeout, this, &FileSelector::onTimeout); |
15 | this->timer.setTimerType(Qt::PreciseTimer); | ||
15 | } | 16 | } |
16 | 17 | ||
17 | QString FileSelector::directory() const { | 18 | QString FileSelector::directory() const { |
@@ -83,8 +84,8 @@ void FileSelector::onTimeout() { | |||
83 | 84 | ||
84 | auto currentTime = std::chrono::system_clock::now(); | 85 | auto currentTime = std::chrono::system_clock::now(); |
85 | uint64_t currentMinorEpoch = currentTime.time_since_epoch() / (*this->mEpoch / this->mFiles.size()); | 86 | uint64_t currentMinorEpoch = currentTime.time_since_epoch() / (*this->mEpoch / this->mFiles.size()); |
86 | auto nextTime = std::chrono::time_point<std::chrono::system_clock>((2 * currentMinorEpoch + 3) * (*this->mEpoch / (this->mFiles.size() * 2))); | 87 | auto nextTime = std::chrono::time_point<std::chrono::system_clock>((currentMinorEpoch + 1) * (*this->mEpoch / this->mFiles.size())); |
87 | this->timer.start(std::chrono::duration_cast<std::chrono::milliseconds>(nextTime - currentTime).count()); | 88 | this->timer.start(std::chrono::duration_cast<std::chrono::milliseconds>(nextTime - currentTime)); |
88 | 89 | ||
89 | emit this->selectedChanged(); | 90 | emit this->selectedChanged(); |
90 | } | 91 | } |