333fred.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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_layer_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_layer_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. qk_tap_dance_action_t tap_dance_actions[] = {
  50. [TD_SYM_VIM] = ACTION_TAP_DANCE_FN_ADVANCED(NULL, tap_dance_layer_finished, tap_dance_layer_reset)
  51. };
  52. void tap_dance_process_record(uint16_t keycode) {
  53. if (tap_dance_state == SINGLE_TAP && keycode != TD(TD_SYM_VIM)) {
  54. tap_dance_active = false;
  55. }
  56. }
  57. __attribute__ ((weak))
  58. void matrix_init_rgb(void) {}
  59. __attribute__ ((weak))
  60. void layer_state_set_rgb(uint32_t state) {}
  61. __attribute__ ((weak))
  62. void matrix_scan_user_keyboard(void) {}
  63. void matrix_scan_user() {
  64. static bool first_run = true;
  65. if (first_run) {
  66. first_run = false;
  67. matrix_init_rgb();
  68. }
  69. matrix_scan_user_keyboard();
  70. }
  71. uint32_t layer_state_set_user(uint32_t state) {
  72. layer_state_set_rgb(state);
  73. return state;
  74. }