From 6fddb31a078cde1849626aa74cc1b45c6cd29a88 Mon Sep 17 00:00:00 2001 From: Megamouse Date: Wed, 22 Jan 2025 18:53:45 +0100 Subject: [PATCH] Qt/input: reset gui pad thread when saving pad settings --- rpcs3/Input/gui_pad_thread.cpp | 22 +++++++++++++++++----- rpcs3/Input/gui_pad_thread.h | 6 ++++++ rpcs3/rpcs3qt/pad_settings_dialog.cpp | 3 +++ 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/rpcs3/Input/gui_pad_thread.cpp b/rpcs3/Input/gui_pad_thread.cpp index 87fa0999f3..7b69b24209 100644 --- a/rpcs3/Input/gui_pad_thread.cpp +++ b/rpcs3/Input/gui_pad_thread.cpp @@ -40,6 +40,8 @@ LOG_CHANNEL(gui_log, "GUI"); +atomic_t gui_pad_thread::m_reset = false; + gui_pad_thread::gui_pad_thread() { m_thread = std::make_unique(&gui_pad_thread::run, this); @@ -145,6 +147,11 @@ bool gui_pad_thread::init() gui_log.notice("gui_pad_thread: Pad %d: device='%s', handler=%s, VID=0x%x, PID=0x%x, class_type=0x%x, class_profile=0x%x", i, cfg->device.to_string(), m_pad->m_pad_handler, m_pad->m_vendor_id, m_pad->m_product_id, m_pad->m_class_type, m_pad->m_class_profile); + if (handler_type != pad_handler::null) + { + input_log.notice("gui_pad_thread %d: config=\n%s", i, cfg->to_string()); + } + // We only use one pad break; } @@ -251,14 +258,19 @@ void gui_pad_thread::run() gui_log.notice("gui_pad_thread: Pad thread started"); - if (!init()) - { - gui_log.warning("gui_pad_thread: Pad thread stopped (init failed)"); - return; - } + m_reset = true; while (!m_terminate) { + if (m_reset && m_reset.exchange(false)) + { + if (!init()) + { + gui_log.warning("gui_pad_thread: Pad thread stopped (init failed during reset)"); + return; + } + } + // Only process input if there is an active window if (m_handler && m_pad && (m_allow_global_input || QApplication::activeWindow())) { diff --git a/rpcs3/Input/gui_pad_thread.h b/rpcs3/Input/gui_pad_thread.h index 4bc0414200..235d97e8b1 100644 --- a/rpcs3/Input/gui_pad_thread.h +++ b/rpcs3/Input/gui_pad_thread.h @@ -23,6 +23,11 @@ public: static std::shared_ptr GetHandler(pad_handler type); static void InitPadConfig(cfg_pad& cfg, pad_handler type, std::shared_ptr& handler); + static void reset() + { + m_reset = true; + } + protected: bool init(); void run(); @@ -60,6 +65,7 @@ protected: std::unique_ptr m_thread; atomic_t m_terminate = false; atomic_t m_allow_global_input = false; + static atomic_t m_reset; std::array(pad_button::pad_button_max_enum)> m_last_button_state{}; diff --git a/rpcs3/rpcs3qt/pad_settings_dialog.cpp b/rpcs3/rpcs3qt/pad_settings_dialog.cpp index 2a2194d1b6..9591514dc3 100644 --- a/rpcs3/rpcs3qt/pad_settings_dialog.cpp +++ b/rpcs3/rpcs3qt/pad_settings_dialog.cpp @@ -20,6 +20,7 @@ #include "Utilities/File.h" #include "Input/pad_thread.h" +#include "Input/gui_pad_thread.h" #include "Input/product_info.h" #include "Input/keyboard_pad_handler.h" @@ -245,6 +246,8 @@ pad_settings_dialog::~pad_settings_dialog() *m_input_thread = thread_state::finished; } + gui_pad_thread::reset(); + if (!Emu.IsStopped()) { pad::reset(Emu.GetTitleID());