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