From a3cdf59cee41af3d555efab577061804ad28ac9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristian=20H=C3=B8gsberg?= Date: Thu, 17 Nov 2011 10:27:17 -0500 Subject: [PATCH] simple-shm: Add a wl_shm listener This way we properly check that WL_SHM_FORMAT_XRGB32 is available. --- clients/simple-shm.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/clients/simple-shm.c b/clients/simple-shm.c index a93c2033..c112303f 100644 --- a/clients/simple-shm.c +++ b/clients/simple-shm.c @@ -37,6 +37,7 @@ struct display { struct wl_compositor *compositor; struct wl_shell *shell; struct wl_shm *shm; + uint32_t formats; uint32_t mask; }; @@ -140,6 +141,18 @@ static const struct wl_callback_listener frame_listener = { redraw }; +static void +shm_format(void *data, struct wl_shm *wl_shm, uint32_t format) +{ + struct display *d = data; + + d->formats |= (1 << format); +} + +struct wl_shm_listener shm_listenter = { + shm_format +}; + static void display_handle_global(struct wl_display *display, uint32_t id, const char *interface, uint32_t version, void *data) @@ -153,6 +166,7 @@ display_handle_global(struct wl_display *display, uint32_t id, d->shell = wl_display_bind(display, id, &wl_shell_interface); } else if (strcmp(interface, "wl_shm") == 0) { d->shm = wl_display_bind(display, id, &wl_shm_interface); + wl_shm_add_listener(d->shm, &shm_listenter, d); } } @@ -175,9 +189,16 @@ create_display(void) display->display = wl_display_connect(NULL); assert(display->display); + display->formats = 0; wl_display_add_global_listener(display->display, display_handle_global, display); wl_display_iterate(display->display, WL_DISPLAY_READABLE); + wl_display_roundtrip(display->display); + + if (!(display->formats & (1 << WL_SHM_FORMAT_XRGB32))) { + fprintf(stderr, "WL_SHM_FORMAT_XRGB32 not available\n"); + exit(1); + } wl_display_get_fd(display->display, event_mask_update, display);