mirror of
https://gitlab.freedesktop.org/libinput/libinput.git
synced 2026-05-09 04:48:02 +02:00
util: move libinput_now() into a utility function
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1067>
This commit is contained in:
parent
d3922661ba
commit
02f5faf6f6
2 changed files with 20 additions and 4 deletions
|
|
@ -836,14 +836,15 @@ switch_notify_toggle(struct libinput_device *device,
|
||||||
static inline uint64_t
|
static inline uint64_t
|
||||||
libinput_now(struct libinput *libinput)
|
libinput_now(struct libinput *libinput)
|
||||||
{
|
{
|
||||||
struct timespec ts = { 0, 0 };
|
uint64_t now;
|
||||||
|
int rc = now_in_us(&now);
|
||||||
|
|
||||||
if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0) {
|
if (rc < 0) {
|
||||||
log_error(libinput, "clock_gettime failed: %s\n", strerror(errno));
|
log_error(libinput, "clock_gettime failed: %s\n", strerror(-rc));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return s2us(ts.tv_sec) + ns2us(ts.tv_nsec);
|
return now;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline struct device_float_coords
|
static inline struct device_float_coords
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#include <errno.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
@ -98,6 +99,20 @@ us2tv(uint64_t time)
|
||||||
return tv;
|
return tv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline int
|
||||||
|
now_in_us(uint64_t *us)
|
||||||
|
{
|
||||||
|
struct timespec ts = { 0, 0 };
|
||||||
|
|
||||||
|
if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0) {
|
||||||
|
*us = 0;
|
||||||
|
return -errno;
|
||||||
|
}
|
||||||
|
|
||||||
|
*us = s2us(ts.tv_sec) + ns2us(ts.tv_nsec);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
struct human_time {
|
struct human_time {
|
||||||
unsigned int value;
|
unsigned int value;
|
||||||
const char *unit;
|
const char *unit;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue