layers: Code refactoring

Refactor the momentary layer handling part of `handleKeymapKeyswitchEvent`.
Instead of a bunch of ifs that are increasingly hard to follow, use a switch
based on the target layer, and branch out depending on `keyState` from there.

Makes it easier to follow what happens.

Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
pull/175/head
Gergely Nagy 7 years ago
parent b218143faf
commit c88062a243

@ -12,32 +12,32 @@ static void handleKeymapKeyswitchEvent(Key keymapEntry, uint8_t keyState) {
if (keymapEntry.keyCode >= MOMENTARY_OFFSET) { if (keymapEntry.keyCode >= MOMENTARY_OFFSET) {
uint8_t target = keymapEntry.keyCode - MOMENTARY_OFFSET; uint8_t target = keymapEntry.keyCode - MOMENTARY_OFFSET;
if (keyToggledOn(keyState)) { switch (target) {
if (target == KEYMAP_NEXT) { case KEYMAP_NEXT:
if (keyToggledOn(keyState))
Layer.next(); Layer.next();
} else if (target == KEYMAP_PREVIOUS) { else if (keyToggledOff(keyState))
Layer.previous(); Layer.previous();
} else { break;
Layer.on(target);
} case KEYMAP_PREVIOUS:
} else if (keyIsPressed(keyState) && if (keyToggledOn(keyState))
target != KEYMAP_NEXT &&
target != KEYMAP_PREVIOUS) {
if (!Layer.isOn(target))
Layer.on(target);
}
if (keyToggledOff(keyState)) {
if (target == KEYMAP_NEXT) {
Layer.previous(); Layer.previous();
} else if (target == KEYMAP_PREVIOUS) { else if (keyToggledOff(keyState))
Layer.next(); Layer.next();
} else { break;
default:
if (keyIsPressed(keyState)) {
if (!Layer.isOn(target))
Layer.on(target);
} else if (keyToggledOff(keyState)) {
Layer.off(target); Layer.off(target);
} }
break;
} }
// switch keymap and stay there
} else if (keyToggledOn(keyState)) { } else if (keyToggledOn(keyState)) {
// switch keymap and stay there
if (Layer.isOn(keymapEntry.keyCode) && keymapEntry.keyCode) if (Layer.isOn(keymapEntry.keyCode) && keymapEntry.keyCode)
Layer.off(keymapEntry.keyCode); Layer.off(keymapEntry.keyCode);
else else

Loading…
Cancel
Save