Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 1 | /* |
| 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 Eoff | 86c68b3 | 2014-01-15 13:02:28 -0800 | [diff] [blame] | 23 | #include "config.h" |
| 24 | |
| 25 | #include <errno.h> |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 26 | #include <stdbool.h> |
| 27 | #include <stdio.h> |
| 28 | #include <stdlib.h> |
| 29 | #include <string.h> |
Pekka Paalanen | 93a6afd | 2014-09-23 22:08:44 -0400 | [diff] [blame^] | 30 | #include <time.h> |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 31 | |
| 32 | #include <wayland-client.h> |
| 33 | |
| 34 | #include "../shared/os-compatibility.h" |
Pekka Paalanen | 93a6afd | 2014-09-23 22:08:44 -0400 | [diff] [blame^] | 35 | #include "presentation_timing-client-protocol.h" |
| 36 | |
| 37 | #define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0]) |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 38 | |
Jonny Lamb | 0695908 | 2014-08-12 14:58:27 +0200 | [diff] [blame] | 39 | #define MIN(x,y) (((x) < (y)) ? (x) : (y)) |
| 40 | |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 41 | typedef void (*print_info_t)(void *info); |
U. Artie Eoff | 86c68b3 | 2014-01-15 13:02:28 -0800 | [diff] [blame] | 42 | typedef void (*destroy_info_t)(void *info); |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 43 | |
| 44 | struct 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 Eoff | 86c68b3 | 2014-01-15 13:02:28 -0800 | [diff] [blame] | 52 | destroy_info_t destroy; |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 53 | }; |
| 54 | |
Philipp Brüschweiler | 97cb62a | 2012-08-15 21:57:24 +0200 | [diff] [blame] | 55 | struct 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üschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 63 | struct output_info { |
| 64 | struct global_info global; |
| 65 | |
| 66 | struct wl_output *output; |
| 67 | |
| 68 | struct { |
| 69 | int32_t x, y; |
| 70 | int32_t physical_width, physical_height; |
| 71 | enum wl_output_subpixel subpixel; |
| 72 | enum wl_output_transform output_transform; |
| 73 | char *make; |
| 74 | char *model; |
| 75 | } geometry; |
| 76 | |
Philipp Brüschweiler | 97cb62a | 2012-08-15 21:57:24 +0200 | [diff] [blame] | 77 | struct wl_list modes; |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 78 | }; |
| 79 | |
| 80 | struct shm_format { |
| 81 | struct wl_list link; |
| 82 | |
| 83 | uint32_t format; |
| 84 | }; |
| 85 | |
| 86 | struct shm_info { |
| 87 | struct global_info global; |
| 88 | struct wl_shm *shm; |
| 89 | |
| 90 | struct wl_list formats; |
| 91 | }; |
| 92 | |
| 93 | struct seat_info { |
| 94 | struct global_info global; |
| 95 | struct wl_seat *seat; |
Jonny Lamb | 0695908 | 2014-08-12 14:58:27 +0200 | [diff] [blame] | 96 | struct weston_info *info; |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 97 | |
| 98 | uint32_t capabilities; |
Rob Bradford | 14a7601 | 2013-05-31 18:09:52 +0100 | [diff] [blame] | 99 | char *name; |
Jonny Lamb | 0695908 | 2014-08-12 14:58:27 +0200 | [diff] [blame] | 100 | |
| 101 | int32_t repeat_rate; |
| 102 | int32_t repeat_delay; |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 103 | }; |
| 104 | |
Pekka Paalanen | 93a6afd | 2014-09-23 22:08:44 -0400 | [diff] [blame^] | 105 | struct presentation_info { |
| 106 | struct global_info global; |
| 107 | struct presentation *presentation; |
| 108 | |
| 109 | clockid_t clk_id; |
| 110 | }; |
| 111 | |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 112 | struct weston_info { |
| 113 | struct wl_display *display; |
Kristian Høgsberg | fa80e11 | 2012-10-10 21:34:26 -0400 | [diff] [blame] | 114 | struct wl_registry *registry; |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 115 | |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 116 | struct wl_list infos; |
Philipp Brüschweiler | bb0d4b9 | 2012-08-15 21:57:23 +0200 | [diff] [blame] | 117 | bool roundtrip_needed; |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 118 | }; |
| 119 | |
Kristian Høgsberg | 06b16c2 | 2013-08-15 14:20:53 -0700 | [diff] [blame] | 120 | static void * |
U. Artie Eoff | 86c68b3 | 2014-01-15 13:02:28 -0800 | [diff] [blame] | 121 | fail_on_null(void *p) |
Kristian Høgsberg | 06b16c2 | 2013-08-15 14:20:53 -0700 | [diff] [blame] | 122 | { |
Kristian Høgsberg | 06b16c2 | 2013-08-15 14:20:53 -0700 | [diff] [blame] | 123 | if (p == NULL) { |
U. Artie Eoff | 86c68b3 | 2014-01-15 13:02:28 -0800 | [diff] [blame] | 124 | fprintf(stderr, "%s: out of memory\n", program_invocation_short_name); |
| 125 | exit(EXIT_FAILURE); |
Kristian Høgsberg | 06b16c2 | 2013-08-15 14:20:53 -0700 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | return p; |
| 129 | } |
| 130 | |
U. Artie Eoff | 86c68b3 | 2014-01-15 13:02:28 -0800 | [diff] [blame] | 131 | static void * |
| 132 | xmalloc(size_t s) |
| 133 | { |
| 134 | return fail_on_null(malloc(s)); |
| 135 | } |
| 136 | |
| 137 | static void * |
| 138 | xzalloc(size_t s) |
| 139 | { |
| 140 | return fail_on_null(calloc(1, s)); |
| 141 | } |
| 142 | |
| 143 | static char * |
| 144 | xstrdup(const char *s) |
| 145 | { |
| 146 | return fail_on_null(strdup(s)); |
| 147 | } |
| 148 | |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 149 | static void |
| 150 | print_global_info(void *data) |
| 151 | { |
| 152 | struct global_info *global = data; |
| 153 | |
| 154 | printf("interface: '%s', version: %u, name: %u\n", |
| 155 | global->interface, global->version, global->id); |
| 156 | } |
| 157 | |
| 158 | static void |
| 159 | init_global_info(struct weston_info *info, |
| 160 | struct global_info *global, uint32_t id, |
| 161 | const char *interface, uint32_t version) |
| 162 | { |
| 163 | global->id = id; |
| 164 | global->version = version; |
U. Artie Eoff | 86c68b3 | 2014-01-15 13:02:28 -0800 | [diff] [blame] | 165 | global->interface = xstrdup(interface); |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 166 | |
| 167 | wl_list_insert(info->infos.prev, &global->link); |
| 168 | } |
| 169 | |
| 170 | static void |
| 171 | print_output_info(void *data) |
| 172 | { |
| 173 | struct output_info *output = data; |
Philipp Brüschweiler | 97cb62a | 2012-08-15 21:57:24 +0200 | [diff] [blame] | 174 | struct output_mode *mode; |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 175 | const char *subpixel_orientation; |
| 176 | const char *transform; |
| 177 | |
| 178 | print_global_info(data); |
| 179 | |
| 180 | switch (output->geometry.subpixel) { |
| 181 | case WL_OUTPUT_SUBPIXEL_UNKNOWN: |
| 182 | subpixel_orientation = "unknown"; |
| 183 | break; |
| 184 | case WL_OUTPUT_SUBPIXEL_NONE: |
| 185 | subpixel_orientation = "none"; |
| 186 | break; |
| 187 | case WL_OUTPUT_SUBPIXEL_HORIZONTAL_RGB: |
| 188 | subpixel_orientation = "horizontal rgb"; |
| 189 | break; |
| 190 | case WL_OUTPUT_SUBPIXEL_HORIZONTAL_BGR: |
| 191 | subpixel_orientation = "horizontal bgr"; |
| 192 | break; |
| 193 | case WL_OUTPUT_SUBPIXEL_VERTICAL_RGB: |
| 194 | subpixel_orientation = "vertical rgb"; |
| 195 | break; |
| 196 | case WL_OUTPUT_SUBPIXEL_VERTICAL_BGR: |
| 197 | subpixel_orientation = "vertical bgr"; |
| 198 | break; |
| 199 | default: |
| 200 | fprintf(stderr, "unknown subpixel orientation %u\n", |
| 201 | output->geometry.subpixel); |
| 202 | subpixel_orientation = "unexpected value"; |
| 203 | break; |
| 204 | } |
| 205 | |
| 206 | switch (output->geometry.output_transform) { |
| 207 | case WL_OUTPUT_TRANSFORM_NORMAL: |
| 208 | transform = "normal"; |
| 209 | break; |
| 210 | case WL_OUTPUT_TRANSFORM_90: |
| 211 | transform = "90°"; |
| 212 | break; |
| 213 | case WL_OUTPUT_TRANSFORM_180: |
| 214 | transform = "180°"; |
| 215 | break; |
| 216 | case WL_OUTPUT_TRANSFORM_270: |
| 217 | transform = "270°"; |
| 218 | break; |
| 219 | case WL_OUTPUT_TRANSFORM_FLIPPED: |
| 220 | transform = "flipped"; |
| 221 | break; |
| 222 | case WL_OUTPUT_TRANSFORM_FLIPPED_90: |
| 223 | transform = "flipped 90°"; |
| 224 | break; |
| 225 | case WL_OUTPUT_TRANSFORM_FLIPPED_180: |
| 226 | transform = "flipped 180°"; |
| 227 | break; |
| 228 | case WL_OUTPUT_TRANSFORM_FLIPPED_270: |
| 229 | transform = "flipped 270°"; |
| 230 | break; |
| 231 | default: |
| 232 | fprintf(stderr, "unknown output transform %u\n", |
| 233 | output->geometry.output_transform); |
| 234 | transform = "unexpected value"; |
| 235 | break; |
| 236 | } |
| 237 | |
Philipp Brüschweiler | 97cb62a | 2012-08-15 21:57:24 +0200 | [diff] [blame] | 238 | printf("\tx: %d, y: %d,\n", |
| 239 | output->geometry.x, output->geometry.y); |
| 240 | printf("\tphysical_width: %d mm, physical_height: %d mm,\n", |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 241 | output->geometry.physical_width, |
Philipp Brüschweiler | 97cb62a | 2012-08-15 21:57:24 +0200 | [diff] [blame] | 242 | output->geometry.physical_height); |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 243 | printf("\tmake: '%s', model: '%s',\n", |
| 244 | output->geometry.make, output->geometry.model); |
U. Artie Eoff | cb0e357 | 2014-04-18 09:30:07 -0700 | [diff] [blame] | 245 | printf("\tsubpixel_orientation: %s, output_transform: %s,\n", |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 246 | subpixel_orientation, transform); |
Philipp Brüschweiler | 97cb62a | 2012-08-15 21:57:24 +0200 | [diff] [blame] | 247 | |
| 248 | wl_list_for_each(mode, &output->modes, link) { |
| 249 | printf("\tmode:\n"); |
| 250 | |
| 251 | printf("\t\twidth: %d px, height: %d px, refresh: %.f Hz,\n", |
| 252 | mode->width, mode->height, |
| 253 | (float) mode->refresh / 1000); |
| 254 | |
| 255 | printf("\t\tflags:"); |
| 256 | if (mode->flags & WL_OUTPUT_MODE_CURRENT) |
| 257 | printf(" current"); |
| 258 | if (mode->flags & WL_OUTPUT_MODE_PREFERRED) |
| 259 | printf(" preferred"); |
| 260 | printf("\n"); |
| 261 | } |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 262 | } |
| 263 | |
| 264 | static void |
| 265 | print_shm_info(void *data) |
| 266 | { |
| 267 | struct shm_info *shm = data; |
| 268 | struct shm_format *format; |
| 269 | |
| 270 | print_global_info(data); |
| 271 | |
| 272 | printf("\tformats:"); |
| 273 | |
| 274 | wl_list_for_each(format, &shm->formats, link) |
Kristian Høgsberg | 8b66ebd | 2013-11-20 13:54:00 -0800 | [diff] [blame] | 275 | switch (format->format) { |
| 276 | case WL_SHM_FORMAT_ARGB8888: |
| 277 | printf(" ARGB8888"); |
| 278 | break; |
| 279 | case WL_SHM_FORMAT_XRGB8888: |
| 280 | printf(" XRGB8888"); |
| 281 | break; |
| 282 | case WL_SHM_FORMAT_RGB565: |
| 283 | printf(" RGB565"); |
| 284 | break; |
| 285 | default: |
| 286 | printf(" unknown(%08x)", format->format); |
| 287 | break; |
| 288 | } |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 289 | |
| 290 | printf("\n"); |
| 291 | } |
| 292 | |
| 293 | static void |
| 294 | print_seat_info(void *data) |
| 295 | { |
| 296 | struct seat_info *seat = data; |
| 297 | |
| 298 | print_global_info(data); |
| 299 | |
Rob Bradford | 14a7601 | 2013-05-31 18:09:52 +0100 | [diff] [blame] | 300 | printf("\tname: %s\n", seat->name); |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 301 | printf("\tcapabilities:"); |
| 302 | |
| 303 | if (seat->capabilities & WL_SEAT_CAPABILITY_POINTER) |
| 304 | printf(" pointer"); |
| 305 | if (seat->capabilities & WL_SEAT_CAPABILITY_KEYBOARD) |
| 306 | printf(" keyboard"); |
| 307 | if (seat->capabilities & WL_SEAT_CAPABILITY_TOUCH) |
| 308 | printf(" touch"); |
| 309 | |
| 310 | printf("\n"); |
Jonny Lamb | 0695908 | 2014-08-12 14:58:27 +0200 | [diff] [blame] | 311 | |
| 312 | if (seat->repeat_rate > 0) |
| 313 | printf("\tkeyboard repeat rate: %d\n", seat->repeat_rate); |
| 314 | if (seat->repeat_delay > 0) |
| 315 | printf("\tkeyboard repeat delay: %d\n", seat->repeat_delay); |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 316 | } |
| 317 | |
| 318 | static void |
Jonny Lamb | 0695908 | 2014-08-12 14:58:27 +0200 | [diff] [blame] | 319 | keyboard_handle_keymap(void *data, struct wl_keyboard *keyboard, |
| 320 | uint32_t format, int fd, uint32_t size) |
| 321 | { |
| 322 | } |
| 323 | |
| 324 | static void |
| 325 | keyboard_handle_enter(void *data, struct wl_keyboard *keyboard, |
| 326 | uint32_t serial, struct wl_surface *surface, |
| 327 | struct wl_array *keys) |
| 328 | { |
| 329 | } |
| 330 | |
| 331 | static void |
| 332 | keyboard_handle_leave(void *data, struct wl_keyboard *keyboard, |
| 333 | uint32_t serial, struct wl_surface *surface) |
| 334 | { |
| 335 | } |
| 336 | |
| 337 | static void |
| 338 | keyboard_handle_key(void *data, struct wl_keyboard *keyboard, |
| 339 | uint32_t serial, uint32_t time, uint32_t key, |
| 340 | uint32_t state) |
| 341 | { |
| 342 | } |
| 343 | |
| 344 | static void |
| 345 | keyboard_handle_modifiers(void *data, struct wl_keyboard *keyboard, |
| 346 | uint32_t serial, uint32_t mods_depressed, |
| 347 | uint32_t mods_latched, uint32_t mods_locked, |
| 348 | uint32_t group) |
| 349 | { |
| 350 | } |
| 351 | |
| 352 | static void |
| 353 | keyboard_handle_repeat_info(void *data, struct wl_keyboard *keyboard, |
| 354 | int32_t rate, int32_t delay) |
| 355 | { |
| 356 | struct seat_info *seat = data; |
| 357 | |
| 358 | seat->repeat_rate = rate; |
| 359 | seat->repeat_delay = delay; |
| 360 | } |
| 361 | |
| 362 | static const struct wl_keyboard_listener keyboard_listener = { |
| 363 | keyboard_handle_keymap, |
| 364 | keyboard_handle_enter, |
| 365 | keyboard_handle_leave, |
| 366 | keyboard_handle_key, |
| 367 | keyboard_handle_modifiers, |
| 368 | keyboard_handle_repeat_info, |
| 369 | }; |
| 370 | |
| 371 | static void |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 372 | seat_handle_capabilities(void *data, struct wl_seat *wl_seat, |
| 373 | enum wl_seat_capability caps) |
| 374 | { |
| 375 | struct seat_info *seat = data; |
Jonny Lamb | 0695908 | 2014-08-12 14:58:27 +0200 | [diff] [blame] | 376 | |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 377 | seat->capabilities = caps; |
Jonny Lamb | 0695908 | 2014-08-12 14:58:27 +0200 | [diff] [blame] | 378 | |
| 379 | /* we want listen for repeat_info from wl_keyboard, but only |
| 380 | * do so if the seat info is >= 4 and if we actually have a |
| 381 | * keyboard */ |
| 382 | if (seat->global.version < 4) |
| 383 | return; |
| 384 | |
| 385 | if (caps & WL_SEAT_CAPABILITY_KEYBOARD) { |
| 386 | struct wl_keyboard *keyboard; |
| 387 | |
| 388 | keyboard = wl_seat_get_keyboard(seat->seat); |
| 389 | wl_keyboard_add_listener(keyboard, &keyboard_listener, |
| 390 | seat); |
| 391 | |
| 392 | seat->info->roundtrip_needed = true; |
| 393 | } |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 394 | } |
| 395 | |
Rob Bradford | 14a7601 | 2013-05-31 18:09:52 +0100 | [diff] [blame] | 396 | static void |
| 397 | seat_handle_name(void *data, struct wl_seat *wl_seat, |
| 398 | const char *name) |
| 399 | { |
| 400 | struct seat_info *seat = data; |
U. Artie Eoff | 86c68b3 | 2014-01-15 13:02:28 -0800 | [diff] [blame] | 401 | seat->name = xstrdup(name); |
Rob Bradford | 14a7601 | 2013-05-31 18:09:52 +0100 | [diff] [blame] | 402 | } |
| 403 | |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 404 | static const struct wl_seat_listener seat_listener = { |
| 405 | seat_handle_capabilities, |
Rob Bradford | 14a7601 | 2013-05-31 18:09:52 +0100 | [diff] [blame] | 406 | seat_handle_name, |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 407 | }; |
| 408 | |
| 409 | static void |
U. Artie Eoff | 86c68b3 | 2014-01-15 13:02:28 -0800 | [diff] [blame] | 410 | destroy_seat_info(void *data) |
| 411 | { |
| 412 | struct seat_info *seat = data; |
| 413 | |
| 414 | wl_seat_destroy(seat->seat); |
| 415 | |
| 416 | if (seat->name != NULL) |
| 417 | free(seat->name); |
| 418 | } |
| 419 | |
| 420 | static void |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 421 | add_seat_info(struct weston_info *info, uint32_t id, uint32_t version) |
| 422 | { |
U. Artie Eoff | 86c68b3 | 2014-01-15 13:02:28 -0800 | [diff] [blame] | 423 | struct seat_info *seat = xzalloc(sizeof *seat); |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 424 | |
Jonny Lamb | 0695908 | 2014-08-12 14:58:27 +0200 | [diff] [blame] | 425 | /* required to set roundtrip_needed to true in capabilities |
| 426 | * handler */ |
| 427 | seat->info = info; |
| 428 | |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 429 | init_global_info(info, &seat->global, id, "wl_seat", version); |
| 430 | seat->global.print = print_seat_info; |
U. Artie Eoff | 86c68b3 | 2014-01-15 13:02:28 -0800 | [diff] [blame] | 431 | seat->global.destroy = destroy_seat_info; |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 432 | |
Kristian Høgsberg | fa80e11 | 2012-10-10 21:34:26 -0400 | [diff] [blame] | 433 | seat->seat = wl_registry_bind(info->registry, |
Jonny Lamb | 0695908 | 2014-08-12 14:58:27 +0200 | [diff] [blame] | 434 | id, &wl_seat_interface, MIN(version, 4)); |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 435 | wl_seat_add_listener(seat->seat, &seat_listener, seat); |
Philipp Brüschweiler | bb0d4b9 | 2012-08-15 21:57:23 +0200 | [diff] [blame] | 436 | |
Jonny Lamb | 0695908 | 2014-08-12 14:58:27 +0200 | [diff] [blame] | 437 | seat->repeat_rate = seat->repeat_delay = -1; |
| 438 | |
Philipp Brüschweiler | bb0d4b9 | 2012-08-15 21:57:23 +0200 | [diff] [blame] | 439 | info->roundtrip_needed = true; |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 440 | } |
| 441 | |
| 442 | static void |
| 443 | shm_handle_format(void *data, struct wl_shm *wl_shm, uint32_t format) |
| 444 | { |
| 445 | struct shm_info *shm = data; |
U. Artie Eoff | 86c68b3 | 2014-01-15 13:02:28 -0800 | [diff] [blame] | 446 | struct shm_format *shm_format = xzalloc(sizeof *shm_format); |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 447 | |
| 448 | wl_list_insert(&shm->formats, &shm_format->link); |
| 449 | shm_format->format = format; |
| 450 | } |
| 451 | |
| 452 | static const struct wl_shm_listener shm_listener = { |
| 453 | shm_handle_format, |
| 454 | }; |
| 455 | |
| 456 | static void |
U. Artie Eoff | 86c68b3 | 2014-01-15 13:02:28 -0800 | [diff] [blame] | 457 | destroy_shm_info(void *data) |
| 458 | { |
| 459 | struct shm_info *shm = data; |
| 460 | struct shm_format *format, *tmp; |
| 461 | |
| 462 | wl_list_for_each_safe(format, tmp, &shm->formats, link) { |
| 463 | wl_list_remove(&format->link); |
| 464 | free(format); |
| 465 | } |
| 466 | |
| 467 | wl_shm_destroy(shm->shm); |
| 468 | } |
| 469 | |
| 470 | static void |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 471 | add_shm_info(struct weston_info *info, uint32_t id, uint32_t version) |
| 472 | { |
U. Artie Eoff | 86c68b3 | 2014-01-15 13:02:28 -0800 | [diff] [blame] | 473 | struct shm_info *shm = xzalloc(sizeof *shm); |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 474 | |
| 475 | init_global_info(info, &shm->global, id, "wl_shm", version); |
| 476 | shm->global.print = print_shm_info; |
U. Artie Eoff | 86c68b3 | 2014-01-15 13:02:28 -0800 | [diff] [blame] | 477 | shm->global.destroy = destroy_shm_info; |
| 478 | |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 479 | wl_list_init(&shm->formats); |
| 480 | |
Kristian Høgsberg | fa80e11 | 2012-10-10 21:34:26 -0400 | [diff] [blame] | 481 | shm->shm = wl_registry_bind(info->registry, |
| 482 | id, &wl_shm_interface, 1); |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 483 | wl_shm_add_listener(shm->shm, &shm_listener, shm); |
Philipp Brüschweiler | bb0d4b9 | 2012-08-15 21:57:23 +0200 | [diff] [blame] | 484 | |
| 485 | info->roundtrip_needed = true; |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 486 | } |
| 487 | |
| 488 | static void |
| 489 | output_handle_geometry(void *data, struct wl_output *wl_output, |
| 490 | int32_t x, int32_t y, |
| 491 | int32_t physical_width, int32_t physical_height, |
| 492 | int32_t subpixel, |
| 493 | const char *make, const char *model, |
| 494 | int32_t output_transform) |
| 495 | { |
| 496 | struct output_info *output = data; |
| 497 | |
| 498 | output->geometry.x = x; |
| 499 | output->geometry.y = y; |
| 500 | output->geometry.physical_width = physical_width; |
| 501 | output->geometry.physical_height = physical_height; |
| 502 | output->geometry.subpixel = subpixel; |
U. Artie Eoff | 86c68b3 | 2014-01-15 13:02:28 -0800 | [diff] [blame] | 503 | output->geometry.make = xstrdup(make); |
| 504 | output->geometry.model = xstrdup(model); |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 505 | output->geometry.output_transform = output_transform; |
| 506 | } |
| 507 | |
| 508 | static void |
| 509 | output_handle_mode(void *data, struct wl_output *wl_output, |
| 510 | uint32_t flags, int32_t width, int32_t height, |
| 511 | int32_t refresh) |
| 512 | { |
| 513 | struct output_info *output = data; |
Kristian Høgsberg | 06b16c2 | 2013-08-15 14:20:53 -0700 | [diff] [blame] | 514 | struct output_mode *mode = xmalloc(sizeof *mode); |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 515 | |
Philipp Brüschweiler | 97cb62a | 2012-08-15 21:57:24 +0200 | [diff] [blame] | 516 | mode->flags = flags; |
| 517 | mode->width = width; |
| 518 | mode->height = height; |
| 519 | mode->refresh = refresh; |
| 520 | |
| 521 | wl_list_insert(output->modes.prev, &mode->link); |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 522 | } |
| 523 | |
| 524 | static const struct wl_output_listener output_listener = { |
| 525 | output_handle_geometry, |
| 526 | output_handle_mode, |
| 527 | }; |
| 528 | |
| 529 | static void |
U. Artie Eoff | 86c68b3 | 2014-01-15 13:02:28 -0800 | [diff] [blame] | 530 | destroy_output_info(void *data) |
| 531 | { |
| 532 | struct output_info *output = data; |
| 533 | struct output_mode *mode, *tmp; |
| 534 | |
| 535 | wl_output_destroy(output->output); |
| 536 | |
| 537 | if (output->geometry.make != NULL) |
| 538 | free(output->geometry.make); |
| 539 | if (output->geometry.model != NULL) |
| 540 | free(output->geometry.model); |
| 541 | |
| 542 | wl_list_for_each_safe(mode, tmp, &output->modes, link) { |
| 543 | wl_list_remove(&mode->link); |
| 544 | free(mode); |
| 545 | } |
| 546 | } |
| 547 | |
| 548 | static void |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 549 | add_output_info(struct weston_info *info, uint32_t id, uint32_t version) |
| 550 | { |
U. Artie Eoff | 86c68b3 | 2014-01-15 13:02:28 -0800 | [diff] [blame] | 551 | struct output_info *output = xzalloc(sizeof *output); |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 552 | |
| 553 | init_global_info(info, &output->global, id, "wl_output", version); |
| 554 | output->global.print = print_output_info; |
U. Artie Eoff | 86c68b3 | 2014-01-15 13:02:28 -0800 | [diff] [blame] | 555 | output->global.destroy = destroy_output_info; |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 556 | |
Philipp Brüschweiler | 97cb62a | 2012-08-15 21:57:24 +0200 | [diff] [blame] | 557 | wl_list_init(&output->modes); |
| 558 | |
Kristian Høgsberg | fa80e11 | 2012-10-10 21:34:26 -0400 | [diff] [blame] | 559 | output->output = wl_registry_bind(info->registry, id, |
| 560 | &wl_output_interface, 1); |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 561 | wl_output_add_listener(output->output, &output_listener, |
| 562 | output); |
Philipp Brüschweiler | bb0d4b9 | 2012-08-15 21:57:23 +0200 | [diff] [blame] | 563 | |
| 564 | info->roundtrip_needed = true; |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 565 | } |
| 566 | |
| 567 | static void |
Pekka Paalanen | 93a6afd | 2014-09-23 22:08:44 -0400 | [diff] [blame^] | 568 | destroy_presentation_info(void *info) |
| 569 | { |
| 570 | struct presentation_info *prinfo = info; |
| 571 | |
| 572 | presentation_destroy(prinfo->presentation); |
| 573 | } |
| 574 | |
| 575 | static const char * |
| 576 | clock_name(clockid_t clk_id) |
| 577 | { |
| 578 | static const char *names[] = { |
| 579 | [CLOCK_REALTIME] = "CLOCK_REALTIME", |
| 580 | [CLOCK_MONOTONIC] = "CLOCK_MONOTONIC", |
| 581 | [CLOCK_MONOTONIC_RAW] = "CLOCK_MONOTONIC_RAW", |
| 582 | [CLOCK_REALTIME_COARSE] = "CLOCK_REALTIME_COARSE", |
| 583 | [CLOCK_MONOTONIC_COARSE] = "CLOCK_MONOTONIC_COARSE", |
| 584 | [CLOCK_BOOTTIME] = "CLOCK_BOOTTIME", |
| 585 | }; |
| 586 | |
| 587 | if (clk_id < 0 || (unsigned)clk_id >= ARRAY_LENGTH(names)) |
| 588 | return "unknown"; |
| 589 | |
| 590 | return names[clk_id]; |
| 591 | } |
| 592 | |
| 593 | static void |
| 594 | print_presentation_info(void *info) |
| 595 | { |
| 596 | struct presentation_info *prinfo = info; |
| 597 | |
| 598 | print_global_info(info); |
| 599 | |
| 600 | printf("\tpresentation clock id: %d (%s)\n", |
| 601 | prinfo->clk_id, clock_name(prinfo->clk_id)); |
| 602 | } |
| 603 | |
| 604 | static void |
| 605 | presentation_handle_clock_id(void *data, struct presentation *presentation, |
| 606 | uint32_t clk_id) |
| 607 | { |
| 608 | struct presentation_info *prinfo = data; |
| 609 | |
| 610 | prinfo->clk_id = clk_id; |
| 611 | } |
| 612 | |
| 613 | static const struct presentation_listener presentation_listener = { |
| 614 | presentation_handle_clock_id |
| 615 | }; |
| 616 | |
| 617 | static void |
| 618 | add_presentation_info(struct weston_info *info, uint32_t id, uint32_t version) |
| 619 | { |
| 620 | struct presentation_info *prinfo = xzalloc(sizeof *prinfo); |
| 621 | |
| 622 | init_global_info(info, &prinfo->global, id, "presentation", version); |
| 623 | prinfo->global.print = print_presentation_info; |
| 624 | prinfo->global.destroy = destroy_presentation_info; |
| 625 | |
| 626 | prinfo->clk_id = -1; |
| 627 | prinfo->presentation = wl_registry_bind(info->registry, id, |
| 628 | &presentation_interface, 1); |
| 629 | presentation_add_listener(prinfo->presentation, &presentation_listener, |
| 630 | prinfo); |
| 631 | |
| 632 | info->roundtrip_needed = true; |
| 633 | } |
| 634 | |
| 635 | static void |
U. Artie Eoff | 86c68b3 | 2014-01-15 13:02:28 -0800 | [diff] [blame] | 636 | destroy_global_info(void *data) |
| 637 | { |
| 638 | } |
| 639 | |
| 640 | static void |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 641 | add_global_info(struct weston_info *info, uint32_t id, |
| 642 | const char *interface, uint32_t version) |
| 643 | { |
U. Artie Eoff | 86c68b3 | 2014-01-15 13:02:28 -0800 | [diff] [blame] | 644 | struct global_info *global = xzalloc(sizeof *global); |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 645 | |
| 646 | init_global_info(info, global, id, interface, version); |
| 647 | global->print = print_global_info; |
U. Artie Eoff | 86c68b3 | 2014-01-15 13:02:28 -0800 | [diff] [blame] | 648 | global->destroy = destroy_global_info; |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 649 | } |
| 650 | |
| 651 | static void |
Kristian Høgsberg | fa80e11 | 2012-10-10 21:34:26 -0400 | [diff] [blame] | 652 | global_handler(void *data, struct wl_registry *registry, uint32_t id, |
| 653 | const char *interface, uint32_t version) |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 654 | { |
| 655 | struct weston_info *info = data; |
| 656 | |
| 657 | if (!strcmp(interface, "wl_seat")) |
| 658 | add_seat_info(info, id, version); |
| 659 | else if (!strcmp(interface, "wl_shm")) |
| 660 | add_shm_info(info, id, version); |
| 661 | else if (!strcmp(interface, "wl_output")) |
| 662 | add_output_info(info, id, version); |
Pekka Paalanen | 93a6afd | 2014-09-23 22:08:44 -0400 | [diff] [blame^] | 663 | else if (!strcmp(interface, "presentation")) |
| 664 | add_presentation_info(info, id, version); |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 665 | else |
| 666 | add_global_info(info, id, interface, version); |
| 667 | } |
| 668 | |
Pekka Paalanen | 0eab05d | 2013-01-22 14:53:55 +0200 | [diff] [blame] | 669 | static void |
| 670 | global_remove_handler(void *data, struct wl_registry *registry, uint32_t name) |
| 671 | { |
| 672 | } |
| 673 | |
Kristian Høgsberg | fa80e11 | 2012-10-10 21:34:26 -0400 | [diff] [blame] | 674 | static const struct wl_registry_listener registry_listener = { |
Pekka Paalanen | 0eab05d | 2013-01-22 14:53:55 +0200 | [diff] [blame] | 675 | global_handler, |
| 676 | global_remove_handler |
Kristian Høgsberg | fa80e11 | 2012-10-10 21:34:26 -0400 | [diff] [blame] | 677 | }; |
| 678 | |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 679 | static void |
| 680 | print_infos(struct wl_list *infos) |
| 681 | { |
| 682 | struct global_info *info; |
| 683 | |
| 684 | wl_list_for_each(info, infos, link) |
| 685 | info->print(info); |
| 686 | } |
| 687 | |
U. Artie Eoff | 86c68b3 | 2014-01-15 13:02:28 -0800 | [diff] [blame] | 688 | static void |
| 689 | destroy_info(void *data) |
| 690 | { |
| 691 | struct global_info *global = data; |
| 692 | |
| 693 | global->destroy(data); |
| 694 | wl_list_remove(&global->link); |
| 695 | free(global->interface); |
| 696 | free(data); |
| 697 | } |
| 698 | |
| 699 | static void |
| 700 | destroy_infos(struct wl_list *infos) |
| 701 | { |
| 702 | struct global_info *info, *tmp; |
| 703 | wl_list_for_each_safe(info, tmp, infos, link) |
| 704 | destroy_info(info); |
| 705 | } |
| 706 | |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 707 | int |
| 708 | main(int argc, char **argv) |
| 709 | { |
| 710 | struct weston_info info; |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 711 | |
| 712 | info.display = wl_display_connect(NULL); |
| 713 | if (!info.display) { |
| 714 | fprintf(stderr, "failed to create display: %m\n"); |
| 715 | return -1; |
| 716 | } |
| 717 | |
| 718 | wl_list_init(&info.infos); |
| 719 | |
Kristian Høgsberg | fa80e11 | 2012-10-10 21:34:26 -0400 | [diff] [blame] | 720 | info.registry = wl_display_get_registry(info.display); |
| 721 | wl_registry_add_listener(info.registry, ®istry_listener, &info); |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 722 | |
Philipp Brüschweiler | bb0d4b9 | 2012-08-15 21:57:23 +0200 | [diff] [blame] | 723 | do { |
| 724 | info.roundtrip_needed = false; |
| 725 | wl_display_roundtrip(info.display); |
| 726 | } while (info.roundtrip_needed); |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 727 | |
| 728 | print_infos(&info.infos); |
U. Artie Eoff | 86c68b3 | 2014-01-15 13:02:28 -0800 | [diff] [blame] | 729 | destroy_infos(&info.infos); |
| 730 | |
| 731 | wl_registry_destroy(info.registry); |
| 732 | wl_display_disconnect(info.display); |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 733 | |
| 734 | return 0; |
| 735 | } |