summaryrefslogtreecommitdiff
path: root/Source/Core/DolphinQt/Config/Mapping/MappingCommon.cpp
diff options
context:
space:
mode:
authorJMC47 <JMC4789@gmail.com>2025-02-15 12:59:23 -0500
committerGitHub <noreply@github.com>2025-02-15 12:59:23 -0500
commita8fae9b82683dd0ea766cb8c282b414707962255 (patch)
tree6ab551bcd3d7ef3459f369bf45206577c60d5231 /Source/Core/DolphinQt/Config/Mapping/MappingCommon.cpp
parentc360ea0d9d5caaa0d305711eb1a86ad30d6353da (diff)
parent6e7e808b6614f98674dba7290bea2ea044c4d5d2 (diff)
Merge pull request #13320 from jordan-woyak/detect-alternations
DolphinQt/Mapping: Add setting to enable waiting for alternate mappings.
Diffstat (limited to 'Source/Core/DolphinQt/Config/Mapping/MappingCommon.cpp')
-rw-r--r--Source/Core/DolphinQt/Config/Mapping/MappingCommon.cpp57
1 files changed, 37 insertions, 20 deletions
diff --git a/Source/Core/DolphinQt/Config/Mapping/MappingCommon.cpp b/Source/Core/DolphinQt/Config/Mapping/MappingCommon.cpp
index edce169c28..37407f2298 100644
--- a/Source/Core/DolphinQt/Config/Mapping/MappingCommon.cpp
+++ b/Source/Core/DolphinQt/Config/Mapping/MappingCommon.cpp
@@ -19,8 +19,10 @@
namespace MappingCommon
{
constexpr auto INPUT_DETECT_INITIAL_TIME = std::chrono::seconds(3);
-constexpr auto INPUT_DETECT_CONFIRMATION_TIME = std::chrono::milliseconds(0);
+constexpr auto INPUT_DETECT_CONFIRMATION_TIME = std::chrono::milliseconds(750);
constexpr auto INPUT_DETECT_MAXIMUM_TIME = std::chrono::seconds(5);
+// Ignore the mouse-click when queuing more buttons with "alternate mappings" enabled.
+constexpr auto INPUT_DETECT_ENDING_IGNORE_TIME = std::chrono::milliseconds(50);
class MappingProcessor : public QWidget
{
@@ -50,7 +52,7 @@ public:
button->StartMapping();
std::vector device_strings{default_device.ToString()};
- if (m_parent->IsMappingAllDevices())
+ if (m_parent->IsCreateOtherDeviceMappingsEnabled())
device_strings = g_controller_interface.GetAllDeviceStrings();
m_input_detector = std::make_unique<ciface::Core::InputDetector>();
@@ -63,33 +65,39 @@ public:
if (!m_input_detector)
return;
- m_input_detector->Update(INPUT_DETECT_INITIAL_TIME, INPUT_DETECT_CONFIRMATION_TIME,
+ const auto confirmation_time =
+ INPUT_DETECT_CONFIRMATION_TIME * (m_parent->IsWaitForAlternateMappingsEnabled() ? 1 : 0);
+
+ m_input_detector->Update(INPUT_DETECT_INITIAL_TIME, confirmation_time,
INPUT_DETECT_MAXIMUM_TIME);
if (m_input_detector->IsComplete())
{
- auto detections = m_input_detector->TakeResults();
- ciface::MappingCommon::RemoveSpuriousTriggerCombinations(&detections);
-
// No inputs detected. Cancel this and any other queued mappings.
- if (detections.empty())
- {
+ if (!FinalizeMapping(m_input_detector->TakeResults()))
CancelMapping();
- return;
- }
+ }
+ }
- const auto& default_device = m_parent->GetController()->GetDefaultDevice();
- auto& button = m_clicked_mapping_buttons.front();
- auto* const control_reference = button->GetControlReference();
+ bool FinalizeMapping(ciface::Core::InputDetector::Results detections)
+ {
+ if (!ciface::MappingCommon::ContainsCompleteDetection(detections))
+ return false;
- control_reference->SetExpression(
- BuildExpression(detections, default_device, ciface::MappingCommon::Quote::On));
- m_parent->Save();
+ ciface::MappingCommon::RemoveSpuriousTriggerCombinations(&detections);
- m_parent->GetController()->UpdateSingleControlReference(g_controller_interface,
- control_reference);
- UnQueueInputDetection(button);
- }
+ const auto& default_device = m_parent->GetController()->GetDefaultDevice();
+ auto& button = m_clicked_mapping_buttons.front();
+ auto* const control_reference = button->GetControlReference();
+
+ control_reference->SetExpression(
+ BuildExpression(detections, default_device, ciface::MappingCommon::Quote::On));
+ m_parent->Save();
+
+ m_parent->GetController()->UpdateSingleControlReference(g_controller_interface,
+ control_reference);
+ UnQueueInputDetection(button);
+ return true;
}
void UpdateInputDetectionStartTimer()
@@ -121,6 +129,15 @@ public:
button->setText(QStringLiteral("[ ... ]"));
m_clicked_mapping_buttons.push_back(button);
+
+ if (m_input_detector)
+ {
+ // Ignore the mouse-click that queued this new detection and finalize the current mapping.
+ auto results = m_input_detector->TakeResults();
+ ciface::MappingCommon::RemoveDetectionsAfterTimePoint(
+ &results, ciface::Core::DeviceContainer::Clock::now() - INPUT_DETECT_ENDING_IGNORE_TIME);
+ FinalizeMapping(std::move(results));
+ }
UpdateInputDetectionStartTimer();
}