tests/wayland/utils: Add method to synchronize with windows being shown

Can be used to wait for a window to be "shown", meaning it'll be added
to the stack and will be part of the next frame (assuming it's actually
not obscured etc).

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3475>
This commit is contained in:
Jonas Ådahl 2024-03-25 10:53:59 +01:00 committed by Marge Bot
parent fd6d86d33d
commit 33ff998a10
4 changed files with 72 additions and 0 deletions

View File

@ -162,6 +162,41 @@ sync_effects_completed (struct wl_client *client,
clutter_stage_schedule_update (CLUTTER_STAGE (stage));
}
static void
on_window_shown (MetaWindow *window,
struct wl_resource *callback)
{
g_signal_handlers_disconnect_by_data (window, callback);
wl_callback_send_done (callback, 0);
}
static void
sync_window_shown (struct wl_client *client,
struct wl_resource *resource,
uint32_t id,
struct wl_resource *surface_resource)
{
MetaWaylandSurface *surface = wl_resource_get_user_data (surface_resource);
MetaWindow *window = meta_wayland_surface_get_window (surface);
struct wl_resource *callback;
g_assert_nonnull (surface);
g_assert_nonnull (window);
callback = wl_resource_create (client, &wl_callback_interface, 1, id);
if (meta_window_is_hidden (window))
{
g_signal_connect (meta_wayland_surface_get_window (surface),
"shown", G_CALLBACK (on_window_shown),
callback);
}
else
{
wl_callback_send_done (callback, 0);
}
}
static void
sync_point (struct wl_client *client,
struct wl_resource *resource,
@ -217,6 +252,7 @@ verify_view (struct wl_client *client,
static const struct test_driver_interface meta_test_driver_interface = {
sync_actor_destroy,
sync_effects_completed,
sync_window_shown,
sync_point,
verify_view,
};

View File

@ -11,6 +11,11 @@
<arg name="surface" type="object" interface="wl_surface"/>
</request>
<request name="sync_window_shown">
<arg name="callback" type="new_id" interface="wl_callback"/>
<arg name="surface" type="object" interface="wl_surface"/>
</request>
<request name="sync_point">
<arg name="sequence" type="uint"/>
<arg name="surface" type="object" interface="wl_surface" allow-null="true"/>

View File

@ -43,6 +43,7 @@ enum
static guint signals[N_SIGNALS];
static struct wl_callback *effects_complete_callback;
static struct wl_callback *window_shown_callback;
static struct wl_callback *view_verification_callback;
struct _WaylandBufferClass
@ -624,6 +625,33 @@ wait_for_effects_completed (WaylandDisplay *display,
}
}
static void
window_shown (void *data,
struct wl_callback *callback,
uint32_t serial)
{
wl_callback_destroy (callback);
window_shown_callback = NULL;
}
static const struct wl_callback_listener window_shown_listener = {
window_shown,
};
void
wait_for_window_shown (WaylandDisplay *display,
struct wl_surface *surface)
{
window_shown_callback =
test_driver_sync_window_shown (display->test_driver, surface);
wl_callback_add_listener (window_shown_callback,
&window_shown_listener,
NULL);
while (window_shown_callback)
wayland_display_dispatch (display);
}
static void
view_verified (void *data,
struct wl_callback *callback,

View File

@ -111,6 +111,9 @@ const char * lookup_property_value (WaylandDisplay *display,
void wait_for_effects_completed (WaylandDisplay *display,
struct wl_surface *surface);
void wait_for_window_shown (WaylandDisplay *display,
struct wl_surface *surface);
void wait_for_view_verified (WaylandDisplay *display,
int sequence);