blob: 0eb589d939c4b3e1985a85321a140c4b12abe82e [file] [log] [blame]
Philipp Brüschweiler585acb02012-08-15 17:12:00 +02001/*
2 * Copyright © 2012 Philipp Brüschweiler
3 *
Bryce Harrington1f6b0d12015-06-10 22:48:59 -07004 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
Philipp Brüschweiler585acb02012-08-15 17:12:00 +020010 *
Bryce Harrington1f6b0d12015-06-10 22:48:59 -070011 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
Philipp Brüschweiler585acb02012-08-15 17:12:00 +020022 */
23
U. Artie Eoff86c68b32014-01-15 13:02:28 -080024#include "config.h"
25
26#include <errno.h>
Philipp Brüschweiler585acb02012-08-15 17:12:00 +020027#include <stdbool.h>
28#include <stdio.h>
29#include <stdlib.h>
30#include <string.h>
Pekka Paalanen93a6afd2014-09-23 22:08:44 -040031#include <time.h>
Philipp Brüschweiler585acb02012-08-15 17:12:00 +020032
33#include <wayland-client.h>
34
Jon Cruz4678bab2015-06-15 15:37:07 -070035#include "shared/os-compatibility.h"
Pekka Paalanen93a6afd2014-09-23 22:08:44 -040036#include "presentation_timing-client-protocol.h"
37
38#define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0])
Philipp Brüschweiler585acb02012-08-15 17:12:00 +020039
Jonny Lamb06959082014-08-12 14:58:27 +020040#define MIN(x,y) (((x) < (y)) ? (x) : (y))
41
Philipp Brüschweiler585acb02012-08-15 17:12:00 +020042typedef void (*print_info_t)(void *info);
U. Artie Eoff86c68b32014-01-15 13:02:28 -080043typedef void (*destroy_info_t)(void *info);
Philipp Brüschweiler585acb02012-08-15 17:12:00 +020044
45struct global_info {
46 struct wl_list link;
47
48 uint32_t id;
49 uint32_t version;
50 char *interface;
51
52 print_info_t print;
U. Artie Eoff86c68b32014-01-15 13:02:28 -080053 destroy_info_t destroy;
Philipp Brüschweiler585acb02012-08-15 17:12:00 +020054};
55
Philipp Brüschweiler97cb62a2012-08-15 21:57:24 +020056struct output_mode {
57 struct wl_list link;
58
59 uint32_t flags;
60 int32_t width, height;
61 int32_t refresh;
62};
63
Philipp Brüschweiler585acb02012-08-15 17:12:00 +020064struct output_info {
65 struct global_info global;
66
67 struct wl_output *output;
68
69 struct {
70 int32_t x, y;
71 int32_t physical_width, physical_height;
72 enum wl_output_subpixel subpixel;
73 enum wl_output_transform output_transform;
74 char *make;
75 char *model;
76 } geometry;
77
Philipp Brüschweiler97cb62a2012-08-15 21:57:24 +020078 struct wl_list modes;
Philipp Brüschweiler585acb02012-08-15 17:12:00 +020079};
80
81struct shm_format {
82 struct wl_list link;
83
84 uint32_t format;
85};
86
87struct shm_info {
88 struct global_info global;
89 struct wl_shm *shm;
90
91 struct wl_list formats;
92};
93
94struct seat_info {
95 struct global_info global;
96 struct wl_seat *seat;
Jonny Lamb06959082014-08-12 14:58:27 +020097 struct weston_info *info;
Philipp Brüschweiler585acb02012-08-15 17:12:00 +020098
99 uint32_t capabilities;
Rob Bradford14a76012013-05-31 18:09:52 +0100100 char *name;
Jonny Lamb06959082014-08-12 14:58:27 +0200101
102 int32_t repeat_rate;
103 int32_t repeat_delay;
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200104};
105
Pekka Paalanen93a6afd2014-09-23 22:08:44 -0400106struct presentation_info {
107 struct global_info global;
108 struct presentation *presentation;
109
110 clockid_t clk_id;
111};
112
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200113struct weston_info {
114 struct wl_display *display;
Kristian Høgsbergfa80e112012-10-10 21:34:26 -0400115 struct wl_registry *registry;
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200116
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200117 struct wl_list infos;
Philipp Brüschweilerbb0d4b92012-08-15 21:57:23 +0200118 bool roundtrip_needed;
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200119};
120
Kristian Høgsberg06b16c22013-08-15 14:20:53 -0700121static void *
U. Artie Eoff86c68b32014-01-15 13:02:28 -0800122fail_on_null(void *p)
Kristian Høgsberg06b16c22013-08-15 14:20:53 -0700123{
Kristian Høgsberg06b16c22013-08-15 14:20:53 -0700124 if (p == NULL) {
U. Artie Eoff86c68b32014-01-15 13:02:28 -0800125 fprintf(stderr, "%s: out of memory\n", program_invocation_short_name);
126 exit(EXIT_FAILURE);
Kristian Høgsberg06b16c22013-08-15 14:20:53 -0700127 }
128
129 return p;
130}
131
U. Artie Eoff86c68b32014-01-15 13:02:28 -0800132static void *
133xmalloc(size_t s)
134{
135 return fail_on_null(malloc(s));
136}
137
138static void *
139xzalloc(size_t s)
140{
141 return fail_on_null(calloc(1, s));
142}
143
144static char *
145xstrdup(const char *s)
146{
147 return fail_on_null(strdup(s));
148}
149
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200150static void
151print_global_info(void *data)
152{
153 struct global_info *global = data;
154
155 printf("interface: '%s', version: %u, name: %u\n",
156 global->interface, global->version, global->id);
157}
158
159static void
160init_global_info(struct weston_info *info,
161 struct global_info *global, uint32_t id,
162 const char *interface, uint32_t version)
163{
164 global->id = id;
165 global->version = version;
U. Artie Eoff86c68b32014-01-15 13:02:28 -0800166 global->interface = xstrdup(interface);
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200167
168 wl_list_insert(info->infos.prev, &global->link);
169}
170
171static void
172print_output_info(void *data)
173{
174 struct output_info *output = data;
Philipp Brüschweiler97cb62a2012-08-15 21:57:24 +0200175 struct output_mode *mode;
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200176 const char *subpixel_orientation;
177 const char *transform;
178
179 print_global_info(data);
180
181 switch (output->geometry.subpixel) {
182 case WL_OUTPUT_SUBPIXEL_UNKNOWN:
183 subpixel_orientation = "unknown";
184 break;
185 case WL_OUTPUT_SUBPIXEL_NONE:
186 subpixel_orientation = "none";
187 break;
188 case WL_OUTPUT_SUBPIXEL_HORIZONTAL_RGB:
189 subpixel_orientation = "horizontal rgb";
190 break;
191 case WL_OUTPUT_SUBPIXEL_HORIZONTAL_BGR:
192 subpixel_orientation = "horizontal bgr";
193 break;
194 case WL_OUTPUT_SUBPIXEL_VERTICAL_RGB:
195 subpixel_orientation = "vertical rgb";
196 break;
197 case WL_OUTPUT_SUBPIXEL_VERTICAL_BGR:
198 subpixel_orientation = "vertical bgr";
199 break;
200 default:
201 fprintf(stderr, "unknown subpixel orientation %u\n",
202 output->geometry.subpixel);
203 subpixel_orientation = "unexpected value";
204 break;
205 }
206
207 switch (output->geometry.output_transform) {
208 case WL_OUTPUT_TRANSFORM_NORMAL:
209 transform = "normal";
210 break;
211 case WL_OUTPUT_TRANSFORM_90:
212 transform = "90°";
213 break;
214 case WL_OUTPUT_TRANSFORM_180:
215 transform = "180°";
216 break;
217 case WL_OUTPUT_TRANSFORM_270:
218 transform = "270°";
219 break;
220 case WL_OUTPUT_TRANSFORM_FLIPPED:
221 transform = "flipped";
222 break;
223 case WL_OUTPUT_TRANSFORM_FLIPPED_90:
224 transform = "flipped 90°";
225 break;
226 case WL_OUTPUT_TRANSFORM_FLIPPED_180:
227 transform = "flipped 180°";
228 break;
229 case WL_OUTPUT_TRANSFORM_FLIPPED_270:
230 transform = "flipped 270°";
231 break;
232 default:
233 fprintf(stderr, "unknown output transform %u\n",
234 output->geometry.output_transform);
235 transform = "unexpected value";
236 break;
237 }
238
Philipp Brüschweiler97cb62a2012-08-15 21:57:24 +0200239 printf("\tx: %d, y: %d,\n",
240 output->geometry.x, output->geometry.y);
241 printf("\tphysical_width: %d mm, physical_height: %d mm,\n",
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200242 output->geometry.physical_width,
Philipp Brüschweiler97cb62a2012-08-15 21:57:24 +0200243 output->geometry.physical_height);
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200244 printf("\tmake: '%s', model: '%s',\n",
245 output->geometry.make, output->geometry.model);
U. Artie Eoffcb0e3572014-04-18 09:30:07 -0700246 printf("\tsubpixel_orientation: %s, output_transform: %s,\n",
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200247 subpixel_orientation, transform);
Philipp Brüschweiler97cb62a2012-08-15 21:57:24 +0200248
249 wl_list_for_each(mode, &output->modes, link) {
250 printf("\tmode:\n");
251
252 printf("\t\twidth: %d px, height: %d px, refresh: %.f Hz,\n",
253 mode->width, mode->height,
254 (float) mode->refresh / 1000);
255
256 printf("\t\tflags:");
257 if (mode->flags & WL_OUTPUT_MODE_CURRENT)
258 printf(" current");
259 if (mode->flags & WL_OUTPUT_MODE_PREFERRED)
260 printf(" preferred");
261 printf("\n");
262 }
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200263}
264
265static void
266print_shm_info(void *data)
267{
268 struct shm_info *shm = data;
269 struct shm_format *format;
270
271 print_global_info(data);
272
273 printf("\tformats:");
274
275 wl_list_for_each(format, &shm->formats, link)
Kristian Høgsberg8b66ebd2013-11-20 13:54:00 -0800276 switch (format->format) {
277 case WL_SHM_FORMAT_ARGB8888:
278 printf(" ARGB8888");
279 break;
280 case WL_SHM_FORMAT_XRGB8888:
281 printf(" XRGB8888");
282 break;
283 case WL_SHM_FORMAT_RGB565:
284 printf(" RGB565");
285 break;
286 default:
287 printf(" unknown(%08x)", format->format);
288 break;
289 }
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200290
291 printf("\n");
292}
293
294static void
295print_seat_info(void *data)
296{
297 struct seat_info *seat = data;
298
299 print_global_info(data);
300
Rob Bradford14a76012013-05-31 18:09:52 +0100301 printf("\tname: %s\n", seat->name);
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200302 printf("\tcapabilities:");
303
304 if (seat->capabilities & WL_SEAT_CAPABILITY_POINTER)
305 printf(" pointer");
306 if (seat->capabilities & WL_SEAT_CAPABILITY_KEYBOARD)
307 printf(" keyboard");
308 if (seat->capabilities & WL_SEAT_CAPABILITY_TOUCH)
309 printf(" touch");
310
311 printf("\n");
Jonny Lamb06959082014-08-12 14:58:27 +0200312
313 if (seat->repeat_rate > 0)
314 printf("\tkeyboard repeat rate: %d\n", seat->repeat_rate);
315 if (seat->repeat_delay > 0)
316 printf("\tkeyboard repeat delay: %d\n", seat->repeat_delay);
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200317}
318
319static void
Jonny Lamb06959082014-08-12 14:58:27 +0200320keyboard_handle_keymap(void *data, struct wl_keyboard *keyboard,
321 uint32_t format, int fd, uint32_t size)
322{
323}
324
325static void
326keyboard_handle_enter(void *data, struct wl_keyboard *keyboard,
327 uint32_t serial, struct wl_surface *surface,
328 struct wl_array *keys)
329{
330}
331
332static void
333keyboard_handle_leave(void *data, struct wl_keyboard *keyboard,
334 uint32_t serial, struct wl_surface *surface)
335{
336}
337
338static void
339keyboard_handle_key(void *data, struct wl_keyboard *keyboard,
340 uint32_t serial, uint32_t time, uint32_t key,
341 uint32_t state)
342{
343}
344
345static void
346keyboard_handle_modifiers(void *data, struct wl_keyboard *keyboard,
347 uint32_t serial, uint32_t mods_depressed,
348 uint32_t mods_latched, uint32_t mods_locked,
349 uint32_t group)
350{
351}
352
353static void
354keyboard_handle_repeat_info(void *data, struct wl_keyboard *keyboard,
355 int32_t rate, int32_t delay)
356{
357 struct seat_info *seat = data;
358
359 seat->repeat_rate = rate;
360 seat->repeat_delay = delay;
361}
362
363static const struct wl_keyboard_listener keyboard_listener = {
364 keyboard_handle_keymap,
365 keyboard_handle_enter,
366 keyboard_handle_leave,
367 keyboard_handle_key,
368 keyboard_handle_modifiers,
369 keyboard_handle_repeat_info,
370};
371
372static void
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200373seat_handle_capabilities(void *data, struct wl_seat *wl_seat,
374 enum wl_seat_capability caps)
375{
376 struct seat_info *seat = data;
Jonny Lamb06959082014-08-12 14:58:27 +0200377
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200378 seat->capabilities = caps;
Jonny Lamb06959082014-08-12 14:58:27 +0200379
380 /* we want listen for repeat_info from wl_keyboard, but only
381 * do so if the seat info is >= 4 and if we actually have a
382 * keyboard */
383 if (seat->global.version < 4)
384 return;
385
386 if (caps & WL_SEAT_CAPABILITY_KEYBOARD) {
387 struct wl_keyboard *keyboard;
388
389 keyboard = wl_seat_get_keyboard(seat->seat);
390 wl_keyboard_add_listener(keyboard, &keyboard_listener,
391 seat);
392
393 seat->info->roundtrip_needed = true;
394 }
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200395}
396
Rob Bradford14a76012013-05-31 18:09:52 +0100397static void
398seat_handle_name(void *data, struct wl_seat *wl_seat,
399 const char *name)
400{
401 struct seat_info *seat = data;
U. Artie Eoff86c68b32014-01-15 13:02:28 -0800402 seat->name = xstrdup(name);
Rob Bradford14a76012013-05-31 18:09:52 +0100403}
404
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200405static const struct wl_seat_listener seat_listener = {
406 seat_handle_capabilities,
Rob Bradford14a76012013-05-31 18:09:52 +0100407 seat_handle_name,
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200408};
409
410static void
U. Artie Eoff86c68b32014-01-15 13:02:28 -0800411destroy_seat_info(void *data)
412{
413 struct seat_info *seat = data;
414
415 wl_seat_destroy(seat->seat);
416
417 if (seat->name != NULL)
418 free(seat->name);
419}
420
421static void
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200422add_seat_info(struct weston_info *info, uint32_t id, uint32_t version)
423{
U. Artie Eoff86c68b32014-01-15 13:02:28 -0800424 struct seat_info *seat = xzalloc(sizeof *seat);
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200425
Jonny Lamb06959082014-08-12 14:58:27 +0200426 /* required to set roundtrip_needed to true in capabilities
427 * handler */
428 seat->info = info;
429
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200430 init_global_info(info, &seat->global, id, "wl_seat", version);
431 seat->global.print = print_seat_info;
U. Artie Eoff86c68b32014-01-15 13:02:28 -0800432 seat->global.destroy = destroy_seat_info;
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200433
Kristian Høgsbergfa80e112012-10-10 21:34:26 -0400434 seat->seat = wl_registry_bind(info->registry,
Jonny Lamb06959082014-08-12 14:58:27 +0200435 id, &wl_seat_interface, MIN(version, 4));
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200436 wl_seat_add_listener(seat->seat, &seat_listener, seat);
Philipp Brüschweilerbb0d4b92012-08-15 21:57:23 +0200437
Jonny Lamb06959082014-08-12 14:58:27 +0200438 seat->repeat_rate = seat->repeat_delay = -1;
439
Philipp Brüschweilerbb0d4b92012-08-15 21:57:23 +0200440 info->roundtrip_needed = true;
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200441}
442
443static void
444shm_handle_format(void *data, struct wl_shm *wl_shm, uint32_t format)
445{
446 struct shm_info *shm = data;
U. Artie Eoff86c68b32014-01-15 13:02:28 -0800447 struct shm_format *shm_format = xzalloc(sizeof *shm_format);
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200448
449 wl_list_insert(&shm->formats, &shm_format->link);
450 shm_format->format = format;
451}
452
453static const struct wl_shm_listener shm_listener = {
454 shm_handle_format,
455};
456
457static void
U. Artie Eoff86c68b32014-01-15 13:02:28 -0800458destroy_shm_info(void *data)
459{
460 struct shm_info *shm = data;
461 struct shm_format *format, *tmp;
462
463 wl_list_for_each_safe(format, tmp, &shm->formats, link) {
464 wl_list_remove(&format->link);
465 free(format);
466 }
467
468 wl_shm_destroy(shm->shm);
469}
470
471static void
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200472add_shm_info(struct weston_info *info, uint32_t id, uint32_t version)
473{
U. Artie Eoff86c68b32014-01-15 13:02:28 -0800474 struct shm_info *shm = xzalloc(sizeof *shm);
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200475
476 init_global_info(info, &shm->global, id, "wl_shm", version);
477 shm->global.print = print_shm_info;
U. Artie Eoff86c68b32014-01-15 13:02:28 -0800478 shm->global.destroy = destroy_shm_info;
479
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200480 wl_list_init(&shm->formats);
481
Kristian Høgsbergfa80e112012-10-10 21:34:26 -0400482 shm->shm = wl_registry_bind(info->registry,
483 id, &wl_shm_interface, 1);
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200484 wl_shm_add_listener(shm->shm, &shm_listener, shm);
Philipp Brüschweilerbb0d4b92012-08-15 21:57:23 +0200485
486 info->roundtrip_needed = true;
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200487}
488
489static void
490output_handle_geometry(void *data, struct wl_output *wl_output,
491 int32_t x, int32_t y,
492 int32_t physical_width, int32_t physical_height,
493 int32_t subpixel,
494 const char *make, const char *model,
495 int32_t output_transform)
496{
497 struct output_info *output = data;
498
499 output->geometry.x = x;
500 output->geometry.y = y;
501 output->geometry.physical_width = physical_width;
502 output->geometry.physical_height = physical_height;
503 output->geometry.subpixel = subpixel;
U. Artie Eoff86c68b32014-01-15 13:02:28 -0800504 output->geometry.make = xstrdup(make);
505 output->geometry.model = xstrdup(model);
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200506 output->geometry.output_transform = output_transform;
507}
508
509static void
510output_handle_mode(void *data, struct wl_output *wl_output,
511 uint32_t flags, int32_t width, int32_t height,
512 int32_t refresh)
513{
514 struct output_info *output = data;
Kristian Høgsberg06b16c22013-08-15 14:20:53 -0700515 struct output_mode *mode = xmalloc(sizeof *mode);
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200516
Philipp Brüschweiler97cb62a2012-08-15 21:57:24 +0200517 mode->flags = flags;
518 mode->width = width;
519 mode->height = height;
520 mode->refresh = refresh;
521
522 wl_list_insert(output->modes.prev, &mode->link);
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200523}
524
525static const struct wl_output_listener output_listener = {
526 output_handle_geometry,
527 output_handle_mode,
528};
529
530static void
U. Artie Eoff86c68b32014-01-15 13:02:28 -0800531destroy_output_info(void *data)
532{
533 struct output_info *output = data;
534 struct output_mode *mode, *tmp;
535
536 wl_output_destroy(output->output);
537
538 if (output->geometry.make != NULL)
539 free(output->geometry.make);
540 if (output->geometry.model != NULL)
541 free(output->geometry.model);
542
543 wl_list_for_each_safe(mode, tmp, &output->modes, link) {
544 wl_list_remove(&mode->link);
545 free(mode);
546 }
547}
548
549static void
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200550add_output_info(struct weston_info *info, uint32_t id, uint32_t version)
551{
U. Artie Eoff86c68b32014-01-15 13:02:28 -0800552 struct output_info *output = xzalloc(sizeof *output);
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200553
554 init_global_info(info, &output->global, id, "wl_output", version);
555 output->global.print = print_output_info;
U. Artie Eoff86c68b32014-01-15 13:02:28 -0800556 output->global.destroy = destroy_output_info;
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200557
Philipp Brüschweiler97cb62a2012-08-15 21:57:24 +0200558 wl_list_init(&output->modes);
559
Kristian Høgsbergfa80e112012-10-10 21:34:26 -0400560 output->output = wl_registry_bind(info->registry, id,
561 &wl_output_interface, 1);
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200562 wl_output_add_listener(output->output, &output_listener,
563 output);
Philipp Brüschweilerbb0d4b92012-08-15 21:57:23 +0200564
565 info->roundtrip_needed = true;
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200566}
567
568static void
Pekka Paalanen93a6afd2014-09-23 22:08:44 -0400569destroy_presentation_info(void *info)
570{
571 struct presentation_info *prinfo = info;
572
573 presentation_destroy(prinfo->presentation);
574}
575
576static const char *
577clock_name(clockid_t clk_id)
578{
579 static const char *names[] = {
580 [CLOCK_REALTIME] = "CLOCK_REALTIME",
581 [CLOCK_MONOTONIC] = "CLOCK_MONOTONIC",
582 [CLOCK_MONOTONIC_RAW] = "CLOCK_MONOTONIC_RAW",
583 [CLOCK_REALTIME_COARSE] = "CLOCK_REALTIME_COARSE",
584 [CLOCK_MONOTONIC_COARSE] = "CLOCK_MONOTONIC_COARSE",
585 [CLOCK_BOOTTIME] = "CLOCK_BOOTTIME",
586 };
587
588 if (clk_id < 0 || (unsigned)clk_id >= ARRAY_LENGTH(names))
589 return "unknown";
590
591 return names[clk_id];
592}
593
594static void
595print_presentation_info(void *info)
596{
597 struct presentation_info *prinfo = info;
598
599 print_global_info(info);
600
601 printf("\tpresentation clock id: %d (%s)\n",
602 prinfo->clk_id, clock_name(prinfo->clk_id));
603}
604
605static void
606presentation_handle_clock_id(void *data, struct presentation *presentation,
607 uint32_t clk_id)
608{
609 struct presentation_info *prinfo = data;
610
611 prinfo->clk_id = clk_id;
612}
613
614static const struct presentation_listener presentation_listener = {
615 presentation_handle_clock_id
616};
617
618static void
619add_presentation_info(struct weston_info *info, uint32_t id, uint32_t version)
620{
621 struct presentation_info *prinfo = xzalloc(sizeof *prinfo);
622
623 init_global_info(info, &prinfo->global, id, "presentation", version);
624 prinfo->global.print = print_presentation_info;
625 prinfo->global.destroy = destroy_presentation_info;
626
627 prinfo->clk_id = -1;
628 prinfo->presentation = wl_registry_bind(info->registry, id,
629 &presentation_interface, 1);
630 presentation_add_listener(prinfo->presentation, &presentation_listener,
631 prinfo);
632
633 info->roundtrip_needed = true;
634}
635
636static void
U. Artie Eoff86c68b32014-01-15 13:02:28 -0800637destroy_global_info(void *data)
638{
639}
640
641static void
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200642add_global_info(struct weston_info *info, uint32_t id,
643 const char *interface, uint32_t version)
644{
U. Artie Eoff86c68b32014-01-15 13:02:28 -0800645 struct global_info *global = xzalloc(sizeof *global);
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200646
647 init_global_info(info, global, id, interface, version);
648 global->print = print_global_info;
U. Artie Eoff86c68b32014-01-15 13:02:28 -0800649 global->destroy = destroy_global_info;
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200650}
651
652static void
Kristian Høgsbergfa80e112012-10-10 21:34:26 -0400653global_handler(void *data, struct wl_registry *registry, uint32_t id,
654 const char *interface, uint32_t version)
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200655{
656 struct weston_info *info = data;
657
658 if (!strcmp(interface, "wl_seat"))
659 add_seat_info(info, id, version);
660 else if (!strcmp(interface, "wl_shm"))
661 add_shm_info(info, id, version);
662 else if (!strcmp(interface, "wl_output"))
663 add_output_info(info, id, version);
Pekka Paalanen93a6afd2014-09-23 22:08:44 -0400664 else if (!strcmp(interface, "presentation"))
665 add_presentation_info(info, id, version);
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200666 else
667 add_global_info(info, id, interface, version);
668}
669
Pekka Paalanen0eab05d2013-01-22 14:53:55 +0200670static void
671global_remove_handler(void *data, struct wl_registry *registry, uint32_t name)
672{
673}
674
Kristian Høgsbergfa80e112012-10-10 21:34:26 -0400675static const struct wl_registry_listener registry_listener = {
Pekka Paalanen0eab05d2013-01-22 14:53:55 +0200676 global_handler,
677 global_remove_handler
Kristian Høgsbergfa80e112012-10-10 21:34:26 -0400678};
679
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200680static void
681print_infos(struct wl_list *infos)
682{
683 struct global_info *info;
684
685 wl_list_for_each(info, infos, link)
686 info->print(info);
687}
688
U. Artie Eoff86c68b32014-01-15 13:02:28 -0800689static void
690destroy_info(void *data)
691{
692 struct global_info *global = data;
693
694 global->destroy(data);
695 wl_list_remove(&global->link);
696 free(global->interface);
697 free(data);
698}
699
700static void
701destroy_infos(struct wl_list *infos)
702{
703 struct global_info *info, *tmp;
704 wl_list_for_each_safe(info, tmp, infos, link)
705 destroy_info(info);
706}
707
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200708int
709main(int argc, char **argv)
710{
711 struct weston_info info;
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200712
713 info.display = wl_display_connect(NULL);
714 if (!info.display) {
715 fprintf(stderr, "failed to create display: %m\n");
716 return -1;
717 }
718
719 wl_list_init(&info.infos);
720
Kristian Høgsbergfa80e112012-10-10 21:34:26 -0400721 info.registry = wl_display_get_registry(info.display);
722 wl_registry_add_listener(info.registry, &registry_listener, &info);
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200723
Philipp Brüschweilerbb0d4b92012-08-15 21:57:23 +0200724 do {
725 info.roundtrip_needed = false;
726 wl_display_roundtrip(info.display);
727 } while (info.roundtrip_needed);
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200728
729 print_infos(&info.infos);
U. Artie Eoff86c68b32014-01-15 13:02:28 -0800730 destroy_infos(&info.infos);
731
732 wl_registry_destroy(info.registry);
733 wl_display_disconnect(info.display);
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200734
735 return 0;
736}