summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGustaf Rydholm <gustaf.rydholm@gmail.com>2022-07-09 01:10:53 +0200
committerGustaf Rydholm <gustaf.rydholm@gmail.com>2022-07-09 01:10:53 +0200
commit73d46a2f1163d5f5469c03c8abf946466a1ebd9c (patch)
tree139988ce722c9995e4f1b259a1c5bdf6d1288f8d
parent2e99d4439308b6ec76ed0408e244cfba036549c0 (diff)
Add custom tap dance
-rw-r--r--aktersnurra/tap_dance.c81
-rw-r--r--aktersnurra/tap_dance.h17
2 files changed, 98 insertions, 0 deletions
diff --git a/aktersnurra/tap_dance.c b/aktersnurra/tap_dance.c
new file mode 100644
index 0000000..265ef0d
--- /dev/null
+++ b/aktersnurra/tap_dance.c
@@ -0,0 +1,81 @@
+#include "tap_dance.h"
+
+static td_state_t td_state;
+
+int cur_dance(qk_tap_dance_state_t *state) {
+ if (state->count == 1) {
+ if (state->interrupted || !state->pressed) {
+ return SINGLE_TAP;
+ } else {
+ return SINGLE_HOLD;
+ }
+ }
+ if (state->count == 2) {
+ return DOUBLE_SINGLE_TAP;
+ } else {
+ return 3;
+ }
+}
+
+void raise_finished(qk_tap_dance_state_t *state, void *user_data) {
+ td_state = cur_dance(state);
+ switch (td_state) {
+ case SINGLE_TAP:
+ register_code16(KC_BSPC);
+ break;
+ case SINGLE_HOLD:
+ layer_on(_RAISE);
+ break;
+ case DOUBLE_SINGLE_TAP:
+ tap_code16(KC_BSPC);
+ register_code16(KC_BSPC);
+ }
+}
+
+void raise_reset(qk_tap_dance_state_t *state, void *user_data) {
+ switch (td_state) {
+ case SINGLE_TAP:
+ unregister_code16(KC_BSPC);
+ break;
+ case SINGLE_HOLD:
+ layer_off(_RAISE);
+ break;
+ case DOUBLE_SINGLE_TAP:
+ unregister_code16(KC_BSPC);
+ }
+}
+
+void lower_finished(qk_tap_dance_state_t *state, void *user_data) {
+ td_state = cur_dance(state);
+ switch (td_state) {
+ case SINGLE_TAP:
+ register_code16(KC_SPC);
+ break;
+ case SINGLE_HOLD:
+ layer_on(_LOWER);
+ break;
+ case DOUBLE_SINGLE_TAP:
+ tap_code16(KC_SPC);
+ register_code16(KC_SPC);
+ }
+}
+
+void lower_reset(qk_tap_dance_state_t *state, void *user_data) {
+ switch (td_state) {
+ case SINGLE_TAP:
+ unregister_code16(KC_SPC);
+ break;
+ case SINGLE_HOLD:
+ layer_off(_LOWER);
+ break;
+ case DOUBLE_SINGLE_TAP:
+ unregister_code16(KC_SPC);
+ }
+}
+
+qk_tap_dance_action_t tap_dance_actions[] = {
+ [M_ESC] = ACTION_TAP_DANCE_DOUBLE(KC_M, KC_ESC),
+ [TD_RAISE] =
+ ACTION_TAP_DANCE_FN_ADVANCED(NULL, raise_finished, raise_reset),
+ [TD_LOWER] =
+ ACTION_TAP_DANCE_FN_ADVANCED(NULL, lower_finished, lower_reset)};
diff --git a/aktersnurra/tap_dance.h b/aktersnurra/tap_dance.h
new file mode 100644
index 0000000..5c7ec14
--- /dev/null
+++ b/aktersnurra/tap_dance.h
@@ -0,0 +1,17 @@
+#pragma once
+
+#include QMK_KEYBOARD_H
+
+typedef enum { _COLEMAK_DH, _LOWER, _RAISE } layers;
+
+typedef enum { SINGLE_TAP, SINGLE_HOLD, DOUBLE_SINGLE_TAP } td_state_t;
+
+typedef enum { M_ESC, TD_LOWER, TD_RAISE } tap_dances;
+
+int cur_dance(qk_tap_dance_state_t *state);
+
+void raise_finished(qk_tap_dance_state_t *state, void *user_data);
+void raise_reset(qk_tap_dance_state_t *state, void *user_data);
+
+void lower_finished(qk_tap_dance_state_t *state, void *user_data);
+void lower_reset(qk_tap_dance_state_t *state, void *user_data);