Skip to content

fix(sdl): keep the mouse captured when the pointer leaves the window - #1251

Merged
hckrman101 merged 1 commit into
NotRexed:mainfrom
ebarrera89:fix/wayland-mouse-capture
Nov 9, 2026
Merged

hckrman101 merged 1 commit into
NotRexed:mainfrom
ebarrera89:fix/wayland-mouse-capture

Conversation

@ebarrera89

Copy link
Copy Markdown
Contributor

What

On Linux/Wayland (GNOME/Mutter), a click in the window turns the relative mouse mode on and SDL sends a
window LEAVE in the same millisecond. host/posix/display_sdl.c released the capture on that event, so the
mouse was free again after ~0 ms: with Mouse camera = Native the camera turned nothing, and the mouse buttons
bound on the Insert menu's Controls page did nothing.

The capture now stays while the window has the focus, as it does on Windows.

Why this is a port bug, not a feature

host/display.c (Windows) releases the capture on WM_KILLFOCUS alone: the capture follows the window's focus,
not the pointer. The SDL port also released on the window's leave event, and on Wayland that event is not "the
pointer went out"; it is part of turning relative mode on.

Change

host/posix/display_sdl.c: HOS_SDL_EV_MOUSE_LEAVE no longer calls mouse_capture(0); it still clears ptr_in,
so the Insert menu's hover state stays right.

Testing

  • Fedora 44, GNOME 50.6 (Wayland), GTX 1650, NVIDIA 615.78.08, built from a clone of main.
  • Before: the capture was dropped in under a millisecond of the click; the camera did not move and the
    mouse-bound buttons did not work.
  • After: the native camera and the mouse-bound buttons work. Esc and losing the focus still release
    the mouse; the Insert menu still gets a free pointer and its clicks.
  • Nothing expected to change on X11 or Windows: while the mouse is captured the pointer cannot leave the window,
    and both still release on focus loss.

Notes

I can split this into an issue first if you prefer to track it there. No game files are involved.

SDL's Wayland back end sends a window LEAVE in the same millisecond the relative mouse
mode is turned on, and the handler released the capture there: the click that captured
the mouse released it again before the first motion. On GNOME Wayland the native mouse
look turned nothing, and the mouse buttons bound on the Controls page did nothing.

Windows releases the capture on WM_KILLFOCUS alone (host/display.c): the capture goes
with the window's focus, not with the pointer. Do the same here; ptr_in still ends, so
the Insert menu's hover state is right.

Tested on Fedora 44, GNOME 50.6 Wayland, GTX 1650 (driver 615.78.08): before, the
capture was gone in under a millisecond of the click; after, the native camera and the
mouse-bound buttons work.
@hckrman101
hckrman101 merged commit 0955224 into NotRexed:main Nov 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant