Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cursor not constrained to window when using SDL_SetRelativeMouseMode and another game is running #7890

Open
Susko3 opened this issue Jun 29, 2023 · 4 comments · May be fixed by #11237
Open
Assignees
Milestone

Comments

@Susko3
Copy link
Contributor

Susko3 commented Jun 29, 2023

/**
* Set relative mouse mode.
*
* While the mouse is in relative mode, the cursor is hidden, the mouse
* position is constrained to the window, and SDL will report continuous
* relative mouse motion even if the mouse is at the edge of the window.
*
* This function will flush any pending mouse motion.
*
* \param enabled SDL_TRUE to enable relative mode, SDL_FALSE to disable.
* \returns 0 on success or a negative error code on failure; call
* SDL_GetError() for more information.
*
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_GetRelativeMouseMode
*/
extern DECLSPEC int SDLCALL SDL_SetRelativeMouseMode(SDL_bool enabled);

the mouse position is constrained to the window

When using relative mode, I would expect the cursor to be constrained to the window. But it appears this is not the case on windows.

Repro steps

  1. Run testwm.exe, I'm using testwm.exe --resizable --geometry 1150x900 --title testwm.exe to have a bigger window for convenience
  2. Press Ctrl+R to enable relative mode
  3. Move the mouse around, and notice that it can exit out of the window
    • note that MOUSE_FOCUS window flag will remain set, even if the mouse is outside the window (unlike when not using relative mode)
2023-06-29.21-09-41.remuxed.mp4

I'm using PowerToys Mouse pointer Crosshairs to show where the actual OS mouse position is. Maybe this can aid debugging of this issue.

Environment

  • latest SDL3 main: 4d23eaf
  • Windows 11 22H2 (OS Build 22621.1848)
  • World of Tanks running in the background

Edit: the bug seems to only happen if World of Tanks is open in the background. Could this invalidate the issue?

@Susko3 Susko3 changed the title Cursor not constrained to window when using SDL_SetRelativeMouseMode on Windows Cursor not constrained to window when using SDL_SetRelativeMouseMode and another game is running Jun 29, 2023
@slouken
Copy link
Collaborator

slouken commented Jun 29, 2023

Interesting. It doesn't happen here on the same code and version of OS. It's very possible that World of Tanks is resetting the Windows cursor clip rectangle while in the background. That would be a bug in the game, and would definitely interfere with this test.

@expikr
Copy link
Contributor

expikr commented Jul 1, 2023

Try running this autoit script in the background instead of World of Tank and see if it recreates the behavior:

opt('guioneventmode',1)
guicreate('')
guisetstate()
guisetonevent(-3,quit)
while sleep(1000)
    dllcall('user32.dll','bool','ClipCursor','struct*',Null)
wend
func quit()
     exit
endfunc

A workaround would be to run GetClipCursor on every WM_MOUSMOVE and send ClipCursor if it's not the right clipping range. In relative mode you should never receive WM_MOUSEMOVE because the cursor is constrained to one pixel.

@Susko3
Copy link
Contributor Author

Susko3 commented Jul 1, 2023

It's very possible that World of Tanks is resetting the Windows cursor clip rectangle while in the background. That would be a bug in the game, and would definitely interfere with this test.

This is exactly it.

I've run the C# equivalent of @expikr's while(true) ClipCursor(NULL); code and it behaves the same as having World of Tanks in the background. I'll be sure to report the bug to the devs.

SDL will update the ClipCursor every 3 seconds, so it can recover if an external app (accidentally) sets it to the wrong value once.

@Susko3
Copy link
Contributor Author

Susko3 commented Jul 1, 2023

I'm eager to close this issue as "not SDL's problem", but I think adding logging would be helpful for pointing the blame onto other running programs.

Something like "ClipCursor rect changed unexpectedly (is another program changing it?). Resetting to expected location,"

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 a pull request may close this issue.

3 participants