mirror of
https://github.com/hyprwm/hyprlock.git
synced 2025-12-24 10:50:03 +01:00
* 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
30 lines
736 B
C++
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;
|
|
}
|