2 * Copyright © 2012 Philipp Brüschweiler
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.
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.
28 #include <wayland-client.h>
30 #include "../shared/os-compatibility.h"
32 typedef void (*print_info_t)(void *info);
48 int32_t width, height;
53 struct global_info global;
55 struct wl_output *output;
59 int32_t physical_width, physical_height;
60 enum wl_output_subpixel subpixel;
61 enum wl_output_transform output_transform;
76 struct global_info global;
79 struct wl_list formats;
83 struct global_info global;
86 uint32_t capabilities;
90 struct wl_display *display;
91 struct wl_registry *registry;
94 bool roundtrip_needed;
98 print_global_info(void *data)
100 struct global_info *global = data;
102 printf("interface: '%s', version: %u, name: %u\n",
103 global->interface, global->version, global->id);
107 init_global_info(struct weston_info *info,
108 struct global_info *global, uint32_t id,
109 const char *interface, uint32_t version)
112 global->version = version;
113 global->interface = strdup(interface);
115 wl_list_insert(info->infos.prev, &global->link);
119 print_output_info(void *data)
121 struct output_info *output = data;
122 struct output_mode *mode;
123 const char *subpixel_orientation;
124 const char *transform;
126 print_global_info(data);
128 switch (output->geometry.subpixel) {
129 case WL_OUTPUT_SUBPIXEL_UNKNOWN:
130 subpixel_orientation = "unknown";
132 case WL_OUTPUT_SUBPIXEL_NONE:
133 subpixel_orientation = "none";
135 case WL_OUTPUT_SUBPIXEL_HORIZONTAL_RGB:
136 subpixel_orientation = "horizontal rgb";
138 case WL_OUTPUT_SUBPIXEL_HORIZONTAL_BGR:
139 subpixel_orientation = "horizontal bgr";
141 case WL_OUTPUT_SUBPIXEL_VERTICAL_RGB:
142 subpixel_orientation = "vertical rgb";
144 case WL_OUTPUT_SUBPIXEL_VERTICAL_BGR:
145 subpixel_orientation = "vertical bgr";
148 fprintf(stderr, "unknown subpixel orientation %u\n",
149 output->geometry.subpixel);
150 subpixel_orientation = "unexpected value";
154 switch (output->geometry.output_transform) {
155 case WL_OUTPUT_TRANSFORM_NORMAL:
156 transform = "normal";
158 case WL_OUTPUT_TRANSFORM_90:
161 case WL_OUTPUT_TRANSFORM_180:
164 case WL_OUTPUT_TRANSFORM_270:
167 case WL_OUTPUT_TRANSFORM_FLIPPED:
168 transform = "flipped";
170 case WL_OUTPUT_TRANSFORM_FLIPPED_90:
171 transform = "flipped 90°";
173 case WL_OUTPUT_TRANSFORM_FLIPPED_180:
174 transform = "flipped 180°";
176 case WL_OUTPUT_TRANSFORM_FLIPPED_270:
177 transform = "flipped 270°";
180 fprintf(stderr, "unknown output transform %u\n",
181 output->geometry.output_transform);
182 transform = "unexpected value";
186 printf("\tx: %d, y: %d,\n",
187 output->geometry.x, output->geometry.y);
188 printf("\tphysical_width: %d mm, physical_height: %d mm,\n",
189 output->geometry.physical_width,
190 output->geometry.physical_height);
191 printf("\tmake: '%s', model: '%s',\n",
192 output->geometry.make, output->geometry.model);
193 printf("\tsubpixel_orientation: %s, output_tranform: %s,\n",
194 subpixel_orientation, transform);
196 wl_list_for_each(mode, &output->modes, link) {
199 printf("\t\twidth: %d px, height: %d px, refresh: %.f Hz,\n",
200 mode->width, mode->height,
201 (float) mode->refresh / 1000);
203 printf("\t\tflags:");
204 if (mode->flags & WL_OUTPUT_MODE_CURRENT)
206 if (mode->flags & WL_OUTPUT_MODE_PREFERRED)
207 printf(" preferred");
213 print_shm_info(void *data)
215 struct shm_info *shm = data;
216 struct shm_format *format;
218 print_global_info(data);
220 printf("\tformats:");
222 wl_list_for_each(format, &shm->formats, link)
223 printf(" %s", (format->format == WL_SHM_FORMAT_ARGB8888) ?
224 "ARGB8888" : "XRGB8888");
230 print_seat_info(void *data)
232 struct seat_info *seat = data;
234 print_global_info(data);
236 printf("\tcapabilities:");
238 if (seat->capabilities & WL_SEAT_CAPABILITY_POINTER)
240 if (seat->capabilities & WL_SEAT_CAPABILITY_KEYBOARD)
242 if (seat->capabilities & WL_SEAT_CAPABILITY_TOUCH)
249 seat_handle_capabilities(void *data, struct wl_seat *wl_seat,
250 enum wl_seat_capability caps)
252 struct seat_info *seat = data;
253 seat->capabilities = caps;
256 static const struct wl_seat_listener seat_listener = {
257 seat_handle_capabilities,
261 add_seat_info(struct weston_info *info, uint32_t id, uint32_t version)
263 struct seat_info *seat = malloc(sizeof *seat);
265 init_global_info(info, &seat->global, id, "wl_seat", version);
266 seat->global.print = print_seat_info;
268 seat->seat = wl_registry_bind(info->registry,
269 id, &wl_seat_interface, 1);
270 wl_seat_add_listener(seat->seat, &seat_listener, seat);
272 info->roundtrip_needed = true;
276 shm_handle_format(void *data, struct wl_shm *wl_shm, uint32_t format)
278 struct shm_info *shm = data;
279 struct shm_format *shm_format = malloc(sizeof *shm_format);
281 wl_list_insert(&shm->formats, &shm_format->link);
282 shm_format->format = format;
285 static const struct wl_shm_listener shm_listener = {
290 add_shm_info(struct weston_info *info, uint32_t id, uint32_t version)
292 struct shm_info *shm = malloc(sizeof *shm);
294 init_global_info(info, &shm->global, id, "wl_shm", version);
295 shm->global.print = print_shm_info;
296 wl_list_init(&shm->formats);
298 shm->shm = wl_registry_bind(info->registry,
299 id, &wl_shm_interface, 1);
300 wl_shm_add_listener(shm->shm, &shm_listener, shm);
302 info->roundtrip_needed = true;
306 output_handle_geometry(void *data, struct wl_output *wl_output,
307 int32_t x, int32_t y,
308 int32_t physical_width, int32_t physical_height,
310 const char *make, const char *model,
311 int32_t output_transform)
313 struct output_info *output = data;
315 output->geometry.x = x;
316 output->geometry.y = y;
317 output->geometry.physical_width = physical_width;
318 output->geometry.physical_height = physical_height;
319 output->geometry.subpixel = subpixel;
320 output->geometry.make = strdup(make);
321 output->geometry.model = strdup(model);
322 output->geometry.output_transform = output_transform;
326 output_handle_mode(void *data, struct wl_output *wl_output,
327 uint32_t flags, int32_t width, int32_t height,
330 struct output_info *output = data;
331 struct output_mode *mode = malloc(sizeof *mode);
335 mode->height = height;
336 mode->refresh = refresh;
338 wl_list_insert(output->modes.prev, &mode->link);
341 static const struct wl_output_listener output_listener = {
342 output_handle_geometry,
347 add_output_info(struct weston_info *info, uint32_t id, uint32_t version)
349 struct output_info *output = malloc(sizeof *output);
351 init_global_info(info, &output->global, id, "wl_output", version);
352 output->global.print = print_output_info;
354 wl_list_init(&output->modes);
356 output->output = wl_registry_bind(info->registry, id,
357 &wl_output_interface, 1);
358 wl_output_add_listener(output->output, &output_listener,
361 info->roundtrip_needed = true;
365 add_global_info(struct weston_info *info, uint32_t id,
366 const char *interface, uint32_t version)
368 struct global_info *global = malloc(sizeof *global);
370 init_global_info(info, global, id, interface, version);
371 global->print = print_global_info;
375 global_handler(void *data, struct wl_registry *registry, uint32_t id,
376 const char *interface, uint32_t version)
378 struct weston_info *info = data;
380 if (!strcmp(interface, "wl_seat"))
381 add_seat_info(info, id, version);
382 else if (!strcmp(interface, "wl_shm"))
383 add_shm_info(info, id, version);
384 else if (!strcmp(interface, "wl_output"))
385 add_output_info(info, id, version);
387 add_global_info(info, id, interface, version);
390 static const struct wl_registry_listener registry_listener = {
395 print_infos(struct wl_list *infos)
397 struct global_info *info;
399 wl_list_for_each(info, infos, link)
404 main(int argc, char **argv)
406 struct weston_info info;
408 info.display = wl_display_connect(NULL);
410 fprintf(stderr, "failed to create display: %m\n");
414 wl_list_init(&info.infos);
416 info.registry = wl_display_get_registry(info.display);
417 wl_registry_add_listener(info.registry, ®istry_listener, &info);
420 info.roundtrip_needed = false;
421 wl_display_roundtrip(info.display);
422 } while (info.roundtrip_needed);
424 print_infos(&info.infos);