From 6891256afefcab9a17b4f4dd1fb402a9ddbe68b3 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Tue, 3 Mar 2026 10:51:38 +0100 Subject: [PATCH] Fix mouse cursor lock regression in cooked game --- Source/Engine/Engine/Screen.cpp | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/Source/Engine/Engine/Screen.cpp b/Source/Engine/Engine/Screen.cpp index 39c6dc865..4faaeb685 100644 --- a/Source/Engine/Engine/Screen.cpp +++ b/Source/Engine/Engine/Screen.cpp @@ -21,9 +21,7 @@ namespace Nullable 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()