summaryrefslogtreecommitdiff
path: root/quantum/process_keycode/process_ucis.c
diff options
context:
space:
mode:
authorRyan <fauxpark@gmail.com>2023-08-27 13:30:19 +1000
committerGitHub <noreply@github.com>2023-08-27 13:30:19 +1000
commit70e34e491c297231a3f987fd69760d38e79dbfa4 (patch)
treea3fe26ea27c9d020142f4c248fa0bab5d32c1f9c /quantum/process_keycode/process_ucis.c
parent95681b8ff4a92aacd0249e124d34cf16e510175e (diff)
Unicode, Unicodemap and UCIS refactor (#21659)
Diffstat (limited to 'quantum/process_keycode/process_ucis.c')
-rw-r--r--quantum/process_keycode/process_ucis.c120
1 files changed, 20 insertions, 100 deletions
diff --git a/quantum/process_keycode/process_ucis.c b/quantum/process_keycode/process_ucis.c
index 3aa09d5948..91a038bab1 100644
--- a/quantum/process_keycode/process_ucis.c
+++ b/quantum/process_keycode/process_ucis.c
@@ -15,110 +15,30 @@
15 */ 15 */
16 16
17#include "process_ucis.h" 17#include "process_ucis.h"
18#include "unicode.h" 18#include "ucis.h"
19#include "keycode.h" 19#include "keycodes.h"
20#include "wait.h"
21 20
22ucis_state_t ucis_state; 21bool process_ucis(uint16_t keycode, keyrecord_t *record) {
23 22 if (ucis_active() && record->event.pressed) {
24void ucis_start(void) { 23 bool special = keycode == KC_SPACE || keycode == KC_ENTER || keycode == KC_ESCAPE || keycode == KC_BACKSPACE;
25 ucis_state.count = 0; 24 if (ucis_count() >= UCIS_MAX_INPUT_LENGTH && !special) {
26 ucis_state.in_progress = true;
27
28 ucis_start_user();
29}
30
31__attribute__((weak)) void ucis_start_user(void) {
32 register_unicode(0x2328); // ⌨
33}
34
35__attribute__((weak)) void ucis_success(uint8_t symbol_index) {}
36
37static bool is_uni_seq(char *seq) {
38 uint8_t i;
39 for (i = 0; seq[i]; i++) {
40 uint16_t keycode;
41 if ('1' <= seq[i] && seq[i] <= '0') {
42 keycode = seq[i] - '1' + KC_1;
43 } else {
44 keycode = seq[i] - 'a' + KC_A;
45 }
46 if (i > ucis_state.count || ucis_state.codes[i] != keycode) {
47 return false; 25 return false;
48 } 26 }
49 }
50 return ucis_state.codes[i] == KC_ENTER || ucis_state.codes[i] == KC_SPACE;
51}
52
53__attribute__((weak)) void ucis_symbol_fallback(void) {
54 for (uint8_t i = 0; i < ucis_state.count - 1; i++) {
55 tap_code(ucis_state.codes[i]);
56 }
57}
58
59__attribute__((weak)) void ucis_cancel(void) {}
60
61void register_ucis(const uint32_t *code_points) {
62 for (int i = 0; i < UCIS_MAX_CODE_POINTS && code_points[i]; i++) {
63 register_unicode(code_points[i]);
64 }
65}
66 27
67bool process_ucis(uint16_t keycode, keyrecord_t *record) { 28 if (!ucis_add(keycode)) {
68 if (!ucis_state.in_progress || !record->event.pressed) { 29 switch (keycode) {
69 return true; 30 case KC_BACKSPACE:
70 } 31 return ucis_remove_last();
71 32 case KC_ESCAPE:
72 bool special = keycode == KC_SPACE || keycode == KC_ENTER || keycode == KC_ESCAPE || keycode == KC_BACKSPACE; 33 ucis_cancel();
73 if (ucis_state.count >= UCIS_MAX_SYMBOL_LENGTH && !special) { 34 return false;
74 return false; 35 case KC_SPACE:
75 } 36 case KC_ENTER:
76 37 ucis_finish();
77 ucis_state.codes[ucis_state.count] = keycode; 38 return false;
78 ucis_state.count++;
79
80 switch (keycode) {
81 case KC_BACKSPACE:
82 if (ucis_state.count >= 2) {
83 ucis_state.count -= 2;
84 return true;
85 } else {
86 ucis_state.count--;
87 return false;
88 }
89
90 case KC_SPACE:
91 case KC_ENTER:
92 case KC_ESCAPE:
93 for (uint8_t i = 0; i < ucis_state.count; i++) {
94 tap_code(KC_BACKSPACE);
95 }
96
97 if (keycode == KC_ESCAPE) {
98 ucis_state.in_progress = false;
99 ucis_cancel();
100 return false;
101 }
102
103 uint8_t i;
104 bool symbol_found = false;
105 for (i = 0; ucis_symbol_table[i].symbol; i++) {
106 if (is_uni_seq(ucis_symbol_table[i].symbol)) {
107 symbol_found = true;
108 register_ucis(ucis_symbol_table[i].code_points);
109 break;
110 }
111 } 39 }
112 if (symbol_found) { 40 }
113 ucis_success(i);
114 } else {
115 ucis_symbol_fallback();
116 }
117
118 ucis_state.in_progress = false;
119 return false;
120
121 default:
122 return true;
123 } 41 }
42
43 return true;
124} 44}