summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Hutterer <peter.hutterer@who-t.net>2024-10-21 11:07:14 +1000
committerMarge Bot <emma+marge@anholt.net>2024-10-30 23:20:42 +0000
commit02f5faf6f6763495a05036faceebfbd4c5a5a203 (patch)
treeb8f49952e7e3a45e143e12a0dcacca30f28d6974
parentd3922661bac7afb6cd7a05494b9cde526d4d3229 (diff)
util: move libinput_now() into a utility function
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1067>
-rw-r--r--src/libinput-private.h9
-rw-r--r--src/util-time.h15
2 files changed, 20 insertions, 4 deletions
diff --git a/src/libinput-private.h b/src/libinput-private.h
index 3038d155..dd526cb0 100644
--- a/src/libinput-private.h
+++ b/src/libinput-private.h
@@ -836,14 +836,15 @@ switch_notify_toggle(struct libinput_device *device,
static inline uint64_t
libinput_now(struct libinput *libinput)
{
- struct timespec ts = { 0, 0 };
+ uint64_t now;
+ int rc = now_in_us(&now);
- if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0) {
- log_error(libinput, "clock_gettime failed: %s\n", strerror(errno));
+ if (rc < 0) {
+ log_error(libinput, "clock_gettime failed: %s\n", strerror(-rc));
return 0;
}
- return s2us(ts.tv_sec) + ns2us(ts.tv_nsec);
+ return now;
}
static inline struct device_float_coords
diff --git a/src/util-time.h b/src/util-time.h
index ec1f9937..e534fcea 100644
--- a/src/util-time.h
+++ b/src/util-time.h
@@ -26,6 +26,7 @@
#include "config.h"
#include <assert.h>
+#include <errno.h>
#include <time.h>
#include <stdint.h>
#include <unistd.h>
@@ -98,6 +99,20 @@ us2tv(uint64_t time)
return tv;
}
+static inline int
+now_in_us(uint64_t *us)
+{
+ struct timespec ts = { 0, 0 };
+
+ if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0) {
+ *us = 0;
+ return -errno;
+ }
+
+ *us = s2us(ts.tv_sec) + ns2us(ts.tv_nsec);
+ return 0;
+}
+
struct human_time {
unsigned int value;
const char *unit;