summaryrefslogtreecommitdiff
path: root/quantum/unicode
diff options
context:
space:
mode:
authorRyan <fauxpark@gmail.com>2022-11-01 08:15:12 +1100
committerGitHub <noreply@github.com>2022-10-31 21:15:12 +0000
commit5974d989fe72f6c576901a065bee4487a58c351d (patch)
treea88a796ec2c0a11d4d554325fa92e53d9fbb82c2 /quantum/unicode
parent743524df32ef265fdc3999518cdaba45cd4abf22 (diff)
Normalise Unicode keycodes (#18898)
* `UC_MOD`/`UC_RMOD` -> `UC_NEXT`/`UC_PREV` * `UNICODE_MODE_*` -> `QK_UNICODE_MODE_*` * `UC_MAC` -> `UNICODE_MODE_MACOS` * `UC_LNX` -> `UNICODE_MODE_LINUX` * `UC_WIN` -> `UNICODE_MODE_WINDOWS` * `UC_BSD` -> `UNICODE_MODE_BSD` * `UC_WINC` -> `UNICODE_MODE_WINCOMPOSE` * `UC_EMACS` -> `UNICODE_MODE_EMACS` * `UC__COUNT` -> `UNICODE_MODE_COUNT` * `UC_M_MA` -> `UC_MAC` * `UC_M_LN` -> `UC_LINX` * `UC_M_WI` -> `UC_WIN` * `UC_M_BS` -> `UC_BSD` * `UC_M_WC` -> `UC_WINC` * `UC_M_EM` -> `UC_EMAC` * Docs * Update quantum/unicode/unicode.h
Diffstat (limited to 'quantum/unicode')
-rw-r--r--quantum/unicode/unicode.c54
-rw-r--r--quantum/unicode/unicode.h15
2 files changed, 35 insertions, 34 deletions
diff --git a/quantum/unicode/unicode.c b/quantum/unicode/unicode.c
index e2bfd68a3a..35cb62e700 100644
--- a/quantum/unicode/unicode.c
+++ b/quantum/unicode/unicode.c
@@ -46,7 +46,7 @@
46#endif 46#endif
47 47
48// Comma-delimited, ordered list of input modes selected for use (e.g. in cycle) 48// Comma-delimited, ordered list of input modes selected for use (e.g. in cycle)
49// Example: #define UNICODE_SELECTED_MODES UC_WINC, UC_LNX 49// Example: #define UNICODE_SELECTED_MODES UNICODE_MODE_WINCOMPOSE, UNICODE_MODE_LINUX
50#ifndef UNICODE_SELECTED_MODES 50#ifndef UNICODE_SELECTED_MODES
51# define UNICODE_SELECTED_MODES -1 51# define UNICODE_SELECTED_MODES -1
52#endif 52#endif
@@ -108,32 +108,32 @@ static float song_emacs[][2] = UNICODE_SONG_EMACS;
108static void unicode_play_song(uint8_t mode) { 108static void unicode_play_song(uint8_t mode) {
109 switch (mode) { 109 switch (mode) {
110# ifdef UNICODE_SONG_MAC 110# ifdef UNICODE_SONG_MAC
111 case UC_MAC: 111 case UNICODE_MODE_MACOS:
112 PLAY_SONG(song_mac); 112 PLAY_SONG(song_mac);
113 break; 113 break;
114# endif 114# endif
115# ifdef UNICODE_SONG_LNX 115# ifdef UNICODE_SONG_LNX
116 case UC_LNX: 116 case UNICODE_MODE_LINUX:
117 PLAY_SONG(song_lnx); 117 PLAY_SONG(song_lnx);
118 break; 118 break;
119# endif 119# endif
120# ifdef UNICODE_SONG_WIN 120# ifdef UNICODE_SONG_WIN
121 case UC_WIN: 121 case UNICODE_MODE_WINDOWS:
122 PLAY_SONG(song_win); 122 PLAY_SONG(song_win);
123 break; 123 break;
124# endif 124# endif
125# ifdef UNICODE_SONG_BSD 125# ifdef UNICODE_SONG_BSD
126 case UC_BSD: 126 case UNICODE_MODE_BSD:
127 PLAY_SONG(song_bsd); 127 PLAY_SONG(song_bsd);
128 break; 128 break;
129# endif 129# endif
130# ifdef UNICODE_SONG_WINC 130# ifdef UNICODE_SONG_WINC
131 case UC_WINC: 131 case UNICODE_MODE_WINCOMPOSE:
132 PLAY_SONG(song_winc); 132 PLAY_SONG(song_winc);
133 break; 133 break;
134# endif 134# endif
135# ifdef UNICODE_SONG_EMACS 135# ifdef UNICODE_SONG_EMACS
136 case UC_EMACS: 136 case UNICODE_MODE_EMACS:
137 PLAY_SONG(song_emacs); 137 PLAY_SONG(song_emacs);
138 break; 138 break;
139# endif 139# endif
@@ -209,7 +209,7 @@ __attribute__((weak)) void unicode_input_start(void) {
209 // Need to do this before we mess around with the mods, or else 209 // Need to do this before we mess around with the mods, or else
210 // UNICODE_KEY_LNX (which is usually Ctrl-Shift-U) might not work 210 // UNICODE_KEY_LNX (which is usually Ctrl-Shift-U) might not work
211 // correctly in the shifted case. 211 // correctly in the shifted case.
212 if (unicode_config.input_mode == UC_LNX && unicode_saved_led_state.caps_lock) { 212 if (unicode_config.input_mode == UNICODE_MODE_LINUX && unicode_saved_led_state.caps_lock) {
213 tap_code(KC_CAPS_LOCK); 213 tap_code(KC_CAPS_LOCK);
214 } 214 }
215 215
@@ -218,13 +218,13 @@ __attribute__((weak)) void unicode_input_start(void) {
218 clear_weak_mods(); 218 clear_weak_mods();
219 219
220 switch (unicode_config.input_mode) { 220 switch (unicode_config.input_mode) {
221 case UC_MAC: 221 case UNICODE_MODE_MACOS:
222 register_code(UNICODE_KEY_MAC); 222 register_code(UNICODE_KEY_MAC);
223 break; 223 break;
224 case UC_LNX: 224 case UNICODE_MODE_LINUX:
225 tap_code16(UNICODE_KEY_LNX); 225 tap_code16(UNICODE_KEY_LNX);
226 break; 226 break;
227 case UC_WIN: 227 case UNICODE_MODE_WINDOWS:
228 // For increased reliability, use numpad keys for inputting digits 228 // For increased reliability, use numpad keys for inputting digits
229 if (!unicode_saved_led_state.num_lock) { 229 if (!unicode_saved_led_state.num_lock) {
230 tap_code(KC_NUM_LOCK); 230 tap_code(KC_NUM_LOCK);
@@ -233,11 +233,11 @@ __attribute__((weak)) void unicode_input_start(void) {
233 wait_ms(UNICODE_TYPE_DELAY); 233 wait_ms(UNICODE_TYPE_DELAY);
234 tap_code(KC_KP_PLUS); 234 tap_code(KC_KP_PLUS);
235 break; 235 break;
236 case UC_WINC: 236 case UNICODE_MODE_WINCOMPOSE:
237 tap_code(UNICODE_KEY_WINC); 237 tap_code(UNICODE_KEY_WINC);
238 tap_code(KC_U); 238 tap_code(KC_U);
239 break; 239 break;
240 case UC_EMACS: 240 case UNICODE_MODE_EMACS:
241 // The usual way to type unicode in emacs is C-x-8 <RET> then the unicode number in hex 241 // The usual way to type unicode in emacs is C-x-8 <RET> then the unicode number in hex
242 tap_code16(LCTL(KC_X)); 242 tap_code16(LCTL(KC_X));
243 tap_code16(KC_8); 243 tap_code16(KC_8);
@@ -250,25 +250,25 @@ __attribute__((weak)) void unicode_input_start(void) {
250 250
251__attribute__((weak)) void unicode_input_finish(void) { 251__attribute__((weak)) void unicode_input_finish(void) {
252 switch (unicode_config.input_mode) { 252 switch (unicode_config.input_mode) {
253 case UC_MAC: 253 case UNICODE_MODE_MACOS:
254 unregister_code(UNICODE_KEY_MAC); 254 unregister_code(UNICODE_KEY_MAC);
255 break; 255 break;
256 case UC_LNX: 256 case UNICODE_MODE_LINUX:
257 tap_code(KC_SPACE); 257 tap_code(KC_SPACE);
258 if (unicode_saved_led_state.caps_lock) { 258 if (unicode_saved_led_state.caps_lock) {
259 tap_code(KC_CAPS_LOCK); 259 tap_code(KC_CAPS_LOCK);
260 } 260 }
261 break; 261 break;
262 case UC_WIN: 262 case UNICODE_MODE_WINDOWS:
263 unregister_code(KC_LEFT_ALT); 263 unregister_code(KC_LEFT_ALT);
264 if (!unicode_saved_led_state.num_lock) { 264 if (!unicode_saved_led_state.num_lock) {
265 tap_code(KC_NUM_LOCK); 265 tap_code(KC_NUM_LOCK);
266 } 266 }
267 break; 267 break;
268 case UC_WINC: 268 case UNICODE_MODE_WINCOMPOSE:
269 tap_code(KC_ENTER); 269 tap_code(KC_ENTER);
270 break; 270 break;
271 case UC_EMACS: 271 case UNICODE_MODE_EMACS:
272 tap_code16(KC_ENTER); 272 tap_code16(KC_ENTER);
273 break; 273 break;
274 } 274 }
@@ -278,25 +278,25 @@ __attribute__((weak)) void unicode_input_finish(void) {
278 278
279__attribute__((weak)) void unicode_input_cancel(void) { 279__attribute__((weak)) void unicode_input_cancel(void) {
280 switch (unicode_config.input_mode) { 280 switch (unicode_config.input_mode) {
281 case UC_MAC: 281 case UNICODE_MODE_MACOS:
282 unregister_code(UNICODE_KEY_MAC); 282 unregister_code(UNICODE_KEY_MAC);
283 break; 283 break;
284 case UC_LNX: 284 case UNICODE_MODE_LINUX:
285 tap_code(KC_ESCAPE); 285 tap_code(KC_ESCAPE);
286 if (unicode_saved_led_state.caps_lock) { 286 if (unicode_saved_led_state.caps_lock) {
287 tap_code(KC_CAPS_LOCK); 287 tap_code(KC_CAPS_LOCK);
288 } 288 }
289 break; 289 break;
290 case UC_WINC: 290 case UNICODE_MODE_WINCOMPOSE:
291 tap_code(KC_ESCAPE); 291 tap_code(KC_ESCAPE);
292 break; 292 break;
293 case UC_WIN: 293 case UNICODE_MODE_WINDOWS:
294 unregister_code(KC_LEFT_ALT); 294 unregister_code(KC_LEFT_ALT);
295 if (!unicode_saved_led_state.num_lock) { 295 if (!unicode_saved_led_state.num_lock) {
296 tap_code(KC_NUM_LOCK); 296 tap_code(KC_NUM_LOCK);
297 } 297 }
298 break; 298 break;
299 case UC_EMACS: 299 case UNICODE_MODE_EMACS:
300 tap_code16(LCTL(KC_G)); // C-g cancels 300 tap_code16(LCTL(KC_G)); // C-g cancels
301 break; 301 break;
302 } 302 }
@@ -307,7 +307,7 @@ __attribute__((weak)) void unicode_input_cancel(void) {
307// clang-format off 307// clang-format off
308 308
309static void send_nibble_wrapper(uint8_t digit) { 309static void send_nibble_wrapper(uint8_t digit) {
310 if (unicode_config.input_mode == UC_WIN) { 310 if (unicode_config.input_mode == UNICODE_MODE_WINDOWS) {
311 uint8_t kc = digit < 10 311 uint8_t kc = digit < 10
312 ? KC_KP_1 + (10 + digit - 1) % 10 312 ? KC_KP_1 + (10 + digit - 1) % 10
313 : KC_A + (digit - 10); 313 : KC_A + (digit - 10);
@@ -328,7 +328,7 @@ void register_hex(uint16_t hex) {
328 328
329void register_hex32(uint32_t hex) { 329void register_hex32(uint32_t hex) {
330 bool first_digit = true; 330 bool first_digit = true;
331 bool needs_leading_zero = (unicode_config.input_mode == UC_WINC); 331 bool needs_leading_zero = (unicode_config.input_mode == UNICODE_MODE_WINCOMPOSE);
332 for (int i = 7; i >= 0; i--) { 332 for (int i = 7; i >= 0; i--) {
333 // Work out the digit we're going to transmit 333 // Work out the digit we're going to transmit
334 uint8_t digit = ((hex >> (i * 4)) & 0xF); 334 uint8_t digit = ((hex >> (i * 4)) & 0xF);
@@ -352,13 +352,13 @@ void register_hex32(uint32_t hex) {
352} 352}
353 353
354void register_unicode(uint32_t code_point) { 354void register_unicode(uint32_t code_point) {
355 if (code_point > 0x10FFFF || (code_point > 0xFFFF && unicode_config.input_mode == UC_WIN)) { 355 if (code_point > 0x10FFFF || (code_point > 0xFFFF && unicode_config.input_mode == UNICODE_MODE_WINDOWS)) {
356 // Code point out of range, do nothing 356 // Code point out of range, do nothing
357 return; 357 return;
358 } 358 }
359 359
360 unicode_input_start(); 360 unicode_input_start();
361 if (code_point > 0xFFFF && unicode_config.input_mode == UC_MAC) { 361 if (code_point > 0xFFFF && unicode_config.input_mode == UNICODE_MODE_MACOS) {
362 // Convert code point to UTF-16 surrogate pair on macOS 362 // Convert code point to UTF-16 surrogate pair on macOS
363 code_point -= 0x10000; 363 code_point -= 0x10000;
364 uint32_t lo = code_point & 0x3FF, hi = (code_point & 0xFFC00) >> 10; 364 uint32_t lo = code_point & 0x3FF, hi = (code_point & 0xFFC00) >> 10;
diff --git a/quantum/unicode/unicode.h b/quantum/unicode/unicode.h
index b3e43799ff..6f1e35d554 100644
--- a/quantum/unicode/unicode.h
+++ b/quantum/unicode/unicode.h
@@ -30,13 +30,14 @@ typedef union {
30extern unicode_config_t unicode_config; 30extern unicode_config_t unicode_config;
31 31
32enum unicode_input_modes { 32enum unicode_input_modes {
33 UC_MAC, // macOS using Unicode Hex Input 33 UNICODE_MODE_MACOS, // macOS using Unicode Hex Input
34 UC_LNX, // Linux using IBus 34 UNICODE_MODE_LINUX, // Linux using IBus
35 UC_WIN, // Windows using EnableHexNumpad 35 UNICODE_MODE_WINDOWS, // Windows using EnableHexNumpad
36 UC_BSD, // BSD (not implemented) 36 UNICODE_MODE_BSD, // BSD (not implemented)
37 UC_WINC, // Windows using WinCompose (https://github.com/samhocevar/wincompose) 37 UNICODE_MODE_WINCOMPOSE, // Windows using WinCompose (https://github.com/samhocevar/wincompose)
38 UC_EMACS, // Emacs is an operating system in search of a good text editor 38 UNICODE_MODE_EMACS, // Emacs is an operating system in search of a good text editor
39 UC__COUNT // Number of available input modes (always leave at the end) 39
40 UNICODE_MODE_COUNT // Number of available input modes (always leave at the end)
40}; 41};
41 42
42void unicode_input_mode_init(void); 43void unicode_input_mode_init(void);