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 <algernon@madhouse-project.org>
pull/57/head
Gergely Nagy 8 years ago
parent 7adf80dacc
commit 12710d6cc0

@ -6,22 +6,24 @@ static uint32_t LayerState;
static void handle_keymap_key_event(Key keymapEntry, uint8_t keyState) { static void handle_keymap_key_event(Key keymapEntry, uint8_t keyState) {
if (keymapEntry.rawKey >= MOMENTARY_OFFSET) { if (keymapEntry.rawKey >= MOMENTARY_OFFSET) {
uint8_t target = keymapEntry.rawKey - MOMENTARY_OFFSET;
if (key_toggled_on(keyState)) { if (key_toggled_on(keyState)) {
if ( keymapEntry.rawKey == KEYMAP_NEXT) { if ( target == KEYMAP_NEXT) {
Layer.next(); Layer.next();
} else if ( keymapEntry.rawKey == KEYMAP_PREVIOUS) { } else if ( target == KEYMAP_PREVIOUS) {
Layer.previous(); Layer.previous();
} else { } else {
Layer.on(keymapEntry.rawKey - MOMENTARY_OFFSET); Layer.on(target);
} }
} }
if (key_toggled_off(keyState)) { if (key_toggled_off(keyState)) {
if ( keymapEntry.rawKey == KEYMAP_NEXT) { if ( target == KEYMAP_NEXT) {
Layer.previous(); Layer.previous();
} else if ( keymapEntry.rawKey == KEYMAP_PREVIOUS) { } else if ( target == KEYMAP_PREVIOUS) {
Layer.next(); Layer.next();
} else { } else {
Layer.off(keymapEntry.rawKey - MOMENTARY_OFFSET); Layer.off(target);
} }
} }

Loading…
Cancel
Save