From 6a53929e310490b973595475a2ab33955b9cbf52 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Tue, 5 Sep 2023 20:12:54 +1000 Subject: [PATCH] Qt: Add option to exit Big Picture UI --- src/duckstation-qt/mainwindow.cpp | 26 +++++++++++++++++++------- src/duckstation-qt/mainwindow.h | 2 ++ src/duckstation-qt/qthost.cpp | 11 +++++++++-- src/duckstation-qt/qthost.h | 1 + 4 files changed, 31 insertions(+), 9 deletions(-) diff --git a/src/duckstation-qt/mainwindow.cpp b/src/duckstation-qt/mainwindow.cpp index 0401f8ea4..c04934a7d 100644 --- a/src/duckstation-qt/mainwindow.cpp +++ b/src/duckstation-qt/mainwindow.cpp @@ -288,9 +288,6 @@ std::optional MainWindow::acquireRenderWindow(bool recreate_window, updateWindowTitle(); updateWindowState(); - m_ui.actionStartFullscreenUI->setEnabled(false); - m_ui.actionStartFullscreenUI2->setEnabled(false); - updateDisplayWidgetCursor(); updateDisplayRelatedActions(true, render_to_main, fullscreen); m_display_widget->setFocus(); @@ -405,8 +402,6 @@ void MainWindow::releaseRenderWindow() m_ui.actionViewSystemDisplay->setEnabled(false); m_ui.actionFullscreen->setEnabled(false); - m_ui.actionStartFullscreenUI->setEnabled(true); - m_ui.actionStartFullscreenUI2->setEnabled(true); } void MainWindow::destroyDisplayWidget(bool show_game_list) @@ -1184,6 +1179,20 @@ void MainWindow::onCheatsMenuAboutToShow() populateCheatsMenu(m_ui.menuCheats); } +void MainWindow::onStartFullscreenUITriggered() +{ + if (m_display_widget) + g_emu_thread->stopFullscreenUI(); + else + g_emu_thread->startFullscreenUI(); +} + +void MainWindow::onFullscreenUIStateChange(bool running) +{ + m_ui.actionStartFullscreenUI->setText(running ? tr("Stop Big Picture Mode") : tr("Start Big Picture Mode")); + m_ui.actionStartFullscreenUI2->setText(running ? tr("Exit Big Picture") : tr("Big Picture")); +} + void MainWindow::onRemoveDiscActionTriggered() { g_emu_thread->changeDisc(QString()); @@ -1633,6 +1642,8 @@ void MainWindow::updateEmulationActions(bool starting, bool running, bool cheevo m_ui.actionStartDisc->setDisabled(starting || running); m_ui.actionStartBios->setDisabled(starting || running); m_ui.actionResumeLastState->setDisabled(starting || running || cheevos_challenge_mode); + m_ui.actionStartFullscreenUI->setDisabled(starting || running); + m_ui.actionStartFullscreenUI2->setDisabled(starting || running); m_ui.actionPowerOff->setDisabled(starting || !running); m_ui.actionPowerOffWithoutSaving->setDisabled(starting || !running); @@ -1879,6 +1890,8 @@ void MainWindow::connectSignals() connect(m_ui.menuSaveState, &QMenu::aboutToShow, this, &MainWindow::onSaveStateMenuAboutToShow); connect(m_ui.menuCheats, &QMenu::aboutToShow, this, &MainWindow::onCheatsMenuAboutToShow); connect(m_ui.actionCheats, &QAction::triggered, [this] { m_ui.menuCheats->exec(QCursor::pos()); }); + connect(m_ui.actionStartFullscreenUI, &QAction::triggered, this, &MainWindow::onStartFullscreenUITriggered); + connect(m_ui.actionStartFullscreenUI2, &QAction::triggered, this, &MainWindow::onStartFullscreenUITriggered); connect(m_ui.actionRemoveDisc, &QAction::triggered, this, &MainWindow::onRemoveDiscActionTriggered); connect(m_ui.actionAddGameDirectory, &QAction::triggered, [this]() { getSettingsDialog()->getGameListSettingsWidget()->addSearchDirectory(this); }); @@ -1945,8 +1958,6 @@ void MainWindow::connectSignals() connect(m_ui.actionGridViewRefreshCovers, &QAction::triggered, m_game_list_widget, &GameListWidget::refreshGridCovers); - connect(m_ui.actionStartFullscreenUI, &QAction::triggered, g_emu_thread, &EmuThread::startFullscreenUI); - connect(m_ui.actionStartFullscreenUI2, &QAction::triggered, g_emu_thread, &EmuThread::startFullscreenUI); connect(g_emu_thread, &EmuThread::settingsResetToDefault, this, &MainWindow::onSettingsResetToDefault, Qt::QueuedConnection); connect(g_emu_thread, &EmuThread::errorReported, this, &MainWindow::reportError, Qt::BlockingQueuedConnection); @@ -1964,6 +1975,7 @@ void MainWindow::connectSignals() connect(g_emu_thread, &EmuThread::systemResumed, this, &MainWindow::onSystemResumed); connect(g_emu_thread, &EmuThread::runningGameChanged, this, &MainWindow::onRunningGameChanged); connect(g_emu_thread, &EmuThread::mouseModeRequested, this, &MainWindow::onMouseModeRequested); + connect(g_emu_thread, &EmuThread::fullscreenUIStateChange, this, &MainWindow::onFullscreenUIStateChange); #ifdef WITH_CHEEVOS connect(g_emu_thread, &EmuThread::achievementsChallengeModeChanged, this, &MainWindow::onAchievementsChallengeModeChanged); diff --git a/src/duckstation-qt/mainwindow.h b/src/duckstation-qt/mainwindow.h index 8fd053592..80b0283fc 100644 --- a/src/duckstation-qt/mainwindow.h +++ b/src/duckstation-qt/mainwindow.h @@ -142,6 +142,8 @@ private Q_SLOTS: void onLoadStateMenuAboutToShow(); void onSaveStateMenuAboutToShow(); void onCheatsMenuAboutToShow(); + void onStartFullscreenUITriggered(); + void onFullscreenUIStateChange(bool running); void onRemoveDiscActionTriggered(); void onViewToolbarActionToggled(bool checked); void onViewLockToolbarActionToggled(bool checked); diff --git a/src/duckstation-qt/qthost.cpp b/src/duckstation-qt/qthost.cpp index 613d6cb43..100e1c532 100644 --- a/src/duckstation-qt/qthost.cpp +++ b/src/duckstation-qt/qthost.cpp @@ -475,6 +475,8 @@ void EmuThread::startFullscreenUI() return; } + emit fullscreenUIStateChange(true); + // poll more frequently so we don't lose events stopBackgroundControllerPollTimer(); startBackgroundControllerPollTimer(); @@ -488,7 +490,7 @@ void EmuThread::stopFullscreenUI() QMetaObject::invokeMethod(this, &EmuThread::stopFullscreenUI, Qt::QueuedConnection); // wait until the host display is gone - while (g_gpu_device) + while (!QtHost::IsSystemValid() && g_gpu_device) QApplication::processEvents(QEventLoop::ExcludeUserInputEvents, 1); return; @@ -497,10 +499,15 @@ void EmuThread::stopFullscreenUI() if (System::IsValid()) shutdownSystem(); + if (m_run_fullscreen_ui) + { + m_run_fullscreen_ui = false; + emit fullscreenUIStateChange(false); + } + if (!g_gpu_device) return; - m_run_fullscreen_ui = false; Host::ReleaseGPUDevice(); Host::ReleaseRenderWindow(); } diff --git a/src/duckstation-qt/qthost.h b/src/duckstation-qt/qthost.h index 7c7f8a9e7..e7a564d48 100644 --- a/src/duckstation-qt/qthost.h +++ b/src/duckstation-qt/qthost.h @@ -140,6 +140,7 @@ Q_SIGNALS: void runningGameChanged(const QString& filename, const QString& game_serial, const QString& game_title); void inputProfileLoaded(); void mouseModeRequested(bool relative, bool hide_cursor); + void fullscreenUIStateChange(bool running); void achievementsRefreshed(quint32 id, const QString& game_info_string, quint32 total, quint32 points); void achievementsChallengeModeChanged(); void cheatEnabled(quint32 index, bool enabled);