2 * Copyright © 2017 Collabora, Ltd.
4 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sublicense, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
12 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial
14 * portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
33 #include "input-timestamps-helper.h"
34 #include "protocol/input-timestamps-unstable-v1-client-protocol.h"
35 #include "shared/timespec-util.h"
36 #include "shared/zalloc.h"
37 #include "weston-test-client-helper.h"
39 struct input_timestamps {
40 struct zwp_input_timestamps_v1 *proxy;
43 static struct zwp_input_timestamps_manager_v1 *
44 get_input_timestamps_manager(struct client *client)
47 struct global *global_ts = NULL;
48 struct zwp_input_timestamps_manager_v1 *ts = NULL;
50 wl_list_for_each(g, &client->global_list, link) {
51 if (strcmp(g->interface, zwp_input_timestamps_manager_v1_interface.name))
55 assert(!"Multiple input timestamp managers");
61 assert(global_ts->version == 1);
63 ts = wl_registry_bind(client->wl_registry, global_ts->name,
64 &zwp_input_timestamps_manager_v1_interface, 1);
71 input_timestamp(void *data,
72 struct zwp_input_timestamps_v1 *zwp_input_timestamps_v1,
77 struct timespec *timestamp = data;
79 timespec_from_proto(timestamp, tv_sec_hi, tv_sec_lo,
82 fprintf(stderr, "test-client: got input timestamp %ld.%ld\n",
83 timestamp->tv_sec, timestamp->tv_nsec);
86 static const struct zwp_input_timestamps_v1_listener
87 input_timestamps_listener = {
88 .timestamp = input_timestamp,
91 struct input_timestamps *
92 input_timestamps_create_for_keyboard(struct client *client)
94 struct zwp_input_timestamps_manager_v1 *manager =
95 get_input_timestamps_manager(client);
96 struct timespec *timestamp= &client->input->keyboard->input_timestamp;
97 struct input_timestamps *input_ts;
99 input_ts = zalloc(sizeof *input_ts);
103 zwp_input_timestamps_manager_v1_get_keyboard_timestamps(
104 manager, client->input->keyboard->wl_keyboard);
105 assert(input_ts->proxy);
107 zwp_input_timestamps_v1_add_listener(input_ts->proxy,
108 &input_timestamps_listener,
111 zwp_input_timestamps_manager_v1_destroy(manager);
113 client_roundtrip(client);
118 struct input_timestamps *
119 input_timestamps_create_for_pointer(struct client *client)
121 struct zwp_input_timestamps_manager_v1 *manager =
122 get_input_timestamps_manager(client);
123 struct timespec *timestamp= &client->input->pointer->input_timestamp;
124 struct input_timestamps *input_ts;
126 input_ts = zalloc(sizeof *input_ts);
130 zwp_input_timestamps_manager_v1_get_pointer_timestamps(
131 manager, client->input->pointer->wl_pointer);
132 assert(input_ts->proxy);
134 zwp_input_timestamps_v1_add_listener(input_ts->proxy,
135 &input_timestamps_listener,
138 zwp_input_timestamps_manager_v1_destroy(manager);
140 client_roundtrip(client);
145 struct input_timestamps *
146 input_timestamps_create_for_touch(struct client *client)
148 struct zwp_input_timestamps_manager_v1 *manager =
149 get_input_timestamps_manager(client);
150 struct timespec *timestamp= &client->input->touch->input_timestamp;
151 struct input_timestamps *input_ts;
153 input_ts = zalloc(sizeof *input_ts);
157 zwp_input_timestamps_manager_v1_get_touch_timestamps(
158 manager, client->input->touch->wl_touch);
159 assert(input_ts->proxy);
161 zwp_input_timestamps_v1_add_listener(input_ts->proxy,
162 &input_timestamps_listener,
165 zwp_input_timestamps_manager_v1_destroy(manager);
167 client_roundtrip(client);
173 input_timestamps_destroy(struct input_timestamps *input_ts)
175 zwp_input_timestamps_v1_destroy(input_ts->proxy);