Skip to content

Commit da4dee2

Browse files
authored
Unicode common cleanup (#17)
* Standardize the Unicode EEPROM code * Remove unicode init from process_record_* functions * Add unicode init to where it belongs: matrix_init_quantum * Move Unicode proccessing to unicode common * Add audio feedback to input mode keys to drive konstantin up a wall * Tap_code cleanup * Update keycodes * Update unicode documentation * Update unicode keycodes for consistency/easier merge * Add Audio Feedback section * Remove Functions from feature page And link to the file instead. Link to specific lines later on. * Fix white spaces Co-Authored-By: drashna <drashna@live.com> * Fix spacing Co-Authored-By: drashna <drashna@live.com> * Because I missed it! Co-Authored-By: drashna <drashna@live.com> * Fix spacing Co-Authored-By: drashna <drashna@live.com> * SPAAAAAAAAAACing Co-Authored-By: drashna <drashna@live.com> * white spaces Co-Authored-By: drashna <drashna@live.com> * Add BSD for future compatibility * Thought I fixed that! Co-Authored-By: drashna <drashna@live.com> * non-breaking Co-Authored-By: drashna <drashna@live.com> * Considered that Co-Authored-By: drashna <drashna@live.com> * Yuuup Co-Authored-By: drashna <drashna@live.com> * consistency Co-Authored-By: drashna <drashna@live.com> * white spaces .... copied from elsewhere Co-Authored-By: drashna <drashna@live.com> * white spaces Co-Authored-By: drashna <drashna@live.com> * white spaces Co-Authored-By: drashna <drashna@live.com> * Update keycode defines * Fix Linux Song * Update all of the songs * Cleanup * Move and update check to ensure only one unicode method is enabled * Update quantum/quantum_keycodes.h * Update documentation * Wordsmithing and cleanup * Format unicode_common (#13) * case alignment * process_record_unicode_common → process_unicode_common * Move song arrays into function where they're used, align preprocessor directives * Swap the order of UC_WIN and UC_BSD * Update Unicode docs * Reorder Unicode mode stuff to match the order of input mode constants * Fix capitalization in doc subtitle * Readd BSD and OSX_RALT songs * Reword BSD note in docs * Readd BSD keycode description * Reword explanation of input on different platforms * Steal vomindoraan's input mode documentation Co-Authored-By: vomindoraan (vomindoraan@gmail.com) * Willingly give Drashna the rest of my Unicode doc improvements * Wordsmithing Co-Authored-By: drashna <drashna@live.com> * Rearrange process_unicode_common functions * Make Unicode input mode constants (UC_*) an enum * Simplify unicode_input_start/finish code * Make the key used for WinCompose configurable * Remove UC_OSX_RALT in favor of setting the key with UNICODE_OSX_KEY * Update Unicode input mode doc * Add descriptions and rearrange definitions in process_unicode_common.h * Add registry command to Unicode docs + misc updates * Reword an explanation in Unicode docs * Add TODO comment * Remove trailing whitespace
1 parent de4dc0f commit da4dee2

File tree

4 files changed

+43
-41
lines changed

4 files changed

+43
-41
lines changed

docs/feature_unicode.md

+2-4
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,7 @@ The following input modes are available:
6464
* **`UC_OSX`**: Mac OS X built-in Unicode hex input. Supports code points up to `0xFFFF` (`0x10FFFF` with `UNICODEMAP`).
6565

6666
To enable, go to _System Preferences > Keyboard > Input Sources_, add _Unicode Hex Input_ to the list (it's under _Other_), then activate it from the input dropdown in the Menu Bar.
67-
68-
* **`UC_OSX_RALT`**: Same as `UC_OSX`, but sends the Right Alt/Option key for Unicode input.
67+
By default, this mode uses the left Option key (`KC_LALT`), but this can be changed by defining `UNICODE_OSX_KEY` with another keycode.
6968

7069
* **`UC_LNX`**: Linux built-in IBus Unicode input. Supports all possible code points (`0x10FFFF`).
7170

@@ -81,7 +80,7 @@ The following input modes are available:
8180
* **`UC_WINC`**: Windows Unicode input using [WinCompose](https://github.com/samhocevar/wincompose). As of v0.8.2, supports code points up to `0xFFFFF`.
8281

8382
To enable, install the [latest release](https://github.com/samhocevar/wincompose/releases/latest). Once installed, WinCompose will automatically run on startup. Works reliably under all version of Windows supported by the app.
84-
This mode relies on the Compose key being set to Right Alt (`KC_RALT`). If you change it to something else in the WinCompose settings, this mode will not work.
83+
By default, this mode uses the right Alt key (`KC_RALT`), but this can be changed in the WinCompose settings and by defining `UNICODE_WINC_KEY` with another keycode.
8584

8685
### Switching Input Modes
8786

@@ -118,7 +117,6 @@ For instance, you can add these definitions to your `config.h` file:
118117
#define UNICODE_SONG_BSD MARIO_GAMEOVER
119118
#define UNICODE_SONG_WIN UNICODE_WINDOWS
120119
#define UNICODE_SONG_WINC UNICODE_WINDOWS
121-
#define UNICODE_SONG_OSX_RALT COIN_SOUND
122120
```
123121

124122
### Additional Customization

quantum/process_keycode/process_unicode_common.c

+15-24
Original file line numberDiff line numberDiff line change
@@ -16,41 +16,39 @@
1616

1717
#include "process_unicode_common.h"
1818
#include "eeprom.h"
19-
#include <string.h>
2019
#include <ctype.h>
20+
#include <string.h>
2121

2222
unicode_config_t unicode_config;
23-
static uint8_t saved_mods;
2423

25-
void set_unicode_input_mode(uint8_t os_target) {
26-
unicode_config.input_mode = os_target;
27-
eeprom_update_byte(EECONFIG_UNICODEMODE, os_target);
24+
void unicode_input_mode_init(void) {
25+
unicode_config.raw = eeprom_read_byte(EECONFIG_UNICODEMODE);
2826
}
2927

3028
uint8_t get_unicode_input_mode(void) {
3129
return unicode_config.input_mode;
3230
}
3331

34-
void unicode_input_mode_init(void) {
35-
unicode_config.raw = eeprom_read_byte(EECONFIG_UNICODEMODE);
32+
void set_unicode_input_mode(uint8_t mode) {
33+
unicode_config.input_mode = mode;
34+
eeprom_update_byte(EECONFIG_UNICODEMODE, mode);
3635
}
3736

37+
static uint8_t saved_mods;
38+
3839
__attribute__((weak))
3940
void unicode_input_start(void) {
4041
saved_mods = get_mods(); // Save current mods
4142
clear_mods(); // Unregister mods to start from a clean state
4243

4344
switch (unicode_config.input_mode) {
4445
case UC_OSX:
45-
register_code(KC_LALT);
46-
break;
47-
case UC_OSX_RALT:
48-
register_code(KC_RALT);
46+
register_code(UNICODE_OSX_KEY);
4947
break;
5048
case UC_LNX:
5149
register_code(KC_LCTL);
5250
register_code(KC_LSFT);
53-
tap_code(KC_U);
51+
tap_code(KC_U); // TODO: Replace with tap_code16(LCTL(LSFT(KC_U))); and test
5452
unregister_code(KC_LSFT);
5553
unregister_code(KC_LCTL);
5654
break;
@@ -61,23 +59,23 @@ void unicode_input_start(void) {
6159
tap_code(KC_PPLS);
6260
break;
6361
case UC_WINC:
64-
tap_code(KC_RALT);
62+
tap_code(UNICODE_WINC_KEY);
6563
tap_code(KC_U);
6664
break;
6765
}
66+
6867
wait_ms(UNICODE_TYPE_DELAY);
6968
}
7069

7170
__attribute__((weak))
7271
void unicode_input_finish(void) {
7372
switch (unicode_config.input_mode) {
7473
case UC_OSX:
74+
unregister_code(UNICODE_OSX_KEY);
75+
break;
7576
case UC_WIN:
7677
unregister_code(KC_LALT);
7778
break;
78-
case UC_OSX_RALT:
79-
unregister_code(KC_RALT);
80-
break;
8179
case UC_LNX:
8280
tap_code(KC_SPC);
8381
break;
@@ -105,7 +103,7 @@ void register_hex(uint16_t hex) {
105103
}
106104

107105
void send_unicode_hex_string(const char *str) {
108-
if (!str) { return; } // Safety net
106+
if (!str) { return; }
109107

110108
while (*str) {
111109
// Find the next code point (token) in the string
@@ -165,13 +163,6 @@ bool process_unicode_common(uint16_t keycode, keyrecord_t *record) {
165163
#if defined(AUDIO_ENABLE) && defined(UNICODE_SONG_WINC)
166164
static float song_winc[][2] = UNICODE_SONG_WINC;
167165
PLAY_SONG(song_winc);
168-
#endif
169-
break;
170-
case UNICODE_MODE_OSX_RALT:
171-
set_unicode_input_mode(UC_OSX_RALT);
172-
#if defined(AUDIO_ENABLE) && defined(UNICODE_SONG_OSX_RALT)
173-
static float song_osx_ralt[][2] = UNICODE_SONG_OSX_RALT;
174-
PLAY_SONG(song_osx_ralt);
175166
#endif
176167
break;
177168
}

quantum/process_keycode/process_unicode_common.h

+24-11
Original file line numberDiff line numberDiff line change
@@ -22,37 +22,50 @@
2222
#error "Cannot enable more than one Unicode method (UNICODE, UNICODEMAP, UCIS) at the same time"
2323
#endif
2424

25+
// Keycodes used for starting Unicode input on different platforms
26+
#ifndef UNICODE_OSX_KEY
27+
#define UNICODE_OSX_KEY KC_LALT
28+
#endif
29+
#ifndef UNICODE_WINC_KEY
30+
#define UNICODE_WINC_KEY KC_RALT
31+
#endif
32+
33+
// Delay between starting Unicode input and sending a sequence, in ms
2534
#ifndef UNICODE_TYPE_DELAY
2635
#define UNICODE_TYPE_DELAY 10
2736
#endif
2837

38+
enum unicode_input_modes {
39+
UC_OSX, // Mac OS X using Unicode Hex Input
40+
UC_LNX, // Linux using IBus
41+
UC_WIN, // Windows using EnableHexNumpad
42+
UC_BSD, // BSD (not implemented)
43+
UC_WINC, // Windows using WinCompose (https://github.com/samhocevar/wincompose)
44+
UC__COUNT // Number of available input modes (always leave at the end)
45+
};
46+
2947
typedef union {
3048
uint32_t raw;
3149
struct {
32-
uint8_t input_mode :8;
50+
uint8_t input_mode : 8;
3351
};
3452
} unicode_config_t;
3553

3654
extern unicode_config_t unicode_config;
3755

38-
void set_unicode_input_mode(uint8_t os_target);
39-
uint8_t get_unicode_input_mode(void);
4056
void unicode_input_mode_init(void);
57+
uint8_t get_unicode_input_mode(void);
58+
void set_unicode_input_mode(uint8_t mode);
59+
4160
void unicode_input_start(void);
4261
void unicode_input_finish(void);
62+
4363
void register_hex(uint16_t hex);
4464
void send_unicode_hex_string(const char *str);
45-
bool process_unicode_common(uint16_t keycode, keyrecord_t *record);
4665

47-
#define UC_OSX 0 // Mac OS X
48-
#define UC_LNX 1 // Linux
49-
#define UC_WIN 2 // Windows 'HexNumpad'
50-
#define UC_BSD 3 // BSD (not implemented)
51-
#define UC_WINC 4 // WinCompose https://github.com/samhocevar/wincompose
52-
#define UC_OSX_RALT 5 // Mac OS X using Right Alt key for Unicode Compose
66+
bool process_unicode_common(uint16_t keycode, keyrecord_t *record);
5367

5468
#define UC_BSPC UC(0x0008)
55-
5669
#define UC_SPC UC(0x0020)
5770

5871
#define UC_EXLM UC(0x0021)

quantum/process_keycode/process_unicodemap.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ bool process_unicode_map(uint16_t keycode, keyrecord_t *record) {
5050
const uint32_t* map = unicode_map;
5151
uint16_t index = keycode - QK_UNICODE_MAP;
5252
uint32_t code = pgm_read_dword(&map[index]);
53-
if (code > 0xFFFF && code <= 0x10ffff && (input_mode == UC_OSX || input_mode == UC_OSX_RALT)) {
53+
if (code > 0xFFFF && code <= 0x10ffff && input_mode == UC_OSX) {
5454
// Convert to UTF-16 surrogate pair
5555
code -= 0x10000;
5656
uint32_t lo = code & 0x3ff;
@@ -59,7 +59,7 @@ bool process_unicode_map(uint16_t keycode, keyrecord_t *record) {
5959
register_hex32(hi + 0xd800);
6060
register_hex32(lo + 0xdc00);
6161
unicode_input_finish();
62-
} else if ((code > 0x10ffff && (input_mode == UC_OSX || input_mode == UC_OSX_RALT)) || (code > 0xFFFFF && input_mode == UC_LNX)) {
62+
} else if ((code > 0x10ffff && input_mode == UC_OSX) || (code > 0xFFFFF && input_mode == UC_LNX)) {
6363
// when character is out of range supported by the OS
6464
unicode_map_input_error();
6565
} else {

0 commit comments

Comments
 (0)