summaryrefslogtreecommitdiff
path: root/src/protocols/core
diff options
context:
space:
mode:
authorVaxry <vaxry@vaxry.net>2025-04-16 01:37:48 +0100
committerVaxry <vaxry@vaxry.net>2025-04-16 01:37:48 +0100
commit877fb5b93ada9b25b4d2f5ca5f69370fa345f1ac (patch)
tree5b52ad19c695590ae50c7adae06b8e3aeccf34c1 /src/protocols/core
parent0e521788bcc414c9cf81648d3167757d83deb60f (diff)
time: move to stl's clocks and move timer
Diffstat (limited to 'src/protocols/core')
-rw-r--r--src/protocols/core/Compositor.cpp12
-rw-r--r--src/protocols/core/Compositor.hpp7
-rw-r--r--src/protocols/core/DataDevice.cpp7
-rw-r--r--src/protocols/core/DataDevice.hpp3
-rw-r--r--src/protocols/core/Seat.cpp5
5 files changed, 15 insertions, 19 deletions
diff --git a/src/protocols/core/Compositor.cpp b/src/protocols/core/Compositor.cpp
index 827ec311..23b14dd3 100644
--- a/src/protocols/core/Compositor.cpp
+++ b/src/protocols/core/Compositor.cpp
@@ -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);
diff --git a/src/protocols/core/Compositor.hpp b/src/protocols/core/Compositor.hpp
index ccfcf0cc..7415b4f5 100644
--- a/src/protocols/core/Compositor.hpp
+++ b/src/protocols/core/Compositor.hpp
@@ -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.
diff --git a/src/protocols/core/DataDevice.cpp b/src/protocols/core/DataDevice.cpp
index d1a98fb5..2915be75 100644
--- a/src/protocols/core/DataDevice.cpp
+++ b/src/protocols/core/DataDevice.cpp
@@ -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;
diff --git a/src/protocols/core/DataDevice.hpp b/src/protocols/core/DataDevice.hpp
index fa5de091..0c53111b 100644
--- a/src/protocols/core/DataDevice.hpp
+++ b/src/protocols/core/DataDevice.hpp
@@ -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();
diff --git a/src/protocols/core/Seat.cpp b/src/protocols/core/Seat.cpp
index f6eee6e1..5faabedc 100644
--- a/src/protocols/core/Seat.cpp
+++ b/src/protocols/core/Seat.cpp
@@ -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);
}
}