aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorVaxry <[email protected]>2024-06-25 16:05:39 +0200
committerVaxry <[email protected]>2024-06-25 16:05:47 +0200
commit1d70962892a6e3e1cacd3663b390bbdf81426984 (patch)
tree168f9049a02e8ecf704fa49f214810b95575240a
parent918d8340afd652b011b937d29d5eea0be08467f5 (diff)
downloadHyprland-1d70962892a6e3e1cacd3663b390bbdf81426984.tar.gz
Hyprland-1d70962892a6e3e1cacd3663b390bbdf81426984.zip
core: move to steady_clock where applicable
avoid issues when system clock gets desynchronized or changed
-rw-r--r--src/events/Monitors.cpp4
-rw-r--r--src/helpers/AnimatedVariable.cpp4
-rw-r--r--src/helpers/AnimatedVariable.hpp6
-rw-r--r--src/helpers/Timer.cpp8
-rw-r--r--src/helpers/Timer.hpp6
-rw-r--r--src/managers/AnimationManager.cpp2
-rw-r--r--src/managers/TokenManager.cpp8
-rw-r--r--src/managers/TokenManager.hpp6
-rw-r--r--src/managers/eventLoop/EventLoopTimer.cpp12
-rw-r--r--src/managers/eventLoop/EventLoopTimer.hpp6
10 files changed, 31 insertions, 31 deletions
diff --git a/src/events/Monitors.cpp b/src/events/Monitors.cpp
index 17b8ef65..2536e1f7 100644
--- a/src/events/Monitors.cpp
+++ b/src/events/Monitors.cpp
@@ -19,7 +19,7 @@
static void checkDefaultCursorWarp(SP<CMonitor> PNEWMONITOR, std::string monitorName) {
static auto PCURSORMONITOR = CConfigValue<std::string>("cursor:default_monitor");
- static auto firstMonitorAdded = std::chrono::system_clock::now();
+ static auto firstMonitorAdded = std::chrono::steady_clock::now();
static bool cursorDefaultDone = false;
static bool firstLaunch = true;
@@ -37,7 +37,7 @@ static void checkDefaultCursorWarp(SP<CMonitor> PNEWMONITOR, std::string monitor
return;
// after 10s, don't set cursor to default monitor
- auto timePassedSec = std::chrono::duration_cast<std::chrono::seconds>(std::chrono::system_clock::now() - firstMonitorAdded);
+ auto timePassedSec = std::chrono::duration_cast<std::chrono::seconds>(std::chrono::steady_clock::now() - firstMonitorAdded);
if (timePassedSec.count() > 10) {
cursorDefaultDone = true;
return;
diff --git a/src/helpers/AnimatedVariable.cpp b/src/helpers/AnimatedVariable.cpp
index bdfb4b77..117cd25b 100644
--- a/src/helpers/AnimatedVariable.cpp
+++ b/src/helpers/AnimatedVariable.cpp
@@ -57,11 +57,11 @@ void CBaseAnimatedVariable::registerVar() {
int CBaseAnimatedVariable::getDurationLeftMs() {
return std::max(
- (int)(m_pConfig->pValues->internalSpeed * 100) - (int)std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now() - animationBegin).count(), 0);
+ (int)(m_pConfig->pValues->internalSpeed * 100) - (int)std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now() - animationBegin).count(), 0);
}
float CBaseAnimatedVariable::getPercent() {
- const auto DURATIONPASSED = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now() - animationBegin).count();
+ const auto DURATIONPASSED = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now() - animationBegin).count();
return std::clamp((DURATIONPASSED / 100.f) / m_pConfig->pValues->internalSpeed, 0.f, 1.f);
}
diff --git a/src/helpers/AnimatedVariable.hpp b/src/helpers/AnimatedVariable.hpp
index 073cf65b..6310afb7 100644
--- a/src/helpers/AnimatedVariable.hpp
+++ b/src/helpers/AnimatedVariable.hpp
@@ -155,7 +155,7 @@ class CBaseAnimatedVariable {
bool m_bIsRegistered = false;
bool m_bIsBeingAnimated = false;
- std::chrono::system_clock::time_point animationBegin;
+ std::chrono::steady_clock::time_point animationBegin;
AVARDAMAGEPOLICY m_eDamagePolicy = AVARDAMAGE_NONE;
ANIMATEDVARTYPE m_Type;
@@ -253,7 +253,7 @@ class CAnimatedVariable : public CBaseAnimatedVariable {
return *this;
m_Goal = v;
- animationBegin = std::chrono::system_clock::now();
+ animationBegin = std::chrono::steady_clock::now();
m_Begun = m_Value;
onAnimationBegin();
@@ -267,7 +267,7 @@ class CAnimatedVariable : public CBaseAnimatedVariable {
return;
m_Value = v;
- animationBegin = std::chrono::system_clock::now();
+ animationBegin = std::chrono::steady_clock::now();
m_Begun = m_Value;
onAnimationBegin();
diff --git a/src/helpers/Timer.cpp b/src/helpers/Timer.cpp
index 6847567a..ec530df4 100644
--- a/src/helpers/Timer.cpp
+++ b/src/helpers/Timer.cpp
@@ -1,11 +1,11 @@
#include "Timer.hpp"
void CTimer::reset() {
- m_tpLastReset = std::chrono::system_clock::now();
+ m_tpLastReset = std::chrono::steady_clock::now();
}
-std::chrono::system_clock::duration CTimer::getDuration() {
- return std::chrono::system_clock::now() - m_tpLastReset;
+std::chrono::steady_clock::duration CTimer::getDuration() {
+ return std::chrono::steady_clock::now() - m_tpLastReset;
}
int CTimer::getMillis() {
@@ -16,6 +16,6 @@ float CTimer::getSeconds() {
return std::chrono::duration_cast<std::chrono::milliseconds>(getDuration()).count() / 1000.f;
}
-const std::chrono::system_clock::time_point& CTimer::chrono() const {
+const std::chrono::steady_clock::time_point& CTimer::chrono() const {
return m_tpLastReset;
} \ No newline at end of file
diff --git a/src/helpers/Timer.hpp b/src/helpers/Timer.hpp
index e55f4ebf..a6d1aeed 100644
--- a/src/helpers/Timer.hpp
+++ b/src/helpers/Timer.hpp
@@ -7,10 +7,10 @@ class CTimer {
void reset();
float getSeconds();
int getMillis();
- const std::chrono::system_clock::time_point& chrono() const;
+ const std::chrono::steady_clock::time_point& chrono() const;
private:
- std::chrono::system_clock::time_point m_tpLastReset;
+ std::chrono::steady_clock::time_point m_tpLastReset;
- std::chrono::system_clock::duration getDuration();
+ std::chrono::steady_clock::duration getDuration();
}; \ No newline at end of file
diff --git a/src/managers/AnimationManager.cpp b/src/managers/AnimationManager.cpp
index 9d6668c9..1fec375e 100644
--- a/src/managers/AnimationManager.cpp
+++ b/src/managers/AnimationManager.cpp
@@ -552,7 +552,7 @@ void CAnimationManager::scheduleTick() {
float refreshDelayMs = std::floor(1000.f / PMOSTHZ->refreshRate);
- const float SINCEPRES = std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::system_clock::now() - PMOSTHZ->lastPresentationTimer.chrono()).count() / 1000.f;
+ const float SINCEPRES = std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::steady_clock::now() - PMOSTHZ->lastPresentationTimer.chrono()).count() / 1000.f;
const auto TOPRES = std::clamp(refreshDelayMs - SINCEPRES, 1.1f, 1000.f); // we can't send 0, that will disarm it
diff --git a/src/managers/TokenManager.cpp b/src/managers/TokenManager.cpp
index 451baac1..cee97c1c 100644
--- a/src/managers/TokenManager.cpp
+++ b/src/managers/TokenManager.cpp
@@ -2,8 +2,8 @@
#include <uuid/uuid.h>
#include <algorithm>
-CUUIDToken::CUUIDToken(const std::string& uuid_, std::any data_, std::chrono::system_clock::duration expires) : data(data_), uuid(uuid_) {
- expiresAt = std::chrono::system_clock::now() + expires;
+CUUIDToken::CUUIDToken(const std::string& uuid_, std::any data_, std::chrono::steady_clock::duration expires) : data(data_), uuid(uuid_) {
+ expiresAt = std::chrono::steady_clock::now() + expires;
}
std::string CUUIDToken::getUUID() {
@@ -23,7 +23,7 @@ std::string CTokenManager::getRandomUUID() {
return uuid;
}
-std::string CTokenManager::registerNewToken(std::any data, std::chrono::system_clock::duration expires) {
+std::string CTokenManager::registerNewToken(std::any data, std::chrono::steady_clock::duration expires) {
std::string uuid = getRandomUUID();
m_mTokens[uuid] = makeShared<CUUIDToken>(uuid, data, expires);
@@ -33,7 +33,7 @@ std::string CTokenManager::registerNewToken(std::any data, std::chrono::system_c
SP<CUUIDToken> CTokenManager::getToken(const std::string& uuid) {
// cleanup expired tokens
- const auto NOW = std::chrono::system_clock::now();
+ const auto NOW = std::chrono::steady_clock::now();
std::erase_if(m_mTokens, [this, &NOW](const auto& el) { return el.second->expiresAt < NOW; });
if (!m_mTokens.contains(uuid))
diff --git a/src/managers/TokenManager.hpp b/src/managers/TokenManager.hpp
index 4587f556..92638e9b 100644
--- a/src/managers/TokenManager.hpp
+++ b/src/managers/TokenManager.hpp
@@ -9,7 +9,7 @@
class CUUIDToken {
public:
- CUUIDToken(const std::string& uuid_, std::any data_, std::chrono::system_clock::duration expires);
+ CUUIDToken(const std::string& uuid_, std::any data_, std::chrono::steady_clock::duration expires);
std::string getUUID();
@@ -18,14 +18,14 @@ class CUUIDToken {
private:
std::string uuid;
- std::chrono::system_clock::time_point expiresAt;
+ std::chrono::steady_clock::time_point expiresAt;
friend class CTokenManager;
};
class CTokenManager {
public:
- std::string registerNewToken(std::any data, std::chrono::system_clock::duration expires);
+ std::string registerNewToken(std::any data, std::chrono::steady_clock::duration expires);
std::string getRandomUUID();
SP<CUUIDToken> getToken(const std::string& uuid);
diff --git a/src/managers/eventLoop/EventLoopTimer.cpp b/src/managers/eventLoop/EventLoopTimer.cpp
index dbb405e5..d3cfdf8d 100644
--- a/src/managers/eventLoop/EventLoopTimer.cpp
+++ b/src/managers/eventLoop/EventLoopTimer.cpp
@@ -2,23 +2,23 @@
#include <limits>
#include "EventLoopManager.hpp"
-CEventLoopTimer::CEventLoopTimer(std::optional<std::chrono::system_clock::duration> timeout, std::function<void(SP<CEventLoopTimer> self, void* data)> cb_, void* data_) :
+CEventLoopTimer::CEventLoopTimer(std::optional<std::chrono::steady_clock::duration> timeout, std::function<void(SP<CEventLoopTimer> self, void* data)> cb_, void* data_) :
cb(cb_), data(data_) {
if (!timeout.has_value())
expires.reset();
else
- expires = std::chrono::system_clock::now() + *timeout;
+ expires = std::chrono::steady_clock::now() + *timeout;
}
-void CEventLoopTimer::updateTimeout(std::optional<std::chrono::system_clock::duration> timeout) {
+void CEventLoopTimer::updateTimeout(std::optional<std::chrono::steady_clock::duration> timeout) {
if (!timeout.has_value()) {
expires.reset();
g_pEventLoopManager->nudgeTimers();
return;
}
- expires = std::chrono::system_clock::now() + *timeout;
+ expires = std::chrono::steady_clock::now() + *timeout;
g_pEventLoopManager->nudgeTimers();
}
@@ -26,7 +26,7 @@ void CEventLoopTimer::updateTimeout(std::optional<std::chrono::system_clock::dur
bool CEventLoopTimer::passed() {
if (!expires.has_value())
return false;
- return std::chrono::system_clock::now() > *expires;
+ return std::chrono::steady_clock::now() > *expires;
}
void CEventLoopTimer::cancel() {
@@ -47,5 +47,5 @@ float CEventLoopTimer::leftUs() {
if (!expires.has_value())
return std::numeric_limits<float>::max();
- return std::chrono::duration_cast<std::chrono::microseconds>(*expires - std::chrono::system_clock::now()).count();
+ return std::chrono::duration_cast<std::chrono::microseconds>(*expires - std::chrono::steady_clock::now()).count();
}
diff --git a/src/managers/eventLoop/EventLoopTimer.hpp b/src/managers/eventLoop/EventLoopTimer.hpp
index 73f5dc73..ad7d3986 100644
--- a/src/managers/eventLoop/EventLoopTimer.hpp
+++ b/src/managers/eventLoop/EventLoopTimer.hpp
@@ -8,11 +8,11 @@
class CEventLoopTimer {
public:
- CEventLoopTimer(std::optional<std::chrono::system_clock::duration> timeout, std::function<void(SP<CEventLoopTimer> self, void* data)> cb_, void* data_);
+ CEventLoopTimer(std::optional<std::chrono::steady_clock::duration> timeout, std::function<void(SP<CEventLoopTimer> self, void* data)> cb_, void* data_);
// if not specified, disarms.
// if specified, arms.
- void updateTimeout(std::optional<std::chrono::system_clock::duration> timeout);
+ void updateTimeout(std::optional<std::chrono::steady_clock::duration> timeout);
void cancel();
bool passed();
@@ -26,6 +26,6 @@ class CEventLoopTimer {
private:
std::function<void(SP<CEventLoopTimer> self, void* data)> cb;
void* data = nullptr;
- std::optional<std::chrono::system_clock::time_point> expires;
+ std::optional<std::chrono::steady_clock::time_point> expires;
bool wasCancelled = false;
};