Mouse grab off leaves mouse confined to single monitor (Windows)
Description
When mouse grab is released, the mouse cursor re-appears, but if you have multiple screens it will not be able to leave the current screen until you can focus a window besides RetroArch.
This is likely specific to the Windows mouse ungrab implementation.
Expected behavior
When mouse grab is released, the released mouse cursor should be able to move to another screen.
Actual behavior
When mouse grab is released, the mouse cursor is confined to the current screen while RetroArch remains focused.
Steps to reproduce the bug
- Start portable Retroarch, default settings, should be windowed.
- Launch any game.
- Press F11 to grab the mouse.
- Press F11 to ungrab the mouse.
- Observe that the mouse cursor is now trapped inside the current monitor screen.
Bisect Results
Has been present since at least 1.16.0. but probably goes much further back. (I would guess 1.9.1 based on the blame of the relevant code.)
Version/Commit
- RetroArch: 1.17.0 (64-bit Windows)
Environment information
- OS: Windows 10
- Drivers: (should be default)
- Menu: ozone
- Video: d3d11
- Input: dinput
I strongly suspect the problem is here: https://github.com/libretro/RetroArch/blob/7d57f00be35bc2fecab09eb415e71efc0e26450e/gfx/common/win32_common.c#L1963
If turning mouse grab off, ClipCursor should use a NULL parameter. Instead of releasing the mouse, we've used GetDesktopWindow() to create a confinement to the current screen.
Created a PR to fix this: #16488
Identifying a problem, debugging it and then submitting a PR to fix it. You get a gold star for good citizenship. :)