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.h108
1 files changed, 103 insertions, 5 deletions
diff --git a/backends/keymapper/hardware-key.h b/backends/keymapper/hardware-key.h
index 8ddeada51e..70168def2d 100644
--- a/backends/keymapper/hardware-key.h
+++ b/backends/keymapper/hardware-key.h
@@ -31,12 +31,47 @@
#ifdef ENABLE_KEYMAPPER
#include "backends/keymapper/types.h"
+#include "common/str.h"
+#include "common/keyboard.h"
+#include "common/list.h"
+#include "common/util.h"
namespace Common {
#define HWKEY_ID_SIZE (30)
+
+// Structure for describing specific key+modifier combos mapped to actions,
+// to allow for modifiers to work properly without having to define the whole
+// hardware key set an additional time for each possible modifier combination
+struct ActionKey {
+ KeyCode keycode;
+ byte flags;
+
+ ActionKey () {
+ keycode = KEYCODE_INVALID;
+ flags = 0;
+ }
+
+ ActionKey (const KeyState &key) {
+ keycode = key.keycode;
+ flags = key.flags;
+ }
+
+
+ ActionKey (KeyCode ky, byte f) {
+ keycode = ky;
+ flags = f;
+ }
+
+ bool operator ==(const ActionKey &x) const {
+ return keycode == x.keycode && flags == x.flags;
+ }
+
+};
+
+
/**
* Describes an available hardware key
*/
@@ -51,19 +86,45 @@ struct HardwareKey {
* The KeyState that is generated by the back-end
* when this hardware key is pressed.
*/
- KeyState key;
+ ActionKey key;
KeyType type;
ActionType preferredAction;
- HardwareKey(const char *i, KeyState ky = KeyState(), String desc = "",
+ // Mask of modifiers that can possibly apply to this key.
+ byte modMask;
+
+ HardwareKey(const char *i, ActionKey ky = ActionKey(), String desc = "", byte mods = ~0,
KeyType typ = kGenericKeyType, ActionType prefAct = kGenericActionType)
- : key(ky), description(desc), type(typ), preferredAction(prefAct) {
+ : key(ky), description(desc), type(typ), preferredAction(prefAct), modMask(mods) {
assert(i);
strncpy(hwKeyId, i, HWKEY_ID_SIZE);
}
};
+/**
+* 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 +141,11 @@ public:
delete *it;
}
+ void addHardwareMod(HardwareMod *mod) {
+ checkForMod(mod);
+ _mods.push_back(mod);
+ }
+
void addHardwareKey(HardwareKey *key) {
checkForKey(key);
_keys.push_back(key);
@@ -95,11 +161,31 @@ public:
return 0;
}
- const HardwareKey *findHardwareKey(const KeyState& keystate) const {
+ const HardwareKey *findHardwareKey(const ActionKey& keystate) const {
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 ActionKey& 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 +213,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;
};