tests/stacking: Add a multi-monitor stacking test

New add_monitor command for adding secondary monitors. Support setting
the workspaces-only-on-primary preference.

The stacking test tests the focus and stacking for multiple monitors
with workspaces-only-on-primary=true. The default_focus changes
previously broke this.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2748>
This commit is contained in:
Sebastian Wick 2022-12-07 23:05:29 +01:00
parent 1920d55ef9
commit 462c1115fe
3 changed files with 103 additions and 11 deletions

View File

@ -489,6 +489,7 @@ stacking_tests = [
'focus-default-window-globally-active-input',
'workspace-unmanaging-window',
'click-to-focus-and-raise',
'workspace-only-on-primary-focus',
]
foreach stacking_test: stacking_tests

View File

@ -0,0 +1,49 @@
resize_monitor primary 800 600
add_monitor secondary 800 600
num_workspaces 2
set_pref raise-on-click false
set_pref workspaces-only-on-primary true
new_client w wayland
create w/1 csd
resize w/1 100 100
show w/1
create w/2 csd
resize w/2 100 100
show w/2
wait_reconfigure
# make sure the windows are on the secondary monitor
move w/1 800 0
move w/2 900 0
wait_reconfigure
assert_stacking w/1 w/2
assert_focused w/2
assert_position w/1 800 0
assert_size w/1 100 100
assert_position w/2 900 0
assert_size w/2 100 100
# click on window w/1 and check that it gets focused but not raised
move_cursor_to 850 50
click
wait
assert_stacking w/1 w/2
assert_focused w/1
# Change to another workspace, create a window with focus, change back to the
# original workspace and make sure the focus for that workspace didn't change
activate_workspace 1
wait
assert_stacking w/1 w/2
assert_focused w/1

View File

@ -42,7 +42,7 @@ typedef struct {
GString *warning_messages;
GMainLoop *loop;
gulong x11_display_opened_handler_id;
MetaVirtualMonitor *virtual_monitor;
GHashTable *virtual_monitors;
ClutterVirtualInputDevice *pointer;
} TestCase;
@ -79,6 +79,7 @@ test_case_new (MetaContext *context)
MetaDisplay *display = meta_context_get_display (context);
MetaBackend *backend = meta_context_get_backend (context);
ClutterSeat *seat = meta_backend_get_default_seat (backend);
MetaVirtualMonitor *monitor;
if (display->x11_display)
{
@ -95,10 +96,16 @@ test_case_new (MetaContext *context)
test->context = context;
test->clients = g_hash_table_new (g_str_hash, g_str_equal);
test->loop = g_main_loop_new (NULL, FALSE);
test->virtual_monitor = meta_create_test_monitor (context, 800, 600, 60.0);
test->pointer = clutter_seat_create_virtual_device (seat,
CLUTTER_POINTER_DEVICE);
test->virtual_monitors = g_hash_table_new_full (g_str_hash,
g_str_equal,
g_free,
g_object_unref);
monitor = meta_create_test_monitor (context, 800, 600, 60.0);
g_hash_table_insert (test->virtual_monitors, g_strdup ("primary"), monitor);
return test;
}
@ -1013,22 +1020,42 @@ test_case_do (TestCase *test,
meta_backend_get_monitor_manager (backend);
MetaCrtcMode *crtc_mode;
const MetaCrtcModeInfo *crtc_mode_info;
MetaVirtualMonitor *monitor;
if (argc != 4)
BAD_COMMAND ("usage: %s <monitor-id> <width> <height>", argv[0]);
if (strcmp (argv[1], "0") != 0 &&
strcmp (argv[1], "primary") != 0)
monitor = g_hash_table_lookup (test->virtual_monitors, argv[1]);
if (!monitor)
BAD_COMMAND ("Unknown monitor %s", argv[1]);
crtc_mode = meta_virtual_monitor_get_crtc_mode (test->virtual_monitor);
crtc_mode = meta_virtual_monitor_get_crtc_mode (monitor);
crtc_mode_info = meta_crtc_mode_get_info (crtc_mode);
meta_virtual_monitor_set_mode (test->virtual_monitor,
meta_virtual_monitor_set_mode (monitor,
atoi (argv[2]),
atoi (argv[3]),
crtc_mode_info->refresh_rate);
meta_monitor_manager_reload (monitor_manager);
}
else if (strcmp (argv[0], "add_monitor") == 0)
{
MetaBackend *backend = meta_context_get_backend (test->context);
MetaMonitorManager *monitor_manager =
meta_backend_get_monitor_manager (backend);
MetaVirtualMonitor *monitor;
int width, height;
if (argc != 4)
BAD_COMMAND ("usage: %s <monitor-id> <width> <height>", argv[0]);
width = atoi (argv[2]);
height = atoi (argv[3]);
monitor = meta_create_test_monitor (test->context, width, height, 60.0);
meta_monitor_manager_reload (monitor_manager);
g_hash_table_insert (test->virtual_monitors, g_strdup (argv[1]), monitor);
}
else if (strcmp (argv[0], "num_workspaces") == 0)
{
if (argc != 2)
@ -1205,13 +1232,16 @@ test_case_do (TestCase *test,
}
else if (strcmp (argv[0], "set_pref") == 0)
{
GSettings *settings;
GSettings *wm;
GSettings *mutter;
if (argc != 3)
BAD_COMMAND("usage: %s <KEY> <VALUE>", argv[0]);
settings = g_settings_new ("org.gnome.desktop.wm.preferences");
g_assert_nonnull (settings);
wm = g_settings_new ("org.gnome.desktop.wm.preferences");
g_assert_nonnull (wm);
mutter = g_settings_new ("org.gnome.mutter");
g_assert_nonnull (mutter);
if (strcmp (argv[1], "raise-on-click") == 0)
{
@ -1223,7 +1253,19 @@ test_case_do (TestCase *test,
else
BAD_COMMAND("usage: %s %s [true|false]", argv[0], argv[1]);
g_assert_true (g_settings_set_boolean (settings, "raise-on-click", value));
g_assert_true (g_settings_set_boolean (wm, "raise-on-click", value));
}
else if (strcmp (argv[1], "workspaces-only-on-primary") == 0)
{
gboolean value;
if (g_ascii_strcasecmp (argv[2], "true") == 0)
value = TRUE;
else if (g_ascii_strcasecmp (argv[2], "false") == 0)
value = FALSE;
else
BAD_COMMAND("usage: %s %s [true|false]", argv[0], argv[1]);
g_assert_true (g_settings_set_boolean (mutter, "workspaces-only-on-primary", value));
}
else {
BAD_COMMAND("Unknown preference %s", argv[1]);
@ -1278,7 +1320,7 @@ test_case_destroy (TestCase *test,
}
g_hash_table_destroy (test->clients);
g_object_unref (test->virtual_monitor);
g_hash_table_unref (test->virtual_monitors);
g_object_unref (test->pointer);
g_free (test);