diff options
author | Tudor Brindus <me@tbrindus.ca> | 2020-06-05 17:50:00 -0400 |
---|---|---|
committer | Simon Ser <contact@emersion.fr> | 2020-06-06 00:09:19 +0200 |
commit | c9c31f803eaebf69481d24ac9355cd1f8d3111d9 (patch) | |
tree | 3ce2ff4a3379b3533778fc5021c12cdadeb1b797 | |
parent | dc13bb827d6b7dd40d76ff6f7f3f06688e7d58a0 (diff) |
util/time: de-duplicate `timespec_to_msec`
-rw-r--r-- | include/util/time.h | 7 | ||||
-rw-r--r-- | types/tablet_v2/wlr_tablet_v2_tool.c | 9 | ||||
-rw-r--r-- | types/wlr_surface.c | 5 | ||||
-rw-r--r-- | util/time.c | 6 |
4 files changed, 15 insertions, 12 deletions
diff --git a/include/util/time.h b/include/util/time.h index a24656a9..d4b5cca7 100644 --- a/include/util/time.h +++ b/include/util/time.h @@ -1,9 +1,16 @@ #ifndef UTIL_TIME_H #define UTIL_TIME_H +#include <time.h> + /** * Get the current time, in milliseconds. */ uint32_t get_current_time_msec(void); +/** + * Convert a timespec to milliseconds. + */ +int64_t timespec_to_msec(const struct timespec *a); + #endif diff --git a/types/tablet_v2/wlr_tablet_v2_tool.c b/types/tablet_v2/wlr_tablet_v2_tool.c index 041139b5..30a3bfae 100644 --- a/types/tablet_v2/wlr_tablet_v2_tool.c +++ b/types/tablet_v2/wlr_tablet_v2_tool.c @@ -4,6 +4,7 @@ #include "tablet-unstable-v2-protocol.h" #include "util/array.h" +#include "util/time.h" #include <assert.h> #include <stdlib.h> #include <types/wlr_tablet_v2.h> @@ -301,16 +302,10 @@ static ssize_t tablet_tool_button_update(struct wlr_tablet_v2_tablet_tool *tool, return i; } -static inline int64_t timespec_to_msec(const struct timespec *a) { - return (int64_t)a->tv_sec * 1000 + a->tv_nsec / 1000000; -} - static void send_tool_frame(void *data) { struct wlr_tablet_tool_client_v2 *tool = data; - struct timespec now; - clock_gettime(CLOCK_MONOTONIC, &now); - zwp_tablet_tool_v2_send_frame(tool->resource, timespec_to_msec(&now)); + zwp_tablet_tool_v2_send_frame(tool->resource, get_current_time_msec()); tool->frame_source = NULL; } diff --git a/types/wlr_surface.c b/types/wlr_surface.c index 5cf119a8..d741d119 100644 --- a/types/wlr_surface.c +++ b/types/wlr_surface.c @@ -11,6 +11,7 @@ #include <wlr/util/log.h> #include <wlr/util/region.h> #include "util/signal.h" +#include "util/time.h" #define CALLBACK_VERSION 1 #define SURFACE_VERSION 4 @@ -1062,10 +1063,6 @@ void wlr_surface_send_leave(struct wlr_surface *surface, } } -static inline int64_t timespec_to_msec(const struct timespec *a) { - return (int64_t)a->tv_sec * 1000 + a->tv_nsec / 1000000; -} - void wlr_surface_send_frame_done(struct wlr_surface *surface, const struct timespec *when) { struct wl_resource *resource, *tmp; diff --git a/util/time.c b/util/time.c index b2333921..a47fc613 100644 --- a/util/time.c +++ b/util/time.c @@ -4,8 +4,12 @@ #include "util/time.h" +int64_t timespec_to_msec(const struct timespec *a) { + return (int64_t)a->tv_sec * 1000 + a->tv_nsec / 1000000; +} + uint32_t get_current_time_msec(void) { struct timespec now; clock_gettime(CLOCK_MONOTONIC, &now); - return now.tv_sec * 1000 + now.tv_nsec / 1000000; + return timespec_to_msec(&now); } |