summaryrefslogtreecommitdiff
path: root/src/protocols
diff options
context:
space:
mode:
Diffstat (limited to 'src/protocols')
-rw-r--r--src/protocols/GlobalShortcuts.cpp12
-rw-r--r--src/protocols/PresentationTime.cpp20
-rw-r--r--src/protocols/PresentationTime.hpp5
-rw-r--r--src/protocols/Screencopy.cpp14
-rw-r--r--src/protocols/Screencopy.hpp5
-rw-r--r--src/protocols/Tablet.cpp5
-rw-r--r--src/protocols/ToplevelExport.cpp22
-rw-r--r--src/protocols/ToplevelExport.hpp9
-rw-r--r--src/protocols/VirtualKeyboard.cpp6
-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
14 files changed, 61 insertions, 71 deletions
diff --git a/src/protocols/GlobalShortcuts.cpp b/src/protocols/GlobalShortcuts.cpp
index 9f8f422c..04e4e091 100644
--- a/src/protocols/GlobalShortcuts.cpp
+++ b/src/protocols/GlobalShortcuts.cpp
@@ -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);
}
}
}
diff --git a/src/protocols/PresentationTime.cpp b/src/protocols/PresentationTime.cpp
index 05fda8ea..b8f06cd3 100644
--- a/src/protocols/PresentationTime.cpp
+++ b/src/protocols/PresentationTime.cpp
@@ -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;
diff --git a/src/protocols/PresentationTime.hpp b/src/protocols/PresentationTime.hpp
index 03b59b89..aa93068b 100644
--- a/src/protocols/PresentationTime.hpp
+++ b/src/protocols/PresentationTime.hpp
@@ -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:
diff --git a/src/protocols/Screencopy.cpp b/src/protocols/Screencopy.cpp
index d5a5f816..11aa5957 100644
--- a/src/protocols/Screencopy.cpp
+++ b/src/protocols/Screencopy.cpp
@@ -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)
diff --git a/src/protocols/Screencopy.hpp b/src/protocols/Screencopy.hpp
index 99dbcc2b..2d3ccab0 100644
--- a/src/protocols/Screencopy.hpp
+++ b/src/protocols/Screencopy.hpp
@@ -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;
diff --git a/src/protocols/Tablet.cpp b/src/protocols/Tablet.cpp
index de2ed71b..449fb576 100644
--- a/src/protocols/Tablet.cpp
+++ b/src/protocols/Tablet.cpp
@@ -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_) {
diff --git a/src/protocols/ToplevelExport.cpp b/src/protocols/ToplevelExport.cpp
index 8f18afbc..fc0dc9d5 100644
--- a/src/protocols/ToplevelExport.cpp
+++ b/src/protocols/ToplevelExport.cpp
@@ -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();
diff --git a/src/protocols/ToplevelExport.hpp b/src/protocols/ToplevelExport.hpp
index 21aafde5..907f6236 100644
--- a/src/protocols/ToplevelExport.hpp
+++ b/src/protocols/ToplevelExport.hpp
@@ -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;
diff --git a/src/protocols/VirtualKeyboard.cpp b/src/protocols/VirtualKeyboard.cpp
index 00aca041..e57d66c8 100644
--- a/src/protocols/VirtualKeyboard.cpp
+++ b/src/protocols/VirtualKeyboard.cpp
@@ -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,
});
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);
}
}