From 57a1e9207fae7d9a879f5b57b19ad51620fad644 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 7 Dec 2023 15:24:55 +1100 Subject: [PATCH] GHOST/Wayland: use monotonic timer for getMilliSeconds This is closer to Wayland's own time-stamps, using this also allows for optimizations calculating time-stamps from events. --- intern/ghost/intern/GHOST_SystemWayland.cc | 8 ++++++++ intern/ghost/intern/GHOST_SystemWayland.hh | 2 ++ 2 files changed, 10 insertions(+) diff --git a/intern/ghost/intern/GHOST_SystemWayland.cc b/intern/ghost/intern/GHOST_SystemWayland.cc index 813e7cbc88e..469a215b758 100644 --- a/intern/ghost/intern/GHOST_SystemWayland.cc +++ b/intern/ghost/intern/GHOST_SystemWayland.cc @@ -6956,6 +6956,14 @@ uint8_t GHOST_SystemWayland::getNumDisplays() const return display_ ? uint8_t(display_->outputs.size()) : 0; } +uint64_t GHOST_SystemWayland::getMilliSeconds() const +{ + /* Match the timing method used by LIBINPUT, so the result is closer to WAYLAND's time-stamps. */ + struct timespec ts = {0, 0}; + clock_gettime(CLOCK_MONOTONIC, &ts); + return ((uint64_t(ts.tv_sec) * 1000) + (ts.tv_nsec / 1000000)); +} + static GHOST_TSuccess getCursorPositionClientRelative_impl( const GWL_SeatStatePointer *seat_state_pointer, const GHOST_WindowWayland *win, diff --git a/intern/ghost/intern/GHOST_SystemWayland.hh b/intern/ghost/intern/GHOST_SystemWayland.hh index 51126f21cb1..7b4154b8d3f 100644 --- a/intern/ghost/intern/GHOST_SystemWayland.hh +++ b/intern/ghost/intern/GHOST_SystemWayland.hh @@ -154,6 +154,8 @@ class GHOST_SystemWayland : public GHOST_System { uint8_t getNumDisplays() const override; + uint64_t getMilliSeconds() const override; + GHOST_TSuccess getCursorPositionClientRelative(const GHOST_IWindow *window, int32_t &x, int32_t &y) const override;