From 2c5264b92756b121d92a7d91015e9c36a6a2e7d6 Mon Sep 17 00:00:00 2001 From: ElBread3 <92335081+ElBread3@users.noreply.github.com> Date: Fri, 9 Aug 2024 10:54:27 -0500 Subject: [PATCH] stop games with esc key or stop button --- CMakeLists.txt | 6 ++++++ src/qt_gui/main_window.cpp | 7 +++++++ src/qt_gui/main_window.h | 1 + src/sdl_window.cpp | 6 ++++++ src/sdl_window_manager.cpp | 16 ++++++++++++++++ src/sdl_window_manager.h | 10 ++++++++++ 6 files changed, 46 insertions(+) create mode 100644 src/sdl_window_manager.cpp create mode 100644 src/sdl_window_manager.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 4df3db2bf..403a2429f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -517,6 +517,8 @@ set(EMULATOR src/emulator.cpp src/emulator.h src/sdl_window.h src/sdl_window.cpp + src/sdl_window_manager.cpp + src/sdl_window_manager.h ) # The above is shared in SDL and Qt version (TODO share them all) @@ -563,6 +565,8 @@ if (ENABLE_QT_GUI) ${VIDEO_CORE} ${EMULATOR} src/images/shadPS4.icns + src/sdl_window_manager.cpp + src/sdl_window_manager.h ) else() add_executable(shadps4 @@ -578,6 +582,8 @@ else() src/emulator.h src/sdl_window.h src/sdl_window.cpp + src/sdl_window_manager.cpp + src/sdl_window_manager.h ) endif() diff --git a/src/qt_gui/main_window.cpp b/src/qt_gui/main_window.cpp index 646433ee7..796b7a946 100644 --- a/src/qt_gui/main_window.cpp +++ b/src/qt_gui/main_window.cpp @@ -15,6 +15,7 @@ #include "core/loader.h" #include "game_install_dialog.h" #include "main_window.h" +#include "sdl_window_manager.h" MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); @@ -185,6 +186,8 @@ void MainWindow::CreateConnects() { connect(m_game_list_frame.get(), &QTableWidget::cellDoubleClicked, this, &MainWindow::StartGame); + connect(ui->stopButton, &QPushButton::clicked, this, &MainWindow::StopGame); + connect(ui->setIconSizeTinyAct, &QAction::triggered, this, [this]() { if (isTableList) { m_game_list_frame->icon_size = @@ -392,6 +395,10 @@ void MainWindow::StartGame() { } } +void MainWindow::StopGame() { + Frontend::QuitAllSDLWindows(); +} + void MainWindow::SearchGameTable(const QString& text) { if (isTableList) { for (int row = 0; row < m_game_list_frame->rowCount(); row++) { diff --git a/src/qt_gui/main_window.h b/src/qt_gui/main_window.h index 39a5d049e..51c67efb6 100644 --- a/src/qt_gui/main_window.h +++ b/src/qt_gui/main_window.h @@ -40,6 +40,7 @@ public: void InstallDragDropPkg(std::filesystem::path file, int pkgNum, int nPkg); void InstallDirectory(); void StartGame(); + void StopGame(); private Q_SLOTS: void ConfigureGuiFromSettings(); diff --git a/src/sdl_window.cpp b/src/sdl_window.cpp index 0d25cd3ff..bd982be35 100644 --- a/src/sdl_window.cpp +++ b/src/sdl_window.cpp @@ -11,6 +11,7 @@ #include "core/libraries/pad/pad.h" #include "input/controller.h" #include "sdl_window.h" +#include "sdl_window_manager.h" #include "video_core/renderdoc.h" #ifdef __APPLE__ @@ -265,6 +266,11 @@ void WindowSDL::onKeyPress(const SDL_Event* event) { case SDLK_SPACE: button = OrbisPadButtonDataOffset::ORBIS_PAD_BUTTON_TOUCH_PAD; break; + case SDLK_ESCAPE: + if (event->type == SDL_EVENT_KEY_UP) { + Frontend::QuitAllSDLWindows(); + } + break; default: break; } diff --git a/src/sdl_window_manager.cpp b/src/sdl_window_manager.cpp new file mode 100644 index 000000000..62ad950cc --- /dev/null +++ b/src/sdl_window_manager.cpp @@ -0,0 +1,16 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#include + +namespace Frontend { + +void QuitAllSDLWindows() { + // In the future, windows would have to be stored accessibly outside functions to close just a + // specific window + SDL_Event quitEvent; + quitEvent.type = SDL_EVENT_QUIT; + SDL_PushEvent(&quitEvent); +} + +} // namespace Frontend \ No newline at end of file diff --git a/src/sdl_window_manager.h b/src/sdl_window_manager.h new file mode 100644 index 000000000..bceb71ada --- /dev/null +++ b/src/sdl_window_manager.h @@ -0,0 +1,10 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +namespace Frontend { + +void QuitAllSDLWindows(); + +} // namespace Frontend \ No newline at end of file