aboutsummaryrefslogtreecommitdiff
path: root/qmk/keyboards/sofle_choc/keymaps/custom/layer_dance.c
diff options
context:
space:
mode:
Diffstat (limited to 'qmk/keyboards/sofle_choc/keymaps/custom/layer_dance.c')
-rw-r--r--qmk/keyboards/sofle_choc/keymaps/custom/layer_dance.c77
1 files changed, 77 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..d35d31b
--- /dev/null
+++ b/qmk/keyboards/sofle_choc/keymaps/custom/layer_dance.c
@@ -0,0 +1,77 @@
+#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.
+//
+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) {
+ // 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(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);
+ }
+ break;
+ case TD_SINGLE_HOLD: layer_on(LAYER_ARROW); break;
+ default: break;
+ }
+}
+
+void arrow_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 (arrow_tap_state.state == TD_SINGLE_HOLD) {
+ layer_clear();
+ }
+ arrow_tap_state.state = TD_NONE;
+}