Signed-off-by: Peter Hutterer <peter.hutte...@who-t.net>
---
 src/evdev.c            |  7 +------
 src/libinput-private.h | 15 +++++++++++++++
 src/libinput-util.h    |  1 +
 src/timer.c            | 29 ++++++++---------------------
 4 files changed, 25 insertions(+), 27 deletions(-)

diff --git a/src/evdev.c b/src/evdev.c
index e24e268..721238f 100644
--- a/src/evdev.c
+++ b/src/evdev.c
@@ -1135,16 +1135,11 @@ static void
 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) {
diff --git a/src/libinput-private.h b/src/libinput-private.h
index 9e084dd..cb90a15 100644
--- a/src/libinput-private.h
+++ b/src/libinput-private.h
@@ -23,6 +23,8 @@
 #ifndef LIBINPUT_PRIVATE_H
 #define LIBINPUT_PRIVATE_H
 
+#include <errno.h>
+
 #include "linux/input.h"
 
 #include "libinput.h"
@@ -229,4 +231,17 @@ touch_notify_touch_up(struct libinput_device *device,
 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 */
diff --git a/src/libinput-util.h b/src/libinput-util.h
index f807210..51759e8 100644
--- a/src/libinput-util.h
+++ b/src/libinput-util.h
@@ -26,6 +26,7 @@
 #include <unistd.h>
 #include <math.h>
 #include <string.h>
+#include <time.h>
 
 #include "libinput.h"
 
diff --git a/src/timer.c b/src/timer.c
index ad0fd7c..f6c8e42 100644
--- a/src/timer.c
+++ b/src/timer.c
@@ -67,19 +67,12 @@ void
 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);
@@ -107,17 +100,11 @@ libinput_timer_handler(void *data)
 {
        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) {
-- 
1.9.3

_______________________________________________
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/wayland-devel

Reply via email to