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

Unregister previous keycode after dynamic keymap set #24517

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from

Conversation

Garretonzo
Copy link

@Garretonzo Garretonzo commented Oct 23, 2024

Description

Changes behavior of dynamic_keymap_set_keycode to unregister the keycode previously set before the keymap update.

I would not exactly call this a "bugfix" but it does prevent keys from getting "stuck" when editing layouts through VIA hotswapping, for example.

This works but feels hacky since unregister_code is called regardless of if that key was in a pressed state or not

Types of Changes

  • Core
  • Bugfix
  • New feature
  • Enhancement/optimization
  • Keyboard (addition or update)
  • Keymap/layout (addition or update)
  • Documentation

Issues Fixed or Closed by This PR

Checklist

  • My code follows the code style of this project: C, Python
  • I have read the PR Checklist document and have made the appropriate changes.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • I have tested the changes and verified that they work and don't break anything (as well as I can manage).

@github-actions github-actions bot added the core label Oct 23, 2024
@zvecr zvecr changed the base branch from master to develop October 23, 2024 19:06
@Garretonzo Garretonzo marked this pull request as draft October 23, 2024 19:09
@Garretonzo Garretonzo marked this pull request as ready for review October 23, 2024 20:31
@drashna drashna requested a review from a team October 24, 2024 01:36
quantum/dynamic_keymap.c Outdated Show resolved Hide resolved
lint formatting

Co-authored-by: Drashna Jaelre <[email protected]>
@drashna drashna requested a review from a team October 24, 2024 20:45
// Big endian, so we can read/write EEPROM directly from host if we want
eeprom_update_byte(address, (uint8_t)(keycode >> 8));
eeprom_update_byte(address + 1, (uint8_t)(keycode & 0xFF));
unregister_code(prev_keycode);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed on discord, this wont correctly handle keycode that are non-basic, and changing it to unregister_code16 would then only handle basic+modded. Using clear_keyboard() covers more scenarios but still does not cover any side effects of quantum keycodes.

Im also not a fan of coupling storage directly to its eventual use, wherever in the tmk action code. I agree updating via.c to be responsible would be error prone for other eventual uses of dynamic_keymap_set_keycode, but it still feels like the cleaner workaround till a better solution is implemented.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A reason I handled things in here was to cover the scenario of:

  1. key pressed
  2. dynamic keymap set
  3. dynamic keymap set (again)
  4. key released

Is changing unregister_code to handle non-basic keycodes an option?
Or creating a new, all-encompassing function to handle unregistering any code?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, when you suggest to have via.c be responsible, would having the same logic but instead immediately before and after the call to dynamic_keymap_set_keycode within the id_dynamic_keymap_set_keycode case suffice? Or would there be more to having this happen in via.c?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants