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.

54 lines
1.7 KiB

  1. /* Copyright 2020 Joseph Wasson
  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. static struct {
  17. int semicolon;
  18. bool mods;
  19. } tap_state = {0};
  20. void tap_dance_semicolon_each(qk_tap_dance_state_t *state, void *user_data) {
  21. tap_state.mods |= get_mods();
  22. }
  23. // Send semi-colon + enter on two taps
  24. void tap_dance_semicolon_finished(qk_tap_dance_state_t *state, void *user_data) {
  25. tap_state.semicolon = hold_cur_dance(state);
  26. switch (tap_state.semicolon) {
  27. case SINGLE_TAP: case DOUBLE_HOLD: register_code(KC_SCLN); break;
  28. case SINGLE_HOLD: layer_on(_NUM); break;
  29. }
  30. }
  31. void tap_dance_semicolon_reset(qk_tap_dance_state_t *state, void *user_data) {
  32. switch (tap_state.semicolon) {
  33. case SINGLE_TAP: case DOUBLE_HOLD: unregister_code(KC_SCLN); break;
  34. case DOUBLE_TAP: {
  35. if (tap_state.mods) {
  36. SEND_STRING(";;"); // send normal when mods are pressed
  37. }
  38. else {
  39. SEND_STRING(";\n");
  40. }
  41. break;
  42. }
  43. case TRIPLE_TAP: {
  44. SEND_STRING(";\n\n");
  45. }
  46. case SPECIAL: layer_invert(_NUM); break;
  47. case SINGLE_HOLD: layer_off(_NUM); break;
  48. }
  49. tap_state.semicolon = 0;
  50. }