mirror of
https://gitlab.freedesktop.org/libinput/libinput.git
synced 2026-01-06 18:50:12 +01:00
Add a helper function for clock_gettime
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Reviewed-by: Hans de Goede <hdegoede@redhat.com>
This commit is contained in:
parent
87c8d82ac5
commit
e9239d81a9
4 changed files with 25 additions and 27 deletions
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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 */
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@
|
|||
#include <unistd.h>
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "libinput.h"
|
||||
|
||||
|
|
|
|||
29
src/timer.c
29
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) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue