Skip to content

Commit

Permalink
stop games with esc key or stop button
Browse files Browse the repository at this point in the history
  • Loading branch information
ElBread3 committed Aug 9, 2024
1 parent ab56665 commit 2c5264b
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 0 deletions.
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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()

Expand Down
7 changes: 7 additions & 0 deletions src/qt_gui/main_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -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++) {
Expand Down
1 change: 1 addition & 0 deletions src/qt_gui/main_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class MainWindow : public QMainWindow {
void InstallDragDropPkg(std::filesystem::path file, int pkgNum, int nPkg);
void InstallDirectory();
void StartGame();
void StopGame();

private Q_SLOTS:
void ConfigureGuiFromSettings();
Expand Down
6 changes: 6 additions & 0 deletions src/sdl_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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__
Expand Down Expand Up @@ -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;
}
Expand Down
16 changes: 16 additions & 0 deletions src/sdl_window_manager.cpp
Original file line number Diff line number Diff line change
@@ -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 changes: 10 additions & 0 deletions src/sdl_window_manager.h
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 2c5264b

Please sign in to comment.