From 12710d6cc0e8ef0001b1c19504ddbdbcedd6ff5c Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Sat, 24 Dec 2016 12:18:31 +0100 Subject: [PATCH] Layer: Fix the momentary layer changing `keymapEntry.rawKey` contains the target layer, but offset by `MOMENTARY_OFFSET`. That value must be subtracted from the value before comparing it to anything, or switching to another layer. Signed-off-by: Gergely Nagy --- src/layers.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/layers.cpp b/src/layers.cpp index 0e8d7662..9444b2b4 100644 --- a/src/layers.cpp +++ b/src/layers.cpp @@ -6,22 +6,24 @@ static uint32_t LayerState; static void handle_keymap_key_event(Key keymapEntry, uint8_t keyState) { if (keymapEntry.rawKey >= MOMENTARY_OFFSET) { + uint8_t target = keymapEntry.rawKey - MOMENTARY_OFFSET; + if (key_toggled_on(keyState)) { - if ( keymapEntry.rawKey == KEYMAP_NEXT) { + if ( target == KEYMAP_NEXT) { Layer.next(); - } else if ( keymapEntry.rawKey == KEYMAP_PREVIOUS) { + } else if ( target == KEYMAP_PREVIOUS) { Layer.previous(); } else { - Layer.on(keymapEntry.rawKey - MOMENTARY_OFFSET); + Layer.on(target); } } if (key_toggled_off(keyState)) { - if ( keymapEntry.rawKey == KEYMAP_NEXT) { + if ( target == KEYMAP_NEXT) { Layer.previous(); - } else if ( keymapEntry.rawKey == KEYMAP_PREVIOUS) { + } else if ( target == KEYMAP_PREVIOUS) { Layer.next(); } else { - Layer.off(keymapEntry.rawKey - MOMENTARY_OFFSET); + Layer.off(target); } }