blob: 8ba80c0e64fae7af27594611ce150cb9d4a37682 [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 Cruz35b2eaa2015-06-15 15:37:08 -070035#include "shared/helpers.h"
Jon Cruz4678bab2015-06-15 15:37:07 -070036#include "shared/os-compatibility.h"
Bryce Harringtone99e4bf2016-03-16 14:15:18 -070037#include "shared/xalloc.h"
Bryce Harrington0d1a6222016-02-11 16:42:49 -080038#include "shared/zalloc.h"
Pekka Paalanenb00c79b2016-02-18 16:53:27 +020039#include "presentation-time-client-protocol.h"
Pekka Paalanen93a6afd2014-09-23 22:08:44 -040040
Philipp Brüschweiler585acb02012-08-15 17:12:00 +020041typedef void (*print_info_t)(void *info);
U. Artie Eoff86c68b32014-01-15 13:02:28 -080042typedef void (*destroy_info_t)(void *info);
Philipp Brüschweiler585acb02012-08-15 17:12:00 +020043
44struct global_info {
45 struct wl_list link;
46
47 uint32_t id;
48 uint32_t version;
49 char *interface;
50
51 print_info_t print;
U. Artie Eoff86c68b32014-01-15 13:02:28 -080052 destroy_info_t destroy;
Philipp Brüschweiler585acb02012-08-15 17:12:00 +020053};
54
Philipp Brüschweiler97cb62a2012-08-15 21:57:24 +020055struct output_mode {
56 struct wl_list link;
57
58 uint32_t flags;
59 int32_t width, height;
60 int32_t refresh;
61};
62
Philipp Brüschweiler585acb02012-08-15 17:12:00 +020063struct output_info {
64 struct global_info global;
65
66 struct wl_output *output;
67
Jonny Lambba9dca02015-12-17 12:31:56 +000068 int32_t version;
69
Philipp Brüschweiler585acb02012-08-15 17:12:00 +020070 struct {
71 int32_t x, y;
Jonny Lambba9dca02015-12-17 12:31:56 +000072 int32_t scale;
Philipp Brüschweiler585acb02012-08-15 17:12:00 +020073 int32_t physical_width, physical_height;
74 enum wl_output_subpixel subpixel;
75 enum wl_output_transform output_transform;
76 char *make;
77 char *model;
78 } geometry;
79
Philipp Brüschweiler97cb62a2012-08-15 21:57:24 +020080 struct wl_list modes;
Philipp Brüschweiler585acb02012-08-15 17:12:00 +020081};
82
83struct shm_format {
84 struct wl_list link;
85
86 uint32_t format;
87};
88
89struct shm_info {
90 struct global_info global;
91 struct wl_shm *shm;
92
93 struct wl_list formats;
94};
95
96struct seat_info {
97 struct global_info global;
98 struct wl_seat *seat;
Jonny Lamb06959082014-08-12 14:58:27 +020099 struct weston_info *info;
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200100
101 uint32_t capabilities;
Rob Bradford14a76012013-05-31 18:09:52 +0100102 char *name;
Jonny Lamb06959082014-08-12 14:58:27 +0200103
104 int32_t repeat_rate;
105 int32_t repeat_delay;
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200106};
107
Pekka Paalanen93a6afd2014-09-23 22:08:44 -0400108struct presentation_info {
109 struct global_info global;
Pekka Paalanenb00c79b2016-02-18 16:53:27 +0200110 struct wp_presentation *presentation;
Pekka Paalanen93a6afd2014-09-23 22:08:44 -0400111
112 clockid_t clk_id;
113};
114
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200115struct weston_info {
116 struct wl_display *display;
Kristian Høgsbergfa80e112012-10-10 21:34:26 -0400117 struct wl_registry *registry;
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200118
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200119 struct wl_list infos;
Philipp Brüschweilerbb0d4b92012-08-15 21:57:23 +0200120 bool roundtrip_needed;
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200121};
122
123static void
124print_global_info(void *data)
125{
126 struct global_info *global = data;
127
128 printf("interface: '%s', version: %u, name: %u\n",
129 global->interface, global->version, global->id);
130}
131
132static void
133init_global_info(struct weston_info *info,
134 struct global_info *global, uint32_t id,
135 const char *interface, uint32_t version)
136{
137 global->id = id;
138 global->version = version;
U. Artie Eoff86c68b32014-01-15 13:02:28 -0800139 global->interface = xstrdup(interface);
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200140
141 wl_list_insert(info->infos.prev, &global->link);
142}
143
144static void
145print_output_info(void *data)
146{
147 struct output_info *output = data;
Philipp Brüschweiler97cb62a2012-08-15 21:57:24 +0200148 struct output_mode *mode;
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200149 const char *subpixel_orientation;
150 const char *transform;
151
152 print_global_info(data);
153
154 switch (output->geometry.subpixel) {
155 case WL_OUTPUT_SUBPIXEL_UNKNOWN:
156 subpixel_orientation = "unknown";
157 break;
158 case WL_OUTPUT_SUBPIXEL_NONE:
159 subpixel_orientation = "none";
160 break;
161 case WL_OUTPUT_SUBPIXEL_HORIZONTAL_RGB:
162 subpixel_orientation = "horizontal rgb";
163 break;
164 case WL_OUTPUT_SUBPIXEL_HORIZONTAL_BGR:
165 subpixel_orientation = "horizontal bgr";
166 break;
167 case WL_OUTPUT_SUBPIXEL_VERTICAL_RGB:
168 subpixel_orientation = "vertical rgb";
169 break;
170 case WL_OUTPUT_SUBPIXEL_VERTICAL_BGR:
171 subpixel_orientation = "vertical bgr";
172 break;
173 default:
174 fprintf(stderr, "unknown subpixel orientation %u\n",
175 output->geometry.subpixel);
176 subpixel_orientation = "unexpected value";
177 break;
178 }
179
180 switch (output->geometry.output_transform) {
181 case WL_OUTPUT_TRANSFORM_NORMAL:
182 transform = "normal";
183 break;
184 case WL_OUTPUT_TRANSFORM_90:
185 transform = "90°";
186 break;
187 case WL_OUTPUT_TRANSFORM_180:
188 transform = "180°";
189 break;
190 case WL_OUTPUT_TRANSFORM_270:
191 transform = "270°";
192 break;
193 case WL_OUTPUT_TRANSFORM_FLIPPED:
194 transform = "flipped";
195 break;
196 case WL_OUTPUT_TRANSFORM_FLIPPED_90:
197 transform = "flipped 90°";
198 break;
199 case WL_OUTPUT_TRANSFORM_FLIPPED_180:
200 transform = "flipped 180°";
201 break;
202 case WL_OUTPUT_TRANSFORM_FLIPPED_270:
203 transform = "flipped 270°";
204 break;
205 default:
206 fprintf(stderr, "unknown output transform %u\n",
207 output->geometry.output_transform);
208 transform = "unexpected value";
209 break;
210 }
211
Jonny Lambba9dca02015-12-17 12:31:56 +0000212 printf("\tx: %d, y: %d,",
Philipp Brüschweiler97cb62a2012-08-15 21:57:24 +0200213 output->geometry.x, output->geometry.y);
Jonny Lambba9dca02015-12-17 12:31:56 +0000214 if (output->version >= 2)
215 printf(" scale: %d,", output->geometry.scale);
216 printf("\n");
217
Philipp Brüschweiler97cb62a2012-08-15 21:57:24 +0200218 printf("\tphysical_width: %d mm, physical_height: %d mm,\n",
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200219 output->geometry.physical_width,
Philipp Brüschweiler97cb62a2012-08-15 21:57:24 +0200220 output->geometry.physical_height);
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200221 printf("\tmake: '%s', model: '%s',\n",
222 output->geometry.make, output->geometry.model);
U. Artie Eoffcb0e3572014-04-18 09:30:07 -0700223 printf("\tsubpixel_orientation: %s, output_transform: %s,\n",
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200224 subpixel_orientation, transform);
Philipp Brüschweiler97cb62a2012-08-15 21:57:24 +0200225
226 wl_list_for_each(mode, &output->modes, link) {
227 printf("\tmode:\n");
228
229 printf("\t\twidth: %d px, height: %d px, refresh: %.f Hz,\n",
230 mode->width, mode->height,
231 (float) mode->refresh / 1000);
232
233 printf("\t\tflags:");
234 if (mode->flags & WL_OUTPUT_MODE_CURRENT)
235 printf(" current");
236 if (mode->flags & WL_OUTPUT_MODE_PREFERRED)
237 printf(" preferred");
238 printf("\n");
239 }
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200240}
241
242static void
243print_shm_info(void *data)
244{
245 struct shm_info *shm = data;
246 struct shm_format *format;
247
248 print_global_info(data);
249
250 printf("\tformats:");
251
252 wl_list_for_each(format, &shm->formats, link)
Kristian Høgsberg8b66ebd2013-11-20 13:54:00 -0800253 switch (format->format) {
254 case WL_SHM_FORMAT_ARGB8888:
255 printf(" ARGB8888");
256 break;
257 case WL_SHM_FORMAT_XRGB8888:
258 printf(" XRGB8888");
259 break;
260 case WL_SHM_FORMAT_RGB565:
261 printf(" RGB565");
262 break;
263 default:
264 printf(" unknown(%08x)", format->format);
265 break;
266 }
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200267
268 printf("\n");
269}
270
271static void
272print_seat_info(void *data)
273{
274 struct seat_info *seat = data;
275
276 print_global_info(data);
277
Rob Bradford14a76012013-05-31 18:09:52 +0100278 printf("\tname: %s\n", seat->name);
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200279 printf("\tcapabilities:");
280
281 if (seat->capabilities & WL_SEAT_CAPABILITY_POINTER)
282 printf(" pointer");
283 if (seat->capabilities & WL_SEAT_CAPABILITY_KEYBOARD)
284 printf(" keyboard");
285 if (seat->capabilities & WL_SEAT_CAPABILITY_TOUCH)
286 printf(" touch");
287
288 printf("\n");
Jonny Lamb06959082014-08-12 14:58:27 +0200289
290 if (seat->repeat_rate > 0)
291 printf("\tkeyboard repeat rate: %d\n", seat->repeat_rate);
292 if (seat->repeat_delay > 0)
293 printf("\tkeyboard repeat delay: %d\n", seat->repeat_delay);
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200294}
295
296static void
Jonny Lamb06959082014-08-12 14:58:27 +0200297keyboard_handle_keymap(void *data, struct wl_keyboard *keyboard,
298 uint32_t format, int fd, uint32_t size)
299{
300}
301
302static void
303keyboard_handle_enter(void *data, struct wl_keyboard *keyboard,
304 uint32_t serial, struct wl_surface *surface,
305 struct wl_array *keys)
306{
307}
308
309static void
310keyboard_handle_leave(void *data, struct wl_keyboard *keyboard,
311 uint32_t serial, struct wl_surface *surface)
312{
313}
314
315static void
316keyboard_handle_key(void *data, struct wl_keyboard *keyboard,
317 uint32_t serial, uint32_t time, uint32_t key,
318 uint32_t state)
319{
320}
321
322static void
323keyboard_handle_modifiers(void *data, struct wl_keyboard *keyboard,
324 uint32_t serial, uint32_t mods_depressed,
325 uint32_t mods_latched, uint32_t mods_locked,
326 uint32_t group)
327{
328}
329
330static void
331keyboard_handle_repeat_info(void *data, struct wl_keyboard *keyboard,
332 int32_t rate, int32_t delay)
333{
334 struct seat_info *seat = data;
335
336 seat->repeat_rate = rate;
337 seat->repeat_delay = delay;
338}
339
340static const struct wl_keyboard_listener keyboard_listener = {
341 keyboard_handle_keymap,
342 keyboard_handle_enter,
343 keyboard_handle_leave,
344 keyboard_handle_key,
345 keyboard_handle_modifiers,
346 keyboard_handle_repeat_info,
347};
348
349static void
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200350seat_handle_capabilities(void *data, struct wl_seat *wl_seat,
351 enum wl_seat_capability caps)
352{
353 struct seat_info *seat = data;
Jonny Lamb06959082014-08-12 14:58:27 +0200354
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200355 seat->capabilities = caps;
Jonny Lamb06959082014-08-12 14:58:27 +0200356
357 /* we want listen for repeat_info from wl_keyboard, but only
358 * do so if the seat info is >= 4 and if we actually have a
359 * keyboard */
360 if (seat->global.version < 4)
361 return;
362
363 if (caps & WL_SEAT_CAPABILITY_KEYBOARD) {
364 struct wl_keyboard *keyboard;
365
366 keyboard = wl_seat_get_keyboard(seat->seat);
367 wl_keyboard_add_listener(keyboard, &keyboard_listener,
368 seat);
369
370 seat->info->roundtrip_needed = true;
371 }
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200372}
373
Rob Bradford14a76012013-05-31 18:09:52 +0100374static void
375seat_handle_name(void *data, struct wl_seat *wl_seat,
376 const char *name)
377{
378 struct seat_info *seat = data;
U. Artie Eoff86c68b32014-01-15 13:02:28 -0800379 seat->name = xstrdup(name);
Rob Bradford14a76012013-05-31 18:09:52 +0100380}
381
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200382static const struct wl_seat_listener seat_listener = {
383 seat_handle_capabilities,
Rob Bradford14a76012013-05-31 18:09:52 +0100384 seat_handle_name,
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200385};
386
387static void
U. Artie Eoff86c68b32014-01-15 13:02:28 -0800388destroy_seat_info(void *data)
389{
390 struct seat_info *seat = data;
391
392 wl_seat_destroy(seat->seat);
393
394 if (seat->name != NULL)
395 free(seat->name);
396}
397
398static void
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200399add_seat_info(struct weston_info *info, uint32_t id, uint32_t version)
400{
U. Artie Eoff86c68b32014-01-15 13:02:28 -0800401 struct seat_info *seat = xzalloc(sizeof *seat);
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200402
Jonny Lamb06959082014-08-12 14:58:27 +0200403 /* required to set roundtrip_needed to true in capabilities
404 * handler */
405 seat->info = info;
406
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200407 init_global_info(info, &seat->global, id, "wl_seat", version);
408 seat->global.print = print_seat_info;
U. Artie Eoff86c68b32014-01-15 13:02:28 -0800409 seat->global.destroy = destroy_seat_info;
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200410
Kristian Høgsbergfa80e112012-10-10 21:34:26 -0400411 seat->seat = wl_registry_bind(info->registry,
Jonny Lamb06959082014-08-12 14:58:27 +0200412 id, &wl_seat_interface, MIN(version, 4));
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200413 wl_seat_add_listener(seat->seat, &seat_listener, seat);
Philipp Brüschweilerbb0d4b92012-08-15 21:57:23 +0200414
Jonny Lamb06959082014-08-12 14:58:27 +0200415 seat->repeat_rate = seat->repeat_delay = -1;
416
Philipp Brüschweilerbb0d4b92012-08-15 21:57:23 +0200417 info->roundtrip_needed = true;
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200418}
419
420static void
421shm_handle_format(void *data, struct wl_shm *wl_shm, uint32_t format)
422{
423 struct shm_info *shm = data;
U. Artie Eoff86c68b32014-01-15 13:02:28 -0800424 struct shm_format *shm_format = xzalloc(sizeof *shm_format);
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200425
426 wl_list_insert(&shm->formats, &shm_format->link);
427 shm_format->format = format;
428}
429
430static const struct wl_shm_listener shm_listener = {
431 shm_handle_format,
432};
433
434static void
U. Artie Eoff86c68b32014-01-15 13:02:28 -0800435destroy_shm_info(void *data)
436{
437 struct shm_info *shm = data;
438 struct shm_format *format, *tmp;
439
440 wl_list_for_each_safe(format, tmp, &shm->formats, link) {
441 wl_list_remove(&format->link);
442 free(format);
443 }
444
445 wl_shm_destroy(shm->shm);
446}
447
448static void
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200449add_shm_info(struct weston_info *info, uint32_t id, uint32_t version)
450{
U. Artie Eoff86c68b32014-01-15 13:02:28 -0800451 struct shm_info *shm = xzalloc(sizeof *shm);
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200452
453 init_global_info(info, &shm->global, id, "wl_shm", version);
454 shm->global.print = print_shm_info;
U. Artie Eoff86c68b32014-01-15 13:02:28 -0800455 shm->global.destroy = destroy_shm_info;
456
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200457 wl_list_init(&shm->formats);
458
Kristian Høgsbergfa80e112012-10-10 21:34:26 -0400459 shm->shm = wl_registry_bind(info->registry,
460 id, &wl_shm_interface, 1);
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200461 wl_shm_add_listener(shm->shm, &shm_listener, shm);
Philipp Brüschweilerbb0d4b92012-08-15 21:57:23 +0200462
463 info->roundtrip_needed = true;
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200464}
465
466static void
467output_handle_geometry(void *data, struct wl_output *wl_output,
468 int32_t x, int32_t y,
469 int32_t physical_width, int32_t physical_height,
470 int32_t subpixel,
471 const char *make, const char *model,
472 int32_t output_transform)
473{
474 struct output_info *output = data;
475
476 output->geometry.x = x;
477 output->geometry.y = y;
478 output->geometry.physical_width = physical_width;
479 output->geometry.physical_height = physical_height;
480 output->geometry.subpixel = subpixel;
U. Artie Eoff86c68b32014-01-15 13:02:28 -0800481 output->geometry.make = xstrdup(make);
482 output->geometry.model = xstrdup(model);
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200483 output->geometry.output_transform = output_transform;
484}
485
486static void
487output_handle_mode(void *data, struct wl_output *wl_output,
488 uint32_t flags, int32_t width, int32_t height,
489 int32_t refresh)
490{
491 struct output_info *output = data;
Kristian Høgsberg06b16c22013-08-15 14:20:53 -0700492 struct output_mode *mode = xmalloc(sizeof *mode);
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200493
Philipp Brüschweiler97cb62a2012-08-15 21:57:24 +0200494 mode->flags = flags;
495 mode->width = width;
496 mode->height = height;
497 mode->refresh = refresh;
498
499 wl_list_insert(output->modes.prev, &mode->link);
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200500}
501
Jonny Lambba9dca02015-12-17 12:31:56 +0000502static void
503output_handle_done(void *data, struct wl_output *wl_output)
504{
505 /* don't bother waiting for this; there's no good reason a
506 * compositor will wait more than one roundtrip before sending
507 * these initial events. */
508}
509
510static void
511output_handle_scale(void *data, struct wl_output *wl_output,
512 int32_t scale)
513{
514 struct output_info *output = data;
515
516 output->geometry.scale = scale;
517}
518
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200519static const struct wl_output_listener output_listener = {
520 output_handle_geometry,
521 output_handle_mode,
Jonny Lambba9dca02015-12-17 12:31:56 +0000522 output_handle_done,
523 output_handle_scale,
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200524};
525
526static void
U. Artie Eoff86c68b32014-01-15 13:02:28 -0800527destroy_output_info(void *data)
528{
529 struct output_info *output = data;
530 struct output_mode *mode, *tmp;
531
532 wl_output_destroy(output->output);
533
534 if (output->geometry.make != NULL)
535 free(output->geometry.make);
536 if (output->geometry.model != NULL)
537 free(output->geometry.model);
538
539 wl_list_for_each_safe(mode, tmp, &output->modes, link) {
540 wl_list_remove(&mode->link);
541 free(mode);
542 }
543}
544
545static void
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200546add_output_info(struct weston_info *info, uint32_t id, uint32_t version)
547{
U. Artie Eoff86c68b32014-01-15 13:02:28 -0800548 struct output_info *output = xzalloc(sizeof *output);
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200549
550 init_global_info(info, &output->global, id, "wl_output", version);
551 output->global.print = print_output_info;
U. Artie Eoff86c68b32014-01-15 13:02:28 -0800552 output->global.destroy = destroy_output_info;
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200553
Jonny Lambba9dca02015-12-17 12:31:56 +0000554 output->version = MIN(version, 2);
555 output->geometry.scale = 1;
Philipp Brüschweiler97cb62a2012-08-15 21:57:24 +0200556 wl_list_init(&output->modes);
557
Kristian Høgsbergfa80e112012-10-10 21:34:26 -0400558 output->output = wl_registry_bind(info->registry, id,
Jonny Lambba9dca02015-12-17 12:31:56 +0000559 &wl_output_interface, output->version);
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200560 wl_output_add_listener(output->output, &output_listener,
561 output);
Philipp Brüschweilerbb0d4b92012-08-15 21:57:23 +0200562
563 info->roundtrip_needed = true;
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200564}
565
566static void
Pekka Paalanen93a6afd2014-09-23 22:08:44 -0400567destroy_presentation_info(void *info)
568{
569 struct presentation_info *prinfo = info;
570
Pekka Paalanenb00c79b2016-02-18 16:53:27 +0200571 wp_presentation_destroy(prinfo->presentation);
Pekka Paalanen93a6afd2014-09-23 22:08:44 -0400572}
573
574static const char *
575clock_name(clockid_t clk_id)
576{
577 static const char *names[] = {
578 [CLOCK_REALTIME] = "CLOCK_REALTIME",
579 [CLOCK_MONOTONIC] = "CLOCK_MONOTONIC",
580 [CLOCK_MONOTONIC_RAW] = "CLOCK_MONOTONIC_RAW",
581 [CLOCK_REALTIME_COARSE] = "CLOCK_REALTIME_COARSE",
582 [CLOCK_MONOTONIC_COARSE] = "CLOCK_MONOTONIC_COARSE",
Derek Foreman32838c92015-06-29 13:20:34 -0500583#ifdef CLOCK_BOOTTIME
Pekka Paalanen93a6afd2014-09-23 22:08:44 -0400584 [CLOCK_BOOTTIME] = "CLOCK_BOOTTIME",
Derek Foreman32838c92015-06-29 13:20:34 -0500585#endif
Pekka Paalanen93a6afd2014-09-23 22:08:44 -0400586 };
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
Pekka Paalanenb00c79b2016-02-18 16:53:27 +0200606presentation_handle_clock_id(void *data, struct wp_presentation *presentation,
Pekka Paalanen93a6afd2014-09-23 22:08:44 -0400607 uint32_t clk_id)
608{
609 struct presentation_info *prinfo = data;
610
611 prinfo->clk_id = clk_id;
612}
613
Pekka Paalanenb00c79b2016-02-18 16:53:27 +0200614static const struct wp_presentation_listener presentation_listener = {
Pekka Paalanen93a6afd2014-09-23 22:08:44 -0400615 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
Pekka Paalanenb00c79b2016-02-18 16:53:27 +0200623 init_global_info(info, &prinfo->global, id,
624 wp_presentation_interface.name, version);
Pekka Paalanen93a6afd2014-09-23 22:08:44 -0400625 prinfo->global.print = print_presentation_info;
626 prinfo->global.destroy = destroy_presentation_info;
627
628 prinfo->clk_id = -1;
629 prinfo->presentation = wl_registry_bind(info->registry, id,
Pekka Paalanenb00c79b2016-02-18 16:53:27 +0200630 &wp_presentation_interface, 1);
631 wp_presentation_add_listener(prinfo->presentation,
632 &presentation_listener, prinfo);
Pekka Paalanen93a6afd2014-09-23 22:08:44 -0400633
634 info->roundtrip_needed = true;
635}
636
637static void
U. Artie Eoff86c68b32014-01-15 13:02:28 -0800638destroy_global_info(void *data)
639{
640}
641
642static void
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200643add_global_info(struct weston_info *info, uint32_t id,
644 const char *interface, uint32_t version)
645{
U. Artie Eoff86c68b32014-01-15 13:02:28 -0800646 struct global_info *global = xzalloc(sizeof *global);
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200647
648 init_global_info(info, global, id, interface, version);
649 global->print = print_global_info;
U. Artie Eoff86c68b32014-01-15 13:02:28 -0800650 global->destroy = destroy_global_info;
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200651}
652
653static void
Kristian Høgsbergfa80e112012-10-10 21:34:26 -0400654global_handler(void *data, struct wl_registry *registry, uint32_t id,
655 const char *interface, uint32_t version)
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200656{
657 struct weston_info *info = data;
658
659 if (!strcmp(interface, "wl_seat"))
660 add_seat_info(info, id, version);
661 else if (!strcmp(interface, "wl_shm"))
662 add_shm_info(info, id, version);
663 else if (!strcmp(interface, "wl_output"))
664 add_output_info(info, id, version);
Pekka Paalanen93a6afd2014-09-23 22:08:44 -0400665 else if (!strcmp(interface, "presentation"))
666 add_presentation_info(info, id, version);
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200667 else
668 add_global_info(info, id, interface, version);
669}
670
Pekka Paalanen0eab05d2013-01-22 14:53:55 +0200671static void
672global_remove_handler(void *data, struct wl_registry *registry, uint32_t name)
673{
674}
675
Kristian Høgsbergfa80e112012-10-10 21:34:26 -0400676static const struct wl_registry_listener registry_listener = {
Pekka Paalanen0eab05d2013-01-22 14:53:55 +0200677 global_handler,
678 global_remove_handler
Kristian Høgsbergfa80e112012-10-10 21:34:26 -0400679};
680
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200681static void
682print_infos(struct wl_list *infos)
683{
684 struct global_info *info;
685
686 wl_list_for_each(info, infos, link)
687 info->print(info);
688}
689
U. Artie Eoff86c68b32014-01-15 13:02:28 -0800690static void
691destroy_info(void *data)
692{
693 struct global_info *global = data;
694
695 global->destroy(data);
696 wl_list_remove(&global->link);
697 free(global->interface);
698 free(data);
699}
700
701static void
702destroy_infos(struct wl_list *infos)
703{
704 struct global_info *info, *tmp;
705 wl_list_for_each_safe(info, tmp, infos, link)
706 destroy_info(info);
707}
708
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200709int
710main(int argc, char **argv)
711{
712 struct weston_info info;
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200713
714 info.display = wl_display_connect(NULL);
715 if (!info.display) {
716 fprintf(stderr, "failed to create display: %m\n");
717 return -1;
718 }
719
720 wl_list_init(&info.infos);
721
Kristian Høgsbergfa80e112012-10-10 21:34:26 -0400722 info.registry = wl_display_get_registry(info.display);
723 wl_registry_add_listener(info.registry, &registry_listener, &info);
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200724
Philipp Brüschweilerbb0d4b92012-08-15 21:57:23 +0200725 do {
726 info.roundtrip_needed = false;
727 wl_display_roundtrip(info.display);
728 } while (info.roundtrip_needed);
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200729
730 print_infos(&info.infos);
U. Artie Eoff86c68b32014-01-15 13:02:28 -0800731 destroy_infos(&info.infos);
732
733 wl_registry_destroy(info.registry);
734 wl_display_disconnect(info.display);
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200735
736 return 0;
737}