Qt/input: reset gui pad thread when saving pad settings

This commit is contained in:
Megamouse 2025-01-22 18:53:45 +01:00
parent 79d79aa80c
commit 6fddb31a07
3 changed files with 26 additions and 5 deletions

View File

@ -40,6 +40,8 @@
LOG_CHANNEL(gui_log, "GUI"); LOG_CHANNEL(gui_log, "GUI");
atomic_t<bool> gui_pad_thread::m_reset = false;
gui_pad_thread::gui_pad_thread() gui_pad_thread::gui_pad_thread()
{ {
m_thread = std::make_unique<std::thread>(&gui_pad_thread::run, this); m_thread = std::make_unique<std::thread>(&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", 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); 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 // We only use one pad
break; break;
} }
@ -251,14 +258,19 @@ void gui_pad_thread::run()
gui_log.notice("gui_pad_thread: Pad thread started"); gui_log.notice("gui_pad_thread: Pad thread started");
if (!init()) m_reset = true;
{
gui_log.warning("gui_pad_thread: Pad thread stopped (init failed)");
return;
}
while (!m_terminate) 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 // Only process input if there is an active window
if (m_handler && m_pad && (m_allow_global_input || QApplication::activeWindow())) if (m_handler && m_pad && (m_allow_global_input || QApplication::activeWindow()))
{ {

View File

@ -23,6 +23,11 @@ public:
static std::shared_ptr<PadHandlerBase> GetHandler(pad_handler type); static std::shared_ptr<PadHandlerBase> GetHandler(pad_handler type);
static void InitPadConfig(cfg_pad& cfg, pad_handler type, std::shared_ptr<PadHandlerBase>& handler); static void InitPadConfig(cfg_pad& cfg, pad_handler type, std::shared_ptr<PadHandlerBase>& handler);
static void reset()
{
m_reset = true;
}
protected: protected:
bool init(); bool init();
void run(); void run();
@ -60,6 +65,7 @@ protected:
std::unique_ptr<std::thread> m_thread; std::unique_ptr<std::thread> m_thread;
atomic_t<bool> m_terminate = false; atomic_t<bool> m_terminate = false;
atomic_t<bool> m_allow_global_input = false; atomic_t<bool> m_allow_global_input = false;
static atomic_t<bool> m_reset;
std::array<bool, static_cast<u32>(pad_button::pad_button_max_enum)> m_last_button_state{}; std::array<bool, static_cast<u32>(pad_button::pad_button_max_enum)> m_last_button_state{};

View File

@ -20,6 +20,7 @@
#include "Utilities/File.h" #include "Utilities/File.h"
#include "Input/pad_thread.h" #include "Input/pad_thread.h"
#include "Input/gui_pad_thread.h"
#include "Input/product_info.h" #include "Input/product_info.h"
#include "Input/keyboard_pad_handler.h" #include "Input/keyboard_pad_handler.h"
@ -245,6 +246,8 @@ pad_settings_dialog::~pad_settings_dialog()
*m_input_thread = thread_state::finished; *m_input_thread = thread_state::finished;
} }
gui_pad_thread::reset();
if (!Emu.IsStopped()) if (!Emu.IsStopped())
{ {
pad::reset(Emu.GetTitleID()); pad::reset(Emu.GetTitleID());