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