keymap_combo.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // Keymap helpers
  2. #define K_ENUM(name, key, ...) name,
  3. #define K_DATA(name, key, ...) const uint16_t PROGMEM cmb_##name[] = {__VA_ARGS__, COMBO_END};
  4. #define K_COMB(name, key, ...) [name] = COMBO(cmb_##name, key),
  5. #define A_ENUM(name, string, ...) name,
  6. #define A_DATA(name, string, ...) const uint16_t PROGMEM cmb_##name[] = {__VA_ARGS__, COMBO_END};
  7. #define A_COMB(name, string, ...) [name] = COMBO_ACTION(cmb_##name),
  8. #define A_ACTI(name, string, ...) \
  9. case name: \
  10. if (pressed) SEND_STRING(string); \
  11. break;
  12. #define A_TOGG(name, layer, ...) \
  13. case name: \
  14. if (pressed) layer_invert(layer); \
  15. break;
  16. #define BLANK(...)
  17. // Generate data needed for combos/actions
  18. // Create Enum
  19. #undef COMB
  20. #undef SUBS
  21. #undef TOGG
  22. #define COMB K_ENUM
  23. #define SUBS A_ENUM
  24. #define TOGG A_ENUM
  25. enum combos {
  26. #include "combos.def"
  27. COMBO_LENGTH
  28. };
  29. // Export length to combo module
  30. uint16_t COMBO_LEN = COMBO_LENGTH;
  31. // Bake combos into mem
  32. #undef COMB
  33. #undef SUBS
  34. #undef TOGG
  35. #define COMB K_DATA
  36. #define SUBS A_DATA
  37. #define TOGG A_DATA
  38. #include "combos.def"
  39. #undef COMB
  40. #undef SUBS
  41. #undef TOGG
  42. // Fill combo array
  43. #define COMB K_COMB
  44. #define SUBS A_COMB
  45. #define TOGG A_COMB
  46. combo_t key_combos[] = {
  47. #include "combos.def"
  48. };
  49. #undef COMB
  50. #undef SUBS
  51. #undef TOGG
  52. // Fill QMK hook
  53. #define COMB BLANK
  54. #define SUBS A_ACTI
  55. #define TOGG A_TOGG
  56. void process_combo_event(uint16_t combo_index, bool pressed) {
  57. switch (combo_index) {
  58. #include "combos.def"
  59. }
  60. // Allow user overrides per keymap
  61. #if __has_include("inject.h")
  62. # include "inject.h"
  63. #endif
  64. }
  65. #undef COMB
  66. #undef SUBS
  67. #undef TOGG