Skip to content

Commit

Permalink
Add ability to use numpad digits for unicode mode UC_WIN (qmk#14496)
Browse files Browse the repository at this point in the history
Co-authored-by: Konstantin Đorđević <[email protected]>
  • Loading branch information
mjvh80 and vomindoraan authored Sep 21, 2021
1 parent 9261aea commit 93aae00
Showing 1 changed file with 37 additions and 10 deletions.
47 changes: 37 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,7 @@
unicode_config_t unicode_config;
uint8_t unicode_saved_mods;
bool unicode_saved_caps_lock;
bool unicode_saved_num_lock;

#if UNICODE_SELECTED_MODES != -1
static uint8_t selected[] = {UNICODE_SELECTED_MODES};
Expand Down Expand Up @@ -79,13 +80,14 @@ 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;
unicode_saved_num_lock = host_keyboard_led_state().num_lock;

// 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 +101,12 @@ __attribute__((weak)) void unicode_input_start(void) {
tap_code16(UNICODE_KEY_LNX);
break;
case UC_WIN:
// For increased reliability, use numpad keys for inputting digits
if (!unicode_saved_num_lock) {
tap_code(KC_NUMLOCK);
}
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 +123,16 @@ __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);
if (!unicode_saved_num_lock) {
tap_code(KC_NUMLOCK);
}
break;
case UC_WINC:
tap_code(KC_ENTER);
Expand All @@ -139,26 +148,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);
if (!unicode_saved_num_lock) {
tap_code(KC_NUMLOCK);
}
break;
}

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

// clang-format off

static void send_nibble_wrapper(uint8_t digit) {
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;
}
send_nibble(digit);
}

// clang-format on

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 +198,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

0 comments on commit 93aae00

Please sign in to comment.