diff options
Diffstat (limited to 'backends/platform/sdl')
-rw-r--r-- | backends/platform/sdl/sdl-window.cpp | 52 | ||||
-rw-r--r-- | backends/platform/sdl/sdl-window.h | 20 | ||||
-rw-r--r-- | backends/platform/sdl/sdl.cpp | 12 | ||||
-rw-r--r-- | backends/platform/sdl/sdl.h | 2 |
4 files changed, 70 insertions, 16 deletions
diff --git a/backends/platform/sdl/sdl-window.cpp b/backends/platform/sdl/sdl-window.cpp index 07ddc998ba..b38a97c5ef 100644 --- a/backends/platform/sdl/sdl-window.cpp +++ b/backends/platform/sdl/sdl-window.cpp @@ -129,14 +129,16 @@ 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 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() { @@ -223,6 +231,33 @@ bool SdlWindow::createOrUpdateWindow(int width, int height, uint32 flags) { const uint32 oldNonUpdateableFlags = _lastFlags & ~updateableFlagsMask; const uint32 newNonUpdateableFlags = flags & ~updateableFlagsMask; + const uint32 fullscreenFlags = flags & fullscreenMask; + + // This is terrible, but there is no way in SDL to get information on the + // maximum bounds of a window with decoration, and SDL is too dumb to make + // sure the window's surface doesn't grow beyond the display bounds, which + // can easily happen with 3x scalers. There is a function in SDL to get the + // window decoration size, but it only exists starting in SDL 2.0.5, which + // is a buggy release on some platforms so we can't safely use 2.0.5+ + // features since some users replace the SDL dynamic library with 2.0.4, and + // the documentation says it only works on X11 anyway, which means it is + // basically worthless. So we'll just try to keep things closeish to the + // maximum for now. + SDL_DisplayMode displayMode; + SDL_GetDesktopDisplayMode(0, &displayMode); + if (!fullscreenFlags) { + displayMode.w -= 20; + displayMode.h -= 30; + } + + if (width > displayMode.w) { + width = displayMode.w; + } + + if (height > displayMode.h) { + height = displayMode.h; + } + if (!_window || oldNonUpdateableFlags != newNonUpdateableFlags) { destroyWindow(); _window = SDL_CreateWindow(_windowCaption.c_str(), _lastX, @@ -231,8 +266,6 @@ bool SdlWindow::createOrUpdateWindow(int width, int height, uint32 flags) { setupIcon(); } } else { - const uint32 fullscreenFlags = flags & fullscreenMask; - if (fullscreenFlags) { SDL_DisplayMode fullscreenMode; fullscreenMode.w = width; @@ -246,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 d75e811f56..05893c47d3 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,18 @@ public: */ bool getSDLWMInformation(SDL_SysWMinfo *info) const; + bool mouseIsGrabbed() const { +#if SDL_VERSION_ATLEAST(2, 0, 0) + if (_window) { + return SDL_GetWindowGrab(_window) == SDL_TRUE; + } +#endif + return _inputGrabState; + } + +private: + bool _inputGrabState; + #if SDL_VERSION_ATLEAST(2, 0, 0) public: /** @@ -108,7 +123,6 @@ private: */ int _lastX, _lastY; - bool _inputGrabState; Common::String _windowCaption; #endif }; diff --git a/backends/platform/sdl/sdl.cpp b/backends/platform/sdl/sdl.cpp index bbd5c89f80..f44d87666a 100644 --- a/backends/platform/sdl/sdl.cpp +++ b/backends/platform/sdl/sdl.cpp @@ -297,20 +297,28 @@ void OSystem_SDL::initBackend() { dynamic_cast<SdlGraphicsManager *>(_graphicsManager)->activateManager(); } -#if defined(USE_TASKBAR) void OSystem_SDL::engineInit() { +#if SDL_VERSION_ATLEAST(2, 0, 0) + dynamic_cast<SdlGraphicsManager *>(_graphicsManager)->unlockWindowSize(); +#endif +#ifdef USE_TASKBAR // Add the started engine to the list of recent tasks _taskbarManager->addRecent(ConfMan.getActiveDomainName(), ConfMan.get("description")); // Set the overlay icon the current running engine _taskbarManager->setOverlayIcon(ConfMan.getActiveDomainName(), ConfMan.get("description")); +#endif } void OSystem_SDL::engineDone() { +#if SDL_VERSION_ATLEAST(2, 0, 0) + dynamic_cast<SdlGraphicsManager *>(_graphicsManager)->unlockWindowSize(); +#endif +#ifdef USE_TASKBAR // Remove overlay icon _taskbarManager->setOverlayIcon("", ""); -} #endif +} void OSystem_SDL::initSDL() { // Check if SDL has not been initialized diff --git a/backends/platform/sdl/sdl.h b/backends/platform/sdl/sdl.h index bc4292be0b..61513fa65f 100644 --- a/backends/platform/sdl/sdl.h +++ b/backends/platform/sdl/sdl.h @@ -59,10 +59,8 @@ public: // Override functions from ModularBackend and OSystem virtual void initBackend(); -#if defined(USE_TASKBAR) virtual void engineInit(); virtual void engineDone(); -#endif virtual void quit(); virtual void fatalError(); |