Peter's keyboard firmware (QMK) https://qmk.fm/
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.

333fred.c 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. #include "333fred.h"
  2. #include "quantum.h"
  3. #include "action.h"
  4. typedef enum {
  5. SINGLE_TAP, SINGLE_HOLD, DOUBLE
  6. } tap_dance_state_enum;
  7. static tap_dance_state_enum tap_dance_state;
  8. static bool tap_dance_active = false;
  9. void tap_dance_sym_vim_finished(qk_tap_dance_state_t *state, void *user_data) {
  10. // Determine the current state
  11. if (state->count == 1) {
  12. if (state->interrupted || state->pressed == 0) tap_dance_state = SINGLE_TAP;
  13. else tap_dance_state = SINGLE_HOLD;
  14. } else {
  15. // Handle any number of other taps as a VIM movement hold
  16. tap_dance_state = DOUBLE;
  17. }
  18. switch (tap_dance_state) {
  19. case SINGLE_TAP:
  20. if (tap_dance_active) {
  21. reset_oneshot_layer();
  22. tap_dance_active = false;
  23. } else {
  24. set_oneshot_layer(SYMB, ONESHOT_START);
  25. tap_dance_active = true;
  26. }
  27. break;
  28. case SINGLE_HOLD:
  29. layer_on(SYMB);
  30. break;
  31. case DOUBLE:
  32. layer_on(VIM);
  33. break;
  34. }
  35. }
  36. void tap_dance_sym_vim_reset(qk_tap_dance_state_t *state, void *user_data) {
  37. switch(tap_dance_state) {
  38. case SINGLE_TAP:
  39. clear_oneshot_layer_state(ONESHOT_PRESSED);
  40. break;
  41. case SINGLE_HOLD:
  42. layer_off(SYMB);
  43. break;
  44. case DOUBLE:
  45. layer_off(VIM);
  46. break;
  47. }
  48. }
  49. void tap_dance_copy_paste_finished(qk_tap_dance_state_t *state, void *user_data) {
  50. bool is_paste = state->count == 2;
  51. // If either the one-shot shift is set, or if shift is being held, count as shift being held.
  52. // We'll clear the one-shot shift if it was held
  53. uint8_t one_shot_mods = get_oneshot_mods();
  54. bool is_shift = false;
  55. if (get_mods() & MOD_MASK_SHIFT) {
  56. is_shift = true;
  57. } else if (one_shot_mods & MOD_MASK_SHIFT) {
  58. set_oneshot_mods(one_shot_mods & ~MOD_MASK_SHIFT);
  59. is_shift = true;
  60. }
  61. if (is_paste) {
  62. if (is_shift) {
  63. SEND_STRING(SS_LSFT(SS_TAP(X_INSERT)));
  64. } else {
  65. SEND_STRING(SS_LCTRL("v"));
  66. }
  67. } else {
  68. if (is_shift) {
  69. SEND_STRING(SS_LCTRL(SS_TAP(X_INSERT)));
  70. } else {
  71. SEND_STRING(SS_LCTRL("c"));
  72. }
  73. }
  74. }
  75. qk_tap_dance_action_t tap_dance_actions[] = {
  76. [TD_SYM_VIM] = ACTION_TAP_DANCE_FN_ADVANCED(NULL, tap_dance_sym_vim_finished, tap_dance_sym_vim_reset),
  77. [TD_COPY_PASTE] = ACTION_TAP_DANCE_FN_ADVANCED(NULL, tap_dance_copy_paste_finished, NULL)
  78. };
  79. void tap_dance_process_record(uint16_t keycode) {
  80. if (tap_dance_state == SINGLE_TAP && keycode != TD(TD_SYM_VIM)) {
  81. tap_dance_active = false;
  82. }
  83. }
  84. __attribute__ ((weak))
  85. void matrix_init_rgb(void) {}
  86. __attribute__ ((weak))
  87. void layer_state_set_rgb(uint32_t state) {}
  88. __attribute__ ((weak))
  89. void matrix_scan_user_keyboard(void) {}
  90. void matrix_scan_user() {
  91. static bool first_run = true;
  92. if (first_run) {
  93. first_run = false;
  94. matrix_init_rgb();
  95. }
  96. matrix_scan_user_keyboard();
  97. }
  98. uint32_t layer_state_set_user(uint32_t state) {
  99. layer_state_set_rgb(state);
  100. return state;
  101. }