From 4ee1a3aceae7d68c89513f7d122606acbceb1e7c Mon Sep 17 00:00:00 2001 From: Tarek Soliman Date: Fri, 24 Feb 2012 13:55:48 -0600 Subject: KEYMAPPER: Add non-key inputs to HardwareInput --- backends/keymapper/hardware-input.cpp | 36 +++++++++++++++++++----- backends/keymapper/hardware-input.h | 53 +++++++++++++++++++++++++++-------- backends/keymapper/keymap.cpp | 21 ++++++++------ backends/keymapper/keymapper.cpp | 4 +++ backends/keymapper/keymapper.h | 5 ++++ backends/keymapper/remap-dialog.cpp | 6 +++- 6 files changed, 97 insertions(+), 28 deletions(-) diff --git a/backends/keymapper/hardware-input.cpp b/backends/keymapper/hardware-input.cpp index a09f0b54fc..d1f8822ac0 100644 --- a/backends/keymapper/hardware-input.cpp +++ b/backends/keymapper/hardware-input.cpp @@ -209,16 +209,33 @@ const HardwareInput *HardwareInputSet::findHardwareInput(String id) const { return 0; } +const HardwareInput *HardwareInputSet::findHardwareInput(const HardwareInputCode code) const { + List::const_iterator it; + + for (it = _inputs.begin(); it != _inputs.end(); ++it) { + const HardwareInput *entry = *it; + if (entry->type == kHardwareInputTypeGeneric && entry->inputCode == code) + return entry; + } + return 0; +} + const HardwareInput *HardwareInputSet::findHardwareInput(const KeyState& keystate) const { List::const_iterator it; for (it = _inputs.begin(); it != _inputs.end(); ++it) { - if ((*it)->key == keystate) - return (*it); + const HardwareInput *entry = *it; + if (entry->type == kHardwareInputTypeKeyboard && entry->key == keystate) + return entry; } return 0; } +void HardwareInputSet::addHardwareInputs(const HardwareInputTableEntry inputs[]) { + for (const HardwareInputTableEntry *entry = inputs; entry->hwId; ++entry) + addHardwareInput(new HardwareInput(entry->hwId, entry->code, entry->desc)); +} + void HardwareInputSet::addHardwareInputs(const KeyTableEntry keys[], const ModifierTableEntry modifiers[]) { const KeyTableEntry *key; const ModifierTableEntry *mod; @@ -247,10 +264,6 @@ void HardwareInputSet::addHardwareInputs(const KeyTableEntry keys[], const Modif } } -void HardwareInputSet::addHardwareInputs(const KeyTableEntry keys[]) { - addHardwareInputs(keys, defaultModifiers); -} - void HardwareInputSet::removeHardwareInput(const HardwareInput *input) { if (!input) return; @@ -259,7 +272,16 @@ void HardwareInputSet::removeHardwareInput(const HardwareInput *input) { for (it = _inputs.begin(); it != _inputs.end(); ++it) { const HardwareInput *entry = (*it); - if (entry->id == input->id || entry->key == input->key) { + bool match = false; + if (entry->id == input->id) + match = true; + else if (input->type == entry->type) { + if (input->type == kHardwareInputTypeGeneric && input->inputCode == entry->inputCode) + match = true; + else if (input->type == kHardwareInputTypeKeyboard && input->key == entry->key) + match = true; + } + if (match) { debug(7, "Removing hardware input [%s] (%s) because it matches [%s] (%s)", entry->id.c_str(), entry->description.c_str(), input->id.c_str(), input->description.c_str()); delete entry; _inputs.erase(it); diff --git a/backends/keymapper/hardware-input.h b/backends/keymapper/hardware-input.h index 9396765bbe..51d4accb5b 100644 --- a/backends/keymapper/hardware-input.h +++ b/backends/keymapper/hardware-input.h @@ -34,6 +34,15 @@ namespace Common { +typedef uint32 HardwareInputCode; + +enum HardwareInputType { + /** Input that sends single events */ + kHardwareInputTypeGeneric, + /** Input that usually send -up and -down events */ + kHardwareInputTypeKeyboard +}; + /** * Describes an available hardware input */ @@ -44,14 +53,33 @@ struct HardwareInput { /** Human readable description */ String description; + const HardwareInputType type; + /** - * The KeyState that is generated by the back-end - * when this hardware key is pressed. - */ + * A platform specific unique identifier for an input event + * generated when this input is triggered. + * This is only relevant when type == kHardwareInputTypeGeneric + */ + HardwareInputCode inputCode; + + /** + * The KeyState that is generated by the back-end + * when this hardware key is pressed. + * This is only relevant when type == kHardwareInputTypeKeyboard + */ KeyState key; - HardwareInput(String i, KeyState ky = KeyState(), String desc = "") - : id(i), key(ky), description(desc) { } + HardwareInput(String i, HardwareInputCode ic = 0, String desc = "") + : id(i), inputCode(ic), description(desc), type(kHardwareInputTypeGeneric) { } + + HardwareInput(String i, KeyState ky, String desc = "") + : id(i), key(ky), description(desc), type(kHardwareInputTypeKeyboard) { } +}; + +struct HardwareInputTableEntry { + const char *hwId; + HardwareInputCode code; + const char *desc; }; /** @@ -97,6 +125,8 @@ public: const HardwareInput *findHardwareInput(String id) const; + const HardwareInput *findHardwareInput(const HardwareInputCode code) const; + const HardwareInput *findHardwareInput(const KeyState& keystate) const; const List &getHardwareInputs() const { return _inputs; } @@ -104,18 +134,17 @@ public: uint size() const { return _inputs.size(); } /** - * Add hardware inputs to the set out of key and modifier tables. - * @param keys table of available keys - * @param modifiers table of available modifiers + * Add hardware inputs to the set out of a table. + * @param inputs table of available inputs */ - void addHardwareInputs(const KeyTableEntry keys[], const ModifierTableEntry modifiers[]); + void addHardwareInputs(const HardwareInputTableEntry inputs[]); /** - * Add hardware inputs to the set out of a key table. - * The default modifiers are applied to the key entries + * Add hardware inputs to the set out of key and modifier tables. * @param keys table of available keys + * @param modifiers table of available modifiers */ - void addHardwareInputs(const KeyTableEntry keys[]); + void addHardwareInputs(const KeyTableEntry keys[], const ModifierTableEntry modifiers[]); void removeHardwareInput(const HardwareInput *input); diff --git a/backends/keymapper/keymap.cpp b/backends/keymapper/keymap.cpp index 8ea975c927..f5155ce1b5 100644 --- a/backends/keymapper/keymap.cpp +++ b/backends/keymapper/keymap.cpp @@ -39,7 +39,8 @@ Keymap::Keymap(const Keymap& km) : _actions(km._actions), _keymap(), _configDoma for (it = _actions.begin(); it != _actions.end(); ++it) { const HardwareInput *hwInput = (*it)->getMappedInput(); - if (hwInput) { + //FIXME: Add support for kHardwareInputTypeGeneric + if (hwInput && hwInput->type == kHardwareInputTypeKeyboard) { _keymap[hwInput->key] = *it; } } @@ -62,21 +63,25 @@ void Keymap::addAction(Action *action) { void Keymap::registerMapping(Action *action, const HardwareInput *hwInput) { HashMap::iterator it; - it = _keymap.find(hwInput->key); + //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) { - it->_value->mapInput(0); + // if key is already mapped to a different action then un-map it + if (it != _keymap.end() && action != it->_value) { + it->_value->mapInput(0); + } + _keymap[hwInput->key] = action; } - - _keymap[hwInput->key] = action; } void Keymap::unregisterMapping(Action *action) { const HardwareInput *hwInput = action->getMappedInput(); if (hwInput) { - _keymap.erase(hwInput->key); + //FIXME: Add support for kHardwareInputTypeGeneric + if (hwInput->type == kHardwareInputTypeKeyboard) + _keymap.erase(hwInput->key); } } diff --git a/backends/keymapper/keymapper.cpp b/backends/keymapper/keymapper.cpp index bda4cd47da..4742886207 100644 --- a/backends/keymapper/keymapper.cpp +++ b/backends/keymapper/keymapper.cpp @@ -295,6 +295,10 @@ const HardwareInput *Keymapper::findHardwareInput(const KeyState& key) { return (_hardwareInputs) ? _hardwareInputs->findHardwareInput(key) : 0; } +const HardwareInput *Keymapper::findHardwareInput(const HardwareInputCode code) { + return (_hardwareInputs) ? _hardwareInputs->findHardwareInput(code) : 0; +} + } // End of namespace Common #endif // #ifdef ENABLE_KEYMAPPER diff --git a/backends/keymapper/keymapper.h b/backends/keymapper/keymapper.h index daa746f379..9a80911dbf 100644 --- a/backends/keymapper/keymapper.h +++ b/backends/keymapper/keymapper.h @@ -172,6 +172,11 @@ public: */ const HardwareInput *findHardwareInput(const KeyState& key); + /** + * Return a HardwareInput pointer for the given input code + */ + const HardwareInput *findHardwareInput(const HardwareInputCode code); + Domain& getGlobalDomain() { return _globalDomain; } Domain& getGameDomain() { return _gameDomain; } const Stack& getActiveStack() const { return _activeMaps; } diff --git a/backends/keymapper/remap-dialog.cpp b/backends/keymapper/remap-dialog.cpp index dab295219a..29f0174aad 100644 --- a/backends/keymapper/remap-dialog.cpp +++ b/backends/keymapper/remap-dialog.cpp @@ -354,9 +354,13 @@ void RemapDialog::loadKeymap() { Keymapper::MapRecord mr = activeKeymaps[i]; debug(3, "RemapDialog::loadKeymap keymap: %s", mr.keymap->getName().c_str()); List::iterator inputIt = freeInputs.begin(); + const HardwareInput *input = *inputIt; while (inputIt != freeInputs.end()) { - Action *act = mr.keymap->getMappedAction((*inputIt)->key); + Action *act = 0; + // FIXME: Add support for kHardwareInputTypeGeneric + if (input->type == kHardwareInputTypeKeyboard) + act = mr.keymap->getMappedAction(input->key); if (act) { ActionInfo info = {act, true, act->description + " (" + mr.keymap->getName() + ")"}; -- cgit v1.2.3