Introduce code to support the implementation of the
input_timestamps_unstable_v1 protocol in libweston. This commit does not
implement the actual timestamp subscriptions, but lays the foundation so
timestamp subscriptions for keyboard/pointer/touch can be added cleanly
in upcoming commits.

Signed-off-by: Alexandros Frantzis <alexandros.frant...@collabora.com>
---
 Makefile.am       |   4 +-
 libweston/input.c | 115 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 118 insertions(+), 1 deletion(-)

diff --git a/Makefile.am b/Makefile.am
index 0b616c11..823e9845 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -181,7 +181,9 @@ nodist_libweston_@LIBWESTON_MAJOR@_la_SOURCES =             
                \
        protocol/relative-pointer-unstable-v1-protocol.c                \
        protocol/relative-pointer-unstable-v1-server-protocol.h         \
        protocol/pointer-constraints-unstable-v1-protocol.c             \
-       protocol/pointer-constraints-unstable-v1-server-protocol.h
+       protocol/pointer-constraints-unstable-v1-server-protocol.h      \
+       protocol/input-timestamps-unstable-v1-protocol.c                \
+       protocol/input-timestamps-unstable-v1-server-protocol.h
 
 BUILT_SOURCES += $(nodist_libweston_@LIBWESTON_MAJOR@_la_SOURCES)
 
diff --git a/libweston/input.c b/libweston/input.c
index 94a3423a..a682fa94 100644
--- a/libweston/input.c
+++ b/libweston/input.c
@@ -42,6 +42,7 @@
 #include "compositor.h"
 #include "relative-pointer-unstable-v1-server-protocol.h"
 #include "pointer-constraints-unstable-v1-server-protocol.h"
+#include "input-timestamps-unstable-v1-server-protocol.h"
 
 enum pointer_constraint_type {
        POINTER_CONSTRAINT_TYPE_LOCK,
@@ -86,6 +87,42 @@ region_init_infinite(pixman_region32_t *region)
                                  UINT32_MAX, UINT32_MAX);
 }
 
+static void
+send_timestamp(struct wl_resource *resource,
+              const struct timespec *time)
+{
+       uint32_t tv_sec_hi, tv_sec_lo, tv_nsec;
+
+       timespec_to_proto(time, &tv_sec_hi, &tv_sec_lo, &tv_nsec);
+       zwp_input_timestamps_v1_send_timestamp(resource, tv_sec_hi, tv_sec_lo,
+                                              tv_nsec);
+}
+
+static void
+send_timestamps_for_input_resource(struct wl_resource *input_resource,
+                                  struct wl_list *list,
+                                  const struct timespec *time)
+{
+       struct wl_resource *resource;
+
+       wl_resource_for_each(resource, list) {
+               if (wl_resource_get_user_data(resource) == input_resource)
+                       send_timestamp(resource, time);
+       }
+}
+
+static void
+remove_input_resource_from_timestamps(struct wl_resource *input_resource,
+                                     struct wl_list *list)
+{
+       struct wl_resource *resource;
+
+       wl_resource_for_each(resource, list) {
+               if (wl_resource_get_user_data(resource) == input_resource)
+                       wl_resource_set_user_data(resource, NULL);
+       }
+}
+
 static struct weston_pointer_client *
 weston_pointer_client_create(struct wl_client *client)
 {
@@ -4493,6 +4530,79 @@ bind_pointer_constraints(struct wl_client *client, void 
*data,
                                       NULL, NULL);
 }
 
+static void
+input_timestamps_destroy(struct wl_client *client,
+                        struct wl_resource *resource)
+{
+       wl_resource_destroy(resource);
+}
+
+static const struct zwp_input_timestamps_v1_interface
+                               input_timestamps_interface = {
+       input_timestamps_destroy,
+};
+
+static void
+input_timestamps_manager_destroy(struct wl_client *client,
+                                struct wl_resource *resource)
+{
+       wl_resource_destroy(resource);
+}
+
+static void
+input_timestamps_manager_get_keyboard_timestamps(struct wl_client *client,
+                                                struct wl_resource *resource,
+                                                uint32_t id,
+                                                struct wl_resource 
*keyboard_resource)
+{
+       wl_client_post_no_memory(client);
+}
+
+static void
+input_timestamps_manager_get_pointer_timestamps(struct wl_client *client,
+                                               struct wl_resource *resource,
+                                               uint32_t id,
+                                               struct wl_resource 
*pointer_resource)
+{
+       wl_client_post_no_memory(client);
+}
+
+static void
+input_timestamps_manager_get_touch_timestamps(struct wl_client *client,
+                                             struct wl_resource *resource,
+                                             uint32_t id,
+                                             struct wl_resource 
*touch_resource)
+{
+       wl_client_post_no_memory(client);
+}
+
+static const struct zwp_input_timestamps_manager_v1_interface
+                               input_timestamps_manager_interface = {
+       input_timestamps_manager_destroy,
+       input_timestamps_manager_get_keyboard_timestamps,
+       input_timestamps_manager_get_pointer_timestamps,
+       input_timestamps_manager_get_touch_timestamps,
+};
+
+static void
+bind_input_timestamps_manager(struct wl_client *client, void *data,
+                             uint32_t version, uint32_t id)
+{
+       struct wl_resource *resource =
+               wl_resource_create(client,
+                                  &zwp_input_timestamps_manager_v1_interface,
+                                  1, id);
+
+       if (resource == NULL) {
+               wl_client_post_no_memory(client);
+               return;
+       }
+
+       wl_resource_set_implementation(resource,
+                                      &input_timestamps_manager_interface,
+                                      NULL, NULL);
+}
+
 int
 weston_input_init(struct weston_compositor *compositor)
 {
@@ -4506,5 +4616,10 @@ weston_input_init(struct weston_compositor *compositor)
                              NULL, bind_pointer_constraints))
                return -1;
 
+       if (!wl_global_create(compositor->wl_display,
+                             &zwp_input_timestamps_manager_v1_interface, 1,
+                             NULL, bind_input_timestamps_manager))
+               return -1;
+
        return 0;
 }
-- 
2.14.1

_______________________________________________
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel

Reply via email to