time: move to stl's clocks and move timer

This commit is contained in:
Vaxry 2025-04-16 01:37:48 +01:00
parent 0e521788bc
commit 877fb5b93a
43 changed files with 392 additions and 248 deletions

View file

@ -1,4 +1,5 @@
#include "GlobalShortcuts.hpp"
#include "../helpers/time/Time.hpp"
CShortcutClient::CShortcutClient(SP<CHyprlandGlobalShortcutsManagerV1> resource_) : resource(resource_) {
if UNLIKELY (!good())
@ -68,14 +69,13 @@ void CGlobalShortcutsProtocol::sendGlobalShortcutEvent(std::string appid, std::s
for (auto const& c : m_vClients) {
for (auto const& sh : c->shortcuts) {
if (sh->appid == appid && sh->id == trigger) {
timespec now;
clock_gettime(CLOCK_MONOTONIC, &now);
uint32_t tvSecHi = (sizeof(now.tv_sec) > 4) ? now.tv_sec >> 32 : 0;
uint32_t tvSecLo = now.tv_sec & 0xFFFFFFFF;
const auto [sec, nsec] = Time::secNsec(Time::steadyNow());
uint32_t tvSecHi = (sizeof(sec) > 4) ? sec >> 32 : 0;
uint32_t tvSecLo = sec & 0xFFFFFFFF;
if (pressed)
sh->resource->sendPressed(tvSecHi, tvSecLo, now.tv_nsec);
sh->resource->sendPressed(tvSecHi, tvSecLo, nsec);
else
sh->resource->sendReleased(tvSecHi, tvSecLo, now.tv_nsec);
sh->resource->sendReleased(tvSecHi, tvSecLo, nsec);
}
}
}

View file

@ -40,7 +40,7 @@ bool CPresentationFeedback::good() {
return resource->resource();
}
void CPresentationFeedback::sendQueued(SP<CQueuedPresentationData> data, timespec* when, uint32_t untilRefreshNs, uint64_t seq, uint32_t reportedFlags) {
void CPresentationFeedback::sendQueued(SP<CQueuedPresentationData> data, const Time::steady_tp& when, uint32_t untilRefreshNs, uint64_t seq, uint32_t reportedFlags) {
auto client = resource->client();
if LIKELY (PROTO::outputs.contains(data->pMonitor->szName)) {
@ -58,12 +58,14 @@ void CPresentationFeedback::sendQueued(SP<CQueuedPresentationData> data, timespe
if (reportedFlags & Aquamarine::IOutput::AQ_OUTPUT_PRESENT_HW_COMPLETION)
flags |= WP_PRESENTATION_FEEDBACK_KIND_HW_COMPLETION;
time_t tv_sec = 0;
const auto TIMESPEC = Time::toTimespec(when);
time_t tv_sec = 0;
if (sizeof(time_t) > 4)
tv_sec = when->tv_sec >> 32;
tv_sec = TIMESPEC.tv_sec >> 32;
if (data->wasPresented)
resource->sendPresented((uint32_t)tv_sec, (uint32_t)(when->tv_sec & 0xFFFFFFFF), (uint32_t)(when->tv_nsec), untilRefreshNs, (uint32_t)(seq >> 32),
resource->sendPresented((uint32_t)tv_sec, (uint32_t)(TIMESPEC.tv_sec & 0xFFFFFFFF), (uint32_t)(TIMESPEC.tv_nsec), untilRefreshNs, (uint32_t)(seq >> 32),
(uint32_t)(seq & 0xFFFFFFFF), (wpPresentationFeedbackKind)flags);
else
resource->sendDiscarded();
@ -107,15 +109,7 @@ void CPresentationProtocol::onGetFeedback(CWpPresentation* pMgr, wl_resource* su
}
}
void CPresentationProtocol::onPresented(PHLMONITOR pMonitor, timespec* when, uint32_t untilRefreshNs, uint64_t seq, uint32_t reportedFlags) {
timespec now;
timespec* presentedAt = when;
if (!presentedAt) {
// just put the current time, we don't have anything better
clock_gettime(CLOCK_MONOTONIC, &now);
when = &now;
}
void CPresentationProtocol::onPresented(PHLMONITOR pMonitor, const Time::steady_tp& when, uint32_t untilRefreshNs, uint64_t seq, uint32_t reportedFlags) {
for (auto const& feedback : m_vFeedbacks) {
if (!feedback->surface)
continue;

View file

@ -4,6 +4,7 @@
#include <cstdint>
#include "WaylandProtocol.hpp"
#include "presentation-time.hpp"
#include "../helpers/time/Time.hpp"
class CMonitor;
class CWLSurfaceResource;
@ -36,7 +37,7 @@ class CPresentationFeedback {
bool good();
void sendQueued(SP<CQueuedPresentationData> data, timespec* when, uint32_t untilRefreshNs, uint64_t seq, uint32_t reportedFlags);
void sendQueued(SP<CQueuedPresentationData> data, const Time::steady_tp& when, uint32_t untilRefreshNs, uint64_t seq, uint32_t reportedFlags);
private:
SP<CWpPresentationFeedback> resource;
@ -52,7 +53,7 @@ class CPresentationProtocol : public IWaylandProtocol {
virtual void bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id);
void onPresented(PHLMONITOR pMonitor, timespec* when, uint32_t untilRefreshNs, uint64_t seq, uint32_t reportedFlags);
void onPresented(PHLMONITOR pMonitor, const Time::steady_tp& when, uint32_t untilRefreshNs, uint64_t seq, uint32_t reportedFlags);
void queueData(SP<CQueuedPresentationData> data);
private:

View file

@ -11,6 +11,7 @@
#include "types/WLBuffer.hpp"
#include "types/Buffer.hpp"
#include "../helpers/Format.hpp"
#include "../helpers/time/Time.hpp"
#include <algorithm>
#include <functional>
@ -166,10 +167,9 @@ void CScreencopyFrame::share() {
if (!buffer || !pMonitor)
return;
timespec now;
clock_gettime(CLOCK_MONOTONIC, &now);
const auto NOW = Time::steadyNow();
auto callback = [this, now, weak = self](bool success) {
auto callback = [this, NOW, weak = self](bool success) {
if (weak.expired())
return;
@ -185,9 +185,11 @@ void CScreencopyFrame::share() {
resource->sendDamage(0, 0, buffer->size.x, buffer->size.y);
}
uint32_t tvSecHi = (sizeof(now.tv_sec) > 4) ? now.tv_sec >> 32 : 0;
uint32_t tvSecLo = now.tv_sec & 0xFFFFFFFF;
resource->sendReady(tvSecHi, tvSecLo, now.tv_nsec);
const auto [sec, nsec] = Time::secNsec(NOW);
uint32_t tvSecHi = (sizeof(sec) > 4) ? sec >> 32 : 0;
uint32_t tvSecLo = sec & 0xFFFFFFFF;
resource->sendReady(tvSecHi, tvSecLo, nsec);
};
if (bufferDMA)

View file

@ -8,7 +8,8 @@
#include <list>
#include <vector>
#include "../managers/HookSystemManager.hpp"
#include "../helpers/Timer.hpp"
#include "../helpers/time/Timer.hpp"
#include "../helpers/time/Time.hpp"
#include "../managers/eventLoop/EventLoopTimer.hpp"
#include <aquamarine/buffer/Buffer.hpp>
@ -102,7 +103,7 @@ class CScreencopyProtocol : public IWaylandProtocol {
void shareFrame(CScreencopyFrame* frame);
void sendFrameDamage(CScreencopyFrame* frame);
bool copyFrameDmabuf(CScreencopyFrame* frame);
bool copyFrameShm(CScreencopyFrame* frame, timespec* now);
bool copyFrameShm(CScreencopyFrame* frame, const Time::steady_tp& now);
friend class CScreencopyFrame;
friend class CScreencopyClient;

View file

@ -3,6 +3,7 @@
#include "../Compositor.hpp"
#include "../managers/SeatManager.hpp"
#include "../managers/input/InputManager.hpp"
#include "../helpers/time/Time.hpp"
#include "core/Seat.hpp"
#include "core/Compositor.hpp"
#include <algorithm>
@ -222,9 +223,7 @@ void CTabletToolV2Resource::sendFrame(bool removeSource) {
if (!current)
return;
timespec now;
clock_gettime(CLOCK_MONOTONIC, &now);
resource->sendFrame(now.tv_sec * 1000 + now.tv_nsec / 1000000);
resource->sendFrame(Time::millis(Time::steadyNow()));
}
CTabletSeat::CTabletSeat(SP<CZwpTabletSeatV2> resource_) : resource(resource_) {

View file

@ -205,16 +205,13 @@ void CToplevelExportFrame::share() {
if (!buffer || !validMapped(pWindow))
return;
timespec now;
clock_gettime(CLOCK_MONOTONIC, &now);
if (bufferDMA) {
if (!copyDmabuf(&now)) {
if (!copyDmabuf(Time::steadyNow())) {
resource->sendFailed();
return;
}
} else {
if (!copyShm(&now)) {
if (!copyShm(Time::steadyNow())) {
resource->sendFailed();
return;
}
@ -222,16 +219,17 @@ void CToplevelExportFrame::share() {
resource->sendFlags((hyprlandToplevelExportFrameV1Flags)0);
if (!m_ignoreDamage) {
if (!m_ignoreDamage)
resource->sendDamage(0, 0, box.width, box.height);
}
uint32_t tvSecHi = (sizeof(now.tv_sec) > 4) ? now.tv_sec >> 32 : 0;
uint32_t tvSecLo = now.tv_sec & 0xFFFFFFFF;
resource->sendReady(tvSecHi, tvSecLo, now.tv_nsec);
const auto [sec, nsec] = Time::secNsec(Time::steadyNow());
uint32_t tvSecHi = (sizeof(sec) > 4) ? sec >> 32 : 0;
uint32_t tvSecLo = sec & 0xFFFFFFFF;
resource->sendReady(tvSecHi, tvSecLo, nsec);
}
bool CToplevelExportFrame::copyShm(timespec* now) {
bool CToplevelExportFrame::copyShm(const Time::steady_tp& now) {
const auto PERM = g_pDynamicPermissionManager->clientPermissionMode(resource->client(), PERMISSION_TYPE_SCREENCOPY);
auto shm = buffer->shm();
auto [pixelData, fmt, bufLen] = buffer->beginDataPtr(0); // no need for end, cuz it's shm
@ -329,7 +327,7 @@ bool CToplevelExportFrame::copyShm(timespec* now) {
return true;
}
bool CToplevelExportFrame::copyDmabuf(timespec* now) {
bool CToplevelExportFrame::copyDmabuf(const Time::steady_tp& now) {
const auto PERM = g_pDynamicPermissionManager->clientPermissionMode(resource->client(), PERMISSION_TYPE_SCREENCOPY);
const auto PMONITOR = pWindow->m_pMonitor.lock();

View file

@ -4,6 +4,7 @@
#include "hyprland-toplevel-export-v1.hpp"
#include "WaylandProtocol.hpp"
#include "Screencopy.hpp"
#include "../helpers/time/Time.hpp"
#include <vector>
@ -62,8 +63,8 @@ class CToplevelExportFrame {
CBox box = {};
void copy(CHyprlandToplevelExportFrameV1* pFrame, wl_resource* buffer, int32_t ignoreDamage);
bool copyDmabuf(timespec* now);
bool copyShm(timespec* now);
bool copyDmabuf(const Time::steady_tp& now);
bool copyShm(const Time::steady_tp& now);
void share();
bool shouldOverlayCursor() const;
@ -87,8 +88,8 @@ class CToplevelExportProtocol : IWaylandProtocol {
std::vector<WP<CToplevelExportFrame>> m_vFramesAwaitingWrite;
void shareFrame(CToplevelExportFrame* frame);
bool copyFrameDmabuf(CToplevelExportFrame* frame, timespec* now);
bool copyFrameShm(CToplevelExportFrame* frame, timespec* now);
bool copyFrameDmabuf(CToplevelExportFrame* frame, const Time::steady_tp& now);
bool copyFrameShm(CToplevelExportFrame* frame, const Time::steady_tp& now);
void sendDamage(CToplevelExportFrame* frame);
friend class CToplevelExportClient;

View file

@ -1,6 +1,7 @@
#include "VirtualKeyboard.hpp"
#include <sys/mman.h>
#include "../devices/IKeyboard.hpp"
#include "../helpers/time/Time.hpp"
using namespace Hyprutils::OS;
CVirtualKeyboardV1Resource::CVirtualKeyboardV1Resource(SP<CZwpVirtualKeyboardV1> resource_) : resource(resource_) {
@ -103,12 +104,9 @@ wl_client* CVirtualKeyboardV1Resource::client() {
}
void CVirtualKeyboardV1Resource::releasePressed() {
timespec now;
clock_gettime(CLOCK_MONOTONIC, &now);
for (auto const& p : pressed) {
events.key.emit(IKeyboard::SKeyEvent{
.timeMs = now.tv_sec * 1000 + now.tv_nsec / 1000000,
.timeMs = Time::millis(Time::steadyNow()),
.keycode = p,
.state = WL_KEYBOARD_KEY_STATE_RELEASED,
});

View file

@ -33,8 +33,8 @@ bool CWLCallbackResource::good() {
return resource->resource();
}
void CWLCallbackResource::send(timespec* now) {
resource->sendDone(now->tv_sec * 1000 + now->tv_nsec / 1000000);
void CWLCallbackResource::send(const Time::steady_tp& now) {
resource->sendDone(Time::millis(now));
}
CWLRegionResource::CWLRegionResource(SP<CWlRegion> resource_) : resource(resource_) {
@ -323,7 +323,7 @@ void CWLSurfaceResource::sendPreferredScale(int32_t scale) {
resource->sendPreferredBufferScale(scale);
}
void CWLSurfaceResource::frame(timespec* now) {
void CWLSurfaceResource::frame(const Time::steady_tp& now) {
if (callbacks.empty())
return;
@ -436,9 +436,7 @@ void CWLSurfaceResource::map() {
mapped = true;
timespec now;
clock_gettime(CLOCK_MONOTONIC, &now);
frame(&now);
frame(Time::steadyNow());
current.bufferDamage = CBox{{}, {INT32_MAX, INT32_MAX}};
pending.bufferDamage = CBox{{}, {INT32_MAX, INT32_MAX}};
@ -565,7 +563,7 @@ void CWLSurfaceResource::updateCursorShm(CRegion damage) {
}
}
void CWLSurfaceResource::presentFeedback(timespec* when, PHLMONITOR pMonitor, bool discarded) {
void CWLSurfaceResource::presentFeedback(const Time::steady_tp& when, PHLMONITOR pMonitor, bool discarded) {
frame(when);
auto FEEDBACK = makeShared<CQueuedPresentationData>(self.lock());
FEEDBACK->attachMonitor(pMonitor);

View file

@ -16,6 +16,7 @@
#include "wayland.hpp"
#include "../../helpers/signal/Signal.hpp"
#include "../../helpers/math/Math.hpp"
#include "../../helpers/time/Time.hpp"
#include "../types/Buffer.hpp"
#include "../types/SurfaceRole.hpp"
#include "../types/SurfaceState.hpp"
@ -36,7 +37,7 @@ class CWLCallbackResource {
CWLCallbackResource(SP<CWlCallback> resource_);
bool good();
void send(timespec* now);
void send(const Time::steady_tp& now);
private:
SP<CWlCallback> resource;
@ -69,7 +70,7 @@ class CWLSurfaceResource {
void leave(PHLMONITOR monitor);
void sendPreferredTransform(wl_output_transform t);
void sendPreferredScale(int32_t scale);
void frame(timespec* now);
void frame(const Time::steady_tp& now);
uint32_t id();
void map();
void unmap();
@ -104,7 +105,7 @@ class CWLSurfaceResource {
void breadthfirst(std::function<void(SP<CWLSurfaceResource>, const Vector2D&, void*)> fn, void* data);
SP<CWLSurfaceResource> findFirstPreorder(std::function<bool(SP<CWLSurfaceResource>)> fn);
void presentFeedback(timespec* when, PHLMONITOR pMonitor, bool discarded = false);
void presentFeedback(const Time::steady_tp& when, PHLMONITOR pMonitor, bool discarded = false);
void commitState(SSurfaceState& state);
// returns a pair: found surface (null if not found) and surface local coords.

View file

@ -604,10 +604,7 @@ void CWLDataDeviceProtocol::initiateDrag(WP<CWLDataSourceResource> currentSource
if (!box.has_value())
return;
timespec timeNow;
clock_gettime(CLOCK_MONOTONIC, &timeNow);
dnd.focusedDevice->sendMotion(timeNow.tv_sec * 1000 + timeNow.tv_nsec / 1000000, V - box->pos());
dnd.focusedDevice->sendMotion(Time::millis(Time::steadyNow()), V - box->pos());
LOGM(LOG, "Drag motion {}", V - box->pos());
}
});
@ -802,7 +799,7 @@ void CWLDataDeviceProtocol::abortDrag() {
g_pSeatManager->resendEnterEvents();
}
void CWLDataDeviceProtocol::renderDND(PHLMONITOR pMonitor, timespec* when) {
void CWLDataDeviceProtocol::renderDND(PHLMONITOR pMonitor, const Time::steady_tp& when) {
if (!dnd.dndSurface || !dnd.dndSurface->current.texture)
return;

View file

@ -15,6 +15,7 @@
#include "wayland.hpp"
#include "../../helpers/signal/Signal.hpp"
#include "../../helpers/math/Math.hpp"
#include "../../helpers/time/Time.hpp"
#include "../types/DataDevice.hpp"
#include <hyprutils/os/FileDescriptor.hpp>
@ -138,7 +139,7 @@ class CWLDataDeviceProtocol : public IWaylandProtocol {
virtual void bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id);
// renders and damages the dnd icon, if present
void renderDND(PHLMONITOR pMonitor, timespec* when);
void renderDND(PHLMONITOR pMonitor, const Time::steady_tp& when);
// for inputmgr to force refocus
// TODO: move handling to seatmgr
bool dndActive();

View file

@ -4,6 +4,7 @@
#include "../../devices/IKeyboard.hpp"
#include "../../devices/IHID.hpp"
#include "../../managers/SeatManager.hpp"
#include "../../helpers/time/Time.hpp"
#include "../../config/ConfigValue.hpp"
#include <algorithm>
@ -174,10 +175,8 @@ void CWLPointerResource::sendLeave() {
// release all buttons unless we have a dnd going on in which case
// the events shall be lost.
if (!PROTO::data->dndActive()) {
timespec now;
clock_gettime(CLOCK_MONOTONIC, &now);
for (auto const& b : pressedButtons) {
sendButton(now.tv_sec * 1000 + now.tv_nsec / 1000000, b, WL_POINTER_BUTTON_STATE_RELEASED);
sendButton(Time::millis(Time::steadyNow()), b, WL_POINTER_BUTTON_STATE_RELEASED);
}
}