FullscreenUI: Fix opening while paused

This commit is contained in:
Stenzek 2023-12-14 16:07:57 +10:00
parent 7e1276fbac
commit 7e2afe82b5
No known key found for this signature in database
6 changed files with 73 additions and 23 deletions

View File

@ -229,6 +229,7 @@ static void ExitFullscreenAndOpenURL(const std::string_view& url);
static void CopyTextToClipboard(std::string title, const std::string_view& text);
static void DrawAboutWindow();
static void OpenAboutWindow();
static void FixStateIfPaused();
static MainWindowType s_current_main_window = MainWindowType::None;
static PauseSubMenu s_current_pause_submenu = PauseSubMenu::None;
@ -595,6 +596,9 @@ bool FullscreenUI::Initialize()
if (!System::IsValid())
SwitchToLanding();
if (!System::IsRunning())
Host::OnIdleStateChanged();
return true;
}
@ -697,6 +701,26 @@ void FullscreenUI::OpenPauseMenu()
s_current_main_window = MainWindowType::PauseMenu;
s_current_pause_submenu = PauseSubMenu::None;
QueueResetFocus();
FixStateIfPaused();
}
void FullscreenUI::FixStateIfPaused()
{
if (!System::IsValid() || System::IsRunning())
return;
// When we're paused, we won't have trickled the key up event for escape yet. Do it now.
ImGui::UpdateInputEvents(false);
Host::OnIdleStateChanged();
Host::RunOnCPUThread([]() {
if (System::IsValid())
{
// Why twice? To clear the "wants keyboard input" flag.
System::InvalidateDisplay();
System::InvalidateDisplay();
}
});
}
void FullscreenUI::ClosePauseMenu()
@ -711,6 +735,7 @@ void FullscreenUI::ClosePauseMenu()
s_current_pause_submenu = PauseSubMenu::None;
s_pause_menu_was_open = false;
QueueResetFocus();
FixStateIfPaused();
}
void FullscreenUI::OpenPauseSubMenu(PauseSubMenu submenu)
@ -837,6 +862,7 @@ void FullscreenUI::ReturnToMainWindow()
{
ClosePauseMenu();
s_current_main_window = System::IsValid() ? MainWindowType::None : MainWindowType::Landing;
FixStateIfPaused();
}
bool FullscreenUI::LoadResources()
@ -3362,12 +3388,13 @@ void FullscreenUI::DrawControllerSettingsPage()
if (mtap_enabled[mtap_port])
{
MenuHeading(TinyString::from_format(fmt::runtime(FSUI_ICONSTR(ICON_FA_PLUG, "Controller Port {}{}")), mtap_port + 1,
mtap_slot_names[mtap_slot]));
MenuHeading(TinyString::from_format(fmt::runtime(FSUI_ICONSTR(ICON_FA_PLUG, "Controller Port {}{}")),
mtap_port + 1, mtap_slot_names[mtap_slot]));
}
else
{
MenuHeading(TinyString::from_format(fmt::runtime(FSUI_ICONSTR(ICON_FA_PLUG, "Controller Port {}")), mtap_port + 1));
MenuHeading(
TinyString::from_format(fmt::runtime(FSUI_ICONSTR(ICON_FA_PLUG, "Controller Port {}")), mtap_port + 1));
}
const TinyString section = TinyString::from_format("Pad{}", global_slot + 1);
@ -3568,8 +3595,8 @@ void FullscreenUI::DrawControllerSettingsPage()
}
else
{
MenuHeading(SmallString::from_format(fmt::runtime(FSUI_ICONSTR(ICON_FA_SLIDERS_H, "Controller Port {} Settings")),
mtap_port + 1));
MenuHeading(SmallString::from_format(
fmt::runtime(FSUI_ICONSTR(ICON_FA_SLIDERS_H, "Controller Port {} Settings")), mtap_port + 1));
}
for (const SettingInfo& si : ci->settings)
@ -5083,8 +5110,8 @@ void FullscreenUI::PopulateSaveStateScreenshot(SaveStateListEntry* li, const Ext
li->preview_texture.reset();
if (ssi && !ssi->screenshot_data.empty())
{
li->preview_texture = g_gpu_device->FetchTexture(
ssi->screenshot_width, ssi->screenshot_height, 1, 1, 1, GPUTexture::Type::Texture, GPUTexture::Format::RGBA8,
li->preview_texture = g_gpu_device->FetchTexture(ssi->screenshot_width, ssi->screenshot_height, 1, 1, 1,
GPUTexture::Type::Texture, GPUTexture::Format::RGBA8,
ssi->screenshot_data.data(), sizeof(u32) * ssi->screenshot_width);
}
else
@ -6523,6 +6550,7 @@ void FullscreenUI::OpenAchievementsWindow()
s_current_main_window = MainWindowType::Achievements;
QueueResetFocus();
FixStateIfPaused();
}
bool FullscreenUI::IsAchievementsWindowOpen()
@ -6553,6 +6581,7 @@ void FullscreenUI::OpenLeaderboardsWindow()
s_current_main_window = MainWindowType::Leaderboards;
QueueResetFocus();
FixStateIfPaused();
}
bool FullscreenUI::IsLeaderboardsWindowOpen()

View File

@ -1108,6 +1108,7 @@ void System::PauseSystem(bool paused)
PlatformMisc::ResumeScreensaver();
Host::OnSystemPaused();
Host::OnIdleStateChanged();
InvalidateDisplay();
}
else
@ -1122,6 +1123,7 @@ void System::PauseSystem(bool paused)
UpdateDisplaySync();
Host::OnSystemResumed();
Host::OnIdleStateChanged();
ResetPerformanceCounters();
ResetThrottler();
@ -1285,6 +1287,7 @@ bool System::BootSystem(SystemBootParameters parameters)
Path::GetFileName(parameters.filename), error.GetDescription()));
s_state = State::Shutdown;
Host::OnSystemDestroyed();
Host::OnIdleStateChanged();
return false;
}
@ -1324,6 +1327,7 @@ bool System::BootSystem(SystemBootParameters parameters)
parameters.filename, error.GetDescription()));
s_state = State::Shutdown;
Host::OnSystemDestroyed();
Host::OnIdleStateChanged();
return false;
}
@ -1338,6 +1342,7 @@ bool System::BootSystem(SystemBootParameters parameters)
parameters.override_exe.c_str());
s_state = State::Shutdown;
Host::OnSystemDestroyed();
Host::OnIdleStateChanged();
return false;
}
@ -1351,6 +1356,7 @@ bool System::BootSystem(SystemBootParameters parameters)
s_state = State::Shutdown;
ClearRunningGame();
Host::OnSystemDestroyed();
Host::OnIdleStateChanged();
return false;
}
@ -1382,6 +1388,7 @@ bool System::BootSystem(SystemBootParameters parameters)
s_state = State::Shutdown;
ClearRunningGame();
Host::OnSystemDestroyed();
Host::OnIdleStateChanged();
return false;
}
}
@ -1392,6 +1399,7 @@ bool System::BootSystem(SystemBootParameters parameters)
s_state = State::Shutdown;
ClearRunningGame();
Host::OnSystemDestroyed();
Host::OnIdleStateChanged();
return false;
}
@ -1401,6 +1409,7 @@ bool System::BootSystem(SystemBootParameters parameters)
s_state = State::Shutdown;
ClearRunningGame();
Host::OnSystemDestroyed();
Host::OnIdleStateChanged();
return false;
}
@ -1453,6 +1462,7 @@ bool System::BootSystem(SystemBootParameters parameters)
PlatformMisc::SuspendScreensaver();
Host::OnSystemStarted();
Host::OnIdleStateChanged();
// try to load the state, if it fails, bail out
if (!parameters.save_state.empty())
@ -1692,6 +1702,7 @@ void System::DestroySystem()
s_state = State::Shutdown;
Host::OnSystemDestroyed();
Host::OnIdleStateChanged();
}
void System::ClearRunningGame()

View File

@ -518,6 +518,9 @@ void OnSystemPaused();
/// Called when the VM is resumed after being paused.
void OnSystemResumed();
/// Called when the pause state changes, or fullscreen UI opens.
void OnIdleStateChanged();
/// Called when performance metrics are updated, approximately once a second.
void OnPerformanceCountersUpdated();

View File

@ -738,6 +738,10 @@ void Host::OnSystemDestroyed()
{
}
void Host::OnIdleStateChanged()
{
}
void Host::BeginPresentFrame()
{
}

View File

@ -485,7 +485,6 @@ void EmuThread::startFullscreenUI()
// poll more frequently so we don't lose events
stopBackgroundControllerPollTimer();
startBackgroundControllerPollTimer();
wakeThread();
}
void EmuThread::stopFullscreenUI()
@ -731,7 +730,6 @@ void Host::OnSystemStarting()
void Host::OnSystemStarted()
{
g_emu_thread->wakeThread();
g_emu_thread->stopBackgroundControllerPollTimer();
emit g_emu_thread->systemStarted();
@ -751,7 +749,6 @@ void Host::OnSystemResumed()
emit g_emu_thread->systemResumed();
g_emu_thread->wakeThread();
g_emu_thread->stopBackgroundControllerPollTimer();
}
@ -760,9 +757,10 @@ void Host::OnSystemDestroyed()
g_emu_thread->resetPerformanceCounters();
g_emu_thread->startBackgroundControllerPollTimer();
emit g_emu_thread->systemDestroyed();
}
// re-wake thread when we're running fsui, otherwise it won't draw
if (g_emu_thread->isRunningFullscreenUI())
void Host::OnIdleStateChanged()
{
g_emu_thread->wakeThread();
}

View File

@ -243,6 +243,11 @@ void Host::OnSystemResumed()
//
}
void Host::OnIdleStateChanged()
{
//
}
void Host::OnPerformanceCountersUpdated()
{
//