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.
This commit is contained in:
Stenzek 2025-03-30 11:40:38 +10:00
parent a3e840526a
commit 3bf5ded0d2
No known key found for this signature in database
4 changed files with 38 additions and 4 deletions

View File

@ -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))
{

View File

@ -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);

View File

@ -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);

View File

@ -1591,6 +1591,8 @@ void System::PauseSystem(bool paused)
if (paused)
{
FullscreenUI::OnSystemPaused();
InputManager::PauseVibration();
InputManager::UpdateHostMouseMode();