blob: c53ac74e58d164513b929eae2ee18987a2f10ecb [file] [log] [blame]
Philipp Brüschweiler585acb02012-08-15 17:12:00 +02001/*
2 * Copyright © 2012 Philipp Brüschweiler
3 *
4 * Permission to use, copy, modify, distribute, and sell this software and
5 * its documentation for any purpose is hereby granted without fee, provided
6 * that the above copyright notice appear in all copies and that both that
7 * copyright notice and this permission notice appear in supporting
8 * documentation, and that the name of the copyright holders not be used in
9 * advertising or publicity pertaining to distribution of the software
10 * without specific, written prior permission. The copyright holders make
11 * no representations about the suitability of this software for any
12 * purpose. It is provided "as is" without express or implied warranty.
13 *
14 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
15 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
17 * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
18 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
19 * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
20 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21 */
22
U. Artie Eoff86c68b32014-01-15 13:02:28 -080023#include "config.h"
24
25#include <errno.h>
Philipp Brüschweiler585acb02012-08-15 17:12:00 +020026#include <stdbool.h>
27#include <stdio.h>
28#include <stdlib.h>
29#include <string.h>
Philipp Brüschweiler585acb02012-08-15 17:12:00 +020030
31#include <wayland-client.h>
32
33#include "../shared/os-compatibility.h"
34
Jonny Lamb06959082014-08-12 14:58:27 +020035#define MIN(x,y) (((x) < (y)) ? (x) : (y))
36
Philipp Brüschweiler585acb02012-08-15 17:12:00 +020037typedef void (*print_info_t)(void *info);
U. Artie Eoff86c68b32014-01-15 13:02:28 -080038typedef void (*destroy_info_t)(void *info);
Philipp Brüschweiler585acb02012-08-15 17:12:00 +020039
40struct global_info {
41 struct wl_list link;
42
43 uint32_t id;
44 uint32_t version;
45 char *interface;
46
47 print_info_t print;
U. Artie Eoff86c68b32014-01-15 13:02:28 -080048 destroy_info_t destroy;
Philipp Brüschweiler585acb02012-08-15 17:12:00 +020049};
50
Philipp Brüschweiler97cb62a2012-08-15 21:57:24 +020051struct output_mode {
52 struct wl_list link;
53
54 uint32_t flags;
55 int32_t width, height;
56 int32_t refresh;
57};
58
Philipp Brüschweiler585acb02012-08-15 17:12:00 +020059struct output_info {
60 struct global_info global;
61
62 struct wl_output *output;
63
64 struct {
65 int32_t x, y;
66 int32_t physical_width, physical_height;
67 enum wl_output_subpixel subpixel;
68 enum wl_output_transform output_transform;
69 char *make;
70 char *model;
71 } geometry;
72
Philipp Brüschweiler97cb62a2012-08-15 21:57:24 +020073 struct wl_list modes;
Philipp Brüschweiler585acb02012-08-15 17:12:00 +020074};
75
76struct shm_format {
77 struct wl_list link;
78
79 uint32_t format;
80};
81
82struct shm_info {
83 struct global_info global;
84 struct wl_shm *shm;
85
86 struct wl_list formats;
87};
88
89struct seat_info {
90 struct global_info global;
91 struct wl_seat *seat;
Jonny Lamb06959082014-08-12 14:58:27 +020092 struct weston_info *info;
Philipp Brüschweiler585acb02012-08-15 17:12:00 +020093
94 uint32_t capabilities;
Rob Bradford14a76012013-05-31 18:09:52 +010095 char *name;
Jonny Lamb06959082014-08-12 14:58:27 +020096
97 int32_t repeat_rate;
98 int32_t repeat_delay;
Philipp Brüschweiler585acb02012-08-15 17:12:00 +020099};
100
101struct weston_info {
102 struct wl_display *display;
Kristian Høgsbergfa80e112012-10-10 21:34:26 -0400103 struct wl_registry *registry;
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200104
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200105 struct wl_list infos;
Philipp Brüschweilerbb0d4b92012-08-15 21:57:23 +0200106 bool roundtrip_needed;
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200107};
108
Kristian Høgsberg06b16c22013-08-15 14:20:53 -0700109static void *
U. Artie Eoff86c68b32014-01-15 13:02:28 -0800110fail_on_null(void *p)
Kristian Høgsberg06b16c22013-08-15 14:20:53 -0700111{
Kristian Høgsberg06b16c22013-08-15 14:20:53 -0700112 if (p == NULL) {
U. Artie Eoff86c68b32014-01-15 13:02:28 -0800113 fprintf(stderr, "%s: out of memory\n", program_invocation_short_name);
114 exit(EXIT_FAILURE);
Kristian Høgsberg06b16c22013-08-15 14:20:53 -0700115 }
116
117 return p;
118}
119
U. Artie Eoff86c68b32014-01-15 13:02:28 -0800120static void *
121xmalloc(size_t s)
122{
123 return fail_on_null(malloc(s));
124}
125
126static void *
127xzalloc(size_t s)
128{
129 return fail_on_null(calloc(1, s));
130}
131
132static char *
133xstrdup(const char *s)
134{
135 return fail_on_null(strdup(s));
136}
137
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200138static void
139print_global_info(void *data)
140{
141 struct global_info *global = data;
142
143 printf("interface: '%s', version: %u, name: %u\n",
144 global->interface, global->version, global->id);
145}
146
147static void
148init_global_info(struct weston_info *info,
149 struct global_info *global, uint32_t id,
150 const char *interface, uint32_t version)
151{
152 global->id = id;
153 global->version = version;
U. Artie Eoff86c68b32014-01-15 13:02:28 -0800154 global->interface = xstrdup(interface);
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200155
156 wl_list_insert(info->infos.prev, &global->link);
157}
158
159static void
160print_output_info(void *data)
161{
162 struct output_info *output = data;
Philipp Brüschweiler97cb62a2012-08-15 21:57:24 +0200163 struct output_mode *mode;
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200164 const char *subpixel_orientation;
165 const char *transform;
166
167 print_global_info(data);
168
169 switch (output->geometry.subpixel) {
170 case WL_OUTPUT_SUBPIXEL_UNKNOWN:
171 subpixel_orientation = "unknown";
172 break;
173 case WL_OUTPUT_SUBPIXEL_NONE:
174 subpixel_orientation = "none";
175 break;
176 case WL_OUTPUT_SUBPIXEL_HORIZONTAL_RGB:
177 subpixel_orientation = "horizontal rgb";
178 break;
179 case WL_OUTPUT_SUBPIXEL_HORIZONTAL_BGR:
180 subpixel_orientation = "horizontal bgr";
181 break;
182 case WL_OUTPUT_SUBPIXEL_VERTICAL_RGB:
183 subpixel_orientation = "vertical rgb";
184 break;
185 case WL_OUTPUT_SUBPIXEL_VERTICAL_BGR:
186 subpixel_orientation = "vertical bgr";
187 break;
188 default:
189 fprintf(stderr, "unknown subpixel orientation %u\n",
190 output->geometry.subpixel);
191 subpixel_orientation = "unexpected value";
192 break;
193 }
194
195 switch (output->geometry.output_transform) {
196 case WL_OUTPUT_TRANSFORM_NORMAL:
197 transform = "normal";
198 break;
199 case WL_OUTPUT_TRANSFORM_90:
200 transform = "90°";
201 break;
202 case WL_OUTPUT_TRANSFORM_180:
203 transform = "180°";
204 break;
205 case WL_OUTPUT_TRANSFORM_270:
206 transform = "270°";
207 break;
208 case WL_OUTPUT_TRANSFORM_FLIPPED:
209 transform = "flipped";
210 break;
211 case WL_OUTPUT_TRANSFORM_FLIPPED_90:
212 transform = "flipped 90°";
213 break;
214 case WL_OUTPUT_TRANSFORM_FLIPPED_180:
215 transform = "flipped 180°";
216 break;
217 case WL_OUTPUT_TRANSFORM_FLIPPED_270:
218 transform = "flipped 270°";
219 break;
220 default:
221 fprintf(stderr, "unknown output transform %u\n",
222 output->geometry.output_transform);
223 transform = "unexpected value";
224 break;
225 }
226
Philipp Brüschweiler97cb62a2012-08-15 21:57:24 +0200227 printf("\tx: %d, y: %d,\n",
228 output->geometry.x, output->geometry.y);
229 printf("\tphysical_width: %d mm, physical_height: %d mm,\n",
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200230 output->geometry.physical_width,
Philipp Brüschweiler97cb62a2012-08-15 21:57:24 +0200231 output->geometry.physical_height);
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200232 printf("\tmake: '%s', model: '%s',\n",
233 output->geometry.make, output->geometry.model);
U. Artie Eoffcb0e3572014-04-18 09:30:07 -0700234 printf("\tsubpixel_orientation: %s, output_transform: %s,\n",
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200235 subpixel_orientation, transform);
Philipp Brüschweiler97cb62a2012-08-15 21:57:24 +0200236
237 wl_list_for_each(mode, &output->modes, link) {
238 printf("\tmode:\n");
239
240 printf("\t\twidth: %d px, height: %d px, refresh: %.f Hz,\n",
241 mode->width, mode->height,
242 (float) mode->refresh / 1000);
243
244 printf("\t\tflags:");
245 if (mode->flags & WL_OUTPUT_MODE_CURRENT)
246 printf(" current");
247 if (mode->flags & WL_OUTPUT_MODE_PREFERRED)
248 printf(" preferred");
249 printf("\n");
250 }
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200251}
252
253static void
254print_shm_info(void *data)
255{
256 struct shm_info *shm = data;
257 struct shm_format *format;
258
259 print_global_info(data);
260
261 printf("\tformats:");
262
263 wl_list_for_each(format, &shm->formats, link)
Kristian Høgsberg8b66ebd2013-11-20 13:54:00 -0800264 switch (format->format) {
265 case WL_SHM_FORMAT_ARGB8888:
266 printf(" ARGB8888");
267 break;
268 case WL_SHM_FORMAT_XRGB8888:
269 printf(" XRGB8888");
270 break;
271 case WL_SHM_FORMAT_RGB565:
272 printf(" RGB565");
273 break;
274 default:
275 printf(" unknown(%08x)", format->format);
276 break;
277 }
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200278
279 printf("\n");
280}
281
282static void
283print_seat_info(void *data)
284{
285 struct seat_info *seat = data;
286
287 print_global_info(data);
288
Rob Bradford14a76012013-05-31 18:09:52 +0100289 printf("\tname: %s\n", seat->name);
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200290 printf("\tcapabilities:");
291
292 if (seat->capabilities & WL_SEAT_CAPABILITY_POINTER)
293 printf(" pointer");
294 if (seat->capabilities & WL_SEAT_CAPABILITY_KEYBOARD)
295 printf(" keyboard");
296 if (seat->capabilities & WL_SEAT_CAPABILITY_TOUCH)
297 printf(" touch");
298
299 printf("\n");
Jonny Lamb06959082014-08-12 14:58:27 +0200300
301 if (seat->repeat_rate > 0)
302 printf("\tkeyboard repeat rate: %d\n", seat->repeat_rate);
303 if (seat->repeat_delay > 0)
304 printf("\tkeyboard repeat delay: %d\n", seat->repeat_delay);
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200305}
306
307static void
Jonny Lamb06959082014-08-12 14:58:27 +0200308keyboard_handle_keymap(void *data, struct wl_keyboard *keyboard,
309 uint32_t format, int fd, uint32_t size)
310{
311}
312
313static void
314keyboard_handle_enter(void *data, struct wl_keyboard *keyboard,
315 uint32_t serial, struct wl_surface *surface,
316 struct wl_array *keys)
317{
318}
319
320static void
321keyboard_handle_leave(void *data, struct wl_keyboard *keyboard,
322 uint32_t serial, struct wl_surface *surface)
323{
324}
325
326static void
327keyboard_handle_key(void *data, struct wl_keyboard *keyboard,
328 uint32_t serial, uint32_t time, uint32_t key,
329 uint32_t state)
330{
331}
332
333static void
334keyboard_handle_modifiers(void *data, struct wl_keyboard *keyboard,
335 uint32_t serial, uint32_t mods_depressed,
336 uint32_t mods_latched, uint32_t mods_locked,
337 uint32_t group)
338{
339}
340
341static void
342keyboard_handle_repeat_info(void *data, struct wl_keyboard *keyboard,
343 int32_t rate, int32_t delay)
344{
345 struct seat_info *seat = data;
346
347 seat->repeat_rate = rate;
348 seat->repeat_delay = delay;
349}
350
351static const struct wl_keyboard_listener keyboard_listener = {
352 keyboard_handle_keymap,
353 keyboard_handle_enter,
354 keyboard_handle_leave,
355 keyboard_handle_key,
356 keyboard_handle_modifiers,
357 keyboard_handle_repeat_info,
358};
359
360static void
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200361seat_handle_capabilities(void *data, struct wl_seat *wl_seat,
362 enum wl_seat_capability caps)
363{
364 struct seat_info *seat = data;
Jonny Lamb06959082014-08-12 14:58:27 +0200365
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200366 seat->capabilities = caps;
Jonny Lamb06959082014-08-12 14:58:27 +0200367
368 /* we want listen for repeat_info from wl_keyboard, but only
369 * do so if the seat info is >= 4 and if we actually have a
370 * keyboard */
371 if (seat->global.version < 4)
372 return;
373
374 if (caps & WL_SEAT_CAPABILITY_KEYBOARD) {
375 struct wl_keyboard *keyboard;
376
377 keyboard = wl_seat_get_keyboard(seat->seat);
378 wl_keyboard_add_listener(keyboard, &keyboard_listener,
379 seat);
380
381 seat->info->roundtrip_needed = true;
382 }
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200383}
384
Rob Bradford14a76012013-05-31 18:09:52 +0100385static void
386seat_handle_name(void *data, struct wl_seat *wl_seat,
387 const char *name)
388{
389 struct seat_info *seat = data;
U. Artie Eoff86c68b32014-01-15 13:02:28 -0800390 seat->name = xstrdup(name);
Rob Bradford14a76012013-05-31 18:09:52 +0100391}
392
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200393static const struct wl_seat_listener seat_listener = {
394 seat_handle_capabilities,
Rob Bradford14a76012013-05-31 18:09:52 +0100395 seat_handle_name,
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200396};
397
398static void
U. Artie Eoff86c68b32014-01-15 13:02:28 -0800399destroy_seat_info(void *data)
400{
401 struct seat_info *seat = data;
402
403 wl_seat_destroy(seat->seat);
404
405 if (seat->name != NULL)
406 free(seat->name);
407}
408
409static void
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200410add_seat_info(struct weston_info *info, uint32_t id, uint32_t version)
411{
U. Artie Eoff86c68b32014-01-15 13:02:28 -0800412 struct seat_info *seat = xzalloc(sizeof *seat);
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200413
Jonny Lamb06959082014-08-12 14:58:27 +0200414 /* required to set roundtrip_needed to true in capabilities
415 * handler */
416 seat->info = info;
417
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200418 init_global_info(info, &seat->global, id, "wl_seat", version);
419 seat->global.print = print_seat_info;
U. Artie Eoff86c68b32014-01-15 13:02:28 -0800420 seat->global.destroy = destroy_seat_info;
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200421
Kristian Høgsbergfa80e112012-10-10 21:34:26 -0400422 seat->seat = wl_registry_bind(info->registry,
Jonny Lamb06959082014-08-12 14:58:27 +0200423 id, &wl_seat_interface, MIN(version, 4));
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200424 wl_seat_add_listener(seat->seat, &seat_listener, seat);
Philipp Brüschweilerbb0d4b92012-08-15 21:57:23 +0200425
Jonny Lamb06959082014-08-12 14:58:27 +0200426 seat->repeat_rate = seat->repeat_delay = -1;
427
Philipp Brüschweilerbb0d4b92012-08-15 21:57:23 +0200428 info->roundtrip_needed = true;
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200429}
430
431static void
432shm_handle_format(void *data, struct wl_shm *wl_shm, uint32_t format)
433{
434 struct shm_info *shm = data;
U. Artie Eoff86c68b32014-01-15 13:02:28 -0800435 struct shm_format *shm_format = xzalloc(sizeof *shm_format);
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200436
437 wl_list_insert(&shm->formats, &shm_format->link);
438 shm_format->format = format;
439}
440
441static const struct wl_shm_listener shm_listener = {
442 shm_handle_format,
443};
444
445static void
U. Artie Eoff86c68b32014-01-15 13:02:28 -0800446destroy_shm_info(void *data)
447{
448 struct shm_info *shm = data;
449 struct shm_format *format, *tmp;
450
451 wl_list_for_each_safe(format, tmp, &shm->formats, link) {
452 wl_list_remove(&format->link);
453 free(format);
454 }
455
456 wl_shm_destroy(shm->shm);
457}
458
459static void
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200460add_shm_info(struct weston_info *info, uint32_t id, uint32_t version)
461{
U. Artie Eoff86c68b32014-01-15 13:02:28 -0800462 struct shm_info *shm = xzalloc(sizeof *shm);
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200463
464 init_global_info(info, &shm->global, id, "wl_shm", version);
465 shm->global.print = print_shm_info;
U. Artie Eoff86c68b32014-01-15 13:02:28 -0800466 shm->global.destroy = destroy_shm_info;
467
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200468 wl_list_init(&shm->formats);
469
Kristian Høgsbergfa80e112012-10-10 21:34:26 -0400470 shm->shm = wl_registry_bind(info->registry,
471 id, &wl_shm_interface, 1);
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200472 wl_shm_add_listener(shm->shm, &shm_listener, shm);
Philipp Brüschweilerbb0d4b92012-08-15 21:57:23 +0200473
474 info->roundtrip_needed = true;
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200475}
476
477static void
478output_handle_geometry(void *data, struct wl_output *wl_output,
479 int32_t x, int32_t y,
480 int32_t physical_width, int32_t physical_height,
481 int32_t subpixel,
482 const char *make, const char *model,
483 int32_t output_transform)
484{
485 struct output_info *output = data;
486
487 output->geometry.x = x;
488 output->geometry.y = y;
489 output->geometry.physical_width = physical_width;
490 output->geometry.physical_height = physical_height;
491 output->geometry.subpixel = subpixel;
U. Artie Eoff86c68b32014-01-15 13:02:28 -0800492 output->geometry.make = xstrdup(make);
493 output->geometry.model = xstrdup(model);
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200494 output->geometry.output_transform = output_transform;
495}
496
497static void
498output_handle_mode(void *data, struct wl_output *wl_output,
499 uint32_t flags, int32_t width, int32_t height,
500 int32_t refresh)
501{
502 struct output_info *output = data;
Kristian Høgsberg06b16c22013-08-15 14:20:53 -0700503 struct output_mode *mode = xmalloc(sizeof *mode);
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200504
Philipp Brüschweiler97cb62a2012-08-15 21:57:24 +0200505 mode->flags = flags;
506 mode->width = width;
507 mode->height = height;
508 mode->refresh = refresh;
509
510 wl_list_insert(output->modes.prev, &mode->link);
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200511}
512
513static const struct wl_output_listener output_listener = {
514 output_handle_geometry,
515 output_handle_mode,
516};
517
518static void
U. Artie Eoff86c68b32014-01-15 13:02:28 -0800519destroy_output_info(void *data)
520{
521 struct output_info *output = data;
522 struct output_mode *mode, *tmp;
523
524 wl_output_destroy(output->output);
525
526 if (output->geometry.make != NULL)
527 free(output->geometry.make);
528 if (output->geometry.model != NULL)
529 free(output->geometry.model);
530
531 wl_list_for_each_safe(mode, tmp, &output->modes, link) {
532 wl_list_remove(&mode->link);
533 free(mode);
534 }
535}
536
537static void
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200538add_output_info(struct weston_info *info, uint32_t id, uint32_t version)
539{
U. Artie Eoff86c68b32014-01-15 13:02:28 -0800540 struct output_info *output = xzalloc(sizeof *output);
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200541
542 init_global_info(info, &output->global, id, "wl_output", version);
543 output->global.print = print_output_info;
U. Artie Eoff86c68b32014-01-15 13:02:28 -0800544 output->global.destroy = destroy_output_info;
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200545
Philipp Brüschweiler97cb62a2012-08-15 21:57:24 +0200546 wl_list_init(&output->modes);
547
Kristian Høgsbergfa80e112012-10-10 21:34:26 -0400548 output->output = wl_registry_bind(info->registry, id,
549 &wl_output_interface, 1);
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200550 wl_output_add_listener(output->output, &output_listener,
551 output);
Philipp Brüschweilerbb0d4b92012-08-15 21:57:23 +0200552
553 info->roundtrip_needed = true;
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200554}
555
556static void
U. Artie Eoff86c68b32014-01-15 13:02:28 -0800557destroy_global_info(void *data)
558{
559}
560
561static void
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200562add_global_info(struct weston_info *info, uint32_t id,
563 const char *interface, uint32_t version)
564{
U. Artie Eoff86c68b32014-01-15 13:02:28 -0800565 struct global_info *global = xzalloc(sizeof *global);
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200566
567 init_global_info(info, global, id, interface, version);
568 global->print = print_global_info;
U. Artie Eoff86c68b32014-01-15 13:02:28 -0800569 global->destroy = destroy_global_info;
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200570}
571
572static void
Kristian Høgsbergfa80e112012-10-10 21:34:26 -0400573global_handler(void *data, struct wl_registry *registry, uint32_t id,
574 const char *interface, uint32_t version)
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200575{
576 struct weston_info *info = data;
577
578 if (!strcmp(interface, "wl_seat"))
579 add_seat_info(info, id, version);
580 else if (!strcmp(interface, "wl_shm"))
581 add_shm_info(info, id, version);
582 else if (!strcmp(interface, "wl_output"))
583 add_output_info(info, id, version);
584 else
585 add_global_info(info, id, interface, version);
586}
587
Pekka Paalanen0eab05d2013-01-22 14:53:55 +0200588static void
589global_remove_handler(void *data, struct wl_registry *registry, uint32_t name)
590{
591}
592
Kristian Høgsbergfa80e112012-10-10 21:34:26 -0400593static const struct wl_registry_listener registry_listener = {
Pekka Paalanen0eab05d2013-01-22 14:53:55 +0200594 global_handler,
595 global_remove_handler
Kristian Høgsbergfa80e112012-10-10 21:34:26 -0400596};
597
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200598static void
599print_infos(struct wl_list *infos)
600{
601 struct global_info *info;
602
603 wl_list_for_each(info, infos, link)
604 info->print(info);
605}
606
U. Artie Eoff86c68b32014-01-15 13:02:28 -0800607static void
608destroy_info(void *data)
609{
610 struct global_info *global = data;
611
612 global->destroy(data);
613 wl_list_remove(&global->link);
614 free(global->interface);
615 free(data);
616}
617
618static void
619destroy_infos(struct wl_list *infos)
620{
621 struct global_info *info, *tmp;
622 wl_list_for_each_safe(info, tmp, infos, link)
623 destroy_info(info);
624}
625
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200626int
627main(int argc, char **argv)
628{
629 struct weston_info info;
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200630
631 info.display = wl_display_connect(NULL);
632 if (!info.display) {
633 fprintf(stderr, "failed to create display: %m\n");
634 return -1;
635 }
636
637 wl_list_init(&info.infos);
638
Kristian Høgsbergfa80e112012-10-10 21:34:26 -0400639 info.registry = wl_display_get_registry(info.display);
640 wl_registry_add_listener(info.registry, &registry_listener, &info);
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200641
Philipp Brüschweilerbb0d4b92012-08-15 21:57:23 +0200642 do {
643 info.roundtrip_needed = false;
644 wl_display_roundtrip(info.display);
645 } while (info.roundtrip_needed);
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200646
647 print_infos(&info.infos);
U. Artie Eoff86c68b32014-01-15 13:02:28 -0800648 destroy_infos(&info.infos);
649
650 wl_registry_destroy(info.registry);
651 wl_display_disconnect(info.display);
Philipp Brüschweiler585acb02012-08-15 17:12:00 +0200652
653 return 0;
654}