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