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.

146 lines
4.2 KiB

  1. /* Copyright 2021 Mats Nilsson
  2. *
  3. * This program is free software: you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation, either version 2 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include "mnil.h"
  17. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  18. switch (keycode) {
  19. case M_TILD: // ~
  20. if (record->event.pressed) {
  21. tap_code16(RALT(KC_RBRC));
  22. tap_code(KC_SPC);
  23. } else {
  24. }
  25. break;
  26. case M_CIRC: // ^
  27. if (record->event.pressed) {
  28. tap_code16(S(KC_RBRC));
  29. tap_code(KC_SPC);
  30. } else {
  31. }
  32. break;
  33. case M_BTCK: // `
  34. if (record->event.pressed) {
  35. tap_code16(S(KC_EQL));
  36. tap_code(KC_SPC);
  37. } else {
  38. }
  39. break;
  40. case QWE_COL: // Swap default keymap layer
  41. if (record->event.pressed) {
  42. if (get_highest_layer(default_layer_state) == _COLEMAK) {
  43. default_layer_set(1UL << _QWERTY);
  44. } else {
  45. default_layer_set(1UL << _COLEMAK);
  46. }
  47. }
  48. break;
  49. }
  50. return true;
  51. };
  52. // Tap Dance
  53. // Determine the current tap dance state
  54. int cur_dance(qk_tap_dance_state_t *state) {
  55. if (state->count == 1) {
  56. if (state->interrupted || !state->pressed)
  57. return SINGLE_TAP;
  58. else
  59. return SINGLE_HOLD;
  60. } else if (state->count == 2) {
  61. if (state->interrupted)
  62. return DOUBLE_SINGLE_TAP;
  63. else if (state->pressed)
  64. return DOUBLE_HOLD;
  65. else
  66. return DOUBLE_SINGLE_TAP;
  67. }
  68. if (state->count == 3) {
  69. if (state->interrupted || !state->pressed)
  70. return TRIPLE_TAP;
  71. else
  72. return TRIPLE_HOLD;
  73. } else
  74. return 8;
  75. }
  76. static tap ae_tap_state = {.is_press_action = true, .state = 0};
  77. void ae_finished(qk_tap_dance_state_t *state, void *user_data) {
  78. ae_tap_state.state = cur_dance(state);
  79. switch (ae_tap_state.state) {
  80. case SINGLE_TAP:
  81. register_code(KC_A);
  82. break;
  83. case SINGLE_HOLD:
  84. tap_code(SE_AE);
  85. break;
  86. case DOUBLE_SINGLE_TAP:
  87. tap_code(KC_A);
  88. register_code(KC_A);
  89. break;
  90. }
  91. }
  92. void ae_reset(qk_tap_dance_state_t *state, void *user_data) {
  93. switch (ae_tap_state.state) {
  94. case SINGLE_TAP:
  95. unregister_code(KC_A);
  96. break;
  97. case DOUBLE_SINGLE_TAP:
  98. unregister_code(KC_A);
  99. break;
  100. }
  101. ae_tap_state.state = 0;
  102. }
  103. static tap aa_tap_state = {.is_press_action = true, .state = 0};
  104. void aa_finished(qk_tap_dance_state_t *state, void *user_data) {
  105. aa_tap_state.state = cur_dance(state);
  106. switch (aa_tap_state.state) {
  107. case SINGLE_TAP:
  108. register_code(SE_OSLH);
  109. break;
  110. case SINGLE_HOLD:
  111. register_code(SE_AA);
  112. unregister_code(SE_AA);
  113. break;
  114. case DOUBLE_SINGLE_TAP:
  115. tap_code(SE_OSLH);
  116. register_code(SE_OSLH);
  117. break;
  118. }
  119. }
  120. void aa_reset(qk_tap_dance_state_t *state, void *user_data) {
  121. switch (aa_tap_state.state) {
  122. case SINGLE_TAP:
  123. unregister_code(SE_OSLH);
  124. break;
  125. case DOUBLE_SINGLE_TAP:
  126. unregister_code(SE_OSLH);
  127. break;
  128. }
  129. aa_tap_state.state = 0;
  130. }
  131. // clang-format off
  132. qk_tap_dance_action_t tap_dance_actions[] = {
  133. [AAE] = ACTION_TAP_DANCE_FN_ADVANCED_TIME(NULL, ae_finished, ae_reset, 250),
  134. [OAA] = ACTION_TAP_DANCE_FN_ADVANCED_TIME(NULL, aa_finished, aa_reset, 250)
  135. };
  136. // clang-format on