summaryrefslogtreecommitdiffstats
path: root/quantum
diff options
context:
space:
mode:
Diffstat (limited to 'quantum')
-rw-r--r--quantum/process_keycode/process_tap_dance.c73
-rw-r--r--quantum/process_keycode/process_tap_dance.h7
-rw-r--r--quantum/quantum.c4
3 files changed, 53 insertions, 31 deletions
diff --git a/quantum/process_keycode/process_tap_dance.c b/quantum/process_keycode/process_tap_dance.c
index f196a9cb6a..94dd17c2fc 100644
--- a/quantum/process_keycode/process_tap_dance.c
+++ b/quantum/process_keycode/process_tap_dance.c
@@ -21,6 +21,15 @@ uint8_t get_oneshot_mods(void);
static uint16_t last_td;
static int8_t highest_td = -1;
+void qk_tap_dance_pair_on_each_tap (qk_tap_dance_state_t *state, void *user_data) {
+ qk_tap_dance_pair_t *pair = (qk_tap_dance_pair_t *)user_data;
+
+ if (state->count == 2) {
+ register_code16 (pair->kc2);
+ state->finished = true;
+ }
+}
+
void qk_tap_dance_pair_finished (qk_tap_dance_state_t *state, void *user_data) {
qk_tap_dance_pair_t *pair = (qk_tap_dance_pair_t *)user_data;
@@ -41,6 +50,15 @@ void qk_tap_dance_pair_reset (qk_tap_dance_state_t *state, void *user_data) {
}
}
+void qk_tap_dance_dual_role_on_each_tap (qk_tap_dance_state_t *state, void *user_data) {
+ qk_tap_dance_dual_role_t *pair = (qk_tap_dance_dual_role_t *)user_data;
+
+ if (state->count == 2) {
+ layer_move (pair->layer);
+ state->finished = true;
+ }
+}
+
void qk_tap_dance_dual_role_finished (qk_tap_dance_state_t *state, void *user_data) {
qk_tap_dance_dual_role_t *pair = (qk_tap_dance_dual_role_t *)user_data;
@@ -92,13 +110,30 @@ static inline void process_tap_dance_action_on_reset (qk_tap_dance_action_t *act
send_keyboard_report();
}
-bool process_tap_dance(uint16_t keycode, keyrecord_t *record) {
- uint16_t idx = keycode - QK_TAP_DANCE;
+void preprocess_tap_dance(uint16_t keycode, keyrecord_t *record) {
qk_tap_dance_action_t *action;
- if (last_td && last_td != keycode) {
- (&tap_dance_actions[last_td - QK_TAP_DANCE])->state.interrupted = true;
+ if (!record->event.pressed)
+ return;
+
+ if (highest_td == -1)
+ return;
+
+ for (int i = 0; i <= highest_td; i++) {
+ action = &tap_dance_actions[i];
+ if (action->state.count) {
+ if (keycode == action->state.keycode && keycode == last_td)
+ continue;
+ action->state.interrupted = true;
+ process_tap_dance_action_on_dance_finished (action);
+ reset_tap_dance (&action->state);
+ }
}
+}
+
+bool process_tap_dance(uint16_t keycode, keyrecord_t *record) {
+ uint16_t idx = keycode - QK_TAP_DANCE;
+ qk_tap_dance_action_t *action;
switch(keycode) {
case QK_TAP_DANCE ... QK_TAP_DANCE_MAX:
@@ -116,34 +151,14 @@ bool process_tap_dance(uint16_t keycode, keyrecord_t *record) {
action->state.weak_mods |= get_weak_mods();
process_tap_dance_action_on_each_tap (action);
- if (last_td && last_td != keycode) {
- qk_tap_dance_action_t *paction = &tap_dance_actions[last_td - QK_TAP_DANCE];
- paction->state.interrupted = true;
- process_tap_dance_action_on_dance_finished (paction);
- reset_tap_dance (&paction->state);
- }
-
last_td = keycode;
+ } else {
+ if (action->state.count && action->state.finished) {
+ reset_tap_dance (&action->state);
+ }
}
break;
-
- default:
- if (!record->event.pressed)
- return true;
-
- if (highest_td == -1)
- return true;
-
- for (int i = 0; i <= highest_td; i++) {
- action = &tap_dance_actions[i];
- if (action->state.count == 0)
- continue;
- action->state.interrupted = true;
- process_tap_dance_action_on_dance_finished (action);
- reset_tap_dance (&action->state);
- }
- break;
}
return true;
@@ -156,7 +171,7 @@ void matrix_scan_tap_dance () {
return;
uint16_t tap_user_defined;
-for (uint8_t i = 0; i <= highest_td; i++) {
+ for (uint8_t i = 0; i <= highest_td; i++) {
qk_tap_dance_action_t *action = &tap_dance_actions[i];
if(action->custom_tapping_term > 0 ) {
tap_user_defined = action->custom_tapping_term;
diff --git a/quantum/process_keycode/process_tap_dance.h b/quantum/process_keycode/process_tap_dance.h
index ab20ea04ed..8b0a47c49b 100644
--- a/quantum/process_keycode/process_tap_dance.h
+++ b/quantum/process_keycode/process_tap_dance.h
@@ -62,12 +62,12 @@ typedef struct
} qk_tap_dance_dual_role_t;
#define ACTION_TAP_DANCE_DOUBLE(kc1, kc2) { \
- .fn = { NULL, qk_tap_dance_pair_finished, qk_tap_dance_pair_reset }, \
+ .fn = { qk_tap_dance_pair_on_each_tap, qk_tap_dance_pair_finished, qk_tap_dance_pair_reset }, \
.user_data = (void *)&((qk_tap_dance_pair_t) { kc1, kc2 }), \
}
#define ACTION_TAP_DANCE_DUAL_ROLE(kc, layer) { \
- .fn = { NULL, qk_tap_dance_dual_role_finished, qk_tap_dance_dual_role_reset }, \
+ .fn = { qk_tap_dance_dual_role_on_each_tap, qk_tap_dance_dual_role_finished, qk_tap_dance_dual_role_reset }, \
.user_data = (void *)&((qk_tap_dance_dual_role_t) { kc, layer }), \
}
@@ -91,13 +91,16 @@ extern qk_tap_dance_action_t tap_dance_actions[];
/* To be used internally */
+void preprocess_tap_dance(uint16_t keycode, keyrecord_t *record);
bool process_tap_dance(uint16_t keycode, keyrecord_t *record);
void matrix_scan_tap_dance (void);
void reset_tap_dance (qk_tap_dance_state_t *state);
+void qk_tap_dance_pair_on_each_tap (qk_tap_dance_state_t *state, void *user_data);
void qk_tap_dance_pair_finished (qk_tap_dance_state_t *state, void *user_data);
void qk_tap_dance_pair_reset (qk_tap_dance_state_t *state, void *user_data);
+void qk_tap_dance_dual_role_on_each_tap (qk_tap_dance_state_t *state, void *user_data);
void qk_tap_dance_dual_role_finished (qk_tap_dance_state_t *state, void *user_data);
void qk_tap_dance_dual_role_reset (qk_tap_dance_state_t *state, void *user_data);
diff --git a/quantum/quantum.c b/quantum/quantum.c
index f5246d9b1e..d3685f50b8 100644
--- a/quantum/quantum.c
+++ b/quantum/quantum.c
@@ -209,6 +209,10 @@ bool process_record_quantum(keyrecord_t *record) {
// return false;
// }
+ #ifdef TAP_DANCE_ENABLE
+ preprocess_tap_dance(keycode, record);
+ #endif
+
if (!(
#if defined(KEY_LOCK_ENABLE)
// Must run first to be able to mask key_up events.