tests/stacking: Add a test for sloppy focus

Tests that
* the window under the cursor has focus
* focus_default_window won't move the focus away from a previously
  focused window even if the cursor is somewhere else

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3258>
This commit is contained in:
Sebastian Wick 2023-02-07 23:07:02 +01:00 committed by Marge Bot
parent de2daf65b4
commit ac33792db4
3 changed files with 86 additions and 0 deletions

View File

@ -708,6 +708,7 @@ stacking_tests = [
'overview-focus', 'overview-focus',
'suspend-state-timeout', 'suspend-state-timeout',
'cloned-windows', 'cloned-windows',
'sloppy-focus',
] ]
foreach stacking_test: stacking_tests foreach stacking_test: stacking_tests

View File

@ -0,0 +1,62 @@
resize_monitor default 800 600
set_pref focus-mode sloppy
set_pref focus-change-on-pointer-rest false
move_cursor_to 150 50
wait
new_client w wayland
create w/0 csd
resize w/0 100 100
show w/0
create w/1 csd
resize w/1 100 100
show w/1
wait_reconfigure
move w/0 0 0
move w/1 100 0
wait_reconfigure
assert_stacking w/0 w/1
assert_focused w/1
assert_position w/0 0 0
assert_size w/0 100 100
assert_position w/1 100 0
assert_size w/1 100 100
move_cursor_to 50 50
assert_stacking w/0 w/1
assert_focused w/0
move_cursor_to 150 50
assert_stacking w/0 w/1
assert_focused w/1
focus_default_window
assert_stacking w/0 w/1
assert_focused w/1
local_activate w/0
focus_default_window
assert_stacking w/1 w/0
assert_focused w/0
move_cursor_to 50 50
assert_stacking w/1 w/0
assert_focused w/0
move_cursor_to 150 50
assert_stacking w/1 w/0
assert_focused w/1

View File

@ -1301,6 +1301,21 @@ test_case_do (TestCase *test,
g_assert_true (g_settings_set_boolean (wm, "raise-on-click", value)); g_assert_true (g_settings_set_boolean (wm, "raise-on-click", value));
} }
else if (strcmp (argv[1], "focus-mode") == 0)
{
GDesktopFocusMode mode;
if (g_ascii_strcasecmp (argv[2], "click") == 0)
mode = G_DESKTOP_FOCUS_MODE_CLICK;
else if (g_ascii_strcasecmp (argv[2], "sloppy") == 0)
mode = G_DESKTOP_FOCUS_MODE_SLOPPY;
else if (g_ascii_strcasecmp (argv[2], "mouse") == 0)
mode = G_DESKTOP_FOCUS_MODE_MOUSE;
else
BAD_COMMAND("usage: %s %s [click|sloppy|mouse]", argv[0], argv[1]);
g_assert_true (g_settings_set_enum (wm, "focus-mode", mode));
}
else if (strcmp (argv[1], "workspaces-only-on-primary") == 0) else if (strcmp (argv[1], "workspaces-only-on-primary") == 0)
{ {
gboolean value; gboolean value;
@ -1309,6 +1324,14 @@ test_case_do (TestCase *test,
g_assert_true (g_settings_set_boolean (mutter, "workspaces-only-on-primary", value)); g_assert_true (g_settings_set_boolean (mutter, "workspaces-only-on-primary", value));
} }
else if (strcmp (argv[1], "focus-change-on-pointer-rest") == 0)
{
gboolean value;
if (!str_to_bool (argv[2], &value))
BAD_COMMAND("usage: %s %s [true|false]", argv[0], argv[1]);
g_assert_true (g_settings_set_boolean (mutter, "focus-change-on-pointer-rest", value));
}
else { else {
BAD_COMMAND("Unknown preference %s", argv[1]); BAD_COMMAND("Unknown preference %s", argv[1]);
} }