diff options
| -rw-r--r-- | src/yuzu/main.cpp | 63 | ||||
| -rw-r--r-- | src/yuzu/main.h | 7 | ||||
| -rw-r--r-- | src/yuzu/util/overlay_dialog.cpp | 9 | ||||
| -rw-r--r-- | src/yuzu/util/overlay_dialog.h | 1 |
4 files changed, 65 insertions, 15 deletions
diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index 7ec613669..6121711e0 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp | |||
| @@ -1550,8 +1550,9 @@ void GMainWindow::AllowOSSleep() { | |||
| 1550 | 1550 | ||
| 1551 | bool GMainWindow::LoadROM(const QString& filename, u64 program_id, std::size_t program_index) { | 1551 | bool GMainWindow::LoadROM(const QString& filename, u64 program_id, std::size_t program_index) { |
| 1552 | // Shutdown previous session if the emu thread is still active... | 1552 | // Shutdown previous session if the emu thread is still active... |
| 1553 | if (emu_thread != nullptr) | 1553 | if (emu_thread != nullptr) { |
| 1554 | ShutdownGame(); | 1554 | ShutdownGame(); |
| 1555 | } | ||
| 1555 | 1556 | ||
| 1556 | if (!render_window->InitRenderTarget()) { | 1557 | if (!render_window->InitRenderTarget()) { |
| 1557 | return false; | 1558 | return false; |
| @@ -1784,7 +1785,7 @@ void GMainWindow::BootGame(const QString& filename, u64 program_id, std::size_t | |||
| 1784 | OnStartGame(); | 1785 | OnStartGame(); |
| 1785 | } | 1786 | } |
| 1786 | 1787 | ||
| 1787 | void GMainWindow::ShutdownGame() { | 1788 | void GMainWindow::OnShutdownBegin() { |
| 1788 | if (!emulation_running) { | 1789 | if (!emulation_running) { |
| 1789 | return; | 1790 | return; |
| 1790 | } | 1791 | } |
| @@ -1807,13 +1808,40 @@ void GMainWindow::ShutdownGame() { | |||
| 1807 | 1808 | ||
| 1808 | emit EmulationStopping(); | 1809 | emit EmulationStopping(); |
| 1809 | 1810 | ||
| 1810 | // Wait for emulation thread to complete and delete it | 1811 | shutdown_timer.setSingleShot(true); |
| 1811 | if (system->DebuggerEnabled() || !emu_thread->wait(5000)) { | 1812 | shutdown_timer.start(system->DebuggerEnabled() ? 0 : 5000); |
| 1813 | connect(&shutdown_timer, &QTimer::timeout, this, &GMainWindow::OnEmulationStopTimeExpired); | ||
| 1814 | connect(emu_thread.get(), &QThread::finished, this, &GMainWindow::OnEmulationStopped); | ||
| 1815 | |||
| 1816 | // Disable everything to prevent anything from being triggered here | ||
| 1817 | ui->action_Pause->setEnabled(false); | ||
| 1818 | ui->action_Restart->setEnabled(false); | ||
| 1819 | ui->action_Stop->setEnabled(false); | ||
| 1820 | } | ||
| 1821 | |||
| 1822 | void GMainWindow::OnShutdownBeginDialog() { | ||
| 1823 | shutdown_dialog = new OverlayDialog(this, *system, QString{}, tr("Closing software..."), | ||
| 1824 | QString{}, QString{}, Qt::AlignHCenter | Qt::AlignVCenter); | ||
| 1825 | shutdown_dialog->open(); | ||
| 1826 | } | ||
| 1827 | |||
| 1828 | void GMainWindow::OnEmulationStopTimeExpired() { | ||
| 1829 | if (emu_thread) { | ||
| 1812 | emu_thread->ForceStop(); | 1830 | emu_thread->ForceStop(); |
| 1813 | emu_thread->wait(); | ||
| 1814 | } | 1831 | } |
| 1832 | } | ||
| 1833 | |||
| 1834 | void GMainWindow::OnEmulationStopped() { | ||
| 1835 | shutdown_timer.stop(); | ||
| 1836 | emu_thread->disconnect(); | ||
| 1837 | emu_thread->wait(); | ||
| 1815 | emu_thread = nullptr; | 1838 | emu_thread = nullptr; |
| 1816 | 1839 | ||
| 1840 | if (shutdown_dialog) { | ||
| 1841 | shutdown_dialog->deleteLater(); | ||
| 1842 | shutdown_dialog = nullptr; | ||
| 1843 | } | ||
| 1844 | |||
| 1817 | emulation_running = false; | 1845 | emulation_running = false; |
| 1818 | 1846 | ||
| 1819 | discord_rpc->Update(); | 1847 | discord_rpc->Update(); |
| @@ -1859,6 +1887,20 @@ void GMainWindow::ShutdownGame() { | |||
| 1859 | 1887 | ||
| 1860 | // When closing the game, destroy the GLWindow to clear the context after the game is closed | 1888 | // When closing the game, destroy the GLWindow to clear the context after the game is closed |
| 1861 | render_window->ReleaseRenderTarget(); | 1889 | render_window->ReleaseRenderTarget(); |
| 1890 | |||
| 1891 | Settings::RestoreGlobalState(system->IsPoweredOn()); | ||
| 1892 | system->HIDCore().ReloadInputDevices(); | ||
| 1893 | UpdateStatusButtons(); | ||
| 1894 | } | ||
| 1895 | |||
| 1896 | void GMainWindow::ShutdownGame() { | ||
| 1897 | if (!emulation_running) { | ||
| 1898 | return; | ||
| 1899 | } | ||
| 1900 | |||
| 1901 | OnShutdownBegin(); | ||
| 1902 | OnEmulationStopTimeExpired(); | ||
| 1903 | OnEmulationStopped(); | ||
| 1862 | } | 1904 | } |
| 1863 | 1905 | ||
| 1864 | void GMainWindow::StoreRecentFile(const QString& filename) { | 1906 | void GMainWindow::StoreRecentFile(const QString& filename) { |
| @@ -2961,11 +3003,8 @@ void GMainWindow::OnStopGame() { | |||
| 2961 | return; | 3003 | return; |
| 2962 | } | 3004 | } |
| 2963 | 3005 | ||
| 2964 | ShutdownGame(); | 3006 | OnShutdownBegin(); |
| 2965 | 3007 | OnShutdownBeginDialog(); | |
| 2966 | Settings::RestoreGlobalState(system->IsPoweredOn()); | ||
| 2967 | system->HIDCore().ReloadInputDevices(); | ||
| 2968 | UpdateStatusButtons(); | ||
| 2969 | } | 3008 | } |
| 2970 | 3009 | ||
| 2971 | void GMainWindow::OnLoadComplete() { | 3010 | void GMainWindow::OnLoadComplete() { |
| @@ -4052,10 +4091,6 @@ void GMainWindow::closeEvent(QCloseEvent* event) { | |||
| 4052 | // Shutdown session if the emu thread is active... | 4091 | // Shutdown session if the emu thread is active... |
| 4053 | if (emu_thread != nullptr) { | 4092 | if (emu_thread != nullptr) { |
| 4054 | ShutdownGame(); | 4093 | ShutdownGame(); |
| 4055 | |||
| 4056 | Settings::RestoreGlobalState(system->IsPoweredOn()); | ||
| 4057 | system->HIDCore().ReloadInputDevices(); | ||
| 4058 | UpdateStatusButtons(); | ||
| 4059 | } | 4094 | } |
| 4060 | 4095 | ||
| 4061 | render_window->close(); | 4096 | render_window->close(); |
diff --git a/src/yuzu/main.h b/src/yuzu/main.h index 5b84c7a00..95220b063 100644 --- a/src/yuzu/main.h +++ b/src/yuzu/main.h | |||
| @@ -29,6 +29,7 @@ class GImageInfo; | |||
| 29 | class GRenderWindow; | 29 | class GRenderWindow; |
| 30 | class LoadingScreen; | 30 | class LoadingScreen; |
| 31 | class MicroProfileDialog; | 31 | class MicroProfileDialog; |
| 32 | class OverlayDialog; | ||
| 32 | class ProfilerWidget; | 33 | class ProfilerWidget; |
| 33 | class ControllerDialog; | 34 | class ControllerDialog; |
| 34 | class QLabel; | 35 | class QLabel; |
| @@ -335,6 +336,10 @@ private slots: | |||
| 335 | void OnReinitializeKeys(ReinitializeKeyBehavior behavior); | 336 | void OnReinitializeKeys(ReinitializeKeyBehavior behavior); |
| 336 | void OnLanguageChanged(const QString& locale); | 337 | void OnLanguageChanged(const QString& locale); |
| 337 | void OnMouseActivity(); | 338 | void OnMouseActivity(); |
| 339 | void OnShutdownBegin(); | ||
| 340 | void OnShutdownBeginDialog(); | ||
| 341 | void OnEmulationStopped(); | ||
| 342 | void OnEmulationStopTimeExpired(); | ||
| 338 | 343 | ||
| 339 | private: | 344 | private: |
| 340 | QString GetGameListErrorRemoving(InstalledEntryType type) const; | 345 | QString GetGameListErrorRemoving(InstalledEntryType type) const; |
| @@ -384,6 +389,8 @@ private: | |||
| 384 | GRenderWindow* render_window; | 389 | GRenderWindow* render_window; |
| 385 | GameList* game_list; | 390 | GameList* game_list; |
| 386 | LoadingScreen* loading_screen; | 391 | LoadingScreen* loading_screen; |
| 392 | QTimer shutdown_timer; | ||
| 393 | OverlayDialog* shutdown_dialog{}; | ||
| 387 | 394 | ||
| 388 | GameListPlaceholder* game_list_placeholder; | 395 | GameListPlaceholder* game_list_placeholder; |
| 389 | 396 | ||
diff --git a/src/yuzu/util/overlay_dialog.cpp b/src/yuzu/util/overlay_dialog.cpp index 3fa3d0afb..796f5bf41 100644 --- a/src/yuzu/util/overlay_dialog.cpp +++ b/src/yuzu/util/overlay_dialog.cpp | |||
| @@ -3,6 +3,7 @@ | |||
| 3 | 3 | ||
| 4 | #include <QKeyEvent> | 4 | #include <QKeyEvent> |
| 5 | #include <QScreen> | 5 | #include <QScreen> |
| 6 | #include <QWindow> | ||
| 6 | 7 | ||
| 7 | #include "core/core.h" | 8 | #include "core/core.h" |
| 8 | #include "core/hid/hid_types.h" | 9 | #include "core/hid/hid_types.h" |
| @@ -162,7 +163,7 @@ void OverlayDialog::MoveAndResizeWindow() { | |||
| 162 | const auto height = static_cast<float>(parentWidget()->height()); | 163 | const auto height = static_cast<float>(parentWidget()->height()); |
| 163 | 164 | ||
| 164 | // High DPI | 165 | // High DPI |
| 165 | const float dpi_scale = qApp->screenAt(pos)->logicalDotsPerInch() / 96.0f; | 166 | const float dpi_scale = parentWidget()->windowHandle()->screen()->logicalDotsPerInch() / 96.0f; |
| 166 | 167 | ||
| 167 | const auto title_text_font_size = BASE_TITLE_FONT_SIZE * (height / BASE_HEIGHT) / dpi_scale; | 168 | const auto title_text_font_size = BASE_TITLE_FONT_SIZE * (height / BASE_HEIGHT) / dpi_scale; |
| 168 | const auto body_text_font_size = | 169 | const auto body_text_font_size = |
| @@ -259,3 +260,9 @@ void OverlayDialog::InputThread() { | |||
| 259 | std::this_thread::sleep_for(std::chrono::milliseconds(50)); | 260 | std::this_thread::sleep_for(std::chrono::milliseconds(50)); |
| 260 | } | 261 | } |
| 261 | } | 262 | } |
| 263 | |||
| 264 | void OverlayDialog::keyPressEvent(QKeyEvent* e) { | ||
| 265 | if (!ui->buttonsDialog->isHidden() || e->key() != Qt::Key_Escape) { | ||
| 266 | QDialog::keyPressEvent(e); | ||
| 267 | } | ||
| 268 | } | ||
diff --git a/src/yuzu/util/overlay_dialog.h b/src/yuzu/util/overlay_dialog.h index 39c44393c..872283d61 100644 --- a/src/yuzu/util/overlay_dialog.h +++ b/src/yuzu/util/overlay_dialog.h | |||
| @@ -94,6 +94,7 @@ private: | |||
| 94 | 94 | ||
| 95 | /// The thread where input is being polled and processed. | 95 | /// The thread where input is being polled and processed. |
| 96 | void InputThread(); | 96 | void InputThread(); |
| 97 | void keyPressEvent(QKeyEvent* e) override; | ||
| 97 | 98 | ||
| 98 | std::unique_ptr<Ui::OverlayDialog> ui; | 99 | std::unique_ptr<Ui::OverlayDialog> ui; |
| 99 | 100 | ||