tests/runner: Move window shown synchronization to helper

https://gitlab.gnome.org/GNOME/mutter/merge_requests/912
This commit is contained in:
Jonas Ådahl 2019-11-01 13:37:22 +01:00
parent db91439bb0
commit 47155ed524
3 changed files with 55 additions and 45 deletions

View File

@ -342,39 +342,6 @@ test_case_check_xserver_stacking (TestCase *test,
return *error == NULL;
}
typedef struct _WaitForShownData
{
GMainLoop *loop;
MetaWindow *window;
guint shown_handler_id;
} WaitForShownData;
static void
on_window_shown (MetaWindow *window,
WaitForShownData *data)
{
g_main_loop_quit (data->loop);
}
static gboolean
test_case_wait_for_showing_before_redraw (gpointer user_data)
{
WaitForShownData *data = user_data;
if (meta_window_is_hidden (data->window))
{
data->shown_handler_id = g_signal_connect (data->window, "shown",
G_CALLBACK (on_window_shown),
data);
}
else
{
g_main_loop_quit (data->loop);
}
return FALSE;
}
static gboolean
test_case_do (TestCase *test,
int argc,
@ -533,18 +500,7 @@ test_case_do (TestCase *test,
if (!window)
return FALSE;
WaitForShownData data = {
.loop = g_main_loop_new (NULL, FALSE),
.window = window,
};
meta_later_add (META_LATER_BEFORE_REDRAW,
test_case_wait_for_showing_before_redraw,
&data,
NULL);
g_main_loop_run (data.loop);
if (data.shown_handler_id)
g_signal_handler_disconnect (window, data.shown_handler_id);
g_main_loop_unref (data.loop);
test_client_wait_for_window_shown (client, window);
}
else if (strcmp (argv[0], "hide") == 0 ||
strcmp (argv[0], "activate") == 0 ||

View File

@ -359,6 +359,57 @@ test_client_find_window (TestClient *client,
return result;
}
typedef struct _WaitForShownData
{
GMainLoop *loop;
MetaWindow *window;
guint shown_handler_id;
} WaitForShownData;
static void
on_window_shown (MetaWindow *window,
WaitForShownData *data)
{
g_main_loop_quit (data->loop);
}
static gboolean
wait_for_showing_before_redraw (gpointer user_data)
{
WaitForShownData *data = user_data;
if (meta_window_is_hidden (data->window))
{
data->shown_handler_id = g_signal_connect (data->window, "shown",
G_CALLBACK (on_window_shown),
data);
}
else
{
g_main_loop_quit (data->loop);
}
return FALSE;
}
void
test_client_wait_for_window_shown (TestClient *client,
MetaWindow *window)
{
WaitForShownData data = {
.loop = g_main_loop_new (NULL, FALSE),
.window = window,
};
meta_later_add (META_LATER_BEFORE_REDRAW,
wait_for_showing_before_redraw,
&data,
NULL);
g_main_loop_run (data.loop);
if (data.shown_handler_id)
g_signal_handler_disconnect (window, data.shown_handler_id);
g_main_loop_unref (data.loop);
}
gboolean
test_client_alarm_filter (MetaX11Display *x11_display,
XSyncAlarmNotifyEvent *event,

View File

@ -70,6 +70,9 @@ MetaWindow * test_client_find_window (TestClient *client,
const char *window_id,
GError **error);
void test_client_wait_for_window_shown (TestClient *client,
MetaWindow *window);
gboolean test_client_quit (TestClient *client,
GError **error);