diff --git a/man/wayland-info.man b/man/wayland-info.man index 2b7404fab1b41e99d297f52b73f6c068159e9c4a..2bed5e4fa6be635b85e19f87d676c8e861c2c946 100644 --- a/man/wayland-info.man +++ b/man/wayland-info.man @@ -3,6 +3,7 @@ wayland-info \- display information utility for Wayland .SH SYNOPSIS .B wayland-info +[option ...] . .\" *************************************************************** .SH DESCRIPTION @@ -23,7 +24,14 @@ protocols. .SH OPTIONS . .B wayland-info -does not accept any command line option. +accepts the following line options: +.TP 8 +.B \-h, \-\-help +Print a summary of command line options, and quit. +.TP 8 +.B \-i, \-\-interface \fIinterface\fR +Only print information about the Wayland globals containing the string +\fIinterface\fR in their name. . .\" *************************************************************** .SH ENVIRONMENT diff --git a/wayland-info/wayland-info.c b/wayland-info/wayland-info.c index 0560167e0d8aedd3cb1288af724b43e3513b68fe..3d7404eb0e906139aba23c1561f75feacc537889 100644 --- a/wayland-info/wayland-info.c +++ b/wayland-info/wayland-info.c @@ -263,6 +263,7 @@ struct presentation_info { struct wayland_info { struct wl_display *display; struct wl_registry *registry; + char *interface; struct wl_list infos; bool roundtrip_needed; @@ -2109,13 +2110,22 @@ static const struct wl_registry_listener registry_listener = { global_remove_handler }; +static bool +should_print_info(struct wayland_info *wayland_info, struct global_info *global) +{ + return !wayland_info->interface || + strstr(global->interface, wayland_info->interface); +} + static void -print_infos(struct wl_list *infos) +print_infos(struct wayland_info *wayland_info) { + struct wl_list *infos = &wayland_info->infos; struct global_info *info; wl_list_for_each(info, infos, link) - info->print(info); + if (should_print_info(wayland_info, info)) + info->print(info); } static void @@ -2137,11 +2147,48 @@ destroy_infos(struct wl_list *infos) destroy_info(info); } +static void +print_usage(const char *name, int exit_status) +{ + fprintf(stderr, "Usage: %s [options...] \n", name); + fprintf(stderr, "\n"); + fprintf(stderr, " -h|--help: Print this help and exit\n"); + fprintf(stderr, " -i|--interface <interface>: Only print information about the" + " Wayland globals containing <interface> in their name\n"); + fprintf(stderr, "\n"); + exit(exit_status); +} + +static void +parse_cmdline(struct wayland_info *info, int argc, char **argv) +{ + int i; + + info->interface = NULL; + + for (i = 1; i < argc; i++) { + if (!strcmp(argv[i], "--help") || !strcmp(argv[i], "-h")) { + print_usage(argv[0], EXIT_SUCCESS); + } else if (!strcmp(argv[i], "--interface") || !strcmp(argv[i], "-i")) { + if (i + 1 >= argc) { + fprintf(stderr, "Missing interface name\n"); + print_usage(argv[0], EXIT_FAILURE); + } + info->interface = strdup(argv[++i]); + } else { + fprintf(stderr, "Unknown option %s\n", argv[i]); + print_usage(argv[0], EXIT_FAILURE); + } + } +} + int main(int argc, char **argv) { struct wayland_info info; + parse_cmdline(&info, argc, argv); + info.display = wl_display_connect(NULL); if (!info.display) { fprintf(stderr, "failed to create display: %s\n", @@ -2163,7 +2210,7 @@ main(int argc, char **argv) wl_display_roundtrip(info.display); } while (info.roundtrip_needed); - print_infos(&info.infos); + print_infos(&info); destroy_infos(&info.infos); wl_registry_destroy(info.registry);