-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Description
Current issues include:
- mouse grab doesn't work if window is partially off-screen (when the center of window is off screen)
- mouse warps to center when window is unfocused
- mouse sometimes warps to center of window when relative mouse is disabled
These issues are caused by clipping the cursor to the center of the window when relative mouse is enabled. Cursor clipping logic was changed so the cursor is clipped to the whole window client area in #4266, but this was silently reverted in a1fabca
.
Was this revert intentional or accidental?
Clipping the cursor to the whole client area fixes all of the mentioned issues.
The proposed fix is to remove the absurdly small clip rect logic here and have relative mode use the clipping logic in the else
block. Which will clip to the window client area by default. Applications which require the old clipping logic (for some reason) can use https://wiki.libsdl.org/SDL_SetWindowMouseRect to set the old rect.
More info as to why:
Mouse grab doesn't work if window is partially off-screen
If the ClipCursor
rect is set off screen, Windows will ignore it. By setting the ClipCursor
to the client area, windows will clip the cursor in the window area that is visible on screen (as expected).
(green = relative mode enabled, red = disabled)
video.mp4
Mouse warps to center when window is unfocused
Self-explanatory. Disabling relative mode is supposed to warp the cursor to the current SDL cursor location, but this doesn't appear to work when the window is unfocused. (Relative mode is disabled here when SDL_WINDOWEVENT_FOCUS_LOST
arrives.)
Clipping to the client area means that the SDL cursor/mouse position will be the same as the one reported by Windows, so no warp/jump will occur. Though when using SDL_HINT_MOUSE_RELATIVE_SPEED_SCALE
, this is still somewhat broken, for our specific use case, the scale is set to 1.0
.
video.mp4
Mouse sometimes warps to center of window when relative mouse is disabled
Caused by the WinAPI SetCursorPos()
sometimes not working (especially when using high pool rate - 1000Hz mouse).
This is somewhat fixed by having the clip rect be the client area as the SDL and Windows cursors will mostly stay in sync (with desync occurring if SDL_HINT_MOUSE_RELATIVE_SPEED_SCALE
is not 1.0
).
Explained in more detail here: #4339 (comment)
(Don't have video of this because it rarely happens.)
Code used for testing: https://gist.github.com/Susko3/1a82687e0e85f6cbb0fbf78e0ec110be