layers: Add a MoveToLayer(n) key

While `ShiftToLayer` and `LockLayer` activate the given layer, and keep all
others active as well, `MoveToLayer` activates the given layer, and deactivates
all others. This allows one to have discrete layers that stand on their own,
without any other layers interfering.

Basically, this is a different way to work with layers, a less powerful, but
also simpler one.

Fixes #564.

Signed-off-by: Gergely Nagy <algernon@keyboard.io>
pull/779/head
Gergely Nagy 5 years ago
parent 5fcdd720cb
commit 2b0e90c592
No known key found for this signature in database
GPG Key ID: AC1E90BAC433F68F

@ -20,7 +20,9 @@
#include "kaleidoscope_internal/deprecations.h"
static const uint8_t LAYER_SHIFT_OFFSET = 42;
static const uint8_t LAYER_OP_OFFSET = 42;
static const uint8_t LAYER_SHIFT_OFFSET = LAYER_OP_OFFSET;
static const uint8_t LAYER_MOVE_OFFSET = LAYER_SHIFT_OFFSET + LAYER_OP_OFFSET;;
#define KEYMAP_0 0
#define KEYMAP_1 1
@ -68,3 +70,10 @@ static const uint8_t LAYER_SHIFT_OFFSET = 42;
* value declared previously.
*/
#define ShiftToLayer(n) Key(n + LAYER_SHIFT_OFFSET, KEY_FLAGS | SYNTHETIC | SWITCH_TO_KEYMAP)
/** Move to layer `n`.
*
* Moving to a layer disables all other layers. Unlike locking and shifting to,
* this is a one-way operation.
*/
#define MoveToLayer(n) Key(n + LAYER_MOVE_OFFSET, KEY_FLAGS | SYNTHETIC | SWITCH_TO_KEYMAP)

@ -45,7 +45,11 @@ uint8_t Layer_::active_layers_[Runtime.device().numKeys()];
Layer_::GetKeyFunction Layer_::getKey = &Layer_::getKeyFromPROGMEM;
void Layer_::handleKeymapKeyswitchEvent(Key keymapEntry, uint8_t keyState) {
if (keymapEntry.getKeyCode() >= LAYER_SHIFT_OFFSET) {
if (keymapEntry.getKeyCode() >= LAYER_MOVE_OFFSET) {
if (keyToggledOn(keyState)) {
move(keymapEntry.getKeyCode() - LAYER_MOVE_OFFSET);
}
} else if (keymapEntry.getKeyCode() >= LAYER_SHIFT_OFFSET) {
uint8_t target = keymapEntry.getKeyCode() - LAYER_SHIFT_OFFSET;
switch (target) {

Loading…
Cancel
Save