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
47 changes: 47 additions & 0 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 @@ -80,6 +83,10 @@ 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;

mjvh80 marked this conversation as resolved.
Show resolved Hide resolved
#ifdef UNICODE_UC_WIN_USE_NUMPAD_IF_POSSIBLE
unicode_saved_num_lock = host_keyboard_led_state().num_lock;
#endif

// 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
Expand All @@ -99,6 +106,11 @@ __attribute__((weak)) void unicode_input_start(void) {
tap_code16(UNICODE_KEY_LNX);
break;
case UC_WIN:
#ifdef UNICODE_UC_WIN_USE_NUMPAD_IF_POSSIBLE
if (!unicode_saved_num_lock) {
tap_code(KC_NUMLOCK);
}
mjvh80 marked this conversation as resolved.
Show resolved Hide resolved
#endif
register_code(KC_LALT);
tap_code(KC_PPLS);
break;
Expand All @@ -124,6 +136,12 @@ __attribute__((weak)) void unicode_input_finish(void) {
break;
case UC_WIN:
unregister_code(KC_LALT);
#ifdef UNICODE_UC_WIN_USE_NUMPAD_IF_POSSIBLE
if (!unicode_saved_num_lock) {
// We switched numlock on, so switch it off again.
tap_code(KC_NUMLOCK);
mjvh80 marked this conversation as resolved.
Show resolved Hide resolved
}
#endif
break;
case UC_WINC:
tap_code(KC_ENTER);
Expand All @@ -149,16 +167,37 @@ __attribute__((weak)) void unicode_input_cancel(void) {
break;
case UC_WIN:
unregister_code(KC_LALT);
#ifdef UNICODE_UC_WIN_USE_NUMPAD_IF_POSSIBLE
if (!unicode_saved_num_lock) {
// We switched numlock on, so switch it off again.
tap_code(KC_NUMLOCK);
mjvh80 marked this conversation as resolved.
Show resolved Hide resolved
}
#endif
break;
}

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

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

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);
#ifdef UNICODE_UC_WIN_USE_NUMPAD_IF_POSSIBLE
send_nibble_using_numpad_if_uc_win(digit);
#else
send_nibble(digit);
#endif
drashna marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand All @@ -171,10 +210,18 @@ void register_hex32(uint32_t hex) {
uint8_t digit = ((hex >> (i * 4)) & 0xF);
if (digit == 0) {
if (!onzerostart) {
#ifdef UNICODE_UC_WIN_USE_NUMPAD_IF_POSSIBLE
send_nibble_using_numpad_if_uc_win(digit);
#else
send_nibble(digit);
#endif
mjvh80 marked this conversation as resolved.
Show resolved Hide resolved
}
} else {
#ifdef UNICODE_UC_WIN_USE_NUMPAD_IF_POSSIBLE
send_nibble_using_numpad_if_uc_win(digit);
#else
send_nibble(digit);
#endif
mjvh80 marked this conversation as resolved.
Show resolved Hide resolved
onzerostart = false;
}
}
Expand Down