time: move to stl's clocks and move timer
This commit is contained in:
parent
0e521788bc
commit
877fb5b93a
43 changed files with 392 additions and 248 deletions
|
|
@ -264,7 +264,7 @@ void CHyprAnimationManager::scheduleTick() {
|
|||
|
||||
float refreshDelayMs = std::floor(1000.f / PMOSTHZ->refreshRate);
|
||||
|
||||
const float SINCEPRES = std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::steady_clock::now() - PMOSTHZ->lastPresentationTimer.chrono()).count() / 1000.f;
|
||||
const float SINCEPRES = std::chrono::duration_cast<std::chrono::microseconds>(Time::steadyNow() - 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
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
#include <xkbcommon/xkbcommon.h>
|
||||
#include "../devices/IPointer.hpp"
|
||||
#include "eventLoop/EventLoopTimer.hpp"
|
||||
#include "../helpers/Timer.hpp"
|
||||
#include "../helpers/time/Timer.hpp"
|
||||
|
||||
class CInputManager;
|
||||
class CConfigManager;
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@
|
|||
#include "../render/Renderer.hpp"
|
||||
#include "../render/OpenGL.hpp"
|
||||
#include "SeatManager.hpp"
|
||||
#include "../helpers/time/Time.hpp"
|
||||
#include <cstring>
|
||||
#include <gbm.h>
|
||||
#include <cairo/cairo.h>
|
||||
|
|
@ -160,9 +161,7 @@ void CPointerManager::setCursorSurface(SP<CWLSurface> surf, const Vector2D& hots
|
|||
|
||||
if (surf->resource()->current.texture) {
|
||||
currentCursorImage.size = surf->resource()->current.bufferSize;
|
||||
timespec now;
|
||||
clock_gettime(CLOCK_MONOTONIC, &now);
|
||||
surf->resource()->frame(&now);
|
||||
surf->resource()->frame(Time::steadyNow());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -592,7 +591,7 @@ SP<Aquamarine::IBuffer> CPointerManager::renderHWCursorBuffer(SP<CPointerManager
|
|||
return buf;
|
||||
}
|
||||
|
||||
void CPointerManager::renderSoftwareCursorsFor(PHLMONITOR pMonitor, timespec* now, CRegion& damage, std::optional<Vector2D> overridePos) {
|
||||
void CPointerManager::renderSoftwareCursorsFor(PHLMONITOR pMonitor, const Time::steady_tp& now, CRegion& damage, std::optional<Vector2D> overridePos) {
|
||||
if (!hasCursor())
|
||||
return;
|
||||
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
#include "../helpers/math/Math.hpp"
|
||||
#include "../desktop/WLSurface.hpp"
|
||||
#include "../helpers/sync/SyncTimeline.hpp"
|
||||
#include "../helpers/time/Time.hpp"
|
||||
#include <tuple>
|
||||
|
||||
class CMonitor;
|
||||
|
|
@ -48,7 +49,7 @@ class CPointerManager {
|
|||
void unlockSoftwareAll();
|
||||
bool softwareLockedFor(PHLMONITOR pMonitor);
|
||||
|
||||
void renderSoftwareCursorsFor(PHLMONITOR pMonitor, timespec* now, CRegion& damage /* logical */, std::optional<Vector2D> overridePos = {} /* monitor-local */);
|
||||
void renderSoftwareCursorsFor(PHLMONITOR pMonitor, const Time::steady_tp& now, CRegion& damage /* logical */, std::optional<Vector2D> overridePos = {} /* monitor-local */);
|
||||
|
||||
// this is needed e.g. during screensharing where
|
||||
// the software cursors aren't locked during the cursor move, but they
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "../defines.hpp"
|
||||
#include "../helpers/Timer.hpp"
|
||||
#include "../helpers/time/Timer.hpp"
|
||||
#include "../helpers/signal/Signal.hpp"
|
||||
#include <cstdint>
|
||||
#include <unordered_map>
|
||||
|
|
|
|||
|
|
@ -2,12 +2,12 @@
|
|||
#include <uuid/uuid.h>
|
||||
#include <algorithm>
|
||||
|
||||
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;
|
||||
CUUIDToken::CUUIDToken(const std::string& uuid_, std::any data_, Time::steady_dur expires) : m_data(data_), m_uuid(uuid_) {
|
||||
m_expiresAt = Time::steadyNow() + expires;
|
||||
}
|
||||
|
||||
std::string CUUIDToken::getUUID() {
|
||||
return uuid;
|
||||
return m_uuid;
|
||||
}
|
||||
|
||||
std::string CTokenManager::getRandomUUID() {
|
||||
|
|
@ -23,7 +23,7 @@ std::string CTokenManager::getRandomUUID() {
|
|||
return uuid;
|
||||
}
|
||||
|
||||
std::string CTokenManager::registerNewToken(std::any data, std::chrono::steady_clock::duration expires) {
|
||||
std::string CTokenManager::registerNewToken(std::any data, Time::steady_dur expires) {
|
||||
std::string uuid = getRandomUUID();
|
||||
|
||||
m_mTokens[uuid] = makeShared<CUUIDToken>(uuid, data, expires);
|
||||
|
|
@ -33,8 +33,8 @@ std::string CTokenManager::registerNewToken(std::any data, std::chrono::steady_c
|
|||
SP<CUUIDToken> CTokenManager::getToken(const std::string& uuid) {
|
||||
|
||||
// cleanup expired tokens
|
||||
const auto NOW = std::chrono::steady_clock::now();
|
||||
std::erase_if(m_mTokens, [&NOW](const auto& el) { return el.second->expiresAt < NOW; });
|
||||
const auto NOW = Time::steadyNow();
|
||||
std::erase_if(m_mTokens, [&NOW](const auto& el) { return el.second->m_expiresAt < NOW; });
|
||||
|
||||
if (!m_mTokens.contains(uuid))
|
||||
return {};
|
||||
|
|
@ -45,5 +45,5 @@ SP<CUUIDToken> CTokenManager::getToken(const std::string& uuid) {
|
|||
void CTokenManager::removeToken(SP<CUUIDToken> token) {
|
||||
if (!token)
|
||||
return;
|
||||
m_mTokens.erase(token->uuid);
|
||||
m_mTokens.erase(token->m_uuid);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,24 +1,23 @@
|
|||
#pragma once
|
||||
|
||||
#include <chrono>
|
||||
#include <any>
|
||||
#include <unordered_map>
|
||||
#include <string>
|
||||
|
||||
#include "../helpers/memory/Memory.hpp"
|
||||
#include "../helpers/time/Time.hpp"
|
||||
|
||||
class CUUIDToken {
|
||||
public:
|
||||
CUUIDToken(const std::string& uuid_, std::any data_, std::chrono::steady_clock::duration expires);
|
||||
CUUIDToken(const std::string& uuid_, std::any data_, Time::steady_dur expires);
|
||||
|
||||
std::string getUUID();
|
||||
|
||||
std::any data;
|
||||
std::any m_data;
|
||||
|
||||
private:
|
||||
std::string uuid;
|
||||
|
||||
std::chrono::steady_clock::time_point expiresAt;
|
||||
std::string m_uuid;
|
||||
Time::steady_tp m_expiresAt;
|
||||
|
||||
friend class CTokenManager;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,3 +1,9 @@
|
|||
#define Time XTime__
|
||||
extern "C" {
|
||||
#include <X11/Xcursor/Xcursor.h>
|
||||
}
|
||||
#undef Time
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
#include <dirent.h>
|
||||
|
|
@ -176,8 +182,9 @@ SP<SXCursors> CXCursorManager::getShape(std::string const& shape, int size, floa
|
|||
return defaultCursor;
|
||||
}
|
||||
|
||||
SP<SXCursors> CXCursorManager::createCursor(std::string const& shape, XcursorImages* xImages) {
|
||||
auto xcursor = makeShared<SXCursors>();
|
||||
SP<SXCursors> CXCursorManager::createCursor(std::string const& shape, void* ximages) {
|
||||
auto xcursor = makeShared<SXCursors>();
|
||||
XcursorImages* xImages = (XcursorImages*)ximages;
|
||||
|
||||
for (int i = 0; i < xImages->nimage; i++) {
|
||||
auto xImage = xImages->images[i];
|
||||
|
|
|
|||
|
|
@ -7,10 +7,6 @@
|
|||
#include <hyprutils/math/Vector2D.hpp>
|
||||
#include "helpers/memory/Memory.hpp"
|
||||
|
||||
extern "C" {
|
||||
#include <X11/Xcursor/Xcursor.h>
|
||||
}
|
||||
|
||||
// gangsta bootleg XCursor impl. adidas balkanized
|
||||
struct SXCursorImage {
|
||||
Hyprutils::Math::Vector2D size;
|
||||
|
|
@ -34,7 +30,7 @@ class CXCursorManager {
|
|||
void syncGsettings();
|
||||
|
||||
private:
|
||||
SP<SXCursors> createCursor(std::string const& shape, XcursorImages* xImages);
|
||||
SP<SXCursors> createCursor(std::string const& shape, void* /* XcursorImages* */ xImages);
|
||||
std::set<std::string> themePaths(std::string const& theme);
|
||||
std::string getLegacyShapeName(std::string const& shape);
|
||||
std::vector<SP<SXCursors>> loadStandardCursors(std::string const& name, int size);
|
||||
|
|
|
|||
|
|
@ -1,55 +1,55 @@
|
|||
#include "EventLoopTimer.hpp"
|
||||
#include <limits>
|
||||
#include "EventLoopManager.hpp"
|
||||
#include "../../helpers/time/Time.hpp"
|
||||
|
||||
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_) {
|
||||
CEventLoopTimer::CEventLoopTimer(std::optional<Time::steady_dur> timeout, std::function<void(SP<CEventLoopTimer> self, void* data)> cb_, void* data_) : m_cb(cb_), m_data(data_) {
|
||||
|
||||
if (!timeout.has_value())
|
||||
expires.reset();
|
||||
m_expires.reset();
|
||||
else
|
||||
expires = std::chrono::steady_clock::now() + *timeout;
|
||||
m_expires = Time::steadyNow() + *timeout;
|
||||
}
|
||||
|
||||
void CEventLoopTimer::updateTimeout(std::optional<std::chrono::steady_clock::duration> timeout) {
|
||||
void CEventLoopTimer::updateTimeout(std::optional<Time::steady_dur> timeout) {
|
||||
if (!timeout.has_value()) {
|
||||
expires.reset();
|
||||
m_expires.reset();
|
||||
g_pEventLoopManager->nudgeTimers();
|
||||
return;
|
||||
}
|
||||
|
||||
expires = std::chrono::steady_clock::now() + *timeout;
|
||||
m_expires = Time::steadyNow() + *timeout;
|
||||
|
||||
g_pEventLoopManager->nudgeTimers();
|
||||
}
|
||||
|
||||
bool CEventLoopTimer::passed() {
|
||||
if (!expires.has_value())
|
||||
if (!m_expires.has_value())
|
||||
return false;
|
||||
return std::chrono::steady_clock::now() > *expires;
|
||||
return Time::steadyNow() > *m_expires;
|
||||
}
|
||||
|
||||
void CEventLoopTimer::cancel() {
|
||||
wasCancelled = true;
|
||||
expires.reset();
|
||||
m_wasCancelled = true;
|
||||
m_expires.reset();
|
||||
}
|
||||
|
||||
bool CEventLoopTimer::cancelled() {
|
||||
return wasCancelled;
|
||||
return m_wasCancelled;
|
||||
}
|
||||
|
||||
void CEventLoopTimer::call(SP<CEventLoopTimer> self) {
|
||||
expires.reset();
|
||||
cb(self, data);
|
||||
m_expires.reset();
|
||||
m_cb(self, m_data);
|
||||
}
|
||||
|
||||
float CEventLoopTimer::leftUs() {
|
||||
if (!expires.has_value())
|
||||
if (!m_expires.has_value())
|
||||
return std::numeric_limits<float>::max();
|
||||
|
||||
return std::chrono::duration_cast<std::chrono::microseconds>(*expires - std::chrono::steady_clock::now()).count();
|
||||
return std::chrono::duration_cast<std::chrono::microseconds>(*m_expires - Time::steadyNow()).count();
|
||||
}
|
||||
|
||||
bool CEventLoopTimer::armed() {
|
||||
return expires.has_value();
|
||||
return m_expires.has_value();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,14 +5,15 @@
|
|||
#include <optional>
|
||||
|
||||
#include "../../helpers/memory/Memory.hpp"
|
||||
#include "../../helpers/time/Time.hpp"
|
||||
|
||||
class CEventLoopTimer {
|
||||
public:
|
||||
CEventLoopTimer(std::optional<std::chrono::steady_clock::duration> timeout, std::function<void(SP<CEventLoopTimer> self, void* data)> cb_, void* data_);
|
||||
CEventLoopTimer(std::optional<Time::steady_dur> 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::steady_clock::duration> timeout);
|
||||
void updateTimeout(std::optional<Time::steady_dur> timeout);
|
||||
|
||||
void cancel();
|
||||
bool passed();
|
||||
|
|
@ -25,8 +26,8 @@ class CEventLoopTimer {
|
|||
void call(SP<CEventLoopTimer> self);
|
||||
|
||||
private:
|
||||
std::function<void(SP<CEventLoopTimer> self, void* data)> cb;
|
||||
void* data = nullptr;
|
||||
std::optional<std::chrono::steady_clock::time_point> expires;
|
||||
bool wasCancelled = false;
|
||||
std::function<void(SP<CEventLoopTimer> self, void* data)> m_cb;
|
||||
void* m_data = nullptr;
|
||||
std::optional<Time::steady_tp> m_expires;
|
||||
bool m_wasCancelled = false;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -36,6 +36,8 @@
|
|||
#include "../../managers/EventManager.hpp"
|
||||
#include "../../managers/LayoutManager.hpp"
|
||||
|
||||
#include "../../helpers/time/Time.hpp"
|
||||
|
||||
#include <aquamarine/input/Input.hpp>
|
||||
|
||||
CInputManager::CInputManager() {
|
||||
|
|
@ -142,10 +144,8 @@ void CInputManager::onMouseWarp(IPointer::SMotionAbsoluteEvent e) {
|
|||
}
|
||||
|
||||
void CInputManager::simulateMouseMovement() {
|
||||
timespec now;
|
||||
clock_gettime(CLOCK_MONOTONIC, &now);
|
||||
m_vLastCursorPosFloored = m_vLastCursorPosFloored - Vector2D(1, 1); // hack: force the mouseMoveUnified to report without making this a refocus.
|
||||
mouseMoveUnified(now.tv_sec * 1000 + now.tv_nsec / 10000000);
|
||||
mouseMoveUnified(Time::millis(Time::steadyNow()));
|
||||
}
|
||||
|
||||
void CInputManager::sendMotionEventsToFocused() {
|
||||
|
|
@ -156,9 +156,6 @@ void CInputManager::sendMotionEventsToFocused() {
|
|||
const auto PWINDOW = g_pCompositor->getWindowFromSurface(g_pCompositor->m_pLastFocus.lock());
|
||||
const auto PLS = g_pCompositor->getLayerSurfaceFromSurface(g_pCompositor->m_pLastFocus.lock());
|
||||
|
||||
timespec now;
|
||||
clock_gettime(CLOCK_MONOTONIC, &now);
|
||||
|
||||
const auto LOCAL = getMouseCoordsInternal() - (PWINDOW ? PWINDOW->m_vRealPosition->goal() : (PLS ? Vector2D{PLS->geometry.x, PLS->geometry.y} : Vector2D{}));
|
||||
|
||||
m_bEmptyFocusCursorSet = false;
|
||||
|
|
@ -1746,11 +1743,8 @@ void CInputManager::releaseAllMouseButtons() {
|
|||
if (PROTO::data->dndActive())
|
||||
return;
|
||||
|
||||
timespec now;
|
||||
clock_gettime(CLOCK_MONOTONIC, &now);
|
||||
|
||||
for (auto const& mb : buttonsCopy) {
|
||||
g_pSeatManager->sendPointerButton(now.tv_sec * 1000 + now.tv_nsec / 1000000, mb, WL_POINTER_BUTTON_STATE_RELEASED);
|
||||
g_pSeatManager->sendPointerButton(Time::millis(Time::steadyNow()), mb, WL_POINTER_BUTTON_STATE_RELEASED);
|
||||
}
|
||||
|
||||
m_lCurrentlyHeldButtons.clear();
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
#include <list>
|
||||
#include <any>
|
||||
#include "../../helpers/WLClasses.hpp"
|
||||
#include "../../helpers/Timer.hpp"
|
||||
#include "../../helpers/time/Timer.hpp"
|
||||
#include "InputMethodRelay.hpp"
|
||||
#include "../../helpers/signal/Signal.hpp"
|
||||
#include "../../devices/IPointer.hpp"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue