Skip to content

Commit

Permalink
[Keymap] New tap dance code added to userspace and keymaps (qmk#5468)
Browse files Browse the repository at this point in the history
* Adding new tap dance key

* Adding new tap dance code

* add code for copy/paste to tap dance

* testing tap dance enums

* New tap dance keycodes

* Fix enums
  • Loading branch information
stanrc85 authored and danielo515 committed Apr 9, 2019
1 parent a247dc5 commit 48ede34
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 14 deletions.
2 changes: 1 addition & 1 deletion keyboards/hs60/v2/keymaps/stanrc85/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC, KC_RBRC, KC_BSLS,
KC_CTLE, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, KC_ENT,
KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT,
KC_LCTL, KC_LGUI, KC_LALT, LT_SPCF, KC_RALT, TD_TWIN, MO(3), KC_RCTL),
KC_LCTL, KC_LGUI, KC_LALT, LT_SPCF, KC_RALT, TD_TWIN, MO(3), TD_TCTL),

[1] = LAYOUT_60_ansi(
KC_GESC, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS, KC_EQL, KC_BSPC,
Expand Down
2 changes: 1 addition & 1 deletion layouts/community/60_ansi/stanrc85-ansi/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC, KC_RBRC, KC_BSLS,
KC_CTLE, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, KC_ENT,
KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT,
KC_LCTL, KC_LGUI, KC_LALT, LT_SPCF, KC_RALT, TD_TWIN, MO(3), KC_RCTL),
KC_LCTL, KC_LGUI, KC_LALT, LT_SPCF, KC_RALT, TD_TWIN, MO(3), TD_TCTL),

[1] = LAYOUT_60_ansi(
KC_GESC, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS, KC_EQL, KC_BSPC,
Expand Down
42 changes: 41 additions & 1 deletion users/stanrc85/stanrc85.c
Original file line number Diff line number Diff line change
@@ -1,13 +1,53 @@
#include "stanrc85.h"

static td_state_t td_state;

__attribute__ ((weak))
bool process_record_keymap(uint16_t keycode, keyrecord_t *record) {
return true;
}

// determine the tapdance state to return
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) { return DOUBLE_TAP; }
else { return 3; } // any number higher than the maximum state value you return above
}

// handle the possible states for each tapdance keycode you define:
void ctl_copy_finished (qk_tap_dance_state_t *state, void *user_data) {
td_state = cur_dance(state);
switch (td_state) {
case SINGLE_TAP:
SEND_STRING(SS_LCTRL("c"));
break;
case SINGLE_HOLD:
register_mods(MOD_BIT(KC_RCTL));
break;
case DOUBLE_TAP:
SEND_STRING(SS_LCTRL("v"));
}
}

void ctl_copy_reset (qk_tap_dance_state_t *state, void *user_data) {
switch (td_state) {
case SINGLE_TAP:
break;
case SINGLE_HOLD:
unregister_mods(MOD_BIT(KC_RCTL));
break;
case DOUBLE_TAP:
break;
}
}

qk_tap_dance_action_t tap_dance_actions[] = {
[TD_WIN] = ACTION_TAP_DANCE_DOUBLE(KC_CAD, KC_LOCK),
[TD_ESC] = ACTION_TAP_DANCE_DOUBLE(KC_ESC, KC_GRV)
[TD_ESC] = ACTION_TAP_DANCE_DOUBLE(KC_ESC, KC_GRV),
[TD_RCTL] = ACTION_TAP_DANCE_FN_ADVANCED(NULL, ctl_copy_finished, ctl_copy_reset)
};

bool process_record_user(uint16_t keycode, keyrecord_t *record) {
Expand Down
36 changes: 25 additions & 11 deletions users/stanrc85/stanrc85.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,6 @@
#define LAYER2 2 //Function keys, arrows, custom shortcuts, volume control
#define LAYER3 3 //RGB Underglow controls and RESET

enum custom_keycodes {
KC_MAKE = SAFE_RANGE,
NEW_SAFE_RANGE //use "NEW_SAFE_RANGE" for keymap specific codes
};

//Tap Dance Declarations
enum {
TD_WIN = 0,
TD_ESC
};

//Aliases for longer keycodes
#define KC_CAD LALT(LCTL(KC_DEL))
#define KC_LOCK LGUI(KC_L)
Expand All @@ -28,3 +17,28 @@ enum {
#define LT_SPCF LT(2, KC_SPC)
#define TD_TESC TD(TD_ESC)
#define TD_TWIN TD(TD_WIN)
#define TD_TCTL TD(TD_RCTL)

enum cust_keys {
KC_MAKE = SAFE_RANGE
};

enum tap_dance {
TD_WIN,
TD_ESC,
TD_RCTL
};

// define a type containing as many tapdance states as you need
typedef enum {
SINGLE_TAP,
SINGLE_HOLD,
DOUBLE_TAP
} td_state_t;

// function to determine the current tapdance state
int cur_dance (qk_tap_dance_state_t *state);

// `finished` and `reset` functions for each tapdance keycode
void ctl_copy_finished (qk_tap_dance_state_t *state, void *user_data);
void ctl_copy_reset (qk_tap_dance_state_t *state, void *user_data);

0 comments on commit 48ede34

Please sign in to comment.