From 3bf5ded0d29dd9267af3d879d62631c12195f131 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Sun, 30 Mar 2025 11:40:38 +1000 Subject: [PATCH] FullscreenUI: Fix various issues - Pause menu losing key focus the first time it's opened. - Pause menu being unopenable after close when paused. - Key nav not being enabled after closing game via main UI. --- src/core/fullscreen_ui.cpp | 36 +++++++++++++++++++++++++++++++++--- src/core/fullscreen_ui.h | 1 + src/core/imgui_overlays.cpp | 3 ++- src/core/system.cpp | 2 ++ 4 files changed, 38 insertions(+), 4 deletions(-) diff --git a/src/core/fullscreen_ui.cpp b/src/core/fullscreen_ui.cpp index 2efb95f64..0f1d376f0 100644 --- a/src/core/fullscreen_ui.cpp +++ b/src/core/fullscreen_ui.cpp @@ -747,7 +747,6 @@ bool FullscreenUI::Initialize() else UpdateRunIdleState(); - ForceKeyNavEnabled(); return true; } @@ -797,6 +796,20 @@ void FullscreenUI::OnSystemStarting() }); } +void FullscreenUI::OnSystemPaused() +{ + // NOTE: Called on CPU thread. + if (!IsInitialized()) + return; + + GPUThread::RunOnThread([]() { + if (!IsInitialized()) + return; + + UpdateRunIdleState(); + }); +} + void FullscreenUI::OnSystemResumed() { // NOTE: Called on CPU thread. @@ -927,9 +940,14 @@ void FullscreenUI::ClosePauseMenu() s_state.current_main_window = MainWindowType::None; s_state.current_pause_submenu = PauseSubMenu::None; s_state.pause_menu_was_open = false; + ImGui::SetWindowFocus(nullptr); QueueResetFocus(FocusResetType::ViewChanged); UpdateRunIdleState(); FixStateIfPaused(); + + // Present frame with menu closed. We have to defer this for a frame so imgui loses keyboard focus. + if (GPUThread::IsSystemPaused()) + GPUThread::PresentCurrentFrame(); } void FullscreenUI::OpenPauseSubMenu(PauseSubMenu submenu) @@ -1122,12 +1140,23 @@ void FullscreenUI::ReturnToPreviousWindow() void FullscreenUI::ReturnToMainWindow() { ClosePauseMenu(); + if (GPUThread::HasGPUBackend()) + { s_state.current_main_window = MainWindowType::None; + ImGui::SetWindowFocus(nullptr); + } else if (ShouldOpenToGameList()) + { SwitchToGameList(); + ForceKeyNavEnabled(); + } else + { s_state.current_main_window = MainWindowType::Landing; + ForceKeyNavEnabled(); + } + UpdateRunIdleState(); FixStateIfPaused(); } @@ -1943,6 +1972,8 @@ void FullscreenUI::DrawLandingWindow() SwitchToGameList(); } + ImGui::SetItemDefaultFocus(); + if (UserThemeableHorizontalButton( "fullscreenui/cdrom.png", "fullscreenui/start-disc.svg", FSUI_CSTR("Start Game"), FSUI_CSTR("Launch a game from a file, disc, or starts the console without any disc inserted."))) @@ -6600,8 +6631,7 @@ void FullscreenUI::DrawPauseMenu() if (MenuButtonWithoutSummary(FSUI_ICONSTR(ICON_FA_PLAY, "Resume Game")) || WantsToCloseMenu()) ClosePauseMenu(); - else - ImGui::SetItemDefaultFocus(); + ImGui::SetItemDefaultFocus(); if (MenuButtonWithoutSummary(FSUI_ICONSTR(ICON_FA_FAST_FORWARD, "Toggle Fast Forward"), false)) { diff --git a/src/core/fullscreen_ui.h b/src/core/fullscreen_ui.h index 8fd01833e..ddcc20d4f 100644 --- a/src/core/fullscreen_ui.h +++ b/src/core/fullscreen_ui.h @@ -24,6 +24,7 @@ bool IsInitialized(); bool HasActiveWindow(); void CheckForConfigChanges(const GPUSettings& old_settings); void OnSystemStarting(); +void OnSystemPaused(); void OnSystemResumed(); void OnSystemDestroyed(); void OnRunningGameChanged(const std::string& path, const std::string& serial, const std::string& title, GameHash hash); diff --git a/src/core/imgui_overlays.cpp b/src/core/imgui_overlays.cpp index 4a842d1c6..6ce42eb54 100644 --- a/src/core/imgui_overlays.cpp +++ b/src/core/imgui_overlays.cpp @@ -626,7 +626,8 @@ void ImGuiManager::DrawFrameTimeOverlay(float& position_y, float scale, float ma ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f); ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0.0f, 0.0f)); ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 0.0f); - if (ImGui::Begin("##frame_times", nullptr, ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoInputs)) + if (ImGui::Begin("##frame_times", nullptr, + ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoInputs | ImGuiWindowFlags_NoFocusOnAppearing)) { ImGui::PushFont(fixed_font); diff --git a/src/core/system.cpp b/src/core/system.cpp index 8bc16268e..ed9528156 100644 --- a/src/core/system.cpp +++ b/src/core/system.cpp @@ -1591,6 +1591,8 @@ void System::PauseSystem(bool paused) if (paused) { + FullscreenUI::OnSystemPaused(); + InputManager::PauseVibration(); InputManager::UpdateHostMouseMode();