util: fix and move get_current_time_msec into a util file

This commit makes `get_current_time_msec` correctly return milliseconds
as opposed to microseconds. It also considers the value of `tv_sec`, so
we don't lose occasionally go back in time by one second. Finally, the
function is moved into `util/time.cc` so that it can be reused elsewhere
without having to consider these pitfalls.
This commit is contained in:
Tudor Brindus 2020-06-05 17:44:30 -04:00 committed by Simon Ser
parent dcae6f1431
commit dc13bb827d
5 changed files with 23 additions and 12 deletions

View file

@ -20,6 +20,7 @@
#include "relative-pointer-unstable-v1-client-protocol.h"
#include "backend/wayland.h"
#include "util/signal.h"
#include "util/time.h"
static struct wlr_wl_pointer *output_get_pointer(struct wlr_wl_output *output) {
struct wlr_input_device *wlr_dev;
@ -197,12 +198,6 @@ static void keyboard_handle_keymap(void *data, struct wl_keyboard *wl_keyboard,
close(fd);
}
static uint32_t get_current_time_msec(void) {
struct timespec now;
clock_gettime(CLOCK_MONOTONIC, &now);
return now.tv_nsec / 1000;
}
static void keyboard_handle_enter(void *data, struct wl_keyboard *wl_keyboard,
uint32_t serial, struct wl_surface *surface, struct wl_array *keys) {
struct wlr_input_device *dev = data;