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

Add option to use numpad for digits entry for unicode mode UC_WIN #14496

Merged
merged 12 commits into from
Sep 21, 2021
Merged
55 changes: 45 additions & 10 deletions quantum/process_keycode/process_unicode_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
unicode_config_t unicode_config;
uint8_t unicode_saved_mods;
bool unicode_saved_caps_lock;
#ifdef UNICODE_UC_WIN_USE_NUMPAD_IF_POSSIBLE
bool unicode_saved_num_lock;
#endif
mjvh80 marked this conversation as resolved.
Show resolved Hide resolved

#if UNICODE_SELECTED_MODES != -1
static uint8_t selected[] = {UNICODE_SELECTED_MODES};
Expand Down Expand Up @@ -79,13 +82,16 @@ void persist_unicode_input_mode(void) { eeprom_update_byte(EECONFIG_UNICODEMODE,

__attribute__((weak)) void unicode_input_start(void) {
unicode_saved_caps_lock = host_keyboard_led_state().caps_lock;
#ifdef UNICODE_UC_WIN_USE_NUMPAD_IF_POSSIBLE
unicode_saved_num_lock = host_keyboard_led_state().num_lock;
#endif
mjvh80 marked this conversation as resolved.
Show resolved Hide resolved

// Note the order matters here!
// Need to do this before we mess around with the mods, or else
// UNICODE_KEY_LNX (which is usually Ctrl-Shift-U) might not work
// correctly in the shifted case.
if (unicode_config.input_mode == UC_LNX && unicode_saved_caps_lock) {
tap_code(KC_CAPS);
tap_code(KC_CAPSLOCK);
}

unicode_saved_mods = get_mods(); // Save current mods
Expand All @@ -99,8 +105,14 @@ __attribute__((weak)) void unicode_input_start(void) {
tap_code16(UNICODE_KEY_LNX);
break;
case UC_WIN:
#ifdef UNICODE_UC_WIN_USE_NUMPAD_IF_POSSIBLE
// For increased reliability, use numpad keys for inputting digits
if (!unicode_saved_num_lock) {
tap_code(KC_NUMLOCK);
}
mjvh80 marked this conversation as resolved.
Show resolved Hide resolved
#endif
mjvh80 marked this conversation as resolved.
Show resolved Hide resolved
register_code(KC_LALT);
tap_code(KC_PPLS);
tap_code(KC_KP_PLUS);
break;
case UC_WINC:
tap_code(UNICODE_KEY_WINC);
Expand All @@ -117,13 +129,18 @@ __attribute__((weak)) void unicode_input_finish(void) {
unregister_code(UNICODE_KEY_MAC);
break;
case UC_LNX:
tap_code(KC_SPC);
tap_code(KC_SPACE);
if (unicode_saved_caps_lock) {
tap_code(KC_CAPS);
tap_code(KC_CAPSLOCK);
}
break;
case UC_WIN:
unregister_code(KC_LALT);
#ifdef UNICODE_UC_WIN_USE_NUMPAD_IF_POSSIBLE
if (!unicode_saved_num_lock) {
tap_code(KC_NUMLOCK);
}
#endif
mjvh80 marked this conversation as resolved.
Show resolved Hide resolved
break;
case UC_WINC:
tap_code(KC_ENTER);
Expand All @@ -139,26 +156,44 @@ __attribute__((weak)) void unicode_input_cancel(void) {
unregister_code(UNICODE_KEY_MAC);
break;
case UC_LNX:
tap_code(KC_ESC);
tap_code(KC_ESCAPE);
if (unicode_saved_caps_lock) {
tap_code(KC_CAPS);
tap_code(KC_CAPSLOCK);
}
break;
case UC_WINC:
tap_code(KC_ESC);
tap_code(KC_ESCAPE);
break;
case UC_WIN:
unregister_code(KC_LALT);
#ifdef UNICODE_UC_WIN_USE_NUMPAD_IF_POSSIBLE
if (!unicode_saved_num_lock) {
tap_code(KC_NUMLOCK);
}
#endif
mjvh80 marked this conversation as resolved.
Show resolved Hide resolved
break;
}

set_mods(unicode_saved_mods); // Reregister previously set mods
}

mjvh80 marked this conversation as resolved.
Show resolved Hide resolved
static void send_nibble_wrapper(uint8_t digit) {
#ifdef UNICODE_UC_WIN_USE_NUMPAD_IF_POSSIBLE
if (unicode_config.input_mode == UC_WIN) {
uint8_t kc = digit < 10
? KC_KP_1 + (10 + digit - 1) % 10
: KC_A + (digit - 10);
tap_code(kc);
return;
}
#endif
mjvh80 marked this conversation as resolved.
Show resolved Hide resolved
send_nibble(digit);
}

mjvh80 marked this conversation as resolved.
Show resolved Hide resolved
void register_hex(uint16_t hex) {
for (int i = 3; i >= 0; i--) {
uint8_t digit = ((hex >> (i * 4)) & 0xF);
send_nibble(digit);
send_nibble_wrapper(digit);
}
}

Expand All @@ -171,10 +206,10 @@ void register_hex32(uint32_t hex) {
uint8_t digit = ((hex >> (i * 4)) & 0xF);
if (digit == 0) {
if (!onzerostart) {
send_nibble(digit);
send_nibble_wrapper(digit);
}
} else {
send_nibble(digit);
send_nibble_wrapper(digit);
onzerostart = false;
}
}
Expand Down