2018-11-27 01:50:45 +08:00
|
|
|
#include "edvorakjp.h"
|
|
|
|
#include "process_keycode/process_tap_dance.h"
|
|
|
|
|
|
|
|
enum tap_state {
|
|
|
|
NONE = 0,
|
|
|
|
SINGLE_TAP = 1,
|
|
|
|
DOUBLE_TAP = 2,
|
|
|
|
HOLD
|
|
|
|
};
|
|
|
|
|
2019-03-10 00:22:21 +08:00
|
|
|
typedef struct {
|
|
|
|
uint8_t lower;
|
|
|
|
uint8_t raise;
|
|
|
|
} td_status_t;
|
|
|
|
static td_status_t td_status = {NONE, NONE};
|
2018-11-27 01:50:45 +08:00
|
|
|
|
|
|
|
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) {
|
2019-03-10 00:22:21 +08:00
|
|
|
td_status.lower = cur_dance(state);
|
|
|
|
switch(td_status.lower) {
|
2018-11-27 01:50:45 +08:00
|
|
|
case SINGLE_TAP:
|
|
|
|
set_japanese_mode(false);
|
|
|
|
break;
|
|
|
|
case DOUBLE_TAP:
|
|
|
|
set_japanese_mode(false);
|
2019-03-10 00:22:21 +08:00
|
|
|
register_code(KC_ESC);
|
2018-11-27 01:50:45 +08:00
|
|
|
break;
|
|
|
|
case HOLD:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
layer_on(_LOWER);
|
|
|
|
}
|
|
|
|
|
|
|
|
void td_lower_reset(qk_tap_dance_state_t *state, void *user_data) {
|
2019-03-10 00:22:21 +08:00
|
|
|
if (td_status.lower == DOUBLE_TAP) {
|
2018-11-27 01:50:45 +08:00
|
|
|
unregister_code(KC_ESC);
|
|
|
|
}
|
|
|
|
layer_off(_LOWER);
|
2019-03-10 00:22:21 +08:00
|
|
|
td_status.lower = NONE;
|
2018-11-27 01:50:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void td_raise_finished(qk_tap_dance_state_t *state, void *user_data) {
|
2019-03-10 00:22:21 +08:00
|
|
|
td_status.raise = cur_dance(state);
|
|
|
|
switch(td_status.raise) {
|
2018-11-27 01:50:45 +08:00
|
|
|
case DOUBLE_TAP:
|
2019-03-10 00:22:21 +08:00
|
|
|
// same as single
|
|
|
|
case SINGLE_TAP:
|
2018-11-27 01:50:45 +08:00
|
|
|
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);
|
2019-03-10 00:22:21 +08:00
|
|
|
td_status.raise = NONE;
|
2018-11-27 01:50:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
qk_tap_dance_action_t tap_dance_actions[] = {
|
2019-03-10 00:22:21 +08:00
|
|
|
[TD_LOWER] =
|
|
|
|
ACTION_TAP_DANCE_FN_ADVANCED_TIME(NULL, td_lower_finished, td_lower_reset, 100),
|
|
|
|
[TD_RAISE] =
|
|
|
|
ACTION_TAP_DANCE_FN_ADVANCED_TIME(NULL, td_raise_finished, td_raise_reset, 100)
|
2018-11-27 01:50:45 +08:00
|
|
|
};
|