Skip to content

Commit

Permalink
test: Fix mouse focus test on X11
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Kontrabant committed Oct 10, 2024
1 parent e4b1a9f commit 40ff6a2
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions test/testautomation_mouse.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
Expand All @@ -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 */
Expand Down

0 comments on commit 40ff6a2

Please sign in to comment.