Fix mouse cursor lock regression in cooked game

This commit is contained in:
Wojtek Figat
2026-03-03 10:51:38 +01:00
parent 17b097b1a3
commit 6891256afe

View File

@@ -21,9 +21,7 @@ namespace
Nullable<Float2> Size;
bool CursorVisible = true;
CursorLockMode CursorLock = CursorLockMode::None;
#if USE_EDITOR
CursorLockMode PendingCursorLock = CursorLockMode::None;
#endif
bool LastGameViewportFocus = false;
}
@@ -140,7 +138,17 @@ void Screen::SetCursorLock(CursorLockMode mode)
}
#else
const auto win = Engine::MainWindow;
Rectangle bounds = win != nullptr ? win->GetClientBounds() : Rectangle();
Rectangle bounds = Rectangle::Empty;
if (win)
bounds.Size = win->GetClientSize();
// Don't change lock mode when window is not focused
if (mode != CursorLockMode::None && win && !win->IsFocused())
{
PendingCursorLock = mode;
return;
}
PendingCursorLock = CursorLockMode::None;
#endif
if (win)
{
@@ -224,11 +232,11 @@ void ScreenService::Update()
if (gameViewportFocus != LastGameViewportFocus)
Screen::SetCursorVisible(CursorVisible);
LastGameViewportFocus = gameViewportFocus;
#endif
// Sync pending cursor lock mode in Editor (eg. when viewport focus can change)
// Sync pending cursor lock mode
if (PendingCursorLock != CursorLockMode::None && Engine::HasGameViewportFocus())
Screen::SetCursorLock(PendingCursorLock);
#endif
}
void ScreenService::Draw()