diff --git a/Source/Core/DolphinQt2/CMakeLists.txt b/Source/Core/DolphinQt2/CMakeLists.txt index aea18542f8..4c9b147f5e 100644 --- a/Source/Core/DolphinQt2/CMakeLists.txt +++ b/Source/Core/DolphinQt2/CMakeLists.txt @@ -65,6 +65,7 @@ set(SRCS GameList/GameTracker.cpp GameList/ListProxyModel.cpp GameList/TableProxyModel.cpp + QtUtils/BlockUserInputFilter.cpp QtUtils/DoubleClickEventFilter.cpp QtUtils/ElidedButton.cpp QtUtils/ListTabWidget.cpp diff --git a/Source/Core/DolphinQt2/Config/Mapping/IOWindow.cpp b/Source/Core/DolphinQt2/Config/Mapping/IOWindow.cpp index 50e56b6bf2..ae40b29c17 100644 --- a/Source/Core/DolphinQt2/Config/Mapping/IOWindow.cpp +++ b/Source/Core/DolphinQt2/Config/Mapping/IOWindow.cpp @@ -21,6 +21,7 @@ #include "Core/Core.h" #include "DolphinQt2/Config/Mapping/MappingCommon.h" #include "DolphinQt2/Config/Mapping/MappingWindow.h" +#include "DolphinQt2/QtUtils/BlockUserInputFilter.h" #include "InputCommon/ControlReference/ControlReference.h" #include "InputCommon/ControllerEmu/ControllerEmu.h" #include "InputCommon/ControllerInterface/ControllerInterface.h" @@ -171,11 +172,10 @@ void IOWindow::OnDialogButtonPressed(QAbstractButton* button) void IOWindow::OnDetectButtonPressed() { - if (m_block.IsSet()) - return; + installEventFilter(BlockUserInputFilter::Instance()); + grabKeyboard(); + grabMouse(); - m_block.Set(true); - m_expression_text->setEnabled(false); std::thread([this] { auto* btn = m_type == IOWindow::Type::Input ? m_detect_button : m_test_button; const auto old_label = btn->text(); @@ -194,8 +194,10 @@ void IOWindow::OnDetectButtonPressed() if (list.size() > 0) m_option_list->setCurrentItem(list[0]); } - m_expression_text->setEnabled(true); - m_block.Set(false); + + releaseMouse(); + releaseKeyboard(); + removeEventFilter(BlockUserInputFilter::Instance()); }).detach(); } @@ -208,9 +210,6 @@ void IOWindow::OnRangeChanged(int value) void IOWindow::UpdateOptionList() { - if (m_block.IsSet()) - return; - m_option_list->clear(); const auto device = g_controller_interface.FindDevice(m_devq); @@ -233,7 +232,6 @@ void IOWindow::UpdateOptionList() void IOWindow::UpdateDeviceList() { - m_block.Set(true); m_devices_combo->clear(); Core::RunAsCPUThread([&] { @@ -254,6 +252,4 @@ void IOWindow::UpdateDeviceList() m_devices_combo->setCurrentIndex(0); }); - - m_block.Set(false); } diff --git a/Source/Core/DolphinQt2/Config/Mapping/IOWindow.h b/Source/Core/DolphinQt2/Config/Mapping/IOWindow.h index 05726eaa3d..0117393272 100644 --- a/Source/Core/DolphinQt2/Config/Mapping/IOWindow.h +++ b/Source/Core/DolphinQt2/Config/Mapping/IOWindow.h @@ -92,6 +92,5 @@ private: ControllerEmu::EmulatedController* m_controller; ciface::Core::DeviceQualifier m_devq; - Common::Flag m_block; Type m_type; }; diff --git a/Source/Core/DolphinQt2/Config/Mapping/MappingButton.cpp b/Source/Core/DolphinQt2/Config/Mapping/MappingButton.cpp index 44bc67e3f0..7c01a527a2 100644 --- a/Source/Core/DolphinQt2/Config/Mapping/MappingButton.cpp +++ b/Source/Core/DolphinQt2/Config/Mapping/MappingButton.cpp @@ -15,6 +15,7 @@ #include "DolphinQt2/Config/Mapping/MappingCommon.h" #include "DolphinQt2/Config/Mapping/MappingWidget.h" #include "DolphinQt2/Config/Mapping/MappingWindow.h" +#include "DolphinQt2/QtUtils/BlockUserInputFilter.h" #include "InputCommon/ControlReference/ControlReference.h" #include "InputCommon/ControllerEmu/ControllerEmu.h" #include "InputCommon/ControllerInterface/ControllerInterface.h" @@ -42,9 +43,7 @@ void MappingButton::OnButtonPressed() if (m_parent->GetDevice() == nullptr || !m_reference->IsInput()) return; - if (!m_block.TestAndSet()) - return; - + installEventFilter(BlockUserInputFilter::Instance()); grabKeyboard(); grabMouse(); @@ -63,7 +62,7 @@ void MappingButton::OnButtonPressed() releaseMouse(); releaseKeyboard(); - m_block.Clear(); + removeEventFilter(BlockUserInputFilter::Instance()); if (!expr.isEmpty()) { @@ -97,22 +96,6 @@ void MappingButton::Update() m_parent->SaveSettings(); } -bool MappingButton::event(QEvent* event) -{ - const QEvent::Type event_type = event->type(); - // Returning 'true' means "yes, this event has been handled, don't propagate it to parent - // widgets". - if (m_block.IsSet() && - (event_type == QEvent::KeyPress || event_type == QEvent::KeyRelease || - event_type == QEvent::MouseButtonPress || event_type == QEvent::MouseButtonRelease || - event_type == QEvent::MouseButtonDblClick)) - { - return true; - } - - return QPushButton::event(event); -} - void MappingButton::mouseReleaseEvent(QMouseEvent* event) { switch (event->button()) diff --git a/Source/Core/DolphinQt2/Config/Mapping/MappingButton.h b/Source/Core/DolphinQt2/Config/Mapping/MappingButton.h index 0714147d43..a8894119e7 100644 --- a/Source/Core/DolphinQt2/Config/Mapping/MappingButton.h +++ b/Source/Core/DolphinQt2/Config/Mapping/MappingButton.h @@ -25,7 +25,6 @@ signals: void AdvancedPressed(); private: - bool event(QEvent* event) override; void mouseReleaseEvent(QMouseEvent* event) override; void OnButtonPressed(); @@ -34,5 +33,4 @@ private: MappingWidget* m_parent; ControlReference* m_reference; - Common::Flag m_block; }; diff --git a/Source/Core/DolphinQt2/DolphinQt2.vcxproj b/Source/Core/DolphinQt2/DolphinQt2.vcxproj index d132c7abc8..6a16f8d4c3 100644 --- a/Source/Core/DolphinQt2/DolphinQt2.vcxproj +++ b/Source/Core/DolphinQt2/DolphinQt2.vcxproj @@ -189,6 +189,7 @@ + @@ -220,6 +221,7 @@ + diff --git a/Source/Core/DolphinQt2/QtUtils/BlockUserInputFilter.cpp b/Source/Core/DolphinQt2/QtUtils/BlockUserInputFilter.cpp new file mode 100644 index 0000000000..6368ae072a --- /dev/null +++ b/Source/Core/DolphinQt2/QtUtils/BlockUserInputFilter.cpp @@ -0,0 +1,21 @@ +// Copyright 2017 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license.txt file included. + +#include "DolphinQt2/QtUtils/BlockUserInputFilter.h" + +#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(); + return event_type == QEvent::KeyPress || event_type == QEvent::KeyRelease || + event_type == QEvent::MouseButtonPress || event_type == QEvent::MouseButtonRelease || + event_type == QEvent::MouseButtonDblClick; +} diff --git a/Source/Core/DolphinQt2/QtUtils/BlockUserInputFilter.h b/Source/Core/DolphinQt2/QtUtils/BlockUserInputFilter.h new file mode 100644 index 0000000000..112c3eea8f --- /dev/null +++ b/Source/Core/DolphinQt2/QtUtils/BlockUserInputFilter.h @@ -0,0 +1,19 @@ +// Copyright 2017 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license.txt file included. + +#pragma once + +#include + +class QEvent; + +class BlockUserInputFilter : public QObject +{ +public: + static BlockUserInputFilter* Instance(); + +private: + BlockUserInputFilter() = default; + bool eventFilter(QObject* object, QEvent* event) override; +};