diff options
| author | Jack Humbert <jack.humb@gmail.com> | 2017-02-15 16:36:31 -0500 |
|---|---|---|
| committer | Jack Humbert <jack.humb@gmail.com> | 2017-02-15 16:36:31 -0500 |
| commit | cbabb4d417ef58f5d484dc256b637f61619efaa8 (patch) | |
| tree | 01ed906acd8ef81a213385697599cee3ac2f68de /quantum/process_keycode/process_unicode.c | |
| parent | 6788cbd76291e1f3103a350598f7bf5d523a7310 (diff) | |
| download | qmk_firmware-cbabb4d417ef58f5d484dc256b637f61619efaa8.tar.gz qmk_firmware-cbabb4d417ef58f5d484dc256b637f61619efaa8.zip | |
split up unicode systems into different files
Diffstat (limited to 'quantum/process_keycode/process_unicode.c')
| -rw-r--r-- | quantum/process_keycode/process_unicode.c | 200 |
1 files changed, 0 insertions, 200 deletions
diff --git a/quantum/process_keycode/process_unicode.c b/quantum/process_keycode/process_unicode.c index 9d01a592d..898e168a3 100644 --- a/quantum/process_keycode/process_unicode.c +++ b/quantum/process_keycode/process_unicode.c | |||
| @@ -4,18 +4,6 @@ | |||
| 4 | static uint8_t input_mode; | 4 | static uint8_t input_mode; |
| 5 | uint8_t mods; | 5 | uint8_t mods; |
| 6 | 6 | ||
| 7 | __attribute__((weak)) | ||
| 8 | uint16_t hex_to_keycode(uint8_t hex) | ||
| 9 | { | ||
| 10 | if (hex == 0x0) { | ||
| 11 | return KC_0; | ||
| 12 | } else if (hex < 0xA) { | ||
| 13 | return KC_1 + (hex - 0x1); | ||
| 14 | } else { | ||
| 15 | return KC_A + (hex - 0xA); | ||
| 16 | } | ||
| 17 | } | ||
| 18 | |||
| 19 | void set_unicode_input_mode(uint8_t os_target) | 7 | void set_unicode_input_mode(uint8_t os_target) |
| 20 | { | 8 | { |
| 21 | input_mode = os_target; | 9 | input_mode = os_target; |
| @@ -108,191 +96,3 @@ bool process_unicode(uint16_t keycode, keyrecord_t *record) { | |||
| 108 | return true; | 96 | return true; |
| 109 | } | 97 | } |
| 110 | 98 | ||
| 111 | #ifdef UNICODEMAP_ENABLE | ||
| 112 | __attribute__((weak)) | ||
| 113 | const uint32_t PROGMEM unicode_map[] = { | ||
| 114 | }; | ||
| 115 | |||
| 116 | void register_hex32(uint32_t hex) { | ||
| 117 | uint8_t onzerostart = 1; | ||
| 118 | for(int i = 7; i >= 0; i--) { | ||
| 119 | if (i <= 3) { | ||
| 120 | onzerostart = 0; | ||
| 121 | } | ||
| 122 | uint8_t digit = ((hex >> (i*4)) & 0xF); | ||
| 123 | if (digit == 0) { | ||
| 124 | if (onzerostart == 0) { | ||
| 125 | register_code(hex_to_keycode(digit)); | ||
| 126 | unregister_code(hex_to_keycode(digit)); | ||
| 127 | } | ||
| 128 | } else { | ||
| 129 | register_code(hex_to_keycode(digit)); | ||
| 130 | unregister_code(hex_to_keycode(digit)); | ||
| 131 | onzerostart = 0; | ||
| 132 | } | ||
| 133 | } | ||
| 134 | } | ||
| 135 | |||
| 136 | __attribute__((weak)) | ||
| 137 | void unicode_map_input_error() {} | ||
| 138 | |||
| 139 | bool process_unicode_map(uint16_t keycode, keyrecord_t *record) { | ||
| 140 | if ((keycode & QK_UNICODE_MAP) == QK_UNICODE_MAP && record->event.pressed) { | ||
| 141 | const uint32_t* map = unicode_map; | ||
| 142 | uint16_t index = keycode - QK_UNICODE_MAP; | ||
| 143 | uint32_t code = pgm_read_dword_far(&map[index]); | ||
| 144 | if (code > 0xFFFF && code <= 0x10ffff && input_mode == UC_OSX) { | ||
| 145 | // Convert to UTF-16 surrogate pair | ||
| 146 | code -= 0x10000; | ||
| 147 | uint32_t lo = code & 0x3ff; | ||
| 148 | uint32_t hi = (code & 0xffc00) >> 10; | ||
| 149 | unicode_input_start(); | ||
| 150 | register_hex32(hi + 0xd800); | ||
| 151 | register_hex32(lo + 0xdc00); | ||
| 152 | unicode_input_finish(); | ||
| 153 | } else if ((code > 0x10ffff && input_mode == UC_OSX) || (code > 0xFFFFF && input_mode == UC_LNX)) { | ||
| 154 | // when character is out of range supported by the OS | ||
| 155 | unicode_map_input_error(); | ||
| 156 | } else { | ||
| 157 | unicode_input_start(); | ||
| 158 | register_hex32(code); | ||
| 159 | unicode_input_finish(); | ||
| 160 | } | ||
| 161 | } | ||
| 162 | return true; | ||
| 163 | } | ||
| 164 | #endif | ||
| 165 | |||
| 166 | #ifdef UCIS_ENABLE | ||
| 167 | qk_ucis_state_t qk_ucis_state; | ||
| 168 | |||
| 169 | void qk_ucis_start(void) { | ||
| 170 | qk_ucis_state.count = 0; | ||
| 171 | qk_ucis_state.in_progress = true; | ||
| 172 | |||
| 173 | qk_ucis_start_user(); | ||
| 174 | } | ||
| 175 | |||
| 176 | __attribute__((weak)) | ||
| 177 | void qk_ucis_start_user(void) { | ||
| 178 | unicode_input_start(); | ||
| 179 | register_hex(0x2328); | ||
| 180 | unicode_input_finish(); | ||
| 181 | } | ||
| 182 | |||
| 183 | static bool is_uni_seq(char *seq) { | ||
| 184 | uint8_t i; | ||
| 185 | |||
| 186 | for (i = 0; seq[i]; i++) { | ||
| 187 | uint16_t code; | ||
| 188 | if (('1' <= seq[i]) && (seq[i] <= '0')) | ||
| 189 | code = seq[i] - '1' + KC_1; | ||
| 190 | else | ||
| 191 | code = seq[i] - 'a' + KC_A; | ||
| 192 | |||
| 193 | if (i > qk_ucis_state.count || qk_ucis_state.codes[i] != code) | ||
| 194 | return false; | ||
| 195 | } | ||
| 196 | |||
| 197 | return (qk_ucis_state.codes[i] == KC_ENT || | ||
| 198 | qk_ucis_state.codes[i] == KC_SPC); | ||
| 199 | } | ||
| 200 | |||
| 201 | __attribute__((weak)) | ||
| 202 | void qk_ucis_symbol_fallback (void) { | ||
| 203 | for (uint8_t i = 0; i < qk_ucis_state.count - 1; i++) { | ||
| 204 | uint8_t code = qk_ucis_state.codes[i]; | ||
| 205 | register_code(code); | ||
| 206 | unregister_code(code); | ||
| 207 | wait_ms(UNICODE_TYPE_DELAY); | ||
| 208 | } | ||
| 209 | } | ||
| 210 | |||
| 211 | void register_ucis(const char *hex) { | ||
| 212 | for(int i = 0; hex[i]; i++) { | ||
| 213 | uint8_t kc = 0; | ||
| 214 | char c = hex[i]; | ||
| 215 | |||
| 216 | switch (c) { | ||
| 217 | case '0': | ||
| 218 | kc = KC_0; | ||
| 219 | break; | ||
| 220 | case '1' ... '9': | ||
| 221 | kc = c - '1' + KC_1; | ||
| 222 | break; | ||
| 223 | case 'a' ... 'f': | ||
| 224 | kc = c - 'a' + KC_A; | ||
| 225 | break; | ||
| 226 | case 'A' ... 'F': | ||
| 227 | kc = c - 'A' + KC_A; | ||
| 228 | break; | ||
| 229 | } | ||
| 230 | |||
| 231 | if (kc) { | ||
| 232 | register_code (kc); | ||
| 233 | unregister_code (kc); | ||
| 234 | wait_ms (UNICODE_TYPE_DELAY); | ||
| 235 | } | ||
| 236 | } | ||
| 237 | } | ||
| 238 | |||
| 239 | bool process_ucis (uint16_t keycode, keyrecord_t *record) { | ||
| 240 | uint8_t i; | ||
| 241 | |||
| 242 | if (!qk_ucis_state.in_progress) | ||
| 243 | return true; | ||
| 244 | |||
| 245 | if (qk_ucis_state.count >= UCIS_MAX_SYMBOL_LENGTH && | ||
| 246 | !(keycode == KC_BSPC || keycode == KC_ESC || keycode == KC_SPC || keycode == KC_ENT)) { | ||
| 247 | return false; | ||
| 248 | } | ||
| 249 | |||
| 250 | if (!record->event.pressed) | ||
| 251 | return true; | ||
| 252 | |||
| 253 | qk_ucis_state.codes[qk_ucis_state.count] = keycode; | ||
| 254 | qk_ucis_state.count++; | ||
| 255 | |||
| 256 | if (keycode == KC_BSPC) { | ||
| 257 | if (qk_ucis_state.count >= 2) { | ||
| 258 | qk_ucis_state.count -= 2; | ||
| 259 | return true; | ||
| 260 | } else { | ||
| 261 | qk_ucis_state.count--; | ||
| 262 | return false; | ||
| 263 | } | ||
| 264 | } | ||
| 265 | |||
| 266 | if (keycode == KC_ENT || keycode == KC_SPC || keycode == KC_ESC) { | ||
| 267 | bool symbol_found = false; | ||
| 268 | |||
| 269 | for (i = qk_ucis_state.count; i > 0; i--) { | ||
| 270 | register_code (KC_BSPC); | ||
| 271 | unregister_code (KC_BSPC); | ||
| 272 | wait_ms(UNICODE_TYPE_DELAY); | ||
| 273 | } | ||
| 274 | |||
| 275 | if (keycode == KC_ESC) { | ||
| 276 | qk_ucis_state.in_progress = false; | ||
| 277 | return false; | ||
| 278 | } | ||
| 279 | |||
| 280 | unicode_input_start(); | ||
| 281 | for (i = 0; ucis_symbol_table[i].symbol; i++) { | ||
| 282 | if (is_uni_seq (ucis_symbol_table[i].symbol)) { | ||
| 283 | symbol_found = true; | ||
| 284 | register_ucis(ucis_symbol_table[i].code + 2); | ||
| 285 | break; | ||
| 286 | } | ||
| 287 | } | ||
| 288 | if (!symbol_found) { | ||
| 289 | qk_ucis_symbol_fallback(); | ||
| 290 | } | ||
| 291 | unicode_input_finish(); | ||
| 292 | |||
| 293 | qk_ucis_state.in_progress = false; | ||
| 294 | return false; | ||
| 295 | } | ||
| 296 | return true; | ||
| 297 | } | ||
| 298 | #endif | ||
