From dde1bf150b8a5f3d4a46b62d8baad7640d366387 Mon Sep 17 00:00:00 2001 From: Drashna Jaelre Date: Fri, 2 Nov 2018 08:37:38 -0700 Subject: [PATCH 01/42] Standardize the Unicode EEPROM code --- .../process_keycode/process_unicode_common.c | 44 +++++-------------- .../process_keycode/process_unicode_common.h | 9 +++- 2 files changed, 18 insertions(+), 35 deletions(-) diff --git a/quantum/process_keycode/process_unicode_common.c b/quantum/process_keycode/process_unicode_common.c index 4285d20a19fb..c270d5119acc 100644 --- a/quantum/process_keycode/process_unicode_common.c +++ b/quantum/process_keycode/process_unicode_common.c @@ -19,42 +19,28 @@ #include #include -static uint8_t input_mode; -uint8_t mods; +unicode_config_t unicode_config; +static uint8_t saved_mods; void set_unicode_input_mode(uint8_t os_target) { - input_mode = os_target; + unicode_config.input_mode = os_target; eeprom_update_byte(EECONFIG_UNICODEMODE, os_target); } uint8_t get_unicode_input_mode(void) { - return input_mode; + return unicode_config.input_mode; } void unicode_input_mode_init(void) { - static bool first_flag = false; - if (!first_flag) { - input_mode = eeprom_read_byte(EECONFIG_UNICODEMODE); - first_flag = true; - } + unicode_config.raw = eeprom_read_byte(EECONFIG_UNICODEMODE); } __attribute__((weak)) void unicode_input_start (void) { - // save current mods - mods = keyboard_report->mods; - - // unregister all mods to start from clean state - 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) { + saved_mods = get_mods(); // Save current mods + clear_mods(); // Unregister mods to start from a clean state + + switch(unicode_config.input_mode) { case UC_OSX: register_code(KC_LALT); break; @@ -85,7 +71,7 @@ void unicode_input_start (void) { __attribute__((weak)) void unicode_input_finish (void) { - switch(input_mode) { + switch(unicode_config.input_mode) { case UC_OSX: case UC_WIN: unregister_code(KC_LALT); @@ -99,15 +85,7 @@ void unicode_input_finish (void) { break; } - // 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); + set_mods(saved_mods); // Reregister previously set mods } __attribute__((weak)) diff --git a/quantum/process_keycode/process_unicode_common.h b/quantum/process_keycode/process_unicode_common.h index e78e1cec6ce9..7f896461b6ae 100644 --- a/quantum/process_keycode/process_unicode_common.h +++ b/quantum/process_keycode/process_unicode_common.h @@ -23,8 +23,13 @@ #define UNICODE_TYPE_DELAY 10 #endif -__attribute__ ((unused)) -static uint8_t input_mode; +typedef union { + uint32_t raw; + struct { + uint8_t input_mode :8; + }; +} unicode_config_t; + void set_unicode_input_mode(uint8_t os_target); uint8_t get_unicode_input_mode(void); From 81c92f341701d8d07d535053f3323464fce2c703 Mon Sep 17 00:00:00 2001 From: Drashna Jaelre Date: Fri, 2 Nov 2018 08:41:55 -0700 Subject: [PATCH 02/42] Remove unicode init from process_record_* functions --- quantum/process_keycode/process_unicode.c | 2 -- quantum/process_keycode/process_unicodemap.c | 1 - 2 files changed, 3 deletions(-) diff --git a/quantum/process_keycode/process_unicode.c b/quantum/process_keycode/process_unicode.c index f39c4a36e1b6..19beb84520b9 100644 --- a/quantum/process_keycode/process_unicode.c +++ b/quantum/process_keycode/process_unicode.c @@ -20,11 +20,9 @@ bool process_unicode(uint16_t keycode, keyrecord_t *record) { if (keycode > QK_UNICODE && record->event.pressed) { uint16_t unicode = keycode & 0x7FFF; - unicode_input_mode_init(); unicode_input_start(); register_hex(unicode); unicode_input_finish(); } return true; } - diff --git a/quantum/process_keycode/process_unicodemap.c b/quantum/process_keycode/process_unicodemap.c index ab5717ba3aff..47c27b911716 100644 --- a/quantum/process_keycode/process_unicodemap.c +++ b/quantum/process_keycode/process_unicodemap.c @@ -45,7 +45,6 @@ __attribute__((weak)) void unicode_map_input_error() {} bool process_unicode_map(uint16_t keycode, keyrecord_t *record) { - unicode_input_mode_init(); uint8_t input_mode = get_unicode_input_mode(); if ((keycode & QK_UNICODE_MAP) == QK_UNICODE_MAP && record->event.pressed) { const uint32_t* map = unicode_map; From f8977b537fcbbaf3fedb9981060ede0576ec8712 Mon Sep 17 00:00:00 2001 From: Drashna Jaelre Date: Fri, 2 Nov 2018 08:43:32 -0700 Subject: [PATCH 03/42] Add unicode init to where it belongs: matrix_init_quantum --- quantum/quantum.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/quantum/quantum.c b/quantum/quantum.c index 69692233ebe4..d23a2970e5a7 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c @@ -1002,6 +1002,9 @@ void matrix_init_quantum() { #ifdef ENCODER_ENABLE encoder_init(); #endif + #if defined(UNICODE_ENABLE) || defined(UNICODEMAP_ENABLE) || defined(UCIS_ENABLE) + unicode_input_mode_init(); + #endif matrix_init_kb(); } From a37505dfc96db134288e6b34b088eae8fc972313 Mon Sep 17 00:00:00 2001 From: Drashna Jaelre Date: Fri, 2 Nov 2018 09:13:08 -0700 Subject: [PATCH 04/42] Move Unicode proccessing to unicode common --- .../process_keycode/process_unicode_common.c | 35 ++++++++++++++++++- .../process_keycode/process_unicode_common.h | 1 + quantum/quantum.c | 12 ++----- quantum/quantum_keycodes.h | 6 ++++ 4 files changed, 44 insertions(+), 10 deletions(-) diff --git a/quantum/process_keycode/process_unicode_common.c b/quantum/process_keycode/process_unicode_common.c index c270d5119acc..e8f5001380c3 100644 --- a/quantum/process_keycode/process_unicode_common.c +++ b/quantum/process_keycode/process_unicode_common.c @@ -22,6 +22,7 @@ unicode_config_t unicode_config; static uint8_t saved_mods; + void set_unicode_input_mode(uint8_t os_target) { unicode_config.input_mode = os_target; eeprom_update_byte(EECONFIG_UNICODEMODE, os_target); @@ -36,7 +37,7 @@ void unicode_input_mode_init(void) { } __attribute__((weak)) -void unicode_input_start (void) { +void unicode_input_start(void) { saved_mods = get_mods(); // Save current mods clear_mods(); // Unregister mods to start from a clean state @@ -131,3 +132,35 @@ void send_unicode_hex_string(const char *str) { str += n; // Move to the first ' ' (or '\0') after the current token } } + +bool process_record_unicode_common(uint16_t keycode, keyrecord_t *record) { + if (record->event.pressed) { + switch (keycode) { + case UNI_OSX: + set_unicode_input_mode(UC_OSX); + break; + case UNI_LINUX: + set_unicode_input_mode(UC_LNX); + break; + case UNI_WIN: + set_unicode_input_mode(UC_WIN); + break; + case UNI_WINC: + set_unicode_input_mode(UC_WINC); + break; + case UNI_OSX_RALT: + set_unicode_input_mode(UC_OSX_RALT); + break; + } + } + #ifdef UNICODE_ENABLE + return process_unicode(keycode, record); + #endif + #ifdef UCIS_ENABLE + return process_ucis(keycode, record); + #endif + #ifdef UNICODEMAP_ENABLE + return process_unicode_map(keycode, record); + #endif + return true; +} diff --git a/quantum/process_keycode/process_unicode_common.h b/quantum/process_keycode/process_unicode_common.h index 7f896461b6ae..b1fc8c0ac834 100644 --- a/quantum/process_keycode/process_unicode_common.h +++ b/quantum/process_keycode/process_unicode_common.h @@ -38,6 +38,7 @@ void unicode_input_start(void); void unicode_input_finish(void); void register_hex(uint16_t hex); void send_unicode_hex_string(const char *str); +bool process_record_unicode_common(uint16_t keycode, keyrecord_t *record); #define UC_OSX 0 // Mac OS X #define UC_LNX 1 // Linux diff --git a/quantum/quantum.c b/quantum/quantum.c index d23a2970e5a7..1fb6a15ac753 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c @@ -256,27 +256,21 @@ bool process_record_quantum(keyrecord_t *record) { #ifdef TAP_DANCE_ENABLE process_tap_dance(keycode, record) && #endif + #if (defined(UNICODE_ENABLE) || defined(UNICODEMAP_ENABLE) || defined(UCIS_ENABLE)) + process_record_unicode_common(keycode, record) && + #endif #ifdef LEADER_ENABLE process_leader(keycode, record) && #endif #ifdef COMBO_ENABLE process_combo(keycode, record) && #endif - #ifdef UNICODE_ENABLE - process_unicode(keycode, record) && - #endif - #ifdef UCIS_ENABLE - process_ucis(keycode, record) && - #endif #ifdef PRINTING_ENABLE process_printer(keycode, record) && #endif #ifdef AUTO_SHIFT_ENABLE process_auto_shift(keycode, record) && #endif - #ifdef UNICODEMAP_ENABLE - process_unicode_map(keycode, record) && - #endif #ifdef TERMINAL_ENABLE process_terminal(keycode, record) && #endif diff --git a/quantum/quantum_keycodes.h b/quantum/quantum_keycodes.h index 7670d53e96cc..a319f5c4b83d 100644 --- a/quantum/quantum_keycodes.h +++ b/quantum/quantum_keycodes.h @@ -456,6 +456,12 @@ enum quantum_keycodes { EEPROM_RESET, + UNI_OSX, + UNI_LINUX, + UNI_WIN, + UNI_WINC, + UNI_OSX_RALT, + // always leave at the end SAFE_RANGE }; From 7761de8585dfcbf2987642115ac79129694584d9 Mon Sep 17 00:00:00 2001 From: Drashna Jaelre Date: Fri, 2 Nov 2018 09:29:24 -0700 Subject: [PATCH 05/42] Add audio feedback to input mode keys to drive konstantin up a wall --- .../process_keycode/process_unicode_common.c | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/quantum/process_keycode/process_unicode_common.c b/quantum/process_keycode/process_unicode_common.c index e8f5001380c3..b69439d7f7e4 100644 --- a/quantum/process_keycode/process_unicode_common.c +++ b/quantum/process_keycode/process_unicode_common.c @@ -21,6 +21,23 @@ unicode_config_t unicode_config; static uint8_t saved_mods; +#ifdef AUDIO_ENABLE + #ifdef UNICODE_LINUX_SONG + float linux_song[][2] = UNICODE_LINUX_SONG; + #endif + #ifdef UNICODE_WINDOWS_SONG + float windows_song[][2] = UNICODE_WINDOWS_SONG; + #endif + #ifdef UNICODE_WIN_COMPOSE_SONG + float win_compose_song[][2] = UNICODE_WIN_COMPOSE_SONG; + #endif + #ifdef UNICODE_OSX_SONG + float osx_song[][2] = UNICODE_OSX_SONG; + #endif + #ifdef UNICODE_OSX_RALT_SONG + float osx_ralt_song[][2] = UNICODE_OSX_RALT_SONG; + #endif +#endif void set_unicode_input_mode(uint8_t os_target) { @@ -138,18 +155,33 @@ bool process_record_unicode_common(uint16_t keycode, keyrecord_t *record) { switch (keycode) { case UNI_OSX: set_unicode_input_mode(UC_OSX); + #if defined(AUDIO_ENABLE) && defined(UNICODE_OSX_SONG) + PLAY_SONG(UNICODE_OSX_SONG); + #endif break; case UNI_LINUX: set_unicode_input_mode(UC_LNX); + #if defined(AUDIO_ENABLE) && defined(UNICODE_LINUX_SONG) + PLAY_SONG(UNICODE_LINUX_SONG); + #endif break; case UNI_WIN: set_unicode_input_mode(UC_WIN); + #if defined(AUDIO_ENABLE) && defined(UNICODE_WINDOWS_SONG) + PLAY_SONG(UNICODE_WINDOWS_SONG); + #endif break; case UNI_WINC: set_unicode_input_mode(UC_WINC); + #if defined(AUDIO_ENABLE) && defined(UNICODE_WIN_COMPOSE_SONG) + PLAY_SONG(UNICODE_WIN_COMPOSE_SONG); + #endif break; case UNI_OSX_RALT: set_unicode_input_mode(UC_OSX_RALT); + #if defined(AUDIO_ENABLE) && defined(UNICODE_OSX_RALT_SONG) + PLAY_SONG(UNICODE_OSX_RALT_SONG); + #endif break; } } From 408a4a664d7bc981e02adc7daf160347da15aa8a Mon Sep 17 00:00:00 2001 From: Drashna Jaelre Date: Fri, 2 Nov 2018 09:35:45 -0700 Subject: [PATCH 06/42] Tap_code cleanup --- .../process_keycode/process_unicode_common.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/quantum/process_keycode/process_unicode_common.c b/quantum/process_keycode/process_unicode_common.c index b69439d7f7e4..254f1a231c7e 100644 --- a/quantum/process_keycode/process_unicode_common.c +++ b/quantum/process_keycode/process_unicode_common.c @@ -68,21 +68,17 @@ void unicode_input_start(void) { case UC_LNX: register_code(KC_LCTL); register_code(KC_LSFT); - register_code(KC_U); - unregister_code(KC_U); + tap_code(KC_U); unregister_code(KC_LSFT); unregister_code(KC_LCTL); break; case UC_WIN: register_code(KC_LALT); - register_code(KC_PPLS); - unregister_code(KC_PPLS); + tap_code(KC_PPLS); break; case UC_WINC: - register_code(KC_RALT); - unregister_code(KC_RALT); - register_code(KC_U); - unregister_code(KC_U); + tap_code(KC_RALT); + tap_code(KC_U); } wait_ms(UNICODE_TYPE_DELAY); } @@ -98,8 +94,7 @@ void unicode_input_finish (void) { unregister_code(KC_RALT); break; case UC_LNX: - register_code(KC_SPC); - unregister_code(KC_SPC); + tap_code(KC_SPC); break; } @@ -120,8 +115,7 @@ uint16_t hex_to_keycode(uint8_t hex) { void register_hex(uint16_t hex) { for(int i = 3; i >= 0; i--) { uint8_t digit = ((hex >> (i*4)) & 0xF); - register_code(hex_to_keycode(digit)); - unregister_code(hex_to_keycode(digit)); + tap_code(hex_to_keycode(digit)); } } From 54027ef22eda8349a362c5b83490dda859892b9b Mon Sep 17 00:00:00 2001 From: Drashna Jaelre Date: Fri, 2 Nov 2018 10:09:45 -0700 Subject: [PATCH 07/42] Update keycodes --- quantum/process_keycode/process_unicode_common.c | 10 +++++----- quantum/quantum_keycodes.h | 16 +++++++++++----- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/quantum/process_keycode/process_unicode_common.c b/quantum/process_keycode/process_unicode_common.c index 254f1a231c7e..a2fe688a302c 100644 --- a/quantum/process_keycode/process_unicode_common.c +++ b/quantum/process_keycode/process_unicode_common.c @@ -147,31 +147,31 @@ void send_unicode_hex_string(const char *str) { bool process_record_unicode_common(uint16_t keycode, keyrecord_t *record) { if (record->event.pressed) { switch (keycode) { - case UNI_OSX: + case UNICODE_MODE_OSX: set_unicode_input_mode(UC_OSX); #if defined(AUDIO_ENABLE) && defined(UNICODE_OSX_SONG) PLAY_SONG(UNICODE_OSX_SONG); #endif break; - case UNI_LINUX: + case UNICODE_MODE_LINUX: set_unicode_input_mode(UC_LNX); #if defined(AUDIO_ENABLE) && defined(UNICODE_LINUX_SONG) PLAY_SONG(UNICODE_LINUX_SONG); #endif break; - case UNI_WIN: + case UNICODE_MODE_WINDOWS: set_unicode_input_mode(UC_WIN); #if defined(AUDIO_ENABLE) && defined(UNICODE_WINDOWS_SONG) PLAY_SONG(UNICODE_WINDOWS_SONG); #endif break; - case UNI_WINC: + case UNICODE_MODE_WIN_COMPOSE: set_unicode_input_mode(UC_WINC); #if defined(AUDIO_ENABLE) && defined(UNICODE_WIN_COMPOSE_SONG) PLAY_SONG(UNICODE_WIN_COMPOSE_SONG); #endif break; - case UNI_OSX_RALT: + case UNICODE_MODE_OSX_RALT: set_unicode_input_mode(UC_OSX_RALT); #if defined(AUDIO_ENABLE) && defined(UNICODE_OSX_RALT_SONG) PLAY_SONG(UNICODE_OSX_RALT_SONG); diff --git a/quantum/quantum_keycodes.h b/quantum/quantum_keycodes.h index a319f5c4b83d..53c42273b5f2 100644 --- a/quantum/quantum_keycodes.h +++ b/quantum/quantum_keycodes.h @@ -456,11 +456,11 @@ enum quantum_keycodes { EEPROM_RESET, - UNI_OSX, - UNI_LINUX, - UNI_WIN, - UNI_WINC, - UNI_OSX_RALT, + UNICODE_MODE_OSX, + UNICODE_MODE_LINUX, + UNICODE_MODE_WINDOWS, + UNICODE_MODE_WIN_COMPOSE, + UNICODE_MODE_OSX_RALT, // always leave at the end SAFE_RANGE @@ -689,6 +689,12 @@ enum quantum_keycodes { #define X(n) (QK_UNICODE_MAP | (n)) #endif +#define UC_M_OS UNICODE_MODE_OSX +#define UC_M_LN UNICODE_MODE_LINUX +#define UC_M_WI UNICODE_MODE_WINDOWS +#define UC_M_WC UNICODE_MODE_WINCOMPOSE +#define UC_M_OR UNICODE_MODE_OSX_RALT + #ifdef SWAP_HANDS_ENABLE #define SH_T(kc) (QK_SWAP_HANDS | (kc)) #define SH_TG (QK_SWAP_HANDS | OP_SH_TOGGLE) From 96f2b081d3239a15781049a7b6c3e497bf543ea8 Mon Sep 17 00:00:00 2001 From: Drashna Jaelre Date: Fri, 2 Nov 2018 10:34:11 -0700 Subject: [PATCH 08/42] Update unicode documentation --- docs/feature_unicode.md | 71 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 69 insertions(+), 2 deletions(-) diff --git a/docs/feature_unicode.md b/docs/feature_unicode.md index c98a4022877f..4a9340b66946 100644 --- a/docs/feature_unicode.md +++ b/docs/feature_unicode.md @@ -80,7 +80,17 @@ void qk_ucis_symbol_fallback (void) { // falls back to manual unicode entry Unicode input in QMK works by inputting a sequence of characters to the OS, 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: +You can set the input method at any time. You can do this by using a keycode here. The Input method is listed next to the keycode for reference. + +|Key |Aliases |Input Method |Description | +|--------------------------|---------|--------------|---------------------------------------------------| +|`UNICODE_MODE_OSX` |`UC_M_OS`|`UC_OSX` |Sets the input method for MacOS X | +|`UNICODE_MODE_LNX` |`UC_M_LN`|`UC_LNX` |Sets the input method for Linux | +|`UNICODE_MODE_WIN` |`UC_M_WI`|`UC_WIN` |Sets the input method for Windows | +|`UNICODE_MODE_WINC` |`UC_M_WC`|`UC_WINC` |Sets the input method for Windows using WinCompose | +|`UNICODE_MODE_OSX_RALT` |`UC_M_OR`|`UC_OSX_RALT` |Sets the input method for MacOS X using RAlt/AltGr | + +You can also set the input method via `set_unicode_input_mode(x)`, and this functions the same way as the keycodes above. * __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. * __UC_OSX_RALT__: Same as UC_OSX, but sends the Right Alt key for unicode input @@ -88,7 +98,64 @@ This is the current list of Unicode input method in QMK: * __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. * __UC_WINC__: Windows Unicode input using WinCompose. Requires [WinCompose](https://github.com/samhocevar/wincompose). Works reliably under many (all?) variations of 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. +?> Keep in mind that both methods write to EEPROM, and are loaded each time the keyboard starts. So you only need to hit this once. + +### Unicode Input Method Customization + +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. + +* `void unicode_input_start(void)` - This is called to start the sequence to input unicode characters. It handles calling RAlt or whatever ever sequence you want. +* `void unicode_input_finish (void)` - This is called to cleanup things, such as releasing the RAlt key in some cases, or tapping a key to finish the sequence. + +The default functions are: + +```c +void unicode_input_start(void) { + saved_mods = get_mods(); // Save current mods + clear_mods(); // Unregister mods to start from a clean state + + switch(unicode_config.input_mode) { + case UC_OSX: + register_code(KC_LALT); + break; + case UC_OSX_RALT: + register_code(KC_RALT); + break; + case UC_LNX: + register_code(KC_LCTL); + register_code(KC_LSFT); + tap_code(KC_U); + unregister_code(KC_LSFT); + unregister_code(KC_LCTL); + break; + case UC_WIN: + register_code(KC_LALT); + tap_code(KC_PPLS); + break; + case UC_WINC: + tap_code(KC_RALT); + tap_code(KC_U); + } + wait_ms(UNICODE_TYPE_DELAY); +} + +void unicode_input_finish (void) { + switch(unicode_config.input_mode) { + case UC_OSX: + case UC_WIN: + unregister_code(KC_LALT); + break; + case UC_OSX_RALT: + unregister_code(KC_RALT); + break; + case UC_LNX: + tap_code(KC_SPC); + break; + } + + set_mods(saved_mods); // Reregister previously set mods +} +``` ## `send_unicode_hex_string` From f2a1e4fb7bb8abb97d49d008ca68759691b41f88 Mon Sep 17 00:00:00 2001 From: Drashna Jaelre Date: Fri, 2 Nov 2018 10:35:48 -0700 Subject: [PATCH 09/42] Update unicode keycodes for consistency/easier merge --- quantum/process_keycode/process_unicode_common.c | 6 +++--- quantum/quantum_keycodes.h | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/quantum/process_keycode/process_unicode_common.c b/quantum/process_keycode/process_unicode_common.c index a2fe688a302c..4782c23bafc3 100644 --- a/quantum/process_keycode/process_unicode_common.c +++ b/quantum/process_keycode/process_unicode_common.c @@ -153,19 +153,19 @@ bool process_record_unicode_common(uint16_t keycode, keyrecord_t *record) { PLAY_SONG(UNICODE_OSX_SONG); #endif break; - case UNICODE_MODE_LINUX: + case UNICODE_MODE_LNX: set_unicode_input_mode(UC_LNX); #if defined(AUDIO_ENABLE) && defined(UNICODE_LINUX_SONG) PLAY_SONG(UNICODE_LINUX_SONG); #endif break; - case UNICODE_MODE_WINDOWS: + case UNICODE_MODE_WIN: set_unicode_input_mode(UC_WIN); #if defined(AUDIO_ENABLE) && defined(UNICODE_WINDOWS_SONG) PLAY_SONG(UNICODE_WINDOWS_SONG); #endif break; - case UNICODE_MODE_WIN_COMPOSE: + case UNICODE_MODE_WINC: set_unicode_input_mode(UC_WINC); #if defined(AUDIO_ENABLE) && defined(UNICODE_WIN_COMPOSE_SONG) PLAY_SONG(UNICODE_WIN_COMPOSE_SONG); diff --git a/quantum/quantum_keycodes.h b/quantum/quantum_keycodes.h index 53c42273b5f2..6e498628d4ef 100644 --- a/quantum/quantum_keycodes.h +++ b/quantum/quantum_keycodes.h @@ -457,9 +457,9 @@ enum quantum_keycodes { EEPROM_RESET, UNICODE_MODE_OSX, - UNICODE_MODE_LINUX, - UNICODE_MODE_WINDOWS, - UNICODE_MODE_WIN_COMPOSE, + UNICODE_MODE_LNX, + UNICODE_MODE_WIN, + UNICODE_MODE_WINC, UNICODE_MODE_OSX_RALT, // always leave at the end @@ -690,9 +690,9 @@ enum quantum_keycodes { #endif #define UC_M_OS UNICODE_MODE_OSX -#define UC_M_LN UNICODE_MODE_LINUX -#define UC_M_WI UNICODE_MODE_WINDOWS -#define UC_M_WC UNICODE_MODE_WINCOMPOSE +#define UC_M_LN UNICODE_MODE_LNX +#define UC_M_WI UNICODE_MODE_WIN +#define UC_M_WC UNICODE_MODE_WINC #define UC_M_OR UNICODE_MODE_OSX_RALT #ifdef SWAP_HANDS_ENABLE From e5f1556befd03d7452e6ab50e8be3dceccde3d38 Mon Sep 17 00:00:00 2001 From: Drashna Jaelre Date: Fri, 2 Nov 2018 10:44:09 -0700 Subject: [PATCH 10/42] Add Audio Feedback section --- docs/feature_unicode.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/docs/feature_unicode.md b/docs/feature_unicode.md index 4a9340b66946..935ce78bb74d 100644 --- a/docs/feature_unicode.md +++ b/docs/feature_unicode.md @@ -100,6 +100,20 @@ You can also set the input method via `set_unicode_input_mode(x)`, and this func ?> Keep in mind that both methods write to EEPROM, and are loaded each time the keyboard starts. So you only need to hit this once. +### Audio Feedback for Input Mode keycodes + +If you have the [Audio feature](feature_audio.md) enabled on the board, you can set "songs" for them to play when pressed, so you have some audio feedback when switching modes. + +For instance, you can add these to your `config.h` file. + +```c +#define UNICODE_LINUX_SONG UNICODE_LINUX +#define UNICODE_WINDOWS_SONG UNICODE_WINDOWS +#define UNICODE_WIN_COMPOSE_SONG UNICODE_WINDOWS +#define UNICODE_OSX_SONG COIN_SOUND +#define UNICODE_OSX_RALT_SONGCOIN_SOUND +``` + ### Unicode Input Method Customization 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. From 635e6e8fa4fdcb84c835ced3480162bdc7e0c73a Mon Sep 17 00:00:00 2001 From: Drashna Jaelre Date: Fri, 2 Nov 2018 12:43:43 -0700 Subject: [PATCH 11/42] Remove Functions from feature page And link to the file instead. Link to specific lines later on. --- docs/feature_unicode.md | 51 ++--------------------------------------- 1 file changed, 2 insertions(+), 49 deletions(-) diff --git a/docs/feature_unicode.md b/docs/feature_unicode.md index 935ce78bb74d..d93d4622af4d 100644 --- a/docs/feature_unicode.md +++ b/docs/feature_unicode.md @@ -118,58 +118,11 @@ For instance, you can add these to your `config.h` file. 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. -* `void unicode_input_start(void)` - This is called to start the sequence to input unicode characters. It handles calling RAlt or whatever ever sequence you want. +* `void unicode_input_start(void)` - This is called to start the sequence to input unicode characters. It handles calling RAlt or whatever ever sequence you want. * `void unicode_input_finish (void)` - This is called to cleanup things, such as releasing the RAlt key in some cases, or tapping a key to finish the sequence. -The default functions are: +You can find the default functions in [`process_unicode_common.c`](https://github.com/qmk/qmk_firmware/blob/master/quantum/process_keycode/process_unicode_common.c). -```c -void unicode_input_start(void) { - saved_mods = get_mods(); // Save current mods - clear_mods(); // Unregister mods to start from a clean state - - switch(unicode_config.input_mode) { - case UC_OSX: - register_code(KC_LALT); - break; - case UC_OSX_RALT: - register_code(KC_RALT); - break; - case UC_LNX: - register_code(KC_LCTL); - register_code(KC_LSFT); - tap_code(KC_U); - unregister_code(KC_LSFT); - unregister_code(KC_LCTL); - break; - case UC_WIN: - register_code(KC_LALT); - tap_code(KC_PPLS); - break; - case UC_WINC: - tap_code(KC_RALT); - tap_code(KC_U); - } - wait_ms(UNICODE_TYPE_DELAY); -} - -void unicode_input_finish (void) { - switch(unicode_config.input_mode) { - case UC_OSX: - case UC_WIN: - unregister_code(KC_LALT); - break; - case UC_OSX_RALT: - unregister_code(KC_RALT); - break; - case UC_LNX: - tap_code(KC_SPC); - break; - } - - set_mods(saved_mods); // Reregister previously set mods -} -``` ## `send_unicode_hex_string` From c17df17173b9d9f6464f908fe01c4f031e5afff1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20=C4=90or=C4=91evi=C4=87?= Date: Fri, 2 Nov 2018 12:45:19 -0700 Subject: [PATCH 12/42] Fix spacing Co-Authored-By: drashna --- quantum/process_keycode/process_unicode_common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/quantum/process_keycode/process_unicode_common.c b/quantum/process_keycode/process_unicode_common.c index 4782c23bafc3..ed20efacac0d 100644 --- a/quantum/process_keycode/process_unicode_common.c +++ b/quantum/process_keycode/process_unicode_common.c @@ -50,7 +50,7 @@ uint8_t get_unicode_input_mode(void) { } void unicode_input_mode_init(void) { - unicode_config.raw = eeprom_read_byte(EECONFIG_UNICODEMODE); + unicode_config.raw = eeprom_read_byte(EECONFIG_UNICODEMODE); } __attribute__((weak)) From 3edc7fcc6483dc0c1dea45d212468cac62c8891d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20=C4=90or=C4=91evi=C4=87?= Date: Fri, 2 Nov 2018 12:45:48 -0700 Subject: [PATCH 13/42] Because I missed it! Co-Authored-By: drashna --- quantum/process_keycode/process_unicode_common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/quantum/process_keycode/process_unicode_common.c b/quantum/process_keycode/process_unicode_common.c index ed20efacac0d..950a45d44e2c 100644 --- a/quantum/process_keycode/process_unicode_common.c +++ b/quantum/process_keycode/process_unicode_common.c @@ -88,7 +88,7 @@ void unicode_input_finish (void) { switch(unicode_config.input_mode) { case UC_OSX: case UC_WIN: - unregister_code(KC_LALT); + unregister_code(KC_LALT); break; case UC_OSX_RALT: unregister_code(KC_RALT); From 8be5b249f440b1d8ac456e1fbf6703b242acd564 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20=C4=90or=C4=91evi=C4=87?= Date: Fri, 2 Nov 2018 12:46:04 -0700 Subject: [PATCH 14/42] Fix spacing Co-Authored-By: drashna --- quantum/process_keycode/process_unicode_common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/quantum/process_keycode/process_unicode_common.c b/quantum/process_keycode/process_unicode_common.c index 950a45d44e2c..71673015e061 100644 --- a/quantum/process_keycode/process_unicode_common.c +++ b/quantum/process_keycode/process_unicode_common.c @@ -148,7 +148,7 @@ bool process_record_unicode_common(uint16_t keycode, keyrecord_t *record) { if (record->event.pressed) { switch (keycode) { case UNICODE_MODE_OSX: - set_unicode_input_mode(UC_OSX); + set_unicode_input_mode(UC_OSX); #if defined(AUDIO_ENABLE) && defined(UNICODE_OSX_SONG) PLAY_SONG(UNICODE_OSX_SONG); #endif From dd152490fcba5317401ea8bd3b7a7c6aeaa6266c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20=C4=90or=C4=91evi=C4=87?= Date: Fri, 2 Nov 2018 12:46:19 -0700 Subject: [PATCH 15/42] SPAAAAAAAAAACing Co-Authored-By: drashna --- quantum/process_keycode/process_unicode_common.h | 1 - 1 file changed, 1 deletion(-) diff --git a/quantum/process_keycode/process_unicode_common.h b/quantum/process_keycode/process_unicode_common.h index b1fc8c0ac834..6d3e08048373 100644 --- a/quantum/process_keycode/process_unicode_common.h +++ b/quantum/process_keycode/process_unicode_common.h @@ -30,7 +30,6 @@ typedef union { }; } unicode_config_t; - void set_unicode_input_mode(uint8_t os_target); uint8_t get_unicode_input_mode(void); void unicode_input_mode_init(void); From b728cd82044e8038b00709dbd539be99734506a2 Mon Sep 17 00:00:00 2001 From: Drashna Jaelre Date: Fri, 2 Nov 2018 12:47:48 -0700 Subject: [PATCH 16/42] Add BSD for future compatibility --- quantum/quantum_keycodes.h | 1 + 1 file changed, 1 insertion(+) diff --git a/quantum/quantum_keycodes.h b/quantum/quantum_keycodes.h index 6e498628d4ef..ffa087496c1c 100644 --- a/quantum/quantum_keycodes.h +++ b/quantum/quantum_keycodes.h @@ -458,6 +458,7 @@ enum quantum_keycodes { UNICODE_MODE_OSX, UNICODE_MODE_LNX, + UNICODE_MODE_BSD, UNICODE_MODE_WIN, UNICODE_MODE_WINC, UNICODE_MODE_OSX_RALT, From 056b008a579eac9b9411fd99d788afb125066d65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20=C4=90or=C4=91evi=C4=87?= Date: Fri, 2 Nov 2018 12:48:01 -0700 Subject: [PATCH 17/42] Thought I fixed that! Co-Authored-By: drashna --- quantum/process_keycode/process_unicode_common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/quantum/process_keycode/process_unicode_common.c b/quantum/process_keycode/process_unicode_common.c index 71673015e061..4609468fc20d 100644 --- a/quantum/process_keycode/process_unicode_common.c +++ b/quantum/process_keycode/process_unicode_common.c @@ -84,7 +84,7 @@ void unicode_input_start(void) { } __attribute__((weak)) -void unicode_input_finish (void) { + void unicode_input_finish(void) { switch(unicode_config.input_mode) { case UC_OSX: case UC_WIN: From 91cdefc33143ffe7845828b84c57c78bc1aab8a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20=C4=90or=C4=91evi=C4=87?= Date: Fri, 2 Nov 2018 12:48:28 -0700 Subject: [PATCH 18/42] non-breaking Co-Authored-By: drashna --- quantum/process_keycode/process_unicode_common.c | 1 + 1 file changed, 1 insertion(+) diff --git a/quantum/process_keycode/process_unicode_common.c b/quantum/process_keycode/process_unicode_common.c index 4609468fc20d..f27e77c52f23 100644 --- a/quantum/process_keycode/process_unicode_common.c +++ b/quantum/process_keycode/process_unicode_common.c @@ -79,6 +79,7 @@ void unicode_input_start(void) { case UC_WINC: tap_code(KC_RALT); tap_code(KC_U); + break; } wait_ms(UNICODE_TYPE_DELAY); } From bd34276414ee11c5c56a9fff9eba61c92929fc81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20=C4=90or=C4=91evi=C4=87?= Date: Fri, 2 Nov 2018 12:48:43 -0700 Subject: [PATCH 19/42] Considered that Co-Authored-By: drashna --- docs/feature_unicode.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/feature_unicode.md b/docs/feature_unicode.md index d93d4622af4d..d0105d5d0cf9 100644 --- a/docs/feature_unicode.md +++ b/docs/feature_unicode.md @@ -107,7 +107,7 @@ If you have the [Audio feature](feature_audio.md) enabled on the board, you can For instance, you can add these to your `config.h` file. ```c -#define UNICODE_LINUX_SONG UNICODE_LINUX +#define UNICODE_SONG_LNX UNICODE_LINUX #define UNICODE_WINDOWS_SONG UNICODE_WINDOWS #define UNICODE_WIN_COMPOSE_SONG UNICODE_WINDOWS #define UNICODE_OSX_SONG COIN_SOUND From 6e2a0447fbeae77854a847d20110442723be2668 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20=C4=90or=C4=91evi=C4=87?= Date: Fri, 2 Nov 2018 12:48:51 -0700 Subject: [PATCH 20/42] Yuuup Co-Authored-By: drashna --- quantum/process_keycode/process_unicode_common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/quantum/process_keycode/process_unicode_common.c b/quantum/process_keycode/process_unicode_common.c index f27e77c52f23..7363a761f819 100644 --- a/quantum/process_keycode/process_unicode_common.c +++ b/quantum/process_keycode/process_unicode_common.c @@ -22,7 +22,7 @@ unicode_config_t unicode_config; static uint8_t saved_mods; #ifdef AUDIO_ENABLE - #ifdef UNICODE_LINUX_SONG + #ifdef UNICODE_SONG_LNX float linux_song[][2] = UNICODE_LINUX_SONG; #endif #ifdef UNICODE_WINDOWS_SONG From 053193b9ad640614684df6ee561321870b919582 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20=C4=90or=C4=91evi=C4=87?= Date: Fri, 2 Nov 2018 12:49:00 -0700 Subject: [PATCH 21/42] consistency Co-Authored-By: drashna --- quantum/process_keycode/process_unicode_common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/quantum/process_keycode/process_unicode_common.c b/quantum/process_keycode/process_unicode_common.c index 7363a761f819..0741ab003000 100644 --- a/quantum/process_keycode/process_unicode_common.c +++ b/quantum/process_keycode/process_unicode_common.c @@ -23,7 +23,7 @@ unicode_config_t unicode_config; static uint8_t saved_mods; #ifdef AUDIO_ENABLE #ifdef UNICODE_SONG_LNX - float linux_song[][2] = UNICODE_LINUX_SONG; + float song_lnx[][2] = UNICODE_SONG_LNX; #endif #ifdef UNICODE_WINDOWS_SONG float windows_song[][2] = UNICODE_WINDOWS_SONG; From f3563196dfb76dcbf84d3cfeb3e1587ad3595694 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20=C4=90or=C4=91evi=C4=87?= Date: Fri, 2 Nov 2018 12:49:27 -0700 Subject: [PATCH 22/42] white spaces .... copied from elsewhere Co-Authored-By: drashna --- quantum/process_keycode/process_unicode_common.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/quantum/process_keycode/process_unicode_common.h b/quantum/process_keycode/process_unicode_common.h index 6d3e08048373..8716b8bc5659 100644 --- a/quantum/process_keycode/process_unicode_common.h +++ b/quantum/process_keycode/process_unicode_common.h @@ -26,7 +26,7 @@ typedef union { uint32_t raw; struct { - uint8_t input_mode :8; + uint8_t input_mode :8; }; } unicode_config_t; From 9b20bbbfe9eab265fe00ac4e7990aa0b1eb7daf3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20=C4=90or=C4=91evi=C4=87?= Date: Fri, 2 Nov 2018 12:50:39 -0700 Subject: [PATCH 23/42] white spaces Co-Authored-By: drashna --- quantum/process_keycode/process_unicode_common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/quantum/process_keycode/process_unicode_common.c b/quantum/process_keycode/process_unicode_common.c index 0741ab003000..1c8a723e2cf0 100644 --- a/quantum/process_keycode/process_unicode_common.c +++ b/quantum/process_keycode/process_unicode_common.c @@ -58,7 +58,7 @@ void unicode_input_start(void) { saved_mods = get_mods(); // Save current mods clear_mods(); // Unregister mods to start from a clean state - switch(unicode_config.input_mode) { + switch (unicode_config.input_mode) { case UC_OSX: register_code(KC_LALT); break; From c7ff865e87446f4a989ea1a41fecc81c5ce981bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20=C4=90or=C4=91evi=C4=87?= Date: Fri, 2 Nov 2018 12:50:51 -0700 Subject: [PATCH 24/42] white spaces Co-Authored-By: drashna --- quantum/process_keycode/process_unicode_common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/quantum/process_keycode/process_unicode_common.c b/quantum/process_keycode/process_unicode_common.c index 1c8a723e2cf0..a329bf451479 100644 --- a/quantum/process_keycode/process_unicode_common.c +++ b/quantum/process_keycode/process_unicode_common.c @@ -86,7 +86,7 @@ void unicode_input_start(void) { __attribute__((weak)) void unicode_input_finish(void) { - switch(unicode_config.input_mode) { + switch (unicode_config.input_mode) { case UC_OSX: case UC_WIN: unregister_code(KC_LALT); From 789898742a3cb37de4484f1207e4758e59698ee0 Mon Sep 17 00:00:00 2001 From: Drashna Jaelre Date: Fri, 2 Nov 2018 12:52:04 -0700 Subject: [PATCH 25/42] Update keycode defines --- quantum/quantum_keycodes.h | 1 + 1 file changed, 1 insertion(+) diff --git a/quantum/quantum_keycodes.h b/quantum/quantum_keycodes.h index ffa087496c1c..ee5aea1579d5 100644 --- a/quantum/quantum_keycodes.h +++ b/quantum/quantum_keycodes.h @@ -692,6 +692,7 @@ enum quantum_keycodes { #define UC_M_OS UNICODE_MODE_OSX #define UC_M_LN UNICODE_MODE_LNX +#define UC_M_BD UNICODE_MODE_BSD #define UC_M_WI UNICODE_MODE_WIN #define UC_M_WC UNICODE_MODE_WINC #define UC_M_OR UNICODE_MODE_OSX_RALT From 02ea07d212d0269f3ad27625b4b6040c18a51d76 Mon Sep 17 00:00:00 2001 From: Drashna Jaelre Date: Fri, 2 Nov 2018 12:52:56 -0700 Subject: [PATCH 26/42] Fix Linux Song --- quantum/process_keycode/process_unicode_common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/quantum/process_keycode/process_unicode_common.c b/quantum/process_keycode/process_unicode_common.c index a329bf451479..f70d2b2f2f37 100644 --- a/quantum/process_keycode/process_unicode_common.c +++ b/quantum/process_keycode/process_unicode_common.c @@ -157,7 +157,7 @@ bool process_record_unicode_common(uint16_t keycode, keyrecord_t *record) { case UNICODE_MODE_LNX: set_unicode_input_mode(UC_LNX); #if defined(AUDIO_ENABLE) && defined(UNICODE_LINUX_SONG) - PLAY_SONG(UNICODE_LINUX_SONG); + PLAY_SONG(song_lnx); #endif break; case UNICODE_MODE_WIN: From dc35a4a72f671139f6e31d19cd9f5fdb519fe603 Mon Sep 17 00:00:00 2001 From: Drashna Jaelre Date: Fri, 2 Nov 2018 12:57:04 -0700 Subject: [PATCH 27/42] Update all of the songs --- .../process_keycode/process_unicode_common.c | 43 +++++++++++-------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/quantum/process_keycode/process_unicode_common.c b/quantum/process_keycode/process_unicode_common.c index f70d2b2f2f37..0f79e42c487c 100644 --- a/quantum/process_keycode/process_unicode_common.c +++ b/quantum/process_keycode/process_unicode_common.c @@ -22,20 +22,23 @@ unicode_config_t unicode_config; static uint8_t saved_mods; #ifdef AUDIO_ENABLE + #ifdef UNICODE_SONG_OSX + float osx_song[][2] = UNICODE_SONG_OSX; + #endif #ifdef UNICODE_SONG_LNX float song_lnx[][2] = UNICODE_SONG_LNX; #endif - #ifdef UNICODE_WINDOWS_SONG - float windows_song[][2] = UNICODE_WINDOWS_SONG; + #ifdef UNICODE_SONG_BSD + float song_bsd[][2] = UNICODE_SONG_BSD; #endif - #ifdef UNICODE_WIN_COMPOSE_SONG - float win_compose_song[][2] = UNICODE_WIN_COMPOSE_SONG; + #ifdef UNICODE_SONG_WINDOWS + float windows_song[][2] = UNICODE_SONG_WINDOWS; #endif - #ifdef UNICODE_OSX_SONG - float osx_song[][2] = UNICODE_OSX_SONG; + #ifdef UNICODE_SONG_WIN_COMPOSE + float win_compose_song[][2] = UNICODE_SONG_WIN_COMPOSE; #endif - #ifdef UNICODE_OSX_RALT_SONG - float osx_ralt_song[][2] = UNICODE_OSX_RALT_SONG; + #ifdef UNICODE_SONG_OSX_RALT + float osx_ralt_song[][2] = UNICODE_SONG_OSX_RALT; #endif #endif @@ -150,32 +153,38 @@ bool process_record_unicode_common(uint16_t keycode, keyrecord_t *record) { switch (keycode) { case UNICODE_MODE_OSX: set_unicode_input_mode(UC_OSX); - #if defined(AUDIO_ENABLE) && defined(UNICODE_OSX_SONG) - PLAY_SONG(UNICODE_OSX_SONG); + #if defined(AUDIO_ENABLE) && defined(UNICODE_SONG_OSX) + PLAY_SONG(osx_song); #endif break; case UNICODE_MODE_LNX: set_unicode_input_mode(UC_LNX); - #if defined(AUDIO_ENABLE) && defined(UNICODE_LINUX_SONG) + #if defined(AUDIO_ENABLE) && defined(UNICODE_SONG_LNX) PLAY_SONG(song_lnx); #endif break; + case UNICODE_MODE_BSD: + set_unicode_input_mode(UC_BSD); + #if defined(AUDIO_ENABLE) && defined(UNICODE_SONG_BSD) + PLAY_SONG(song_bsd); + #endif + break; case UNICODE_MODE_WIN: set_unicode_input_mode(UC_WIN); - #if defined(AUDIO_ENABLE) && defined(UNICODE_WINDOWS_SONG) - PLAY_SONG(UNICODE_WINDOWS_SONG); + #if defined(AUDIO_ENABLE) && defined(UNICODE_SONG_WINDOWS) + PLAY_SONG(windows_song); #endif break; case UNICODE_MODE_WINC: set_unicode_input_mode(UC_WINC); - #if defined(AUDIO_ENABLE) && defined(UNICODE_WIN_COMPOSE_SONG) - PLAY_SONG(UNICODE_WIN_COMPOSE_SONG); + #if defined(AUDIO_ENABLE) && defined(UNICODE_SONG_WIN_COMPOSE) + PLAY_SONG(win_compose_song); #endif break; case UNICODE_MODE_OSX_RALT: set_unicode_input_mode(UC_OSX_RALT); - #if defined(AUDIO_ENABLE) && defined(UNICODE_OSX_RALT_SONG) - PLAY_SONG(UNICODE_OSX_RALT_SONG); + #if defined(AUDIO_ENABLE) && defined(UNICODE_SONG_OSX_RALT) + PLAY_SONG(osx_ralt_song); #endif break; } From 8e0ec8fa7d0b824cf1ac8accf36fe8d1e242cec5 Mon Sep 17 00:00:00 2001 From: Drashna Jaelre Date: Fri, 2 Nov 2018 13:29:23 -0700 Subject: [PATCH 28/42] Cleanup --- quantum/process_keycode/process_ucis.h | 5 +---- quantum/process_keycode/process_unicode.h | 5 +---- quantum/process_keycode/process_unicode_common.c | 2 +- quantum/process_keycode/process_unicode_common.h | 7 +++---- quantum/process_keycode/process_unicodemap.h | 4 +--- 5 files changed, 7 insertions(+), 16 deletions(-) diff --git a/quantum/process_keycode/process_ucis.h b/quantum/process_keycode/process_ucis.h index d4aa34cde73a..b114d839ab8d 100644 --- a/quantum/process_keycode/process_ucis.h +++ b/quantum/process_keycode/process_ucis.h @@ -14,8 +14,7 @@ * along with this program. If not, see . */ -#ifndef PROCESS_UCIS_H -#define PROCESS_UCIS_H +#pragma once #include "quantum.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 register_ucis(const char *hex); bool process_ucis (uint16_t keycode, keyrecord_t *record); - -#endif diff --git a/quantum/process_keycode/process_unicode.h b/quantum/process_keycode/process_unicode.h index c525b74f03fe..0913e991075c 100644 --- a/quantum/process_keycode/process_unicode.h +++ b/quantum/process_keycode/process_unicode.h @@ -13,12 +13,9 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -#ifndef PROCESS_UNICODE_H -#define PROCESS_UNICODE_H +#pragma once #include "quantum.h" #include "process_unicode_common.h" bool process_unicode(uint16_t keycode, keyrecord_t *record); - -#endif diff --git a/quantum/process_keycode/process_unicode_common.c b/quantum/process_keycode/process_unicode_common.c index 0f79e42c487c..1adf70eaa004 100644 --- a/quantum/process_keycode/process_unicode_common.c +++ b/quantum/process_keycode/process_unicode_common.c @@ -88,7 +88,7 @@ void unicode_input_start(void) { } __attribute__((weak)) - void unicode_input_finish(void) { +void unicode_input_finish(void) { switch (unicode_config.input_mode) { case UC_OSX: case UC_WIN: diff --git a/quantum/process_keycode/process_unicode_common.h b/quantum/process_keycode/process_unicode_common.h index 8716b8bc5659..54f867a4998a 100644 --- a/quantum/process_keycode/process_unicode_common.h +++ b/quantum/process_keycode/process_unicode_common.h @@ -14,8 +14,7 @@ * along with this program. If not, see . */ -#ifndef PROCESS_UNICODE_COMMON_H -#define PROCESS_UNICODE_COMMON_H +#pragma once #include "quantum.h" @@ -30,6 +29,8 @@ typedef union { }; } 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); @@ -152,5 +153,3 @@ bool process_record_unicode_common(uint16_t keycode, keyrecord_t *record); #define UC_RCBR UC(0x007D) #define UC_TILD UC(0x007E) #define UC_DEL UC(0x007F) - -#endif diff --git a/quantum/process_keycode/process_unicodemap.h b/quantum/process_keycode/process_unicodemap.h index 929c88c0b616..f6d64bb86b02 100644 --- a/quantum/process_keycode/process_unicodemap.h +++ b/quantum/process_keycode/process_unicodemap.h @@ -14,12 +14,10 @@ * along with this program. If not, see . */ -#ifndef PROCESS_UNICODEMAP_H -#define PROCESS_UNICODEMAP_H +#pragma once #include "quantum.h" #include "process_unicode_common.h" void unicode_map_input_error(void); bool process_unicode_map(uint16_t keycode, keyrecord_t *record); -#endif From de8b38ee31b65a98d8cb5fe3d1371b6a011c528b Mon Sep 17 00:00:00 2001 From: Drashna Jaelre Date: Fri, 2 Nov 2018 13:39:07 -0700 Subject: [PATCH 29/42] Move and update check to ensure only one unicode method is enabled --- quantum/process_keycode/process_unicode_common.h | 4 ++++ quantum/quantum_keycodes.h | 3 --- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/quantum/process_keycode/process_unicode_common.h b/quantum/process_keycode/process_unicode_common.h index 54f867a4998a..8a1f809eb7aa 100644 --- a/quantum/process_keycode/process_unicode_common.h +++ b/quantum/process_keycode/process_unicode_common.h @@ -18,6 +18,10 @@ #include "quantum.h" +#if defined(UNICODE_ENABLE) + defined(UNICODEMAP_ENABLE) + defined(UCIS_ENABLE) > 1 + #error "Cannot enable more than one unicode method (UNICODE, UNICODEMAP, UCIS) at the same time" +#endif + #ifndef UNICODE_TYPE_DELAY #define UNICODE_TYPE_DELAY 10 #endif diff --git a/quantum/quantum_keycodes.h b/quantum/quantum_keycodes.h index ee5aea1579d5..e55568c1d1e2 100644 --- a/quantum/quantum_keycodes.h +++ b/quantum/quantum_keycodes.h @@ -81,9 +81,6 @@ enum quantum_keycodes { #endif QK_MOD_TAP = 0x6000, QK_MOD_TAP_MAX = 0x7FFF, -#if defined(UNICODEMAP_ENABLE) && defined(UNICODE_ENABLE) - #error "Cannot enable both UNICODEMAP && UNICODE" -#endif #ifdef UNICODE_ENABLE QK_UNICODE = 0x8000, QK_UNICODE_MAX = 0xFFFF, From 6f1c31fa3f38d5d0b6fb1d3fda4aa021cfc375a8 Mon Sep 17 00:00:00 2001 From: Drashna Jaelre Date: Fri, 2 Nov 2018 13:41:48 -0700 Subject: [PATCH 30/42] Update quantum/quantum_keycodes.h --- quantum/quantum_keycodes.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/quantum/quantum_keycodes.h b/quantum/quantum_keycodes.h index e55568c1d1e2..c7f642353759 100644 --- a/quantum/quantum_keycodes.h +++ b/quantum/quantum_keycodes.h @@ -689,7 +689,7 @@ enum quantum_keycodes { #define UC_M_OS UNICODE_MODE_OSX #define UC_M_LN UNICODE_MODE_LNX -#define UC_M_BD UNICODE_MODE_BSD +#define UC_M_BS UNICODE_MODE_BSD #define UC_M_WI UNICODE_MODE_WIN #define UC_M_WC UNICODE_MODE_WINC #define UC_M_OR UNICODE_MODE_OSX_RALT From 65cfcf93be1d77cd02794f34c722f009288d0b3c Mon Sep 17 00:00:00 2001 From: Drashna Jaelre Date: Fri, 2 Nov 2018 13:44:53 -0700 Subject: [PATCH 31/42] Update documentation --- docs/feature_unicode.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/docs/feature_unicode.md b/docs/feature_unicode.md index d0105d5d0cf9..cc4b81794b86 100644 --- a/docs/feature_unicode.md +++ b/docs/feature_unicode.md @@ -100,6 +100,8 @@ You can also set the input method via `set_unicode_input_mode(x)`, and this func ?> Keep in mind that both methods write to EEPROM, and are loaded each time the keyboard starts. So you only need to hit this once. +!> There are options for BSD, but it is not actually supported at this time. If you use BSD and want support for this, please [open an issue on GitHub](https://github.com/qmk/qmk_firmware/issues) + ### Audio Feedback for Input Mode keycodes If you have the [Audio feature](feature_audio.md) enabled on the board, you can set "songs" for them to play when pressed, so you have some audio feedback when switching modes. @@ -107,11 +109,11 @@ If you have the [Audio feature](feature_audio.md) enabled on the board, you can For instance, you can add these to your `config.h` file. ```c +#define UNICODE_SONG_OSX COIN_SOUND #define UNICODE_SONG_LNX UNICODE_LINUX -#define UNICODE_WINDOWS_SONG UNICODE_WINDOWS -#define UNICODE_WIN_COMPOSE_SONG UNICODE_WINDOWS -#define UNICODE_OSX_SONG COIN_SOUND -#define UNICODE_OSX_RALT_SONGCOIN_SOUND +#define UNICODE_SONG_WINDOWS UNICODE_WINDOWS +#define UNICODE_SONG_WIN_COMPOSE UNICODE_WINDOWS +#define UNICODE_SONG_OSX_RALT COIN_SOUND ``` ### Unicode Input Method Customization From 662d3ffd3c137e9dd239f6bbaab780d5686488e7 Mon Sep 17 00:00:00 2001 From: Drashna Jaelre Date: Sat, 3 Nov 2018 09:22:46 -0700 Subject: [PATCH 32/42] Wordsmithing and cleanup --- docs/feature_unicode.md | 58 ++++++++++--------- .../process_keycode/process_unicode_common.c | 30 +++++----- .../process_keycode/process_unicode_common.h | 2 +- quantum/quantum.c | 2 +- quantum/quantum_keycodes.h | 4 +- 5 files changed, 52 insertions(+), 44 deletions(-) diff --git a/docs/feature_unicode.md b/docs/feature_unicode.md index cc4b81794b86..32ea7d344b45 100644 --- a/docs/feature_unicode.md +++ b/docs/feature_unicode.md @@ -13,16 +13,16 @@ Supports Unicode up to 0xFFFFFFFF. You need to maintain a separate 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: ```c -enum unicode_name { +enum unicode_names { BANG, // โ€ฝ IRONY, // โธฎ SNEK // snke ๐Ÿ }; const uint32_t PROGMEM unicode_map[] = { - [BANG] = 0x0203D, // โ€ฝ - [IRONY] = 0x02E2E, // โธฎ - [SNEK] = 0x1F40D // snke ๐Ÿ + [BANG] = 0x0203D, // โ€ฝ + [IRONY] = 0x02E2E, // โธฎ + [SNEK] = 0x1F40D // snke ๐Ÿ }: ``` @@ -75,44 +75,50 @@ void qk_ucis_symbol_fallback (void) { // falls back to manual unicode entry } ``` -## Unicode Input methods +## Input Modes -Unicode input in QMK works by inputting a sequence of characters to the OS, -sort of like macro. Unfortunately, each OS has different ideas on how Unicode is input. +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. -You can set the input method at any time. You can do this by using a keycode here. The Input method is listed next to the keycode for reference. +There are two ways to set the input mode for Unicode, by keycode or by function. + +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. + +!> 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) -|Key |Aliases |Input Method |Description | -|--------------------------|---------|--------------|---------------------------------------------------| -|`UNICODE_MODE_OSX` |`UC_M_OS`|`UC_OSX` |Sets the input method for MacOS X | -|`UNICODE_MODE_LNX` |`UC_M_LN`|`UC_LNX` |Sets the input method for Linux | -|`UNICODE_MODE_WIN` |`UC_M_WI`|`UC_WIN` |Sets the input method for Windows | -|`UNICODE_MODE_WINC` |`UC_M_WC`|`UC_WINC` |Sets the input method for Windows using WinCompose | -|`UNICODE_MODE_OSX_RALT` |`UC_M_OR`|`UC_OSX_RALT` |Sets the input method for MacOS X using RAlt/AltGr | -You can also set the input method via `set_unicode_input_mode(x)`, and this functions the same way as the keycodes above. +### Functions + +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. * __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. * __UC_OSX_RALT__: Same as UC_OSX, but sends the Right Alt key for unicode input * __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. +* __UC_BSD__: (non operational) Unicode input method under BSD. * __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. * __UC_WINC__: Windows Unicode input using WinCompose. Requires [WinCompose](https://github.com/samhocevar/wincompose). Works reliably under many (all?) variations of Windows. -?> Keep in mind that both methods write to EEPROM, and are loaded each time the keyboard starts. So you only need to hit this once. - -!> There are options for BSD, but it is not actually supported at this time. If you use BSD and want support for this, please [open an issue on GitHub](https://github.com/qmk/qmk_firmware/issues) +### Keycodes +|Key |Aliases |Input Method |Description | +|--------------------------|---------|--------------|---------------------------------------------------| +|`UNICODE_MODE_OSX` |`UC_M_OS`|`UC_OSX` |Sets the input method for MacOS X | +|`UNICODE_MODE_LNX` |`UC_M_LN`|`UC_LNX` |Sets the input method for Linux | +|`UNICODE_MODE_BSD` |`UC_M_BS`|`UC_BSD` |Sets the input method for BSD (Non-Operational) | +|`UNICODE_MODE_WIN` |`UC_M_WI`|`UC_WIN` |Sets the input method for Windows | +|`UNICODE_MODE_WINC` |`UC_M_WC`|`UC_WINC` |Sets the input method for Windows using WinCompose | +|`UNICODE_MODE_OSX_RALT` |`UC_M_OR`|`UC_OSX_RALT` |Sets the input method for MacOS X using RAlt/AltGr | ### Audio Feedback for Input Mode keycodes -If you have the [Audio feature](feature_audio.md) enabled on the board, you can set "songs" for them to play when pressed, so you have some audio feedback when switching modes. +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. For instance, you can add these to your `config.h` file. ```c -#define UNICODE_SONG_OSX COIN_SOUND +#define UNICODE_SONG_OSX COIN_SOUND #define UNICODE_SONG_LNX UNICODE_LINUX -#define UNICODE_SONG_WINDOWS UNICODE_WINDOWS -#define UNICODE_SONG_WIN_COMPOSE UNICODE_WINDOWS +#define UNICODE_SONG_BSD MARIO_GAMEOVER +#define UNICODE_SONG_WIN UNICODE_WINDOWS +#define UNICODE_SONG_WINC UNICODE_WINDOWS #define UNICODE_SONG_OSX_RALT COIN_SOUND ``` @@ -120,10 +126,10 @@ For instance, you can add these to your `config.h` file. 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. -* `void unicode_input_start(void)` - This is called to start the sequence to input unicode characters. It handles calling RAlt or whatever ever sequence you want. -* `void unicode_input_finish (void)` - This is called to cleanup things, such as releasing the RAlt key in some cases, or tapping a key to finish the sequence. +* `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)` - his is called to exit Unicode input mode, for example by pressing Space or releasing the Option key. -You can find the default functions in [`process_unicode_common.c`](https://github.com/qmk/qmk_firmware/blob/master/quantum/process_keycode/process_unicode_common.c). +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). ## `send_unicode_hex_string` diff --git a/quantum/process_keycode/process_unicode_common.c b/quantum/process_keycode/process_unicode_common.c index 1adf70eaa004..65afc3785995 100644 --- a/quantum/process_keycode/process_unicode_common.c +++ b/quantum/process_keycode/process_unicode_common.c @@ -28,14 +28,14 @@ static uint8_t saved_mods; #ifdef UNICODE_SONG_LNX float song_lnx[][2] = UNICODE_SONG_LNX; #endif + #ifdef UNICODE_SONG_WIN + float windows_song[][2] = UNICODE_SONG_WIN; + #endif #ifdef UNICODE_SONG_BSD float song_bsd[][2] = UNICODE_SONG_BSD; #endif - #ifdef UNICODE_SONG_WINDOWS - float windows_song[][2] = UNICODE_SONG_WINDOWS; - #endif - #ifdef UNICODE_SONG_WIN_COMPOSE - float win_compose_song[][2] = UNICODE_SONG_WIN_COMPOSE; + #ifdef UNICODE_SONG_WINC + float win_compose_song[][2] = UNICODE_SONG_WINC; #endif #ifdef UNICODE_SONG_OSX_RALT float osx_ralt_song[][2] = UNICODE_SONG_OSX_RALT; @@ -75,6 +75,8 @@ void unicode_input_start(void) { unregister_code(KC_LSFT); unregister_code(KC_LCTL); break; + case UC_BSD: + break; case UC_WIN: register_code(KC_LALT); tap_code(KC_PPLS); @@ -92,7 +94,7 @@ void unicode_input_finish(void) { switch (unicode_config.input_mode) { case UC_OSX: case UC_WIN: - unregister_code(KC_LALT); + unregister_code(KC_LALT); break; case UC_OSX_RALT: unregister_code(KC_RALT); @@ -148,7 +150,7 @@ void send_unicode_hex_string(const char *str) { } } -bool process_record_unicode_common(uint16_t keycode, keyrecord_t *record) { +bool process_unicode_common(uint16_t keycode, keyrecord_t *record) { if (record->event.pressed) { switch (keycode) { case UNICODE_MODE_OSX: @@ -163,21 +165,21 @@ bool process_record_unicode_common(uint16_t keycode, keyrecord_t *record) { PLAY_SONG(song_lnx); #endif break; + case UNICODE_MODE_WIN: + set_unicode_input_mode(UC_WIN); + #if defined(AUDIO_ENABLE) && defined(UNICODE_SONG_WIN) + PLAY_SONG(windows_song); + #endif + break; case UNICODE_MODE_BSD: set_unicode_input_mode(UC_BSD); #if defined(AUDIO_ENABLE) && defined(UNICODE_SONG_BSD) PLAY_SONG(song_bsd); #endif break; - case UNICODE_MODE_WIN: - set_unicode_input_mode(UC_WIN); - #if defined(AUDIO_ENABLE) && defined(UNICODE_SONG_WINDOWS) - PLAY_SONG(windows_song); - #endif - break; case UNICODE_MODE_WINC: set_unicode_input_mode(UC_WINC); - #if defined(AUDIO_ENABLE) && defined(UNICODE_SONG_WIN_COMPOSE) + #if defined(AUDIO_ENABLE) && defined(UNICODE_SONG_WINC) PLAY_SONG(win_compose_song); #endif break; diff --git a/quantum/process_keycode/process_unicode_common.h b/quantum/process_keycode/process_unicode_common.h index 8a1f809eb7aa..1beeda467e33 100644 --- a/quantum/process_keycode/process_unicode_common.h +++ b/quantum/process_keycode/process_unicode_common.h @@ -42,7 +42,7 @@ void unicode_input_start(void); void unicode_input_finish(void); void register_hex(uint16_t hex); void send_unicode_hex_string(const char *str); -bool process_record_unicode_common(uint16_t keycode, keyrecord_t *record); +bool process_unicode_common(uint16_t keycode, keyrecord_t *record); #define UC_OSX 0 // Mac OS X #define UC_LNX 1 // Linux diff --git a/quantum/quantum.c b/quantum/quantum.c index 1fb6a15ac753..6923b633bd0b 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c @@ -257,7 +257,7 @@ bool process_record_quantum(keyrecord_t *record) { process_tap_dance(keycode, record) && #endif #if (defined(UNICODE_ENABLE) || defined(UNICODEMAP_ENABLE) || defined(UCIS_ENABLE)) - process_record_unicode_common(keycode, record) && + process_unicode_common(keycode, record) && #endif #ifdef LEADER_ENABLE process_leader(keycode, record) && diff --git a/quantum/quantum_keycodes.h b/quantum/quantum_keycodes.h index c7f642353759..d537ebcfbc0e 100644 --- a/quantum/quantum_keycodes.h +++ b/quantum/quantum_keycodes.h @@ -455,8 +455,8 @@ enum quantum_keycodes { UNICODE_MODE_OSX, UNICODE_MODE_LNX, - UNICODE_MODE_BSD, UNICODE_MODE_WIN, + UNICODE_MODE_BSD, UNICODE_MODE_WINC, UNICODE_MODE_OSX_RALT, @@ -689,8 +689,8 @@ enum quantum_keycodes { #define UC_M_OS UNICODE_MODE_OSX #define UC_M_LN UNICODE_MODE_LNX -#define UC_M_BS UNICODE_MODE_BSD #define UC_M_WI UNICODE_MODE_WIN +#define UC_M_BS UNICODE_MODE_BSD #define UC_M_WC UNICODE_MODE_WINC #define UC_M_OR UNICODE_MODE_OSX_RALT From 2fa2c425866c76a9f38fabe9b3755dcf9e831aa8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20=C4=90or=C4=91evi=C4=87?= Date: Sat, 3 Nov 2018 18:24:24 +0100 Subject: [PATCH 33/42] Format unicode_common (#13) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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 --- docs/feature_unicode.md | 67 +++++---- .../process_keycode/process_unicode_common.c | 134 ++++++++---------- .../process_keycode/process_unicode_common.h | 4 +- quantum/quantum.c | 6 +- 4 files changed, 97 insertions(+), 114 deletions(-) diff --git a/docs/feature_unicode.md b/docs/feature_unicode.md index 32ea7d344b45..5901f3f86c59 100644 --- a/docs/feature_unicode.md +++ b/docs/feature_unicode.md @@ -1,6 +1,6 @@ # Unicode Support -There are three Unicode keymap definition method available in QMK: +There are three Unicode keymap definition methods available in QMK: ## UNICODE_ENABLE @@ -14,15 +14,15 @@ And you may want to have an enum to make reference easier. So you'd want to add ```c enum unicode_names { - BANG, // โ€ฝ - IRONY, // โธฎ - SNEK // snke ๐Ÿ + BANG, + IRONY, + SNEK, }; const uint32_t PROGMEM unicode_map[] = { - [BANG] = 0x0203D, // โ€ฝ - [IRONY] = 0x02E2E, // โธฎ - [SNEK] = 0x1F40D // snke ๐Ÿ + [BANG] = 0x203D, // โ€ฝ + [IRONY] = 0x2E2E, // โธฎ + [SNEK] = 0x1F40D, // ๐Ÿ }: ``` @@ -77,18 +77,9 @@ void qk_ucis_symbol_fallback (void) { // falls back to manual unicode entry ## Input Modes -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. +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. -There are two ways to set the input mode for Unicode, by keycode or by function. - -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. - -!> 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) - - -### Functions - -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. +The following input modes are available: * __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. * __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 * __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. * __UC_WINC__: Windows Unicode input using WinCompose. Requires [WinCompose](https://github.com/samhocevar/wincompose). Works reliably under many (all?) variations of Windows. -### Keycodes +!> 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). + +### Switching Input Modes -|Key |Aliases |Input Method |Description | -|--------------------------|---------|--------------|---------------------------------------------------| -|`UNICODE_MODE_OSX` |`UC_M_OS`|`UC_OSX` |Sets the input method for MacOS X | -|`UNICODE_MODE_LNX` |`UC_M_LN`|`UC_LNX` |Sets the input method for Linux | -|`UNICODE_MODE_BSD` |`UC_M_BS`|`UC_BSD` |Sets the input method for BSD (Non-Operational) | -|`UNICODE_MODE_WIN` |`UC_M_WI`|`UC_WIN` |Sets the input method for Windows | -|`UNICODE_MODE_WINC` |`UC_M_WC`|`UC_WINC` |Sets the input method for Windows using WinCompose | -|`UNICODE_MODE_OSX_RALT` |`UC_M_OR`|`UC_OSX_RALT` |Sets the input method for MacOS X using RAlt/AltGr | -### Audio Feedback for Input Mode keycodes +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. + +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_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.| +|`UNICODE_MODE_OSX_RALT`|`UC_M_OR`|`UC_OSX_RALT`|Switch to Mac OS X input using Right Alt.| + +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. + +### Audio Feedback 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. -For instance, you can add these to your `config.h` file. +For instance, you can add these definitions to your `config.h` file: ```c #define UNICODE_SONG_OSX COIN_SOUND @@ -122,16 +122,15 @@ For instance, you can add these to your `config.h` file. #define UNICODE_SONG_OSX_RALT COIN_SOUND ``` -### Unicode Input Method Customization +### Additional Customization -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. +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)` - his is called to exit Unicode input mode, for example by pressing Space or releasing the Option key. +* `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). - ## `send_unicode_hex_string` 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. diff --git a/quantum/process_keycode/process_unicode_common.c b/quantum/process_keycode/process_unicode_common.c index 65afc3785995..12315c0922ba 100644 --- a/quantum/process_keycode/process_unicode_common.c +++ b/quantum/process_keycode/process_unicode_common.c @@ -21,27 +21,6 @@ unicode_config_t unicode_config; static uint8_t saved_mods; -#ifdef AUDIO_ENABLE - #ifdef UNICODE_SONG_OSX - float osx_song[][2] = UNICODE_SONG_OSX; - #endif - #ifdef UNICODE_SONG_LNX - float song_lnx[][2] = UNICODE_SONG_LNX; - #endif - #ifdef UNICODE_SONG_WIN - float windows_song[][2] = UNICODE_SONG_WIN; - #endif - #ifdef UNICODE_SONG_BSD - float song_bsd[][2] = UNICODE_SONG_BSD; - #endif - #ifdef UNICODE_SONG_WINC - float win_compose_song[][2] = UNICODE_SONG_WINC; - #endif - #ifdef UNICODE_SONG_OSX_RALT - float osx_ralt_song[][2] = UNICODE_SONG_OSX_RALT; - #endif -#endif - void set_unicode_input_mode(uint8_t os_target) { unicode_config.input_mode = os_target; @@ -92,16 +71,16 @@ void unicode_input_start(void) { __attribute__((weak)) void unicode_input_finish(void) { switch (unicode_config.input_mode) { - case UC_OSX: - case UC_WIN: - unregister_code(KC_LALT); - break; - case UC_OSX_RALT: - unregister_code(KC_RALT); - break; - case UC_LNX: - tap_code(KC_SPC); - break; + case UC_OSX: + case UC_WIN: + unregister_code(KC_LALT); + break; + case UC_OSX_RALT: + unregister_code(KC_RALT); + break; + case UC_LNX: + tap_code(KC_SPC); + break; } set_mods(saved_mods); // Reregister previously set mods @@ -153,52 +132,57 @@ void send_unicode_hex_string(const char *str) { bool process_unicode_common(uint16_t keycode, keyrecord_t *record) { if (record->event.pressed) { switch (keycode) { - case UNICODE_MODE_OSX: + case UNICODE_MODE_OSX: set_unicode_input_mode(UC_OSX); - #if defined(AUDIO_ENABLE) && defined(UNICODE_SONG_OSX) - PLAY_SONG(osx_song); - #endif - break; - case UNICODE_MODE_LNX: - set_unicode_input_mode(UC_LNX); - #if defined(AUDIO_ENABLE) && defined(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) - PLAY_SONG(windows_song); - #endif - break; - case UNICODE_MODE_BSD: - set_unicode_input_mode(UC_BSD); - #if defined(AUDIO_ENABLE) && defined(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) - PLAY_SONG(win_compose_song); - #endif - break; - case UNICODE_MODE_OSX_RALT: - set_unicode_input_mode(UC_OSX_RALT); - #if defined(AUDIO_ENABLE) && defined(UNICODE_SONG_OSX_RALT) - PLAY_SONG(osx_ralt_song); - #endif - break; +#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; + case UNICODE_MODE_OSX_RALT: + set_unicode_input_mode(UC_OSX_RALT); +#if defined(AUDIO_ENABLE) && defined(UNICODE_SONG_OSX_RALT) + static float song_osx_ralt[][2] = UNICODE_SONG_OSX_RALT; + PLAY_SONG(song_osx_ralt); +#endif + break; } } - #ifdef UNICODE_ENABLE - return process_unicode(keycode, record); - #endif - #ifdef UCIS_ENABLE - return process_ucis(keycode, record); - #endif - #ifdef UNICODEMAP_ENABLE - return process_unicode_map(keycode, record); - #endif +#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 } diff --git a/quantum/process_keycode/process_unicode_common.h b/quantum/process_keycode/process_unicode_common.h index 1beeda467e33..8fdc312eb32e 100644 --- a/quantum/process_keycode/process_unicode_common.h +++ b/quantum/process_keycode/process_unicode_common.h @@ -19,11 +19,11 @@ #include "quantum.h" #if defined(UNICODE_ENABLE) + defined(UNICODEMAP_ENABLE) + defined(UCIS_ENABLE) > 1 - #error "Cannot enable more than one unicode method (UNICODE, UNICODEMAP, UCIS) at the same time" + #error "Cannot enable more than one Unicode method (UNICODE, UNICODEMAP, UCIS) at the same time" #endif #ifndef UNICODE_TYPE_DELAY -#define UNICODE_TYPE_DELAY 10 + #define UNICODE_TYPE_DELAY 10 #endif typedef union { diff --git a/quantum/quantum.c b/quantum/quantum.c index 6923b633bd0b..5f40b590c07f 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c @@ -235,7 +235,7 @@ bool process_record_quantum(keyrecord_t *record) { process_key_lock(&keycode, record) && #endif #if defined(AUDIO_ENABLE) && defined(AUDIO_CLICKY) - process_clicky(keycode, record) && + process_clicky(keycode, record) && #endif //AUDIO_CLICKY process_record_kb(keycode, record) && #if defined(RGB_MATRIX_ENABLE) && defined(RGB_MATRIX_KEYPRESSES) @@ -250,13 +250,13 @@ bool process_record_quantum(keyrecord_t *record) { #ifdef STENO_ENABLE process_steno(keycode, record) && #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) && #endif #ifdef TAP_DANCE_ENABLE process_tap_dance(keycode, record) && #endif - #if (defined(UNICODE_ENABLE) || defined(UNICODEMAP_ENABLE) || defined(UCIS_ENABLE)) + #if defined(UNICODE_ENABLE) || defined(UNICODEMAP_ENABLE) || defined(UCIS_ENABLE) process_unicode_common(keycode, record) && #endif #ifdef LEADER_ENABLE From 735fdfd07e9a5f1fb6703d83dc94d00c2d000bef Mon Sep 17 00:00:00 2001 From: Drashna Jaelre Date: Sat, 3 Nov 2018 11:21:01 -0700 Subject: [PATCH 34/42] Steal vomindoraan's input mode documentation Co-Authored-By: vomindoraan (vomindoraan@gmail.com) --- docs/feature_unicode.md | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/docs/feature_unicode.md b/docs/feature_unicode.md index 5901f3f86c59..b3fd9f6d1f77 100644 --- a/docs/feature_unicode.md +++ b/docs/feature_unicode.md @@ -81,12 +81,27 @@ Unicode input in QMK works by inputting a sequence of characters to the OS, sort The following input modes are available: -* __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. -* __UC_OSX_RALT__: Same as UC_OSX, but sends the Right Alt key for unicode input -* __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. -* __UC_BSD__: (non operational) Unicode input method under BSD. -* __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. -* __UC_WINC__: Windows Unicode input using WinCompose. Requires [WinCompose](https://github.com/samhocevar/wincompose). Works reliably under many (all?) variations of Windows. +* **`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. + +* **`UC_OSX_RALT`**: Same as UC_OSX, but sends the Right Alt key for unicode input + +* **`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_BSD`**: (non operational) Unicode input method under BSD. + +* **`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_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. + This mode uses the right Alt key (`KC_RALT`), and this needs to be set to this in WinCompose's settings. !> 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). From 3ad9833686724e7c37f073be4ba6adbb9a9de6eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20=C4=90or=C4=91evi=C4=87?= Date: Sat, 3 Nov 2018 22:26:08 +0100 Subject: [PATCH 35/42] Willingly give Drashna the rest of my Unicode doc improvements --- docs/feature_unicode.md | 46 ++++++++++++++--------------------------- 1 file changed, 15 insertions(+), 31 deletions(-) diff --git a/docs/feature_unicode.md b/docs/feature_unicode.md index b3fd9f6d1f77..b03514ab7b19 100644 --- a/docs/feature_unicode.md +++ b/docs/feature_unicode.md @@ -4,11 +4,11 @@ There are three Unicode keymap definition methods available in QMK: ## 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 -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: @@ -30,7 +30,7 @@ Make sure that the order for both matches. ## 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: @@ -53,27 +53,7 @@ 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_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: - -```c -void qk_ucis_start_user(void) { // outputs keyboard emoji - unicode_input_start(); - 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); - } -} -``` +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 @@ -85,25 +65,23 @@ The following input modes are available: 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. -* **`UC_OSX_RALT`**: Same as UC_OSX, but sends the Right Alt key for unicode input +* **`UC_OSX_RALT`**: Same as `UC_OSX`, but sends the Right Alt/Option key for Unicode input. * **`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_BSD`**: (non operational) Unicode input method under BSD. - * **`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. - This mode uses the right Alt key (`KC_RALT`), and this needs to be set to this in WinCompose's settings. - -!> 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). + 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. ### Switching Input Modes @@ -120,7 +98,13 @@ You can switch the input mode at any time by using one of the following keycodes |`UNICODE_MODE_WINC` |`UC_M_WC`|`UC_WINC` |Switch to Windows input using WinCompose.| |`UNICODE_MODE_OSX_RALT`|`UC_M_OR`|`UC_OSX_RALT`|Switch to Mac OS X input using Right Alt.| -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. +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 +void eeconfig_init_user(void) { + set_unicode_input_mode(UC_LNX); +} +``` ### Audio Feedback From 917bf83fcd85bd410e74c0a75dd6c59020b2dde7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20=C4=90or=C4=91evi=C4=87?= Date: Sat, 3 Nov 2018 14:52:32 -0700 Subject: [PATCH 36/42] Wordsmithing Co-Authored-By: drashna --- docs/feature_unicode.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/feature_unicode.md b/docs/feature_unicode.md index b03514ab7b19..86923a54ec59 100644 --- a/docs/feature_unicode.md +++ b/docs/feature_unicode.md @@ -85,7 +85,7 @@ The following input modes are available: ### 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 once, you don't need to set it again unless you want to change it, or you've reset the EEPROM settings. +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. From 41e6877015217892b2f679f279a34679dbe09bd3 Mon Sep 17 00:00:00 2001 From: Drashna Jaelre Date: Sun, 25 Nov 2018 11:44:06 -0800 Subject: [PATCH 37/42] remove merge artifacts --- quantum/process_keycode/process_ucis.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/quantum/process_keycode/process_ucis.c b/quantum/process_keycode/process_ucis.c index 8deb24a86747..5de2e41fc305 100644 --- a/quantum/process_keycode/process_ucis.c +++ b/quantum/process_keycode/process_ucis.c @@ -95,8 +95,6 @@ void register_ucis(const char *hex) { bool process_ucis (uint16_t keycode, keyrecord_t *record) { uint8_t i; - unicode_input_mode_init(); - if (!qk_ucis_state.in_progress) return true; From dd36ebadc23119e9f740e088dcbf35bc49e89afa Mon Sep 17 00:00:00 2001 From: Drashna Jaelre Date: Sun, 25 Nov 2018 13:06:29 -0800 Subject: [PATCH 38/42] Unicode common cleanup (#17) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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 * Fix spacing Co-Authored-By: drashna * Because I missed it! Co-Authored-By: drashna * Fix spacing Co-Authored-By: drashna * SPAAAAAAAAAACing Co-Authored-By: drashna * white spaces Co-Authored-By: drashna * Add BSD for future compatibility * Thought I fixed that! Co-Authored-By: drashna * non-breaking Co-Authored-By: drashna * Considered that Co-Authored-By: drashna * Yuuup Co-Authored-By: drashna * consistency Co-Authored-By: drashna * white spaces .... copied from elsewhere Co-Authored-By: drashna * white spaces Co-Authored-By: drashna * white spaces Co-Authored-By: drashna * 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 * 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 --- docs/feature_unicode.md | 6 +-- .../process_keycode/process_unicode_common.c | 39 +++++++------------ .../process_keycode/process_unicode_common.h | 35 +++++++++++------ quantum/process_keycode/process_unicodemap.c | 4 +- 4 files changed, 43 insertions(+), 41 deletions(-) diff --git a/docs/feature_unicode.md b/docs/feature_unicode.md index 86923a54ec59..648504f99029 100644 --- a/docs/feature_unicode.md +++ b/docs/feature_unicode.md @@ -64,8 +64,7 @@ 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. - -* **`UC_OSX_RALT`**: Same as `UC_OSX`, but sends the Right Alt/Option key for Unicode input. + By default, this mode uses the left Option key (`KC_LALT`), but this can be changed by defining `UNICODE_OSX_KEY` with another keycode. * **`UC_LNX`**: Linux built-in IBus Unicode input. Supports all possible code points (`0x10FFFF`). @@ -81,7 +80,7 @@ The following input modes are available: * **`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. - 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. + 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. ### Switching Input Modes @@ -118,7 +117,6 @@ For instance, you can add these definitions to your `config.h` file: #define UNICODE_SONG_BSD MARIO_GAMEOVER #define UNICODE_SONG_WIN UNICODE_WINDOWS #define UNICODE_SONG_WINC UNICODE_WINDOWS -#define UNICODE_SONG_OSX_RALT COIN_SOUND ``` ### Additional Customization diff --git a/quantum/process_keycode/process_unicode_common.c b/quantum/process_keycode/process_unicode_common.c index 12315c0922ba..82ae0a5ad4eb 100644 --- a/quantum/process_keycode/process_unicode_common.c +++ b/quantum/process_keycode/process_unicode_common.c @@ -16,25 +16,26 @@ #include "process_unicode_common.h" #include "eeprom.h" -#include #include +#include unicode_config_t unicode_config; -static uint8_t saved_mods; -void set_unicode_input_mode(uint8_t os_target) { - unicode_config.input_mode = os_target; - eeprom_update_byte(EECONFIG_UNICODEMODE, os_target); +void unicode_input_mode_init(void) { + unicode_config.raw = eeprom_read_byte(EECONFIG_UNICODEMODE); } uint8_t get_unicode_input_mode(void) { return unicode_config.input_mode; } -void unicode_input_mode_init(void) { - unicode_config.raw = eeprom_read_byte(EECONFIG_UNICODEMODE); +void set_unicode_input_mode(uint8_t mode) { + unicode_config.input_mode = mode; + eeprom_update_byte(EECONFIG_UNICODEMODE, mode); } +static uint8_t saved_mods; + __attribute__((weak)) void unicode_input_start(void) { saved_mods = get_mods(); // Save current mods @@ -42,15 +43,12 @@ void unicode_input_start(void) { switch (unicode_config.input_mode) { case UC_OSX: - register_code(KC_LALT); - break; - case UC_OSX_RALT: - register_code(KC_RALT); + register_code(UNICODE_OSX_KEY); break; case UC_LNX: register_code(KC_LCTL); register_code(KC_LSFT); - tap_code(KC_U); + tap_code(KC_U); // TODO: Replace with tap_code16(LCTL(LSFT(KC_U))); and test unregister_code(KC_LSFT); unregister_code(KC_LCTL); break; @@ -61,10 +59,11 @@ void unicode_input_start(void) { tap_code(KC_PPLS); break; case UC_WINC: - tap_code(KC_RALT); + tap_code(UNICODE_WINC_KEY); tap_code(KC_U); break; } + wait_ms(UNICODE_TYPE_DELAY); } @@ -72,12 +71,11 @@ __attribute__((weak)) void unicode_input_finish(void) { switch (unicode_config.input_mode) { case UC_OSX: + unregister_code(UNICODE_OSX_KEY); + break; case UC_WIN: unregister_code(KC_LALT); break; - case UC_OSX_RALT: - unregister_code(KC_RALT); - break; case UC_LNX: tap_code(KC_SPC); break; @@ -105,7 +103,7 @@ void register_hex(uint16_t hex) { } void send_unicode_hex_string(const char *str) { - if (!str) { return; } // Safety net + if (!str) { return; } while (*str) { // Find the next code point (token) in the string @@ -165,13 +163,6 @@ bool process_unicode_common(uint16_t keycode, keyrecord_t *record) { #if defined(AUDIO_ENABLE) && defined(UNICODE_SONG_WINC) static float song_winc[][2] = UNICODE_SONG_WINC; PLAY_SONG(song_winc); -#endif - break; - case UNICODE_MODE_OSX_RALT: - set_unicode_input_mode(UC_OSX_RALT); -#if defined(AUDIO_ENABLE) && defined(UNICODE_SONG_OSX_RALT) - static float song_osx_ralt[][2] = UNICODE_SONG_OSX_RALT; - PLAY_SONG(song_osx_ralt); #endif break; } diff --git a/quantum/process_keycode/process_unicode_common.h b/quantum/process_keycode/process_unicode_common.h index 8fdc312eb32e..056c1a8518df 100644 --- a/quantum/process_keycode/process_unicode_common.h +++ b/quantum/process_keycode/process_unicode_common.h @@ -22,37 +22,50 @@ #error "Cannot enable more than one Unicode method (UNICODE, UNICODEMAP, UCIS) at the same time" #endif +// Keycodes used for starting Unicode input on different platforms +#ifndef UNICODE_OSX_KEY + #define UNICODE_OSX_KEY KC_LALT +#endif +#ifndef UNICODE_WINC_KEY + #define UNICODE_WINC_KEY KC_RALT +#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; + 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); +uint8_t get_unicode_input_mode(void); +void set_unicode_input_mode(uint8_t mode); + void unicode_input_start(void); void unicode_input_finish(void); + void register_hex(uint16_t hex); void send_unicode_hex_string(const char *str); -bool process_unicode_common(uint16_t keycode, keyrecord_t *record); -#define UC_OSX 0 // Mac OS X -#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 +bool process_unicode_common(uint16_t keycode, keyrecord_t *record); #define UC_BSPC UC(0x0008) - #define UC_SPC UC(0x0020) #define UC_EXLM UC(0x0021) diff --git a/quantum/process_keycode/process_unicodemap.c b/quantum/process_keycode/process_unicodemap.c index 47c27b911716..75f35112b133 100644 --- a/quantum/process_keycode/process_unicodemap.c +++ b/quantum/process_keycode/process_unicodemap.c @@ -50,7 +50,7 @@ bool process_unicode_map(uint16_t keycode, keyrecord_t *record) { const uint32_t* map = unicode_map; uint16_t index = keycode - QK_UNICODE_MAP; 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 code -= 0x10000; uint32_t lo = code & 0x3ff; @@ -59,7 +59,7 @@ bool process_unicode_map(uint16_t keycode, keyrecord_t *record) { register_hex32(hi + 0xd800); register_hex32(lo + 0xdc00); 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 unicode_map_input_error(); } else { From 5cfd48d2d2eea0e8747a6969a552770f3797b7d6 Mon Sep 17 00:00:00 2001 From: Drashna Jaelre Date: Sun, 25 Nov 2018 13:57:40 -0800 Subject: [PATCH 39/42] Improve Cycling documentation --- docs/feature_unicode.md | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/docs/feature_unicode.md b/docs/feature_unicode.md index 648504f99029..ddb08e21031b 100644 --- a/docs/feature_unicode.md +++ b/docs/feature_unicode.md @@ -64,7 +64,8 @@ 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` with another keycode. + + * By default, this mode uses the left Option key (KC_LALT), but this can be changed by defining UNICODE_OSX_KEY with another keycode. * **`UC_LNX`**: Linux built-in IBus Unicode input. Supports all possible code points (`0x10FFFF`). @@ -80,7 +81,7 @@ The following input modes are available: * **`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` with another keycode. + 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. ### Switching Input Modes @@ -95,7 +96,8 @@ You can switch the input mode at any time by using one of the following keycodes |`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.| -|`UNICODE_MODE_OSX_RALT`|`UC_M_OR`|`UC_OSX_RALT`|Switch to Mac OS X input using Right Alt.| +|`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)| 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: @@ -121,6 +123,10 @@ For instance, you can add these definitions to your `config.h` file: ### 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. @@ -128,6 +134,25 @@ The functions for starting and finishing Unicode input on your platform can be o 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` 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. From 464c9aa6c5c6ed5c6a732c1ae6365610cb29fc09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20=C4=90or=C4=91evi=C4=87?= Date: Sun, 25 Nov 2018 23:25:05 +0100 Subject: [PATCH 40/42] Add Unicode Input method Cycling support (#19) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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 * Fix spacing Co-Authored-By: drashna * Because I missed it! Co-Authored-By: drashna * Fix spacing Co-Authored-By: drashna * SPAAAAAAAAAACing Co-Authored-By: drashna * white spaces Co-Authored-By: drashna * Add BSD for future compatibility * Thought I fixed that! Co-Authored-By: drashna * non-breaking Co-Authored-By: drashna * Considered that Co-Authored-By: drashna * Yuuup Co-Authored-By: drashna * consistency Co-Authored-By: drashna * white spaces .... copied from elsewhere Co-Authored-By: drashna * white spaces Co-Authored-By: drashna * white spaces Co-Authored-By: drashna * 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 * 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 --- docs/feature_unicode.md | 14 ++--- .../whitefox/keymaps/konstantin/config.h | 4 ++ .../whitefox/keymaps/konstantin/keymap.c | 8 +-- .../process_keycode/process_unicode_common.c | 58 +++++++++++++++++-- .../process_keycode/process_unicode_common.h | 13 +++++ quantum/quantum_keycodes.h | 6 ++ 6 files changed, 83 insertions(+), 20 deletions(-) diff --git a/docs/feature_unicode.md b/docs/feature_unicode.md index ddb08e21031b..1b083896a2b4 100644 --- a/docs/feature_unicode.md +++ b/docs/feature_unicode.md @@ -64,8 +64,7 @@ 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 with another keycode. + 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`). @@ -81,7 +80,7 @@ The following input modes are available: * **`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. - 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. + 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 @@ -91,13 +90,13 @@ You can switch the input mode at any time by using one of the following keycodes |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.| -|`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)| 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: @@ -143,7 +142,8 @@ Additionally, you can customize the keys used to trigger the unicode input for m #define UNICODE_OSX_KEY KC_LALT #define UNICODE_WINC_KEY KC_RALT ``` -#### Input method Cycling + +#### 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. @@ -151,8 +151,6 @@ Also, you can choose which input methods are availble for cycling through. By d #define UNICODE_SELECTED_MODES UC_OSX, UC_LNX, UC_WIN, UC_BSD, UC_WINC ``` - - ## `send_unicode_hex_string` 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. diff --git a/keyboards/whitefox/keymaps/konstantin/config.h b/keyboards/whitefox/keymaps/konstantin/config.h index ee30dbece1a2..ab920a50baf7 100644 --- a/keyboards/whitefox/keymaps/konstantin/config.h +++ b/keyboards/whitefox/keymaps/konstantin/config.h @@ -21,3 +21,7 @@ #define PERMISSIVE_HOLD #define TAPPING_TERM 200 #define TAPPING_TOGGLE 2 + +#define UNICODE_CYCLE_PERSIST false +#define UNICODE_SELECTED_MODES UC_WINC, UC_LNX +#define UNICODE_WINC_KEY KC_RGUI diff --git a/keyboards/whitefox/keymaps/konstantin/keymap.c b/keyboards/whitefox/keymaps/konstantin/keymap.c index 55db5ca6b839..54777cfe08b6 100644 --- a/keyboards/whitefox/keymaps/konstantin/keymap.c +++ b/keyboards/whitefox/keymaps/konstantin/keymap.c @@ -23,10 +23,6 @@ #define DIVIDE UC(0x00F7) #define MINUS UC(0x2212) -void eeconfig_init_user(void) { - set_unicode_input_mode(UC_WINC); -} - enum layers { L_BASE, L_FN, @@ -162,7 +158,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { * โ”Œโ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ” * โ”‚ โ”‚F1 โ”‚F2 โ”‚F3 โ”‚F4 โ”‚F5 โ”‚F6 โ”‚F7 โ”‚F8 โ”‚F9 โ”‚F10โ”‚F11โ”‚F12โ”‚Numโ”‚Scrโ”‚Pauโ”‚ * โ”œโ”€โ”€โ”€โ”ดโ”€โ”ฌโ”€โ”ดโ”€โ”ฌโ”€โ”ดโ”€โ”ฌโ”€โ”ดโ”€โ”ฌโ”€โ”ดโ”€โ”ฌโ”€โ”ดโ”€โ”ฌโ”€โ”ดโ”€โ”ฌโ”€โ”ดโ”€โ”ฌโ”€โ”ดโ”€โ”ฌโ”€โ”ดโ”€โ”ฌโ”€โ”ดโ”€โ”ฌโ”€โ”ดโ”€โ”ฌโ”€โ”ดโ”€โ”ฌโ”€โ”ดโ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”ค - * โ”‚ M4 โ”‚M2 โ”‚Mโ†‘ โ”‚M1 โ”‚M3 โ”‚M5 โ”‚ โ”‚ โ”‚ โ”‚Stpโ”‚Plyโ”‚Prvโ”‚Nxtโ”‚Clearโ”‚Insโ”‚ + * โ”‚ M4 โ”‚M2 โ”‚Mโ†‘ โ”‚M1 โ”‚M3 โ”‚M5 โ”‚ โ”‚UCMโ”‚ โ”‚Stpโ”‚Plyโ”‚Prvโ”‚Nxtโ”‚Clearโ”‚Insโ”‚ * โ”œโ”€โ”€โ”€โ”€โ”€โ”ดโ”ฌโ”€โ”€โ”ดโ”ฌโ”€โ”€โ”ดโ”ฌโ”€โ”€โ”ดโ”ฌโ”€โ”€โ”ดโ”ฌโ”€โ”€โ”ดโ”ฌโ”€โ”€โ”ดโ”ฌโ”€โ”€โ”ดโ”ฌโ”€โ”€โ”ดโ”ฌโ”€โ”€โ”ดโ”ฌโ”€โ”€โ”ดโ”ฌโ”€โ”€โ”ดโ”ฌโ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”ค * โ”‚ โ”‚Mโ† โ”‚Mโ†“ โ”‚Mโ†’ โ”‚MWโ†‘โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚Topโ”‚ * โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”ฌโ”€โ”ดโ”€โ”ฌโ”€โ”ดโ”€โ”ฌโ”€โ”ดโ”€โ”ฌโ”€โ”ดโ”€โ”ฌโ”€โ”ดโ”€โ”ฌโ”€โ”ดโ”€โ”ฌโ”€โ”ดโ”€โ”ฌโ”€โ”ดโ”€โ”ฌโ”€โ”ดโ”€โ”ฌโ”€โ”ดโ”€โ”ฌโ”€โ”ดโ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”ค @@ -173,7 +169,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { */ [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_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_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 \ diff --git a/quantum/process_keycode/process_unicode_common.c b/quantum/process_keycode/process_unicode_common.c index 82ae0a5ad4eb..3286f45b5d8a 100644 --- a/quantum/process_keycode/process_unicode_common.c +++ b/quantum/process_keycode/process_unicode_common.c @@ -20,9 +20,34 @@ #include unicode_config_t unicode_config; +#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 unicode_input_mode_init(void) { unicode_config.raw = eeprom_read_byte(EECONFIG_UNICODEMODE); +#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) { @@ -31,7 +56,23 @@ uint8_t get_unicode_input_mode(void) { void set_unicode_input_mode(uint8_t mode) { unicode_config.input_mode = mode; - eeprom_update_byte(EECONFIG_UNICODEMODE, mode); + persist_unicode_input_mode(); + dprintf("Unicode input mode set to: %u\n", unicode_config.input_mode); +} + +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; @@ -52,8 +93,6 @@ void unicode_input_start(void) { unregister_code(KC_LSFT); unregister_code(KC_LCTL); break; - case UC_BSD: - break; case UC_WIN: register_code(KC_LALT); tap_code(KC_PPLS); @@ -73,12 +112,12 @@ void unicode_input_finish(void) { case UC_OSX: unregister_code(UNICODE_OSX_KEY); break; - case UC_WIN: - unregister_code(KC_LALT); - break; case UC_LNX: tap_code(KC_SPC); break; + case UC_WIN: + unregister_code(KC_LALT); + break; } set_mods(saved_mods); // Reregister previously set mods @@ -130,6 +169,13 @@ void send_unicode_hex_string(const char *str) { 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) diff --git a/quantum/process_keycode/process_unicode_common.h b/quantum/process_keycode/process_unicode_common.h index 056c1a8518df..e608ab76be7b 100644 --- a/quantum/process_keycode/process_unicode_common.h +++ b/quantum/process_keycode/process_unicode_common.h @@ -30,6 +30,17 @@ #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 @@ -56,6 +67,8 @@ extern unicode_config_t unicode_config; 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_finish(void); diff --git a/quantum/quantum_keycodes.h b/quantum/quantum_keycodes.h index d537ebcfbc0e..92af61e85813 100644 --- a/quantum/quantum_keycodes.h +++ b/quantum/quantum_keycodes.h @@ -453,6 +453,9 @@ enum quantum_keycodes { EEPROM_RESET, + UNICODE_MODE_FORWARD, + UNICODE_MODE_REVERSE, + UNICODE_MODE_OSX, UNICODE_MODE_LNX, UNICODE_MODE_WIN, @@ -687,6 +690,9 @@ enum quantum_keycodes { #define X(n) (QK_UNICODE_MAP | (n)) #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 From fadc2185d85a7f3e5b94319b3460d75f085909fd Mon Sep 17 00:00:00 2001 From: Drashna Jaelre Date: Sun, 25 Nov 2018 14:43:23 -0800 Subject: [PATCH 41/42] Cleanup of RALT code and unicode compilation stuff --- quantum/quantum_keycodes.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/quantum/quantum_keycodes.h b/quantum/quantum_keycodes.h index 92af61e85813..a5c7371d6e24 100644 --- a/quantum/quantum_keycodes.h +++ b/quantum/quantum_keycodes.h @@ -461,7 +461,6 @@ enum quantum_keycodes { UNICODE_MODE_WIN, UNICODE_MODE_BSD, UNICODE_MODE_WINC, - UNICODE_MODE_OSX_RALT, // always leave at the end SAFE_RANGE @@ -684,10 +683,15 @@ enum quantum_keycodes { // To have a key that sends out ล’, go UC(0x0152) #define UNICODE(n) (QK_UNICODE | (n)) #define UC(n) UNICODE(n) +#else + #define UNICODE(n) KC_NO + #define UC(n) KC_NO #endif #ifdef UNICODEMAP_ENABLE #define X(n) (QK_UNICODE_MAP | (n)) +#else + #define X(n) KC_NO #endif #define UC_MOD UNICODE_MODE_FORWARD @@ -698,7 +702,6 @@ enum quantum_keycodes { #define UC_M_WI UNICODE_MODE_WIN #define UC_M_BS UNICODE_MODE_BSD #define UC_M_WC UNICODE_MODE_WINC -#define UC_M_OR UNICODE_MODE_OSX_RALT #ifdef SWAP_HANDS_ENABLE #define SH_T(kc) (QK_SWAP_HANDS | (kc)) From 0f524266836e4adbf3d545fc3e59328d5e5c86d3 Mon Sep 17 00:00:00 2001 From: Drashna Jaelre Date: Sun, 25 Nov 2018 14:54:49 -0800 Subject: [PATCH 42/42] Remove else for unicode handling --- quantum/quantum_keycodes.h | 5 ----- 1 file changed, 5 deletions(-) diff --git a/quantum/quantum_keycodes.h b/quantum/quantum_keycodes.h index a5c7371d6e24..e40e68f32b56 100644 --- a/quantum/quantum_keycodes.h +++ b/quantum/quantum_keycodes.h @@ -683,15 +683,10 @@ enum quantum_keycodes { // To have a key that sends out ล’, go UC(0x0152) #define UNICODE(n) (QK_UNICODE | (n)) #define UC(n) UNICODE(n) -#else - #define UNICODE(n) KC_NO - #define UC(n) KC_NO #endif #ifdef UNICODEMAP_ENABLE #define X(n) (QK_UNICODE_MAP | (n)) -#else - #define X(n) KC_NO #endif #define UC_MOD UNICODE_MODE_FORWARD