diff --git a/resources/inputmaps/keyboard.json b/resources/inputmaps/keyboard.json index f1ae568..c10d1a4 100644 --- a/resources/inputmaps/keyboard.json +++ b/resources/inputmaps/keyboard.json @@ -17,6 +17,9 @@ // map X and Shift+X to X. This allows normal number input "(?:Shift\\+)?([0-9])": "%1", + // map X and Shift+X to X for letters. This allows normal text input + "(?:Shift\\+)?([A-Z])": "%1", + // map some other normal buttons that might be useful "(?:Shift\\+)?(\\.|\\:|\\_)": "%1", diff --git a/src/input/InputComponent.cpp b/src/input/InputComponent.cpp index c13c9e0..17c44e4 100644 --- a/src/input/InputComponent.cpp +++ b/src/input/InputComponent.cpp @@ -167,28 +167,31 @@ void InputComponent::remapInput(const QString &source, const QString &keycode, b // hide mouse if it's visible. SystemComponent::Get().setCursorVisibility(false); - QVariant action = m_mappings->mapToAction(source, keycode); - if (action.isNull()) + auto actions = m_mappings->mapToAction(source, keycode); + if (actions.isEmpty()) { QLOG_WARN() << "Could not map:" << source << keycode << "to any useful action"; return; } - if (action.type() == QVariant::String) + for (auto action : actions) { - handleAction(action.toString()); - } - else if (action.type() == QVariant::Map) - { - QVariantMap map = action.toMap(); - if (map.contains("long")) + if (action.type() == QVariant::String) { - m_longHoldTimer.start(); - m_currentLongPressAction = map; + handleAction(action.toString()); } - else if (map.contains("short")) + else if (action.type() == QVariant::Map) { - handleAction(map.value("short").toString()); + QVariantMap map = action.toMap(); + if (map.contains("long")) + { + m_longHoldTimer.start(); + m_currentLongPressAction = map; + } + else if (map.contains("short")) + { + handleAction(map.value("short").toString()); + } } } } diff --git a/src/input/InputMapping.cpp b/src/input/InputMapping.cpp index 84223ed..9964cae 100644 --- a/src/input/InputMapping.cpp +++ b/src/input/InputMapping.cpp @@ -52,21 +52,19 @@ bool InputMapping::loadMappings() } ///////////////////////////////////////////////////////////////////////////////////////// -QVariant InputMapping::mapToAction(const QString& source, const QString& keycode) +QVariantList InputMapping::mapToAction(const QString& source, const QString& keycode) { // if the source is direct we will just use the keycode as the action if (source == "direct") - return keycode; + return { QVariant(keycode) }; + + QVariantList strActions; // first we need to match the source - QVariant sourceName = m_sourceMatcher.match(source); - if (sourceName.isValid()) - { - QVariant action = m_inputMatcher.value(sourceName.toString())->match(keycode); - if (action.isValid()) - return action; - } - return QString(); + for (auto src : m_sourceMatcher.match(source)) + strActions << m_inputMatcher.value(src.toString())->match(keycode); + + return strActions; } /////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/input/InputMapping.h b/src/input/InputMapping.h index 0bcf640..5996506 100644 --- a/src/input/InputMapping.h +++ b/src/input/InputMapping.h @@ -16,7 +16,7 @@ class InputMapping : public QObject public: explicit InputMapping(QObject *parent = nullptr); bool loadMappings(); - QVariant mapToAction(const QString& source, const QString& keycode); + QVariantList mapToAction(const QString& source, const QString& keycode); private Q_SLOTS: void dirChange(); diff --git a/src/utils/CachedRegexMatcher.cpp b/src/utils/CachedRegexMatcher.cpp index 8682ca0..4aeaaf6 100644 --- a/src/utils/CachedRegexMatcher.cpp +++ b/src/utils/CachedRegexMatcher.cpp @@ -20,12 +20,14 @@ bool CachedRegexMatcher::addMatcher(const QString& pattern, const QVariant& resu } ///////////////////////////////////////////////////////////////////////////////////////// -QVariant CachedRegexMatcher::match(const QString& input) +QVariantList CachedRegexMatcher::match(const QString& input) { // first we check if this match has already happened before if (m_matcherCache.contains(input)) return m_matcherCache.value(input); + QVariantList matches; + // otherwise try to iterate our list and find a match for(const MatcherValuePair& matcher : m_matcherList) { @@ -49,17 +51,19 @@ QVariant CachedRegexMatcher::match(const QString& input) returnValue = QVariant(value); } - // now cache the match and the final value - m_matcherCache.insert(input, returnValue); - - return returnValue; + matches << returnValue; } } QLOG_DEBUG() << "No match for:" << input; - // no match at all - return QVariant(); + if (!matches.isEmpty()) + { + m_matcherCache.insert(input, matches); + return matches; + } + + return QVariantList(); } ///////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/utils/CachedRegexMatcher.h b/src/utils/CachedRegexMatcher.h index 728abef..f2901ca 100644 --- a/src/utils/CachedRegexMatcher.h +++ b/src/utils/CachedRegexMatcher.h @@ -19,12 +19,12 @@ public: explicit CachedRegexMatcher(QObject* parent = nullptr) : QObject(parent) {} bool addMatcher(const QString& pattern, const QVariant& result); - QVariant match(const QString& input); + QVariantList match(const QString& input); void clear(); private: MatcherValueList m_matcherList; - QHash m_matcherCache; + QHash m_matcherCache; }; #endif //KONVERGO_CACHEDREGEXMATCHER_H