diff options
author | Alex Ong <the.onga@gmail.com> | 2019-01-04 19:39:14 +1100 |
---|---|---|
committer | Alex Ong <the.onga@gmail.com> | 2019-01-04 19:39:14 +1100 |
commit | 47c91fc7f75ae0a477e55b687aa0fc30da0a283c (patch) | |
tree | 65ad39452748ff2e6d4a83ce54ede6ca22c9ada9 /users/edvorakjp/edvorakjp_tap_dance.c | |
parent | ac9b88e8ccbbf38762871504cd827ff0d941c426 (diff) | |
parent | 563ce3f225d981ce460c12ca5130dfe47af41df0 (diff) |
Merge branch 'master' of https://github.com/qmk/qmk_firmware
Diffstat (limited to 'users/edvorakjp/edvorakjp_tap_dance.c')
-rw-r--r-- | users/edvorakjp/edvorakjp_tap_dance.c | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/users/edvorakjp/edvorakjp_tap_dance.c b/users/edvorakjp/edvorakjp_tap_dance.c new file mode 100644 index 0000000000..62c0c100a2 --- /dev/null +++ b/users/edvorakjp/edvorakjp_tap_dance.c @@ -0,0 +1,71 @@ +#include "edvorakjp.h" +#include "process_keycode/process_tap_dance.h" + +enum tap_state { + NONE = 0, + SINGLE_TAP = 1, + DOUBLE_TAP = 2, + HOLD +}; + +static int td_status_lower = NONE; +static int td_status_raise = NONE; + +int cur_dance(qk_tap_dance_state_t *state) { + if (state->interrupted || !state->pressed) { + return state->count == 1 ? SINGLE_TAP : DOUBLE_TAP; + } else { + return HOLD; + } +} + +void td_lower_finished(qk_tap_dance_state_t *state, void *user_data) { + td_status_lower = cur_dance(state); + switch(td_status_lower) { + case SINGLE_TAP: + set_japanese_mode(false); + register_code(KC_ESC); + break; + case DOUBLE_TAP: + set_japanese_mode(false); + break; + case HOLD: + break; + } + layer_on(_LOWER); +} + +void td_lower_reset(qk_tap_dance_state_t *state, void *user_data) { + if (td_status_lower == SINGLE_TAP) { + unregister_code(KC_ESC); + } + layer_off(_LOWER); + td_status_lower = NONE; +} + +void td_raise_finished(qk_tap_dance_state_t *state, void *user_data) { + td_status_raise = cur_dance(state); + switch(td_status_raise) { + case SINGLE_TAP: + case DOUBLE_TAP: + set_japanese_mode(true); + break; + case HOLD: + break; + } + layer_on(_RAISE); +} + +void td_raise_reset(qk_tap_dance_state_t *state, void *user_data) { + layer_off(_RAISE); + td_status_raise = NONE; +} + +qk_tap_dance_action_t tap_dance_actions[] = { + [TD_LOWER] = ACTION_TAP_DANCE_FN_ADVANCED_TIME( + NULL, td_lower_finished, td_lower_reset, TAPPING_TERM * 1.5 + ), + [TD_RAISE] = ACTION_TAP_DANCE_FN_ADVANCED_TIME( + NULL, td_raise_finished, td_raise_reset, TAPPING_TERM * 1.5 + ) +}; |