aboutsummaryrefslogtreecommitdiff
path: root/backends/keymapper
diff options
context:
space:
mode:
Diffstat (limited to 'backends/keymapper')
-rw-r--r--backends/keymapper/hardware-key.h62
-rw-r--r--backends/keymapper/keymapper.cpp4
-rw-r--r--backends/keymapper/keymapper.h5
-rw-r--r--backends/keymapper/remap-dialog.cpp6
-rw-r--r--backends/keymapper/types.h1
5 files changed, 76 insertions, 2 deletions
diff --git a/backends/keymapper/hardware-key.h b/backends/keymapper/hardware-key.h
index 8ddeada51e..34631a9484 100644
--- a/backends/keymapper/hardware-key.h
+++ b/backends/keymapper/hardware-key.h
@@ -64,6 +64,29 @@ struct HardwareKey {
}
};
+/**
+* Describes an available hardware modifier
+*/
+struct HardwareMod {
+ /** unique id used for saving/loading to config */
+ char hwModId[HWKEY_ID_SIZE];
+
+ /** Human readable description */
+ String description;
+
+ /**
+ * The modifier flags that are generated by the
+ * back-end when this modifier key is pressed.
+ */
+ byte modFlags;
+
+ HardwareMod(const char *i, byte mf, String desc = "")
+ : modFlags(mf), description(desc) {
+ assert(i);
+ strncpy(hwModId, i, HWKEY_ID_SIZE);
+ }
+};
+
/**
* Simple class to encapsulate a device's set of HardwareKeys.
@@ -80,6 +103,11 @@ public:
delete *it;
}
+ void addHardwareMod(HardwareMod *mod) {
+ checkForMod(mod);
+ _mods.push_back(mod);
+ }
+
void addHardwareKey(HardwareKey *key) {
checkForKey(key);
_keys.push_back(key);
@@ -99,7 +127,27 @@ public:
List<const HardwareKey*>::const_iterator it;
for (it = _keys.begin(); it != _keys.end(); it++) {
- if ((*it)->key == keystate)
+ if ((*it)->key.keycode == keystate.keycode)
+ return (*it);
+ }
+ return 0;
+ }
+
+ const HardwareMod *findHardwareMod(const char *id) const {
+ List<const HardwareMod*>::const_iterator it;
+
+ for (it = _mods.begin(); it != _mods.end(); it++) {
+ if (strncmp((*it)->hwModId, id, HWKEY_ID_SIZE) == 0)
+ return (*it);
+ }
+ return 0;
+ }
+
+ const HardwareMod *findHardwareMod(const KeyState& keystate) const {
+ List<const HardwareMod*>::const_iterator it;
+
+ for (it = _mods.begin(); it != _mods.end(); it++) {
+ if ((*it)->modFlags == keystate.flags)
return (*it);
}
return 0;
@@ -127,7 +175,19 @@ private:
}
}
+ void checkForMod(HardwareMod *mod) {
+ List<const HardwareMod*>::iterator it;
+
+ for (it = _mods.begin(); it != _mods.end(); it++) {
+ if (strncmp((*it)->hwModId, mod->hwModId, HWKEY_ID_SIZE) == 0)
+ error("Error adding HardwareMod '%s' - id of %s already in use!", mod->description.c_str(), mod->hwModId);
+ else if ((*it)->modFlags == mod->modFlags)
+ error("Error adding HardwareMod '%s' - modFlags already in use!", mod->description.c_str());
+ }
+ }
+
List<const HardwareKey*> _keys;
+ List<const HardwareMod*> _mods;
};
diff --git a/backends/keymapper/keymapper.cpp b/backends/keymapper/keymapper.cpp
index c0c454168c..a121ebafee 100644
--- a/backends/keymapper/keymapper.cpp
+++ b/backends/keymapper/keymapper.cpp
@@ -272,6 +272,10 @@ const HardwareKey *Keymapper::findHardwareKey(const KeyState& key) {
return (_hardwareKeys) ? _hardwareKeys->findHardwareKey(key) : 0;
}
+const HardwareMod *Keymapper::findHardwareMod(const KeyState& key) {
+ return (_hardwareKeys) ? _hardwareKeys->findHardwareMod(key) : 0;
+}
+
} // end of namespace Common
#endif // #ifdef ENABLE_KEYMAPPER
diff --git a/backends/keymapper/keymapper.h b/backends/keymapper/keymapper.h
index f492882ca2..af3314f8f5 100644
--- a/backends/keymapper/keymapper.h
+++ b/backends/keymapper/keymapper.h
@@ -170,6 +170,11 @@ public:
*/
const HardwareKey *findHardwareKey(const KeyState& key);
+ /**
+ * Return a HardwareMod pointer for the given key state
+ */
+ const HardwareMod *findHardwareMod(const KeyState& key);
+
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 0440acdd0a..9341c82747 100644
--- a/backends/keymapper/remap-dialog.cpp
+++ b/backends/keymapper/remap-dialog.cpp
@@ -239,11 +239,15 @@ void RemapDialog::handleKeyDown(Common::KeyState state) {
void RemapDialog::handleKeyUp(Common::KeyState state) {
if (_activeRemapAction) {
const HardwareKey *hwkey = _keymapper->findHardwareKey(state);
+ const HardwareMod *hwmod = _keymapper->findHardwareMod(state);
debug(0, "Key: %d, %d (%c), %x", state.keycode, state.ascii, (state.ascii ? state.ascii : ' '), state.flags);
if (hwkey) {
- _activeRemapAction->mapKey(hwkey);
+ HardwareKey *temphwkey = new HardwareKey(*hwkey);
+ temphwkey->description = hwkey->description;
+ temphwkey->key.flags = hwmod->modFlags;
+ _activeRemapAction->mapKey(temphwkey);
_activeRemapAction->getParent()->saveMappings();
_changes = true;
stopRemapping();
diff --git a/backends/keymapper/types.h b/backends/keymapper/types.h
index 7ad4c0e538..004a90bfcd 100644
--- a/backends/keymapper/types.h
+++ b/backends/keymapper/types.h
@@ -43,6 +43,7 @@ enum KeyType {
kTriggerRightKeyType,
kStartKeyType,
kSelectKeyType,
+// kModiferKeyType,
/* ... */
kKeyTypeMax