process_leader.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /* Copyright 2016 Jack Humbert
  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 "process_leader.h"
  17. __attribute__ ((weak))
  18. void leader_start(void) {}
  19. __attribute__ ((weak))
  20. void leader_end(void) {}
  21. // Leader key stuff
  22. bool leading = false;
  23. uint16_t leader_time = 0;
  24. uint16_t leader_sequence[5] = {0, 0, 0, 0, 0};
  25. uint8_t leader_sequence_size = 0;
  26. bool process_leader(uint16_t keycode, keyrecord_t *record) {
  27. // Leader key set-up
  28. if (record->event.pressed) {
  29. if (!leading && keycode == KC_LEAD) {
  30. leader_start();
  31. leading = true;
  32. leader_time = timer_read();
  33. leader_sequence_size = 0;
  34. leader_sequence[0] = 0;
  35. leader_sequence[1] = 0;
  36. leader_sequence[2] = 0;
  37. leader_sequence[3] = 0;
  38. leader_sequence[4] = 0;
  39. return false;
  40. }
  41. if (leading && timer_elapsed(leader_time) < LEADER_TIMEOUT) {
  42. leader_sequence[leader_sequence_size] = keycode;
  43. leader_sequence_size++;
  44. return false;
  45. }
  46. }
  47. return true;
  48. }