mirror of
https://github.com/Keychron/qmk_firmware.git
synced 2024-12-27 03:28:46 +06:00
fdeec29636
* Standardize the Unicode EEPROM code * Remove unicode init from process_record_* functions * Add unicode init to where it belongs: matrix_init_quantum * Move Unicode proccessing to unicode common * Add audio feedback to input mode keys to drive konstantin up a wall * Tap_code cleanup * Update keycodes * Update unicode documentation * Update unicode keycodes for consistency/easier merge * Add Audio Feedback section * Remove Functions from feature page And link to the file instead. Link to specific lines later on. * Fix spacing Co-Authored-By: drashna <drashna@live.com> * Because I missed it! Co-Authored-By: drashna <drashna@live.com> * Fix spacing Co-Authored-By: drashna <drashna@live.com> * SPAAAAAAAAAACing Co-Authored-By: drashna <drashna@live.com> * Add BSD for future compatibility * Thought I fixed that! Co-Authored-By: drashna <drashna@live.com> * non-breaking Co-Authored-By: drashna <drashna@live.com> * Considered that Co-Authored-By: drashna <drashna@live.com> * Yuuup Co-Authored-By: drashna <drashna@live.com> * consistency Co-Authored-By: drashna <drashna@live.com> * white spaces .... copied from elsewhere Co-Authored-By: drashna <drashna@live.com> * white spaces Co-Authored-By: drashna <drashna@live.com> * white spaces Co-Authored-By: drashna <drashna@live.com> * Update keycode defines * Fix Linux Song * Update all of the songs * Cleanup * Move and update check to ensure only one unicode method is enabled * Update quantum/quantum_keycodes.h * Update documentation * Wordsmithing and cleanup * Format unicode_common (#13) * case alignment * process_record_unicode_common → process_unicode_common * Move song arrays into function where they're used, align preprocessor directives * Swap the order of UC_WIN and UC_BSD * Update Unicode docs * Reorder Unicode mode stuff to match the order of input mode constants * Fix capitalization in doc subtitle * Readd BSD and OSX_RALT songs * Reword BSD note in docs * Readd BSD keycode description * Reword explanation of input on different platforms * Steal vomindoraan's input mode documentation Co-Authored-By: vomindoraan (vomindoraan@gmail.com) * Willingly give Drashna the rest of my Unicode doc improvements * Wordsmithing Co-Authored-By: drashna <drashna@live.com> * remove merge artifacts * Unicode common cleanup (#17) * Standardize the Unicode EEPROM code * Remove unicode init from process_record_* functions * Add unicode init to where it belongs: matrix_init_quantum * Move Unicode proccessing to unicode common * Add audio feedback to input mode keys to drive konstantin up a wall * Tap_code cleanup * Update keycodes * Update unicode documentation * Update unicode keycodes for consistency/easier merge * Add Audio Feedback section * Remove Functions from feature page And link to the file instead. Link to specific lines later on. * Fix white spaces Co-Authored-By: drashna <drashna@live.com> * Fix spacing Co-Authored-By: drashna <drashna@live.com> * Because I missed it! Co-Authored-By: drashna <drashna@live.com> * Fix spacing Co-Authored-By: drashna <drashna@live.com> * SPAAAAAAAAAACing Co-Authored-By: drashna <drashna@live.com> * white spaces Co-Authored-By: drashna <drashna@live.com> * Add BSD for future compatibility * Thought I fixed that! Co-Authored-By: drashna <drashna@live.com> * non-breaking Co-Authored-By: drashna <drashna@live.com> * Considered that Co-Authored-By: drashna <drashna@live.com> * Yuuup Co-Authored-By: drashna <drashna@live.com> * consistency Co-Authored-By: drashna <drashna@live.com> * white spaces .... copied from elsewhere Co-Authored-By: drashna <drashna@live.com> * white spaces Co-Authored-By: drashna <drashna@live.com> * white spaces Co-Authored-By: drashna <drashna@live.com> * Update keycode defines * Fix Linux Song * Update all of the songs * Cleanup * Move and update check to ensure only one unicode method is enabled * Update quantum/quantum_keycodes.h * Update documentation * Wordsmithing and cleanup * Format unicode_common (#13) * case alignment * process_record_unicode_common → process_unicode_common * Move song arrays into function where they're used, align preprocessor directives * Swap the order of UC_WIN and UC_BSD * Update Unicode docs * Reorder Unicode mode stuff to match the order of input mode constants * Fix capitalization in doc subtitle * Readd BSD and OSX_RALT songs * Reword BSD note in docs * Readd BSD keycode description * Reword explanation of input on different platforms * Steal vomindoraan's input mode documentation Co-Authored-By: vomindoraan (vomindoraan@gmail.com) * Willingly give Drashna the rest of my Unicode doc improvements * Wordsmithing Co-Authored-By: drashna <drashna@live.com> * Rearrange process_unicode_common functions * Make Unicode input mode constants (UC_*) an enum * Simplify unicode_input_start/finish code * Make the key used for WinCompose configurable * Remove UC_OSX_RALT in favor of setting the key with UNICODE_OSX_KEY * Update Unicode input mode doc * Add descriptions and rearrange definitions in process_unicode_common.h * Add registry command to Unicode docs + misc updates * Reword an explanation in Unicode docs * Add TODO comment * Remove trailing whitespace * Improve Cycling documentation * Add Unicode Input method Cycling support (#19) * Standardize the Unicode EEPROM code * Remove unicode init from process_record_* functions * Add unicode init to where it belongs: matrix_init_quantum * Move Unicode proccessing to unicode common * Add audio feedback to input mode keys to drive konstantin up a wall * Tap_code cleanup * Update keycodes * Update unicode documentation * Update unicode keycodes for consistency/easier merge * Add Audio Feedback section * Remove Functions from feature page And link to the file instead. Link to specific lines later on. * Fix white spaces Co-Authored-By: drashna <drashna@live.com> * Fix spacing Co-Authored-By: drashna <drashna@live.com> * Because I missed it! Co-Authored-By: drashna <drashna@live.com> * Fix spacing Co-Authored-By: drashna <drashna@live.com> * SPAAAAAAAAAACing Co-Authored-By: drashna <drashna@live.com> * white spaces Co-Authored-By: drashna <drashna@live.com> * Add BSD for future compatibility * Thought I fixed that! Co-Authored-By: drashna <drashna@live.com> * non-breaking Co-Authored-By: drashna <drashna@live.com> * Considered that Co-Authored-By: drashna <drashna@live.com> * Yuuup Co-Authored-By: drashna <drashna@live.com> * consistency Co-Authored-By: drashna <drashna@live.com> * white spaces .... copied from elsewhere Co-Authored-By: drashna <drashna@live.com> * white spaces Co-Authored-By: drashna <drashna@live.com> * white spaces Co-Authored-By: drashna <drashna@live.com> * Update keycode defines * Fix Linux Song * Update all of the songs * Cleanup * Move and update check to ensure only one unicode method is enabled * Update quantum/quantum_keycodes.h * Update documentation * Wordsmithing and cleanup * Format unicode_common (#13) * case alignment * process_record_unicode_common → process_unicode_common * Move song arrays into function where they're used, align preprocessor directives * Swap the order of UC_WIN and UC_BSD * Update Unicode docs * Reorder Unicode mode stuff to match the order of input mode constants * Fix capitalization in doc subtitle * Readd BSD and OSX_RALT songs * Reword BSD note in docs * Readd BSD keycode description * Reword explanation of input on different platforms * Steal vomindoraan's input mode documentation Co-Authored-By: vomindoraan (vomindoraan@gmail.com) * Willingly give Drashna the rest of my Unicode doc improvements * Wordsmithing Co-Authored-By: drashna <drashna@live.com> * Rearrange process_unicode_common functions * Make Unicode input mode constants (UC_*) an enum * Simplify unicode_input_start/finish code * Make the key used for WinCompose configurable * Remove UC_OSX_RALT in favor of setting the key with UNICODE_OSX_KEY * Update Unicode input mode doc * Add descriptions and rearrange definitions in process_unicode_common.h * Add registry command to Unicode docs + misc updates * Reword an explanation in Unicode docs * Add TODO comment * Add cycle_unicode_input_mode and UNICODE_SELECTED_MODES macro * Add an option for making cycle changes persistent * Add debug prints to functions that change input_mode * Use cycle_unicode_input_mode in whitefox/konstantin * Add persist_unicode_input_mode function * Add offset to cycle to allow stepping in reverse * Add keycodes: UNICODE_MODE_FORWARD, UNICODE_MODE_REVERSE Aliases: UC_MOD, UC_RMOD (respectively) * REVERT ME: Undo changes to whitefox/konstantin to avoid conflicts * Fix wrong constant name * Revert "REVERT ME: Undo changes to whitefox/konstantin to avoid conflicts" This reverts commit 42676bf251fc8e3823f5e614dad6e510ba47a2f3. * Change dprintf text * Give selected modes priority over EEPROM when !UNICODE_CYCLE_PERSIST * Remove trailing whitespace * Cleanup of RALT code and unicode compilation stuff * Remove else for unicode handling
158 lines
3.6 KiB
C
158 lines
3.6 KiB
C
/* Copyright 2017 Jack Humbert
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, either version 2 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#include "process_ucis.h"
|
|
|
|
qk_ucis_state_t qk_ucis_state;
|
|
|
|
void qk_ucis_start(void) {
|
|
qk_ucis_state.count = 0;
|
|
qk_ucis_state.in_progress = true;
|
|
|
|
qk_ucis_start_user();
|
|
}
|
|
|
|
__attribute__((weak))
|
|
void qk_ucis_start_user(void) {
|
|
unicode_input_start();
|
|
register_hex(0x2328);
|
|
unicode_input_finish();
|
|
}
|
|
|
|
__attribute__((weak))
|
|
void qk_ucis_success(uint8_t symbol_index) {
|
|
}
|
|
|
|
static bool is_uni_seq(char *seq) {
|
|
uint8_t i;
|
|
|
|
for (i = 0; seq[i]; i++) {
|
|
uint16_t code;
|
|
if (('1' <= seq[i]) && (seq[i] <= '0'))
|
|
code = seq[i] - '1' + KC_1;
|
|
else
|
|
code = seq[i] - 'a' + KC_A;
|
|
|
|
if (i > qk_ucis_state.count || qk_ucis_state.codes[i] != code)
|
|
return false;
|
|
}
|
|
|
|
return (qk_ucis_state.codes[i] == KC_ENT ||
|
|
qk_ucis_state.codes[i] == KC_SPC);
|
|
}
|
|
|
|
__attribute__((weak))
|
|
void qk_ucis_symbol_fallback (void) {
|
|
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);
|
|
}
|
|
}
|
|
|
|
void register_ucis(const char *hex) {
|
|
for(int i = 0; hex[i]; i++) {
|
|
uint8_t kc = 0;
|
|
char c = hex[i];
|
|
|
|
switch (c) {
|
|
case '0':
|
|
kc = KC_0;
|
|
break;
|
|
case '1' ... '9':
|
|
kc = c - '1' + KC_1;
|
|
break;
|
|
case 'a' ... 'f':
|
|
kc = c - 'a' + KC_A;
|
|
break;
|
|
case 'A' ... 'F':
|
|
kc = c - 'A' + KC_A;
|
|
break;
|
|
}
|
|
|
|
if (kc) {
|
|
register_code (kc);
|
|
unregister_code (kc);
|
|
wait_ms (UNICODE_TYPE_DELAY);
|
|
}
|
|
}
|
|
}
|
|
|
|
bool process_ucis (uint16_t keycode, keyrecord_t *record) {
|
|
uint8_t i;
|
|
|
|
if (!qk_ucis_state.in_progress)
|
|
return true;
|
|
|
|
if (qk_ucis_state.count >= UCIS_MAX_SYMBOL_LENGTH &&
|
|
!(keycode == KC_BSPC || keycode == KC_ESC || keycode == KC_SPC || keycode == KC_ENT)) {
|
|
return false;
|
|
}
|
|
|
|
if (!record->event.pressed)
|
|
return true;
|
|
|
|
qk_ucis_state.codes[qk_ucis_state.count] = keycode;
|
|
qk_ucis_state.count++;
|
|
|
|
if (keycode == KC_BSPC) {
|
|
if (qk_ucis_state.count >= 2) {
|
|
qk_ucis_state.count -= 2;
|
|
return true;
|
|
} else {
|
|
qk_ucis_state.count--;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
if (keycode == KC_ENT || keycode == KC_SPC || keycode == KC_ESC) {
|
|
bool symbol_found = false;
|
|
|
|
for (i = qk_ucis_state.count; i > 0; i--) {
|
|
register_code (KC_BSPC);
|
|
unregister_code (KC_BSPC);
|
|
wait_ms(UNICODE_TYPE_DELAY);
|
|
}
|
|
|
|
if (keycode == KC_ESC) {
|
|
qk_ucis_state.in_progress = false;
|
|
return false;
|
|
}
|
|
|
|
unicode_input_start();
|
|
for (i = 0; ucis_symbol_table[i].symbol; i++) {
|
|
if (is_uni_seq (ucis_symbol_table[i].symbol)) {
|
|
symbol_found = true;
|
|
register_ucis(ucis_symbol_table[i].code + 2);
|
|
break;
|
|
}
|
|
}
|
|
if (!symbol_found) {
|
|
qk_ucis_symbol_fallback();
|
|
}
|
|
unicode_input_finish();
|
|
|
|
if (symbol_found) {
|
|
qk_ucis_success(i);
|
|
}
|
|
|
|
qk_ucis_state.in_progress = false;
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|