diff options
| author | stanrc85 <47038504+stanrc85@users.noreply.github.com> | 2019-03-22 23:50:56 -0400 |
|---|---|---|
| committer | Drashna Jaelre <drashna@live.com> | 2019-03-22 20:50:56 -0700 |
| commit | 3a7816843cb3fc890351cae2182d65b5deaa323e (patch) | |
| tree | c7585ab05696c0560f7f1fe0333f66b5e5d6e8ba /users | |
| parent | 1dda671e4ab44b978cf4fa78fd39c5d647b5ab86 (diff) | |
| download | qmk_firmware-3a7816843cb3fc890351cae2182d65b5deaa323e.tar.gz qmk_firmware-3a7816843cb3fc890351cae2182d65b5deaa323e.zip | |
[Keymap] New tap dance code added to userspace and keymaps (#5468)
* 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
Diffstat (limited to 'users')
| -rw-r--r-- | users/stanrc85/stanrc85.c | 42 | ||||
| -rw-r--r-- | users/stanrc85/stanrc85.h | 36 |
2 files changed, 66 insertions, 12 deletions
diff --git a/users/stanrc85/stanrc85.c b/users/stanrc85/stanrc85.c index e8fc5c1df..3838f33ef 100644 --- a/users/stanrc85/stanrc85.c +++ b/users/stanrc85/stanrc85.c | |||
| @@ -1,13 +1,53 @@ | |||
| 1 | #include "stanrc85.h" | 1 | #include "stanrc85.h" |
| 2 | 2 | ||
| 3 | static td_state_t td_state; | ||
| 4 | |||
| 3 | __attribute__ ((weak)) | 5 | __attribute__ ((weak)) |
| 4 | bool process_record_keymap(uint16_t keycode, keyrecord_t *record) { | 6 | bool process_record_keymap(uint16_t keycode, keyrecord_t *record) { |
| 5 | return true; | 7 | return true; |
| 6 | } | 8 | } |
| 7 | 9 | ||
| 10 | // determine the tapdance state to return | ||
| 11 | int cur_dance (qk_tap_dance_state_t *state) { | ||
| 12 | if (state->count == 1) { | ||
| 13 | if (state->interrupted || !state->pressed) { return SINGLE_TAP; } | ||
| 14 | else { return SINGLE_HOLD; } | ||
| 15 | } | ||
| 16 | if (state->count == 2) { return DOUBLE_TAP; } | ||
| 17 | else { return 3; } // any number higher than the maximum state value you return above | ||
| 18 | } | ||
| 19 | |||
| 20 | // handle the possible states for each tapdance keycode you define: | ||
| 21 | void ctl_copy_finished (qk_tap_dance_state_t *state, void *user_data) { | ||
| 22 | td_state = cur_dance(state); | ||
| 23 | switch (td_state) { | ||
| 24 | case SINGLE_TAP: | ||
| 25 | SEND_STRING(SS_LCTRL("c")); | ||
| 26 | break; | ||
| 27 | case SINGLE_HOLD: | ||
| 28 | register_mods(MOD_BIT(KC_RCTL)); | ||
| 29 | break; | ||
| 30 | case DOUBLE_TAP: | ||
| 31 | SEND_STRING(SS_LCTRL("v")); | ||
| 32 | } | ||
| 33 | } | ||
| 34 | |||
| 35 | void ctl_copy_reset (qk_tap_dance_state_t *state, void *user_data) { | ||
| 36 | switch (td_state) { | ||
| 37 | case SINGLE_TAP: | ||
| 38 | break; | ||
| 39 | case SINGLE_HOLD: | ||
| 40 | unregister_mods(MOD_BIT(KC_RCTL)); | ||
| 41 | break; | ||
| 42 | case DOUBLE_TAP: | ||
| 43 | break; | ||
| 44 | } | ||
| 45 | } | ||
| 46 | |||
| 8 | qk_tap_dance_action_t tap_dance_actions[] = { | 47 | qk_tap_dance_action_t tap_dance_actions[] = { |
| 9 | [TD_WIN] = ACTION_TAP_DANCE_DOUBLE(KC_CAD, KC_LOCK), | 48 | [TD_WIN] = ACTION_TAP_DANCE_DOUBLE(KC_CAD, KC_LOCK), |
| 10 | [TD_ESC] = ACTION_TAP_DANCE_DOUBLE(KC_ESC, KC_GRV) | 49 | [TD_ESC] = ACTION_TAP_DANCE_DOUBLE(KC_ESC, KC_GRV), |
| 50 | [TD_RCTL] = ACTION_TAP_DANCE_FN_ADVANCED(NULL, ctl_copy_finished, ctl_copy_reset) | ||
| 11 | }; | 51 | }; |
| 12 | 52 | ||
| 13 | bool process_record_user(uint16_t keycode, keyrecord_t *record) { | 53 | bool process_record_user(uint16_t keycode, keyrecord_t *record) { |
diff --git a/users/stanrc85/stanrc85.h b/users/stanrc85/stanrc85.h index c0a0e8766..2f999ff50 100644 --- a/users/stanrc85/stanrc85.h +++ b/users/stanrc85/stanrc85.h | |||
| @@ -8,17 +8,6 @@ | |||
| 8 | #define LAYER2 2 //Function keys, arrows, custom shortcuts, volume control | 8 | #define LAYER2 2 //Function keys, arrows, custom shortcuts, volume control |
| 9 | #define LAYER3 3 //RGB Underglow controls and RESET | 9 | #define LAYER3 3 //RGB Underglow controls and RESET |
| 10 | 10 | ||
| 11 | enum custom_keycodes { | ||
| 12 | KC_MAKE = SAFE_RANGE, | ||
| 13 | NEW_SAFE_RANGE //use "NEW_SAFE_RANGE" for keymap specific codes | ||
| 14 | }; | ||
| 15 | |||
| 16 | //Tap Dance Declarations | ||
| 17 | enum { | ||
| 18 | TD_WIN = 0, | ||
| 19 | TD_ESC | ||
| 20 | }; | ||
| 21 | |||
| 22 | //Aliases for longer keycodes | 11 | //Aliases for longer keycodes |
| 23 | #define KC_CAD LALT(LCTL(KC_DEL)) | 12 | #define KC_CAD LALT(LCTL(KC_DEL)) |
| 24 | #define KC_LOCK LGUI(KC_L) | 13 | #define KC_LOCK LGUI(KC_L) |
| @@ -28,3 +17,28 @@ enum { | |||
| 28 | #define LT_SPCF LT(2, KC_SPC) | 17 | #define LT_SPCF LT(2, KC_SPC) |
| 29 | #define TD_TESC TD(TD_ESC) | 18 | #define TD_TESC TD(TD_ESC) |
| 30 | #define TD_TWIN TD(TD_WIN) | 19 | #define TD_TWIN TD(TD_WIN) |
| 20 | #define TD_TCTL TD(TD_RCTL) | ||
| 21 | |||
| 22 | enum cust_keys { | ||
| 23 | KC_MAKE = SAFE_RANGE | ||
| 24 | }; | ||
| 25 | |||
| 26 | enum tap_dance { | ||
| 27 | TD_WIN, | ||
| 28 | TD_ESC, | ||
| 29 | TD_RCTL | ||
| 30 | }; | ||
| 31 | |||
| 32 | // define a type containing as many tapdance states as you need | ||
| 33 | typedef enum { | ||
| 34 | SINGLE_TAP, | ||
| 35 | SINGLE_HOLD, | ||
| 36 | DOUBLE_TAP | ||
| 37 | } td_state_t; | ||
| 38 | |||
| 39 | // function to determine the current tapdance state | ||
| 40 | int cur_dance (qk_tap_dance_state_t *state); | ||
| 41 | |||
| 42 | // `finished` and `reset` functions for each tapdance keycode | ||
| 43 | void ctl_copy_finished (qk_tap_dance_state_t *state, void *user_data); | ||
| 44 | void ctl_copy_reset (qk_tap_dance_state_t *state, void *user_data); | ||
