diff --git a/pcsx2-qt/EmuThread.cpp b/pcsx2-qt/EmuThread.cpp index 6351088606..bd814ad752 100644 --- a/pcsx2-qt/EmuThread.cpp +++ b/pcsx2-qt/EmuThread.cpp @@ -905,6 +905,41 @@ void Host::RunOnCPUThread(std::function function, bool block /* = false Q_ARG(const std::function&, std::move(function))); } +void Host::RefreshGameListAsync(bool invalidate_cache) +{ + QMetaObject::invokeMethod(g_main_window, "refreshGameList", Qt::QueuedConnection, + Q_ARG(bool, invalidate_cache)); +} + +void Host::CancelGameListRefresh() +{ + QMetaObject::invokeMethod(g_main_window, "cancelGameListRefresh", Qt::BlockingQueuedConnection); +} + +void Host::RequestExit(bool save_state_if_running) +{ + if (VMManager::HasValidVM()) + g_emu_thread->shutdownVM(save_state_if_running); + + QMetaObject::invokeMethod(g_main_window, "requestExit", Qt::QueuedConnection); +} + +void Host::RequestVMShutdown(bool save_state) +{ + if (VMManager::HasValidVM()) + g_emu_thread->shutdownVM(save_state); +} + +bool Host::IsFullscreen() +{ + return g_emu_thread->isFullscreen(); +} + +void Host::SetFullscreen(bool enabled) +{ + g_emu_thread->setFullscreen(enabled); +} + alignas(16) static SysMtgsThread s_mtgs_thread; SysMtgsThread& GetMTGS() diff --git a/pcsx2-qt/EmuThread.h b/pcsx2-qt/EmuThread.h index 334ed521cd..9e3b4fe7f6 100644 --- a/pcsx2-qt/EmuThread.h +++ b/pcsx2-qt/EmuThread.h @@ -42,6 +42,7 @@ public: static void stop(); __fi QEventLoop* getEventLoop() const { return m_event_loop; } + __fi bool isFullscreen() const { return m_is_fullscreen; } bool isOnEmuThread() const; diff --git a/pcsx2-qt/GameList/GameListWidget.cpp b/pcsx2-qt/GameList/GameListWidget.cpp index de9f676da4..0ef24abb1b 100644 --- a/pcsx2-qt/GameList/GameListWidget.cpp +++ b/pcsx2-qt/GameList/GameListWidget.cpp @@ -163,13 +163,7 @@ bool GameListWidget::getShowGridCoverTitles() const void GameListWidget::refresh(bool invalidate_cache) { - if (m_refresh_thread) - { - m_refresh_thread->cancel(); - m_refresh_thread->wait(); - QApplication::processEvents(QEventLoop::ExcludeUserInputEvents); - pxAssertRel(!m_refresh_thread, "Game list thread should be unreferenced by now"); - } + cancelRefresh(); m_refresh_thread = new GameListRefreshThread(invalidate_cache); connect(m_refresh_thread, &GameListRefreshThread::refreshProgress, this, &GameListWidget::onRefreshProgress, @@ -179,6 +173,17 @@ void GameListWidget::refresh(bool invalidate_cache) m_refresh_thread->start(); } +void GameListWidget::cancelRefresh() +{ + if (!m_refresh_thread) + return; + + m_refresh_thread->cancel(); + m_refresh_thread->wait(); + QApplication::processEvents(QEventLoop::ExcludeUserInputEvents); + pxAssertRel(!m_refresh_thread, "Game list thread should be unreferenced by now"); +} + void GameListWidget::onRefreshProgress(const QString& status, int current, int total) { // switch away from the placeholder while we scan, in case we find anything diff --git a/pcsx2-qt/GameList/GameListWidget.h b/pcsx2-qt/GameList/GameListWidget.h index 9ca5f116d9..8fd915c4a3 100644 --- a/pcsx2-qt/GameList/GameListWidget.h +++ b/pcsx2-qt/GameList/GameListWidget.h @@ -54,6 +54,7 @@ public: void initialize(); void refresh(bool invalidate_cache); + void cancelRefresh(); bool isShowingGameList() const; bool isShowingGameGrid() const; diff --git a/pcsx2-qt/MainWindow.cpp b/pcsx2-qt/MainWindow.cpp index e8b0c99261..53bab7b29c 100644 --- a/pcsx2-qt/MainWindow.cpp +++ b/pcsx2-qt/MainWindow.cpp @@ -731,6 +731,11 @@ void MainWindow::refreshGameList(bool invalidate_cache) m_game_list_widget->refresh(invalidate_cache); } +void MainWindow::cancelGameListRefresh() +{ + m_game_list_widget->cancelRefresh(); +} + void MainWindow::invalidateSaveStateCache() { m_save_states_invalidated = true; diff --git a/pcsx2-qt/MainWindow.h b/pcsx2-qt/MainWindow.h index 889f0bf8d1..aceaa1692d 100644 --- a/pcsx2-qt/MainWindow.h +++ b/pcsx2-qt/MainWindow.h @@ -87,6 +87,7 @@ public: public Q_SLOTS: void checkForUpdates(bool display_message); void refreshGameList(bool invalidate_cache); + void cancelGameListRefresh(); void invalidateSaveStateCache(); void reportError(const QString& title, const QString& message); void runOnUIThread(const std::function& func); diff --git a/pcsx2/HostSettings.cpp b/pcsx2/HostSettings.cpp index ace38bf77b..d83b5b5c01 100644 --- a/pcsx2/HostSettings.cpp +++ b/pcsx2/HostSettings.cpp @@ -116,6 +116,11 @@ std::vector Host::GetStringListSetting(const char* section, const c return s_layered_settings_interface.GetStringList(section, key); } +SettingsInterface* Host::Internal::GetBaseSettingsLayer() +{ + return s_layered_settings_interface.GetLayer(LayeredSettingsInterface::LAYER_BASE); +} + void Host::Internal::SetBaseSettingsLayer(SettingsInterface* sif) { pxAssertRel(s_layered_settings_interface.GetLayer(LayeredSettingsInterface::LAYER_BASE) == nullptr, "Base layer has not been set"); diff --git a/pcsx2/HostSettings.h b/pcsx2/HostSettings.h index 9350e58098..90b3b81bdc 100644 --- a/pcsx2/HostSettings.h +++ b/pcsx2/HostSettings.h @@ -47,6 +47,9 @@ namespace Host namespace Internal { + /// Retrieves the base settings layer. Must call with lock held. + SettingsInterface* GetBaseSettingsLayer(); + /// Sets the base settings layer. Should be called by the host at initialization time. void SetBaseSettingsLayer(SettingsInterface* sif); diff --git a/pcsx2/VMManager.h b/pcsx2/VMManager.h index 556fd16a37..df29926d54 100644 --- a/pcsx2/VMManager.h +++ b/pcsx2/VMManager.h @@ -211,4 +211,23 @@ namespace Host /// Safely executes a function on the VM thread. void RunOnCPUThread(std::function function, bool block = false); + + /// Asynchronously starts refreshing the game list. + void RefreshGameListAsync(bool invalidate_cache); + + /// Cancels game list refresh, if there is one in progress. + void CancelGameListRefresh(); + + /// Requests shut down and exit of the hosting application. This may not actually exit, + /// if the user cancels the shutdown confirmation. + void RequestExit(bool save_state_if_running); + + /// Requests shut down of the current virtual machine. + void RequestVMShutdown(bool save_state); + + /// Returns true if the hosting application is currently fullscreen. + bool IsFullscreen(); + + /// Alters fullscreen state of hosting application. + void SetFullscreen(bool enabled); }