keymap_combo.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. // Keymap helpers
  2. // define reference layers per layer.
  3. #define REF_LAYER_FOR_LAYER(LAYER, REF_LAYER) \
  4. case LAYER: return REF_LAYER;
  5. #define DEF_REF_LAYER(LAYER) \
  6. default: return LAYER;
  7. #define K_ENUM(name, key, ...) name,
  8. #define K_DATA(name, key, ...) const uint16_t PROGMEM cmb_##name[] = {__VA_ARGS__, COMBO_END};
  9. #define K_COMB(name, key, ...) [name] = COMBO(cmb_##name, key),
  10. #define A_ENUM(name, string, ...) name,
  11. #define A_DATA(name, string, ...) const uint16_t PROGMEM cmb_##name[] = {__VA_ARGS__, COMBO_END};
  12. #define A_COMB(name, string, ...) [name] = COMBO_ACTION(cmb_##name),
  13. #define A_ACTI(name, string, ...) \
  14. case name: \
  15. if (pressed) SEND_STRING(string); \
  16. break;
  17. #define A_TOGG(name, layer, ...) \
  18. case name: \
  19. if (pressed) layer_invert(layer); \
  20. break;
  21. #define BLANK(...)
  22. #undef COMBO_REF_LAYER
  23. #undef DEFAULT_REF_LAYER
  24. #define COMBO_REF_LAYER BLANK
  25. #define DEFAULT_REF_LAYER BLANK
  26. // Generate data needed for combos/actions
  27. // Create Enum
  28. #undef COMB
  29. #undef SUBS
  30. #undef TOGG
  31. #define COMB K_ENUM
  32. #define SUBS A_ENUM
  33. #define TOGG A_ENUM
  34. enum combos {
  35. #include "combos.def"
  36. COMBO_LENGTH
  37. };
  38. // Export length to combo module
  39. uint16_t COMBO_LEN = COMBO_LENGTH;
  40. // Bake combos into mem
  41. #undef COMB
  42. #undef SUBS
  43. #undef TOGG
  44. #define COMB K_DATA
  45. #define SUBS A_DATA
  46. #define TOGG A_DATA
  47. #include "combos.def"
  48. #undef COMB
  49. #undef SUBS
  50. #undef TOGG
  51. // Fill combo array
  52. #define COMB K_COMB
  53. #define SUBS A_COMB
  54. #define TOGG A_COMB
  55. combo_t key_combos[] = {
  56. #include "combos.def"
  57. };
  58. #undef COMB
  59. #undef SUBS
  60. #undef TOGG
  61. // Fill QMK hook
  62. #define COMB BLANK
  63. #define SUBS A_ACTI
  64. #define TOGG A_TOGG
  65. void process_combo_event(uint16_t combo_index, bool pressed) {
  66. switch (combo_index) {
  67. #include "combos.def"
  68. }
  69. // Allow user overrides per keymap
  70. #if __has_include("inject.h")
  71. # include "inject.h"
  72. #endif
  73. }
  74. #undef COMB
  75. #undef SUBS
  76. #undef TOGG
  77. // Allow reference layers per layer.
  78. #define COMB BLANK
  79. #define SUBS BLANK
  80. #define TOGG BLANK
  81. #undef DEFAULT_REF_LAYER
  82. #undef COMBO_REF_LAYER
  83. #define COMBO_REF_LAYER REF_LAYER_FOR_LAYER
  84. #define DEFAULT_REF_LAYER DEF_REF_LAYER
  85. uint8_t combo_ref_from_layer(uint8_t current_layer){
  86. switch (current_layer){
  87. #include "combos.def"
  88. }
  89. return current_layer;
  90. }
  91. #undef COMB
  92. #undef SUBS
  93. #undef TOGG
  94. #undef COMBO_REF_LAYER
  95. #undef DEFAULT_REF_LAYER