logo

qmk_firmware

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

keymap_engine.h (2555B)


  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. // Clear all X Macros
  11. #define PRES BLANK
  12. #define KEYS BLANK
  13. #define SUBS BLANK
  14. #define EXEC BLANK
  15. #define SPEC BLANK
  16. // Process single key pushes
  17. #undef PRES
  18. #define PRES P_KEYMAP
  19. const struct keyEntry keyDict[] = {
  20. #include "dicts.def"
  21. };
  22. #undef PRES
  23. #define PRES BLANK
  24. // Process Combos
  25. #undef KEYS
  26. #define KEYS K_ACTION
  27. #include "dicts.def"
  28. #undef KEYS
  29. #define KEYS BLANK
  30. #undef KEYS
  31. #define KEYS K_KEYMAP
  32. const struct comboEntry PROGMEM cmbDict[] = {
  33. #include "dicts.def"
  34. };
  35. #undef KEYS
  36. #define KEYS BLANK
  37. // Process String stubs
  38. #undef SUBS
  39. #define SUBS S_ACTION
  40. #include "dicts.def"
  41. #undef SUBS
  42. #define SUBS BLANK
  43. // Generate dict for strings
  44. #undef SUBS
  45. #define SUBS S_KEYMAP
  46. const struct stringEntry PROGMEM strDict[] = {
  47. #include "dicts.def"
  48. };
  49. #undef SUBS
  50. #define SUBS BLANK
  51. // Generate function stubs
  52. #undef EXEC
  53. #define EXEC X_ACTION
  54. #include "dicts.def"
  55. #undef EXEC
  56. #define EXEC BLANK
  57. // Process the function structure
  58. #undef EXEC
  59. #define EXEC X_KEYMAP
  60. const struct funcEntry funDict[] = {
  61. #include "dicts.def"
  62. };
  63. #undef EXEC
  64. #define EXEC BLANK
  65. // Handle Special calls
  66. #undef SPEC
  67. #define SPEC Z_KEYMAP
  68. const struct specialEntry spcDict[] = {
  69. #include "dicts.def"
  70. };
  71. #undef SPEC
  72. #define SPEC BLANK
  73. // Test for collisions!
  74. // Switch statement will explode on duplicate
  75. // chords. This will be optimized out
  76. #undef PRES
  77. #undef KEYS
  78. #undef SUBS
  79. #undef EXEC
  80. #undef SPEC
  81. #define PRES TEST_COLLISION
  82. #define KEYS TEST_COLLISION
  83. #define SUBS TEST_COLLISION
  84. #define EXEC TEST_COLLISION
  85. #define SPEC TEST_COLLISION
  86. void testCollisions(void) {
  87. C_SIZE bomb = 0;
  88. switch (bomb) {
  89. #include "dicts.def"
  90. }
  91. }
  92. // Test for unexpected input
  93. // Should return blank lines for all valid input
  94. #undef PRES
  95. #undef KEYS
  96. #undef SUBS
  97. #undef EXEC
  98. #undef SPEC
  99. #define PRES BLANK
  100. #define KEYS BLANK
  101. #define SUBS BLANK
  102. #define EXEC BLANK
  103. #define SPEC BLANK
  104. #include "dicts.def"
  105. // Get size data back into the engine
  106. size_t funcsLen = ARRAY_SIZE(funDict);
  107. size_t stringLen = ARRAY_SIZE(strDict);
  108. size_t keyLen = ARRAY_SIZE(keyDict);
  109. size_t comboLen = ARRAY_SIZE(cmbDict);
  110. size_t specialLen = ARRAY_SIZE(spcDict);