refactor: simplify conversion between OsCode and KeyCode #1341
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Describe your changes. Use imperative present tense.
The mapping between
KeyCode
andOsCode
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 totransmute
. Both enums are alreadyu16
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 theOsCode
u16
values are important for use in Linux, theKeyCode
numbers are not, so arbitrary adjustments were made toKeyCode
numbers to fill in the gaps.To do validation I wrote a test that:
transmute
roundtrips correctly for allOsCode
enum values.Checklist