diff options
| author | Konstantin Đorđević <vomindoraan@gmail.com> | 2019-01-07 21:56:57 +0100 |
|---|---|---|
| committer | Drashna Jaelre <drashna@live.com> | 2019-01-07 12:56:57 -0800 |
| commit | cd9262d7b2dcde5d31aa34f066dd593a012d7049 (patch) | |
| tree | bb9cda36efc39af997e019af4f6a91f451d12807 /quantum | |
| parent | 6e984a8b5e34ba181b0893a929af569a1faef2b6 (diff) | |
| download | qmk_firmware-cd9262d7b2dcde5d31aa34f066dd593a012d7049.tar.gz qmk_firmware-cd9262d7b2dcde5d31aa34f066dd593a012d7049.zip | |
Improve consistency in UNICODEMAP code and docs, update docs/understanding_qmk (#4774)
* Remove unused UNICODE(n) macro, update docs
* Add note about max length of unicode_map to docs
* QK_UNICODE_MAP → QK_UNICODEMAP
* Refactor process_unicode_map
* process_unicode_map → process_unicodemap
This is done for consistency: UNICODEMAP is the method (hence UNICODEMAP_ENABLE, process_unicodemap), whereas unicode_map is the mapping table itself.
* Update references and ordering in docs/understanding_qmk
* Add additional note to docs/understanding_qmk
* &unicode_map[index] → unicode_map + index
This avoids the issue of the compiler sometimes complaining about the array index being out of range
* Update docs/getting_started_make_guide
* Update method sections in docs/feature_unicode
Diffstat (limited to 'quantum')
| -rw-r--r-- | quantum/process_keycode/process_unicode_common.c | 2 | ||||
| -rw-r--r-- | quantum/process_keycode/process_unicodemap.c | 33 | ||||
| -rw-r--r-- | quantum/process_keycode/process_unicodemap.h | 4 | ||||
| -rw-r--r-- | quantum/quantum_keycodes.h | 15 |
4 files changed, 25 insertions, 29 deletions
diff --git a/quantum/process_keycode/process_unicode_common.c b/quantum/process_keycode/process_unicode_common.c index 3286f45b5..b64feb700 100644 --- a/quantum/process_keycode/process_unicode_common.c +++ b/quantum/process_keycode/process_unicode_common.c | |||
| @@ -216,7 +216,7 @@ bool process_unicode_common(uint16_t keycode, keyrecord_t *record) { | |||
| 216 | #if defined(UNICODE_ENABLE) | 216 | #if defined(UNICODE_ENABLE) |
| 217 | return process_unicode(keycode, record); | 217 | return process_unicode(keycode, record); |
| 218 | #elif defined(UNICODEMAP_ENABLE) | 218 | #elif defined(UNICODEMAP_ENABLE) |
| 219 | return process_unicode_map(keycode, record); | 219 | return process_unicodemap(keycode, record); |
| 220 | #elif defined(UCIS_ENABLE) | 220 | #elif defined(UCIS_ENABLE) |
| 221 | return process_ucis(keycode, record); | 221 | return process_ucis(keycode, record); |
| 222 | #else | 222 | #else |
diff --git a/quantum/process_keycode/process_unicodemap.c b/quantum/process_keycode/process_unicodemap.c index 75f35112b..cee9acb5f 100644 --- a/quantum/process_keycode/process_unicodemap.c +++ b/quantum/process_keycode/process_unicodemap.c | |||
| @@ -18,8 +18,7 @@ | |||
| 18 | #include "process_unicode_common.h" | 18 | #include "process_unicode_common.h" |
| 19 | 19 | ||
| 20 | __attribute__((weak)) | 20 | __attribute__((weak)) |
| 21 | const uint32_t PROGMEM unicode_map[] = { | 21 | const uint32_t PROGMEM unicode_map[] = {}; |
| 22 | }; | ||
| 23 | 22 | ||
| 24 | void register_hex32(uint32_t hex) { | 23 | void register_hex32(uint32_t hex) { |
| 25 | bool onzerostart = true; | 24 | bool onzerostart = true; |
| @@ -42,26 +41,26 @@ void register_hex32(uint32_t hex) { | |||
| 42 | } | 41 | } |
| 43 | 42 | ||
| 44 | __attribute__((weak)) | 43 | __attribute__((weak)) |
| 45 | void unicode_map_input_error() {} | 44 | void unicodemap_input_error() {} |
| 46 | 45 | ||
| 47 | bool process_unicode_map(uint16_t keycode, keyrecord_t *record) { | 46 | bool process_unicodemap(uint16_t keycode, keyrecord_t *record) { |
| 48 | uint8_t input_mode = get_unicode_input_mode(); | 47 | if ((keycode & QK_UNICODEMAP) == QK_UNICODEMAP && record->event.pressed) { |
| 49 | if ((keycode & QK_UNICODE_MAP) == QK_UNICODE_MAP && record->event.pressed) { | 48 | uint16_t index = keycode - QK_UNICODEMAP; |
| 50 | const uint32_t* map = unicode_map; | 49 | uint32_t code = pgm_read_dword(unicode_map + index); |
| 51 | uint16_t index = keycode - QK_UNICODE_MAP; | 50 | uint8_t input_mode = get_unicode_input_mode(); |
| 52 | uint32_t code = pgm_read_dword(&map[index]); | 51 | |
| 53 | if (code > 0xFFFF && code <= 0x10ffff && input_mode == UC_OSX) { | 52 | if (code > 0xFFFF && code <= 0x10FFFF && input_mode == UC_OSX) { |
| 54 | // Convert to UTF-16 surrogate pair | 53 | // Convert to UTF-16 surrogate pair |
| 55 | code -= 0x10000; | 54 | code -= 0x10000; |
| 56 | uint32_t lo = code & 0x3ff; | 55 | uint32_t lo = code & 0x3FF, hi = (code & 0xFFC00) >> 10; |
| 57 | uint32_t hi = (code & 0xffc00) >> 10; | 56 | |
| 58 | unicode_input_start(); | 57 | unicode_input_start(); |
| 59 | register_hex32(hi + 0xd800); | 58 | register_hex32(hi + 0xD800); |
| 60 | register_hex32(lo + 0xdc00); | 59 | register_hex32(lo + 0xDC00); |
| 61 | unicode_input_finish(); | 60 | unicode_input_finish(); |
| 62 | } else if ((code > 0x10ffff && input_mode == UC_OSX) || (code > 0xFFFFF && input_mode == UC_LNX)) { | 61 | } else if ((code > 0x10FFFF && input_mode == UC_OSX) || (code > 0xFFFFF && input_mode == UC_LNX)) { |
| 63 | // when character is out of range supported by the OS | 62 | // Character is out of range supported by the OS |
| 64 | unicode_map_input_error(); | 63 | unicodemap_input_error(); |
| 65 | } else { | 64 | } else { |
| 66 | unicode_input_start(); | 65 | unicode_input_start(); |
| 67 | register_hex32(code); | 66 | register_hex32(code); |
diff --git a/quantum/process_keycode/process_unicodemap.h b/quantum/process_keycode/process_unicodemap.h index f6d64bb86..5764697f8 100644 --- a/quantum/process_keycode/process_unicodemap.h +++ b/quantum/process_keycode/process_unicodemap.h | |||
| @@ -19,5 +19,5 @@ | |||
| 19 | #include "quantum.h" | 19 | #include "quantum.h" |
| 20 | #include "process_unicode_common.h" | 20 | #include "process_unicode_common.h" |
| 21 | 21 | ||
| 22 | void unicode_map_input_error(void); | 22 | void unicodemap_input_error(void); |
| 23 | bool process_unicode_map(uint16_t keycode, keyrecord_t *record); | 23 | bool process_unicodemap(uint16_t keycode, keyrecord_t *record); |
diff --git a/quantum/quantum_keycodes.h b/quantum/quantum_keycodes.h index 2b309f4d5..ccf5371f0 100644 --- a/quantum/quantum_keycodes.h +++ b/quantum/quantum_keycodes.h | |||
| @@ -86,8 +86,8 @@ enum quantum_keycodes { | |||
| 86 | QK_UNICODE_MAX = 0xFFFF, | 86 | QK_UNICODE_MAX = 0xFFFF, |
| 87 | #endif | 87 | #endif |
| 88 | #ifdef UNICODEMAP_ENABLE | 88 | #ifdef UNICODEMAP_ENABLE |
| 89 | QK_UNICODE_MAP = 0x8000, | 89 | QK_UNICODEMAP = 0x8000, |
| 90 | QK_UNICODE_MAP_MAX = 0x83FF, | 90 | QK_UNICODEMAP_MAX = 0x83FF, |
| 91 | #endif | 91 | #endif |
| 92 | 92 | ||
| 93 | // Loose keycodes - to be used directly | 93 | // Loose keycodes - to be used directly |
| @@ -679,15 +679,12 @@ enum quantum_keycodes { | |||
| 679 | #define KC_MEH MEH(KC_NO) | 679 | #define KC_MEH MEH(KC_NO) |
| 680 | 680 | ||
| 681 | #ifdef UNICODE_ENABLE | 681 | #ifdef UNICODE_ENABLE |
| 682 | // For sending unicode codes. | 682 | // Allows Unicode input up to 0x7FFF |
| 683 | // You may not send codes over 7FFF -- this supports most of UTF8. | 683 | #define UC(c) (QK_UNICODE | (c)) |
| 684 | // To have a key that sends out Œ, go UC(0x0152) | ||
| 685 | #define UNICODE(n) (QK_UNICODE | (n)) | ||
| 686 | #define UC(n) UNICODE(n) | ||
| 687 | #endif | 684 | #endif |
| 688 | |||
| 689 | #ifdef UNICODEMAP_ENABLE | 685 | #ifdef UNICODEMAP_ENABLE |
| 690 | #define X(n) (QK_UNICODE_MAP | (n)) | 686 | // Allows Unicode input up to 0x10FFFF, requires unicode_map |
| 687 | #define X(i) (QK_UNICODEMAP | (i)) | ||
| 691 | #endif | 688 | #endif |
| 692 | 689 | ||
| 693 | #define UC_MOD UNICODE_MODE_FORWARD | 690 | #define UC_MOD UNICODE_MODE_FORWARD |
