From 61fc28e03e4f4c352a11bc27b4baa463af0b1e8c Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Thu, 18 Dec 2014 01:20:37 -0800 Subject: [PATCH] Qt: Ensure holding down a button while mapping only takes effect once --- src/platform/qt/GBAKeyEditor.cpp | 30 +++++++++++++++++------------- src/platform/qt/GBAKeyEditor.h | 9 +++++++++ 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/src/platform/qt/GBAKeyEditor.cpp b/src/platform/qt/GBAKeyEditor.cpp index 648aa76c6..2611a8f11 100644 --- a/src/platform/qt/GBAKeyEditor.cpp +++ b/src/platform/qt/GBAKeyEditor.cpp @@ -25,6 +25,7 @@ GBAKeyEditor::GBAKeyEditor(InputController* controller, int type, QWidget* paren : QWidget(parent) , m_type(type) , m_controller(controller) + , m_gamepadTimer(nullptr) { setWindowFlags(windowFlags() & ~Qt::WindowFullscreenButtonHint); setMinimumSize(300, 300); @@ -112,8 +113,11 @@ GBAKeyEditor::GBAKeyEditor(InputController* controller, int type, QWidget* paren setAll->setFocus(); #ifdef BUILD_SDL - if (type == SDL_BINDING_BUTTON) {\ - QTimer::singleShot(50, this, SLOT(testGamepad())); + if (type == SDL_BINDING_BUTTON) { + m_gamepadTimer = new QTimer(this); + connect(m_gamepadTimer, SIGNAL(timeout()), this, SLOT(testGamepad())); + m_gamepadTimer->setInterval(50); + m_gamepadTimer->start(); } #endif } @@ -217,29 +221,29 @@ void GBAKeyEditor::bindKey(const KeyEditor* keyEditor, GBAKey key) { #ifdef BUILD_SDL void GBAKeyEditor::testGamepad() { + m_gamepadTimer->setInterval(50); if (m_currentKey == m_keyOrder.end() || !*m_currentKey) { - QTimer::singleShot(50, this, SLOT(testGamepad())); return; } KeyEditor* focused = *m_currentKey; - QSet> activeAxes = m_controller->activeGamepadAxes(); + auto activeAxes = m_controller->activeGamepadAxes(); + auto oldAxes = m_activeAxes; + m_activeAxes = activeAxes; + activeAxes.subtract(oldAxes); if (!activeAxes.empty()) { focused->setValueAxis(activeAxes.begin()->first, activeAxes.begin()->second); - - QTimer::singleShot(200, this, SLOT(testGamepad())); return; } - QSet activeKeys = m_controller->activeGamepadButtons(); - if (!activeKeys.empty()) { - focused->setValueButton(*activeKeys.begin()); - - QTimer::singleShot(200, this, SLOT(testGamepad())); + auto activeButtons = m_controller->activeGamepadButtons(); + auto oldButtons = m_activeButtons; + m_activeButtons = activeButtons; + activeButtons.subtract(oldButtons); + if (!activeButtons.empty()) { + focused->setValueButton(*activeButtons.begin()); return; } - - QTimer::singleShot(50, this, SLOT(testGamepad())); } #endif diff --git a/src/platform/qt/GBAKeyEditor.h b/src/platform/qt/GBAKeyEditor.h index d02f96af3..cc1a30abb 100644 --- a/src/platform/qt/GBAKeyEditor.h +++ b/src/platform/qt/GBAKeyEditor.h @@ -8,12 +8,15 @@ #include #include +#include #include extern "C" { #include "gba-input.h" } +class QTimer; + namespace QGBA { class InputController; @@ -70,6 +73,12 @@ private: QList m_keyOrder; QList::iterator m_currentKey; +#ifdef BUILD_SDL + QSet m_activeButtons; + QSet> m_activeAxes; + QTimer* m_gamepadTimer; +#endif + uint32_t m_type; InputController* m_controller;