Skip to content

Commit 919c90e

Browse files
vomindoraandrashna
authored andcommitted
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
1 parent 7b729ed commit 919c90e

File tree

4 files changed

+97
-114
lines changed

4 files changed

+97
-114
lines changed

docs/feature_unicode.md

+33-34
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Unicode Support
22

3-
There are three Unicode keymap definition method available in QMK:
3+
There are three Unicode keymap definition methods available in QMK:
44

55
## UNICODE_ENABLE
66

@@ -14,15 +14,15 @@ And you may want to have an enum to make reference easier. So you'd want to add
1414

1515
```c
1616
enum unicode_names {
17-
BANG, // ‽
18-
IRONY, // ⸮
19-
SNEK // snke 🐍
17+
BANG,
18+
IRONY,
19+
SNEK,
2020
};
2121

2222
const uint32_t PROGMEM unicode_map[] = {
23-
[BANG] = 0x0203D, // ‽
24-
[IRONY] = 0x02E2E, // ⸮
25-
[SNEK] = 0x1F40D // snke 🐍
23+
[BANG] = 0x203D, // ‽
24+
[IRONY] = 0x2E2E, // ⸮
25+
[SNEK] = 0x1F40D, // 🐍
2626
}:
2727
```
2828

@@ -77,18 +77,9 @@ void qk_ucis_symbol_fallback (void) { // falls back to manual unicode entry
7777
7878
## Input Modes
7979
80-
Unicode input in QMK works by inputting a sequence of characters to the OS, sort of like a macro. Unfortunately, each OS has different ideas on how Unicode is input. Specifically, each OS has one (or more) key sequences that it requires to input unicode characters.
80+
Unicode input in QMK works by inputting a sequence of characters to the OS, sort of like a macro. Unfortunately, the way this is done differs for each platform. Specifically, each platform requires a different combination of keys to trigger Unicode input. Therefore, a corresponding input mode has to be set in QMK.
8181
82-
There are two ways to set the input mode for Unicode, by keycode or by function.
83-
84-
Keep in mind that both methods write to persistant storage (EEPROM), and are loaded each time the keyboard starts. So once you've set it once, you do not need to set it again unless you need to change it or you've reset the EEPROM settings.
85-
86-
!> There are options for BSD here, but it is not implemented at this time. If you use BSD and want to help in adding support for this, please [open an issue on GitHub](https://github.com/qmk/qmk_firmware/issues)
87-
88-
89-
### Functions
90-
91-
You can also switch the input mode by calling `set_unicode_input_mode(x)` in your code, and this works the same way as the keycodes below.
82+
The following input modes are available:
9283
9384
* __UC_OSX__: MacOS Unicode Hex Input support. Works only up to 0xFFFF. Disabled by default. To enable: go to System Preferences -> Keyboard -> Input Sources, and enable Unicode Hex.
9485
* __UC_OSX_RALT__: Same as UC_OSX, but sends the Right Alt key for unicode input
@@ -97,21 +88,30 @@ You can also switch the input mode by calling `set_unicode_input_mode(x)` in you
9788
* __UC_WIN__: (not recommended) Windows built-in Unicode input. To enable: create registry key under `HKEY_CURRENT_USER\Control Panel\Input Method\EnableHexNumpad` of type `REG_SZ` called `EnableHexNumpad`, set its value to 1, and reboot. This method is not recommended because of reliability and compatibility issue, use WinCompose method below instead.
9889
* __UC_WINC__: Windows Unicode input using WinCompose. Requires [WinCompose](https://github.com/samhocevar/wincompose). Works reliably under many (all?) variations of Windows.
9990
100-
### Keycodes
91+
!> There is an input mode option for BSD, but it's not implemented at this time. If you use BSD and want to help with adding support for it, please [open an issue on GitHub](https://github.com/qmk/qmk_firmware/issues).
92+
93+
### Switching Input Modes
10194
102-
|Key |Aliases |Input Method |Description |
103-
|--------------------------|---------|--------------|---------------------------------------------------|
104-
|`UNICODE_MODE_OSX` |`UC_M_OS`|`UC_OSX` |Sets the input method for MacOS X |
105-
|`UNICODE_MODE_LNX` |`UC_M_LN`|`UC_LNX` |Sets the input method for Linux |
106-
|`UNICODE_MODE_BSD` |`UC_M_BS`|`UC_BSD` |Sets the input method for BSD (Non-Operational) |
107-
|`UNICODE_MODE_WIN` |`UC_M_WI`|`UC_WIN` |Sets the input method for Windows |
108-
|`UNICODE_MODE_WINC` |`UC_M_WC`|`UC_WINC` |Sets the input method for Windows using WinCompose |
109-
|`UNICODE_MODE_OSX_RALT` |`UC_M_OR`|`UC_OSX_RALT` |Sets the input method for MacOS X using RAlt/AltGr |
110-
### Audio Feedback for Input Mode keycodes
95+
There are two ways to set the input mode for Unicode: by keycode or by function. Keep in mind that both methods write to persistent storage (EEPROM), and are loaded each time the keyboard starts. So once you've set it once, you don't need to set it again unless you want to change it, or you've reset the EEPROM settings.
96+
97+
You can switch the input mode at any time by using one of the following keycodes. The easiest way is to add the ones you use to your keymap.
98+
99+
|Keycode |Alias |Input mode |Description |
100+
|-----------------------|---------|-------------|-----------------------------------------|
101+
|`UNICODE_MODE_OSX` |`UC_M_OS`|`UC_OSX` |Switch to Mac OS X input. |
102+
|`UNICODE_MODE_LNX` |`UC_M_LN`|`UC_LNX` |Switch to Linux input. |
103+
|`UNICODE_MODE_WIN` |`UC_M_WI`|`UC_WIN` |Switch to Windows input. |
104+
|`UNICODE_MODE_BSD` |`UC_M_BS`|`UC_BSD` |Switch to BSD input (not implemented). |
105+
|`UNICODE_MODE_WINC` |`UC_M_WC`|`UC_WINC` |Switch to Windows input using WinCompose.|
106+
|`UNICODE_MODE_OSX_RALT`|`UC_M_OR`|`UC_OSX_RALT`|Switch to Mac OS X input using Right Alt.|
107+
108+
You can also switch the input mode by calling `set_unicode_input_mode(x)` in your code, and this works the same way as the above keycodes.
109+
110+
### Audio Feedback
111111
112112
If you have the [Audio feature](feature_audio.md) enabled on the board, you can set melodies to be played when you press the above keys. That way you can have some audio feedback when switching input modes.
113113
114-
For instance, you can add these to your `config.h` file.
114+
For instance, you can add these definitions to your `config.h` file:
115115
116116
```c
117117
#define UNICODE_SONG_OSX COIN_SOUND
@@ -122,16 +122,15 @@ For instance, you can add these to your `config.h` file.
122122
#define UNICODE_SONG_OSX_RALT COIN_SOUND
123123
```
124124

125-
### Unicode Input Method Customization
125+
### Additional Customization
126126

127-
The "start" and "finish" functions for unicode method can be customized locally. A great use for this is to customize the input methods if you don't use the default keys. Or to add visual, or audio feedback when inputting unicode characters.
127+
The functions for starting and finishing Unicode input on your platform can be overridden locally. Possible uses include customizing input mode behavior if you don't use the default keys, or adding extra visual/audio feedback to Unicode input.
128128

129-
* `void unicode_input_start(void)` - This sends the initial sequence that tells your platform to enter Unicode input mode. For example, it presses Ctrl+Shift+U on Linux and holds the Option key on Mac.
130-
* `void unicode_input_finish (void)` - his is called to exit Unicode input mode, for example by pressing Space or releasing the Option key.
129+
* `void unicode_input_start(void)` This sends the initial sequence that tells your platform to enter Unicode input mode. For example, it presses Ctrl+Shift+U on Linux and holds the Option key on Mac.
130+
* `void unicode_input_finish(void)` – This is called to exit Unicode input mode, for example by pressing Space or releasing the Option key.
131131

132132
You can find the default implementations of these functions in [`process_unicode_common.c`](https://github.com/qmk/qmk_firmware/blob/master/quantum/process_keycode/process_unicode_common.c).
133133

134-
135134
## `send_unicode_hex_string`
136135

137136
To type multiple characters for things like (ノಠ痊ಠ)ノ彡┻━┻, you can use `send_unicode_hex_string()` much like `SEND_STRING()` except you would use hex values separate by spaces.

quantum/process_keycode/process_unicode_common.c

+59-75
Original file line numberDiff line numberDiff line change
@@ -21,27 +21,6 @@
2121

2222
unicode_config_t unicode_config;
2323
static uint8_t saved_mods;
24-
#ifdef AUDIO_ENABLE
25-
#ifdef UNICODE_SONG_OSX
26-
float osx_song[][2] = UNICODE_SONG_OSX;
27-
#endif
28-
#ifdef UNICODE_SONG_LNX
29-
float song_lnx[][2] = UNICODE_SONG_LNX;
30-
#endif
31-
#ifdef UNICODE_SONG_WIN
32-
float windows_song[][2] = UNICODE_SONG_WIN;
33-
#endif
34-
#ifdef UNICODE_SONG_BSD
35-
float song_bsd[][2] = UNICODE_SONG_BSD;
36-
#endif
37-
#ifdef UNICODE_SONG_WINC
38-
float win_compose_song[][2] = UNICODE_SONG_WINC;
39-
#endif
40-
#ifdef UNICODE_SONG_OSX_RALT
41-
float osx_ralt_song[][2] = UNICODE_SONG_OSX_RALT;
42-
#endif
43-
#endif
44-
4524

4625
void set_unicode_input_mode(uint8_t os_target) {
4726
unicode_config.input_mode = os_target;
@@ -92,16 +71,16 @@ void unicode_input_start(void) {
9271
__attribute__((weak))
9372
void unicode_input_finish(void) {
9473
switch (unicode_config.input_mode) {
95-
case UC_OSX:
96-
case UC_WIN:
97-
unregister_code(KC_LALT);
98-
break;
99-
case UC_OSX_RALT:
100-
unregister_code(KC_RALT);
101-
break;
102-
case UC_LNX:
103-
tap_code(KC_SPC);
104-
break;
74+
case UC_OSX:
75+
case UC_WIN:
76+
unregister_code(KC_LALT);
77+
break;
78+
case UC_OSX_RALT:
79+
unregister_code(KC_RALT);
80+
break;
81+
case UC_LNX:
82+
tap_code(KC_SPC);
83+
break;
10584
}
10685

10786
set_mods(saved_mods); // Reregister previously set mods
@@ -153,52 +132,57 @@ void send_unicode_hex_string(const char *str) {
153132
bool process_unicode_common(uint16_t keycode, keyrecord_t *record) {
154133
if (record->event.pressed) {
155134
switch (keycode) {
156-
case UNICODE_MODE_OSX:
135+
case UNICODE_MODE_OSX:
157136
set_unicode_input_mode(UC_OSX);
158-
#if defined(AUDIO_ENABLE) && defined(UNICODE_SONG_OSX)
159-
PLAY_SONG(osx_song);
160-
#endif
161-
break;
162-
case UNICODE_MODE_LNX:
163-
set_unicode_input_mode(UC_LNX);
164-
#if defined(AUDIO_ENABLE) && defined(UNICODE_SONG_LNX)
165-
PLAY_SONG(song_lnx);
166-
#endif
167-
break;
168-
case UNICODE_MODE_WIN:
169-
set_unicode_input_mode(UC_WIN);
170-
#if defined(AUDIO_ENABLE) && defined(UNICODE_SONG_WIN)
171-
PLAY_SONG(windows_song);
172-
#endif
173-
break;
174-
case UNICODE_MODE_BSD:
175-
set_unicode_input_mode(UC_BSD);
176-
#if defined(AUDIO_ENABLE) && defined(UNICODE_SONG_BSD)
177-
PLAY_SONG(song_bsd);
178-
#endif
179-
break;
180-
case UNICODE_MODE_WINC:
181-
set_unicode_input_mode(UC_WINC);
182-
#if defined(AUDIO_ENABLE) && defined(UNICODE_SONG_WINC)
183-
PLAY_SONG(win_compose_song);
184-
#endif
185-
break;
186-
case UNICODE_MODE_OSX_RALT:
187-
set_unicode_input_mode(UC_OSX_RALT);
188-
#if defined(AUDIO_ENABLE) && defined(UNICODE_SONG_OSX_RALT)
189-
PLAY_SONG(osx_ralt_song);
190-
#endif
191-
break;
137+
#if defined(AUDIO_ENABLE) && defined(UNICODE_SONG_OSX)
138+
static float song_osx[][2] = UNICODE_SONG_OSX;
139+
PLAY_SONG(song_osx);
140+
#endif
141+
break;
142+
case UNICODE_MODE_LNX:
143+
set_unicode_input_mode(UC_LNX);
144+
#if defined(AUDIO_ENABLE) && defined(UNICODE_SONG_LNX)
145+
static float song_lnx[][2] = UNICODE_SONG_LNX;
146+
PLAY_SONG(song_lnx);
147+
#endif
148+
break;
149+
case UNICODE_MODE_WIN:
150+
set_unicode_input_mode(UC_WIN);
151+
#if defined(AUDIO_ENABLE) && defined(UNICODE_SONG_WIN)
152+
static float song_win[][2] = UNICODE_SONG_WIN;
153+
PLAY_SONG(song_win);
154+
#endif
155+
break;
156+
case UNICODE_MODE_BSD:
157+
set_unicode_input_mode(UC_BSD);
158+
#if defined(AUDIO_ENABLE) && defined(UNICODE_SONG_BSD)
159+
static float song_bsd[][2] = UNICODE_SONG_BSD;
160+
PLAY_SONG(song_bsd);
161+
#endif
162+
break;
163+
case UNICODE_MODE_WINC:
164+
set_unicode_input_mode(UC_WINC);
165+
#if defined(AUDIO_ENABLE) && defined(UNICODE_SONG_WINC)
166+
static float song_winc[][2] = UNICODE_SONG_WINC;
167+
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);
175+
#endif
176+
break;
192177
}
193178
}
194-
#ifdef UNICODE_ENABLE
195-
return process_unicode(keycode, record);
196-
#endif
197-
#ifdef UCIS_ENABLE
198-
return process_ucis(keycode, record);
199-
#endif
200-
#ifdef UNICODEMAP_ENABLE
201-
return process_unicode_map(keycode, record);
202-
#endif
179+
#if defined(UNICODE_ENABLE)
180+
return process_unicode(keycode, record);
181+
#elif defined(UNICODEMAP_ENABLE)
182+
return process_unicode_map(keycode, record);
183+
#elif defined(UCIS_ENABLE)
184+
return process_ucis(keycode, record);
185+
#else
203186
return true;
187+
#endif
204188
}

quantum/process_keycode/process_unicode_common.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@
1919
#include "quantum.h"
2020

2121
#if defined(UNICODE_ENABLE) + defined(UNICODEMAP_ENABLE) + defined(UCIS_ENABLE) > 1
22-
#error "Cannot enable more than one unicode method (UNICODE, UNICODEMAP, UCIS) at the same time"
22+
#error "Cannot enable more than one Unicode method (UNICODE, UNICODEMAP, UCIS) at the same time"
2323
#endif
2424

2525
#ifndef UNICODE_TYPE_DELAY
26-
#define UNICODE_TYPE_DELAY 10
26+
#define UNICODE_TYPE_DELAY 10
2727
#endif
2828

2929
typedef union {

quantum/quantum.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ bool process_record_quantum(keyrecord_t *record) {
235235
process_key_lock(&keycode, record) &&
236236
#endif
237237
#if defined(AUDIO_ENABLE) && defined(AUDIO_CLICKY)
238-
process_clicky(keycode, record) &&
238+
process_clicky(keycode, record) &&
239239
#endif //AUDIO_CLICKY
240240
process_record_kb(keycode, record) &&
241241
#if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_KEYPRESSES)
@@ -250,13 +250,13 @@ bool process_record_quantum(keyrecord_t *record) {
250250
#ifdef STENO_ENABLE
251251
process_steno(keycode, record) &&
252252
#endif
253-
#if ( defined(AUDIO_ENABLE) || (defined(MIDI_ENABLE) && defined(MIDI_BASIC))) && !defined(NO_MUSIC_MODE)
253+
#if (defined(AUDIO_ENABLE) || (defined(MIDI_ENABLE) && defined(MIDI_BASIC))) && !defined(NO_MUSIC_MODE)
254254
process_music(keycode, record) &&
255255
#endif
256256
#ifdef TAP_DANCE_ENABLE
257257
process_tap_dance(keycode, record) &&
258258
#endif
259-
#if (defined(UNICODE_ENABLE) || defined(UNICODEMAP_ENABLE) || defined(UCIS_ENABLE))
259+
#if defined(UNICODE_ENABLE) || defined(UNICODEMAP_ENABLE) || defined(UCIS_ENABLE)
260260
process_unicode_common(keycode, record) &&
261261
#endif
262262
#ifdef LEADER_ENABLE

0 commit comments

Comments
 (0)