diff options
Diffstat (limited to 'backends/keymapper/keymap.cpp')
| -rw-r--r-- | backends/keymapper/keymap.cpp | 56 |
1 files changed, 37 insertions, 19 deletions
diff --git a/backends/keymapper/keymap.cpp b/backends/keymapper/keymap.cpp index bd020937eb..daf92e1d15 100644 --- a/backends/keymapper/keymap.cpp +++ b/backends/keymapper/keymap.cpp @@ -24,7 +24,10 @@ #ifdef ENABLE_KEYMAPPER +#include "common/system.h" + #include "backends/keymapper/hardware-key.h" +#include "backends/keymapper/keymapper-defaults.h" #define KEYMAP_KEY_PREFIX "keymap_" @@ -121,35 +124,50 @@ void Keymap::loadMappings(const HardwareKeySet *hwKeys) { if (!_configDomain) return; - ConfigManager::Domain::iterator it; - String prefix = KEYMAP_KEY_PREFIX + _name + "_"; - - for (it = _configDomain->begin(); it != _configDomain->end(); ++it) { - const String& key = it->_key; - - if (!key.hasPrefix(prefix.c_str())) - continue; + if (_actions.empty()) + return; - // parse Action ID - const char *actionId = key.c_str() + prefix.size(); - Action *ua = getAction(actionId); + Common::KeymapperDefaultBindings *defaults = g_system->getKeymapperDefaultBindings(); - if (!ua) { - warning("'%s' keymap does not contain Action with ID %s", - _name.c_str(), actionId); - _configDomain->erase(key); + HashMap<String, const HardwareKey *> mappedKeys; + List<Action*>::iterator it; + String prefix = KEYMAP_KEY_PREFIX + _name + "_"; - continue; + for (it = _actions.begin(); it != _actions.end(); ++it) { + Action* ua = *it; + String actionId(ua->id); + String confKey = prefix + actionId; + + String hwKeyId = _configDomain->getVal(confKey); + + bool defaulted = false; + // fall back to the platform-specific defaults + if (hwKeyId.empty() && defaults) { + hwKeyId = defaults->getDefaultBinding(_name, actionId); + if (!hwKeyId.empty()) + defaulted = true; } + // there's no mapping + if (hwKeyId.empty()) + continue; - const HardwareKey *hwKey = hwKeys->findHardwareKey(it->_value.c_str()); + const HardwareKey *hwKey = hwKeys->findHardwareKey(hwKeyId.c_str()); if (!hwKey) { - warning("HardwareKey with ID '%s' not known", it->_value.c_str()); - _configDomain->erase(key); + warning("HardwareKey with ID '%s' not known", hwKeyId.c_str()); continue; } + if (defaulted) { + if (mappedKeys.contains(hwKeyId)) { + debug(1, "Action [%s] not falling back to hardcoded default value [%s] because the key is in use", confKey.c_str(), hwKeyId.c_str()); + continue; + } + warning("Action [%s] fell back to hardcoded default value [%s]", confKey.c_str(), hwKeyId.c_str()); + } + + mappedKeys.setVal(hwKeyId, hwKey); + // map the key ua->mapKey(hwKey); } } |
