enum {
SINGLE_TAP = 1,
SINGLE_HOLD = 2,
DOUBLE_TAP = 3,
DOUBLE_SINGLE_TAP = 4,
UNKNOWN_TAPS = 5
};
typedef struct {
bool is_press_action;
int state;
} tap;
int cur_dance (qk_tap_dance_state_t *state) {
if (state->count == 1) {
if (state->interrupted || !state->pressed) {
return SINGLE_TAP;
} else {
return SINGLE_HOLD;
}
}
if (state->count == 2) {
if (state->interrupted) {
return DOUBLE_SINGLE_TAP;
} else if (!state->pressed) {
return DOUBLE_TAP;
}
}
return UNKNOWN_TAPS;
}
static tap quote_state = {
.is_press_action = true,
.state = 0
};
void quote_finished(qk_tap_dance_state_t *state, void *user_data) {
quote_state.state = cur_dance(state);
switch(quote_state.state) {
case SINGLE_TAP: register_code(KC_QUOT); break;
case SINGLE_HOLD: layer_on(_LEANDOWN); break;
case DOUBLE_TAP: register_code(KC_MINS); break;
case DOUBLE_SINGLE_TAP: register_code(KC_QUOT); unregister_code(KC_QUOT); register_code(KC_QUOT); break;
}
}
void quote_reset(qk_tap_dance_state_t *state, void *user_data) {
switch(quote_state.state) {
case SINGLE_TAP: unregister_code(KC_QUOT); break;
case SINGLE_HOLD: layer_off(_LEANDOWN); break;
case DOUBLE_TAP: unregister_code(KC_MINS); break;
case DOUBLE_SINGLE_TAP: unregister_code(KC_QUOT); break;
}
quote_state.state = 0;
}
static tap ralt_state = {
.is_press_action = true,
.state = 0
};
void ralt_finished(qk_tap_dance_state_t *state, void *user_data) {
ralt_state.state = cur_dance(state);
switch(ralt_state.state) {
case SINGLE_TAP: register_code(KC_LBRC); break;
case SINGLE_HOLD: register_code(KC_RALT); break;
case DOUBLE_TAP: register_code(KC_LSFT); register_code(KC_LBRC); break;
case DOUBLE_SINGLE_TAP: register_code(KC_RALT); break;
}
}
void ralt_reset(qk_tap_dance_state_t *state, void *user_data) {
switch(ralt_state.state) {
case SINGLE_TAP: unregister_code(KC_LBRC); break;
case SINGLE_HOLD: unregister_code(KC_RALT); break;
case DOUBLE_TAP: unregister_code(KC_LBRC); unregister_code(KC_LSFT); break;
case DOUBLE_SINGLE_TAP: unregister_code(KC_RALT); break;
}
ralt_state.state = 0;
}
static tap rgui_state = {
.is_press_action = true,
.state = 0
};
void rgui_finished(qk_tap_dance_state_t *state, void *user_data) {
rgui_state.state = cur_dance(state);
switch(rgui_state.state) {
case SINGLE_TAP: register_code(KC_RBRC); break;
case SINGLE_HOLD: register_code(KC_RGUI); break;
case DOUBLE_TAP: register_code(KC_LSFT); register_code(KC_RBRC); break;
case DOUBLE_SINGLE_TAP: register_code(KC_RGUI); break;
}
}
void rgui_reset(qk_tap_dance_state_t *state, void *user_data) {
switch(rgui_state.state) {
case SINGLE_TAP: unregister_code(KC_RBRC); break;
case SINGLE_HOLD: unregister_code(KC_RGUI); break;
case DOUBLE_TAP: unregister_code(KC_RBRC); unregister_code(KC_LSFT); break;
case DOUBLE_SINGLE_TAP: unregister_code(KC_RGUI); break;
}
rgui_state.state = 0;
}
enum {
TD_ALT_SHIFT = 0,
TD_LQUT_MINS,
TD_QUOT_LEAN_MINS,
TD_LBRC_RALT_LCBR,
TD_RBRC_RGUI_RCBR
};
qk_tap_dance_action_t tap_dance_actions[] = {
[TD_ALT_SHIFT] = ACTION_TAP_DANCE_DOUBLE(KC_RALT, KC_RSFT),
[TD_QUOT_LEAN_MINS] = ACTION_TAP_DANCE_FN_ADVANCED(NULL, quote_finished, quote_reset),
[TD_LBRC_RALT_LCBR] = ACTION_TAP_DANCE_FN_ADVANCED(NULL, ralt_finished, ralt_reset),
[TD_RBRC_RGUI_RCBR] = ACTION_TAP_DANCE_FN_ADVANCED(NULL, rgui_finished, rgui_reset)
};