diff --git a/src/kaleidoscope/key_defs_keymaps.h b/src/kaleidoscope/key_defs_keymaps.h index aa341e15..21698eab 100644 --- a/src/kaleidoscope/key_defs_keymaps.h +++ b/src/kaleidoscope/key_defs_keymaps.h @@ -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) diff --git a/src/kaleidoscope/layers.cpp b/src/kaleidoscope/layers.cpp index 1010c26a..a3442b03 100644 --- a/src/kaleidoscope/layers.cpp +++ b/src/kaleidoscope/layers.cpp @@ -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) {