-
-
Notifications
You must be signed in to change notification settings - Fork 39.8k
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
Fix bug in UC_RMOD, add shift and audio support for UC_MOD/UC_RMOD #8674
Conversation
I don't own a board with audio to test the audio changes, but they should be okay. @drashna, I recall you using this feature; if it's not too much of a bother, could you try it out and let me know if it still works with these changes? |
void cycle_unicode_input_mode(uint8_t offset) { | ||
void cycle_unicode_input_mode(int8_t offset) { | ||
#if UNICODE_SELECTED_MODES != -1 | ||
selected_index = (selected_index + offset) % selected_count; | ||
selected_index = (selected_index + offset) % selected_count; | ||
if (selected_index < 0) { | ||
selected_index += selected_count; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Explanation:
First off, since you're supposed to be able to cycle backward (using a negative offset
) as well as forward, the parameter shouldn't be unsigned. The index calculation tries to take (selected_index + offset) mod selected_count
, but only succeeds in doing so partially because the C %
operator is a remainder, not a modulo operation. In other words, its result can be negative, and if it is, it needs to be shifted back into the [0, selected_count)
range.
The current behavior of this section (prior to the changes) is equivalent to the following pseudocode:
if offset < 0 then
selected_index ← (selected_index + offset + 1) mod selected_count
else
selected_index ← (selected_index + offset) mod selected_count
fi
This is a quirk of the operands being unsigned. Needless to say, it's not the desired behavior, and any arithmetic that expects logically negative operands should be changed to signed arithmetic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, with the caveat that I don't use either Unicode or Audio.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clang-format
puts back a few of the changes to quantum/process_keycode/process_unicode_common.c
, can it be run on the changes please. (And if some of the style change is required, worked around.)
Done. |
…k#8674) * Invert UC_MOD/UC_RMOD direction when Shift is held Also use MOD_MASK_SHIFT in process_rgb.c * Allow audio to be played for UC_MOD, UC_RMOD keycodes as well * Fix signedness bug in reverse input mode cycling * Misc formatting in process_unicode_common.c * Address clang-format issues * Make decode_utf8 helper function file-local (static)
…k#8674) * Invert UC_MOD/UC_RMOD direction when Shift is held Also use MOD_MASK_SHIFT in process_rgb.c * Allow audio to be played for UC_MOD, UC_RMOD keycodes as well * Fix signedness bug in reverse input mode cycling * Misc formatting in process_unicode_common.c * Address clang-format issues * Make decode_utf8 helper function file-local (static)
…k#8674) * Invert UC_MOD/UC_RMOD direction when Shift is held Also use MOD_MASK_SHIFT in process_rgb.c * Allow audio to be played for UC_MOD, UC_RMOD keycodes as well * Fix signedness bug in reverse input mode cycling * Misc formatting in process_unicode_common.c * Address clang-format issues * Make decode_utf8 helper function file-local (static)
…k#8674) * Invert UC_MOD/UC_RMOD direction when Shift is held Also use MOD_MASK_SHIFT in process_rgb.c * Allow audio to be played for UC_MOD, UC_RMOD keycodes as well * Fix signedness bug in reverse input mode cycling * Misc formatting in process_unicode_common.c * Address clang-format issues * Make decode_utf8 helper function file-local (static)
…k#8674) * Invert UC_MOD/UC_RMOD direction when Shift is held Also use MOD_MASK_SHIFT in process_rgb.c * Allow audio to be played for UC_MOD, UC_RMOD keycodes as well * Fix signedness bug in reverse input mode cycling * Misc formatting in process_unicode_common.c * Address clang-format issues * Make decode_utf8 helper function file-local (static)
…k#8674) * Invert UC_MOD/UC_RMOD direction when Shift is held Also use MOD_MASK_SHIFT in process_rgb.c * Allow audio to be played for UC_MOD, UC_RMOD keycodes as well * Fix signedness bug in reverse input mode cycling * Misc formatting in process_unicode_common.c * Address clang-format issues * Make decode_utf8 helper function file-local (static)
…k#8674) * Invert UC_MOD/UC_RMOD direction when Shift is held Also use MOD_MASK_SHIFT in process_rgb.c * Allow audio to be played for UC_MOD, UC_RMOD keycodes as well * Fix signedness bug in reverse input mode cycling * Misc formatting in process_unicode_common.c * Address clang-format issues * Make decode_utf8 helper function file-local (static)
…k#8674) * Invert UC_MOD/UC_RMOD direction when Shift is held Also use MOD_MASK_SHIFT in process_rgb.c * Allow audio to be played for UC_MOD, UC_RMOD keycodes as well * Fix signedness bug in reverse input mode cycling * Misc formatting in process_unicode_common.c * Address clang-format issues * Make decode_utf8 helper function file-local (static)
Description
There is a bug in
cycle_unicode_input_mode()
that prevents cycling in reverse. The bug is due to unsigned arithmetic. As a consequence, theUC_RMOD
keycode does not currently work. This PR changes theuint8_t offset
parameter toint8_t
and fixes the bug.This PR further allows Shift to be used for inverting the direction of the
UC_MOD
,UC_RMOD
keycodes, similar to howRGB_MOD
,RGB_RMOD
work.I've tested
UC_RMOD
and cycling with Shift after these changes and can confirm that they work as intended.Currently, audio feedback for changing input modes currently only plays for specific
UC_M_*
keycodes. This PR allows it to play when changing input modes withUC_MOD
,UC_RMOD
as well.Types of Changes
Checklist