From b58d216868189f71475404d75839f426cb086d22 Mon Sep 17 00:00:00 2001 From: "Eevee (Lexy Munroe)" Date: Fri, 5 May 2017 19:10:45 -0700 Subject: [PATCH] Qt: Fix resetting selected gamepad when opening settings dialog MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I have a Wacom tablet always plugged in. For unrelated asinine reasons, SDL detects both the pen and the tablet itself as (completely useless) gamepads, so they always show up in the list first. I also have a Wii U Bluetooth controller, which shows up third. When the settings dialog is spawned, selectGamepad is bound to the currentIndexChanged event, so picking a controller from the combobox will call it. The current index is initially -1 (because the combobox is empty), and when updateJoysticks is called to populate it, the index automatically changes to 0. The event is fired and the current gamepad is changed to the first one, which in my case is my tablet pen. updateJoysticks tries to avoid this by explicitly reselecting the active gamepad after refreshing the combobox, but at this point the "active" gamepad has already changed. The upshot of this was that opening the settings dialog for any reason would disable my controller, unless I remembered to go change it back. I've also seen the button configuration for the wacom pen or controller be saved under each others' names. The fix, which works on my machineā„¢, is to disable signals altogether while mucking with the contents of the combobox, explicitly reselect the right gamepad, and then explicitly call selectGamepad. (I dropped the last two lines because the same thing is already done in refresh, which is called by selectGamepad.) Arguably this is still a little wrong: - If I unplugged my Wacom tablet, my controller would shift upwards to slot 0. This code would fail to notice and keep trying to use joystick 2. That's a pretty obscure case, though, and maybe difficult to fix correctly. - This panel makes changes immediately, but it should wait for OK or Apply. --- src/platform/qt/GBAKeyEditor.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/platform/qt/GBAKeyEditor.cpp b/src/platform/qt/GBAKeyEditor.cpp index 1f5aafeed..4e157c85c 100644 --- a/src/platform/qt/GBAKeyEditor.cpp +++ b/src/platform/qt/GBAKeyEditor.cpp @@ -396,14 +396,14 @@ void GBAKeyEditor::updateJoysticks() { m_controller->updateJoysticks(); m_controller->recalibrateAxes(); + // Block the currentIndexChanged signal while rearranging the combo box + auto wasBlocked = m_profileSelect->blockSignals(true); m_profileSelect->clear(); m_profileSelect->addItems(m_controller->connectedGamepads(m_type)); int activeGamepad = m_controller->gamepad(m_type); + m_profileSelect->setCurrentIndex(activeGamepad); + m_profileSelect->blockSignals(wasBlocked); + selectGamepad(activeGamepad); - if (activeGamepad > 0) { - m_profileSelect->setCurrentIndex(activeGamepad); - } - lookupAxes(m_controller->map()); - lookupHats(m_controller->map()); } #endif