From a3a47a6556b42645cee43025fb0863e057d70a09 Mon Sep 17 00:00:00 2001 From: Joshua Diamond Date: Sun, 18 Sep 2022 11:51:04 -0400 Subject: Work around WinCompose issue for U+Axxx or U+Exxx (#18260) * Work around WinCompose issue for U+Axxx or U+Exxx * tzarc's more efficient version Co-authored-by: Thomas --- quantum/unicode/unicode.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) (limited to 'quantum/unicode/unicode.c') diff --git a/quantum/unicode/unicode.c b/quantum/unicode/unicode.c index f9f429e7af..3f934c9277 100644 --- a/quantum/unicode/unicode.c +++ b/quantum/unicode/unicode.c @@ -324,19 +324,26 @@ void register_hex(uint16_t hex) { } void register_hex32(uint32_t hex) { - bool onzerostart = true; + bool first_digit = true; + bool needs_leading_zero = (unicode_config.input_mode == UC_WINC); for (int i = 7; i >= 0; i--) { - if (i <= 3) { - onzerostart = false; - } + // Work out the digit we're going to transmit uint8_t digit = ((hex >> (i * 4)) & 0xF); - if (digit == 0) { - if (!onzerostart) { - send_nibble_wrapper(digit); - } - } else { + + // If we're still searching for the first digit, and found one + // that needs a leading zero sent out, send the zero. + if (first_digit && needs_leading_zero && digit > 9) { + send_nibble_wrapper(0); + } + + // Always send digits (including zero) if we're down to the last + // two bytes of nibbles. + bool must_send = i < 4; + + // If we've found a digit worth transmitting, do so. + if (digit != 0 || !first_digit || must_send) { send_nibble_wrapper(digit); - onzerostart = false; + first_digit = false; } } } -- cgit v1.2.3