diff options
Diffstat (limited to 'backends/keymapper/keymap.cpp')
-rw-r--r-- | backends/keymapper/keymap.cpp | 43 |
1 files changed, 30 insertions, 13 deletions
diff --git a/backends/keymapper/keymap.cpp b/backends/keymapper/keymap.cpp index f5155ce1b5..e95dd6afb5 100644 --- a/backends/keymapper/keymap.cpp +++ b/backends/keymapper/keymap.cpp @@ -33,15 +33,17 @@ namespace Common { -Keymap::Keymap(const Keymap& km) : _actions(km._actions), _keymap(), _configDomain(0) { +Keymap::Keymap(const Keymap& km) : _actions(km._actions), _keymap(), _nonkeymap(), _configDomain(0) { List<Action *>::iterator it; for (it = _actions.begin(); it != _actions.end(); ++it) { const HardwareInput *hwInput = (*it)->getMappedInput(); - //FIXME: Add support for kHardwareInputTypeGeneric - if (hwInput && hwInput->type == kHardwareInputTypeKeyboard) { - _keymap[hwInput->key] = *it; + if (hwInput) { + if (hwInput->type == kHardwareInputTypeKeyboard) + _keymap[hwInput->key] = *it; + else if (hwInput->type == kHardwareInputTypeGeneric) + _nonkeymap[hwInput->inputCode] = *it; } } } @@ -61,17 +63,20 @@ void Keymap::addAction(Action *action) { } void Keymap::registerMapping(Action *action, const HardwareInput *hwInput) { - HashMap<KeyState, Action *>::iterator it; - - //FIXME: Add support for kHardwareInputTypeGeneric if (hwInput->type == kHardwareInputTypeKeyboard) { - it = _keymap.find(hwInput->key); - - // if key is already mapped to a different action then un-map it - if (it != _keymap.end() && action != it->_value) { + HashMap<KeyState, Action *>::iterator it = _keymap.find(hwInput->key); + // if input is already mapped to a different action then unmap it from there + if (it != _keymap.end() && action != it->_value) it->_value->mapInput(0); - } + // now map it _keymap[hwInput->key] = action; + } else if (hwInput->type == kHardwareInputTypeGeneric) { + HashMap<HardwareInputCode, Action *>::iterator it = _nonkeymap.find(hwInput->inputCode); + // if input is already mapped to a different action then unmap it from there + if (it != _nonkeymap.end() && action != it->_value) + it->_value->mapInput(0); + // now map it + _nonkeymap[hwInput->inputCode] = action; } } @@ -79,9 +84,10 @@ void Keymap::unregisterMapping(Action *action) { const HardwareInput *hwInput = action->getMappedInput(); if (hwInput) { - //FIXME: Add support for kHardwareInputTypeGeneric if (hwInput->type == kHardwareInputTypeKeyboard) _keymap.erase(hwInput->key); + else if (hwInput->type == kHardwareInputTypeGeneric) + _nonkeymap.erase(hwInput->inputCode); } } @@ -121,6 +127,17 @@ Action *Keymap::getMappedAction(const KeyState& ks) const { return it->_value; } +Action *Keymap::getMappedAction(const HardwareInputCode code) const { + HashMap<HardwareInputCode, Action *>::iterator it; + + it = _nonkeymap.find(code); + + if (it == _nonkeymap.end()) + return 0; + else + return it->_value; +} + void Keymap::setConfigDomain(ConfigManager::Domain *dom) { _configDomain = dom; } |