keymap_combo.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. #pragma once
  2. /*
  3. Copyright 2018-2022 Eric Gebhart <e.a.gebhart@gmail.com>
  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 2 of the License, or
  7. (at your option) any later version.
  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. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. // Keymap helpers
  16. void process_combo_event(uint16_t combo_index, bool pressed);
  17. // define reference layers per layer.
  18. #define REF_LAYER(LAYER, REF_LAYER) \
  19. case LAYER: return REF_LAYER;
  20. #define K_ENUM(name, key, ...) name,
  21. #define K_DATA(name, key, ...) const uint16_t PROGMEM cmb_##name[] = {__VA_ARGS__, COMBO_END};
  22. #define K_COMB(name, key, ...) [name] = COMBO(cmb_##name, key),
  23. #define A_ENUM(name, string, ...) name,
  24. #define A_DATA(name, string, ...) const uint16_t PROGMEM cmb_##name[] = {__VA_ARGS__, COMBO_END};
  25. #define A_COMB(name, string, ...) [name] = COMBO_ACTION(cmb_##name),
  26. #define A_ACTI(name, string, ...) \
  27. case name: \
  28. if (pressed) SEND_STRING(string); \
  29. break;
  30. #define A_TOGG(name, layer, ...) \
  31. case name: \
  32. if (pressed) layer_invert(layer); \
  33. break;
  34. #define BLANK(...)
  35. // Generate data needed for combos/actions
  36. // Create Enum
  37. #define COMBO_REF_LAYER BLANK
  38. #undef COMB
  39. #undef SUBS
  40. #undef TOGG
  41. #define COMB K_ENUM
  42. #define SUBS A_ENUM
  43. #define TOGG A_ENUM
  44. enum combos {
  45. #include "combos.def"
  46. COMBO_LENGTH
  47. };
  48. // Export length to combo module
  49. uint16_t COMBO_LEN = COMBO_LENGTH;
  50. // Bake combos into mem
  51. #undef COMB
  52. #undef SUBS
  53. #undef TOGG
  54. #define COMB K_DATA
  55. #define SUBS A_DATA
  56. #define TOGG A_DATA
  57. #include "combos.def"
  58. #undef COMB
  59. #undef SUBS
  60. #undef TOGG
  61. // Fill combo array
  62. #define COMB K_COMB
  63. #define SUBS A_COMB
  64. #define TOGG A_COMB
  65. combo_t key_combos[] = {
  66. #include "combos.def"
  67. };
  68. #undef COMB
  69. #undef SUBS
  70. #undef TOGG
  71. // Fill QMK hook
  72. #define COMB BLANK
  73. #define SUBS A_ACTI
  74. #define TOGG A_TOGG
  75. void process_combo_event(uint16_t combo_index, bool pressed) {
  76. #if defined( CONSOLE_ENABLE) && defined(CONSOLE_KEY_LOGGER_ENABLE)
  77. if (pressed) {
  78. combo_t *combo = &key_combos[combo_index];
  79. uint8_t idx = 0;
  80. uint16_t combo_keycode;
  81. while ((combo_keycode = pgm_read_word(&combo->keys[idx])) != COMBO_END) {
  82. uprintf("0x%04X,NA,NA,%u,%u,0x%02X,0x%02X,0\n",
  83. combo_keycode,
  84. /* <missing row information> */
  85. /* <missing column information> */
  86. get_highest_layer(layer_state),
  87. pressed,
  88. get_mods(),
  89. get_oneshot_mods()
  90. );
  91. idx++;
  92. }
  93. }
  94. #endif
  95. switch (combo_index) {
  96. #include "combos.def"
  97. }
  98. // Allow user overrides per keymap
  99. #if __has_include("inject.h")
  100. # include "inject.h"
  101. #endif
  102. }
  103. #undef COMB
  104. #undef SUBS
  105. #undef TOGG
  106. #define COMB BLANK
  107. #define SUBS BLANK
  108. #define TOGG BLANK
  109. #undef COMBO_REF_LAYER
  110. #define COMBO_REF_LAYER REF_LAYER
  111. uint16_t combo_ref_from_layer(uint16_t layer){
  112. switch (biton32(layer_state)){
  113. #include "combos.def"
  114. #ifdef COMBO_REF_DEFAULT
  115. default: return COMBO_REF_DEFAULT;
  116. #else
  117. default: return layer;
  118. #endif
  119. }
  120. }