You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

111 lines
3.7 KiB

  1. #include "ninjonas.h"
  2. //// BEGIN: Advanced Tap Dances
  3. int cur_dance (qk_tap_dance_state_t *state) {
  4. if (state->count == 1) {
  5. if (state->interrupted || !state->pressed) return SINGLE_TAP;
  6. //key has not been interrupted, but they key is still held. Means you want to send a 'HOLD'.
  7. else return SINGLE_HOLD;
  8. }
  9. else if (state->count == 2) {
  10. /*
  11. * DOUBLE_SINGLE_TAP is to distinguish between typing "pepper", and actually wanting a double tap
  12. * action when hitting 'pp'. Suggested use case for this return value is when you want to send two
  13. * keystrokes of the key, and not the 'double tap' action/macro.
  14. */
  15. if (state->interrupted) return DOUBLE_SINGLE_TAP;
  16. else if (state->pressed) return DOUBLE_HOLD;
  17. else return DOUBLE_TAP;
  18. }
  19. //Assumes no one is trying to type the same letter three times (at least not quickly).
  20. //If your tap dance key is 'KC_W', and you want to type "www." quickly - then you will need to add
  21. //an exception here to return a 'TRIPLE_SINGLE_TAP', and define that enum just like 'DOUBLE_SINGLE_TAP'
  22. if (state->count == 3) {
  23. if (state->interrupted || !state->pressed) return TRIPLE_TAP;
  24. else return TRIPLE_HOLD;
  25. }
  26. else return 8; //magic number. At some point this method will expand to work for more presses
  27. }
  28. // BEGIN: Copy, Paste, Apps
  29. // https://beta.docs.qmk.fm/features/feature_tap_dance#example-6-using-tap-dance-for-momentary-layer-switch-and-layer-toggle-keys
  30. static tap copy_paste_app_tap_state = {
  31. .is_press_action = true,
  32. .state = 0
  33. };
  34. void copy_paste_app_finished (qk_tap_dance_state_t *state, void *user_data) {
  35. copy_paste_app_tap_state.state = cur_dance(state);
  36. switch (copy_paste_app_tap_state.state) {
  37. case SINGLE_TAP:
  38. tap_code16(LGUI(KC_V)); // Tap Cmd + V
  39. break;
  40. case SINGLE_HOLD:
  41. tap_code16(LGUI(KC_C)); // Hold Cmd + C
  42. break;
  43. case DOUBLE_TAP:
  44. SEND_STRING(SS_DOWN(X_LGUI) SS_TAP(X_SPACE) SS_UP(X_LGUI));
  45. wait_ms(250);
  46. SEND_STRING("line\n");
  47. break;
  48. case TRIPLE_TAP:
  49. SEND_STRING(SS_DOWN(X_LGUI) SS_TAP(X_SPACE) SS_UP(X_LGUI));
  50. wait_ms(250);
  51. SEND_STRING("itunes\n");
  52. break;
  53. }
  54. }
  55. void copy_paste_app_reset (qk_tap_dance_state_t *state, void *user_data) {
  56. copy_paste_app_tap_state.state = 0;
  57. }
  58. // END: Copy, Paste, Apps
  59. // BEGIN: Y, NUMPAD
  60. static tap y_numpad_tap_state = {
  61. .is_press_action = true,
  62. .state = 0
  63. };
  64. void y_numpad_finished (qk_tap_dance_state_t *state, void *user_data) {
  65. y_numpad_tap_state.state = cur_dance(state);
  66. switch (y_numpad_tap_state.state) {
  67. case SINGLE_TAP:
  68. tap_code(KC_Y);
  69. break;
  70. case SINGLE_HOLD:
  71. register_code16(KC_Y);
  72. break;
  73. case DOUBLE_TAP:
  74. if (layer_state_is(_NUMPAD)) {
  75. layer_off(_NUMPAD);
  76. } else {
  77. layer_on(_NUMPAD);
  78. }
  79. break;
  80. }
  81. }
  82. void y_numpad_reset (qk_tap_dance_state_t *state, void *user_data) {
  83. switch (y_numpad_tap_state.state) {
  84. case SINGLE_HOLD:
  85. unregister_code16(KC_Y);
  86. break;
  87. }
  88. y_numpad_tap_state.state = 0;
  89. }
  90. // END: Y, NUMPAD
  91. //// END: Advanced Tap Dances
  92. qk_tap_dance_action_t tap_dance_actions[] = {
  93. [TD_ESC_CAPS] = ACTION_TAP_DANCE_DOUBLE(KC_ESC, KC_CAPS),
  94. [TD_LBRC_BACK] = ACTION_TAP_DANCE_DOUBLE(KC_LBRC, LGUI(KC_LBRC)),
  95. [TD_RBRC_FWD] = ACTION_TAP_DANCE_DOUBLE(KC_RBRC, LGUI(KC_RBRC)),
  96. [TD_TAB_CTRLTAB] = ACTION_TAP_DANCE_DOUBLE(KC_TAB, LCTL(KC_TAB)),
  97. [TD_GRV_CTRLGRV] = ACTION_TAP_DANCE_DOUBLE(KC_GRV, LGUI(KC_GRV)),
  98. [TD_GUI_GUISPC] = ACTION_TAP_DANCE_DOUBLE(KC_LGUI, LGUI(KC_SPC)),
  99. // Advanced Tap Dances
  100. [TD_COPY_PASTE_APP] = ACTION_TAP_DANCE_FN_ADVANCED_TIME(NULL, copy_paste_app_finished, copy_paste_app_reset, 300),
  101. [TD_Y_NUMPAD] = ACTION_TAP_DANCE_FN_ADVANCED_TIME(NULL, y_numpad_finished, y_numpad_reset, 300),
  102. };