From b05a4b1a4be36e00095eac3188b3b748c5fe1362 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20=C4=90or=C4=91evi=C4=87?= Date: Mon, 18 Feb 2019 05:41:03 +0100 Subject: Replace td_lshift_fn with generic td_mod_layer, add TD_RCTL_FN Move TD_FN_RCTL after TD_RCTL_FN --- users/konstantin/tap_dance.c | 78 ++++++++++++++++++++++++-------------------- users/konstantin/tap_dance.h | 6 ++-- 2 files changed, 47 insertions(+), 37 deletions(-) (limited to 'users') diff --git a/users/konstantin/tap_dance.c b/users/konstantin/tap_dance.c index cdf7b731c5..166bb10a69 100644 --- a/users/konstantin/tap_dance.c +++ b/users/konstantin/tap_dance.c @@ -1,31 +1,59 @@ #include "tap_dance.h" #include "konstantin.h" -#define ACTION_TAP_DANCE_DOUBLE_MODS(mod1, mod2) { \ - .fn = { td_double_mods_each, NULL, td_double_mods_reset }, \ - .user_data = &(qk_tap_dance_pair_t){ mod1, mod2 }, \ +#define ACTION_TAP_DANCE_DOUBLE_MODS(mod1, mod2) { \ + .fn = { td_double_mods_each, NULL, td_double_mods_reset }, \ + .user_data = &(qk_tap_dance_pair_t){ mod1, mod2 }, \ } void td_double_mods_each(qk_tap_dance_state_t *state, void *user_data) { - qk_tap_dance_pair_t *mods = (qk_tap_dance_pair_t *)user_data; + qk_tap_dance_pair_t *data = (qk_tap_dance_pair_t *)user_data; // Single tap → mod1, double tap → mod2, triple tap etc. → mod1+mod2 if (state->count == 1 || state->count == 3) { - register_code(mods->kc1); + register_code(data->kc1); } else if (state->count == 2) { - unregister_code(mods->kc1); - register_code(mods->kc2); + unregister_code(data->kc1); + register_code(data->kc2); } - // Prevent tap dance from sending kc1 and kc2 as weak mods - state->weak_mods &= ~(MOD_BIT(mods->kc1) | MOD_BIT(mods->kc2)); + // Prevent tap dance from sending the mods as weak mods + state->weak_mods &= ~(MOD_BIT(data->kc1) | MOD_BIT(data->kc2)); } void td_double_mods_reset(qk_tap_dance_state_t *state, void *user_data) { - qk_tap_dance_pair_t *mods = (qk_tap_dance_pair_t *)user_data; + qk_tap_dance_pair_t *data = (qk_tap_dance_pair_t *)user_data; if (state->count == 1 || state->count >= 3) { - unregister_code(mods->kc1); + unregister_code(data->kc1); } if (state->count >= 2) { - unregister_code(mods->kc2); + 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; + // 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; + if (state->count == 1 || state->count >= 3) { + unregister_code(data->kc); + } + if (state->count >= 2) { + layer_off(data->layer); } } @@ -60,27 +88,6 @@ void td_fn_rctrl_reset(qk_tap_dance_state_t *state, void *user_data) { td_fn_rctrl_data.started = false; } -void td_lshift_fn_each(qk_tap_dance_state_t *state, void *user_data) { - // Single tap → LShift, double tap → Fn, triple tap etc. → Fn+LShift - if (state->count == 1 || state->count == 3) { - register_code(KC_LSFT); - } else if (state->count == 2) { - unregister_code(KC_LSFT); - // Prevent tap dance from sending LShift as a weak mod - state->weak_mods &= ~MOD_BIT(KC_LSFT); - layer_on(L_FN); - } -} - -void td_lshift_fn_reset(qk_tap_dance_state_t *state, void *user_data) { - if (state->count == 1 || state->count >= 3) { - unregister_code(KC_LSFT); - } - if (state->count >= 2) { - layer_off(L_FN); - } -} - qk_tap_dance_action_t tap_dance_actions[] = { [TD_DST_A_R] = ACTION_TAP_DANCE_DOUBLE(DST_ADD, DST_REM), @@ -88,6 +95,7 @@ qk_tap_dance_action_t tap_dance_actions[] = { [TD_RAL_RGU] = ACTION_TAP_DANCE_DOUBLE_MODS(KC_RALT, KC_RGUI), [TD_RCT_RSF] = ACTION_TAP_DANCE_DOUBLE_MODS(KC_RCTL, KC_RSFT), - [TD_FN_RCTL] = ACTION_TAP_DANCE_FN_ADVANCED(td_fn_rctrl_each, NULL, td_fn_rctrl_reset), - [TD_LSFT_FN] = ACTION_TAP_DANCE_FN_ADVANCED(td_lshift_fn_each, NULL, td_lshift_fn_reset), + [TD_LSFT_FN] = ACTION_TAP_DANCE_MOD_LAYER(KC_LSFT, L_FN), + [TD_RCTL_FN] = ACTION_TAP_DANCE_MOD_LAYER(KC_RCTL, L_FN), + [TD_FN_RCTL] = ACTION_TAP_DANCE_FN_ADVANCED(td_fn_rctrl_each, NULL, td_fn_rctrl_reset), }; diff --git a/users/konstantin/tap_dance.h b/users/konstantin/tap_dance.h index 1757e9b113..ad7c04cb7f 100644 --- a/users/konstantin/tap_dance.h +++ b/users/konstantin/tap_dance.h @@ -8,8 +8,9 @@ #define RAL_RGU TD(TD_RAL_RGU) #define RCT_RSF TD(TD_RCT_RSF) -#define FN_RCTL TD(TD_FN_RCTL) #define LSFT_FN TD(TD_LSFT_FN) +#define RCTL_FN TD(TD_RCTL_FN) +#define FN_RCTL TD(TD_FN_RCTL) enum tap_dance { TD_DST_A_R, @@ -18,6 +19,7 @@ enum tap_dance { TD_RAL_RGU, TD_RCT_RSF, - TD_FN_RCTL, TD_LSFT_FN, + TD_RCTL_FN, + TD_FN_RCTL, }; -- cgit v1.2.1