Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: simplify conversion between OsCode and KeyCode #1341

Merged
merged 3 commits into from
Nov 10, 2024
Merged

Conversation

jtroo
Copy link
Owner

@jtroo jtroo commented Nov 10, 2024

Describe your changes. Use imperative present tense.

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 I wrote a test that:

  1. Checked the original code roundtrips correctly for every mapped key.
  2. Checked the new code with transmute roundtrips correctly for all OsCode enum values.

Checklist

  • Add documentation to docs/config.adoc
    • N/A
  • Add example and basic docs to cfg_samples/kanata.kbd
    • N/A
  • Update error messages
    • N/A
  • Added tests, or did manual testing
    • Yes

@jtroo jtroo merged commit d932574 into main Nov 10, 2024
4 checks passed
@jtroo jtroo deleted the keycodeoscode branch November 10, 2024 09:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant