Qt: Fix shutdown and save state in fullscreen UI

This commit is contained in:
Connor McLaughlin 2022-10-03 22:18:49 +10:00
parent 74452eede3
commit 106addf5a8
6 changed files with 19 additions and 17 deletions

View file

@ -473,7 +473,7 @@ void RequestResizeHostDisplay(s32 width, s32 height);
void RequestExit(bool save_state_if_running); void RequestExit(bool save_state_if_running);
/// Requests shut down of the current virtual machine. /// Requests shut down of the current virtual machine.
void RequestSystemShutdown(bool allow_confirm, bool allow_save_state); void RequestSystemShutdown(bool allow_confirm, bool save_state);
/// Returns true if the hosting application is currently fullscreen. /// Returns true if the hosting application is currently fullscreen.
bool IsFullscreen(); bool IsFullscreen();

View file

@ -975,12 +975,12 @@ void Host::RequestExit(bool save_state_if_running)
s_running.store(false, std::memory_order_release); s_running.store(false, std::memory_order_release);
} }
void Host::RequestSystemShutdown(bool allow_confirm, bool allow_save_state) void Host::RequestSystemShutdown(bool allow_confirm, bool save_state)
{ {
// TODO: Confirm // TODO: Confirm
if (System::IsValid()) if (System::IsValid())
{ {
Host::RunOnCPUThread([allow_save_state]() { System::ShutdownSystem(allow_save_state); }); Host::RunOnCPUThread([save_state]() { System::ShutdownSystem(save_state); });
} }
} }

View file

@ -1793,8 +1793,10 @@ void MainWindow::connectSignals()
connect(m_ui.actionRemoveDisc, &QAction::triggered, this, &MainWindow::onRemoveDiscActionTriggered); connect(m_ui.actionRemoveDisc, &QAction::triggered, this, &MainWindow::onRemoveDiscActionTriggered);
connect(m_ui.actionAddGameDirectory, &QAction::triggered, connect(m_ui.actionAddGameDirectory, &QAction::triggered,
[this]() { getSettingsDialog()->getGameListSettingsWidget()->addSearchDirectory(this); }); [this]() { getSettingsDialog()->getGameListSettingsWidget()->addSearchDirectory(this); });
connect(m_ui.actionPowerOff, &QAction::triggered, this, [this]() { requestShutdown(true, true); }); connect(m_ui.actionPowerOff, &QAction::triggered, this,
connect(m_ui.actionPowerOffWithoutSaving, &QAction::triggered, this, [this]() { requestShutdown(false, false); }); [this]() { requestShutdown(true, true, g_settings.save_state_on_exit); });
connect(m_ui.actionPowerOffWithoutSaving, &QAction::triggered, this,
[this]() { requestShutdown(false, false, false); });
connect(m_ui.actionReset, &QAction::triggered, g_emu_thread, &EmuThread::resetSystem); connect(m_ui.actionReset, &QAction::triggered, g_emu_thread, &EmuThread::resetSystem);
connect(m_ui.actionPause, &QAction::toggled, [](bool active) { g_emu_thread->setSystemPaused(active); }); connect(m_ui.actionPause, &QAction::toggled, [](bool active) { g_emu_thread->setSystemPaused(active); });
connect(m_ui.actionScreenshot, &QAction::triggered, g_emu_thread, &EmuThread::saveScreenshot); connect(m_ui.actionScreenshot, &QAction::triggered, g_emu_thread, &EmuThread::saveScreenshot);
@ -2367,14 +2369,14 @@ void MainWindow::runOnUIThread(const std::function<void()>& func)
} }
bool MainWindow::requestShutdown(bool allow_confirm /* = true */, bool allow_save_to_state /* = true */, bool MainWindow::requestShutdown(bool allow_confirm /* = true */, bool allow_save_to_state /* = true */,
bool block_until_done /* = false */) bool save_state /* = true */, bool block_until_done /* = false */)
{ {
if (!s_system_valid) if (!s_system_valid)
return true; return true;
// If we don't have a serial, we can't save state. // If we don't have a serial, we can't save state.
allow_save_to_state &= !m_current_game_code.empty(); allow_save_to_state &= !m_current_game_code.empty();
bool save_state = allow_save_to_state && g_settings.save_state_on_exit; save_state &= allow_save_to_state;
// Only confirm on UI thread because we need to display a msgbox. // Only confirm on UI thread because we need to display a msgbox.
if (!m_is_closing && allow_confirm && g_settings.confim_power_off) if (!m_is_closing && allow_confirm && g_settings.confim_power_off)
@ -2387,7 +2389,7 @@ bool MainWindow::requestShutdown(bool allow_confirm /* = true */, bool allow_sav
msgbox.setText("Are you sure you want to shut down the virtual machine?"); msgbox.setText("Are you sure you want to shut down the virtual machine?");
QCheckBox* save_cb = new QCheckBox(tr("Save State For Resume"), &msgbox); QCheckBox* save_cb = new QCheckBox(tr("Save State For Resume"), &msgbox);
save_cb->setChecked(save_state); save_cb->setChecked(allow_save_to_state && save_state);
save_cb->setEnabled(allow_save_to_state); save_cb->setEnabled(allow_save_to_state);
msgbox.setCheckBox(save_cb); msgbox.setCheckBox(save_cb);
msgbox.addButton(QMessageBox::Yes); msgbox.addButton(QMessageBox::Yes);
@ -2434,7 +2436,7 @@ bool MainWindow::requestShutdown(bool allow_confirm /* = true */, bool allow_sav
void MainWindow::requestExit(bool allow_save_to_state /* = true */) void MainWindow::requestExit(bool allow_save_to_state /* = true */)
{ {
// this is block, because otherwise closeEvent() will also prompt // this is block, because otherwise closeEvent() will also prompt
if (!requestShutdown(true, allow_save_to_state, true)) if (!requestShutdown(true, allow_save_to_state, g_settings.save_state_on_exit))
return; return;
// We could use close here, but if we're not visible (e.g. quitting from fullscreen), closing the window // We could use close here, but if we're not visible (e.g. quitting from fullscreen), closing the window

View file

@ -94,7 +94,7 @@ public Q_SLOTS:
void cancelGameListRefresh(); void cancelGameListRefresh();
void runOnUIThread(const std::function<void()>& func); void runOnUIThread(const std::function<void()>& func);
bool requestShutdown(bool allow_confirm = true, bool allow_save_to_state = true, bool block_until_done = false); bool requestShutdown(bool allow_confirm = true, bool allow_save_to_state = true, bool save_state = true, bool block_until_done = false);
void requestExit(bool allow_save_to_state = true); void requestExit(bool allow_save_to_state = true);
void checkForSettingChanges(); void checkForSettingChanges();

View file

@ -1714,13 +1714,13 @@ void QtHost::QueueSettingsSave()
s_settings_save_timer->start(SETTINGS_SAVE_DELAY); s_settings_save_timer->start(SETTINGS_SAVE_DELAY);
} }
void Host::RequestSystemShutdown(bool allow_confirm, bool allow_save_state) void Host::RequestSystemShutdown(bool allow_confirm, bool save_state)
{ {
if (!System::IsValid()) if (!System::IsValid())
return; return;
QMetaObject::invokeMethod(g_main_window, "requestShutdown", Qt::QueuedConnection, Q_ARG(bool, allow_confirm), QMetaObject::invokeMethod(g_main_window, "requestShutdown", Qt::QueuedConnection, Q_ARG(bool, allow_confirm),
Q_ARG(bool, allow_save_state), Q_ARG(bool, false)); Q_ARG(bool, true), Q_ARG(bool, save_state), Q_ARG(bool, false));
} }
void Host::RequestExit(bool save_state_if_running) void Host::RequestExit(bool save_state_if_running)

View file

@ -3909,7 +3909,7 @@ void FullscreenUI::DrawPauseMenu(MainWindowType type)
case PauseSubMenu::None: case PauseSubMenu::None:
{ {
// NOTE: Menu close must come first, because otherwise VM destruction options will race. // NOTE: Menu close must come first, because otherwise VM destruction options will race.
const bool can_load_or_save_state = System::IsValid(); const bool has_game = System::IsValid() && !System::GetRunningCode().empty();
if (ActiveButton(ICON_FA_PLAY " Resume Game", false) || WantsToCloseMenu()) if (ActiveButton(ICON_FA_PLAY " Resume Game", false) || WantsToCloseMenu())
ClosePauseMenu(); ClosePauseMenu();
@ -3920,13 +3920,13 @@ void FullscreenUI::DrawPauseMenu(MainWindowType type)
DoToggleFastForward(); DoToggleFastForward();
} }
if (ActiveButton(ICON_FA_UNDO " Load State", false, can_load_or_save_state)) if (ActiveButton(ICON_FA_UNDO " Load State", false, has_game))
{ {
if (OpenSaveStateSelector(true)) if (OpenSaveStateSelector(true))
s_current_main_window = MainWindowType::None; s_current_main_window = MainWindowType::None;
} }
if (ActiveButton(ICON_FA_DOWNLOAD " Save State", false, can_load_or_save_state)) if (ActiveButton(ICON_FA_DOWNLOAD " Save State", false, has_game))
{ {
if (OpenSaveStateSelector(false)) if (OpenSaveStateSelector(false))
s_current_main_window = MainWindowType::None; s_current_main_window = MainWindowType::None;
@ -3945,7 +3945,7 @@ void FullscreenUI::DrawPauseMenu(MainWindowType type)
DoToggleAnalogMode(); DoToggleAnalogMode();
} }
if (ActiveButton(ICON_FA_WRENCH " Game Properties", false, !System::GetRunningCode().empty())) if (ActiveButton(ICON_FA_WRENCH " Game Properties", false, has_game))
{ {
SwitchToGameSettings(); SwitchToGameSettings();
} }
@ -3984,7 +3984,7 @@ void FullscreenUI::DrawPauseMenu(MainWindowType type)
if (ActiveButton(ICON_FA_POWER_OFF " Close Game", false)) if (ActiveButton(ICON_FA_POWER_OFF " Close Game", false))
{ {
// skip submenu when we can't save anyway // skip submenu when we can't save anyway
if (!can_load_or_save_state) if (!has_game)
DoShutdown(false); DoShutdown(false);
else else
OpenPauseSubMenu(PauseSubMenu::Exit); OpenPauseSubMenu(PauseSubMenu::Exit);