SDL: Automatically grab mouse upon entering fullscreen

Folks are confused about the new behaviour where the mouse is not
restricted to the game area in fullscreen, which is understandable.

This changes mouseIsGrabbed to use SDL directly in order to avoid
making changes to the user preference in the _inputGrabState.
Otherwise we'd either clobber the user's previous windowed mouse
grab preference, or require maintaining a second variable just to
track the original state, when we can have SDL do that for us.
This commit is contained in:
Colin Snover 2017-10-23 22:36:04 -05:00
parent f638f1453c
commit 3a95213905
2 changed files with 11 additions and 3 deletions

View file

@ -129,7 +129,7 @@ void SdlWindow::setWindowCaption(const Common::String &caption) {
void SdlWindow::toggleMouseGrab() {
#if SDL_VERSION_ATLEAST(2, 0, 0)
if (_window) {
_inputGrabState = !(SDL_GetWindowGrab(_window) == SDL_TRUE);
_inputGrabState = SDL_GetWindowGrab(_window) == SDL_FALSE;
SDL_SetWindowGrab(_window, _inputGrabState ? SDL_TRUE : SDL_FALSE);
}
#else
@ -279,7 +279,8 @@ bool SdlWindow::createOrUpdateWindow(int width, int height, uint32 flags) {
}
SDL_SetWindowFullscreen(_window, fullscreenFlags);
SDL_SetWindowGrab(_window, (flags & SDL_WINDOW_INPUT_GRABBED) ? SDL_TRUE : SDL_FALSE);
const bool shouldGrab = (flags & SDL_WINDOW_INPUT_GRABBED) | fullscreenFlags;
SDL_SetWindowGrab(_window, shouldGrab ? SDL_TRUE : SDL_FALSE);
}
if (!_window) {