diff options
Diffstat (limited to 'qmk/keyboards/sofle_choc/keymaps/custom/layer_dance.c')
| -rw-r--r-- | qmk/keyboards/sofle_choc/keymaps/custom/layer_dance.c | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/qmk/keyboards/sofle_choc/keymaps/custom/layer_dance.c b/qmk/keyboards/sofle_choc/keymaps/custom/layer_dance.c new file mode 100644 index 0000000..31689c5 --- /dev/null +++ b/qmk/keyboards/sofle_choc/keymaps/custom/layer_dance.c @@ -0,0 +1,46 @@ +#include QMK_KEYBOARD_H +#include "quad_tapdance.h" +#include "layer_dance.h" + +// +// Definition for the layer key +// +// The only one usage is to activate the layer over the keyboard, but there is +// two way of doing it: +// +// The first mode, when hold, is to activate the layer as long as the key is +// pressed. +// The second one is to switch in the layer mode when tapped, in this mode, +// you can go back into the normal layer by a single press on the key. +// + +// Functions that control what our tap dance key does +void tap_dance_layer_finished(tap_dance_state_t *state, void *user_data) { + + tap_dance_layer_t *tap_layer = (tap_dance_layer_t *)user_data; + tap_layer->state = cur_dance(state); + switch (tap_layer->state) { + // Remove the layer with a single tap, this way I always have a key to + // remove the the layer, without knowing the previous state I had. + // + // Here, we control both the keypad or the arrow layers + case TD_SINGLE_TAP: + if (layer_state_is(LAYER_KEYPAD) || layer_state_is(LAYER_ARROW) ) { + layer_clear(); + } else { + layer_on(tap_layer->layer); + } + break; + case TD_SINGLE_HOLD: layer_on(tap_layer->layer); break; + default: break; + } +} + +void tap_dance_layer_reset(tap_dance_state_t *state, void *user_data) { + tap_dance_layer_t *tap_layer = (tap_dance_layer_t *)user_data; + // If the key was held down and now is released then switch off the layer + if (tap_layer->state == TD_SINGLE_HOLD) { + layer_off(tap_layer->layer); + } + tap_layer->state = TD_NONE; +} |
