Overhaul Unicode Common functionality (#4325)

* 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 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>

* 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>

* remove merge artifacts

* 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

* Improve Cycling documentation

* Add Unicode Input method Cycling support (#19)

* 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

* Add cycle_unicode_input_mode and UNICODE_SELECTED_MODES macro

* Add an option for making cycle changes persistent

* Add debug prints to functions that change input_mode

* Use cycle_unicode_input_mode in whitefox/konstantin

* Add persist_unicode_input_mode function

* Add offset to cycle to allow stepping in reverse

* Add keycodes: UNICODE_MODE_FORWARD, UNICODE_MODE_REVERSE

Aliases: UC_MOD, UC_RMOD (respectively)

* REVERT ME: Undo changes to whitefox/konstantin to avoid conflicts

* Fix wrong constant name

* Revert "REVERT ME: Undo changes to whitefox/konstantin to avoid conflicts"

This reverts commit 42676bf251fc8e3823f5e614dad6e510ba47a2f3.

* Change dprintf text

* Give selected modes priority over EEPROM when !UNICODE_CYCLE_PERSIST

* Remove trailing whitespace

* Cleanup of RALT code and unicode compilation stuff

* Remove else for unicode handling
master
Drashna Jaelre 2018-12-19 08:39:24 -08:00 committed by MechMerlin
parent 40bf3a2ce9
commit fdeec29636
13 changed files with 321 additions and 157 deletions

View File

@ -1,28 +1,28 @@
# Unicode Support # Unicode Support
There are three Unicode keymap definition method available in QMK: There are three Unicode keymap definition methods available in QMK:
## UNICODE_ENABLE ## UNICODE_ENABLE
Supports Unicode input up to 0xFFFF. The keycode function is `UC(n)` in keymap file, where *n* is a 4 digit hexadecimal. Supports Unicode up to `0xFFFF`. The keycode function is `UC(n)` in the keymap file, where _n_ is a 4 digit hexadecimal number.
## UNICODEMAP_ENABLE ## UNICODEMAP_ENABLE
Supports Unicode up to 0xFFFFFFFF. You need to maintain a separate mapping table `const uint32_t PROGMEM unicode_map[] = {...}` in your keymap file. The keycode function is `X(n)` where *n* is the array index of the mapping table. Supports Unicode up to `0x10FFFF` (all possible code points). You need to maintain a separate mapping table `const uint32_t PROGMEM unicode_map[] = {...}` in your keymap file. The keycode function is `X(n)`, where _n_ is an array index into the mapping table.
And you may want to have an enum to make reference easier. So you'd want to add something like this to your keymap: And you may want to have an enum to make reference easier. So you'd want to add something like this to your keymap:
```c ```c
enum unicode_name { enum unicode_names {
BANG, // ‽ BANG,
IRONY, // ⸮ IRONY,
SNEK // snke 🐍 SNEK,
}; };
const uint32_t PROGMEM unicode_map[] = { const uint32_t PROGMEM unicode_map[] = {
[BANG] = 0x0203D, // ‽ [BANG] = 0x203D, // ‽
[IRONY] = 0x02E2E, // ⸮ [IRONY] = 0x2E2E, // ⸮
[SNEK] = 0x1F40D // snke 🐍 [SNEK] = 0x1F40D, // 🐍
}: }:
``` ```
@ -30,7 +30,7 @@ Make sure that the order for both matches.
## UCIS_ENABLE ## UCIS_ENABLE
Supports Unicode up to 0xFFFFFFFF. As with `UNICODE_MAP`, you may want to maintain a mapping table in your keymap file. However, there is no keycodes for this feature, you will have to add a keycode or function to call `qk_ucis_start()`. Once you've run that, you can just type the text for your unicode, and then hit space or enter to complete it, or ESC to cancel it. And if it matches an entry in your table, it will automatically "backspace" the trigger word (from your table) and then will input the unicode sequence. Supports Unicode up to `0x10FFFF` (all possible code points). As with `UNICODEMAP`, you may want to maintain a mapping table in your keymap file. However, there are no built-in keycodes for this feature — you will have to add a keycode or function that calls `qk_ucis_start()`. Once it's been called, you can type the mnemonic for your character, then hit Space or Enter to complete it or Esc to cancel. If the mnemonic matches an entry in your table, the typed text will automatically be erased and the corresponding Unicode sequence inserted.
For instance, you would need to have a table like this in your keymap: For instance, you would need to have a table like this in your keymap:
@ -53,42 +53,103 @@ There are several functions that you can add to your keymap to customize the fun
* `void qk_ucis_success(uint8_t symbol_index)` - This runs when the unicode input has matched something, and has completed. Default doesn't do anything. * `void qk_ucis_success(uint8_t symbol_index)` - This runs when the unicode input has matched something, and has completed. Default doesn't do anything.
* `void qk_ucis_symbol_fallback (void)` - This runs if the input text doesn't match anything. The default function falls back to trying that input as a unicode code. * `void qk_ucis_symbol_fallback (void)` - This runs if the input text doesn't match anything. The default function falls back to trying that input as a unicode code.
The default code for these are: You can find the default implementations of these functions in [`process_ucis.c`](https://github.com/qmk/qmk_firmware/blob/master/quantum/process_keycode/process_ucis.c).
## Input Modes
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.
The following input modes are available:
* **`UC_OSX`**: Mac OS X built-in Unicode hex input. Supports code points up to `0xFFFF` (`0x10FFFF` with `UNICODEMAP`).
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.
By default, this mode uses the left Option key (`KC_LALT`), but this can be changed by defining [`UNICODE_OSX_KEY`](#input-key-configuration) with another keycode.
* **`UC_LNX`**: Linux built-in IBus Unicode input. Supports all possible code points (`0x10FFFF`).
Enabled by default and works almost anywhere on IBus-enabled distros. Without IBus, this mode works under GTK apps, but rarely anywhere else.
* **`UC_WIN`**: _(not recommended)_ Windows built-in hex numpad Unicode input. Supports code points up to `0xFFFF`.
To enable, create a registry key under `HKEY_CURRENT_USER\Control Panel\Input Method\EnableHexNumpad` of type `REG_SZ` called `EnableHexNumpad` and set its value to `1`. This can be done from the Command Prompt by running `reg add "HKCU\Control Panel\Input Method" -v EnableHexNumpad -t REG_SZ -d 1` with administrator privileges. Afterwards, reboot.
This mode is not recommended because of reliability and compatibility issues; use the `UC_WINC` mode instead.
* **`UC_BSD`**: _(non implemented)_ Unicode input under BSD. Not implemented at this time. If you're a BSD user and want to help add support for it, please [open an issue on GitHub](https://github.com/qmk/qmk_firmware/issues).
* **`UC_WINC`**: Windows Unicode input using [WinCompose](https://github.com/samhocevar/wincompose). As of v0.8.2, supports code points up to `0xFFFFF`.
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.
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`](#input-key-configuration) with another keycode.
### Switching Input Modes
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 the first time, you don't need to set it again unless you want to change it, or you've reset the EEPROM settings.
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.
|Keycode |Alias |Input mode |Description |
|-----------------------|---------|-------------|-----------------------------------------|
|`UNICODE_MODE_FORWARD` |`UC_MOD` | |Cycles forwards through the available modes. [(Disabled by default)](#input-method-cycling)|
|`UNICODE_MODE_REVERSE` |`UC_RMOD`| |Cycles forwards through the available modes. [(Disabled by default)](#input-method-cycling)|
|`UNICODE_MODE_OSX` |`UC_M_OS`|`UC_OSX` |Switch to Mac OS X input. |
|`UNICODE_MODE_LNX` |`UC_M_LN`|`UC_LNX` |Switch to Linux input. |
|`UNICODE_MODE_WIN` |`UC_M_WI`|`UC_WIN` |Switch to Windows input. |
|`UNICODE_MODE_BSD` |`UC_M_BS`|`UC_BSD` |Switch to BSD input (not implemented). |
|`UNICODE_MODE_WINC` |`UC_M_WC`|`UC_WINC` |Switch to Windows input using WinCompose.|
You can also switch the input mode by calling `set_unicode_input_mode(x)` in your code, where _x_ is one of the above input mode constants (e.g. `UC_LNX`). Since the function only needs to be called once, it's recommended that you do it in `eeconfig_init_user` (or a similar function). For example:
```c ```c
void qk_ucis_start_user(void) { // outputs keyboard emoji void eeconfig_init_user(void) {
unicode_input_start(); set_unicode_input_mode(UC_LNX);
register_hex(0x2328);
unicode_input_finish();
}
void qk_ucis_success(uint8_t symbol_index) {
}
void qk_ucis_symbol_fallback (void) { // falls back to manual unicode entry
for (uint8_t i = 0; i < qk_ucis_state.count - 1; i++) {
uint8_t code = qk_ucis_state.codes[i];
register_code(code);
unregister_code(code);
wait_ms(UNICODE_TYPE_DELAY);
}
} }
``` ```
## Unicode Input methods ### Audio Feedback
Unicode input in QMK works by inputting a sequence of characters to the OS, 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.
sort of like macro. Unfortunately, each OS has different ideas on how Unicode is input.
This is the current list of Unicode input method in QMK: For instance, you can add these definitions to your `config.h` file:
* __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. ```c
* __UC_OSX_RALT__: Same as UC_OSX, but sends the Right Alt key for unicode input #define UNICODE_SONG_OSX COIN_SOUND
* __UC_LNX__: Unicode input method under Linux. Works up to 0xFFFFF. Should work almost anywhere on ibus enabled distros. Without ibus, this works under GTK apps, but rarely anywhere else. #define UNICODE_SONG_LNX UNICODE_LINUX
* __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. #define UNICODE_SONG_BSD MARIO_GAMEOVER
* __UC_WINC__: Windows Unicode input using WinCompose. Requires [WinCompose](https://github.com/samhocevar/wincompose). Works reliably under many (all?) variations of Windows. #define UNICODE_SONG_WIN UNICODE_WINDOWS
#define UNICODE_SONG_WINC UNICODE_WINDOWS
```
At some point, you need to call `set_unicode_input_mode(x)` to set the correct unicode method. This sets the method that is used to send the unicode, and stores it in EEPROM, so you only need to call this once. ### Additional Customization
Because Unicode is such a large and variable feature, there are a number of options that you can customize to work better on your system.
#### Start and Finish input functions
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.
* `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.
* `void unicode_input_finish(void)` This is called to exit Unicode input mode, for example by pressing Space or releasing the Option key.
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).
#### Input Key Configuration
Additionally, you can customize the keys used to trigger the unicode input for macOS and WinCompose by adding defines to your `config.h`
```c
#define UNICODE_OSX_KEY KC_LALT
#define UNICODE_WINC_KEY KC_RALT
```
#### Input Method Cycling
Also, you can choose which input methods are availble for cycling through. By default, this is disabled. But if you want to enabled it, then limiting it to just those modes makes sense. Note that `UNICODE_SELECTED_MODES` define is comma delimited.
```c
#define UNICODE_SELECTED_MODES UC_OSX, UC_LNX, UC_WIN, UC_BSD, UC_WINC
```
## `send_unicode_hex_string` ## `send_unicode_hex_string`

View File

@ -21,3 +21,7 @@
#define PERMISSIVE_HOLD #define PERMISSIVE_HOLD
#define TAPPING_TERM 200 #define TAPPING_TERM 200
#define TAPPING_TOGGLE 2 #define TAPPING_TOGGLE 2
#define UNICODE_CYCLE_PERSIST false
#define UNICODE_SELECTED_MODES UC_WINC, UC_LNX
#define UNICODE_WINC_KEY KC_RGUI

View File

@ -23,10 +23,6 @@
#define DIVIDE UC(0x00F7) #define DIVIDE UC(0x00F7)
#define MINUS UC(0x2212) #define MINUS UC(0x2212)
void eeconfig_init_user(void) {
set_unicode_input_mode(UC_WINC);
}
enum layers { enum layers {
L_BASE, L_BASE,
L_FN, L_FN,
@ -162,7 +158,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
* *
* F1 F2 F3 F4 F5 F6 F7 F8 F9 F10F11F12NumScrPau * F1 F2 F3 F4 F5 F6 F7 F8 F9 F10F11F12NumScrPau
* *
* M4 M2 M M1 M3 M5 StpPlyPrvNxtClearIns * M4 M2 M M1 M3 M5 UCM StpPlyPrvNxtClearIns
* *
* M M M MW Top * M M M MW Top
* *
@ -173,7 +169,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
*/ */
[L_FN] = LAYOUT_truefox( \ [L_FN] = LAYOUT_truefox( \
_______, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, NUMPAD, KC_SLCK, KC_PAUS, \ _______, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, NUMPAD, KC_SLCK, KC_PAUS, \
KC_BTN4, KC_BTN2, KC_MS_U, KC_BTN1, KC_BTN3, KC_BTN5, _______, _______, _______, KC_MSTP, KC_MPLY, KC_MPRV, KC_MNXT, CLEAR, KC_INS, \ KC_BTN4, KC_BTN2, KC_MS_U, KC_BTN1, KC_BTN3, KC_BTN5, _______, UC_MOD, _______, KC_MSTP, KC_MPLY, KC_MPRV, KC_MNXT, CLEAR, KC_INS, \
_______, KC_MS_L, KC_MS_D, KC_MS_R, KC_WH_U, _______, _______, _______, _______, _______, _______, _______, _______, TOP, \ _______, KC_MS_L, KC_MS_D, KC_MS_R, KC_WH_U, _______, _______, _______, _______, _______, _______, _______, _______, TOP, \
_______, KC_ACL0, KC_ACL2, KC_WH_L, KC_WH_R, _______, _______, _______, KC_VOLD, KC_VOLU, KC_MUTE, KC_APP, KC_PGUP, BOTTOM, \ _______, KC_ACL0, KC_ACL2, KC_WH_L, KC_WH_R, _______, _______, _______, KC_VOLD, KC_VOLU, KC_MUTE, KC_APP, KC_PGUP, BOTTOM, \
_______, DESKTOP, DSKTP_L, KC_WH_D, DSKTP_R, _______, KC_HOME, KC_PGDN, KC_END \ _______, DESKTOP, DSKTP_L, KC_WH_D, DSKTP_R, _______, KC_HOME, KC_PGDN, KC_END \

View File

@ -95,8 +95,6 @@ void register_ucis(const char *hex) {
bool process_ucis (uint16_t keycode, keyrecord_t *record) { bool process_ucis (uint16_t keycode, keyrecord_t *record) {
uint8_t i; uint8_t i;
unicode_input_mode_init();
if (!qk_ucis_state.in_progress) if (!qk_ucis_state.in_progress)
return true; return true;

View File

@ -14,8 +14,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef PROCESS_UCIS_H #pragma once
#define PROCESS_UCIS_H
#include "quantum.h" #include "quantum.h"
#include "process_unicode_common.h" #include "process_unicode_common.h"
@ -48,5 +47,3 @@ void qk_ucis_symbol_fallback (void);
void qk_ucis_success(uint8_t symbol_index); void qk_ucis_success(uint8_t symbol_index);
void register_ucis(const char *hex); void register_ucis(const char *hex);
bool process_ucis (uint16_t keycode, keyrecord_t *record); bool process_ucis (uint16_t keycode, keyrecord_t *record);
#endif

View File

@ -20,11 +20,9 @@
bool process_unicode(uint16_t keycode, keyrecord_t *record) { bool process_unicode(uint16_t keycode, keyrecord_t *record) {
if (keycode > QK_UNICODE && record->event.pressed) { if (keycode > QK_UNICODE && record->event.pressed) {
uint16_t unicode = keycode & 0x7FFF; uint16_t unicode = keycode & 0x7FFF;
unicode_input_mode_init();
unicode_input_start(); unicode_input_start();
register_hex(unicode); register_hex(unicode);
unicode_input_finish(); unicode_input_finish();
} }
return true; return true;
} }

View File

@ -13,12 +13,9 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef PROCESS_UNICODE_H #pragma once
#define PROCESS_UNICODE_H
#include "quantum.h" #include "quantum.h"
#include "process_unicode_common.h" #include "process_unicode_common.h"
bool process_unicode(uint16_t keycode, keyrecord_t *record); bool process_unicode(uint16_t keycode, keyrecord_t *record);
#endif

View File

@ -16,98 +16,111 @@
#include "process_unicode_common.h" #include "process_unicode_common.h"
#include "eeprom.h" #include "eeprom.h"
#include <string.h>
#include <ctype.h> #include <ctype.h>
#include <string.h>
static uint8_t input_mode; unicode_config_t unicode_config;
uint8_t mods; #if UNICODE_SELECTED_MODES != -1
static uint8_t selected[] = { UNICODE_SELECTED_MODES };
static uint8_t selected_count = sizeof selected / sizeof *selected;
static uint8_t selected_index;
#endif
void set_unicode_input_mode(uint8_t os_target) { void unicode_input_mode_init(void) {
input_mode = os_target; unicode_config.raw = eeprom_read_byte(EECONFIG_UNICODEMODE);
eeprom_update_byte(EECONFIG_UNICODEMODE, os_target); #if UNICODE_SELECTED_MODES != -1
#if UNICODE_CYCLE_PERSIST
// Find input_mode in selected modes
uint8_t i;
for (i = 0; i < selected_count; i++) {
if (selected[i] == unicode_config.input_mode) {
selected_index = i;
break;
}
}
if (i == selected_count) {
// Not found: input_mode isn't selected, change to one that is
unicode_config.input_mode = selected[selected_index = 0];
}
#else
// Always change to the first selected input mode
unicode_config.input_mode = selected[selected_index = 0];
#endif
#endif
dprintf("Unicode input mode init to: %u\n", unicode_config.input_mode);
} }
uint8_t get_unicode_input_mode(void) { uint8_t get_unicode_input_mode(void) {
return input_mode; return unicode_config.input_mode;
} }
void unicode_input_mode_init(void) { void set_unicode_input_mode(uint8_t mode) {
static bool first_flag = false; unicode_config.input_mode = mode;
if (!first_flag) { persist_unicode_input_mode();
input_mode = eeprom_read_byte(EECONFIG_UNICODEMODE); dprintf("Unicode input mode set to: %u\n", unicode_config.input_mode);
first_flag = true;
}
} }
void cycle_unicode_input_mode(uint8_t offset) {
#if UNICODE_SELECTED_MODES != -1
selected_index = (selected_index + offset) % selected_count;
unicode_config.input_mode = selected[selected_index];
#if UNICODE_CYCLE_PERSIST
persist_unicode_input_mode();
#endif
dprintf("Unicode input mode cycle to: %u\n", unicode_config.input_mode);
#endif
}
void persist_unicode_input_mode(void) {
eeprom_update_byte(EECONFIG_UNICODEMODE, unicode_config.input_mode);
}
static uint8_t saved_mods;
__attribute__((weak)) __attribute__((weak))
void unicode_input_start (void) { void unicode_input_start(void) {
// save current mods saved_mods = get_mods(); // Save current mods
mods = keyboard_report->mods; clear_mods(); // Unregister mods to start from a clean state
// unregister all mods to start from clean state switch (unicode_config.input_mode) {
if (mods & MOD_BIT(KC_LSFT)) unregister_code(KC_LSFT);
if (mods & MOD_BIT(KC_RSFT)) unregister_code(KC_RSFT);
if (mods & MOD_BIT(KC_LCTL)) unregister_code(KC_LCTL);
if (mods & MOD_BIT(KC_RCTL)) unregister_code(KC_RCTL);
if (mods & MOD_BIT(KC_LALT)) unregister_code(KC_LALT);
if (mods & MOD_BIT(KC_RALT)) unregister_code(KC_RALT);
if (mods & MOD_BIT(KC_LGUI)) unregister_code(KC_LGUI);
if (mods & MOD_BIT(KC_RGUI)) unregister_code(KC_RGUI);
switch(input_mode) {
case UC_OSX: case UC_OSX:
register_code(KC_LALT); register_code(UNICODE_OSX_KEY);
break;
case UC_OSX_RALT:
register_code(KC_RALT);
break; break;
case UC_LNX: case UC_LNX:
register_code(KC_LCTL); register_code(KC_LCTL);
register_code(KC_LSFT); register_code(KC_LSFT);
register_code(KC_U); tap_code(KC_U); // TODO: Replace with tap_code16(LCTL(LSFT(KC_U))); and test
unregister_code(KC_U);
unregister_code(KC_LSFT); unregister_code(KC_LSFT);
unregister_code(KC_LCTL); unregister_code(KC_LCTL);
break; break;
case UC_WIN: case UC_WIN:
register_code(KC_LALT); register_code(KC_LALT);
register_code(KC_PPLS); tap_code(KC_PPLS);
unregister_code(KC_PPLS);
break; break;
case UC_WINC: case UC_WINC:
register_code(KC_RALT); tap_code(UNICODE_WINC_KEY);
unregister_code(KC_RALT); tap_code(KC_U);
register_code(KC_U); break;
unregister_code(KC_U);
} }
wait_ms(UNICODE_TYPE_DELAY); wait_ms(UNICODE_TYPE_DELAY);
} }
__attribute__((weak)) __attribute__((weak))
void unicode_input_finish (void) { void unicode_input_finish(void) {
switch(input_mode) { switch (unicode_config.input_mode) {
case UC_OSX: case UC_OSX:
case UC_WIN: unregister_code(UNICODE_OSX_KEY);
unregister_code(KC_LALT); break;
break; case UC_LNX:
case UC_OSX_RALT: tap_code(KC_SPC);
unregister_code(KC_RALT); break;
break; case UC_WIN:
case UC_LNX: unregister_code(KC_LALT);
register_code(KC_SPC); break;
unregister_code(KC_SPC);
break;
} }
// reregister previously set mods set_mods(saved_mods); // Reregister previously set mods
if (mods & MOD_BIT(KC_LSFT)) register_code(KC_LSFT);
if (mods & MOD_BIT(KC_RSFT)) register_code(KC_RSFT);
if (mods & MOD_BIT(KC_LCTL)) register_code(KC_LCTL);
if (mods & MOD_BIT(KC_RCTL)) register_code(KC_RCTL);
if (mods & MOD_BIT(KC_LALT)) register_code(KC_LALT);
if (mods & MOD_BIT(KC_RALT)) register_code(KC_RALT);
if (mods & MOD_BIT(KC_LGUI)) register_code(KC_LGUI);
if (mods & MOD_BIT(KC_RGUI)) register_code(KC_RGUI);
} }
__attribute__((weak)) __attribute__((weak))
@ -124,13 +137,12 @@ uint16_t hex_to_keycode(uint8_t hex) {
void register_hex(uint16_t hex) { void register_hex(uint16_t hex) {
for(int i = 3; i >= 0; i--) { for(int i = 3; i >= 0; i--) {
uint8_t digit = ((hex >> (i*4)) & 0xF); uint8_t digit = ((hex >> (i*4)) & 0xF);
register_code(hex_to_keycode(digit)); tap_code(hex_to_keycode(digit));
unregister_code(hex_to_keycode(digit));
} }
} }
void send_unicode_hex_string(const char *str) { void send_unicode_hex_string(const char *str) {
if (!str) { return; } // Safety net if (!str) { return; }
while (*str) { while (*str) {
// Find the next code point (token) in the string // Find the next code point (token) in the string
@ -153,3 +165,61 @@ void send_unicode_hex_string(const char *str) {
str += n; // Move to the first ' ' (or '\0') after the current token str += n; // Move to the first ' ' (or '\0') after the current token
} }
} }
bool process_unicode_common(uint16_t keycode, keyrecord_t *record) {
if (record->event.pressed) {
switch (keycode) {
case UNICODE_MODE_FORWARD:
cycle_unicode_input_mode(+1);
break;
case UNICODE_MODE_REVERSE:
cycle_unicode_input_mode(-1);
break;
case UNICODE_MODE_OSX:
set_unicode_input_mode(UC_OSX);
#if defined(AUDIO_ENABLE) && defined(UNICODE_SONG_OSX)
static float song_osx[][2] = UNICODE_SONG_OSX;
PLAY_SONG(song_osx);
#endif
break;
case UNICODE_MODE_LNX:
set_unicode_input_mode(UC_LNX);
#if defined(AUDIO_ENABLE) && defined(UNICODE_SONG_LNX)
static float song_lnx[][2] = UNICODE_SONG_LNX;
PLAY_SONG(song_lnx);
#endif
break;
case UNICODE_MODE_WIN:
set_unicode_input_mode(UC_WIN);
#if defined(AUDIO_ENABLE) && defined(UNICODE_SONG_WIN)
static float song_win[][2] = UNICODE_SONG_WIN;
PLAY_SONG(song_win);
#endif
break;
case UNICODE_MODE_BSD:
set_unicode_input_mode(UC_BSD);
#if defined(AUDIO_ENABLE) && defined(UNICODE_SONG_BSD)
static float song_bsd[][2] = UNICODE_SONG_BSD;
PLAY_SONG(song_bsd);
#endif
break;
case UNICODE_MODE_WINC:
set_unicode_input_mode(UC_WINC);
#if defined(AUDIO_ENABLE) && defined(UNICODE_SONG_WINC)
static float song_winc[][2] = UNICODE_SONG_WINC;
PLAY_SONG(song_winc);
#endif
break;
}
}
#if defined(UNICODE_ENABLE)
return process_unicode(keycode, record);
#elif defined(UNICODEMAP_ENABLE)
return process_unicode_map(keycode, record);
#elif defined(UCIS_ENABLE)
return process_ucis(keycode, record);
#else
return true;
#endif
}

View File

@ -14,35 +14,71 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef PROCESS_UNICODE_COMMON_H #pragma once
#define PROCESS_UNICODE_COMMON_H
#include "quantum.h" #include "quantum.h"
#ifndef UNICODE_TYPE_DELAY #if defined(UNICODE_ENABLE) + defined(UNICODEMAP_ENABLE) + defined(UCIS_ENABLE) > 1
#define UNICODE_TYPE_DELAY 10 #error "Cannot enable more than one Unicode method (UNICODE, UNICODEMAP, UCIS) at the same time"
#endif #endif
__attribute__ ((unused)) // Keycodes used for starting Unicode input on different platforms
static uint8_t input_mode; #ifndef UNICODE_OSX_KEY
#define UNICODE_OSX_KEY KC_LALT
#endif
#ifndef UNICODE_WINC_KEY
#define UNICODE_WINC_KEY KC_RALT
#endif
// Comma-delimited, ordered list of input modes selected for use (e.g. in cycle)
// Example: #define UNICODE_SELECTED_MODES UC_WINC, UC_LNX
#ifndef UNICODE_SELECTED_MODES
#define UNICODE_SELECTED_MODES -1
#endif
// Whether input mode changes in cycle should be written to EEPROM
#ifndef UNICODE_CYCLE_PERSIST
#define UNICODE_CYCLE_PERSIST true
#endif
// Delay between starting Unicode input and sending a sequence, in ms
#ifndef UNICODE_TYPE_DELAY
#define UNICODE_TYPE_DELAY 10
#endif
enum unicode_input_modes {
UC_OSX, // Mac OS X using Unicode Hex Input
UC_LNX, // Linux using IBus
UC_WIN, // Windows using EnableHexNumpad
UC_BSD, // BSD (not implemented)
UC_WINC, // Windows using WinCompose (https://github.com/samhocevar/wincompose)
UC__COUNT // Number of available input modes (always leave at the end)
};
typedef union {
uint32_t raw;
struct {
uint8_t input_mode : 8;
};
} unicode_config_t;
extern unicode_config_t unicode_config;
void set_unicode_input_mode(uint8_t os_target);
uint8_t get_unicode_input_mode(void);
void unicode_input_mode_init(void); void unicode_input_mode_init(void);
uint8_t get_unicode_input_mode(void);
void set_unicode_input_mode(uint8_t mode);
void cycle_unicode_input_mode(uint8_t offset);
void persist_unicode_input_mode(void);
void unicode_input_start(void); void unicode_input_start(void);
void unicode_input_finish(void); void unicode_input_finish(void);
void register_hex(uint16_t hex); void register_hex(uint16_t hex);
void send_unicode_hex_string(const char *str); void send_unicode_hex_string(const char *str);
#define UC_OSX 0 // Mac OS X bool process_unicode_common(uint16_t keycode, keyrecord_t *record);
#define UC_LNX 1 // Linux
#define UC_WIN 2 // Windows 'HexNumpad'
#define UC_BSD 3 // BSD (not implemented)
#define UC_WINC 4 // WinCompose https://github.com/samhocevar/wincompose
#define UC_OSX_RALT 5 // Mac OS X using Right Alt key for Unicode Compose
#define UC_BSPC UC(0x0008) #define UC_BSPC UC(0x0008)
#define UC_SPC UC(0x0020) #define UC_SPC UC(0x0020)
#define UC_EXLM UC(0x0021) #define UC_EXLM UC(0x0021)
@ -147,5 +183,3 @@ void send_unicode_hex_string(const char *str);
#define UC_RCBR UC(0x007D) #define UC_RCBR UC(0x007D)
#define UC_TILD UC(0x007E) #define UC_TILD UC(0x007E)
#define UC_DEL UC(0x007F) #define UC_DEL UC(0x007F)
#endif

View File

@ -45,13 +45,12 @@ __attribute__((weak))
void unicode_map_input_error() {} void unicode_map_input_error() {}
bool process_unicode_map(uint16_t keycode, keyrecord_t *record) { bool process_unicode_map(uint16_t keycode, keyrecord_t *record) {
unicode_input_mode_init();
uint8_t input_mode = get_unicode_input_mode(); uint8_t input_mode = get_unicode_input_mode();
if ((keycode & QK_UNICODE_MAP) == QK_UNICODE_MAP && record->event.pressed) { if ((keycode & QK_UNICODE_MAP) == QK_UNICODE_MAP && record->event.pressed) {
const uint32_t* map = unicode_map; const uint32_t* map = unicode_map;
uint16_t index = keycode - QK_UNICODE_MAP; uint16_t index = keycode - QK_UNICODE_MAP;
uint32_t code = pgm_read_dword(&map[index]); uint32_t code = pgm_read_dword(&map[index]);
if (code > 0xFFFF && code <= 0x10ffff && (input_mode == UC_OSX || input_mode == UC_OSX_RALT)) { if (code > 0xFFFF && code <= 0x10ffff && input_mode == UC_OSX) {
// Convert to UTF-16 surrogate pair // Convert to UTF-16 surrogate pair
code -= 0x10000; code -= 0x10000;
uint32_t lo = code & 0x3ff; uint32_t lo = code & 0x3ff;
@ -60,7 +59,7 @@ bool process_unicode_map(uint16_t keycode, keyrecord_t *record) {
register_hex32(hi + 0xd800); register_hex32(hi + 0xd800);
register_hex32(lo + 0xdc00); register_hex32(lo + 0xdc00);
unicode_input_finish(); unicode_input_finish();
} else if ((code > 0x10ffff && (input_mode == UC_OSX || input_mode == UC_OSX_RALT)) || (code > 0xFFFFF && input_mode == UC_LNX)) { } else if ((code > 0x10ffff && input_mode == UC_OSX) || (code > 0xFFFFF && input_mode == UC_LNX)) {
// when character is out of range supported by the OS // when character is out of range supported by the OS
unicode_map_input_error(); unicode_map_input_error();
} else { } else {

View File

@ -14,12 +14,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef PROCESS_UNICODEMAP_H #pragma once
#define PROCESS_UNICODEMAP_H
#include "quantum.h" #include "quantum.h"
#include "process_unicode_common.h" #include "process_unicode_common.h"
void unicode_map_input_error(void); void unicode_map_input_error(void);
bool process_unicode_map(uint16_t keycode, keyrecord_t *record); bool process_unicode_map(uint16_t keycode, keyrecord_t *record);
#endif

View File

@ -243,7 +243,7 @@ bool process_record_quantum(keyrecord_t *record) {
process_key_lock(&keycode, record) && process_key_lock(&keycode, record) &&
#endif #endif
#if defined(AUDIO_ENABLE) && defined(AUDIO_CLICKY) #if defined(AUDIO_ENABLE) && defined(AUDIO_CLICKY)
process_clicky(keycode, record) && process_clicky(keycode, record) &&
#endif //AUDIO_CLICKY #endif //AUDIO_CLICKY
process_record_kb(keycode, record) && process_record_kb(keycode, record) &&
#if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_KEYPRESSES) #if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_KEYPRESSES)
@ -258,33 +258,27 @@ bool process_record_quantum(keyrecord_t *record) {
#ifdef STENO_ENABLE #ifdef STENO_ENABLE
process_steno(keycode, record) && process_steno(keycode, record) &&
#endif #endif
#if ( defined(AUDIO_ENABLE) || (defined(MIDI_ENABLE) && defined(MIDI_BASIC))) && !defined(NO_MUSIC_MODE) #if (defined(AUDIO_ENABLE) || (defined(MIDI_ENABLE) && defined(MIDI_BASIC))) && !defined(NO_MUSIC_MODE)
process_music(keycode, record) && process_music(keycode, record) &&
#endif #endif
#ifdef TAP_DANCE_ENABLE #ifdef TAP_DANCE_ENABLE
process_tap_dance(keycode, record) && process_tap_dance(keycode, record) &&
#endif #endif
#if defined(UNICODE_ENABLE) || defined(UNICODEMAP_ENABLE) || defined(UCIS_ENABLE)
process_unicode_common(keycode, record) &&
#endif
#ifdef LEADER_ENABLE #ifdef LEADER_ENABLE
process_leader(keycode, record) && process_leader(keycode, record) &&
#endif #endif
#ifdef COMBO_ENABLE #ifdef COMBO_ENABLE
process_combo(keycode, record) && process_combo(keycode, record) &&
#endif #endif
#ifdef UNICODE_ENABLE
process_unicode(keycode, record) &&
#endif
#ifdef UCIS_ENABLE
process_ucis(keycode, record) &&
#endif
#ifdef PRINTING_ENABLE #ifdef PRINTING_ENABLE
process_printer(keycode, record) && process_printer(keycode, record) &&
#endif #endif
#ifdef AUTO_SHIFT_ENABLE #ifdef AUTO_SHIFT_ENABLE
process_auto_shift(keycode, record) && process_auto_shift(keycode, record) &&
#endif #endif
#ifdef UNICODEMAP_ENABLE
process_unicode_map(keycode, record) &&
#endif
#ifdef TERMINAL_ENABLE #ifdef TERMINAL_ENABLE
process_terminal(keycode, record) && process_terminal(keycode, record) &&
#endif #endif
@ -1010,6 +1004,9 @@ void matrix_init_quantum() {
#ifdef ENCODER_ENABLE #ifdef ENCODER_ENABLE
encoder_init(); encoder_init();
#endif #endif
#if defined(UNICODE_ENABLE) || defined(UNICODEMAP_ENABLE) || defined(UCIS_ENABLE)
unicode_input_mode_init();
#endif
matrix_init_kb(); matrix_init_kb();
} }

View File

@ -81,9 +81,6 @@ enum quantum_keycodes {
#endif #endif
QK_MOD_TAP = 0x6000, QK_MOD_TAP = 0x6000,
QK_MOD_TAP_MAX = 0x7FFF, QK_MOD_TAP_MAX = 0x7FFF,
#if defined(UNICODEMAP_ENABLE) && defined(UNICODE_ENABLE)
#error "Cannot enable both UNICODEMAP && UNICODE"
#endif
#ifdef UNICODE_ENABLE #ifdef UNICODE_ENABLE
QK_UNICODE = 0x8000, QK_UNICODE = 0x8000,
QK_UNICODE_MAX = 0xFFFF, QK_UNICODE_MAX = 0xFFFF,
@ -456,6 +453,15 @@ enum quantum_keycodes {
EEPROM_RESET, EEPROM_RESET,
UNICODE_MODE_FORWARD,
UNICODE_MODE_REVERSE,
UNICODE_MODE_OSX,
UNICODE_MODE_LNX,
UNICODE_MODE_WIN,
UNICODE_MODE_BSD,
UNICODE_MODE_WINC,
// always leave at the end // always leave at the end
SAFE_RANGE SAFE_RANGE
}; };
@ -684,6 +690,15 @@ enum quantum_keycodes {
#define X(n) (QK_UNICODE_MAP | (n)) #define X(n) (QK_UNICODE_MAP | (n))
#endif #endif
#define UC_MOD UNICODE_MODE_FORWARD
#define UC_RMOD UNICODE_MODE_REVERSE
#define UC_M_OS UNICODE_MODE_OSX
#define UC_M_LN UNICODE_MODE_LNX
#define UC_M_WI UNICODE_MODE_WIN
#define UC_M_BS UNICODE_MODE_BSD
#define UC_M_WC UNICODE_MODE_WINC
#ifdef SWAP_HANDS_ENABLE #ifdef SWAP_HANDS_ENABLE
#define SH_T(kc) (QK_SWAP_HANDS | (kc)) #define SH_T(kc) (QK_SWAP_HANDS | (kc))
#define SH_TG (QK_SWAP_HANDS | OP_SH_TOGGLE) #define SH_TG (QK_SWAP_HANDS | OP_SH_TOGGLE)