Auto-lock the cursor in single display borderless windowed scenarios

This commit is contained in:
Cameron Gutman 2025-10-22 23:13:03 -05:00
commit 9bcc6291be
2 changed files with 11 additions and 2 deletions

View file

@ -269,8 +269,10 @@ void SdlInputHandler::updatePointerRegionLock()
// toggled it themselves using the keyboard shortcut. If that's the case, they
// have full control over it and we don't touch it anymore.
if (!m_PointerRegionLockToggledByUser) {
// Lock the pointer in true full-screen mode and leave it unlocked in other modes
m_PointerRegionLockActive = (SDL_GetWindowFlags(m_Window) & SDL_WINDOW_FULLSCREEN_DESKTOP) == SDL_WINDOW_FULLSCREEN;
// Lock the pointer in true full-screen mode or in any fullscreen mode when only a single monitor is present
Uint32 fullscreenFlags = SDL_GetWindowFlags(m_Window) & SDL_WINDOW_FULLSCREEN_DESKTOP;
m_PointerRegionLockActive = (fullscreenFlags == SDL_WINDOW_FULLSCREEN) ||
(fullscreenFlags != 0 && SDL_GetNumVideoDisplays() == 1);
}
// If region lock is enabled, grab the cursor so it can't accidentally leave our window.

View file

@ -2351,6 +2351,13 @@ void Session::execInternal()
case SDL_FINGERUP:
m_InputHandler->handleTouchFingerEvent(&event.tfinger);
break;
case SDL_DISPLAYEVENT:
switch (event.display.event) {
case SDL_DISPLAYEVENT_CONNECTED:
case SDL_DISPLAYEVENT_DISCONNECTED:
m_InputHandler->updatePointerRegionLock();
break;
}
}
}