Add helper function for time to timeval conversion

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
Peter Hutterer 2016-12-22 11:33:19 +10:00
parent 4ed0f7ee0e
commit 407649e599
2 changed files with 12 additions and 2 deletions

View file

@ -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;

View file

@ -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)
{