mirror of
https://gitlab.freedesktop.org/wlroots/wlroots.git
synced 2026-04-15 08:22:07 -04:00
This feature is meant to be used with VRR / Adaptive Sync. Currently cursor move drives the display at the poll rate of the mouse. This adds a deferred delay for a variety situations: To save power on battery To maintain smooth video playback (i.e. render video 30fps at 60 or 120fps) To maintain smooth gaming experience (i.e. only enforce redraw at VRR minimum Hz) I've tried to make it as unopinionated as possible, while also reducing complexity for downstream developers. The design should be backwards compatible, as long as wlr_set_cursor_max_latency() is never called wlr_cursor_move() should act as normal I considered using wl_signals, but I'm not familiar with the interface, and it felt somewhat overkill. There's a reference implementation in branch deferred-cursor-move: github:YellowOnion/sway
38 lines
898 B
C
38 lines
898 B
C
#define _POSIX_C_SOURCE 200809L
|
|
#include <stdint.h>
|
|
#include <time.h>
|
|
|
|
#include "util/time.h"
|
|
|
|
int64_t timespec_to_msec(const struct timespec *a) {
|
|
return (int64_t)a->tv_sec * 1000 + a->tv_nsec / 1000000;
|
|
}
|
|
|
|
int64_t timespec_to_nsec(const struct timespec *a) {
|
|
return (int64_t)a->tv_sec * NSEC_PER_SEC + a->tv_nsec;
|
|
}
|
|
|
|
void timespec_from_nsec(struct timespec *r, int64_t nsec) {
|
|
r->tv_sec = nsec / NSEC_PER_SEC;
|
|
r->tv_nsec = nsec % NSEC_PER_SEC;
|
|
}
|
|
|
|
int64_t get_current_time_msec(void) {
|
|
struct timespec now;
|
|
clock_gettime(CLOCK_MONOTONIC, &now);
|
|
return timespec_to_msec(&now);
|
|
}
|
|
|
|
void timespec_sub(struct timespec *r, const struct timespec *a,
|
|
const struct timespec *b) {
|
|
r->tv_sec = a->tv_sec - b->tv_sec;
|
|
r->tv_nsec = a->tv_nsec - b->tv_nsec;
|
|
if (r->tv_nsec < 0) {
|
|
r->tv_sec--;
|
|
r->tv_nsec += NSEC_PER_SEC;
|
|
}
|
|
}
|
|
|
|
int32_t mhz_to_nsec(int32_t mhz) {
|
|
return 1000000000000LL / mhz;
|
|
}
|