diff options
Diffstat (limited to 'src/tests/wayland-test-clients/wayland-test-client-utils.c')
-rw-r--r-- | src/tests/wayland-test-clients/wayland-test-client-utils.c | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/src/tests/wayland-test-clients/wayland-test-client-utils.c b/src/tests/wayland-test-clients/wayland-test-client-utils.c index 6021ad5be..06c963f52 100644 --- a/src/tests/wayland-test-clients/wayland-test-client-utils.c +++ b/src/tests/wayland-test-clients/wayland-test-client-utils.c @@ -381,6 +381,94 @@ draw_surface (WaylandDisplay *display, wl_surface_attach (surface, buffer, 0, 0); } +static void +handle_xdg_toplevel_configure (void *data, + struct xdg_toplevel *xdg_toplevel, + int32_t width, + int32_t height, + struct wl_array *state) +{ + WaylandSurface *surface = data; + + if (width == 0) + surface->width = surface->default_width; + else + surface->width = width; + + if (height == 0) + surface->height = surface->default_height; + else + surface->height = height; +} + +static void +handle_xdg_toplevel_close (void *data, + struct xdg_toplevel *xdg_toplevel) +{ + g_assert_not_reached (); +} + +static const struct xdg_toplevel_listener xdg_toplevel_listener = { + handle_xdg_toplevel_configure, + handle_xdg_toplevel_close, +}; + +static void +handle_xdg_surface_configure (void *data, + struct xdg_surface *xdg_surface, + uint32_t serial) +{ + WaylandSurface *surface = data; + + draw_surface (surface->display, + surface->wl_surface, + surface->width, surface->height, + surface->color); + + xdg_surface_ack_configure (xdg_surface, serial); + wl_surface_commit (surface->wl_surface); +} + +static const struct xdg_surface_listener xdg_surface_listener = { + handle_xdg_surface_configure, +}; + +WaylandSurface * +wayland_surface_new (WaylandDisplay *display, + const char *title, + int default_width, + int default_height, + uint32_t color) +{ + WaylandSurface *surface; + + surface = g_new0 (WaylandSurface, 1); + surface->display = display; + surface->default_width = default_width; + surface->default_height = default_height; + surface->color = color; + surface->wl_surface = wl_compositor_create_surface (display->compositor); + surface->xdg_surface = xdg_wm_base_get_xdg_surface (display->xdg_wm_base, + surface->wl_surface); + xdg_surface_add_listener (surface->xdg_surface, &xdg_surface_listener, + surface); + surface->xdg_toplevel = xdg_surface_get_toplevel (surface->xdg_surface); + xdg_toplevel_add_listener (surface->xdg_toplevel, &xdg_toplevel_listener, + surface); + xdg_toplevel_set_title (surface->xdg_toplevel, title); + + return surface; +} + +void +wayland_surface_free (WaylandSurface *surface) +{ + g_clear_pointer (&surface->xdg_toplevel, xdg_toplevel_destroy); + g_clear_pointer (&surface->xdg_surface, xdg_surface_destroy); + g_clear_pointer (&surface->wl_surface, wl_surface_destroy); + g_free (surface); +} + const char * lookup_property_value (WaylandDisplay *display, const char *name) |