release_pressed_keys(struct evdev_device *device)
{
struct libinput *libinput = device->base.seat->libinput;
- struct timespec ts;
uint64_t time;
int code;
- if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0) {
- log_bug_libinput(libinput, "clock_gettime: %s\n", strerror(errno));
+ if ((time = libinput_now(libinput)) == 0)
return;
- }
-
- time = ts.tv_sec * 1000ULL + ts.tv_nsec / 1000000;
for (code = 0; code < KEY_CNT; code++) {
if (get_key_down_count(device, code) > 0) {
#ifndef LIBINPUT_PRIVATE_H
#define LIBINPUT_PRIVATE_H
+#include <errno.h>
+
#include "linux/input.h"
#include "libinput.h"
void
touch_notify_frame(struct libinput_device *device,
uint32_t time);
+
+static inline uint64_t
+libinput_now(struct libinput *libinput)
+{
+ struct timespec ts = { 0, 0 };
+
+ if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0) {
+ log_error(libinput, "clock_gettime failed: %s\n", strerror(errno));
+ return 0;
+ }
+
+ return ts.tv_sec * 1000ULL + ts.tv_nsec / 1000000;
+}
#endif /* LIBINPUT_PRIVATE_H */
libinput_timer_set(struct libinput_timer *timer, uint64_t expire)
{
#ifndef NDEBUG
- struct timespec ts;
-
- if (clock_gettime(CLOCK_MONOTONIC, &ts) == 0) {
- uint64_t now = ts.tv_sec * 1000ULL + ts.tv_nsec / 1000000;
- if (abs(expire - now) > 5000)
- log_bug_libinput(timer->libinput,
- "timer offset more than 5s, now %"
- PRIu64 " expire %" PRIu64 "\n",
- now, expire);
- } else {
- log_error(timer->libinput,
- "clock_gettime error: %s\n", strerror(errno));
- }
+ uint64_t now = libinput_now(timer->libinput);
+ if (abs(expire - now) > 5000)
+ log_bug_libinput(timer->libinput,
+ "timer offset more than 5s, now %"
+ PRIu64 " expire %" PRIu64 "\n",
+ now, expire);
#endif
assert(expire);
{
struct libinput *libinput = data;
struct libinput_timer *timer, *tmp;
- struct timespec ts;
uint64_t now;
- int r;
- r = clock_gettime(CLOCK_MONOTONIC, &ts);
- if (r) {
- log_error(libinput, "clock_gettime error: %s\n", strerror(errno));
+ now = libinput_now(libinput);
+ if (now == 0)
return;
- }
-
- now = ts.tv_sec * 1000ULL + ts.tv_nsec / 1000000;
list_for_each_safe(timer, tmp, &libinput->timer.list, link) {
if (timer->expire <= now) {