From 407649e599e6d1b3ac35406f89811a1d2dadcca9 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Thu, 22 Dec 2016 11:33:19 +1000 Subject: [PATCH] Add helper function for time to timeval conversion Signed-off-by: Peter Hutterer --- src/evdev-mt-touchpad-buttons.c | 3 +-- src/libinput-util.h | 11 +++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/evdev-mt-touchpad-buttons.c b/src/evdev-mt-touchpad-buttons.c index 358b9ea4..8c374345 100644 --- a/src/evdev-mt-touchpad-buttons.c +++ b/src/evdev-mt-touchpad-buttons.c @@ -1056,8 +1056,7 @@ tp_notify_clickpadbutton(struct tp_dispatch *tp, struct evdev_dispatch *dispatch = tp->buttons.trackpoint->dispatch; struct input_event event; - event.time.tv_sec = time / ms2us(1000); - event.time.tv_usec = time % ms2us(1000); + event.time = us2tv(time); event.type = EV_KEY; event.code = button; event.value = (state == LIBINPUT_BUTTON_STATE_PRESSED) ? 1 : 0; diff --git a/src/libinput-util.h b/src/libinput-util.h index ab485c56..57bcdbb5 100644 --- a/src/libinput-util.h +++ b/src/libinput-util.h @@ -473,6 +473,17 @@ tv2us(const struct timeval *tv) return s2us(tv->tv_sec) + tv->tv_usec; } +static inline struct timeval +us2tv(uint64_t time) +{ + struct timeval tv; + + tv.tv_sec = time / ms2us(1000); + tv.tv_usec = time % ms2us(1000); + + return tv; +} + static inline bool safe_atoi_base(const char *str, int *val, int base) {