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;
93 bool roundtrip_needed;
97 print_global_info(void *data)
99 struct global_info *global = data;
101 printf("interface: '%s', version: %u, name: %u\n",
102 global->interface, global->version, global->id);
106 init_global_info(struct weston_info *info,
107 struct global_info *global, uint32_t id,
108 const char *interface, uint32_t version)
111 global->version = version;
112 global->interface = strdup(interface);
114 wl_list_insert(info->infos.prev, &global->link);
118 print_output_info(void *data)
120 struct output_info *output = data;
121 struct output_mode *mode;
122 const char *subpixel_orientation;
123 const char *transform;
125 print_global_info(data);
127 switch (output->geometry.subpixel) {
128 case WL_OUTPUT_SUBPIXEL_UNKNOWN:
129 subpixel_orientation = "unknown";
131 case WL_OUTPUT_SUBPIXEL_NONE:
132 subpixel_orientation = "none";
134 case WL_OUTPUT_SUBPIXEL_HORIZONTAL_RGB:
135 subpixel_orientation = "horizontal rgb";
137 case WL_OUTPUT_SUBPIXEL_HORIZONTAL_BGR:
138 subpixel_orientation = "horizontal bgr";
140 case WL_OUTPUT_SUBPIXEL_VERTICAL_RGB:
141 subpixel_orientation = "vertical rgb";
143 case WL_OUTPUT_SUBPIXEL_VERTICAL_BGR:
144 subpixel_orientation = "vertical bgr";
147 fprintf(stderr, "unknown subpixel orientation %u\n",
148 output->geometry.subpixel);
149 subpixel_orientation = "unexpected value";
153 switch (output->geometry.output_transform) {
154 case WL_OUTPUT_TRANSFORM_NORMAL:
155 transform = "normal";
157 case WL_OUTPUT_TRANSFORM_90:
160 case WL_OUTPUT_TRANSFORM_180:
163 case WL_OUTPUT_TRANSFORM_270:
166 case WL_OUTPUT_TRANSFORM_FLIPPED:
167 transform = "flipped";
169 case WL_OUTPUT_TRANSFORM_FLIPPED_90:
170 transform = "flipped 90°";
172 case WL_OUTPUT_TRANSFORM_FLIPPED_180:
173 transform = "flipped 180°";
175 case WL_OUTPUT_TRANSFORM_FLIPPED_270:
176 transform = "flipped 270°";
179 fprintf(stderr, "unknown output transform %u\n",
180 output->geometry.output_transform);
181 transform = "unexpected value";
185 printf("\tx: %d, y: %d,\n",
186 output->geometry.x, output->geometry.y);
187 printf("\tphysical_width: %d mm, physical_height: %d mm,\n",
188 output->geometry.physical_width,
189 output->geometry.physical_height);
190 printf("\tmake: '%s', model: '%s',\n",
191 output->geometry.make, output->geometry.model);
192 printf("\tsubpixel_orientation: %s, output_tranform: %s,\n",
193 subpixel_orientation, transform);
195 wl_list_for_each(mode, &output->modes, link) {
198 printf("\t\twidth: %d px, height: %d px, refresh: %.f Hz,\n",
199 mode->width, mode->height,
200 (float) mode->refresh / 1000);
202 printf("\t\tflags:");
203 if (mode->flags & WL_OUTPUT_MODE_CURRENT)
205 if (mode->flags & WL_OUTPUT_MODE_PREFERRED)
206 printf(" preferred");
212 print_shm_info(void *data)
214 struct shm_info *shm = data;
215 struct shm_format *format;
217 print_global_info(data);
219 printf("\tformats:");
221 wl_list_for_each(format, &shm->formats, link)
222 printf(" %s", (format->format == WL_SHM_FORMAT_ARGB8888) ?
223 "ARGB8888" : "XRGB8888");
229 print_seat_info(void *data)
231 struct seat_info *seat = data;
233 print_global_info(data);
235 printf("\tcapabilities:");
237 if (seat->capabilities & WL_SEAT_CAPABILITY_POINTER)
239 if (seat->capabilities & WL_SEAT_CAPABILITY_KEYBOARD)
241 if (seat->capabilities & WL_SEAT_CAPABILITY_TOUCH)
248 seat_handle_capabilities(void *data, struct wl_seat *wl_seat,
249 enum wl_seat_capability caps)
251 struct seat_info *seat = data;
252 seat->capabilities = caps;
255 static const struct wl_seat_listener seat_listener = {
256 seat_handle_capabilities,
260 add_seat_info(struct weston_info *info, uint32_t id, uint32_t version)
262 struct seat_info *seat = malloc(sizeof *seat);
264 init_global_info(info, &seat->global, id, "wl_seat", version);
265 seat->global.print = print_seat_info;
267 seat->seat = wl_display_bind(info->display, id, &wl_seat_interface);
268 wl_seat_add_listener(seat->seat, &seat_listener, seat);
270 info->roundtrip_needed = true;
274 shm_handle_format(void *data, struct wl_shm *wl_shm, uint32_t format)
276 struct shm_info *shm = data;
277 struct shm_format *shm_format = malloc(sizeof *shm_format);
279 wl_list_insert(&shm->formats, &shm_format->link);
280 shm_format->format = format;
283 static const struct wl_shm_listener shm_listener = {
288 add_shm_info(struct weston_info *info, uint32_t id, uint32_t version)
290 struct shm_info *shm = malloc(sizeof *shm);
292 init_global_info(info, &shm->global, id, "wl_shm", version);
293 shm->global.print = print_shm_info;
294 wl_list_init(&shm->formats);
296 shm->shm = wl_display_bind(info->display, id, &wl_shm_interface);
297 wl_shm_add_listener(shm->shm, &shm_listener, shm);
299 info->roundtrip_needed = true;
303 output_handle_geometry(void *data, struct wl_output *wl_output,
304 int32_t x, int32_t y,
305 int32_t physical_width, int32_t physical_height,
307 const char *make, const char *model,
308 int32_t output_transform)
310 struct output_info *output = data;
312 output->geometry.x = x;
313 output->geometry.y = y;
314 output->geometry.physical_width = physical_width;
315 output->geometry.physical_height = physical_height;
316 output->geometry.subpixel = subpixel;
317 output->geometry.make = strdup(make);
318 output->geometry.model = strdup(model);
319 output->geometry.output_transform = output_transform;
323 output_handle_mode(void *data, struct wl_output *wl_output,
324 uint32_t flags, int32_t width, int32_t height,
327 struct output_info *output = data;
328 struct output_mode *mode = malloc(sizeof *mode);
332 mode->height = height;
333 mode->refresh = refresh;
335 wl_list_insert(output->modes.prev, &mode->link);
338 static const struct wl_output_listener output_listener = {
339 output_handle_geometry,
344 add_output_info(struct weston_info *info, uint32_t id, uint32_t version)
346 struct output_info *output = malloc(sizeof *output);
348 init_global_info(info, &output->global, id, "wl_output", version);
349 output->global.print = print_output_info;
351 wl_list_init(&output->modes);
353 output->output = wl_display_bind(info->display, id,
354 &wl_output_interface);
355 wl_output_add_listener(output->output, &output_listener,
358 info->roundtrip_needed = true;
362 add_global_info(struct weston_info *info, uint32_t id,
363 const char *interface, uint32_t version)
365 struct global_info *global = malloc(sizeof *global);
367 init_global_info(info, global, id, interface, version);
368 global->print = print_global_info;
372 global_handler(struct wl_display *display, uint32_t id,
373 const char *interface, uint32_t version, void *data)
375 struct weston_info *info = data;
377 if (!strcmp(interface, "wl_seat"))
378 add_seat_info(info, id, version);
379 else if (!strcmp(interface, "wl_shm"))
380 add_shm_info(info, id, version);
381 else if (!strcmp(interface, "wl_output"))
382 add_output_info(info, id, version);
384 add_global_info(info, id, interface, version);
388 print_infos(struct wl_list *infos)
390 struct global_info *info;
392 wl_list_for_each(info, infos, link)
397 main(int argc, char **argv)
399 struct weston_info info;
401 info.display = wl_display_connect(NULL);
403 fprintf(stderr, "failed to create display: %m\n");
407 wl_list_init(&info.infos);
409 wl_display_add_global_listener(info.display,
414 info.roundtrip_needed = false;
415 wl_display_roundtrip(info.display);
416 } while (info.roundtrip_needed);
418 print_infos(&info.infos);