summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonas Ã…dahl <jadahl@gmail.com>2022-11-15 10:48:57 +0100
committerMarge Bot <marge-bot@gnome.org>2022-12-17 20:38:23 +0000
commit474c0938017bf051bf4305b3162b3edc56536ce3 (patch)
tree57ead744ce2dedb80d93cc6136f989dc11277bf5
parentd97c160122950c6b197dee64d8a145c68310df77 (diff)
downloadmutter-474c0938017bf051bf4305b3162b3edc56536ce3.tar.gz
tests/wayland-client-utils: Add simple toplevel helper
Add a helper to create a toplevel painted with a given color, size and title. It's meant to be "dumb" and have a default size, but respect any configured size. Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2770>
-rw-r--r--src/tests/wayland-test-clients/wayland-test-client-utils.c88
-rw-r--r--src/tests/wayland-test-clients/wayland-test-client-utils.h24
2 files changed, 112 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)
diff --git a/src/tests/wayland-test-clients/wayland-test-client-utils.h b/src/tests/wayland-test-clients/wayland-test-client-utils.h
index d98040c38..1b926e994 100644
--- a/src/tests/wayland-test-clients/wayland-test-client-utils.h
+++ b/src/tests/wayland-test-clients/wayland-test-client-utils.h
@@ -36,6 +36,22 @@ typedef struct _WaylandDisplay
GHashTable *properties;
} WaylandDisplay;
+typedef struct _WaylandSurface
+{
+ WaylandDisplay *display;
+
+ struct wl_surface *wl_surface;
+ struct xdg_surface *xdg_surface;
+ struct xdg_toplevel *xdg_toplevel;
+
+ int default_width;
+ int default_height;
+ int width;
+ int height;
+
+ uint32_t color;
+} WaylandSurface;
+
G_DECLARE_FINAL_TYPE (WaylandDisplay, wayland_display,
WAYLAND, DISPLAY,
GObject)
@@ -44,6 +60,14 @@ int create_anonymous_file (off_t size);
WaylandDisplay * wayland_display_new (WaylandDisplayCapabilities capabilities);
+WaylandSurface * wayland_surface_new (WaylandDisplay *display,
+ const char *title,
+ int default_width,
+ int default_height,
+ uint32_t color);
+
+void wayland_surface_free (WaylandSurface *surface);
+
gboolean create_shm_buffer (WaylandDisplay *display,
int width,
int height,