summaryrefslogtreecommitdiff
path: root/src/tests
diff options
context:
space:
mode:
authorJonas Ã…dahl <jadahl@gmail.com>2022-01-27 18:58:56 +0100
committerMarge Bot <marge-bot@gnome.org>2022-02-09 09:04:09 +0000
commitb7f23c1bafb68af0a9b378e0ad2d362faeaca533 (patch)
tree9b1791fd097eac0212a3b3e0a625571a7bbc2571 /src/tests
parentb522e3cecdad737394a7554a7da9dc098eaf9d48 (diff)
downloadmutter-b7f23c1bafb68af0a9b378e0ad2d362faeaca533.tar.gz
tests/utils: Add helper to find a window given a title
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2262>
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/meta-test-utils.c49
-rw-r--r--src/tests/meta-test-utils.h4
2 files changed, 29 insertions, 24 deletions
diff --git a/src/tests/meta-test-utils.c b/src/tests/meta-test-utils.c
index 281dbc25b..6be07af04 100644
--- a/src/tests/meta-test-utils.c
+++ b/src/tests/meta-test-utils.c
@@ -336,46 +336,47 @@ meta_test_client_wait (MetaTestClient *client,
}
MetaWindow *
-meta_test_client_find_window (MetaTestClient *client,
- const char *window_id,
- GError **error)
+meta_find_window_from_title (MetaContext *context,
+ const char *title)
{
- MetaDisplay *display = meta_get_display ();
- GSList *windows;
- GSList *l;
- MetaWindow *result;
- char *expected_title;
-
- windows =
- meta_display_list_windows (display,
- META_LIST_INCLUDE_OVERRIDE_REDIRECT);
+ g_autoptr (GList) windows = NULL;
+ GList *l;
- expected_title = g_strdup_printf ("test/%s/%s", client->id, window_id);
-
- result = NULL;
+ windows = meta_display_list_all_windows (meta_context_get_display (context));
for (l = windows; l; l = l->next)
{
MetaWindow *window = l->data;
- if (g_strcmp0 (window->title, expected_title) == 0)
- {
- result = window;
- break;
- }
+ if (g_strcmp0 (window->title, title) == 0)
+ return window;
}
- g_slist_free (windows);
- g_free (expected_title);
+ return NULL;
+}
+
+MetaWindow *
+meta_test_client_find_window (MetaTestClient *client,
+ const char *window_id,
+ GError **error)
+{
+ MetaDisplay *display = meta_get_display ();
+ g_autofree char *expected_title = NULL;
+ MetaWindow *window;
+
+ expected_title = g_strdup_printf ("test/%s/%s", client->id, window_id);
+ window = meta_find_window_from_title (meta_display_get_context (display),
+ expected_title);
- if (result == NULL)
+ if (!window)
{
g_set_error (error,
META_TEST_CLIENT_ERROR,
META_TEST_CLIENT_ERROR_RUNTIME_ERROR,
"window %s/%s isn't known to Mutter", client->id, window_id);
+ return NULL;
}
- return result;
+ return window;
}
typedef struct _WaitForShownData
diff --git a/src/tests/meta-test-utils.h b/src/tests/meta-test-utils.h
index 2273b7811..2a42fa641 100644
--- a/src/tests/meta-test-utils.h
+++ b/src/tests/meta-test-utils.h
@@ -85,6 +85,10 @@ gboolean meta_test_client_do (MetaTestClient *client,
...) G_GNUC_NULL_TERMINATED;
META_EXPORT
+MetaWindow * meta_find_window_from_title (MetaContext *context,
+ const char *title);
+
+META_EXPORT
MetaWindow * meta_test_client_find_window (MetaTestClient *client,
const char *window_id,
GError **error);