aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFilippos Karapetis2011-12-30 13:59:05 +0200
committerFilippos Karapetis2011-12-30 13:59:55 +0200
commita473934abd2dc4d402963c6f43cec4147ab71e82 (patch)
tree09379ce18975b206f6941ce52e437fbd41126aaa
parentadb53422471386b4eb3551fe15a489bcd88b6571 (diff)
downloadscummvm-rg350-a473934abd2dc4d402963c6f43cec4147ab71e82.tar.gz
scummvm-rg350-a473934abd2dc4d402963c6f43cec4147ab71e82.tar.bz2
scummvm-rg350-a473934abd2dc4d402963c6f43cec4147ab71e82.zip
COMMON: Perform some keymapper-related changes to the KeyState struct
The == operator in KeyState should not be checking for sticky modifier keys. This allows the keymapper's defined actions to function correctly in desktop platforms, when sticky modifier keys such as caps lock and num lock are turned on. Also, added some sanity checks to hasFlags() and enums for sticky and non-sticky keys
-rw-r--r--backends/keymapper/hardware-key.h2
-rw-r--r--common/keyboard.h21
2 files changed, 17 insertions, 6 deletions
diff --git a/backends/keymapper/hardware-key.h b/backends/keymapper/hardware-key.h
index daa853df08..32df042525 100644
--- a/backends/keymapper/hardware-key.h
+++ b/backends/keymapper/hardware-key.h
@@ -97,7 +97,7 @@ public:
List<const HardwareKey*>::const_iterator it;
for (it = _keys.begin(); it != _keys.end(); it++) {
- if (keystate.keycode == (*it)->key.keycode && keystate.hasFlags((*it)->key.flags))
+ if ((*it)->key == keystate)
return (*it);
}
return 0;
diff --git a/common/keyboard.h b/common/keyboard.h
index ead6ed427b..2fd6b43082 100644
--- a/common/keyboard.h
+++ b/common/keyboard.h
@@ -224,11 +224,14 @@ enum {
KBD_CTRL = 1 << 0,
KBD_ALT = 1 << 1,
KBD_SHIFT = 1 << 2,
+ KBD_NON_STICKY = (KBD_CTRL|KBD_ALT|KBD_SHIFT),
// Sticky modifier flags
KBD_NUM = 1 << 3,
KBD_CAPS = 1 << 4,
- KBD_SCRL = 1 << 5
+ KBD_SCRL = 1 << 5,
+ KBD_STICKY = (KBD_NUM|KBD_CAPS|KBD_SCRL)
+
};
/**
@@ -281,19 +284,27 @@ struct KeyState {
/**
* Check whether the non-sticky flags are *exactly* as specified by f.
- * This ignors the sticky flags (KBD_NUM, KBD_CAPS, KBD_SCRL).
+ * This ignores the sticky flags (KBD_NUM, KBD_CAPS, KBD_SCRL).
+ * Sticky flags should never be passed to this function.
* If you just want to check whether a modifier flag is set, just bit-and
* the flag. E.g. to check whether the control key modifier is set,
* you can write
* if (keystate.flags & KBD_CTRL) { ... }
*/
bool hasFlags(byte f) const {
- return f == (flags & ~(KBD_NUM|KBD_CAPS|KBD_SCRL));
+ assert (!(f & KBD_STICKY));
+ return f == (flags & ~KBD_STICKY);
}
+ /**
+ * Check if two key states are equal. This implementation ignores the state
+ * of the sticky flags (caps lock, num lock, scroll lock) completely. This
+ * functionality is currently only used by the keymapper.
+ */
bool operator==(const KeyState &x) const {
- // intentionally ignore ascii
- return keycode == x.keycode && flags == x.flags;
+ // Intentionally ignore ASCII, as the keycode and non-sticky flag
+ // combination should suffice.
+ return keycode == x.keycode && hasFlags(x.flags & ~KBD_STICKY);
}
};