diff options
| -rw-r--r-- | Makefile | 7 | ||||
| -rw-r--r-- | quantum/process_keycode/process_unicode.c | 203 | ||||
| -rw-r--r-- | quantum/process_keycode/process_unicode.h | 38 | ||||
| -rw-r--r-- | quantum/quantum.c | 3 |
4 files changed, 221 insertions, 30 deletions
| @@ -198,6 +198,11 @@ ifeq ($(strip $(AUDIO_ENABLE)), yes) | |||
| 198 | SRC += $(QUANTUM_DIR)/audio/luts.c | 198 | SRC += $(QUANTUM_DIR)/audio/luts.c |
| 199 | endif | 199 | endif |
| 200 | 200 | ||
| 201 | ifeq ($(strip $(UCIS_ENABLE)), yes) | ||
| 202 | OPT_DEFS += -DUCIS_ENABLE | ||
| 203 | UNICODE_ENABLE = yes | ||
| 204 | endif | ||
| 205 | |||
| 201 | ifeq ($(strip $(UNICODE_ENABLE)), yes) | 206 | ifeq ($(strip $(UNICODE_ENABLE)), yes) |
| 202 | OPT_DEFS += -DUNICODE_ENABLE | 207 | OPT_DEFS += -DUNICODE_ENABLE |
| 203 | SRC += $(QUANTUM_DIR)/process_keycode/process_unicode.c | 208 | SRC += $(QUANTUM_DIR)/process_keycode/process_unicode.c |
| @@ -273,4 +278,4 @@ BUILD_DATE := $(shell date +"%Y-%m-%d-%H:%M:%S") | |||
| 273 | OPT_DEFS += -DQMK_KEYBOARD=\"$(KEYBOARD)\" -DQMK_KEYMAP=\"$(KEYMAP)\" | 278 | OPT_DEFS += -DQMK_KEYBOARD=\"$(KEYBOARD)\" -DQMK_KEYMAP=\"$(KEYMAP)\" |
| 274 | 279 | ||
| 275 | $(shell echo '#define QMK_VERSION "$(GIT_VERSION)"' > $(QUANTUM_PATH)/version.h) | 280 | $(shell echo '#define QMK_VERSION "$(GIT_VERSION)"' > $(QUANTUM_PATH)/version.h) |
| 276 | $(shell echo '#define QMK_BUILDDATE "$(BUILD_DATE)"' >> $(QUANTUM_PATH)/version.h) \ No newline at end of file | 281 | $(shell echo '#define QMK_BUILDDATE "$(BUILD_DATE)"' >> $(QUANTUM_PATH)/version.h) |
diff --git a/quantum/process_keycode/process_unicode.c b/quantum/process_keycode/process_unicode.c index 3fcac15ce..72c809c30 100644 --- a/quantum/process_keycode/process_unicode.c +++ b/quantum/process_keycode/process_unicode.c | |||
| @@ -18,40 +18,187 @@ void set_unicode_input_mode(uint8_t os_target) | |||
| 18 | input_mode = os_target; | 18 | input_mode = os_target; |
| 19 | } | 19 | } |
| 20 | 20 | ||
| 21 | void unicode_input_start (void) { | ||
| 22 | switch(input_mode) { | ||
| 23 | case UC_OSX: | ||
| 24 | register_code(KC_LALT); | ||
| 25 | break; | ||
| 26 | case UC_LNX: | ||
| 27 | register_code(KC_LCTL); | ||
| 28 | register_code(KC_LSFT); | ||
| 29 | register_code(KC_U); | ||
| 30 | unregister_code(KC_U); | ||
| 31 | unregister_code(KC_LSFT); | ||
| 32 | unregister_code(KC_LCTL); | ||
| 33 | break; | ||
| 34 | case UC_WIN: | ||
| 35 | register_code(KC_LALT); | ||
| 36 | register_code(KC_PPLS); | ||
| 37 | unregister_code(KC_PPLS); | ||
| 38 | break; | ||
| 39 | } | ||
| 40 | wait_ms(UNICODE_TYPE_DELAY); | ||
| 41 | } | ||
| 42 | |||
| 43 | void unicode_input_finish (void) { | ||
| 44 | switch(input_mode) { | ||
| 45 | case UC_OSX: | ||
| 46 | case UC_WIN: | ||
| 47 | unregister_code(KC_LALT); | ||
| 48 | break; | ||
| 49 | case UC_LNX: | ||
| 50 | register_code(KC_SPC); | ||
| 51 | unregister_code(KC_SPC); | ||
| 52 | break; | ||
| 53 | } | ||
| 54 | } | ||
| 55 | |||
| 56 | void register_hex(uint16_t hex) { | ||
| 57 | for(int i = 3; i >= 0; i--) { | ||
| 58 | uint8_t digit = ((hex >> (i*4)) & 0xF); | ||
| 59 | register_code(hex_to_keycode(digit)); | ||
| 60 | unregister_code(hex_to_keycode(digit)); | ||
| 61 | } | ||
| 62 | } | ||
| 63 | |||
| 21 | bool process_unicode(uint16_t keycode, keyrecord_t *record) { | 64 | bool process_unicode(uint16_t keycode, keyrecord_t *record) { |
| 22 | if (keycode > QK_UNICODE && record->event.pressed) { | 65 | if (keycode > QK_UNICODE && record->event.pressed) { |
| 23 | uint16_t unicode = keycode & 0x7FFF; | 66 | uint16_t unicode = keycode & 0x7FFF; |
| 24 | switch(input_mode) { | 67 | unicode_input_start(); |
| 25 | case UC_OSX: | 68 | register_hex(unicode); |
| 26 | register_code(KC_LALT); | 69 | unicode_input_finish(); |
| 27 | break; | 70 | } |
| 28 | case UC_LNX: | 71 | return true; |
| 29 | register_code(KC_LCTL); | 72 | } |
| 30 | register_code(KC_LSFT); | 73 | |
| 31 | register_code(KC_U); | 74 | #ifdef UCIS_ENABLE |
| 32 | unregister_code(KC_U); | 75 | void qk_ucis_start(void) { |
| 33 | break; | 76 | qk_ucis_state.count = 0; |
| 34 | case UC_WIN: | 77 | qk_ucis_state.in_progress = true; |
| 35 | register_code(KC_LALT); | 78 | |
| 36 | register_code(KC_PPLS); | 79 | qk_ucis_start_user(); |
| 37 | unregister_code(KC_PPLS); | 80 | } |
| 38 | break; | 81 | |
| 82 | __attribute__((weak)) | ||
| 83 | void qk_ucis_start_user(void) { | ||
| 84 | unicode_input_start(); | ||
| 85 | register_hex(0x2328); | ||
| 86 | unicode_input_finish(); | ||
| 87 | } | ||
| 88 | |||
| 89 | static bool is_uni_seq(char *seq) { | ||
| 90 | uint8_t i; | ||
| 91 | |||
| 92 | for (i = 0; seq[i]; i++) { | ||
| 93 | uint16_t code; | ||
| 94 | if (('1' <= seq[i]) && (seq[i] <= '0')) | ||
| 95 | code = seq[i] - '1' + KC_1; | ||
| 96 | else | ||
| 97 | code = seq[i] - 'a' + KC_A; | ||
| 98 | |||
| 99 | if (i > qk_ucis_state.count || qk_ucis_state.codes[i] != code) | ||
| 100 | return false; | ||
| 101 | } | ||
| 102 | |||
| 103 | return (qk_ucis_state.codes[i] == KC_ENT || | ||
| 104 | qk_ucis_state.codes[i] == KC_SPC); | ||
| 105 | } | ||
| 106 | |||
| 107 | __attribute__((weak)) | ||
| 108 | void qk_ucis_symbol_fallback (void) { | ||
| 109 | for (uint8_t i = 0; i < qk_ucis_state.count - 1; i++) { | ||
| 110 | uint8_t code = qk_ucis_state.codes[i]; | ||
| 111 | register_code(code); | ||
| 112 | unregister_code(code); | ||
| 113 | wait_ms(UNICODE_TYPE_DELAY); | ||
| 114 | } | ||
| 115 | } | ||
| 116 | |||
| 117 | void register_ucis(const char *hex) { | ||
| 118 | for(int i = 0; hex[i]; i++) { | ||
| 119 | uint8_t kc = 0; | ||
| 120 | char c = hex[i]; | ||
| 121 | |||
| 122 | switch (c) { | ||
| 123 | case '0': | ||
| 124 | kc = KC_0; | ||
| 125 | break; | ||
| 126 | case '1' ... '9': | ||
| 127 | kc = c - '1' + KC_1; | ||
| 128 | break; | ||
| 129 | case 'a' ... 'f': | ||
| 130 | kc = c - 'a' + KC_A; | ||
| 131 | break; | ||
| 132 | case 'A' ... 'F': | ||
| 133 | kc = c - 'A' + KC_A; | ||
| 134 | break; | ||
| 39 | } | 135 | } |
| 40 | for(int i = 3; i >= 0; i--) { | 136 | |
| 41 | uint8_t digit = ((unicode >> (i*4)) & 0xF); | 137 | if (kc) { |
| 42 | register_code(hex_to_keycode(digit)); | 138 | register_code (kc); |
| 43 | unregister_code(hex_to_keycode(digit)); | 139 | unregister_code (kc); |
| 140 | wait_ms (UNICODE_TYPE_DELAY); | ||
| 44 | } | 141 | } |
| 45 | switch(input_mode) { | 142 | } |
| 46 | case UC_OSX: | 143 | } |
| 47 | case UC_WIN: | 144 | |
| 48 | unregister_code(KC_LALT); | 145 | bool process_ucis (uint16_t keycode, keyrecord_t *record) { |
| 49 | break; | 146 | uint8_t i; |
| 50 | case UC_LNX: | 147 | |
| 51 | unregister_code(KC_LCTL); | 148 | if (!qk_ucis_state.in_progress) |
| 52 | unregister_code(KC_LSFT); | 149 | return true; |
| 150 | |||
| 151 | if (qk_ucis_state.count >= UCIS_MAX_SYMBOL_LENGTH && | ||
| 152 | !(keycode == KC_BSPC || keycode == KC_ESC || keycode == KC_SPC || keycode == KC_ENT)) { | ||
| 153 | return false; | ||
| 154 | } | ||
| 155 | |||
| 156 | if (!record->event.pressed) | ||
| 157 | return true; | ||
| 158 | |||
| 159 | qk_ucis_state.codes[qk_ucis_state.count] = keycode; | ||
| 160 | qk_ucis_state.count++; | ||
| 161 | |||
| 162 | if (keycode == KC_BSPC) { | ||
| 163 | if (qk_ucis_state.count >= 2) { | ||
| 164 | qk_ucis_state.count -= 2; | ||
| 165 | return true; | ||
| 166 | } else { | ||
| 167 | qk_ucis_state.count--; | ||
| 168 | return false; | ||
| 169 | } | ||
| 170 | } | ||
| 171 | |||
| 172 | if (keycode == KC_ENT || keycode == KC_SPC || keycode == KC_ESC) { | ||
| 173 | bool symbol_found = false; | ||
| 174 | |||
| 175 | for (i = qk_ucis_state.count; i > 0; i--) { | ||
| 176 | register_code (KC_BSPC); | ||
| 177 | unregister_code (KC_BSPC); | ||
| 178 | wait_ms(UNICODE_TYPE_DELAY); | ||
| 179 | } | ||
| 180 | |||
| 181 | if (keycode == KC_ESC) { | ||
| 182 | qk_ucis_state.in_progress = false; | ||
| 183 | return false; | ||
| 184 | } | ||
| 185 | |||
| 186 | unicode_input_start(); | ||
| 187 | for (i = 0; ucis_symbol_table[i].symbol; i++) { | ||
| 188 | if (is_uni_seq (ucis_symbol_table[i].symbol)) { | ||
| 189 | symbol_found = true; | ||
| 190 | register_ucis(ucis_symbol_table[i].code + 2); | ||
| 53 | break; | 191 | break; |
| 192 | } | ||
| 54 | } | 193 | } |
| 194 | if (!symbol_found) { | ||
| 195 | qk_ucis_symbol_fallback(); | ||
| 196 | } | ||
| 197 | unicode_input_finish(); | ||
| 198 | |||
| 199 | qk_ucis_state.in_progress = false; | ||
| 200 | return false; | ||
| 55 | } | 201 | } |
| 56 | return true; | 202 | return true; |
| 57 | } \ No newline at end of file | 203 | } |
| 204 | #endif | ||
diff --git a/quantum/process_keycode/process_unicode.h b/quantum/process_keycode/process_unicode.h index ca17f8f66..85364e8eb 100644 --- a/quantum/process_keycode/process_unicode.h +++ b/quantum/process_keycode/process_unicode.h | |||
| @@ -8,10 +8,46 @@ | |||
| 8 | #define UC_WIN 2 | 8 | #define UC_WIN 2 |
| 9 | #define UC_BSD 3 | 9 | #define UC_BSD 3 |
| 10 | 10 | ||
| 11 | #ifndef UNICODE_TYPE_DELAY | ||
| 12 | #define UNICODE_TYPE_DELAY 10 | ||
| 13 | #endif | ||
| 14 | |||
| 11 | void set_unicode_input_mode(uint8_t os_target); | 15 | void set_unicode_input_mode(uint8_t os_target); |
| 16 | void unicode_input_start(void); | ||
| 17 | void unicode_input_finish(void); | ||
| 18 | void register_hex(uint16_t hex); | ||
| 12 | 19 | ||
| 13 | bool process_unicode(uint16_t keycode, keyrecord_t *record); | 20 | bool process_unicode(uint16_t keycode, keyrecord_t *record); |
| 14 | 21 | ||
| 22 | #ifdef UCIS_ENABLE | ||
| 23 | #ifndef UCIS_MAX_SYMBOL_LENGTH | ||
| 24 | #define UCIS_MAX_SYMBOL_LENGTH 32 | ||
| 25 | #endif | ||
| 26 | |||
| 27 | typedef struct { | ||
| 28 | char *symbol; | ||
| 29 | char *code; | ||
| 30 | } qk_ucis_symbol_t; | ||
| 31 | |||
| 32 | struct { | ||
| 33 | uint8_t count; | ||
| 34 | uint16_t codes[UCIS_MAX_SYMBOL_LENGTH]; | ||
| 35 | bool in_progress:1; | ||
| 36 | } qk_ucis_state; | ||
| 37 | |||
| 38 | #define UCIS_TABLE(...) {__VA_ARGS__, {NULL, NULL}} | ||
| 39 | #define UCIS_SYM(name, code) {name, #code} | ||
| 40 | |||
| 41 | extern const qk_ucis_symbol_t ucis_symbol_table[]; | ||
| 42 | |||
| 43 | void qk_ucis_start(void); | ||
| 44 | void qk_ucis_start_user(void); | ||
| 45 | void qk_ucis_symbol_fallback (void); | ||
| 46 | void register_ucis(const char *hex); | ||
| 47 | bool process_ucis (uint16_t keycode, keyrecord_t *record); | ||
| 48 | |||
| 49 | #endif | ||
| 50 | |||
| 15 | #define UC_BSPC UC(0x0008) | 51 | #define UC_BSPC UC(0x0008) |
| 16 | 52 | ||
| 17 | #define UC_SPC UC(0x0020) | 53 | #define UC_SPC UC(0x0020) |
| @@ -119,4 +155,4 @@ bool process_unicode(uint16_t keycode, keyrecord_t *record); | |||
| 119 | #define UC_TILD UC(0x007E) | 155 | #define UC_TILD UC(0x007E) |
| 120 | #define UC_DEL UC(0x007F) | 156 | #define UC_DEL UC(0x007F) |
| 121 | 157 | ||
| 122 | #endif \ No newline at end of file | 158 | #endif |
diff --git a/quantum/quantum.c b/quantum/quantum.c index bc2da510f..a4c5c2ddb 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c | |||
| @@ -87,6 +87,9 @@ bool process_record_quantum(keyrecord_t *record) { | |||
| 87 | #ifdef UNICODE_ENABLE | 87 | #ifdef UNICODE_ENABLE |
| 88 | process_unicode(keycode, record) && | 88 | process_unicode(keycode, record) && |
| 89 | #endif | 89 | #endif |
| 90 | #ifdef UCIS_ENABLE | ||
| 91 | process_ucis(keycode, record) && | ||
| 92 | #endif | ||
| 90 | true)) { | 93 | true)) { |
| 91 | return false; | 94 | return false; |
| 92 | } | 95 | } |
