hyprlock/src/core/Timer.cpp
Maximilian Seidler d84b44e695
core: use hyprutils atomic pointers (#808)
* widgets: move references to hyprutils atomic shared

* core: move std::shared_pointers to hyprutils atomic shared pointers

* Nix: bump hyprutils input

* clang-format

* cmake: bump hyprutils to v0.8.0

* and bump nix again
2025-06-28 11:01:28 +02:00

30 lines
736 B
C++

#include "Timer.hpp"
CTimer::CTimer(std::chrono::system_clock::duration timeout, std::function<void(ASP<CTimer> self, void* data)> cb_, void* data_, bool force) :
cb(cb_), data(data_), allowForceUpdate(force) {
expires = std::chrono::system_clock::now() + timeout;
}
bool CTimer::passed() {
return std::chrono::system_clock::now() > expires;
}
void CTimer::cancel() {
wasCancelled = true;
}
bool CTimer::cancelled() {
return wasCancelled;
}
void CTimer::call(ASP<CTimer> self) {
cb(self, data);
}
float CTimer::leftMs() {
return std::chrono::duration_cast<std::chrono::milliseconds>(expires - std::chrono::system_clock::now()).count();
}
bool CTimer::canForceUpdate() {
return allowForceUpdate;
}