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 | 35b2eaa | 2015-06-15 15:37:08 -0700 | [diff] [blame] | 35 | #include "shared/helpers.h" |
Jon Cruz | 4678bab | 2015-06-15 15:37:07 -0700 | [diff] [blame] | 36 | #include "shared/os-compatibility.h" |
Pekka Paalanen | b00c79b | 2016-02-18 16:53:27 +0200 | [diff] [blame^] | 37 | #include "presentation-time-client-protocol.h" |
Pekka Paalanen | 93a6afd | 2014-09-23 22:08:44 -0400 | [diff] [blame] | 38 | |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 39 | typedef void (*print_info_t)(void *info); |
U. Artie Eoff | 86c68b3 | 2014-01-15 13:02:28 -0800 | [diff] [blame] | 40 | typedef void (*destroy_info_t)(void *info); |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 41 | |
| 42 | struct global_info { |
| 43 | struct wl_list link; |
| 44 | |
| 45 | uint32_t id; |
| 46 | uint32_t version; |
| 47 | char *interface; |
| 48 | |
| 49 | print_info_t print; |
U. Artie Eoff | 86c68b3 | 2014-01-15 13:02:28 -0800 | [diff] [blame] | 50 | destroy_info_t destroy; |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 51 | }; |
| 52 | |
Philipp Brüschweiler | 97cb62a | 2012-08-15 21:57:24 +0200 | [diff] [blame] | 53 | struct output_mode { |
| 54 | struct wl_list link; |
| 55 | |
| 56 | uint32_t flags; |
| 57 | int32_t width, height; |
| 58 | int32_t refresh; |
| 59 | }; |
| 60 | |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 61 | struct output_info { |
| 62 | struct global_info global; |
| 63 | |
| 64 | struct wl_output *output; |
| 65 | |
Jonny Lamb | ba9dca0 | 2015-12-17 12:31:56 +0000 | [diff] [blame] | 66 | int32_t version; |
| 67 | |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 68 | struct { |
| 69 | int32_t x, y; |
Jonny Lamb | ba9dca0 | 2015-12-17 12:31:56 +0000 | [diff] [blame] | 70 | int32_t scale; |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 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; |
Pekka Paalanen | b00c79b | 2016-02-18 16:53:27 +0200 | [diff] [blame^] | 108 | struct wp_presentation *presentation; |
Pekka Paalanen | 93a6afd | 2014-09-23 22:08:44 -0400 | [diff] [blame] | 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 | |
Jonny Lamb | ba9dca0 | 2015-12-17 12:31:56 +0000 | [diff] [blame] | 239 | printf("\tx: %d, y: %d,", |
Philipp Brüschweiler | 97cb62a | 2012-08-15 21:57:24 +0200 | [diff] [blame] | 240 | output->geometry.x, output->geometry.y); |
Jonny Lamb | ba9dca0 | 2015-12-17 12:31:56 +0000 | [diff] [blame] | 241 | if (output->version >= 2) |
| 242 | printf(" scale: %d,", output->geometry.scale); |
| 243 | printf("\n"); |
| 244 | |
Philipp Brüschweiler | 97cb62a | 2012-08-15 21:57:24 +0200 | [diff] [blame] | 245 | printf("\tphysical_width: %d mm, physical_height: %d mm,\n", |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 246 | output->geometry.physical_width, |
Philipp Brüschweiler | 97cb62a | 2012-08-15 21:57:24 +0200 | [diff] [blame] | 247 | output->geometry.physical_height); |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 248 | printf("\tmake: '%s', model: '%s',\n", |
| 249 | output->geometry.make, output->geometry.model); |
U. Artie Eoff | cb0e357 | 2014-04-18 09:30:07 -0700 | [diff] [blame] | 250 | printf("\tsubpixel_orientation: %s, output_transform: %s,\n", |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 251 | subpixel_orientation, transform); |
Philipp Brüschweiler | 97cb62a | 2012-08-15 21:57:24 +0200 | [diff] [blame] | 252 | |
| 253 | wl_list_for_each(mode, &output->modes, link) { |
| 254 | printf("\tmode:\n"); |
| 255 | |
| 256 | printf("\t\twidth: %d px, height: %d px, refresh: %.f Hz,\n", |
| 257 | mode->width, mode->height, |
| 258 | (float) mode->refresh / 1000); |
| 259 | |
| 260 | printf("\t\tflags:"); |
| 261 | if (mode->flags & WL_OUTPUT_MODE_CURRENT) |
| 262 | printf(" current"); |
| 263 | if (mode->flags & WL_OUTPUT_MODE_PREFERRED) |
| 264 | printf(" preferred"); |
| 265 | printf("\n"); |
| 266 | } |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 267 | } |
| 268 | |
| 269 | static void |
| 270 | print_shm_info(void *data) |
| 271 | { |
| 272 | struct shm_info *shm = data; |
| 273 | struct shm_format *format; |
| 274 | |
| 275 | print_global_info(data); |
| 276 | |
| 277 | printf("\tformats:"); |
| 278 | |
| 279 | wl_list_for_each(format, &shm->formats, link) |
Kristian Høgsberg | 8b66ebd | 2013-11-20 13:54:00 -0800 | [diff] [blame] | 280 | switch (format->format) { |
| 281 | case WL_SHM_FORMAT_ARGB8888: |
| 282 | printf(" ARGB8888"); |
| 283 | break; |
| 284 | case WL_SHM_FORMAT_XRGB8888: |
| 285 | printf(" XRGB8888"); |
| 286 | break; |
| 287 | case WL_SHM_FORMAT_RGB565: |
| 288 | printf(" RGB565"); |
| 289 | break; |
| 290 | default: |
| 291 | printf(" unknown(%08x)", format->format); |
| 292 | break; |
| 293 | } |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 294 | |
| 295 | printf("\n"); |
| 296 | } |
| 297 | |
| 298 | static void |
| 299 | print_seat_info(void *data) |
| 300 | { |
| 301 | struct seat_info *seat = data; |
| 302 | |
| 303 | print_global_info(data); |
| 304 | |
Rob Bradford | 14a7601 | 2013-05-31 18:09:52 +0100 | [diff] [blame] | 305 | printf("\tname: %s\n", seat->name); |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 306 | printf("\tcapabilities:"); |
| 307 | |
| 308 | if (seat->capabilities & WL_SEAT_CAPABILITY_POINTER) |
| 309 | printf(" pointer"); |
| 310 | if (seat->capabilities & WL_SEAT_CAPABILITY_KEYBOARD) |
| 311 | printf(" keyboard"); |
| 312 | if (seat->capabilities & WL_SEAT_CAPABILITY_TOUCH) |
| 313 | printf(" touch"); |
| 314 | |
| 315 | printf("\n"); |
Jonny Lamb | 0695908 | 2014-08-12 14:58:27 +0200 | [diff] [blame] | 316 | |
| 317 | if (seat->repeat_rate > 0) |
| 318 | printf("\tkeyboard repeat rate: %d\n", seat->repeat_rate); |
| 319 | if (seat->repeat_delay > 0) |
| 320 | printf("\tkeyboard repeat delay: %d\n", seat->repeat_delay); |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 321 | } |
| 322 | |
| 323 | static void |
Jonny Lamb | 0695908 | 2014-08-12 14:58:27 +0200 | [diff] [blame] | 324 | keyboard_handle_keymap(void *data, struct wl_keyboard *keyboard, |
| 325 | uint32_t format, int fd, uint32_t size) |
| 326 | { |
| 327 | } |
| 328 | |
| 329 | static void |
| 330 | keyboard_handle_enter(void *data, struct wl_keyboard *keyboard, |
| 331 | uint32_t serial, struct wl_surface *surface, |
| 332 | struct wl_array *keys) |
| 333 | { |
| 334 | } |
| 335 | |
| 336 | static void |
| 337 | keyboard_handle_leave(void *data, struct wl_keyboard *keyboard, |
| 338 | uint32_t serial, struct wl_surface *surface) |
| 339 | { |
| 340 | } |
| 341 | |
| 342 | static void |
| 343 | keyboard_handle_key(void *data, struct wl_keyboard *keyboard, |
| 344 | uint32_t serial, uint32_t time, uint32_t key, |
| 345 | uint32_t state) |
| 346 | { |
| 347 | } |
| 348 | |
| 349 | static void |
| 350 | keyboard_handle_modifiers(void *data, struct wl_keyboard *keyboard, |
| 351 | uint32_t serial, uint32_t mods_depressed, |
| 352 | uint32_t mods_latched, uint32_t mods_locked, |
| 353 | uint32_t group) |
| 354 | { |
| 355 | } |
| 356 | |
| 357 | static void |
| 358 | keyboard_handle_repeat_info(void *data, struct wl_keyboard *keyboard, |
| 359 | int32_t rate, int32_t delay) |
| 360 | { |
| 361 | struct seat_info *seat = data; |
| 362 | |
| 363 | seat->repeat_rate = rate; |
| 364 | seat->repeat_delay = delay; |
| 365 | } |
| 366 | |
| 367 | static const struct wl_keyboard_listener keyboard_listener = { |
| 368 | keyboard_handle_keymap, |
| 369 | keyboard_handle_enter, |
| 370 | keyboard_handle_leave, |
| 371 | keyboard_handle_key, |
| 372 | keyboard_handle_modifiers, |
| 373 | keyboard_handle_repeat_info, |
| 374 | }; |
| 375 | |
| 376 | static void |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 377 | seat_handle_capabilities(void *data, struct wl_seat *wl_seat, |
| 378 | enum wl_seat_capability caps) |
| 379 | { |
| 380 | struct seat_info *seat = data; |
Jonny Lamb | 0695908 | 2014-08-12 14:58:27 +0200 | [diff] [blame] | 381 | |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 382 | seat->capabilities = caps; |
Jonny Lamb | 0695908 | 2014-08-12 14:58:27 +0200 | [diff] [blame] | 383 | |
| 384 | /* we want listen for repeat_info from wl_keyboard, but only |
| 385 | * do so if the seat info is >= 4 and if we actually have a |
| 386 | * keyboard */ |
| 387 | if (seat->global.version < 4) |
| 388 | return; |
| 389 | |
| 390 | if (caps & WL_SEAT_CAPABILITY_KEYBOARD) { |
| 391 | struct wl_keyboard *keyboard; |
| 392 | |
| 393 | keyboard = wl_seat_get_keyboard(seat->seat); |
| 394 | wl_keyboard_add_listener(keyboard, &keyboard_listener, |
| 395 | seat); |
| 396 | |
| 397 | seat->info->roundtrip_needed = true; |
| 398 | } |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 399 | } |
| 400 | |
Rob Bradford | 14a7601 | 2013-05-31 18:09:52 +0100 | [diff] [blame] | 401 | static void |
| 402 | seat_handle_name(void *data, struct wl_seat *wl_seat, |
| 403 | const char *name) |
| 404 | { |
| 405 | struct seat_info *seat = data; |
U. Artie Eoff | 86c68b3 | 2014-01-15 13:02:28 -0800 | [diff] [blame] | 406 | seat->name = xstrdup(name); |
Rob Bradford | 14a7601 | 2013-05-31 18:09:52 +0100 | [diff] [blame] | 407 | } |
| 408 | |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 409 | static const struct wl_seat_listener seat_listener = { |
| 410 | seat_handle_capabilities, |
Rob Bradford | 14a7601 | 2013-05-31 18:09:52 +0100 | [diff] [blame] | 411 | seat_handle_name, |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 412 | }; |
| 413 | |
| 414 | static void |
U. Artie Eoff | 86c68b3 | 2014-01-15 13:02:28 -0800 | [diff] [blame] | 415 | destroy_seat_info(void *data) |
| 416 | { |
| 417 | struct seat_info *seat = data; |
| 418 | |
| 419 | wl_seat_destroy(seat->seat); |
| 420 | |
| 421 | if (seat->name != NULL) |
| 422 | free(seat->name); |
| 423 | } |
| 424 | |
| 425 | static void |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 426 | add_seat_info(struct weston_info *info, uint32_t id, uint32_t version) |
| 427 | { |
U. Artie Eoff | 86c68b3 | 2014-01-15 13:02:28 -0800 | [diff] [blame] | 428 | struct seat_info *seat = xzalloc(sizeof *seat); |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 429 | |
Jonny Lamb | 0695908 | 2014-08-12 14:58:27 +0200 | [diff] [blame] | 430 | /* required to set roundtrip_needed to true in capabilities |
| 431 | * handler */ |
| 432 | seat->info = info; |
| 433 | |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 434 | init_global_info(info, &seat->global, id, "wl_seat", version); |
| 435 | seat->global.print = print_seat_info; |
U. Artie Eoff | 86c68b3 | 2014-01-15 13:02:28 -0800 | [diff] [blame] | 436 | seat->global.destroy = destroy_seat_info; |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 437 | |
Kristian Høgsberg | fa80e11 | 2012-10-10 21:34:26 -0400 | [diff] [blame] | 438 | seat->seat = wl_registry_bind(info->registry, |
Jonny Lamb | 0695908 | 2014-08-12 14:58:27 +0200 | [diff] [blame] | 439 | id, &wl_seat_interface, MIN(version, 4)); |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 440 | wl_seat_add_listener(seat->seat, &seat_listener, seat); |
Philipp Brüschweiler | bb0d4b9 | 2012-08-15 21:57:23 +0200 | [diff] [blame] | 441 | |
Jonny Lamb | 0695908 | 2014-08-12 14:58:27 +0200 | [diff] [blame] | 442 | seat->repeat_rate = seat->repeat_delay = -1; |
| 443 | |
Philipp Brüschweiler | bb0d4b9 | 2012-08-15 21:57:23 +0200 | [diff] [blame] | 444 | info->roundtrip_needed = true; |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 445 | } |
| 446 | |
| 447 | static void |
| 448 | shm_handle_format(void *data, struct wl_shm *wl_shm, uint32_t format) |
| 449 | { |
| 450 | struct shm_info *shm = data; |
U. Artie Eoff | 86c68b3 | 2014-01-15 13:02:28 -0800 | [diff] [blame] | 451 | struct shm_format *shm_format = xzalloc(sizeof *shm_format); |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 452 | |
| 453 | wl_list_insert(&shm->formats, &shm_format->link); |
| 454 | shm_format->format = format; |
| 455 | } |
| 456 | |
| 457 | static const struct wl_shm_listener shm_listener = { |
| 458 | shm_handle_format, |
| 459 | }; |
| 460 | |
| 461 | static void |
U. Artie Eoff | 86c68b3 | 2014-01-15 13:02:28 -0800 | [diff] [blame] | 462 | destroy_shm_info(void *data) |
| 463 | { |
| 464 | struct shm_info *shm = data; |
| 465 | struct shm_format *format, *tmp; |
| 466 | |
| 467 | wl_list_for_each_safe(format, tmp, &shm->formats, link) { |
| 468 | wl_list_remove(&format->link); |
| 469 | free(format); |
| 470 | } |
| 471 | |
| 472 | wl_shm_destroy(shm->shm); |
| 473 | } |
| 474 | |
| 475 | static void |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 476 | add_shm_info(struct weston_info *info, uint32_t id, uint32_t version) |
| 477 | { |
U. Artie Eoff | 86c68b3 | 2014-01-15 13:02:28 -0800 | [diff] [blame] | 478 | struct shm_info *shm = xzalloc(sizeof *shm); |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 479 | |
| 480 | init_global_info(info, &shm->global, id, "wl_shm", version); |
| 481 | shm->global.print = print_shm_info; |
U. Artie Eoff | 86c68b3 | 2014-01-15 13:02:28 -0800 | [diff] [blame] | 482 | shm->global.destroy = destroy_shm_info; |
| 483 | |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 484 | wl_list_init(&shm->formats); |
| 485 | |
Kristian Høgsberg | fa80e11 | 2012-10-10 21:34:26 -0400 | [diff] [blame] | 486 | shm->shm = wl_registry_bind(info->registry, |
| 487 | id, &wl_shm_interface, 1); |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 488 | wl_shm_add_listener(shm->shm, &shm_listener, shm); |
Philipp Brüschweiler | bb0d4b9 | 2012-08-15 21:57:23 +0200 | [diff] [blame] | 489 | |
| 490 | info->roundtrip_needed = true; |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 491 | } |
| 492 | |
| 493 | static void |
| 494 | output_handle_geometry(void *data, struct wl_output *wl_output, |
| 495 | int32_t x, int32_t y, |
| 496 | int32_t physical_width, int32_t physical_height, |
| 497 | int32_t subpixel, |
| 498 | const char *make, const char *model, |
| 499 | int32_t output_transform) |
| 500 | { |
| 501 | struct output_info *output = data; |
| 502 | |
| 503 | output->geometry.x = x; |
| 504 | output->geometry.y = y; |
| 505 | output->geometry.physical_width = physical_width; |
| 506 | output->geometry.physical_height = physical_height; |
| 507 | output->geometry.subpixel = subpixel; |
U. Artie Eoff | 86c68b3 | 2014-01-15 13:02:28 -0800 | [diff] [blame] | 508 | output->geometry.make = xstrdup(make); |
| 509 | output->geometry.model = xstrdup(model); |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 510 | output->geometry.output_transform = output_transform; |
| 511 | } |
| 512 | |
| 513 | static void |
| 514 | output_handle_mode(void *data, struct wl_output *wl_output, |
| 515 | uint32_t flags, int32_t width, int32_t height, |
| 516 | int32_t refresh) |
| 517 | { |
| 518 | struct output_info *output = data; |
Kristian Høgsberg | 06b16c2 | 2013-08-15 14:20:53 -0700 | [diff] [blame] | 519 | struct output_mode *mode = xmalloc(sizeof *mode); |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 520 | |
Philipp Brüschweiler | 97cb62a | 2012-08-15 21:57:24 +0200 | [diff] [blame] | 521 | mode->flags = flags; |
| 522 | mode->width = width; |
| 523 | mode->height = height; |
| 524 | mode->refresh = refresh; |
| 525 | |
| 526 | wl_list_insert(output->modes.prev, &mode->link); |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 527 | } |
| 528 | |
Jonny Lamb | ba9dca0 | 2015-12-17 12:31:56 +0000 | [diff] [blame] | 529 | static void |
| 530 | output_handle_done(void *data, struct wl_output *wl_output) |
| 531 | { |
| 532 | /* don't bother waiting for this; there's no good reason a |
| 533 | * compositor will wait more than one roundtrip before sending |
| 534 | * these initial events. */ |
| 535 | } |
| 536 | |
| 537 | static void |
| 538 | output_handle_scale(void *data, struct wl_output *wl_output, |
| 539 | int32_t scale) |
| 540 | { |
| 541 | struct output_info *output = data; |
| 542 | |
| 543 | output->geometry.scale = scale; |
| 544 | } |
| 545 | |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 546 | static const struct wl_output_listener output_listener = { |
| 547 | output_handle_geometry, |
| 548 | output_handle_mode, |
Jonny Lamb | ba9dca0 | 2015-12-17 12:31:56 +0000 | [diff] [blame] | 549 | output_handle_done, |
| 550 | output_handle_scale, |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 551 | }; |
| 552 | |
| 553 | static void |
U. Artie Eoff | 86c68b3 | 2014-01-15 13:02:28 -0800 | [diff] [blame] | 554 | destroy_output_info(void *data) |
| 555 | { |
| 556 | struct output_info *output = data; |
| 557 | struct output_mode *mode, *tmp; |
| 558 | |
| 559 | wl_output_destroy(output->output); |
| 560 | |
| 561 | if (output->geometry.make != NULL) |
| 562 | free(output->geometry.make); |
| 563 | if (output->geometry.model != NULL) |
| 564 | free(output->geometry.model); |
| 565 | |
| 566 | wl_list_for_each_safe(mode, tmp, &output->modes, link) { |
| 567 | wl_list_remove(&mode->link); |
| 568 | free(mode); |
| 569 | } |
| 570 | } |
| 571 | |
| 572 | static void |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 573 | add_output_info(struct weston_info *info, uint32_t id, uint32_t version) |
| 574 | { |
U. Artie Eoff | 86c68b3 | 2014-01-15 13:02:28 -0800 | [diff] [blame] | 575 | struct output_info *output = xzalloc(sizeof *output); |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 576 | |
| 577 | init_global_info(info, &output->global, id, "wl_output", version); |
| 578 | output->global.print = print_output_info; |
U. Artie Eoff | 86c68b3 | 2014-01-15 13:02:28 -0800 | [diff] [blame] | 579 | output->global.destroy = destroy_output_info; |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 580 | |
Jonny Lamb | ba9dca0 | 2015-12-17 12:31:56 +0000 | [diff] [blame] | 581 | output->version = MIN(version, 2); |
| 582 | output->geometry.scale = 1; |
Philipp Brüschweiler | 97cb62a | 2012-08-15 21:57:24 +0200 | [diff] [blame] | 583 | wl_list_init(&output->modes); |
| 584 | |
Kristian Høgsberg | fa80e11 | 2012-10-10 21:34:26 -0400 | [diff] [blame] | 585 | output->output = wl_registry_bind(info->registry, id, |
Jonny Lamb | ba9dca0 | 2015-12-17 12:31:56 +0000 | [diff] [blame] | 586 | &wl_output_interface, output->version); |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 587 | wl_output_add_listener(output->output, &output_listener, |
| 588 | output); |
Philipp Brüschweiler | bb0d4b9 | 2012-08-15 21:57:23 +0200 | [diff] [blame] | 589 | |
| 590 | info->roundtrip_needed = true; |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 591 | } |
| 592 | |
| 593 | static void |
Pekka Paalanen | 93a6afd | 2014-09-23 22:08:44 -0400 | [diff] [blame] | 594 | destroy_presentation_info(void *info) |
| 595 | { |
| 596 | struct presentation_info *prinfo = info; |
| 597 | |
Pekka Paalanen | b00c79b | 2016-02-18 16:53:27 +0200 | [diff] [blame^] | 598 | wp_presentation_destroy(prinfo->presentation); |
Pekka Paalanen | 93a6afd | 2014-09-23 22:08:44 -0400 | [diff] [blame] | 599 | } |
| 600 | |
| 601 | static const char * |
| 602 | clock_name(clockid_t clk_id) |
| 603 | { |
| 604 | static const char *names[] = { |
| 605 | [CLOCK_REALTIME] = "CLOCK_REALTIME", |
| 606 | [CLOCK_MONOTONIC] = "CLOCK_MONOTONIC", |
| 607 | [CLOCK_MONOTONIC_RAW] = "CLOCK_MONOTONIC_RAW", |
| 608 | [CLOCK_REALTIME_COARSE] = "CLOCK_REALTIME_COARSE", |
| 609 | [CLOCK_MONOTONIC_COARSE] = "CLOCK_MONOTONIC_COARSE", |
Derek Foreman | 32838c9 | 2015-06-29 13:20:34 -0500 | [diff] [blame] | 610 | #ifdef CLOCK_BOOTTIME |
Pekka Paalanen | 93a6afd | 2014-09-23 22:08:44 -0400 | [diff] [blame] | 611 | [CLOCK_BOOTTIME] = "CLOCK_BOOTTIME", |
Derek Foreman | 32838c9 | 2015-06-29 13:20:34 -0500 | [diff] [blame] | 612 | #endif |
Pekka Paalanen | 93a6afd | 2014-09-23 22:08:44 -0400 | [diff] [blame] | 613 | }; |
| 614 | |
| 615 | if (clk_id < 0 || (unsigned)clk_id >= ARRAY_LENGTH(names)) |
| 616 | return "unknown"; |
| 617 | |
| 618 | return names[clk_id]; |
| 619 | } |
| 620 | |
| 621 | static void |
| 622 | print_presentation_info(void *info) |
| 623 | { |
| 624 | struct presentation_info *prinfo = info; |
| 625 | |
| 626 | print_global_info(info); |
| 627 | |
| 628 | printf("\tpresentation clock id: %d (%s)\n", |
| 629 | prinfo->clk_id, clock_name(prinfo->clk_id)); |
| 630 | } |
| 631 | |
| 632 | static void |
Pekka Paalanen | b00c79b | 2016-02-18 16:53:27 +0200 | [diff] [blame^] | 633 | presentation_handle_clock_id(void *data, struct wp_presentation *presentation, |
Pekka Paalanen | 93a6afd | 2014-09-23 22:08:44 -0400 | [diff] [blame] | 634 | uint32_t clk_id) |
| 635 | { |
| 636 | struct presentation_info *prinfo = data; |
| 637 | |
| 638 | prinfo->clk_id = clk_id; |
| 639 | } |
| 640 | |
Pekka Paalanen | b00c79b | 2016-02-18 16:53:27 +0200 | [diff] [blame^] | 641 | static const struct wp_presentation_listener presentation_listener = { |
Pekka Paalanen | 93a6afd | 2014-09-23 22:08:44 -0400 | [diff] [blame] | 642 | presentation_handle_clock_id |
| 643 | }; |
| 644 | |
| 645 | static void |
| 646 | add_presentation_info(struct weston_info *info, uint32_t id, uint32_t version) |
| 647 | { |
| 648 | struct presentation_info *prinfo = xzalloc(sizeof *prinfo); |
| 649 | |
Pekka Paalanen | b00c79b | 2016-02-18 16:53:27 +0200 | [diff] [blame^] | 650 | init_global_info(info, &prinfo->global, id, |
| 651 | wp_presentation_interface.name, version); |
Pekka Paalanen | 93a6afd | 2014-09-23 22:08:44 -0400 | [diff] [blame] | 652 | prinfo->global.print = print_presentation_info; |
| 653 | prinfo->global.destroy = destroy_presentation_info; |
| 654 | |
| 655 | prinfo->clk_id = -1; |
| 656 | prinfo->presentation = wl_registry_bind(info->registry, id, |
Pekka Paalanen | b00c79b | 2016-02-18 16:53:27 +0200 | [diff] [blame^] | 657 | &wp_presentation_interface, 1); |
| 658 | wp_presentation_add_listener(prinfo->presentation, |
| 659 | &presentation_listener, prinfo); |
Pekka Paalanen | 93a6afd | 2014-09-23 22:08:44 -0400 | [diff] [blame] | 660 | |
| 661 | info->roundtrip_needed = true; |
| 662 | } |
| 663 | |
| 664 | static void |
U. Artie Eoff | 86c68b3 | 2014-01-15 13:02:28 -0800 | [diff] [blame] | 665 | destroy_global_info(void *data) |
| 666 | { |
| 667 | } |
| 668 | |
| 669 | static void |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 670 | add_global_info(struct weston_info *info, uint32_t id, |
| 671 | const char *interface, uint32_t version) |
| 672 | { |
U. Artie Eoff | 86c68b3 | 2014-01-15 13:02:28 -0800 | [diff] [blame] | 673 | struct global_info *global = xzalloc(sizeof *global); |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 674 | |
| 675 | init_global_info(info, global, id, interface, version); |
| 676 | global->print = print_global_info; |
U. Artie Eoff | 86c68b3 | 2014-01-15 13:02:28 -0800 | [diff] [blame] | 677 | global->destroy = destroy_global_info; |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 678 | } |
| 679 | |
| 680 | static void |
Kristian Høgsberg | fa80e11 | 2012-10-10 21:34:26 -0400 | [diff] [blame] | 681 | global_handler(void *data, struct wl_registry *registry, uint32_t id, |
| 682 | const char *interface, uint32_t version) |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 683 | { |
| 684 | struct weston_info *info = data; |
| 685 | |
| 686 | if (!strcmp(interface, "wl_seat")) |
| 687 | add_seat_info(info, id, version); |
| 688 | else if (!strcmp(interface, "wl_shm")) |
| 689 | add_shm_info(info, id, version); |
| 690 | else if (!strcmp(interface, "wl_output")) |
| 691 | add_output_info(info, id, version); |
Pekka Paalanen | 93a6afd | 2014-09-23 22:08:44 -0400 | [diff] [blame] | 692 | else if (!strcmp(interface, "presentation")) |
| 693 | add_presentation_info(info, id, version); |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 694 | else |
| 695 | add_global_info(info, id, interface, version); |
| 696 | } |
| 697 | |
Pekka Paalanen | 0eab05d | 2013-01-22 14:53:55 +0200 | [diff] [blame] | 698 | static void |
| 699 | global_remove_handler(void *data, struct wl_registry *registry, uint32_t name) |
| 700 | { |
| 701 | } |
| 702 | |
Kristian Høgsberg | fa80e11 | 2012-10-10 21:34:26 -0400 | [diff] [blame] | 703 | static const struct wl_registry_listener registry_listener = { |
Pekka Paalanen | 0eab05d | 2013-01-22 14:53:55 +0200 | [diff] [blame] | 704 | global_handler, |
| 705 | global_remove_handler |
Kristian Høgsberg | fa80e11 | 2012-10-10 21:34:26 -0400 | [diff] [blame] | 706 | }; |
| 707 | |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 708 | static void |
| 709 | print_infos(struct wl_list *infos) |
| 710 | { |
| 711 | struct global_info *info; |
| 712 | |
| 713 | wl_list_for_each(info, infos, link) |
| 714 | info->print(info); |
| 715 | } |
| 716 | |
U. Artie Eoff | 86c68b3 | 2014-01-15 13:02:28 -0800 | [diff] [blame] | 717 | static void |
| 718 | destroy_info(void *data) |
| 719 | { |
| 720 | struct global_info *global = data; |
| 721 | |
| 722 | global->destroy(data); |
| 723 | wl_list_remove(&global->link); |
| 724 | free(global->interface); |
| 725 | free(data); |
| 726 | } |
| 727 | |
| 728 | static void |
| 729 | destroy_infos(struct wl_list *infos) |
| 730 | { |
| 731 | struct global_info *info, *tmp; |
| 732 | wl_list_for_each_safe(info, tmp, infos, link) |
| 733 | destroy_info(info); |
| 734 | } |
| 735 | |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 736 | int |
| 737 | main(int argc, char **argv) |
| 738 | { |
| 739 | struct weston_info info; |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 740 | |
| 741 | info.display = wl_display_connect(NULL); |
| 742 | if (!info.display) { |
| 743 | fprintf(stderr, "failed to create display: %m\n"); |
| 744 | return -1; |
| 745 | } |
| 746 | |
| 747 | wl_list_init(&info.infos); |
| 748 | |
Kristian Høgsberg | fa80e11 | 2012-10-10 21:34:26 -0400 | [diff] [blame] | 749 | info.registry = wl_display_get_registry(info.display); |
| 750 | wl_registry_add_listener(info.registry, ®istry_listener, &info); |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 751 | |
Philipp Brüschweiler | bb0d4b9 | 2012-08-15 21:57:23 +0200 | [diff] [blame] | 752 | do { |
| 753 | info.roundtrip_needed = false; |
| 754 | wl_display_roundtrip(info.display); |
| 755 | } while (info.roundtrip_needed); |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 756 | |
| 757 | print_infos(&info.infos); |
U. Artie Eoff | 86c68b3 | 2014-01-15 13:02:28 -0800 | [diff] [blame] | 758 | destroy_infos(&info.infos); |
| 759 | |
| 760 | wl_registry_destroy(info.registry); |
| 761 | wl_display_disconnect(info.display); |
Philipp Brüschweiler | 585acb0 | 2012-08-15 17:12:00 +0200 | [diff] [blame] | 762 | |
| 763 | return 0; |
| 764 | } |