diff options
| author | Jason Laqua <jlaqua118@gmail.com> | 2020-06-18 02:07:34 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-06-18 08:07:34 +0100 |
| commit | f7eb030e917a8fa360ad7cc7bb26d804cf4c5f6c (patch) | |
| tree | 8415ddb70ed9fa1cfea2651a6ef950483648d851 /quantum/process_keycode/process_ucis.c | |
| parent | aae1814319c4992471d074ed18b8b7b4842b0a66 (diff) | |
| download | qmk_firmware-f7eb030e917a8fa360ad7cc7bb26d804cf4c5f6c.tar.gz qmk_firmware-f7eb030e917a8fa360ad7cc7bb26d804cf4c5f6c.zip | |
Standardize how unicode is processed (fixes #8768) (#8770)
Co-authored-by: Konstantin Đorđević <vomindoraan@gmail.com>
Diffstat (limited to 'quantum/process_keycode/process_ucis.c')
| -rw-r--r-- | quantum/process_keycode/process_ucis.c | 97 |
1 files changed, 38 insertions, 59 deletions
diff --git a/quantum/process_keycode/process_ucis.c b/quantum/process_keycode/process_ucis.c index 024077317..2541d6eb2 100644 --- a/quantum/process_keycode/process_ucis.c +++ b/quantum/process_keycode/process_ucis.c | |||
| @@ -27,7 +27,7 @@ void qk_ucis_start(void) { | |||
| 27 | 27 | ||
| 28 | __attribute__((weak)) void qk_ucis_start_user(void) { | 28 | __attribute__((weak)) void qk_ucis_start_user(void) { |
| 29 | unicode_input_start(); | 29 | unicode_input_start(); |
| 30 | register_hex(0x2328); | 30 | register_hex(0x2328); // ⌨ |
| 31 | unicode_input_finish(); | 31 | unicode_input_finish(); |
| 32 | } | 32 | } |
| 33 | 33 | ||
| @@ -35,74 +35,54 @@ __attribute__((weak)) void qk_ucis_success(uint8_t symbol_index) {} | |||
| 35 | 35 | ||
| 36 | static bool is_uni_seq(char *seq) { | 36 | static bool is_uni_seq(char *seq) { |
| 37 | uint8_t i; | 37 | uint8_t i; |
| 38 | |||
| 39 | for (i = 0; seq[i]; i++) { | 38 | for (i = 0; seq[i]; i++) { |
| 40 | uint16_t code; | 39 | uint16_t keycode; |
| 41 | if (('1' <= seq[i]) && (seq[i] <= '0')) | 40 | if ('1' <= seq[i] && seq[i] <= '0') { |
| 42 | code = seq[i] - '1' + KC_1; | 41 | keycode = seq[i] - '1' + KC_1; |
| 43 | else | 42 | } else { |
| 44 | code = seq[i] - 'a' + KC_A; | 43 | keycode = seq[i] - 'a' + KC_A; |
| 45 | 44 | } | |
| 46 | if (i > qk_ucis_state.count || qk_ucis_state.codes[i] != code) return false; | 45 | if (i > qk_ucis_state.count || qk_ucis_state.codes[i] != keycode) { |
| 46 | return false; | ||
| 47 | } | ||
| 47 | } | 48 | } |
| 48 | 49 | return qk_ucis_state.codes[i] == KC_ENT || qk_ucis_state.codes[i] == KC_SPC; | |
| 49 | return (qk_ucis_state.codes[i] == KC_ENT || qk_ucis_state.codes[i] == KC_SPC); | ||
| 50 | } | 50 | } |
| 51 | 51 | ||
| 52 | __attribute__((weak)) void qk_ucis_symbol_fallback(void) { | 52 | __attribute__((weak)) void qk_ucis_symbol_fallback(void) { |
| 53 | for (uint8_t i = 0; i < qk_ucis_state.count - 1; i++) { | 53 | for (uint8_t i = 0; i < qk_ucis_state.count - 1; i++) { |
| 54 | uint8_t code = qk_ucis_state.codes[i]; | 54 | uint8_t keycode = qk_ucis_state.codes[i]; |
| 55 | register_code(code); | 55 | register_code(keycode); |
| 56 | unregister_code(code); | 56 | unregister_code(keycode); |
| 57 | wait_ms(UNICODE_TYPE_DELAY); | 57 | wait_ms(UNICODE_TYPE_DELAY); |
| 58 | } | 58 | } |
| 59 | } | 59 | } |
| 60 | 60 | ||
| 61 | __attribute__((weak)) void qk_ucis_cancel(void) {} | 61 | __attribute__((weak)) void qk_ucis_cancel(void) {} |
| 62 | 62 | ||
| 63 | void register_ucis(const char *hex) { | 63 | void register_ucis(const uint32_t *code_points) { |
| 64 | for (int i = 0; hex[i]; i++) { | 64 | for (int i = 0; i < UCIS_MAX_CODE_POINTS && code_points[i]; i++) { |
| 65 | uint8_t kc = 0; | 65 | register_unicode(code_points[i]); |
| 66 | char c = hex[i]; | 66 | wait_ms(UNICODE_TYPE_DELAY); |
| 67 | |||
| 68 | switch (c) { | ||
| 69 | case '0': | ||
| 70 | kc = KC_0; | ||
| 71 | break; | ||
| 72 | case '1' ... '9': | ||
| 73 | kc = c - '1' + KC_1; | ||
| 74 | break; | ||
| 75 | case 'a' ... 'f': | ||
| 76 | kc = c - 'a' + KC_A; | ||
| 77 | break; | ||
| 78 | case 'A' ... 'F': | ||
| 79 | kc = c - 'A' + KC_A; | ||
| 80 | break; | ||
| 81 | } | ||
| 82 | |||
| 83 | if (kc) { | ||
| 84 | register_code(kc); | ||
| 85 | unregister_code(kc); | ||
| 86 | wait_ms(UNICODE_TYPE_DELAY); | ||
| 87 | } | ||
| 88 | } | 67 | } |
| 89 | } | 68 | } |
| 90 | 69 | ||
| 91 | bool process_ucis(uint16_t keycode, keyrecord_t *record) { | 70 | bool process_ucis(uint16_t keycode, keyrecord_t *record) { |
| 92 | uint8_t i; | 71 | if (!qk_ucis_state.in_progress || !record->event.pressed) { |
| 93 | 72 | return true; | |
| 94 | if (!qk_ucis_state.in_progress) return true; | 73 | } |
| 95 | 74 | ||
| 96 | if (qk_ucis_state.count >= UCIS_MAX_SYMBOL_LENGTH && !(keycode == KC_BSPC || keycode == KC_ESC || keycode == KC_SPC || keycode == KC_ENT)) { | 75 | bool special = keycode == KC_SPC || keycode == KC_ENT || |
| 76 | keycode == KC_ESC || keycode == KC_BSPC; | ||
| 77 | if (qk_ucis_state.count >= UCIS_MAX_SYMBOL_LENGTH && !special) { | ||
| 97 | return false; | 78 | return false; |
| 98 | } | 79 | } |
| 99 | 80 | ||
| 100 | if (!record->event.pressed) return true; | ||
| 101 | |||
| 102 | qk_ucis_state.codes[qk_ucis_state.count] = keycode; | 81 | qk_ucis_state.codes[qk_ucis_state.count] = keycode; |
| 103 | qk_ucis_state.count++; | 82 | qk_ucis_state.count++; |
| 104 | 83 | ||
| 105 | if (keycode == KC_BSPC) { | 84 | switch (keycode) { |
| 85 | case KC_BSPC: | ||
| 106 | if (qk_ucis_state.count >= 2) { | 86 | if (qk_ucis_state.count >= 2) { |
| 107 | qk_ucis_state.count -= 2; | 87 | qk_ucis_state.count -= 2; |
| 108 | return true; | 88 | return true; |
| @@ -110,12 +90,11 @@ bool process_ucis(uint16_t keycode, keyrecord_t *record) { | |||
| 110 | qk_ucis_state.count--; | 90 | qk_ucis_state.count--; |
| 111 | return false; | 91 | return false; |
| 112 | } | 92 | } |
| 113 | } | ||
| 114 | 93 | ||
| 115 | if (keycode == KC_ENT || keycode == KC_SPC || keycode == KC_ESC) { | 94 | case KC_SPC: |
| 116 | bool symbol_found = false; | 95 | case KC_ENT: |
| 117 | 96 | case KC_ESC: | |
| 118 | for (i = qk_ucis_state.count; i > 0; i--) { | 97 | for (uint8_t i = 0; i < qk_ucis_state.count; i++) { |
| 119 | register_code(KC_BSPC); | 98 | register_code(KC_BSPC); |
| 120 | unregister_code(KC_BSPC); | 99 | unregister_code(KC_BSPC); |
| 121 | wait_ms(UNICODE_TYPE_DELAY); | 100 | wait_ms(UNICODE_TYPE_DELAY); |
| @@ -127,25 +106,25 @@ bool process_ucis(uint16_t keycode, keyrecord_t *record) { | |||
| 127 | return false; | 106 | return false; |
| 128 | } | 107 | } |
| 129 | 108 | ||
| 130 | unicode_input_start(); | 109 | uint8_t i; |
| 110 | bool symbol_found = false; | ||
| 131 | for (i = 0; ucis_symbol_table[i].symbol; i++) { | 111 | for (i = 0; ucis_symbol_table[i].symbol; i++) { |
| 132 | if (is_uni_seq(ucis_symbol_table[i].symbol)) { | 112 | if (is_uni_seq(ucis_symbol_table[i].symbol)) { |
| 133 | symbol_found = true; | 113 | symbol_found = true; |
| 134 | register_ucis(ucis_symbol_table[i].code + 2); | 114 | register_ucis(ucis_symbol_table[i].code_points); |
| 135 | break; | 115 | break; |
| 136 | } | 116 | } |
| 137 | } | 117 | } |
| 138 | if (!symbol_found) { | ||
| 139 | qk_ucis_symbol_fallback(); | ||
| 140 | } | ||
| 141 | unicode_input_finish(); | ||
| 142 | |||
| 143 | if (symbol_found) { | 118 | if (symbol_found) { |
| 144 | qk_ucis_success(i); | 119 | qk_ucis_success(i); |
| 120 | } else { | ||
| 121 | qk_ucis_symbol_fallback(); | ||
| 145 | } | 122 | } |
| 146 | 123 | ||
| 147 | qk_ucis_state.in_progress = false; | 124 | qk_ucis_state.in_progress = false; |
| 148 | return false; | 125 | return false; |
| 126 | |||
| 127 | default: | ||
| 128 | return true; | ||
| 149 | } | 129 | } |
| 150 | return true; | ||
| 151 | } | 130 | } |
