From 67bc556c6640273b4dde4bce430131c36fff7a85 Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Wed, 16 Nov 2016 21:57:17 +0100 Subject: [PATCH] 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 --- src/key_events.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/key_events.cpp b/src/key_events.cpp index 09c24aa6..a21f18c8 100644 --- a/src/key_events.cpp +++ b/src/key_events.cpp @@ -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) { + if (mappedKey.raw == Key_NoKey.raw) { + mappedKey = lookup_key(temporary_keymap, row, col); + } for (byte i = 0; eventHandlers[i] != NULL && i < HOOK_MAX; i++) { custom_handler_t handler = eventHandlers[i]; 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 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) { - 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 || baseKey.flags & SWITCH_TO_KEYMAP_MOMENTARY)) {