333fred.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. }
  34. }
  35. void tap_dance_layer_reset(qk_tap_dance_state_t *state, void *user_data) {
  36. switch(tap_dance_state) {
  37. case SINGLE_TAP:
  38. clear_oneshot_layer_state(ONESHOT_PRESSED);
  39. break;
  40. case SINGLE_HOLD:
  41. layer_off(SYMB);
  42. break;
  43. case DOUBLE:
  44. layer_off(VIM);
  45. break;
  46. }
  47. }
  48. qk_tap_dance_action_t tap_dance_actions[] = {
  49. [TD_SYM_VIM] = ACTION_TAP_DANCE_FN_ADVANCED(NULL, tap_dance_layer_finished, tap_dance_layer_reset)
  50. };
  51. void tap_dance_process_record(uint16_t keycode) {
  52. if (tap_dance_state == SINGLE_TAP && keycode != TD(TD_SYM_VIM)) {
  53. tap_dance_active = false;
  54. }
  55. }