-
Notifications
You must be signed in to change notification settings - Fork 0
/
tapdance.h
154 lines (136 loc) · 4.04 KB
/
tapdance.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#include QMK_KEYBOARD_H
#include "keymap.h"
typedef struct {
bool is_press_action;
uint8_t state;
} tap;
enum {
SINGLE_TAP = 1,
SINGLE_HOLD,
DOUBLE_TAP,
DOUBLE_HOLD,
DOUBLE_SINGLE_TAP, // Send two single taps
};
// Tap dance enums
enum {
SL_HLP,
SEMI_,
B_F_DEL
};
uint8_t cur_dance(qk_tap_dance_state_t *state);
// =============================================================================
// TAP DANCE SECTION
// =============================================================================
uint8_t cur_dance(qk_tap_dance_state_t *state) {
if (state->count == 1) {
if (state->interrupted || !state->pressed) return SINGLE_TAP;
else return SINGLE_HOLD;
} else if (state->count == 2) {
if (state->interrupted) return DOUBLE_SINGLE_TAP;
else if (state->pressed) return DOUBLE_HOLD;
else return DOUBLE_TAP;
} else return 8;
}
// Create an instance of 'tap' for the 'x' tap dance.
static tap help_tap_state = {
.is_press_action = true,
.state = 0
};
void help_finished(qk_tap_dance_state_t *state, void *user_data) {
help_tap_state.state = cur_dance(state);
switch (help_tap_state.state) {
case SINGLE_TAP:
register_code(KC_SLSH);
break;
case DOUBLE_TAP:
register_code(KC_LCMD);
register_code(KC_LSFT);
register_code(KC_SLSH);
}
}
void help_reset(qk_tap_dance_state_t *state, void *user_data) {
switch (help_tap_state.state) {
case SINGLE_TAP:
unregister_code(KC_SLSH);
break;
case DOUBLE_TAP:
unregister_code(KC_LCMD);
unregister_code(KC_LSFT);
unregister_code(KC_SLSH);
}
help_tap_state.state = 0;
}
// Create an instance of 'tap' for the 'x' tap dance.
static tap semi_tap_state = {
.is_press_action = true,
.state = 0
};
void semi_finished(qk_tap_dance_state_t *state, void *user_data) {
semi_tap_state.state = cur_dance(state);
switch (semi_tap_state.state) {
case SINGLE_TAP:
register_code(KC_QUOT);
// register_code(KC_SCLN);
break;
case DOUBLE_TAP:
register_code(KC_SCLN);
// register_code(KC_LSFT);
// register_code(KC_MINS);
}
}
void semi_reset(qk_tap_dance_state_t *state, void *user_data) {
switch (semi_tap_state.state) {
case SINGLE_TAP:
// unregister_code(KC_SCLN);
unregister_code(KC_QUOT);
break;
case DOUBLE_TAP:
unregister_code(KC_SCLN);
// unregister_code(KC_LSFT);
// unregister_code(KC_MINS);
}
semi_tap_state.state = 0;
}
// Create an instance of 'tap' for the 'x' tap dance.
static tap bfdel_tap_state = {
.is_press_action = true,
.state = 0
};
void bfdel_finished(qk_tap_dance_state_t *state, void *user_data) {
bfdel_tap_state.state = cur_dance(state);
switch (bfdel_tap_state.state) {
case SINGLE_TAP:
register_code(KC_LCMD);
register_code(KC_LSFT);
tap_code(KC_LEFT);
unregister_code(KC_LCMD);
unregister_code(KC_LSFT);
tap_code(KC_BSPC);
break;
case DOUBLE_TAP:
register_code(KC_LCMD);
register_code(KC_LSFT);
tap_code(KC_RIGHT);
unregister_code(KC_LCMD);
unregister_code(KC_LSFT);
tap_code(KC_BSPC);
}
}
void bfdel_reset(qk_tap_dance_state_t *state, void *user_data) {
switch (bfdel_tap_state.state) {
case SINGLE_TAP:
unregister_code(KC_BSPC);
break;
case DOUBLE_TAP:
unregister_code(KC_BSPC);
}
bfdel_tap_state.state = 0;
}
qk_tap_dance_action_t tap_dance_actions[] = {
[SL_HLP] = ACTION_TAP_DANCE_FN_ADVANCED(NULL, help_finished, help_reset),
[SEMI_] = ACTION_TAP_DANCE_FN_ADVANCED(NULL, semi_finished, semi_reset),
[B_F_DEL] = ACTION_TAP_DANCE_FN_ADVANCED(NULL, bfdel_finished, bfdel_reset)
};
// =============================================================================
// END TAPDANCE.C
// =============================================================================