diff --git a/rpcs3/Emu/System.cpp b/rpcs3/Emu/System.cpp index 4bfd1da740..b5967324b8 100644 --- a/rpcs3/Emu/System.cpp +++ b/rpcs3/Emu/System.cpp @@ -1752,19 +1752,6 @@ void Emulator::Stop(bool restart) vm::close(); - if (do_exit) - { - GetCallbacks().exit(true); - } - else - { - if (full_stop) - { - GetCallbacks().exit(false); - } - Init(); - } - #ifdef LLVM_AVAILABLE extern void jit_finalize(); jit_finalize(); @@ -1793,6 +1780,24 @@ void Emulator::Stop(bool restart) { enable_display_sleep(); } + + if (do_exit || full_stop) + { + if (Quit(do_exit)) + { + return; + } + } + + Init(); +} + +bool Emulator::Quit(bool force_quit) const +{ + Emu.SetForceBoot(false); + Emu.Stop(); + + return GetCallbacks().exit(force_quit); } std::string Emulator::GetFormattedTitle(double fps) const diff --git a/rpcs3/Emu/System.h b/rpcs3/Emu/System.h index 15bbc75c70..ec2b6aaed0 100644 --- a/rpcs3/Emu/System.h +++ b/rpcs3/Emu/System.h @@ -37,7 +37,7 @@ struct EmuCallbacks std::function on_resume; std::function on_stop; std::function on_ready; - std::function exit; // (force_quit) close RPCS3 + std::function exit; // (force_quit) close RPCS3 std::function handle_taskbar_progress; // (type, value) type: 0 for reset, 1 for increment, 2 for set_limit std::function init_kb_handler; std::function init_mouse_handler; @@ -202,6 +202,7 @@ public: void Resume(); void Stop(bool restart = false); void Restart() { Stop(true); } + bool Quit(bool force_quit) const; bool IsRunning() const { return m_state == system_state::running; } bool IsPaused() const { return m_state == system_state::paused; } diff --git a/rpcs3/headless_application.cpp b/rpcs3/headless_application.cpp index e19dc53403..3cb0dabefa 100644 --- a/rpcs3/headless_application.cpp +++ b/rpcs3/headless_application.cpp @@ -39,12 +39,15 @@ void headless_application::InitializeCallbacks() { EmuCallbacks callbacks = CreateCallbacks(); - callbacks.exit = [this](bool force_quit) + callbacks.exit = [this](bool force_quit) -> bool { if (force_quit) { quit(); + return true; } + + return false; }; callbacks.call_after = [=, this](std::function func) { diff --git a/rpcs3/rpcs3qt/gui_application.cpp b/rpcs3/rpcs3qt/gui_application.cpp index 599e578418..654c501900 100644 --- a/rpcs3/rpcs3qt/gui_application.cpp +++ b/rpcs3/rpcs3qt/gui_application.cpp @@ -267,13 +267,21 @@ void gui_application::InitializeCallbacks() { EmuCallbacks callbacks = CreateCallbacks(); - callbacks.exit = [this](bool force_quit) + callbacks.exit = [this](bool force_quit) -> bool { // Close rpcs3 if closed in no-gui mode if (force_quit || !m_main_window) { + if (m_main_window) + { + // Close main window in order to save its window state + m_main_window->close(); + } quit(); + return true; } + + return false; }; callbacks.call_after = [this](std::function func) { diff --git a/rpcs3/rpcs3qt/main_window.cpp b/rpcs3/rpcs3qt/main_window.cpp index 93115c602c..4266004f2a 100644 --- a/rpcs3/rpcs3qt/main_window.cpp +++ b/rpcs3/rpcs3qt/main_window.cpp @@ -72,6 +72,7 @@ main_window::main_window(std::shared_ptr gui_settings, std::shared main_window::~main_window() { + SaveWindowState(); delete ui; } @@ -2140,7 +2141,7 @@ void main_window::mouseDoubleClickEvent(QMouseEvent *event) } } -/** Override the Qt close event to have the emulator stop and the application die. May add a warning dialog in future. +/** Override the Qt close event to have the emulator stop and the application die. */ void main_window::closeEvent(QCloseEvent* closeEvent) { @@ -2150,13 +2151,8 @@ void main_window::closeEvent(QCloseEvent* closeEvent) return; } - // Cleanly stop the emulator. - Emu.Stop(); - - SaveWindowState(); - - // It's possible to have other windows open, like games. So, force the application to die. - QApplication::quit(); + // Cleanly stop and quit the emulator. + Emu.Quit(true); } /**