logo

qmk_firmware

custom branch of QMK firmware git clone https://anongit.hacktivis.me/git/qmk_firmware.git

keymap_engine.h (2578B)


  1. /* If for some reason you're still here, maybe due to horror, shock or
  2. * some other godforsaken reason. Meet X Macros.
  3. *
  4. * The we abuse the include system to generate data structures that are
  5. * used by the internal chording engine. The alternative to this is
  6. * using a external generator (Like is done for the ASETNIOP base keymaps)
  7. * With this disgusting bodge, you can just edit your .defs and compile!
  8. */
  9. #pragma once
  10. #include "g/engine.h"
  11. // Clear all X Macros
  12. #define PRES BLANK
  13. #define KEYS BLANK
  14. #define SUBS BLANK
  15. #define EXEC BLANK
  16. #define SPEC BLANK
  17. // Process single key pushes
  18. #undef PRES
  19. #define PRES P_KEYMAP
  20. const struct keyEntry keyDict[] = {
  21. #include "dicts.def"
  22. };
  23. #undef PRES
  24. #define PRES BLANK
  25. // Process Combos
  26. #undef KEYS
  27. #define KEYS K_ACTION
  28. #include "dicts.def"
  29. #undef KEYS
  30. #define KEYS BLANK
  31. #undef KEYS
  32. #define KEYS K_KEYMAP
  33. const struct comboEntry PROGMEM cmbDict[] = {
  34. #include "dicts.def"
  35. };
  36. #undef KEYS
  37. #define KEYS BLANK
  38. // Process String stubs
  39. #undef SUBS
  40. #define SUBS S_ACTION
  41. #include "dicts.def"
  42. #undef SUBS
  43. #define SUBS BLANK
  44. // Generate dict for strings
  45. #undef SUBS
  46. #define SUBS S_KEYMAP
  47. const struct stringEntry PROGMEM strDict[] = {
  48. #include "dicts.def"
  49. };
  50. #undef SUBS
  51. #define SUBS BLANK
  52. // Generate function stubs
  53. #undef EXEC
  54. #define EXEC X_ACTION
  55. #include "dicts.def"
  56. #undef EXEC
  57. #define EXEC BLANK
  58. // Process the function structure
  59. #undef EXEC
  60. #define EXEC X_KEYMAP
  61. const struct funcEntry funDict[] = {
  62. #include "dicts.def"
  63. };
  64. #undef EXEC
  65. #define EXEC BLANK
  66. // Handle Special calls
  67. #undef SPEC
  68. #define SPEC Z_KEYMAP
  69. const struct specialEntry spcDict[] = {
  70. #include "dicts.def"
  71. };
  72. #undef SPEC
  73. #define SPEC BLANK
  74. // Test for collisions!
  75. // Switch statement will explode on duplicate
  76. // chords. This will be optimized out
  77. #undef PRES
  78. #undef KEYS
  79. #undef SUBS
  80. #undef EXEC
  81. #undef SPEC
  82. #define PRES TEST_COLLISION
  83. #define KEYS TEST_COLLISION
  84. #define SUBS TEST_COLLISION
  85. #define EXEC TEST_COLLISION
  86. #define SPEC TEST_COLLISION
  87. void testCollisions(void) {
  88. C_SIZE bomb = 0;
  89. switch (bomb) {
  90. #include "dicts.def"
  91. }
  92. }
  93. // Test for unexpected input
  94. // Should return blank lines for all valid input
  95. #undef PRES
  96. #undef KEYS
  97. #undef SUBS
  98. #undef EXEC
  99. #undef SPEC
  100. #define PRES BLANK
  101. #define KEYS BLANK
  102. #define SUBS BLANK
  103. #define EXEC BLANK
  104. #define SPEC BLANK
  105. #include "dicts.def"
  106. // Get size data back into the engine
  107. size_t funcsLen = ARRAY_SIZE(funDict);
  108. size_t stringLen = ARRAY_SIZE(strDict);
  109. size_t keyLen = ARRAY_SIZE(keyDict);
  110. size_t comboLen = ARRAY_SIZE(cmbDict);
  111. size_t specialLen = ARRAY_SIZE(spcDict);