diff --git a/src/tests/wayland-test-clients/service-client.c b/src/tests/wayland-test-clients/service-client.c index 7bf02eade..65f0b0726 100644 --- a/src/tests/wayland-test-clients/service-client.c +++ b/src/tests/wayland-test-clients/service-client.c @@ -93,6 +93,6 @@ main (int argc, return EXIT_FAILURE; } - wayland_surface_free (surface); + g_object_unref (surface); g_object_unref (display); } 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 1de9d9a55..c89d3f7c9 100644 --- a/src/tests/wayland-test-clients/wayland-test-client-utils.c +++ b/src/tests/wayland-test-clients/wayland-test-client-utils.c @@ -47,6 +47,10 @@ G_DEFINE_TYPE (WaylandDisplay, wayland_display, G_TYPE_OBJECT) +G_DEFINE_TYPE (WaylandSurface, + wayland_surface, + G_TYPE_OBJECT) + static int create_tmpfile_cloexec (char *tmpname) { @@ -450,6 +454,31 @@ static const struct xdg_surface_listener xdg_surface_listener = { handle_xdg_surface_configure, }; +static void +wayland_surface_dispose (GObject *object) +{ + WaylandSurface *surface = WAYLAND_SURFACE (object); + + 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_OBJECT_CLASS (wayland_surface_parent_class)->dispose (object); +} + +static void +wayland_surface_class_init (WaylandSurfaceClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->dispose = wayland_surface_dispose; +} + +static void +wayland_surface_init (WaylandSurface *surface) +{ +} + WaylandSurface * wayland_surface_new (WaylandDisplay *display, const char *title, @@ -459,7 +488,8 @@ wayland_surface_new (WaylandDisplay *display, { WaylandSurface *surface; - surface = g_new0 (WaylandSurface, 1); + surface = g_object_new (WAYLAND_TYPE_SURFACE, NULL); + surface->display = display; surface->default_width = default_width; surface->default_height = default_height; @@ -477,15 +507,6 @@ wayland_surface_new (WaylandDisplay *display, 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 86d80566e..1c58fa3ee 100644 --- a/src/tests/wayland-test-clients/wayland-test-client-utils.h +++ b/src/tests/wayland-test-clients/wayland-test-client-utils.h @@ -60,6 +60,11 @@ typedef struct _WaylandSurface uint32_t color; } WaylandSurface; +#define WAYLAND_TYPE_SURFACE (wayland_surface_get_type ()) +G_DECLARE_FINAL_TYPE (WaylandSurface, wayland_surface, + WAYLAND, SURFACE, + GObject) + int create_anonymous_file (off_t size); WaylandDisplay * wayland_display_new (WaylandDisplayCapabilities capabilities); @@ -73,8 +78,6 @@ WaylandSurface * wayland_surface_new (WaylandDisplay *display, int default_height, uint32_t color); -void wayland_surface_free (WaylandSurface *surface); - gboolean create_shm_buffer (WaylandDisplay *display, int width, int height, diff --git a/src/tests/wayland-test-clients/xdg-foreign.c b/src/tests/wayland-test-clients/xdg-foreign.c index 42bd83c0f..f2dbec151 100644 --- a/src/tests/wayland-test-clients/xdg-foreign.c +++ b/src/tests/wayland-test-clients/xdg-foreign.c @@ -130,10 +130,10 @@ int main (int argc, char **argv) { - WaylandSurface *window1; - WaylandSurface *window2; - WaylandSurface *window3; - WaylandSurface *window4; + g_autoptr (WaylandSurface) window1; + g_autoptr (WaylandSurface) window2; + g_autoptr (WaylandSurface) window3; + g_autoptr (WaylandSurface) window4; g_autofree char *handle1 = NULL; g_autofree char *handle3 = NULL; struct wl_registry *registry; @@ -222,11 +222,6 @@ main (int argc, return EXIT_FAILURE; } - wayland_surface_free (window1); - wayland_surface_free (window2); - wayland_surface_free (window3); - wayland_surface_free (window4); - g_object_unref (display); return EXIT_SUCCESS;