wayland: Add mouse pointer warp support

The pointer confinement protocol does allow attempted warping the pointer via a hint, provided that the pointer is locked at the time of the request, and the requested coordinates fall within the bounds of the window.

Toggle the pointer locked state and request the pointer warp when the required protocol is available. This is similar to what XWayland does internally.
This commit is contained in:
Frank Praznik
2024-05-01 12:57:39 -04:00
parent 22016228ca
commit 3a6d9c59f4
6 changed files with 108 additions and 52 deletions

View File

@@ -2995,19 +2995,21 @@ extern "C" {
#define SDL_HINT_VIDEO_WAYLAND_ALLOW_LIBDECOR "SDL_VIDEO_WAYLAND_ALLOW_LIBDECOR"
/**
* Enable or disable mouse pointer warp emulation, needed by some older games.
* Enable or disable hidden mouse pointer warp emulation, needed by some older games.
*
* Wayland does not directly support warping the mouse. When this hint is set,
* any SDL will emulate mouse warps using relative mouse mode. This is
* required for some older games (such as Source engine games), which warp the
* mouse to the centre of the screen rather than using relative mouse motion.
* Note that relative mouse mode may have different mouse acceleration
* behaviour than pointer warps.
* Wayland requires the pointer confinement protocol to warp the mouse, but
* that is just a hint that the compositor is free to ignore, and warping the
* the pointer to or from regions outside of the focused window is prohibited.
* When this hint is set and the pointer is hidden, SDL will emulate mouse warps
* using relative mouse mode. This is required for some older games (such as Source
* engine games), which warp the mouse to the centre of the screen rather than using
* relative mouse motion. Note that relative mouse mode may have different mouse
* acceleration behaviour than pointer warps.
*
* The variable can be set to the following values:
*
* - "0": All mouse warps fail, as mouse warping is not available under
* wayland.
* - "0": Attempts to warp the mouse will be made, if the appropriate protocol
* is available.
* - "1": Some mouse warps will be emulated by forcing relative mouse mode.
*
* If not set, this is automatically enabled unless an application uses