tests: Add "set_parent_exported" command

Add a "set_parent_exported" command to test the xdg-foreign support, so
that we can add a test which uses the GDK API for exported window:

  `gdk_wayland_window_set_transient_for_exported()`

That will allow to detect if transient is applied correctly between
foreign windows and detect possible crashes such as issue !174.

Related: https://gitlab.gnome.org/GNOME/mutter/issues/174
This commit is contained in:
Olivier Fourdan 2018-07-13 16:40:31 +02:00
parent fa9e330f2c
commit 3d5784342d
2 changed files with 46 additions and 2 deletions

View File

@ -20,6 +20,7 @@
#include <gio/gunixinputstream.h>
#include <gtk/gtk.h>
#include <gdk/gdkx.h>
#include <gdk/gdkwayland.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
@ -31,6 +32,19 @@ GHashTable *windows;
static void read_next_line (GDataInputStream *in);
static void
window_export_handle_cb (GdkWindow *window,
const char *handle_str,
gpointer user_data)
{
GdkWindow *gdk_window = gtk_widget_get_window (GTK_WIDGET (user_data));
if (!gdk_wayland_window_set_transient_for_exported (gdk_window,
(gchar *) handle_str))
g_print ("Fail to set transient_for exported window handle %s", handle_str);
gdk_window_set_modal_hint (gdk_window, TRUE);
}
static GtkWidget *
lookup_window (const char *window_id)
{
@ -151,6 +165,35 @@ process_line (const char *line)
gtk_window_set_transient_for (GTK_WINDOW (window),
GTK_WINDOW (parent_window));
}
else if (strcmp (argv[0], "set_parent_exported") == 0)
{
if (argc != 3)
{
g_print ("usage: set_parent_exported <window-id> <parent-id>");
goto out;
}
GtkWidget *window = lookup_window (argv[1]);
if (!window)
{
g_print ("unknown window %s", argv[1]);
goto out;
}
GtkWidget *parent_window = lookup_window (argv[2]);
if (!parent_window)
{
g_print ("unknown parent window %s", argv[2]);
goto out;
}
GdkWindow *parent_gdk_window = gtk_widget_get_window (parent_window);
if (!gdk_wayland_window_export_handle (parent_gdk_window,
window_export_handle_cb,
window,
NULL))
g_print ("Fail to export handle for window id %s", argv[2]);
}
else if (strcmp (argv[0], "show") == 0)
{
if (argc != 2)

View File

@ -423,7 +423,8 @@ test_case_do (TestCase *test,
NULL))
return FALSE;
}
else if (strcmp (argv[0], "set_parent") == 0)
else if (strcmp (argv[0], "set_parent") == 0 ||
strcmp (argv[0], "set_parent_exported") == 0)
{
if (argc != 3)
BAD_COMMAND("usage: %s <client-id>/<window-id> <parent-window-id>",
@ -435,7 +436,7 @@ test_case_do (TestCase *test,
return FALSE;
if (!test_client_do (client, error,
"set_parent", window_id,
argv[0], window_id,
argv[2],
NULL))
return FALSE;