aboutsummaryrefslogtreecommitdiff
path: root/backends/keymapper
diff options
context:
space:
mode:
Diffstat (limited to 'backends/keymapper')
-rw-r--r--backends/keymapper/hardware-input.cpp36
-rw-r--r--backends/keymapper/hardware-input.h53
-rw-r--r--backends/keymapper/keymap.cpp21
-rw-r--r--backends/keymapper/keymapper.cpp4
-rw-r--r--backends/keymapper/keymapper.h5
-rw-r--r--backends/keymapper/remap-dialog.cpp6
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 HardwareInput *>::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 HardwareInput *>::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<const HardwareInput *> &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<KeyState, Action *>::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<MapRecord>& 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<const HardwareInput *>::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() + ")"};