aboutsummaryrefslogtreecommitdiff
path: root/users/wanleg/tapdances.c
diff options
context:
space:
mode:
Diffstat (limited to 'users/wanleg/tapdances.c')
-rw-r--r--users/wanleg/tapdances.c110
1 files changed, 110 insertions, 0 deletions
diff --git a/users/wanleg/tapdances.c b/users/wanleg/tapdances.c
new file mode 100644
index 000000000..318810b1b
--- /dev/null
+++ b/users/wanleg/tapdances.c
@@ -0,0 +1,110 @@
1//Tap Dance Settings
2#include "wanleg.h"
3
4///// QUAD FUNCTION TAP DANCE GENERAL SETUP SECTION START /////
5///// (no need to edit this section) /////
6//Enums used to clearly convey the state of the tap dance
7enum {
8 SINGLE_TAP = 1,
9 SINGLE_HOLD = 2,
10 DOUBLE_TAP = 3,
11 DOUBLE_HOLD = 4,
12 DOUBLE_SINGLE_TAP = 5 //send SINGLE_TAP twice - NOT DOUBLE_TAP
13 // Add more enums here if you want for triple, quadruple, etc.
14};
15
16typedef struct {
17 bool is_press_action;
18 int state;
19} tap;
20
21int cur_dance (qk_tap_dance_state_t *state) {
22 if (state->count == 1) {
23 //If count = 1, and it has been interrupted - it doesn't matter if it is pressed or not: Send SINGLE_TAP
24 if (state->interrupted || !state->pressed) return SINGLE_TAP;
25 if (state->interrupted) return SINGLE_TAP;
26 else return SINGLE_HOLD;
27 }
28 //If count = 2, and it has been interrupted - assume that user is trying to type the letter associated
29 //with single tap.
30 else if (state->count == 2) {
31 if (state->interrupted) return DOUBLE_SINGLE_TAP;
32 else if (state->pressed) return DOUBLE_HOLD;
33 else return DOUBLE_TAP;
34 }
35 else return 6; //magic number. At some point this method will expand to work for more presses
36}
37///// QUAD FUNCTION TAP DANCE GENERAL SETUP SECTION END /////
38///// QUAD FUNCTION TAP DANCE PERSONALIZATION SECTION START /////
39//instantialize an instance of 'tap' for the 'ENT' tap dance.
40static tap ENTtap_state = {
41 .is_press_action = true,
42 .state = 0
43};
44
45void ENT_finished (qk_tap_dance_state_t *state, void *user_data) {
46 ENTtap_state.state = cur_dance(state);
47 switch (ENTtap_state.state) {
48 case SINGLE_TAP: register_code(KC_SPC); break;
49 case SINGLE_HOLD: register_code(KC_LSFT); break;
50 case DOUBLE_TAP: register_code(KC_ENT); break;
51 case DOUBLE_HOLD: register_code(KC_NO); break; // setting double hold to do nothing (change this if you want)
52 case DOUBLE_SINGLE_TAP: register_code(KC_SPC); unregister_code(KC_SPC); register_code(KC_SPC);
53 //Last case is for fast typing. Assuming your key is `f`:
54 //For example, when typing the word `buffer`, and you want to make sure that you send `ff` and not `Esc`.
55 //In order to type `ff` when typing fast, the next character will have to be hit within the `TAPPING_TERM`, which by default is 200ms.
56 }
57}
58
59void ENT_reset (qk_tap_dance_state_t *state, void *user_data) {
60 switch (ENTtap_state.state) {
61 case SINGLE_TAP: unregister_code(KC_SPC); break;
62 case SINGLE_HOLD: unregister_code(KC_LSFT); break;
63 case DOUBLE_TAP: unregister_code(KC_ENT); break;
64 case DOUBLE_HOLD: unregister_code(KC_NO);
65 case DOUBLE_SINGLE_TAP: unregister_code(KC_SPC);
66 }
67 ENTtap_state.state = 0;
68}
69
70//instanalize an instance of 'tap' for the 'DEL' tap dance.
71static tap DELtap_state = {
72 .is_press_action = true,
73 .state = 0
74};
75
76void DEL_finished (qk_tap_dance_state_t *state, void *user_data) {
77 DELtap_state.state = cur_dance(state);
78 switch (DELtap_state.state) {
79 case SINGLE_TAP: register_code(KC_BSPC); break;
80 case SINGLE_HOLD: register_code(KC_LCTL); break;
81 case DOUBLE_TAP: register_code(KC_DEL); break;
82 case DOUBLE_HOLD: register_code(KC_NO); break;
83 case DOUBLE_SINGLE_TAP: register_code(KC_BSPC); unregister_code(KC_BSPC); register_code(KC_BSPC);
84 }
85}
86
87void DEL_reset (qk_tap_dance_state_t *state, void *user_data) {
88 switch (DELtap_state.state) {
89 case SINGLE_TAP: unregister_code(KC_BSPC); break;
90 case SINGLE_HOLD: unregister_code(KC_LCTL); break;
91 case DOUBLE_TAP: unregister_code(KC_DEL); break;
92 case DOUBLE_HOLD: unregister_code(KC_NO);
93 case DOUBLE_SINGLE_TAP: unregister_code(KC_BSPC);
94 }
95 DELtap_state.state = 0;
96}
97///// QUAD FUNCTION TAP DANCE PERSONALIZATION SECTION END /////
98
99//Tap Dance Definitions
100//THIS SECTION HAS TO BE AT THE END OF THE TAP DANCE SECTION
101qk_tap_dance_action_t tap_dance_actions[] = {
102 [TD_SFT_CAPS] = ACTION_TAP_DANCE_DOUBLE(KC_LSFT, KC_CAPS)
103// Other declarations would go here, separated by commas, if you have them
104 ,[TD_Q_ESC] = ACTION_TAP_DANCE_DOUBLE(KC_Q, KC_ESC)
105 ,[ENT_TAP_DANCE] = ACTION_TAP_DANCE_FN_ADVANCED(NULL, ENT_finished, ENT_reset)
106 ,[DEL_TAP_DANCE] = ACTION_TAP_DANCE_FN_ADVANCED(NULL, DEL_finished, DEL_reset)
107};
108
109//In Layer declaration, add tap dance item in place of a key code
110//TD(TD_SFT_CAPS) \ No newline at end of file