stop games with esc key or stop button

This commit is contained in:
ElBread3 2024-08-09 10:54:27 -05:00
parent ab56665d4b
commit 2c5264b927
6 changed files with 46 additions and 0 deletions

View file

@ -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()

View file

@ -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++) {

View file

@ -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();

View file

@ -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;
}

View file

@ -0,0 +1,16 @@
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include <SDL3/SDL_events.h>
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

10
src/sdl_window_manager.h Normal file
View file

@ -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