aboutsummaryrefslogtreecommitdiff
path: root/backends/keymapper/hardware-key.h
diff options
context:
space:
mode:
Diffstat (limited to 'backends/keymapper/hardware-key.h')
-rw-r--r--backends/keymapper/hardware-key.h62
1 files changed, 61 insertions, 1 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;
};