From 40ff6a27857a98026f6767590e85958d68843b26 Mon Sep 17 00:00:00 2001 From: Frank Praznik Date: Wed, 9 Oct 2024 16:15:20 -0400 Subject: [PATCH] test: Fix mouse focus test on X11 X11 seems to need a slight delay before warping the pointer to ensure that the window is actually fully visible on the desktop, or the pointer enter event may not be sent. This also disables the warp focus test on XWayland, as warping the mouse cursor when outside the window on any Wayland desktop usually just doesn't work. --- test/testautomation_mouse.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/test/testautomation_mouse.c b/test/testautomation_mouse.c index 057822a571..9efa630fab 100644 --- a/test/testautomation_mouse.c +++ b/test/testautomation_mouse.c @@ -512,7 +512,8 @@ static int SDLCALL mouse_getMouseFocus(void *arg) float x, y; SDL_Window *window; SDL_Window *focusWindow; - const bool video_driver_is_wayland = !SDL_strcmp(SDL_GetCurrentVideoDriver(), "wayland"); + const char *xdg_session = SDL_getenv("XDG_SESSION_TYPE"); + const bool env_is_wayland = !SDL_strcmp(xdg_session ? xdg_session : "", "wayland"); /* Get focus - focus non-deterministic */ focusWindow = SDL_GetMouseFocus(); @@ -523,9 +524,12 @@ static int SDLCALL mouse_getMouseFocus(void *arg) if (!window) { return TEST_ABORTED; } + + /* Delay a brief period to allow the window to actually appear on the desktop. */ + SDL_Delay(100); - /* Wayland explicitly disallows warping the mouse pointer, so this test must be skipped. */ - if (!video_driver_is_wayland) { + /* Warping the pointer when it is outside the window on a Wayland desktop usually doesn't work, so this test will be skipped. */ + if (!env_is_wayland) { /* Mouse to random position inside window */ x = (float)SDLTest_RandomIntegerInRange(1, w - 1); y = (float)SDLTest_RandomIntegerInRange(1, h - 1); @@ -549,7 +553,7 @@ static int SDLCALL mouse_getMouseFocus(void *arg) SDL_WarpMouseInWindow(window, x, y); SDLTest_AssertPass("SDL_WarpMouseInWindow(...,%.f,%.f)", x, y); } else { - SDLTest_Log("Skipping mouse warp focus tests: Wayland does not support warping the mouse pointer"); + SDLTest_Log("Skipping mouse warp focus tests: warping the mouse pointer when outside the window is unreliable on Wayland/XWayland"); } /* Clean up test window */