diff options
Diffstat (limited to 'backends/platform')
-rw-r--r-- | backends/platform/sdl/sdl-window.cpp | 18 | ||||
-rw-r--r-- | backends/platform/sdl/sdl-window.h | 13 |
2 files changed, 23 insertions, 8 deletions
diff --git a/backends/platform/sdl/sdl-window.cpp b/backends/platform/sdl/sdl-window.cpp index 75cf813638..fe27d84de2 100644 --- a/backends/platform/sdl/sdl-window.cpp +++ b/backends/platform/sdl/sdl-window.cpp @@ -135,8 +135,10 @@ void SdlWindow::toggleMouseGrab() { #else if (SDL_WM_GrabInput(SDL_GRAB_QUERY) == SDL_GRAB_OFF) { SDL_WM_GrabInput(SDL_GRAB_ON); + _inputGrabState = true; } else { SDL_WM_GrabInput(SDL_GRAB_OFF); + _inputGrabState = false; } #endif } @@ -153,14 +155,20 @@ bool SdlWindow::hasMouseFocus() const { #endif } -void SdlWindow::warpMouseInWindow(uint x, uint y) { +bool SdlWindow::warpMouseInWindow(int x, int y) { + if (hasMouseFocus()) { #if SDL_VERSION_ATLEAST(2, 0, 0) - if (_window && hasMouseFocus()) { - SDL_WarpMouseInWindow(_window, x, y); - } + if (_window) { + SDL_WarpMouseInWindow(_window, x, y); + return true; + } #else - SDL_WarpMouse(x, y); + SDL_WarpMouse(x, y); + return true; #endif + } + + return false; } void SdlWindow::iconifyWindow() { diff --git a/backends/platform/sdl/sdl-window.h b/backends/platform/sdl/sdl-window.h index d75e811f56..e1a3499d19 100644 --- a/backends/platform/sdl/sdl-window.h +++ b/backends/platform/sdl/sdl-window.h @@ -56,9 +56,12 @@ public: bool hasMouseFocus() const; /** - * Warp the mouse to the specified position in window coordinates. + * Warp the mouse to the specified position in window coordinates. The mouse + * will only be warped if the window is focused in the window manager. + * + * @returns true if the system cursor was warped. */ - void warpMouseInWindow(uint x, uint y); + bool warpMouseInWindow(int x, int y); /** * Iconifies the window. @@ -73,6 +76,11 @@ public: */ bool getSDLWMInformation(SDL_SysWMinfo *info) const; + bool mouseIsGrabbed() const { return _inputGrabState; } + +private: + bool _inputGrabState; + #if SDL_VERSION_ATLEAST(2, 0, 0) public: /** @@ -108,7 +116,6 @@ private: */ int _lastX, _lastY; - bool _inputGrabState; Common::String _windowCaption; #endif }; |