process_combo.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. #pragma once
  17. #include "progmem.h"
  18. #include "quantum.h"
  19. #include <stdint.h>
  20. #ifdef EXTRA_SHORT_COMBOS
  21. # define MAX_COMBO_LENGTH 6
  22. #elif defined(EXTRA_EXTRA_LONG_COMBOS)
  23. # define MAX_COMBO_LENGTH 32
  24. #elif defined(EXTRA_LONG_COMBOS)
  25. # define MAX_COMBO_LENGTH 16
  26. #else
  27. # define MAX_COMBO_LENGTH 8
  28. #endif
  29. #ifndef COMBO_KEY_BUFFER_LENGTH
  30. # define COMBO_KEY_BUFFER_LENGTH MAX_COMBO_LENGTH
  31. #endif
  32. #ifndef COMBO_BUFFER_LENGTH
  33. # define COMBO_BUFFER_LENGTH 4
  34. #endif
  35. typedef struct {
  36. const uint16_t *keys;
  37. uint16_t keycode;
  38. #ifdef EXTRA_SHORT_COMBOS
  39. uint8_t state;
  40. #else
  41. bool disabled;
  42. bool active;
  43. # if defined(EXTRA_EXTRA_LONG_COMBOS)
  44. uint32_t state;
  45. # elif defined(EXTRA_LONG_COMBOS)
  46. uint16_t state;
  47. # else
  48. uint8_t state;
  49. # endif
  50. #endif
  51. } combo_t;
  52. #define COMBO(ck, ca) \
  53. { .keys = &(ck)[0], .keycode = (ca) }
  54. #define COMBO_ACTION(ck) \
  55. { .keys = &(ck)[0] }
  56. #define COMBO_END 0
  57. #ifndef COMBO_TERM
  58. # define COMBO_TERM 50
  59. #endif
  60. #ifndef COMBO_HOLD_TERM
  61. # define COMBO_HOLD_TERM TAPPING_TERM
  62. #endif
  63. /* check if keycode is only modifiers */
  64. #define KEYCODE_IS_MOD(code) (IS_MOD(code) || (code >= QK_MODS && code <= QK_MODS_MAX && !(code & QK_BASIC_MAX)))
  65. bool process_combo(uint16_t keycode, keyrecord_t *record);
  66. void combo_task(void);
  67. void process_combo_event(uint16_t combo_index, bool pressed);
  68. void combo_enable(void);
  69. void combo_disable(void);
  70. void combo_toggle(void);
  71. bool is_combo_enabled(void);