2019-01-14 23:09:47 +06:00
|
|
|
#include "tap_dance.h"
|
|
|
|
#include "konstantin.h"
|
|
|
|
|
2019-02-18 17:11:37 +06:00
|
|
|
#define ACTION_TAP_DANCE_DOUBLE_MOD(mod1, mod2) { \
|
|
|
|
.fn = { td_double_mod_each, NULL, td_double_mod_reset }, \
|
|
|
|
.user_data = &(qk_tap_dance_pair_t){ mod1, mod2 }, \
|
2019-01-14 23:09:47 +06:00
|
|
|
}
|
|
|
|
|
2019-02-18 17:11:37 +06:00
|
|
|
void td_double_mod_each(qk_tap_dance_state_t *state, void *user_data) {
|
2019-02-18 10:41:03 +06:00
|
|
|
qk_tap_dance_pair_t *data = (qk_tap_dance_pair_t *)user_data;
|
2019-02-18 11:08:52 +06:00
|
|
|
|
2019-01-14 23:09:47 +06:00
|
|
|
// Single tap → mod1, double tap → mod2, triple tap etc. → mod1+mod2
|
|
|
|
if (state->count == 1 || state->count == 3) {
|
2019-02-18 10:41:03 +06:00
|
|
|
register_code(data->kc1);
|
2019-01-14 23:09:47 +06:00
|
|
|
} else if (state->count == 2) {
|
2019-02-18 10:41:03 +06:00
|
|
|
unregister_code(data->kc1);
|
|
|
|
register_code(data->kc2);
|
2019-01-14 23:09:47 +06:00
|
|
|
}
|
2019-02-18 10:41:03 +06:00
|
|
|
// Prevent tap dance from sending the mods as weak mods
|
|
|
|
state->weak_mods &= ~(MOD_BIT(data->kc1) | MOD_BIT(data->kc2));
|
2019-01-14 23:09:47 +06:00
|
|
|
}
|
|
|
|
|
2019-02-18 17:11:37 +06:00
|
|
|
void td_double_mod_reset(qk_tap_dance_state_t *state, void *user_data) {
|
2019-02-18 10:41:03 +06:00
|
|
|
qk_tap_dance_pair_t *data = (qk_tap_dance_pair_t *)user_data;
|
2019-02-18 11:08:52 +06:00
|
|
|
|
2019-01-14 23:09:47 +06:00
|
|
|
if (state->count == 1 || state->count >= 3) {
|
2019-02-18 10:41:03 +06:00
|
|
|
unregister_code(data->kc1);
|
2019-01-14 23:09:47 +06:00
|
|
|
}
|
|
|
|
if (state->count >= 2) {
|
2019-02-18 10:41:03 +06:00
|
|
|
unregister_code(data->kc2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#define ACTION_TAP_DANCE_MOD_LAYER(mod, layer) { \
|
|
|
|
.fn = { td_mod_layer_each, NULL, td_mod_layer_reset }, \
|
|
|
|
.user_data = &(qk_tap_dance_dual_role_t){ mod, layer }, \
|
|
|
|
}
|
|
|
|
|
|
|
|
void td_mod_layer_each(qk_tap_dance_state_t *state, void *user_data) {
|
|
|
|
qk_tap_dance_dual_role_t *data = (qk_tap_dance_dual_role_t *)user_data;
|
2019-02-18 11:08:52 +06:00
|
|
|
|
2019-02-18 10:41:03 +06:00
|
|
|
// Single tap → mod, double tap → layer, triple tap etc. → mod+layer
|
|
|
|
if (state->count == 1 || state->count == 3) {
|
|
|
|
register_code(data->kc);
|
|
|
|
} else if (state->count == 2) {
|
|
|
|
unregister_code(data->kc);
|
|
|
|
// Prevent tap dance from sending the mod as a weak mod
|
|
|
|
state->weak_mods &= ~MOD_BIT(data->kc);
|
|
|
|
layer_on(data->layer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void td_mod_layer_reset(qk_tap_dance_state_t *state, void *user_data) {
|
|
|
|
qk_tap_dance_dual_role_t *data = (qk_tap_dance_dual_role_t *)user_data;
|
2019-02-18 11:08:52 +06:00
|
|
|
|
2019-02-18 10:41:03 +06:00
|
|
|
if (state->count == 1 || state->count >= 3) {
|
|
|
|
unregister_code(data->kc);
|
|
|
|
}
|
|
|
|
if (state->count >= 2) {
|
|
|
|
layer_off(data->layer);
|
2019-01-14 23:09:47 +06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-18 11:00:05 +06:00
|
|
|
#define ACTION_TAP_DANCE_LAYER_MOD(layer, mod) { \
|
|
|
|
.fn = { td_layer_mod_each, NULL, td_layer_mod_reset }, \
|
2019-02-18 11:08:52 +06:00
|
|
|
.user_data = &(qk_tap_dance_layer_mod_t){ layer, mod, 0, 0 }, \
|
2019-02-18 11:00:05 +06:00
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
uint8_t layer;
|
|
|
|
uint16_t kc;
|
|
|
|
bool layer_on; // Layer state when tap dance started
|
|
|
|
bool started;
|
|
|
|
} qk_tap_dance_layer_mod_t;
|
2019-01-14 23:09:47 +06:00
|
|
|
|
2019-02-18 11:00:05 +06:00
|
|
|
void td_layer_mod_each(qk_tap_dance_state_t *state, void *user_data) {
|
|
|
|
qk_tap_dance_layer_mod_t *data = (qk_tap_dance_layer_mod_t *)user_data;
|
|
|
|
if (!data->started) {
|
|
|
|
data->layer_on = IS_LAYER_ON(data->layer);
|
|
|
|
data->started = true;
|
2019-01-14 23:09:47 +06:00
|
|
|
}
|
2019-02-18 11:08:52 +06:00
|
|
|
|
2019-02-18 11:00:05 +06:00
|
|
|
// Single tap → layer, double tap → mod, triple tap etc. → layer+mod
|
2019-01-14 23:09:47 +06:00
|
|
|
if (state->count == 1 || state->count == 3) {
|
2019-02-18 11:00:05 +06:00
|
|
|
layer_on(data->layer);
|
2019-01-14 23:09:47 +06:00
|
|
|
} else if (state->count == 2) {
|
2019-02-18 11:00:05 +06:00
|
|
|
if (!data->layer_on) {
|
|
|
|
layer_off(data->layer);
|
2019-01-14 23:09:47 +06:00
|
|
|
}
|
2019-02-18 11:00:05 +06:00
|
|
|
register_code(data->kc);
|
2019-01-14 23:09:47 +06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-18 11:00:05 +06:00
|
|
|
void td_layer_mod_reset(qk_tap_dance_state_t *state, void *user_data) {
|
|
|
|
qk_tap_dance_layer_mod_t *data = (qk_tap_dance_layer_mod_t *)user_data;
|
2019-02-18 11:08:52 +06:00
|
|
|
|
2019-02-18 11:00:05 +06:00
|
|
|
if ((state->count == 1 || state->count >= 3) && !data->layer_on) {
|
|
|
|
layer_off(data->layer);
|
2019-01-14 23:09:47 +06:00
|
|
|
}
|
|
|
|
if (state->count >= 2) {
|
2019-02-18 11:00:05 +06:00
|
|
|
unregister_code(data->kc);
|
2019-01-14 23:09:47 +06:00
|
|
|
}
|
2019-02-18 11:08:52 +06:00
|
|
|
|
2019-02-18 11:00:05 +06:00
|
|
|
data->started = false;
|
2019-01-14 23:09:47 +06:00
|
|
|
}
|
|
|
|
|
|
|
|
qk_tap_dance_action_t tap_dance_actions[] = {
|
2019-01-29 05:37:10 +06:00
|
|
|
[TD_DST_A_R] = ACTION_TAP_DANCE_DOUBLE(DST_ADD, DST_REM),
|
2019-01-14 23:09:47 +06:00
|
|
|
|
2019-02-18 17:11:37 +06:00
|
|
|
[TD_RAL_LAL] = ACTION_TAP_DANCE_DOUBLE_MOD(KC_RALT, KC_LALT),
|
|
|
|
[TD_RAL_RGU] = ACTION_TAP_DANCE_DOUBLE_MOD(KC_RALT, KC_RGUI),
|
|
|
|
[TD_RCT_RSF] = ACTION_TAP_DANCE_DOUBLE_MOD(KC_RCTL, KC_RSFT),
|
2019-01-14 23:09:47 +06:00
|
|
|
|
2019-02-18 10:41:03 +06:00
|
|
|
[TD_LSFT_FN] = ACTION_TAP_DANCE_MOD_LAYER(KC_LSFT, L_FN),
|
|
|
|
[TD_RCTL_FN] = ACTION_TAP_DANCE_MOD_LAYER(KC_RCTL, L_FN),
|
2019-02-18 11:00:05 +06:00
|
|
|
[TD_FN_RCTL] = ACTION_TAP_DANCE_LAYER_MOD(L_FN, KC_RCTL),
|
2019-01-14 23:09:47 +06:00
|
|
|
};
|