2 * Copyright © 2012 Philipp Brüschweiler
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:
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
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.
36 #include <wayland-client.h>
38 #include "shared/helpers.h"
39 #include "shared/os-compatibility.h"
40 #include "shared/xalloc.h"
41 #include "shared/zalloc.h"
42 #include "presentation-time-client-protocol.h"
43 #include "linux-dmabuf-unstable-v1-client-protocol.h"
44 #include "tablet-unstable-v2-client-protocol.h"
46 typedef void (*print_info_t)(void *info);
47 typedef void (*destroy_info_t)(void *info);
57 destroy_info_t destroy;
64 int32_t width, height;
69 struct global_info global;
71 struct wl_output *output;
78 int32_t physical_width, physical_height;
79 enum wl_output_subpixel subpixel;
80 enum wl_output_transform output_transform;
95 struct global_info global;
98 struct wl_list formats;
101 struct linux_dmabuf_modifier {
108 struct linux_dmabuf_info {
109 struct global_info global;
110 struct zwp_linux_dmabuf_v1 *dmabuf;
112 struct wl_list modifiers;
116 struct global_info global;
117 struct wl_list global_link;
118 struct wl_seat *seat;
119 struct weston_info *info;
121 uint32_t capabilities;
125 int32_t repeat_delay;
128 struct tablet_v2_path {
133 struct tablet_tool_info {
135 struct zwp_tablet_tool_v2 *tool;
137 uint64_t hardware_serial;
138 uint64_t hardware_id_wacom;
139 enum zwp_tablet_tool_v2_type type;
149 struct tablet_pad_group_info {
151 struct zwp_tablet_pad_group_v2 *group;
160 struct tablet_pad_info {
162 struct zwp_tablet_pad_v2 *pad;
165 struct wl_list paths;
166 struct wl_list groups;
171 struct zwp_tablet_v2 *tablet;
175 struct wl_list paths;
178 struct tablet_seat_info {
181 struct zwp_tablet_seat_v2 *seat;
182 struct seat_info *seat_info;
184 struct wl_list tablets;
185 struct wl_list tools;
189 struct tablet_v2_info {
190 struct global_info global;
191 struct zwp_tablet_manager_v2 *manager;
192 struct weston_info *info;
194 struct wl_list seats;
197 struct presentation_info {
198 struct global_info global;
199 struct wp_presentation *presentation;
205 struct wl_display *display;
206 struct wl_registry *registry;
208 struct wl_list infos;
209 bool roundtrip_needed;
211 /* required for tablet-unstable-v2 */
212 struct wl_list seats;
213 struct tablet_v2_info *tablet_info;
217 print_global_info(void *data)
219 struct global_info *global = data;
221 printf("interface: '%s', version: %u, name: %u\n",
222 global->interface, global->version, global->id);
226 init_global_info(struct weston_info *info,
227 struct global_info *global, uint32_t id,
228 const char *interface, uint32_t version)
231 global->version = version;
232 global->interface = xstrdup(interface);
234 wl_list_insert(info->infos.prev, &global->link);
238 print_output_info(void *data)
240 struct output_info *output = data;
241 struct output_mode *mode;
242 const char *subpixel_orientation;
243 const char *transform;
245 print_global_info(data);
247 switch (output->geometry.subpixel) {
248 case WL_OUTPUT_SUBPIXEL_UNKNOWN:
249 subpixel_orientation = "unknown";
251 case WL_OUTPUT_SUBPIXEL_NONE:
252 subpixel_orientation = "none";
254 case WL_OUTPUT_SUBPIXEL_HORIZONTAL_RGB:
255 subpixel_orientation = "horizontal rgb";
257 case WL_OUTPUT_SUBPIXEL_HORIZONTAL_BGR:
258 subpixel_orientation = "horizontal bgr";
260 case WL_OUTPUT_SUBPIXEL_VERTICAL_RGB:
261 subpixel_orientation = "vertical rgb";
263 case WL_OUTPUT_SUBPIXEL_VERTICAL_BGR:
264 subpixel_orientation = "vertical bgr";
267 fprintf(stderr, "unknown subpixel orientation %u\n",
268 output->geometry.subpixel);
269 subpixel_orientation = "unexpected value";
273 switch (output->geometry.output_transform) {
274 case WL_OUTPUT_TRANSFORM_NORMAL:
275 transform = "normal";
277 case WL_OUTPUT_TRANSFORM_90:
280 case WL_OUTPUT_TRANSFORM_180:
283 case WL_OUTPUT_TRANSFORM_270:
286 case WL_OUTPUT_TRANSFORM_FLIPPED:
287 transform = "flipped";
289 case WL_OUTPUT_TRANSFORM_FLIPPED_90:
290 transform = "flipped 90°";
292 case WL_OUTPUT_TRANSFORM_FLIPPED_180:
293 transform = "flipped 180°";
295 case WL_OUTPUT_TRANSFORM_FLIPPED_270:
296 transform = "flipped 270°";
299 fprintf(stderr, "unknown output transform %u\n",
300 output->geometry.output_transform);
301 transform = "unexpected value";
305 printf("\tx: %d, y: %d,",
306 output->geometry.x, output->geometry.y);
307 if (output->version >= 2)
308 printf(" scale: %d,", output->geometry.scale);
311 printf("\tphysical_width: %d mm, physical_height: %d mm,\n",
312 output->geometry.physical_width,
313 output->geometry.physical_height);
314 printf("\tmake: '%s', model: '%s',\n",
315 output->geometry.make, output->geometry.model);
316 printf("\tsubpixel_orientation: %s, output_transform: %s,\n",
317 subpixel_orientation, transform);
319 wl_list_for_each(mode, &output->modes, link) {
322 printf("\t\twidth: %d px, height: %d px, refresh: %.3f Hz,\n",
323 mode->width, mode->height,
324 (float) mode->refresh / 1000);
326 printf("\t\tflags:");
327 if (mode->flags & WL_OUTPUT_MODE_CURRENT)
329 if (mode->flags & WL_OUTPUT_MODE_PREFERRED)
330 printf(" preferred");
336 bits2graph(uint32_t value, unsigned bitoffset)
338 int c = (value >> bitoffset) & 0xff;
340 if (isgraph(c) || isspace(c))
347 fourcc2str(uint32_t format, char *str, int len)
353 for (i = 0; i < 4; i++)
354 str[i] = bits2graph(format, i * 8);
359 print_shm_info(void *data)
362 struct shm_info *shm = data;
363 struct shm_format *format;
365 print_global_info(data);
367 printf("\tformats:");
369 wl_list_for_each(format, &shm->formats, link)
370 switch (format->format) {
371 case WL_SHM_FORMAT_ARGB8888:
374 case WL_SHM_FORMAT_XRGB8888:
377 case WL_SHM_FORMAT_RGB565:
381 fourcc2str(format->format, str, sizeof(str));
382 printf(" '%s'(0x%08x)", str, format->format);
390 print_linux_dmabuf_info(void *data)
393 struct linux_dmabuf_info *dmabuf = data;
394 struct linux_dmabuf_modifier *modifier;
396 print_global_info(data);
398 printf("\tformats:");
400 wl_list_for_each(modifier, &dmabuf->modifiers, link) {
401 fourcc2str(modifier->format, str, sizeof(str));
402 printf("\n\t'%s'(0x%08x), modifier: 0x%016"PRIx64, str, modifier->format, modifier->modifier);
409 print_seat_info(void *data)
411 struct seat_info *seat = data;
413 print_global_info(data);
415 printf("\tname: %s\n", seat->name);
416 printf("\tcapabilities:");
418 if (seat->capabilities & WL_SEAT_CAPABILITY_POINTER)
420 if (seat->capabilities & WL_SEAT_CAPABILITY_KEYBOARD)
422 if (seat->capabilities & WL_SEAT_CAPABILITY_TOUCH)
427 if (seat->repeat_rate > 0)
428 printf("\tkeyboard repeat rate: %d\n", seat->repeat_rate);
429 if (seat->repeat_delay > 0)
430 printf("\tkeyboard repeat delay: %d\n", seat->repeat_delay);
434 keyboard_handle_keymap(void *data, struct wl_keyboard *keyboard,
435 uint32_t format, int fd, uint32_t size)
440 keyboard_handle_enter(void *data, struct wl_keyboard *keyboard,
441 uint32_t serial, struct wl_surface *surface,
442 struct wl_array *keys)
447 keyboard_handle_leave(void *data, struct wl_keyboard *keyboard,
448 uint32_t serial, struct wl_surface *surface)
453 keyboard_handle_key(void *data, struct wl_keyboard *keyboard,
454 uint32_t serial, uint32_t time, uint32_t key,
460 keyboard_handle_modifiers(void *data, struct wl_keyboard *keyboard,
461 uint32_t serial, uint32_t mods_depressed,
462 uint32_t mods_latched, uint32_t mods_locked,
468 keyboard_handle_repeat_info(void *data, struct wl_keyboard *keyboard,
469 int32_t rate, int32_t delay)
471 struct seat_info *seat = data;
473 seat->repeat_rate = rate;
474 seat->repeat_delay = delay;
477 static const struct wl_keyboard_listener keyboard_listener = {
478 keyboard_handle_keymap,
479 keyboard_handle_enter,
480 keyboard_handle_leave,
482 keyboard_handle_modifiers,
483 keyboard_handle_repeat_info,
487 seat_handle_capabilities(void *data, struct wl_seat *wl_seat,
488 enum wl_seat_capability caps)
490 struct seat_info *seat = data;
492 seat->capabilities = caps;
494 /* we want listen for repeat_info from wl_keyboard, but only
495 * do so if the seat info is >= 4 and if we actually have a
497 if (seat->global.version < 4)
500 if (caps & WL_SEAT_CAPABILITY_KEYBOARD) {
501 struct wl_keyboard *keyboard;
503 keyboard = wl_seat_get_keyboard(seat->seat);
504 wl_keyboard_add_listener(keyboard, &keyboard_listener,
507 seat->info->roundtrip_needed = true;
512 seat_handle_name(void *data, struct wl_seat *wl_seat,
515 struct seat_info *seat = data;
516 seat->name = xstrdup(name);
519 static const struct wl_seat_listener seat_listener = {
520 seat_handle_capabilities,
525 destroy_seat_info(void *data)
527 struct seat_info *seat = data;
529 wl_seat_destroy(seat->seat);
531 if (seat->name != NULL)
534 wl_list_remove(&seat->global_link);
538 tablet_tool_type_to_str(enum zwp_tablet_tool_v2_type type)
541 case ZWP_TABLET_TOOL_V2_TYPE_PEN:
543 case ZWP_TABLET_TOOL_V2_TYPE_ERASER:
545 case ZWP_TABLET_TOOL_V2_TYPE_BRUSH:
547 case ZWP_TABLET_TOOL_V2_TYPE_PENCIL:
549 case ZWP_TABLET_TOOL_V2_TYPE_AIRBRUSH:
551 case ZWP_TABLET_TOOL_V2_TYPE_FINGER:
553 case ZWP_TABLET_TOOL_V2_TYPE_MOUSE:
555 case ZWP_TABLET_TOOL_V2_TYPE_LENS:
559 return "Unknown type";
563 print_tablet_tool_info(const struct tablet_tool_info *info)
565 printf("\t\ttablet_tool: %s\n", tablet_tool_type_to_str(info->type));
566 if (info->hardware_serial) {
567 printf("\t\t\thardware serial: %lx\n", info->hardware_serial);
569 if (info->hardware_id_wacom) {
570 printf("\t\t\thardware wacom: %lx\n", info->hardware_id_wacom);
573 printf("\t\t\tcapabilities:");
575 if (info->has_tilt) {
578 if (info->has_pressure) {
581 if (info->has_distance) {
584 if (info->has_rotation) {
587 if (info->has_slider) {
590 if (info->has_wheel) {
597 destroy_tablet_tool_info(struct tablet_tool_info *info)
599 wl_list_remove(&info->link);
600 zwp_tablet_tool_v2_destroy(info->tool);
605 print_tablet_pad_group_info(const struct tablet_pad_group_info *info)
608 printf("\t\t\tgroup:\n");
609 printf("\t\t\t\tmodes: %u\n", info->modes);
610 printf("\t\t\t\tstrips: %zu\n", info->strips);
611 printf("\t\t\t\trings: %zu\n", info->rings);
612 printf("\t\t\t\tbuttons:");
614 for (i = 0; i < info->button_count; ++i) {
615 printf(" %d", info->buttons[i]);
622 destroy_tablet_pad_group_info(struct tablet_pad_group_info *info)
624 wl_list_remove(&info->link);
625 zwp_tablet_pad_group_v2_destroy(info->group);
634 print_tablet_pad_info(const struct tablet_pad_info *info)
636 const struct tablet_v2_path *path;
637 const struct tablet_pad_group_info *group;
639 printf("\t\tpad:\n");
640 printf("\t\t\tbuttons: %u\n", info->buttons);
642 wl_list_for_each(path, &info->paths, link) {
643 printf("\t\t\tpath: %s\n", path->path);
646 wl_list_for_each(group, &info->groups, link) {
647 print_tablet_pad_group_info(group);
652 destroy_tablet_pad_info(struct tablet_pad_info *info)
654 struct tablet_v2_path *path;
655 struct tablet_v2_path *tmp_path;
656 struct tablet_pad_group_info *group;
657 struct tablet_pad_group_info *tmp_group;
659 wl_list_remove(&info->link);
660 zwp_tablet_pad_v2_destroy(info->pad);
662 wl_list_for_each_safe(path, tmp_path, &info->paths, link) {
663 wl_list_remove(&path->link);
668 wl_list_for_each_safe(group, tmp_group, &info->groups, link) {
669 destroy_tablet_pad_group_info(group);
676 print_tablet_info(const struct tablet_info *info)
678 const struct tablet_v2_path *path;
680 printf("\t\ttablet: %s\n", info->name);
681 printf("\t\t\tvendor: %u\n", info->vid);
682 printf("\t\t\tproduct: %u\n", info->pid);
684 wl_list_for_each(path, &info->paths, link) {
685 printf("\t\t\tpath: %s\n", path->path);
690 destroy_tablet_info(struct tablet_info *info)
692 struct tablet_v2_path *path;
693 struct tablet_v2_path *tmp;
695 wl_list_remove(&info->link);
696 zwp_tablet_v2_destroy(info->tablet);
702 wl_list_for_each_safe(path, tmp, &info->paths, link) {
703 wl_list_remove(&path->link);
712 print_tablet_seat_info(const struct tablet_seat_info *info)
714 const struct tablet_info *tablet;
715 const struct tablet_pad_info *pad;
716 const struct tablet_tool_info *tool;
718 printf("\ttablet_seat: %s\n", info->seat_info->name);
720 wl_list_for_each(tablet, &info->tablets, link) {
721 print_tablet_info(tablet);
724 wl_list_for_each(pad, &info->pads, link) {
725 print_tablet_pad_info(pad);
728 wl_list_for_each(tool, &info->tools, link) {
729 print_tablet_tool_info(tool);
734 destroy_tablet_seat_info(struct tablet_seat_info *info)
736 struct tablet_info *tablet;
737 struct tablet_info *tmp_tablet;
738 struct tablet_pad_info *pad;
739 struct tablet_pad_info *tmp_pad;
740 struct tablet_tool_info *tool;
741 struct tablet_tool_info *tmp_tool;
743 wl_list_remove(&info->link);
744 zwp_tablet_seat_v2_destroy(info->seat);
746 wl_list_for_each_safe(tablet, tmp_tablet, &info->tablets, link) {
747 destroy_tablet_info(tablet);
750 wl_list_for_each_safe(pad, tmp_pad, &info->pads, link) {
751 destroy_tablet_pad_info(pad);
754 wl_list_for_each_safe(tool, tmp_tool, &info->tools, link) {
755 destroy_tablet_tool_info(tool);
762 print_tablet_v2_info(void *data)
764 struct tablet_v2_info *info = data;
765 struct tablet_seat_info *seat;
766 print_global_info(data);
768 wl_list_for_each(seat, &info->seats, link) {
769 /* Skip tablet_seats without a tablet, they are irrelevant */
770 if (wl_list_empty(&seat->pads) &&
771 wl_list_empty(&seat->tablets) &&
772 wl_list_empty(&seat->tools)) {
776 print_tablet_seat_info(seat);
781 destroy_tablet_v2_info(void *data)
783 struct tablet_v2_info *info = data;
784 struct tablet_seat_info *seat;
785 struct tablet_seat_info *tmp;
787 zwp_tablet_manager_v2_destroy(info->manager);
789 wl_list_for_each_safe(seat, tmp, &info->seats, link) {
790 destroy_tablet_seat_info(seat);
795 handle_tablet_v2_tablet_tool_done(void *data, struct zwp_tablet_tool_v2 *tool)
797 /* don't bother waiting for this; there's no good reason a
798 * compositor will wait more than one roundtrip before sending
799 * these initial events. */
803 handle_tablet_v2_tablet_tool_removed(void *data, struct zwp_tablet_tool_v2 *tool)
805 /* don't bother waiting for this; we never make any request either way. */
809 handle_tablet_v2_tablet_tool_type(void *data, struct zwp_tablet_tool_v2 *tool,
812 struct tablet_tool_info *info = data;
813 info->type = tool_type;
817 handle_tablet_v2_tablet_tool_hardware_serial(void *data,
818 struct zwp_tablet_tool_v2 *tool,
822 struct tablet_tool_info *info = data;
824 info->hardware_serial = ((uint64_t) serial_hi) << 32 |
825 (uint64_t) serial_lo;
829 handle_tablet_v2_tablet_tool_hardware_id_wacom(void *data,
830 struct zwp_tablet_tool_v2 *tool,
831 uint32_t id_hi, uint32_t id_lo)
833 struct tablet_tool_info *info = data;
835 info->hardware_id_wacom = ((uint64_t) id_hi) << 32 | (uint64_t) id_lo;
839 handle_tablet_v2_tablet_tool_capability(void *data,
840 struct zwp_tablet_tool_v2 *tool,
843 struct tablet_tool_info *info = data;
844 enum zwp_tablet_tool_v2_capability cap = capability;
847 case ZWP_TABLET_TOOL_V2_CAPABILITY_TILT:
848 info->has_tilt = true;
850 case ZWP_TABLET_TOOL_V2_CAPABILITY_PRESSURE:
851 info->has_pressure = true;
853 case ZWP_TABLET_TOOL_V2_CAPABILITY_DISTANCE:
854 info->has_distance = true;
856 case ZWP_TABLET_TOOL_V2_CAPABILITY_ROTATION:
857 info->has_rotation = true;
859 case ZWP_TABLET_TOOL_V2_CAPABILITY_SLIDER:
860 info->has_slider = true;
862 case ZWP_TABLET_TOOL_V2_CAPABILITY_WHEEL:
863 info->has_wheel = true;
869 handle_tablet_v2_tablet_tool_proximity_in(void *data,
870 struct zwp_tablet_tool_v2 *zwp_tablet_tool_v2,
871 uint32_t serial, struct zwp_tablet_v2 *tablet,
872 struct wl_surface *surface)
878 handle_tablet_v2_tablet_tool_proximity_out(void *data,
879 struct zwp_tablet_tool_v2 *zwp_tablet_tool_v2)
885 handle_tablet_v2_tablet_tool_down(void *data,
886 struct zwp_tablet_tool_v2 *zwp_tablet_tool_v2,
893 handle_tablet_v2_tablet_tool_up(void *data,
894 struct zwp_tablet_tool_v2 *zwp_tablet_tool_v2)
901 handle_tablet_v2_tablet_tool_motion(void *data,
902 struct zwp_tablet_tool_v2 *zwp_tablet_tool_v2,
910 handle_tablet_v2_tablet_tool_pressure(void *data,
911 struct zwp_tablet_tool_v2 *zwp_tablet_tool_v2,
918 handle_tablet_v2_tablet_tool_distance(void *data,
919 struct zwp_tablet_tool_v2 *zwp_tablet_tool_v2,
926 handle_tablet_v2_tablet_tool_tilt(void *data,
927 struct zwp_tablet_tool_v2 *zwp_tablet_tool_v2,
935 handle_tablet_v2_tablet_tool_rotation(void *data,
936 struct zwp_tablet_tool_v2 *zwp_tablet_tool_v2,
943 handle_tablet_v2_tablet_tool_slider(void *data,
944 struct zwp_tablet_tool_v2 *zwp_tablet_tool_v2,
951 handle_tablet_v2_tablet_tool_wheel(void *data,
952 struct zwp_tablet_tool_v2 *zwp_tablet_tool_v2,
960 handle_tablet_v2_tablet_tool_button(void *data,
961 struct zwp_tablet_tool_v2 *zwp_tablet_tool_v2,
970 handle_tablet_v2_tablet_tool_frame(void *data,
971 struct zwp_tablet_tool_v2 *zwp_tablet_tool_v2,
977 static const struct zwp_tablet_tool_v2_listener tablet_tool_listener = {
978 .removed = handle_tablet_v2_tablet_tool_removed,
979 .done = handle_tablet_v2_tablet_tool_done,
980 .type = handle_tablet_v2_tablet_tool_type,
981 .hardware_serial = handle_tablet_v2_tablet_tool_hardware_serial,
982 .hardware_id_wacom = handle_tablet_v2_tablet_tool_hardware_id_wacom,
983 .capability = handle_tablet_v2_tablet_tool_capability,
985 .proximity_in = handle_tablet_v2_tablet_tool_proximity_in,
986 .proximity_out = handle_tablet_v2_tablet_tool_proximity_out,
987 .down = handle_tablet_v2_tablet_tool_down,
988 .up = handle_tablet_v2_tablet_tool_up,
990 .motion = handle_tablet_v2_tablet_tool_motion,
991 .pressure = handle_tablet_v2_tablet_tool_pressure,
992 .distance = handle_tablet_v2_tablet_tool_distance,
993 .tilt = handle_tablet_v2_tablet_tool_tilt,
994 .rotation = handle_tablet_v2_tablet_tool_rotation,
995 .slider = handle_tablet_v2_tablet_tool_slider,
996 .wheel = handle_tablet_v2_tablet_tool_wheel,
997 .button = handle_tablet_v2_tablet_tool_button,
998 .frame = handle_tablet_v2_tablet_tool_frame,
1001 static void add_tablet_v2_tablet_tool_info(void *data,
1002 struct zwp_tablet_seat_v2 *tablet_seat_v2,
1003 struct zwp_tablet_tool_v2 *tool)
1005 struct tablet_seat_info *tablet_seat = data;
1006 struct tablet_tool_info *tool_info = xzalloc(sizeof *tool_info);
1008 tool_info->tool = tool;
1009 wl_list_insert(&tablet_seat->tools, &tool_info->link);
1011 zwp_tablet_tool_v2_add_listener(tool, &tablet_tool_listener, tool_info);
1015 handle_tablet_v2_tablet_pad_group_mode_switch(void *data,
1016 struct zwp_tablet_pad_group_v2 *zwp_tablet_pad_group_v2,
1017 uint32_t time, uint32_t serial, uint32_t mode)
1019 /* This shouldn't ever happen */
1023 handle_tablet_v2_tablet_pad_group_done(void *data,
1024 struct zwp_tablet_pad_group_v2 *group)
1026 /* don't bother waiting for this; there's no good reason a
1027 * compositor will wait more than one roundtrip before sending
1028 * these initial events. */
1032 handle_tablet_v2_tablet_pad_group_modes(void *data,
1033 struct zwp_tablet_pad_group_v2 *group,
1036 struct tablet_pad_group_info *info = data;
1037 info->modes = modes;
1041 handle_tablet_v2_tablet_pad_group_buttons(void *data,
1042 struct zwp_tablet_pad_group_v2 *group,
1043 struct wl_array *buttons)
1045 struct tablet_pad_group_info *info = data;
1047 info->button_count = buttons->size / sizeof(int);
1048 info->buttons = xzalloc(buttons->size);
1049 memcpy(info->buttons, buttons->data, buttons->size);
1053 handle_tablet_v2_tablet_pad_group_ring(void *data,
1054 struct zwp_tablet_pad_group_v2 *group,
1055 struct zwp_tablet_pad_ring_v2 *ring)
1057 struct tablet_pad_group_info *info = data;
1060 zwp_tablet_pad_ring_v2_destroy(ring);
1064 handle_tablet_v2_tablet_pad_group_strip(void *data,
1065 struct zwp_tablet_pad_group_v2 *group,
1066 struct zwp_tablet_pad_strip_v2 *strip)
1068 struct tablet_pad_group_info *info = data;
1071 zwp_tablet_pad_strip_v2_destroy(strip);
1074 static const struct zwp_tablet_pad_group_v2_listener tablet_pad_group_listener = {
1075 .buttons = handle_tablet_v2_tablet_pad_group_buttons,
1076 .modes = handle_tablet_v2_tablet_pad_group_modes,
1077 .ring = handle_tablet_v2_tablet_pad_group_ring,
1078 .strip = handle_tablet_v2_tablet_pad_group_strip,
1079 .done = handle_tablet_v2_tablet_pad_group_done,
1080 .mode_switch = handle_tablet_v2_tablet_pad_group_mode_switch,
1084 handle_tablet_v2_tablet_pad_group(void *data,
1085 struct zwp_tablet_pad_v2 *zwp_tablet_pad_v2,
1086 struct zwp_tablet_pad_group_v2 *pad_group)
1088 struct tablet_pad_info *pad_info = data;
1089 struct tablet_pad_group_info *group = xzalloc(sizeof *group);
1091 wl_list_insert(&pad_info->groups, &group->link);
1092 group->group = pad_group;
1093 zwp_tablet_pad_group_v2_add_listener(pad_group,
1094 &tablet_pad_group_listener, group);
1098 handle_tablet_v2_tablet_pad_path(void *data, struct zwp_tablet_pad_v2 *pad,
1101 struct tablet_pad_info *pad_info = data;
1102 struct tablet_v2_path *path_elem = xzalloc(sizeof *path_elem);
1103 path_elem->path = xstrdup(path);
1105 wl_list_insert(&pad_info->paths, &path_elem->link);
1109 handle_tablet_v2_tablet_pad_buttons(void *data, struct zwp_tablet_pad_v2 *pad,
1112 struct tablet_pad_info *pad_info = data;
1114 pad_info->buttons = buttons;
1118 handle_tablet_v2_tablet_pad_done(void *data, struct zwp_tablet_pad_v2 *pad)
1120 /* don't bother waiting for this; there's no good reason a
1121 * compositor will wait more than one roundtrip before sending
1122 * these initial events. */
1126 handle_tablet_v2_tablet_pad_removed(void *data, struct zwp_tablet_pad_v2 *pad)
1128 /* don't bother waiting for this; We never make any request that's not
1129 * allowed to be issued either way. */
1133 handle_tablet_v2_tablet_pad_button(void *data, struct zwp_tablet_pad_v2 *pad,
1134 uint32_t time, uint32_t button, uint32_t state)
1136 /* we don't have a surface, so this can't ever happen */
1140 handle_tablet_v2_tablet_pad_enter(void *data, struct zwp_tablet_pad_v2 *pad,
1142 struct zwp_tablet_v2 *tablet,
1143 struct wl_surface *surface)
1145 /* we don't have a surface, so this can't ever happen */
1149 handle_tablet_v2_tablet_pad_leave(void *data, struct zwp_tablet_pad_v2 *pad,
1150 uint32_t serial, struct wl_surface *surface)
1152 /* we don't have a surface, so this can't ever happen */
1155 static const struct zwp_tablet_pad_v2_listener tablet_pad_listener = {
1156 .group = handle_tablet_v2_tablet_pad_group,
1157 .path = handle_tablet_v2_tablet_pad_path,
1158 .buttons = handle_tablet_v2_tablet_pad_buttons,
1159 .done = handle_tablet_v2_tablet_pad_done,
1160 .removed = handle_tablet_v2_tablet_pad_removed,
1161 .button = handle_tablet_v2_tablet_pad_button,
1162 .enter = handle_tablet_v2_tablet_pad_enter,
1163 .leave = handle_tablet_v2_tablet_pad_leave,
1166 static void add_tablet_v2_tablet_pad_info(void *data,
1167 struct zwp_tablet_seat_v2 *tablet_seat_v2,
1168 struct zwp_tablet_pad_v2 *pad)
1170 struct tablet_seat_info *tablet_seat = data;
1171 struct tablet_pad_info *pad_info = xzalloc(sizeof *pad_info);
1173 wl_list_init(&pad_info->paths);
1174 wl_list_init(&pad_info->groups);
1175 pad_info->pad = pad;
1176 wl_list_insert(&tablet_seat->pads, &pad_info->link);
1178 zwp_tablet_pad_v2_add_listener(pad, &tablet_pad_listener, pad_info);
1182 handle_tablet_v2_tablet_name(void *data, struct zwp_tablet_v2 *zwp_tablet_v2,
1185 struct tablet_info *tablet_info = data;
1186 tablet_info->name = xstrdup(name);
1190 handle_tablet_v2_tablet_path(void *data, struct zwp_tablet_v2 *zwp_tablet_v2,
1193 struct tablet_info *tablet_info = data;
1194 struct tablet_v2_path *path_elem = xzalloc(sizeof *path_elem);
1195 path_elem->path = xstrdup(path);
1197 wl_list_insert(&tablet_info->paths, &path_elem->link);
1201 handle_tablet_v2_tablet_id(void *data, struct zwp_tablet_v2 *zwp_tablet_v2,
1202 uint32_t vid, uint32_t pid)
1204 struct tablet_info *tablet_info = data;
1206 tablet_info->vid = vid;
1207 tablet_info->pid = pid;
1211 handle_tablet_v2_tablet_done(void *data, struct zwp_tablet_v2 *zwp_tablet_v2)
1213 /* don't bother waiting for this; there's no good reason a
1214 * compositor will wait more than one roundtrip before sending
1215 * these initial events. */
1219 handle_tablet_v2_tablet_removed(void *data, struct zwp_tablet_v2 *zwp_tablet_v2)
1221 /* don't bother waiting for this; We never make any request that's not
1222 * allowed to be issued either way. */
1225 static const struct zwp_tablet_v2_listener tablet_listener = {
1226 .name = handle_tablet_v2_tablet_name,
1227 .id = handle_tablet_v2_tablet_id,
1228 .path = handle_tablet_v2_tablet_path,
1229 .done = handle_tablet_v2_tablet_done,
1230 .removed = handle_tablet_v2_tablet_removed
1234 add_tablet_v2_tablet_info(void *data, struct zwp_tablet_seat_v2 *tablet_seat_v2,
1235 struct zwp_tablet_v2 *tablet)
1237 struct tablet_seat_info *tablet_seat = data;
1238 struct tablet_info *tablet_info = xzalloc(sizeof *tablet_info);
1240 wl_list_init(&tablet_info->paths);
1241 tablet_info->tablet = tablet;
1242 wl_list_insert(&tablet_seat->tablets, &tablet_info->link);
1244 zwp_tablet_v2_add_listener(tablet, &tablet_listener, tablet_info);
1247 static const struct zwp_tablet_seat_v2_listener tablet_seat_listener = {
1248 .tablet_added = add_tablet_v2_tablet_info,
1249 .pad_added = add_tablet_v2_tablet_pad_info,
1250 .tool_added = add_tablet_v2_tablet_tool_info,
1254 add_tablet_seat_info(struct tablet_v2_info *tablet_info, struct seat_info *seat)
1256 struct tablet_seat_info *tablet_seat = xzalloc(sizeof *tablet_seat);
1258 wl_list_insert(&tablet_info->seats, &tablet_seat->link);
1259 tablet_seat->seat = zwp_tablet_manager_v2_get_tablet_seat(
1260 tablet_info->manager, seat->seat);
1261 zwp_tablet_seat_v2_add_listener(tablet_seat->seat,
1262 &tablet_seat_listener, tablet_seat);
1264 wl_list_init(&tablet_seat->pads);
1265 wl_list_init(&tablet_seat->tablets);
1266 wl_list_init(&tablet_seat->tools);
1267 tablet_seat->seat_info = seat;
1269 tablet_info->info->roundtrip_needed = true;
1273 add_tablet_v2_info(struct weston_info *info, uint32_t id, uint32_t version)
1275 struct seat_info *seat;
1276 struct tablet_v2_info *tablet = xzalloc(sizeof *tablet);
1278 wl_list_init(&tablet->seats);
1279 tablet->info = info;
1281 init_global_info(info, &tablet->global, id,
1282 zwp_tablet_manager_v2_interface.name, version);
1283 tablet->global.print = print_tablet_v2_info;
1284 tablet->global.destroy = destroy_tablet_v2_info;
1286 tablet->manager = wl_registry_bind(info->registry,
1287 id, &zwp_tablet_manager_v2_interface, 1);
1289 wl_list_for_each(seat, &info->seats, global_link) {
1290 add_tablet_seat_info(tablet, seat);
1293 info->tablet_info = tablet;
1297 add_seat_info(struct weston_info *info, uint32_t id, uint32_t version)
1299 struct seat_info *seat = xzalloc(sizeof *seat);
1301 /* required to set roundtrip_needed to true in capabilities
1305 init_global_info(info, &seat->global, id, "wl_seat", version);
1306 seat->global.print = print_seat_info;
1307 seat->global.destroy = destroy_seat_info;
1309 seat->seat = wl_registry_bind(info->registry,
1310 id, &wl_seat_interface, MIN(version, 4));
1311 wl_seat_add_listener(seat->seat, &seat_listener, seat);
1313 seat->repeat_rate = seat->repeat_delay = -1;
1315 info->roundtrip_needed = true;
1316 wl_list_insert(&info->seats, &seat->global_link);
1318 if (info->tablet_info) {
1319 add_tablet_seat_info(info->tablet_info, seat);
1324 shm_handle_format(void *data, struct wl_shm *wl_shm, uint32_t format)
1326 struct shm_info *shm = data;
1327 struct shm_format *shm_format = xzalloc(sizeof *shm_format);
1329 wl_list_insert(&shm->formats, &shm_format->link);
1330 shm_format->format = format;
1333 static const struct wl_shm_listener shm_listener = {
1338 destroy_shm_info(void *data)
1340 struct shm_info *shm = data;
1341 struct shm_format *format, *tmp;
1343 wl_list_for_each_safe(format, tmp, &shm->formats, link) {
1344 wl_list_remove(&format->link);
1348 wl_shm_destroy(shm->shm);
1352 add_shm_info(struct weston_info *info, uint32_t id, uint32_t version)
1354 struct shm_info *shm = xzalloc(sizeof *shm);
1356 init_global_info(info, &shm->global, id, "wl_shm", version);
1357 shm->global.print = print_shm_info;
1358 shm->global.destroy = destroy_shm_info;
1360 wl_list_init(&shm->formats);
1362 shm->shm = wl_registry_bind(info->registry,
1363 id, &wl_shm_interface, 1);
1364 wl_shm_add_listener(shm->shm, &shm_listener, shm);
1366 info->roundtrip_needed = true;
1370 linux_dmabuf_handle_format(void *data, struct zwp_linux_dmabuf_v1 *zwp_linux_dmabuf_v1, uint32_t format)
1372 /* This is a deprecated event, don’t use it. */
1376 linux_dmabuf_handle_modifier(void *data, struct zwp_linux_dmabuf_v1 *zwp_linux_dmabuf_v1, uint32_t format, uint32_t modifier_hi, uint32_t modifier_lo)
1378 struct linux_dmabuf_info *dmabuf = data;
1379 struct linux_dmabuf_modifier *linux_dmabuf_modifier = xzalloc(sizeof *linux_dmabuf_modifier);
1381 wl_list_insert(&dmabuf->modifiers, &linux_dmabuf_modifier->link);
1382 linux_dmabuf_modifier->format = format;
1383 linux_dmabuf_modifier->modifier = ((uint64_t)modifier_hi) << 32 | modifier_lo;
1386 static const struct zwp_linux_dmabuf_v1_listener linux_dmabuf_listener = {
1387 linux_dmabuf_handle_format,
1388 linux_dmabuf_handle_modifier,
1392 destroy_linux_dmabuf_info(void *data)
1394 struct linux_dmabuf_info *dmabuf = data;
1395 struct linux_dmabuf_modifier *modifier, *tmp;
1397 wl_list_for_each_safe(modifier, tmp, &dmabuf->modifiers, link) {
1398 wl_list_remove(&modifier->link);
1402 zwp_linux_dmabuf_v1_destroy(dmabuf->dmabuf);
1406 add_linux_dmabuf_info(struct weston_info *info, uint32_t id, uint32_t version)
1408 struct linux_dmabuf_info *dmabuf = xzalloc(sizeof *dmabuf);
1410 init_global_info(info, &dmabuf->global, id, "zwp_linux_dmabuf_v1", version);
1411 dmabuf->global.print = print_linux_dmabuf_info;
1412 dmabuf->global.destroy = destroy_linux_dmabuf_info;
1414 wl_list_init(&dmabuf->modifiers);
1417 dmabuf->dmabuf = wl_registry_bind(info->registry,
1418 id, &zwp_linux_dmabuf_v1_interface, 3);
1419 zwp_linux_dmabuf_v1_add_listener(dmabuf->dmabuf, &linux_dmabuf_listener, dmabuf);
1421 info->roundtrip_needed = true;
1426 output_handle_geometry(void *data, struct wl_output *wl_output,
1427 int32_t x, int32_t y,
1428 int32_t physical_width, int32_t physical_height,
1430 const char *make, const char *model,
1431 int32_t output_transform)
1433 struct output_info *output = data;
1435 output->geometry.x = x;
1436 output->geometry.y = y;
1437 output->geometry.physical_width = physical_width;
1438 output->geometry.physical_height = physical_height;
1439 output->geometry.subpixel = subpixel;
1440 output->geometry.make = xstrdup(make);
1441 output->geometry.model = xstrdup(model);
1442 output->geometry.output_transform = output_transform;
1446 output_handle_mode(void *data, struct wl_output *wl_output,
1447 uint32_t flags, int32_t width, int32_t height,
1450 struct output_info *output = data;
1451 struct output_mode *mode = xmalloc(sizeof *mode);
1453 mode->flags = flags;
1454 mode->width = width;
1455 mode->height = height;
1456 mode->refresh = refresh;
1458 wl_list_insert(output->modes.prev, &mode->link);
1462 output_handle_done(void *data, struct wl_output *wl_output)
1464 /* don't bother waiting for this; there's no good reason a
1465 * compositor will wait more than one roundtrip before sending
1466 * these initial events. */
1470 output_handle_scale(void *data, struct wl_output *wl_output,
1473 struct output_info *output = data;
1475 output->geometry.scale = scale;
1478 static const struct wl_output_listener output_listener = {
1479 output_handle_geometry,
1482 output_handle_scale,
1486 destroy_output_info(void *data)
1488 struct output_info *output = data;
1489 struct output_mode *mode, *tmp;
1491 wl_output_destroy(output->output);
1493 if (output->geometry.make != NULL)
1494 free(output->geometry.make);
1495 if (output->geometry.model != NULL)
1496 free(output->geometry.model);
1498 wl_list_for_each_safe(mode, tmp, &output->modes, link) {
1499 wl_list_remove(&mode->link);
1505 add_output_info(struct weston_info *info, uint32_t id, uint32_t version)
1507 struct output_info *output = xzalloc(sizeof *output);
1509 init_global_info(info, &output->global, id, "wl_output", version);
1510 output->global.print = print_output_info;
1511 output->global.destroy = destroy_output_info;
1513 output->version = MIN(version, 2);
1514 output->geometry.scale = 1;
1515 wl_list_init(&output->modes);
1517 output->output = wl_registry_bind(info->registry, id,
1518 &wl_output_interface, output->version);
1519 wl_output_add_listener(output->output, &output_listener,
1522 info->roundtrip_needed = true;
1526 destroy_presentation_info(void *info)
1528 struct presentation_info *prinfo = info;
1530 wp_presentation_destroy(prinfo->presentation);
1534 clock_name(clockid_t clk_id)
1536 static const char *names[] = {
1537 [CLOCK_REALTIME] = "CLOCK_REALTIME",
1538 [CLOCK_MONOTONIC] = "CLOCK_MONOTONIC",
1539 [CLOCK_MONOTONIC_RAW] = "CLOCK_MONOTONIC_RAW",
1540 [CLOCK_REALTIME_COARSE] = "CLOCK_REALTIME_COARSE",
1541 [CLOCK_MONOTONIC_COARSE] = "CLOCK_MONOTONIC_COARSE",
1542 #ifdef CLOCK_BOOTTIME
1543 [CLOCK_BOOTTIME] = "CLOCK_BOOTTIME",
1547 if (clk_id < 0 || (unsigned)clk_id >= ARRAY_LENGTH(names))
1550 return names[clk_id];
1554 print_presentation_info(void *info)
1556 struct presentation_info *prinfo = info;
1558 print_global_info(info);
1560 printf("\tpresentation clock id: %d (%s)\n",
1561 prinfo->clk_id, clock_name(prinfo->clk_id));
1565 presentation_handle_clock_id(void *data, struct wp_presentation *presentation,
1568 struct presentation_info *prinfo = data;
1570 prinfo->clk_id = clk_id;
1573 static const struct wp_presentation_listener presentation_listener = {
1574 presentation_handle_clock_id
1578 add_presentation_info(struct weston_info *info, uint32_t id, uint32_t version)
1580 struct presentation_info *prinfo = xzalloc(sizeof *prinfo);
1582 init_global_info(info, &prinfo->global, id,
1583 wp_presentation_interface.name, version);
1584 prinfo->global.print = print_presentation_info;
1585 prinfo->global.destroy = destroy_presentation_info;
1587 prinfo->clk_id = -1;
1588 prinfo->presentation = wl_registry_bind(info->registry, id,
1589 &wp_presentation_interface, 1);
1590 wp_presentation_add_listener(prinfo->presentation,
1591 &presentation_listener, prinfo);
1593 info->roundtrip_needed = true;
1597 destroy_global_info(void *data)
1602 add_global_info(struct weston_info *info, uint32_t id,
1603 const char *interface, uint32_t version)
1605 struct global_info *global = xzalloc(sizeof *global);
1607 init_global_info(info, global, id, interface, version);
1608 global->print = print_global_info;
1609 global->destroy = destroy_global_info;
1613 global_handler(void *data, struct wl_registry *registry, uint32_t id,
1614 const char *interface, uint32_t version)
1616 struct weston_info *info = data;
1618 if (!strcmp(interface, "wl_seat"))
1619 add_seat_info(info, id, version);
1620 else if (!strcmp(interface, "wl_shm"))
1621 add_shm_info(info, id, version);
1622 else if (!strcmp(interface, "zwp_linux_dmabuf_v1"))
1623 add_linux_dmabuf_info(info, id, version);
1624 else if (!strcmp(interface, "wl_output"))
1625 add_output_info(info, id, version);
1626 else if (!strcmp(interface, wp_presentation_interface.name))
1627 add_presentation_info(info, id, version);
1628 else if (!strcmp(interface, zwp_tablet_manager_v2_interface.name))
1629 add_tablet_v2_info(info, id, version);
1631 add_global_info(info, id, interface, version);
1635 global_remove_handler(void *data, struct wl_registry *registry, uint32_t name)
1639 static const struct wl_registry_listener registry_listener = {
1641 global_remove_handler
1645 print_infos(struct wl_list *infos)
1647 struct global_info *info;
1649 wl_list_for_each(info, infos, link)
1654 destroy_info(void *data)
1656 struct global_info *global = data;
1658 global->destroy(data);
1659 wl_list_remove(&global->link);
1660 free(global->interface);
1665 destroy_infos(struct wl_list *infos)
1667 struct global_info *info, *tmp;
1668 wl_list_for_each_safe(info, tmp, infos, link)
1673 main(int argc, char **argv)
1675 struct weston_info info;
1677 info.display = wl_display_connect(NULL);
1678 if (!info.display) {
1679 fprintf(stderr, "failed to create display: %m\n");
1683 info.tablet_info = NULL;
1684 wl_list_init(&info.infos);
1685 wl_list_init(&info.seats);
1687 info.registry = wl_display_get_registry(info.display);
1688 wl_registry_add_listener(info.registry, ®istry_listener, &info);
1691 info.roundtrip_needed = false;
1692 wl_display_roundtrip(info.display);
1693 } while (info.roundtrip_needed);
1695 print_infos(&info.infos);
1696 destroy_infos(&info.infos);
1698 wl_registry_destroy(info.registry);
1699 wl_display_disconnect(info.display);