From fdeec296369c0995bad1117e50946b2df84f35e4 Mon Sep 17 00:00:00 2001 From: Drashna Jaelre Date: Wed, 19 Dec 2018 08:39:24 -0800 Subject: Overhaul Unicode Common functionality (#4325) 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 spacing Co-Authored-By: drashna * Because I missed it! Co-Authored-By: drashna * Fix spacing Co-Authored-By: drashna * SPAAAAAAAAAACing 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 * remove merge artifacts * Unicode common cleanup (#17) * Standardize the Unicode EEPROM code * Remove unicode init from process_record_* functions * Add unicode init to where it belongs: matrix_init_quantum * Move Unicode proccessing to unicode common * Add audio feedback to input mode keys to drive konstantin up a wall * Tap_code cleanup * Update keycodes * Update unicode documentation * Update unicode keycodes for consistency/easier merge * Add Audio Feedback section * Remove Functions from feature page And link to the file instead. Link to specific lines later on. * Fix white spaces Co-Authored-By: drashna * 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 * Improve Cycling documentation * Add Unicode Input method Cycling support (#19) * Standardize the Unicode EEPROM code * Remove unicode init from process_record_* functions * Add unicode init to where it belongs: matrix_init_quantum * Move Unicode proccessing to unicode common * Add audio feedback to input mode keys to drive konstantin up a wall * Tap_code cleanup * Update keycodes * Update unicode documentation * Update unicode keycodes for consistency/easier merge * Add Audio Feedback section * Remove Functions from feature page And link to the file instead. Link to specific lines later on. * Fix white spaces Co-Authored-By: drashna * 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 * Cleanup of RALT code and unicode compilation stuff * Remove else for unicode handling --- quantum/process_keycode/process_unicode_common.c | 200 +++++++++++++++-------- 1 file changed, 135 insertions(+), 65 deletions(-) (limited to 'quantum/process_keycode/process_unicode_common.c') diff --git a/quantum/process_keycode/process_unicode_common.c b/quantum/process_keycode/process_unicode_common.c index 4285d20a1..3286f45b5 100644 --- a/quantum/process_keycode/process_unicode_common.c +++ b/quantum/process_keycode/process_unicode_common.c @@ -16,98 +16,111 @@ #include "process_unicode_common.h" #include "eeprom.h" -#include #include +#include -static uint8_t input_mode; -uint8_t mods; +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 set_unicode_input_mode(uint8_t os_target) { - 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); +#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) { - 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; - } +void set_unicode_input_mode(uint8_t mode) { + unicode_config.input_mode = 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; + __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) { +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); + register_code(UNICODE_OSX_KEY); break; case UC_LNX: register_code(KC_LCTL); register_code(KC_LSFT); - register_code(KC_U); - unregister_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; 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(UNICODE_WINC_KEY); + tap_code(KC_U); + break; } + wait_ms(UNICODE_TYPE_DELAY); } __attribute__((weak)) -void unicode_input_finish (void) { - switch(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: - register_code(KC_SPC); - unregister_code(KC_SPC); - break; +void unicode_input_finish(void) { + switch (unicode_config.input_mode) { + case UC_OSX: + unregister_code(UNICODE_OSX_KEY); + break; + case UC_LNX: + tap_code(KC_SPC); + break; + case UC_WIN: + unregister_code(KC_LALT); + 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)) @@ -124,13 +137,12 @@ 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)); } } 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 @@ -153,3 +165,61 @@ void send_unicode_hex_string(const char *str) { str += n; // Move to the first ' ' (or '\0') after the current token } } + +bool process_unicode_common(uint16_t keycode, keyrecord_t *record) { + if (record->event.pressed) { + switch (keycode) { + case UNICODE_MODE_FORWARD: + cycle_unicode_input_mode(+1); + break; + case UNICODE_MODE_REVERSE: + cycle_unicode_input_mode(-1); + break; + + case UNICODE_MODE_OSX: + set_unicode_input_mode(UC_OSX); +#if defined(AUDIO_ENABLE) && defined(UNICODE_SONG_OSX) + static float song_osx[][2] = UNICODE_SONG_OSX; + PLAY_SONG(song_osx); +#endif + break; + case UNICODE_MODE_LNX: + set_unicode_input_mode(UC_LNX); +#if defined(AUDIO_ENABLE) && defined(UNICODE_SONG_LNX) + static float song_lnx[][2] = UNICODE_SONG_LNX; + PLAY_SONG(song_lnx); +#endif + break; + case UNICODE_MODE_WIN: + set_unicode_input_mode(UC_WIN); +#if defined(AUDIO_ENABLE) && defined(UNICODE_SONG_WIN) + static float song_win[][2] = UNICODE_SONG_WIN; + PLAY_SONG(song_win); +#endif + break; + case UNICODE_MODE_BSD: + set_unicode_input_mode(UC_BSD); +#if defined(AUDIO_ENABLE) && defined(UNICODE_SONG_BSD) + static float song_bsd[][2] = UNICODE_SONG_BSD; + PLAY_SONG(song_bsd); +#endif + break; + case UNICODE_MODE_WINC: + set_unicode_input_mode(UC_WINC); +#if defined(AUDIO_ENABLE) && defined(UNICODE_SONG_WINC) + static float song_winc[][2] = UNICODE_SONG_WINC; + PLAY_SONG(song_winc); +#endif + break; + } + } +#if defined(UNICODE_ENABLE) + return process_unicode(keycode, record); +#elif defined(UNICODEMAP_ENABLE) + return process_unicode_map(keycode, record); +#elif defined(UCIS_ENABLE) + return process_ucis(keycode, record); +#else + return true; +#endif +} -- cgit v1.2.3-24-g4f1b