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. };
  28. // Bake combos into mem
  29. #undef COMB
  30. #undef SUBS
  31. #undef TOGG
  32. #define COMB K_DATA
  33. #define SUBS A_DATA
  34. #define TOGG A_DATA
  35. #include "combos.def"
  36. #undef COMB
  37. #undef SUBS
  38. #undef TOGG
  39. // Fill combo array
  40. #define COMB K_COMB
  41. #define SUBS A_COMB
  42. #define TOGG A_COMB
  43. combo_t key_combos[] = {
  44. #include "combos.def"
  45. };
  46. #undef COMB
  47. #undef SUBS
  48. #undef TOGG
  49. // Export length to combo module
  50. int COMBO_LEN = sizeof(key_combos) / sizeof(key_combos[0]);
  51. // Fill QMK hook
  52. #define COMB BLANK
  53. #define SUBS A_ACTI
  54. #define TOGG A_TOGG
  55. void process_combo_event(uint16_t combo_index, bool pressed) {
  56. switch (combo_index) {
  57. #include "combos.def"
  58. }
  59. // Allow user overrides per keymap
  60. #if __has_include("inject.h")
  61. # include "inject.h"
  62. #endif
  63. }
  64. #undef COMB
  65. #undef SUBS
  66. #undef TOGG