diff --git a/src/qt_gui/control_settings.cpp b/src/qt_gui/control_settings.cpp index 89abcc7f4..fbeedc802 100644 --- a/src/qt_gui/control_settings.cpp +++ b/src/qt_gui/control_settings.cpp @@ -8,13 +8,13 @@ #include "common/logging/log.h" #include "common/path_util.h" #include "control_settings.h" -#include "sdl_window.h" +#include "input/input_handler.h" #include "ui_control_settings.h" ControlSettings::ControlSettings(std::shared_ptr game_info_get, bool isGameRunning, - QWidget* parent) + std::string GameRunningSerial, QWidget* parent) : QDialog(parent), m_game_info(game_info_get), GameRunning(isGameRunning), - ui(new Ui::ControlSettings) { + RunningGameSerial(GameRunningSerial), ui(new Ui::ControlSettings) { ui->setupUi(this); @@ -24,9 +24,6 @@ ControlSettings::ControlSettings(std::shared_ptr game_info_get, b CheckGamePad(); } else { SDL_SetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, "1"); - SDL_Event pauseGame{}; - pauseGame.type = SDL_EVENT_TOGGLE_PAUSE; - SDL_PushEvent(&pauseGame); } AddBoxItems(); @@ -327,6 +324,11 @@ void ControlSettings::SaveControllerConfig(bool CloseOnSave) { ui->BSlider->value()); Config::save(Common::FS::GetUserPath(Common::FS::PathType::UserDir) / "config.toml"); + if (GameRunning) { + Config::GetUseUnifiedInputConfig() ? Input::ParseInputConfig("default") + : Input::ParseInputConfig(RunningGameSerial); + } + if (CloseOnSave) QWidget::close(); } @@ -929,9 +931,6 @@ void ControlSettings::Cleanup() { SDL_Quit(); } else { SDL_SetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, "0"); - SDL_Event resumeGame{}; - resumeGame.type = SDL_EVENT_TOGGLE_PAUSE; - SDL_PushEvent(&resumeGame); } } diff --git a/src/qt_gui/control_settings.h b/src/qt_gui/control_settings.h index e47a79936..00ac202fd 100644 --- a/src/qt_gui/control_settings.h +++ b/src/qt_gui/control_settings.h @@ -15,7 +15,7 @@ class ControlSettings : public QDialog { Q_OBJECT public: explicit ControlSettings(std::shared_ptr game_info_get, bool GameRunning, - QWidget* parent = nullptr); + std::string GameRunningSerial, QWidget* parent = nullptr); ~ControlSettings(); signals: @@ -50,6 +50,7 @@ private: QList AxisList; QSet pressedButtons; + std::string RunningGameSerial; bool GameRunning; bool L2Pressed = false; bool R2Pressed = false; diff --git a/src/qt_gui/kbm_gui.cpp b/src/qt_gui/kbm_gui.cpp index 10c08e391..a67c02ff8 100644 --- a/src/qt_gui/kbm_gui.cpp +++ b/src/qt_gui/kbm_gui.cpp @@ -10,29 +10,23 @@ #include #include "common/path_util.h" +#include "input/input_handler.h" #include "kbm_config_dialog.h" #include "kbm_gui.h" #include "kbm_help_dialog.h" -#include "sdl_window.h" #include "ui_kbm_gui.h" HelpDialog* HelpWindow; KBMSettings::KBMSettings(std::shared_ptr game_info_get, bool isGameRunning, - QWidget* parent) + std::string GameRunningSerial, QWidget* parent) : QDialog(parent), m_game_info(game_info_get), GameRunning(isGameRunning), - ui(new Ui::KBMSettings) { + RunningGameSerial(GameRunningSerial), ui(new Ui::KBMSettings) { ui->setupUi(this); ui->PerGameCheckBox->setChecked(!Config::GetUseUnifiedInputConfig()); ui->TextEditorButton->setFocus(); this->setFocusPolicy(Qt::StrongFocus); - if (GameRunning) { - SDL_Event pauseGame{}; - pauseGame.type = SDL_EVENT_TOGGLE_PAUSE; - SDL_PushEvent(&pauseGame); - } - ui->MouseJoystickBox->addItem("none"); ui->MouseJoystickBox->addItem("right"); ui->MouseJoystickBox->addItem("left"); @@ -340,6 +334,11 @@ QString(tr("Cannot bind any unique input more than once. Duplicate inputs mapped Config::SetUseUnifiedInputConfig(!ui->PerGameCheckBox->isChecked()); Config::save(Common::FS::GetUserPath(Common::FS::PathType::UserDir) / "config.toml"); + if (GameRunning) { + Config::GetUseUnifiedInputConfig() ? Input::ParseInputConfig("default") + : Input::ParseInputConfig(RunningGameSerial); + } + if (close_on_save) QWidget::close(); } @@ -1011,12 +1010,4 @@ bool KBMSettings::eventFilter(QObject* obj, QEvent* event) { return QDialog::eventFilter(obj, event); } -void KBMSettings::Cleanup() { - if (GameRunning) { - SDL_Event resumeGame{}; - resumeGame.type = SDL_EVENT_TOGGLE_PAUSE; - SDL_PushEvent(&resumeGame); - } -} - KBMSettings::~KBMSettings() {} diff --git a/src/qt_gui/kbm_gui.h b/src/qt_gui/kbm_gui.h index ddc2b9422..7a0a5916f 100644 --- a/src/qt_gui/kbm_gui.h +++ b/src/qt_gui/kbm_gui.h @@ -24,7 +24,7 @@ class KBMSettings : public QDialog { Q_OBJECT public: explicit KBMSettings(std::shared_ptr game_info_get, bool GameRunning, - QWidget* parent = nullptr); + std::string GameRunningSerial, QWidget* parent = nullptr); ~KBMSettings(); private Q_SLOTS: @@ -47,6 +47,7 @@ private: void SetMapping(QString input); void Cleanup(); + std::string RunningGameSerial; QSet pressedKeys; bool GameRunning; bool EnableMapping = false; @@ -69,9 +70,4 @@ private: "pad_left", "pad_right", "axis_left_x", "axis_left_y", "axis_right_x", "axis_right_y", "back"}; - -protected: - void closeEvent(QCloseEvent* event) override { - Cleanup(); - } }; diff --git a/src/qt_gui/main_window.cpp b/src/qt_gui/main_window.cpp index 0b2b1e7cd..f561bf392 100644 --- a/src/qt_gui/main_window.cpp +++ b/src/qt_gui/main_window.cpp @@ -473,12 +473,13 @@ void MainWindow::CreateConnects() { }); connect(ui->controllerButton, &QPushButton::clicked, this, [this]() { - ControlSettings* remapWindow = new ControlSettings(m_game_info, isGameRunning, this); + ControlSettings* remapWindow = + new ControlSettings(m_game_info, isGameRunning, runningGameSerial, this); remapWindow->exec(); }); connect(ui->keyboardButton, &QPushButton::clicked, this, [this]() { - auto kbmWindow = new KBMSettings(m_game_info, isGameRunning, this); + auto kbmWindow = new KBMSettings(m_game_info, isGameRunning, runningGameSerial, this); kbmWindow->exec(); }); @@ -846,12 +847,14 @@ void MainWindow::StartGame() { if (m_game_list_frame->currentItem()) { int itemID = m_game_list_frame->currentItem()->row(); Common::FS::PathToQString(gamePath, m_game_info->m_games[itemID].path / "eboot.bin"); + runningGameSerial = m_game_info->m_games[itemID].serial; } } else if (table_mode == 1) { if (m_game_grid_frame->cellClicked) { int itemID = (m_game_grid_frame->crtRow * m_game_grid_frame->columnCnt) + m_game_grid_frame->crtColumn; Common::FS::PathToQString(gamePath, m_game_info->m_games[itemID].path / "eboot.bin"); + runningGameSerial = m_game_info->m_games[itemID].serial; } } else { if (m_elf_viewer->currentItem()) { diff --git a/src/qt_gui/main_window.h b/src/qt_gui/main_window.h index eec1a65de..5b880c15e 100644 --- a/src/qt_gui/main_window.h +++ b/src/qt_gui/main_window.h @@ -75,11 +75,13 @@ private: void PlayBackgroundMusic(); QIcon RecolorIcon(const QIcon& icon, bool isWhite); void StartEmulator(std::filesystem::path); + bool isIconBlack = false; bool isTableList = true; bool isGameRunning = false; bool isWhite = false; bool is_paused = false; + std::string runningGameSerial = ""; QActionGroup* m_icon_size_act_group = nullptr; QActionGroup* m_list_mode_act_group = nullptr; diff --git a/src/qt_gui/sdl_event_wrapper.cpp b/src/qt_gui/sdl_event_wrapper.cpp index c45d4d448..3f6ba6e93 100644 --- a/src/qt_gui/sdl_event_wrapper.cpp +++ b/src/qt_gui/sdl_event_wrapper.cpp @@ -19,6 +19,10 @@ Wrapper* Wrapper::GetInstance() { bool Wrapper::ProcessEvent(SDL_Event* event) { switch (event->type) { + case SDL_EVENT_GAMEPAD_ADDED: + return false; + case SDL_EVENT_GAMEPAD_REMOVED: + return false; case SDL_EVENT_QUIT: emit SDLEvent(SDL_EVENT_QUIT, 0, 0); return true; @@ -31,8 +35,9 @@ bool Wrapper::ProcessEvent(SDL_Event* event) { case SDL_EVENT_GAMEPAD_AXIS_MOTION: emit SDLEvent(SDL_EVENT_GAMEPAD_AXIS_MOTION, event->gaxis.axis, event->gaxis.value); return true; + // block all other SDL events while wrapper is active default: - return false; + return true; } } Wrapper::~Wrapper() {}