key_events: look up mappedKey earlier

Do the mappedKey lookup earlier, in handle_key_event, so that if any of
our handlers need to look at the mapped key, they do not have to look it
up themselves. This simplifies plugged hooks considerably, as they can
always assume that the mapped key they receive is correct. They still
receive enough information to do the lookup themselves, though, if they
ever need that.

Additionally, in handle_key_event_default, baseKey is only looked up if
mappedKey was NoKey. This is so that hooks can defer to this function,
via handle_key_event, setting their own mappedKey, without having to
worry about setting a row/col that would map to a special key on the
base layer.

Fixes #39.

Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
pull/41/head
Gergely Nagy 8 years ago
parent 9fff7d8519
commit 67bc556c66

@ -50,6 +50,9 @@ Key lookup_key(byte keymap, byte row, byte col) {
} }
void handle_key_event(Key mappedKey, byte row, byte col, uint8_t currentState, uint8_t previousState) { void handle_key_event(Key mappedKey, byte row, byte col, uint8_t currentState, uint8_t previousState) {
if (mappedKey.raw == Key_NoKey.raw) {
mappedKey = lookup_key(temporary_keymap, row, col);
}
for (byte i = 0; eventHandlers[i] != NULL && i < HOOK_MAX; i++) { for (byte i = 0; eventHandlers[i] != NULL && i < HOOK_MAX; i++) {
custom_handler_t handler = eventHandlers[i]; custom_handler_t handler = eventHandlers[i];
if ((*handler)(mappedKey, row, col, currentState, previousState)) if ((*handler)(mappedKey, row, col, currentState, previousState))
@ -61,10 +64,10 @@ bool handle_key_event_default(Key mappedKey, byte row, byte col, uint8_t current
//for every newly pressed button, figure out what logical key it is and send a key down event //for every newly pressed button, figure out what logical key it is and send a key down event
// for every newly released button, figure out what logical key it is and send a key up event // for every newly released button, figure out what logical key it is and send a key up event
Key baseKey = Key_NoKey;
if (mappedKey.raw == Key_NoKey.raw) { if (mappedKey.raw == Key_NoKey.raw) {
mappedKey = lookup_key(temporary_keymap, row, col); baseKey = lookup_key(primary_keymap, row, col);
} }
Key baseKey = lookup_key(primary_keymap, row, col);
if ((baseKey.flags & SWITCH_TO_KEYMAP if ((baseKey.flags & SWITCH_TO_KEYMAP
|| baseKey.flags & SWITCH_TO_KEYMAP_MOMENTARY)) { || baseKey.flags & SWITCH_TO_KEYMAP_MOMENTARY)) {

Loading…
Cancel
Save