diff options
Diffstat (limited to 'quantum/process_keycode/process_unicode_common.c')
| -rw-r--r-- | quantum/process_keycode/process_unicode_common.c | 53 |
1 files changed, 40 insertions, 13 deletions
diff --git a/quantum/process_keycode/process_unicode_common.c b/quantum/process_keycode/process_unicode_common.c index 889c768a8..7685bb1c9 100644 --- a/quantum/process_keycode/process_unicode_common.c +++ b/quantum/process_keycode/process_unicode_common.c | |||
| @@ -22,6 +22,7 @@ | |||
| 22 | unicode_config_t unicode_config; | 22 | unicode_config_t unicode_config; |
| 23 | uint8_t unicode_saved_mods; | 23 | uint8_t unicode_saved_mods; |
| 24 | bool unicode_saved_caps_lock; | 24 | bool unicode_saved_caps_lock; |
| 25 | bool unicode_saved_num_lock; | ||
| 25 | 26 | ||
| 26 | #if UNICODE_SELECTED_MODES != -1 | 27 | #if UNICODE_SELECTED_MODES != -1 |
| 27 | static uint8_t selected[] = {UNICODE_SELECTED_MODES}; | 28 | static uint8_t selected[] = {UNICODE_SELECTED_MODES}; |
| @@ -79,13 +80,14 @@ void persist_unicode_input_mode(void) { eeprom_update_byte(EECONFIG_UNICODEMODE, | |||
| 79 | 80 | ||
| 80 | __attribute__((weak)) void unicode_input_start(void) { | 81 | __attribute__((weak)) void unicode_input_start(void) { |
| 81 | unicode_saved_caps_lock = host_keyboard_led_state().caps_lock; | 82 | unicode_saved_caps_lock = host_keyboard_led_state().caps_lock; |
| 83 | unicode_saved_num_lock = host_keyboard_led_state().num_lock; | ||
| 82 | 84 | ||
| 83 | // Note the order matters here! | 85 | // Note the order matters here! |
| 84 | // Need to do this before we mess around with the mods, or else | 86 | // Need to do this before we mess around with the mods, or else |
| 85 | // UNICODE_KEY_LNX (which is usually Ctrl-Shift-U) might not work | 87 | // UNICODE_KEY_LNX (which is usually Ctrl-Shift-U) might not work |
| 86 | // correctly in the shifted case. | 88 | // correctly in the shifted case. |
| 87 | if (unicode_config.input_mode == UC_LNX && unicode_saved_caps_lock) { | 89 | if (unicode_config.input_mode == UC_LNX && unicode_saved_caps_lock) { |
| 88 | tap_code(KC_CAPS); | 90 | tap_code(KC_CAPS_LOCK); |
| 89 | } | 91 | } |
| 90 | 92 | ||
| 91 | unicode_saved_mods = get_mods(); // Save current mods | 93 | unicode_saved_mods = get_mods(); // Save current mods |
| @@ -99,9 +101,13 @@ __attribute__((weak)) void unicode_input_start(void) { | |||
| 99 | tap_code16(UNICODE_KEY_LNX); | 101 | tap_code16(UNICODE_KEY_LNX); |
| 100 | break; | 102 | break; |
| 101 | case UC_WIN: | 103 | case UC_WIN: |
| 102 | register_code(KC_LALT); | 104 | // For increased reliability, use numpad keys for inputting digits |
| 105 | if (!unicode_saved_num_lock) { | ||
| 106 | tap_code(KC_NUM_LOCK); | ||
| 107 | } | ||
| 108 | register_code(KC_LEFT_ALT); | ||
| 103 | wait_ms(UNICODE_TYPE_DELAY); | 109 | wait_ms(UNICODE_TYPE_DELAY); |
| 104 | tap_code(KC_PPLS); | 110 | tap_code(KC_KP_PLUS); |
| 105 | break; | 111 | break; |
| 106 | case UC_WINC: | 112 | case UC_WINC: |
| 107 | tap_code(UNICODE_KEY_WINC); | 113 | tap_code(UNICODE_KEY_WINC); |
| @@ -118,13 +124,16 @@ __attribute__((weak)) void unicode_input_finish(void) { | |||
| 118 | unregister_code(UNICODE_KEY_MAC); | 124 | unregister_code(UNICODE_KEY_MAC); |
| 119 | break; | 125 | break; |
| 120 | case UC_LNX: | 126 | case UC_LNX: |
| 121 | tap_code(KC_SPC); | 127 | tap_code(KC_SPACE); |
| 122 | if (unicode_saved_caps_lock) { | 128 | if (unicode_saved_caps_lock) { |
| 123 | tap_code(KC_CAPS); | 129 | tap_code(KC_CAPS_LOCK); |
| 124 | } | 130 | } |
| 125 | break; | 131 | break; |
| 126 | case UC_WIN: | 132 | case UC_WIN: |
| 127 | unregister_code(KC_LALT); | 133 | unregister_code(KC_LEFT_ALT); |
| 134 | if (!unicode_saved_num_lock) { | ||
| 135 | tap_code(KC_NUM_LOCK); | ||
| 136 | } | ||
| 128 | break; | 137 | break; |
| 129 | case UC_WINC: | 138 | case UC_WINC: |
| 130 | tap_code(KC_ENTER); | 139 | tap_code(KC_ENTER); |
| @@ -140,26 +149,44 @@ __attribute__((weak)) void unicode_input_cancel(void) { | |||
| 140 | unregister_code(UNICODE_KEY_MAC); | 149 | unregister_code(UNICODE_KEY_MAC); |
| 141 | break; | 150 | break; |
| 142 | case UC_LNX: | 151 | case UC_LNX: |
| 143 | tap_code(KC_ESC); | 152 | tap_code(KC_ESCAPE); |
| 144 | if (unicode_saved_caps_lock) { | 153 | if (unicode_saved_caps_lock) { |
| 145 | tap_code(KC_CAPS); | 154 | tap_code(KC_CAPS_LOCK); |
| 146 | } | 155 | } |
| 147 | break; | 156 | break; |
| 148 | case UC_WINC: | 157 | case UC_WINC: |
| 149 | tap_code(KC_ESC); | 158 | tap_code(KC_ESCAPE); |
| 150 | break; | 159 | break; |
| 151 | case UC_WIN: | 160 | case UC_WIN: |
| 152 | unregister_code(KC_LALT); | 161 | unregister_code(KC_LEFT_ALT); |
| 162 | if (!unicode_saved_num_lock) { | ||
| 163 | tap_code(KC_NUM_LOCK); | ||
| 164 | } | ||
| 153 | break; | 165 | break; |
| 154 | } | 166 | } |
| 155 | 167 | ||
| 156 | set_mods(unicode_saved_mods); // Reregister previously set mods | 168 | set_mods(unicode_saved_mods); // Reregister previously set mods |
| 157 | } | 169 | } |
| 158 | 170 | ||
| 171 | // clang-format off | ||
| 172 | |||
| 173 | static void send_nibble_wrapper(uint8_t digit) { | ||
| 174 | if (unicode_config.input_mode == UC_WIN) { | ||
| 175 | uint8_t kc = digit < 10 | ||
| 176 | ? KC_KP_1 + (10 + digit - 1) % 10 | ||
| 177 | : KC_A + (digit - 10); | ||
| 178 | tap_code(kc); | ||
| 179 | return; | ||
| 180 | } | ||
| 181 | send_nibble(digit); | ||
| 182 | } | ||
| 183 | |||
| 184 | // clang-format on | ||
| 185 | |||
| 159 | void register_hex(uint16_t hex) { | 186 | void register_hex(uint16_t hex) { |
| 160 | for (int i = 3; i >= 0; i--) { | 187 | for (int i = 3; i >= 0; i--) { |
| 161 | uint8_t digit = ((hex >> (i * 4)) & 0xF); | 188 | uint8_t digit = ((hex >> (i * 4)) & 0xF); |
| 162 | send_nibble(digit); | 189 | send_nibble_wrapper(digit); |
| 163 | } | 190 | } |
| 164 | } | 191 | } |
| 165 | 192 | ||
| @@ -172,10 +199,10 @@ void register_hex32(uint32_t hex) { | |||
| 172 | uint8_t digit = ((hex >> (i * 4)) & 0xF); | 199 | uint8_t digit = ((hex >> (i * 4)) & 0xF); |
| 173 | if (digit == 0) { | 200 | if (digit == 0) { |
| 174 | if (!onzerostart) { | 201 | if (!onzerostart) { |
| 175 | send_nibble(digit); | 202 | send_nibble_wrapper(digit); |
| 176 | } | 203 | } |
| 177 | } else { | 204 | } else { |
| 178 | send_nibble(digit); | 205 | send_nibble_wrapper(digit); |
| 179 | onzerostart = false; | 206 | onzerostart = false; |
| 180 | } | 207 | } |
| 181 | } | 208 | } |
