From 375d26de32ddcc826743e5d5e49baf22499b0846 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Thu, 11 Apr 2019 16:56:25 +0200 Subject: [PATCH] The magic hotkey handling alorithm developed and tested in joined effort via SLACK * no redundant action calls * do not call release action if the action is still active by another combination ref T585 --- src/blackcore/inputmanager.cpp | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/src/blackcore/inputmanager.cpp b/src/blackcore/inputmanager.cpp index de532bb99..f5c45215f 100644 --- a/src/blackcore/inputmanager.cpp +++ b/src/blackcore/inputmanager.cpp @@ -175,27 +175,30 @@ namespace BlackCore return; } - for (const CHotkeyCombination &combination : makeKeysRange(as_const(m_configuredActions))) + QSet newActiveActions; + for (const auto pair : makePairsRange(as_const(m_configuredActions))) { - QString action = m_configuredActions.value(combination); + const CHotkeyCombination &combination = pair.first; + const QString &action = pair.second; if (combination.isSubsetOf(currentCombination)) { - if (!m_activeActions.contains(action)) - { - m_activeActions.insert(action); - callFunctionsBy(action, true); - } - } - else - { - if (m_activeActions.contains(action)) - { - callFunctionsBy(action, false); - m_activeActions.remove(action); - } + newActiveActions.insert(action); } } + const QSet pressedActions = newActiveActions - m_activeActions; + const QSet releasedActions = m_activeActions - newActiveActions; + m_activeActions = newActiveActions; + for (const QString &action : pressedActions) + { + callFunctionsBy(action, true); + } + for (const QString &action : releasedActions) + { + callFunctionsBy(action, false); + } + + // combination m_lastCombination = currentCombination; } }