[PATCH weston 2/6] libweston: Use the monotonic clock in weston_compositor_get_time

Dima Ryazanov dima at gmail.com
Mon Dec 5 03:36:31 UTC 2016


(This is kind of a workaround, but perhaps the right thing to do anyways.)

The menu implementation in window.c needs to know the time of the event that
triggered the menu - however, the xdg-shell's show_window_menu API does not
give us that info. There doesn't seem to be an easy way to fake it because
different compositors use different times when sending events:
- compositor-drm uses the monotonic clock
- compositor-x11 uses weston_compositor_get_time
- compositor-wayland uses the event times in got from the parent compositor
- GNOME appears to use the monotonic clock

Switching weston_compositor_get_time to use the monotonic clock works around
this issue - though things would break in compositor-wayland if its parent
uses something else.

Signed-off-by: Dima Ryazanov <dima at gmail.com>
---
 libweston/compositor.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/libweston/compositor.c b/libweston/compositor.c
index 6457858..aa4bf345 100644
--- a/libweston/compositor.c
+++ b/libweston/compositor.c
@@ -1693,11 +1693,11 @@ weston_surface_update_size(struct weston_surface *surface)
 WL_EXPORT uint32_t
 weston_compositor_get_time(void)
 {
-       struct timeval tv;
+       struct timespec ts;
 
-       gettimeofday(&tv, NULL);
+       clock_gettime(CLOCK_MONOTONIC, &ts);
 
-       return tv.tv_sec * 1000 + tv.tv_usec / 1000;
+       return ts.tv_sec * 1000 + ts.tv_nsec / 1000000;
 }
 
 WL_EXPORT struct weston_view *
-- 
2.9.3



More information about the wayland-devel mailing list