Skip to content

Commit

Permalink
Add a tap dance for 1 key shift
Browse files Browse the repository at this point in the history
  • Loading branch information
simonTurintech authored and Slyces committed May 10, 2021
1 parent 5e7e080 commit 0f5ce64
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 10 deletions.
15 changes: 8 additions & 7 deletions keyboards/kyria/keymaps/slyces/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,16 @@
/* Re-pass though to allow templates to be used */
#define LAYOUT_kyria_custom_wrapper(...) LAYOUT_kyria_custom(__VA_ARGS__)

/* ───────────────────────────────────────── shortcuts ────────────────────────────────────────── */
#define OS_SFT OSM(MOD_LSFT)

/* ───────────────────────────────────── Tap dance Shortcuts ───────────────────────────────────── */
#ifdef TAP_DANCE_ENABLE
#define TD_M TD(TD_MOVE)
#define TD_A TD(TD_ALT)
#else
#define TD_M _______
#define TD_A _______
#endif

/* ─────────────────────────────────────── Thumb Clusters ──────────────────────────────────────── */
Expand All @@ -113,17 +118,13 @@
/* ,-------------. ,-------------.
* |GAMING|CONFIG| |CONFIG|GAMING|
* ,--------------------+------+------| |------+------+--------------------.
* | | | ESC | ENTR | i3 | | i3 | SPC | TAB | | |
* | | |OS_SFT| ENTR | i3 | | i3 | SPC |OS_SFT| | |
* | | |[ALT] |[CTRL]| tmux | | tmux |[CTRL]| [ALT]| | |
* `----------------------------------' `----------------------------------'
*/
#define _____________DEFAULT_THUMBS_CLUSTER____________ \
DF(_GAMING), MO(_CONFIG), MO(_CONFIG), DF(_GAMING), \
_______, _______, ALT_T(KC_ESC), CTL_T(KC_ENT), TD_M, TD_M, CTL_T(KC_SPC), ALT_T(KC_TAB), _______, _______


/* ───────────────────────────────────────── shortcuts ────────────────────────────────────────── */
#define OS_SFT OSM(MOD_LSFT)
DF(_GAMING), MO(_CONFIG), MO(_CONFIG), DF(_GAMING), \
_______, _______, TD_A, CTL_T(KC_ENT), TD_M, TD_M, CTL_T(KC_SPC), TD_A, _______, _______

/* ─────────────────────────────────────────── layers ──────────────────────────────────────────── */
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
Expand Down
32 changes: 30 additions & 2 deletions users/slyces/tap_dances.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ uint16_t get_tapping_term(uint16_t keycode, keyrecord_t *record) {
}

/* ────────────────────────── tap dance functions ─────────────────────────── */
// Functions that control what our tap dance key does
void mv_finished(qk_tap_dance_state_t *state, void *user_data) {
mv_state.state = cur_dance(state);
switch (mv_state.state) {
Expand Down Expand Up @@ -83,7 +82,8 @@ void mv_reset(qk_tap_dance_state_t *state, void *user_data) {
mv_state.state = 0;
}

// Functions that control what our tap dance key does
// --------------------------------

void sft_finished(qk_tap_dance_state_t *state, void *user_data) {
sft_state.state = cur_dance(state);
switch (sft_state.state) {
Expand All @@ -101,8 +101,36 @@ void sft_reset(qk_tap_dance_state_t *state, void *user_data) {
sft_state.state = 0;
}

// --------------------------------

void os_alt_finished(qk_tap_dance_state_t *state, void *user_data) {
mv_state.state = cur_dance(state);
switch (mv_state.state) {
case SINGLE_TAP: // 1 Tap → OSL(shift)
set_oneshot_mods(MOD_LSFT);
break;
case SINGLE_HOLD: // Hold → NUM + ALT
register_mods(MOD_BIT(KC_LALT));
break;
}
}

void os_alt_reset(qk_tap_dance_state_t *state, void *user_data) {
// If the key was held down and now is released then switch off the mod
switch (mv_state.state) {
case SINGLE_TAP: break;
case SINGLE_HOLD:
layer_off(_NUM);
unregister_mods(MOD_BIT(KC_LALT));
break;
}
mv_state.state = 0;
}

/* ────────────────────────────────────────────────────────────────────────── */
// Associate our tap dance key with its functionality
qk_tap_dance_action_t tap_dance_actions[] = {
[TD_MOVE] = ACTION_TAP_DANCE_FN_ADVANCED(NULL, mv_finished, mv_reset),
[TD_SCOL] = ACTION_TAP_DANCE_FN_ADVANCED(NULL, sft_finished, sft_reset),
[TD_ALT] = ACTION_TAP_DANCE_FN_ADVANCED(NULL, os_alt_finished, os_alt_reset),
};
7 changes: 6 additions & 1 deletion users/slyces/tap_dances.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ typedef struct {
/* -------------------------------- keycodes -------------------------------- */
enum td_keycodes {
TD_MOVE,
TD_SCOL
TD_SCOL,
TD_ALT,
};


Expand All @@ -45,5 +46,9 @@ void mv_reset(qk_tap_dance_state_t *state, void *user_data);
void sft_finished(qk_tap_dance_state_t *state, void *user_data);
void sft_reset(qk_tap_dance_state_t *state, void *user_data);

// alt + OSL(sft)
void os_alt_finished(qk_tap_dance_state_t *state, void *user_data);
void os_alt_reset(qk_tap_dance_state_t *state, void *user_data);

/* --------------------------------- utils ---------------------------------- */
uint8_t cur_dance(qk_tap_dance_state_t *state);

0 comments on commit 0f5ce64

Please sign in to comment.