summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKristian Høgsberg <krh@bitplanet.net>2010-12-06 16:56:28 -0500
committerKristian Høgsberg <krh@bitplanet.net>2010-12-06 16:56:28 -0500
commitab8475cafd730fb5b762dd3bcf9b7ae5d7a0f9ba (patch)
tree381c8c81a15cc91de997b103f2bfb9631b8993dc
parentc551bd2ae8bbb4cec52fd9576a217ae5e2cef43a (diff)
Move get_time() helper to core
We'll need a better strategy for generating timestamps without input events or pageflips. At least we'll need to ensure everybody is using the same underlying time source.
-rw-r--r--compositor/compositor.c24
-rw-r--r--wayland/wayland-server.c11
-rw-r--r--wayland/wayland-server.h3
3 files changed, 23 insertions, 15 deletions
diff --git a/compositor/compositor.c b/compositor/compositor.c
index 7b1adec..8fadf76 100644
--- a/compositor/compositor.c
+++ b/compositor/compositor.c
@@ -28,7 +28,6 @@
#include <unistd.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <math.h>
-#include <time.h>
#include <linux/input.h>
#include "wayland-server-protocol.h"
@@ -568,16 +567,6 @@ shell_resize(struct wl_client *client, struct wl_shell *shell,
wlsc_input_device_set_pointer_image(wd, pointer);
}
-static uint32_t
-get_time(void)
-{
- struct timeval tv;
-
- gettimeofday(&tv, NULL);
-
- return tv.tv_sec * 1000 + tv.tv_usec / 1000;
-}
-
struct wlsc_drag {
struct wl_drag drag;
struct wl_listener listener;
@@ -607,7 +596,8 @@ drag_handle_surface_destroy(struct wl_listener *listener,
{
struct wlsc_drag *drag =
container_of(listener, struct wlsc_drag, listener);
- uint32_t time = get_time();
+ uint32_t time =
+ wl_display_get_time(wl_client_get_display(surface->client));
if (drag->drag.pointer_focus == surface)
wl_drag_set_pointer_focus(&drag->drag, NULL, time, 0, 0, 0, 0);
@@ -1139,11 +1129,13 @@ drag_cancel(struct wl_client *client, struct wl_drag *drag)
{
struct wlsc_input_device *device =
(struct wlsc_input_device *) drag->input_device;
+ uint32_t time;
if (drag->source == NULL || drag->source->client != client)
return;
- wlsc_input_device_end_grab(device, get_time());
+ time = wl_display_get_time(wl_client_get_display(client));
+ wlsc_input_device_end_grab(device, time);
device->drag = NULL;
}
@@ -1157,11 +1149,12 @@ static void
lose_pointer_focus(struct wl_listener *listener,
struct wl_surface *surface)
{
- uint32_t time = get_time();
struct wlsc_input_device *device =
container_of(listener, struct wlsc_input_device,
input_device.pointer_focus_listener);
+ uint32_t time;
+ time = wl_display_get_time(wl_client_get_display(surface->client));
wl_input_device_set_pointer_focus(&device->input_device,
NULL, time, 0, 0, 0, 0);
wlsc_input_device_end_grab(device, time);
@@ -1171,11 +1164,12 @@ static void
lose_keyboard_focus(struct wl_listener *listener,
struct wl_surface *surface)
{
- uint32_t time = get_time();
struct wlsc_input_device *device =
container_of(listener, struct wlsc_input_device,
input_device.keyboard_focus_listener);
+ uint32_t time;
+ time = wl_display_get_time(wl_client_get_display(surface->client));
wl_input_device_set_keyboard_focus(&device->input_device, NULL, time);
}
diff --git a/wayland/wayland-server.c b/wayland/wayland-server.c
index 487bddc..7a0268f 100644
--- a/wayland/wayland-server.c
+++ b/wayland/wayland-server.c
@@ -32,6 +32,7 @@
#include <sys/un.h>
#include <dlfcn.h>
#include <assert.h>
+#include <sys/time.h>
#include <ffi.h>
#include "wayland-server.h"
@@ -484,6 +485,16 @@ wl_display_destroy(struct wl_display *display)
free(display);
}
+WL_EXPORT uint32_t
+wl_display_get_time(struct wl_display *display)
+{
+ struct timeval tv;
+
+ gettimeofday(&tv, NULL);
+
+ return tv.tv_sec * 1000 + tv.tv_usec / 1000;
+}
+
WL_EXPORT void
wl_display_add_object(struct wl_display *display, struct wl_object *object)
{
diff --git a/wayland/wayland-server.h b/wayland/wayland-server.h
index 15a02a4..6f4b2ce 100644
--- a/wayland/wayland-server.h
+++ b/wayland/wayland-server.h
@@ -177,6 +177,9 @@ wl_display_set_compositor(struct wl_display *display,
struct wl_compositor *compositor,
const struct wl_compositor_interface *implementation);
+uint32_t
+wl_display_get_time(struct wl_display *display);
+
void
wl_display_post_frame(struct wl_display *display, uint32_t msecs);