Skip to content

Commit

Permalink
refactor: simplify conversion between OsCode and KeyCode (#1341)
Browse files Browse the repository at this point in the history
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
jtroo authored Nov 10, 2024
1 parent 1bbb18e commit d932574
Show file tree
Hide file tree
Showing 5 changed files with 3,818 additions and 2,163 deletions.
Loading

0 comments on commit d932574

Please sign in to comment.