aboutsummaryrefslogtreecommitdiff
path: root/backends
diff options
context:
space:
mode:
authorColin Snover2017-10-23 22:36:04 -0500
committerColin Snover2017-10-23 22:36:04 -0500
commit3a95213905b9ca1b8339131a66ff97df8e21ad7c (patch)
tree7c1532bfae6fbe157c44328103764a57e4f64d22 /backends
parentf638f1453c7770ec9e5ea9d3b55b5d3098e06186 (diff)
downloadscummvm-rg350-3a95213905b9ca1b8339131a66ff97df8e21ad7c.tar.gz
scummvm-rg350-3a95213905b9ca1b8339131a66ff97df8e21ad7c.tar.bz2
scummvm-rg350-3a95213905b9ca1b8339131a66ff97df8e21ad7c.zip
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.
Diffstat (limited to 'backends')
-rw-r--r--backends/platform/sdl/sdl-window.cpp5
-rw-r--r--backends/platform/sdl/sdl-window.h9
2 files changed, 11 insertions, 3 deletions
diff --git a/backends/platform/sdl/sdl-window.cpp b/backends/platform/sdl/sdl-window.cpp
index fe27d84de2..b38a97c5ef 100644
--- a/backends/platform/sdl/sdl-window.cpp
+++ b/backends/platform/sdl/sdl-window.cpp
@@ -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) {
diff --git a/backends/platform/sdl/sdl-window.h b/backends/platform/sdl/sdl-window.h
index e1a3499d19..05893c47d3 100644
--- a/backends/platform/sdl/sdl-window.h
+++ b/backends/platform/sdl/sdl-window.h
@@ -76,7 +76,14 @@ public:
*/
bool getSDLWMInformation(SDL_SysWMinfo *info) const;
- bool mouseIsGrabbed() const { return _inputGrabState; }
+ bool mouseIsGrabbed() const {
+#if SDL_VERSION_ATLEAST(2, 0, 0)
+ if (_window) {
+ return SDL_GetWindowGrab(_window) == SDL_TRUE;
+ }
+#endif
+ return _inputGrabState;
+ }
private:
bool _inputGrabState;