diff options
-rw-r--r-- | Makefile | 7 | ||||
-rw-r--r-- | quantum/process_keycode/process_unicode.c | 93 | ||||
-rw-r--r-- | quantum/process_keycode/process_unicode.h | 29 |
3 files changed, 126 insertions, 3 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 55e47f179..8a6509300 100644 --- a/quantum/process_keycode/process_unicode.c +++ b/quantum/process_keycode/process_unicode.c | |||
@@ -68,4 +68,95 @@ bool process_unicode(uint16_t keycode, keyrecord_t *record) { | |||
68 | unicode_input_finish(); | 68 | unicode_input_finish(); |
69 | } | 69 | } |
70 | return true; | 70 | return true; |
71 | } \ No newline at end of file | 71 | } |
72 | |||
73 | #ifdef UCIS_ENABLE | ||
74 | void qk_ucis_start(void) { | ||
75 | qk_ucis_state.count = 0; | ||
76 | qk_ucis_state.in_progress = true; | ||
77 | |||
78 | unicode_input_start(); | ||
79 | register_hex(0x2328); | ||
80 | unicode_input_finish(); | ||
81 | } | ||
82 | |||
83 | static bool is_uni_seq(char *seq) { | ||
84 | uint8_t i; | ||
85 | |||
86 | for (i = 0; seq[i]; i++) { | ||
87 | uint16_t code; | ||
88 | if (('1' <= seq[i]) && (seq[i] <= '0')) | ||
89 | code = seq[i] - '1' + KC_1; | ||
90 | else | ||
91 | code = seq[i] - 'a' + KC_A; | ||
92 | |||
93 | if (i > qk_ucis_state.count || qk_ucis_state.codes[i] != code) | ||
94 | return false; | ||
95 | } | ||
96 | |||
97 | return (qk_ucis_state.codes[i] == KC_ENT || | ||
98 | qk_ucis_state.codes[i] == KC_SPC); | ||
99 | } | ||
100 | |||
101 | __attribute__((weak)) | ||
102 | void qk_ucis_symbol_fallback (void) { | ||
103 | for (uint8_t i = 0; i < qk_ucis_state.count - 1; i++) { | ||
104 | uint8_t code = qk_ucis_state.codes[i]; | ||
105 | register_code(code); | ||
106 | unregister_code(code); | ||
107 | } | ||
108 | } | ||
109 | |||
110 | bool process_record_ucis (uint16_t keycode, keyrecord_t *record) { | ||
111 | uint8_t i; | ||
112 | |||
113 | if (!qk_ucis_state.in_progress || !record->event.pressed) | ||
114 | return true; | ||
115 | |||
116 | qk_ucis_state.codes[qk_ucis_state.count] = keycode; | ||
117 | qk_ucis_state.count++; | ||
118 | |||
119 | if (keycode == KC_BSPC) { | ||
120 | if (qk_ucis_state.count >= 2) { | ||
121 | qk_ucis_state.count -= 2; | ||
122 | return true; | ||
123 | } else { | ||
124 | qk_ucis_state.count--; | ||
125 | return false; | ||
126 | } | ||
127 | } | ||
128 | |||
129 | if (keycode == KC_ENT || keycode == KC_SPC || keycode == KC_ESC) { | ||
130 | bool symbol_found = false; | ||
131 | |||
132 | for (i = qk_ucis_state.count; i > 0; i--) { | ||
133 | register_code (KC_BSPC); | ||
134 | unregister_code (KC_BSPC); | ||
135 | } | ||
136 | |||
137 | if (keycode == KC_ESC) { | ||
138 | qk_ucis_state.in_progress = false; | ||
139 | return false; | ||
140 | } | ||
141 | |||
142 | unicode_input_start(); | ||
143 | for (i = 0; ucis_symbol_table[i].symbol; i++) { | ||
144 | if (is_uni_seq (ucis_symbol_table[i].symbol)) { | ||
145 | symbol_found = true; | ||
146 | for (uint8_t j = 0; ucis_symbol_table[i].codes[j]; j++) { | ||
147 | register_hex(ucis_symbol_table[i].codes[j]); | ||
148 | } | ||
149 | break; | ||
150 | } | ||
151 | } | ||
152 | if (!symbol_found) { | ||
153 | qk_ucis_symbol_fallback(); | ||
154 | } | ||
155 | unicode_input_finish(); | ||
156 | |||
157 | qk_ucis_state.in_progress = false; | ||
158 | return false; | ||
159 | } | ||
160 | return true; | ||
161 | } | ||
162 | #endif | ||
diff --git a/quantum/process_keycode/process_unicode.h b/quantum/process_keycode/process_unicode.h index f719a1226..372ea2f0d 100644 --- a/quantum/process_keycode/process_unicode.h +++ b/quantum/process_keycode/process_unicode.h | |||
@@ -15,6 +15,33 @@ void register_hex(uint16_t hex); | |||
15 | 15 | ||
16 | bool process_unicode(uint16_t keycode, keyrecord_t *record); | 16 | bool process_unicode(uint16_t keycode, keyrecord_t *record); |
17 | 17 | ||
18 | #ifdef UCIS_ENABLE | ||
19 | #ifndef UCIS_MAX_SYMBOL_LENGTH | ||
20 | #define UCIS_MAX_SYMBOL_LENGTH 32 | ||
21 | #endif | ||
22 | |||
23 | typedef struct { | ||
24 | char *symbol; | ||
25 | uint16_t codes[4]; | ||
26 | } qk_ucis_symbol_t; | ||
27 | |||
28 | struct { | ||
29 | uint8_t count; | ||
30 | uint16_t codes[UCIS_MAX_SYMBOL_LENGTH]; | ||
31 | bool in_progress:1; | ||
32 | } qk_ucis_state; | ||
33 | |||
34 | #define UCIS_TABLE(...) {__VA_ARGS__, {NULL, {}}} | ||
35 | #define UCIS_SYM(name, ...) {name, {__VA_ARGS__, 0}} | ||
36 | |||
37 | extern const qk_ucis_symbol_t ucis_symbol_table[]; | ||
38 | |||
39 | void qk_ucis_start(void); | ||
40 | void qk_ucis_symbol_fallback (void); | ||
41 | bool process_record_ucis (uint16_t keycode, keyrecord_t *record); | ||
42 | |||
43 | #endif | ||
44 | |||
18 | #define UC_BSPC UC(0x0008) | 45 | #define UC_BSPC UC(0x0008) |
19 | 46 | ||
20 | #define UC_SPC UC(0x0020) | 47 | #define UC_SPC UC(0x0020) |
@@ -122,4 +149,4 @@ bool process_unicode(uint16_t keycode, keyrecord_t *record); | |||
122 | #define UC_TILD UC(0x007E) | 149 | #define UC_TILD UC(0x007E) |
123 | #define UC_DEL UC(0x007F) | 150 | #define UC_DEL UC(0x007F) |
124 | 151 | ||
125 | #endif \ No newline at end of file | 152 | #endif |