From 4e39d833ae412709c854486e49d4de2f9f174306 Mon Sep 17 00:00:00 2001 From: Jordan Woyak Date: Sat, 27 Apr 2019 12:35:26 -0500 Subject: [PATCH] DolphinQt: Fix mapping of space, return, and mouse-clicks from immediately re-activating detection. --- .../Config/Mapping/MappingButton.cpp | 2 +- .../Config/Mapping/MappingCommon.cpp | 20 ++++++++++++++----- .../QtUtils/BlockUserInputFilter.cpp | 6 ------ .../DolphinQt/QtUtils/BlockUserInputFilter.h | 3 +-- 4 files changed, 17 insertions(+), 14 deletions(-) diff --git a/Source/Core/DolphinQt/Config/Mapping/MappingButton.cpp b/Source/Core/DolphinQt/Config/Mapping/MappingButton.cpp index 3d43e02e96..bc582e1bd9 100644 --- a/Source/Core/DolphinQt/Config/Mapping/MappingButton.cpp +++ b/Source/Core/DolphinQt/Config/Mapping/MappingButton.cpp @@ -56,7 +56,7 @@ MappingButton::MappingButton(MappingWidget* parent, ControlReference* ref, bool setToolTip( tr("Left-click to detect input.\nMiddle-click to clear.\nRight-click for more options.")); - connect(this, &MappingButton::pressed, this, &MappingButton::Detect); + connect(this, &MappingButton::clicked, this, &MappingButton::Detect); if (indicator) connect(parent, &MappingWidget::Update, this, &MappingButton::UpdateIndicator); diff --git a/Source/Core/DolphinQt/Config/Mapping/MappingCommon.cpp b/Source/Core/DolphinQt/Config/Mapping/MappingCommon.cpp index f1a5d67c91..01aa95d3a0 100644 --- a/Source/Core/DolphinQt/Config/Mapping/MappingCommon.cpp +++ b/Source/Core/DolphinQt/Config/Mapping/MappingCommon.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include "DolphinQt/QtUtils/BlockUserInputFilter.h" #include "InputCommon/ControlReference/ControlReference.h" @@ -52,7 +53,9 @@ QString DetectExpression(QPushButton* button, ciface::Core::DeviceContainer& dev const std::vector& device_strings, const ciface::Core::DeviceQualifier& default_device, Quote quote) { - button->installEventFilter(BlockUserInputFilter::Instance()); + const auto filter = new BlockUserInputFilter(button); + + button->installEventFilter(filter); button->grabKeyboard(); button->grabMouse(); @@ -63,16 +66,23 @@ QString DetectExpression(QPushButton* button, ciface::Core::DeviceContainer& dev QApplication::processEvents(); // Avoid that the button press itself is registered as an event - Common::SleepCurrentThread(100); + Common::SleepCurrentThread(50); std::shared_ptr device; ciface::Core::Device::Input* input; std::tie(device, input) = device_container.DetectInput(INPUT_DETECT_TIME, device_strings); - button->releaseMouse(); - button->releaseKeyboard(); - button->removeEventFilter(BlockUserInputFilter::Instance()); + const auto timer = new QTimer(button); + + button->connect(timer, &QTimer::timeout, [button, filter] { + button->releaseMouse(); + button->releaseKeyboard(); + button->removeEventFilter(filter); + }); + + // Prevent mappings of "space", "return", or mouse clicks from re-activating detection. + timer->start(500); button->setText(old_text); diff --git a/Source/Core/DolphinQt/QtUtils/BlockUserInputFilter.cpp b/Source/Core/DolphinQt/QtUtils/BlockUserInputFilter.cpp index d9ac74041e..38083c2873 100644 --- a/Source/Core/DolphinQt/QtUtils/BlockUserInputFilter.cpp +++ b/Source/Core/DolphinQt/QtUtils/BlockUserInputFilter.cpp @@ -6,12 +6,6 @@ #include -BlockUserInputFilter* BlockUserInputFilter::Instance() -{ - static BlockUserInputFilter s_block_user_input_filter; - return &s_block_user_input_filter; -} - bool BlockUserInputFilter::eventFilter(QObject* object, QEvent* event) { const QEvent::Type event_type = event->type(); diff --git a/Source/Core/DolphinQt/QtUtils/BlockUserInputFilter.h b/Source/Core/DolphinQt/QtUtils/BlockUserInputFilter.h index 3c62dfd07d..a7037f88d3 100644 --- a/Source/Core/DolphinQt/QtUtils/BlockUserInputFilter.h +++ b/Source/Core/DolphinQt/QtUtils/BlockUserInputFilter.h @@ -12,9 +12,8 @@ class BlockUserInputFilter : public QObject { Q_OBJECT public: - static BlockUserInputFilter* Instance(); + using QObject::QObject; private: - BlockUserInputFilter() = default; bool eventFilter(QObject* object, QEvent* event) override; };