diff options
Diffstat (limited to 'keyboards/gboards/engine/keymap_engine.h')
-rw-r--r-- | keyboards/gboards/engine/keymap_engine.h | 121 |
1 files changed, 121 insertions, 0 deletions
diff --git a/keyboards/gboards/engine/keymap_engine.h b/keyboards/gboards/engine/keymap_engine.h new file mode 100644 index 000000000..c8a42a052 --- /dev/null +++ b/keyboards/gboards/engine/keymap_engine.h | |||
@@ -0,0 +1,121 @@ | |||
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 | |||
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 | |||
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 | |||
26 | // Process Combos | ||
27 | #undef KEYS | ||
28 | #define KEYS K_ACTION | ||
29 | #include "dicts.def" | ||
30 | #undef KEYS | ||
31 | #define KEYS BLANK | ||
32 | |||
33 | #undef KEYS | ||
34 | #define KEYS K_KEYMAP | ||
35 | const struct comboEntry PROGMEM cmbDict[] = { | ||
36 | #include "dicts.def" | ||
37 | }; | ||
38 | #undef KEYS | ||
39 | #define KEYS BLANK | ||
40 | |||
41 | // Process String stubs | ||
42 | #undef SUBS | ||
43 | #define SUBS S_ACTION | ||
44 | #include "dicts.def" | ||
45 | #undef SUBS | ||
46 | #define SUBS BLANK | ||
47 | |||
48 | // Generate dict for strings | ||
49 | #undef SUBS | ||
50 | #define SUBS S_KEYMAP | ||
51 | const struct stringEntry PROGMEM strDict[] = { | ||
52 | #include "dicts.def" | ||
53 | }; | ||
54 | #undef SUBS | ||
55 | #define SUBS BLANK | ||
56 | |||
57 | // Generate function stubs | ||
58 | #undef EXEC | ||
59 | #define EXEC X_ACTION | ||
60 | #include "dicts.def" | ||
61 | #undef EXEC | ||
62 | #define EXEC BLANK | ||
63 | |||
64 | // Process the function structure | ||
65 | #undef EXEC | ||
66 | #define EXEC X_KEYMAP | ||
67 | const struct funcEntry funDict[] = { | ||
68 | #include "dicts.def" | ||
69 | }; | ||
70 | #undef EXEC | ||
71 | #define EXEC BLANK | ||
72 | |||
73 | // Handle Special calls | ||
74 | #undef SPEC | ||
75 | #define SPEC Z_KEYMAP | ||
76 | const struct specialEntry spcDict[] = { | ||
77 | #include "dicts.def" | ||
78 | }; | ||
79 | #undef SPEC | ||
80 | #define SPEC BLANK | ||
81 | |||
82 | // Test for collisions! | ||
83 | // Switch statement will explode on duplicate | ||
84 | // chords. This will be optimized out | ||
85 | #undef PRES | ||
86 | #undef KEYS | ||
87 | #undef SUBS | ||
88 | #undef EXEC | ||
89 | #undef SPEC | ||
90 | #define PRES TEST_COLLISION | ||
91 | #define KEYS TEST_COLLISION | ||
92 | #define SUBS TEST_COLLISION | ||
93 | #define EXEC TEST_COLLISION | ||
94 | #define SPEC TEST_COLLISION | ||
95 | void testCollisions(void) { | ||
96 | C_SIZE bomb = 0; | ||
97 | switch (bomb) { | ||
98 | #include "dicts.def" | ||
99 | } | ||
100 | } | ||
101 | |||
102 | // Test for unexpected input | ||
103 | // Should return blank lines for all valid input | ||
104 | #undef PRES | ||
105 | #undef KEYS | ||
106 | #undef SUBS | ||
107 | #undef EXEC | ||
108 | #undef SPEC | ||
109 | #define PRES BLANK | ||
110 | #define KEYS BLANK | ||
111 | #define SUBS BLANK | ||
112 | #define EXEC BLANK | ||
113 | #define SPEC BLANK | ||
114 | #include "dicts.def" | ||
115 | |||
116 | // Get size data back into the engine | ||
117 | size_t funcsLen = sizeof(funDict) / sizeof(funDict[0]); | ||
118 | size_t stringLen = sizeof(strDict) / sizeof(strDict[0]); | ||
119 | size_t keyLen = sizeof(keyDict) / sizeof(keyDict[0]); | ||
120 | size_t comboLen = sizeof(cmbDict) / sizeof(cmbDict[0]); | ||
121 | size_t specialLen = sizeof(spcDict) / sizeof(spcDict[0]); | ||