diff --git a/src/tests/test-runner.c b/src/tests/test-runner.c index 377b256c2..7560c957e 100644 --- a/src/tests/test-runner.c +++ b/src/tests/test-runner.c @@ -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 || diff --git a/src/tests/test-utils.c b/src/tests/test-utils.c index a42005451..c16ccf8b2 100644 --- a/src/tests/test-utils.c +++ b/src/tests/test-utils.c @@ -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, diff --git a/src/tests/test-utils.h b/src/tests/test-utils.h index e11f25353..2f1a73116 100644 --- a/src/tests/test-utils.h +++ b/src/tests/test-utils.h @@ -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);