Extract time functions into own module
parent
61657c97ba
commit
baad0ecd68
|
@ -0,0 +1,16 @@
|
||||||
|
#include <time.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
static inline double gettime_s(void)
|
||||||
|
{
|
||||||
|
struct timespec ts = { 0 };
|
||||||
|
clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||||
|
return (double)ts.tv_sec + (double)ts.tv_nsec / 1.0e-9;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline uint32_t gettime_ms(void)
|
||||||
|
{
|
||||||
|
struct timespec ts = { 0 };
|
||||||
|
clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||||
|
return ts.tv_sec * 1000UL + ts.tv_nsec / 1000000UL;
|
||||||
|
}
|
|
@ -17,18 +17,11 @@
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <wayland-client-protocol.h>
|
#include <wayland-client-protocol.h>
|
||||||
#include <wayland-client.h>
|
#include <wayland-client.h>
|
||||||
#include <time.h>
|
|
||||||
#include <linux/input-event-codes.h>
|
#include <linux/input-event-codes.h>
|
||||||
|
|
||||||
#include "pointer.h"
|
#include "pointer.h"
|
||||||
#include "wlr-virtual-pointer-unstable-v1.h"
|
#include "wlr-virtual-pointer-unstable-v1.h"
|
||||||
|
#include "time-util.h"
|
||||||
static inline uint32_t gettime_ms(void)
|
|
||||||
{
|
|
||||||
struct timespec ts = { 0 };
|
|
||||||
clock_gettime(CLOCK_MONOTONIC, &ts);
|
|
||||||
return ts.tv_sec * 1000UL + ts.tv_nsec / 1000000UL;
|
|
||||||
}
|
|
||||||
|
|
||||||
int pointer_init(struct pointer* self)
|
int pointer_init(struct pointer* self)
|
||||||
{
|
{
|
||||||
|
|
11
src/smooth.c
11
src/smooth.c
|
@ -15,20 +15,13 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "smooth.h"
|
#include "smooth.h"
|
||||||
|
#include "time-util.h"
|
||||||
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <time.h>
|
|
||||||
|
|
||||||
static inline double smooth__gettime(void)
|
|
||||||
{
|
|
||||||
struct timespec ts = { 0 };
|
|
||||||
clock_gettime(CLOCK_MONOTONIC, &ts);
|
|
||||||
return (double)ts.tv_sec + (double)ts.tv_nsec / 1.0e-9;
|
|
||||||
}
|
|
||||||
|
|
||||||
double smooth(struct smooth* self, double input)
|
double smooth(struct smooth* self, double input)
|
||||||
{
|
{
|
||||||
double now = smooth__gettime();
|
double now = gettime_s();
|
||||||
double dt = now - self->last_time;
|
double dt = now - self->last_time;
|
||||||
self->last_time = now;
|
self->last_time = now;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue