Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: simplify conversion between OsCode and KeyCode (#1341)
The mapping between `KeyCode` and `OsCode` is for the most part irrelevant. Ideally there should only be one representation of this. This not being the case is not an inherent problem and is mostly residual/accidental from mixing the originally-from Linux OsCode numbers used in the ktrl project with the USB numbers used in keyberon. There is code using both KeyCode and OsCode now though so I'm somewhat lazy to fix everything up. For the time being this commit improves the performance and simplicity of converting between the two; conversion _should_ be a no-op now since it is a call to `transmute`. Both enums are already `u16` so this should be fine to do so long as there is a proper value on both sides. All gaps in both enums were filled with meaningless number codes for proper roundtripping. While the `OsCode` `u16` values are important for use in Linux, the `KeyCode` numbers are not, so arbitrary adjustments were made to `KeyCode` numbers to fill in the gaps. To do validation a test is added that: 1. Checked the original code roundtrips correctly for every mapped key. Some were skipped due to a lack of mapping. 2. Checks the new code with `transmute` roundtrips correctly for all `OsCode` enum values. The formerly skipped no-mapping values are no longer skipped after changing to transmute.
- Loading branch information