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 | 55 |
1 files changed, 12 insertions, 43 deletions
diff --git a/qmk/keyboards/sofle_choc/keymaps/custom/layer_dance.c b/qmk/keyboards/sofle_choc/keymaps/custom/layer_dance.c index d35d31b..31689c5 100644 --- a/qmk/keyboards/sofle_choc/keymaps/custom/layer_dance.c +++ b/qmk/keyboards/sofle_choc/keymaps/custom/layer_dance.c @@ -13,14 +13,13 @@ // 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. // -static td_tap_t keypad_tap_state = { - .state = TD_NONE -}; // Functions that control what our tap dance key does -void keypad_finished(tap_dance_state_t *state, void *user_data) { - keypad_tap_state.state = cur_dance(state); - switch (keypad_tap_state.state) { +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. // @@ -29,49 +28,19 @@ void keypad_finished(tap_dance_state_t *state, void *user_data) { if (layer_state_is(LAYER_KEYPAD) || layer_state_is(LAYER_ARROW) ) { layer_clear(); } else { - layer_on(LAYER_KEYPAD); - } - break; - case TD_SINGLE_HOLD: layer_on(LAYER_KEYPAD); break; - default: break; - } -} - -void keypad_reset(tap_dance_state_t *state, void *user_data) { - // If the key was held down and now is released then switch off the layer - if (keypad_tap_state.state == TD_SINGLE_HOLD) { - layer_clear(); - } - keypad_tap_state.state = TD_NONE; -} - -// Do the same for the arrow layer. -static td_tap_t arrow_tap_state = { - .state = TD_NONE -}; - -// Functions that control what our tap dance key does -void arrow_finished(tap_dance_state_t *state, void *user_data) { - arrow_tap_state.state = cur_dance(state); - switch (arrow_tap_state.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. - case TD_SINGLE_TAP: - if (layer_state_is(LAYER_KEYPAD) || layer_state_is(LAYER_ARROW) ) { - layer_clear(); - } else { - layer_on(LAYER_ARROW); + layer_on(tap_layer->layer); } break; - case TD_SINGLE_HOLD: layer_on(LAYER_ARROW); break; + case TD_SINGLE_HOLD: layer_on(tap_layer->layer); break; default: break; } } -void arrow_reset(tap_dance_state_t *state, void *user_data) { +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 (arrow_tap_state.state == TD_SINGLE_HOLD) { - layer_clear(); + if (tap_layer->state == TD_SINGLE_HOLD) { + layer_off(tap_layer->layer); } - arrow_tap_state.state = TD_NONE; + tap_layer->state = TD_NONE; } |
