diff options
author | Drashna Jaelre <drashna@live.com> | 2018-12-19 08:39:24 -0800 |
---|---|---|
committer | MechMerlin <30334081+mechmerlin@users.noreply.github.com> | 2018-12-19 08:39:24 -0800 |
commit | fdeec296369c0995bad1117e50946b2df84f35e4 (patch) | |
tree | c20ca5d0e302b189298d37b3abb97c4f37f5b606 /quantum/process_keycode/process_unicode_common.c | |
parent | 40bf3a2ce9ec781cc2ff7218f909ffdbece44e97 (diff) | |
download | qmk_firmware-fdeec296369c0995bad1117e50946b2df84f35e4.tar.gz qmk_firmware-fdeec296369c0995bad1117e50946b2df84f35e4.zip |
Overhaul Unicode Common functionality (#4325)
* Standardize the Unicode EEPROM code
* Remove unicode init from process_record_* functions
* Add unicode init to where it belongs: matrix_init_quantum
* Move Unicode proccessing to unicode common
* Add audio feedback to input mode keys to drive konstantin up a wall
* Tap_code cleanup
* Update keycodes
* Update unicode documentation
* Update unicode keycodes for consistency/easier merge
* Add Audio Feedback section
* Remove Functions from feature page
And link to the file instead. Link to specific lines later on.
* Fix spacing
Co-Authored-By: drashna <drashna@live.com>
* Because I missed it!
Co-Authored-By: drashna <drashna@live.com>
* Fix spacing
Co-Authored-By: drashna <drashna@live.com>
* SPAAAAAAAAAACing
Co-Authored-By: drashna <drashna@live.com>
* Add BSD for future compatibility
* Thought I fixed that!
Co-Authored-By: drashna <drashna@live.com>
* non-breaking
Co-Authored-By: drashna <drashna@live.com>
* Considered that
Co-Authored-By: drashna <drashna@live.com>
* Yuuup
Co-Authored-By: drashna <drashna@live.com>
* consistency
Co-Authored-By: drashna <drashna@live.com>
* white spaces .... copied from elsewhere
Co-Authored-By: drashna <drashna@live.com>
* white spaces
Co-Authored-By: drashna <drashna@live.com>
* white spaces
Co-Authored-By: drashna <drashna@live.com>
* Update keycode defines
* Fix Linux Song
* Update all of the songs
* Cleanup
* Move and update check to ensure only one unicode method is enabled
* Update quantum/quantum_keycodes.h
* Update documentation
* Wordsmithing and cleanup
* Format unicode_common (#13)
* case alignment
* process_record_unicode_common → process_unicode_common
* Move song arrays into function where they're used, align preprocessor directives
* Swap the order of UC_WIN and UC_BSD
* Update Unicode docs
* Reorder Unicode mode stuff to match the order of input mode constants
* Fix capitalization in doc subtitle
* Readd BSD and OSX_RALT songs
* Reword BSD note in docs
* Readd BSD keycode description
* Reword explanation of input on different platforms
* Steal vomindoraan's input mode documentation
Co-Authored-By: vomindoraan (vomindoraan@gmail.com)
* Willingly give Drashna the rest of my Unicode doc improvements
* Wordsmithing
Co-Authored-By: drashna <drashna@live.com>
* remove merge artifacts
* Unicode common cleanup (#17)
* Standardize the Unicode EEPROM code
* Remove unicode init from process_record_* functions
* Add unicode init to where it belongs: matrix_init_quantum
* Move Unicode proccessing to unicode common
* Add audio feedback to input mode keys to drive konstantin up a wall
* Tap_code cleanup
* Update keycodes
* Update unicode documentation
* Update unicode keycodes for consistency/easier merge
* Add Audio Feedback section
* Remove Functions from feature page
And link to the file instead. Link to specific lines later on.
* Fix white spaces
Co-Authored-By: drashna <drashna@live.com>
* Fix spacing
Co-Authored-By: drashna <drashna@live.com>
* Because I missed it!
Co-Authored-By: drashna <drashna@live.com>
* Fix spacing
Co-Authored-By: drashna <drashna@live.com>
* SPAAAAAAAAAACing
Co-Authored-By: drashna <drashna@live.com>
* white spaces
Co-Authored-By: drashna <drashna@live.com>
* Add BSD for future compatibility
* Thought I fixed that!
Co-Authored-By: drashna <drashna@live.com>
* non-breaking
Co-Authored-By: drashna <drashna@live.com>
* Considered that
Co-Authored-By: drashna <drashna@live.com>
* Yuuup
Co-Authored-By: drashna <drashna@live.com>
* consistency
Co-Authored-By: drashna <drashna@live.com>
* white spaces .... copied from elsewhere
Co-Authored-By: drashna <drashna@live.com>
* white spaces
Co-Authored-By: drashna <drashna@live.com>
* white spaces
Co-Authored-By: drashna <drashna@live.com>
* Update keycode defines
* Fix Linux Song
* Update all of the songs
* Cleanup
* Move and update check to ensure only one unicode method is enabled
* Update quantum/quantum_keycodes.h
* Update documentation
* Wordsmithing and cleanup
* Format unicode_common (#13)
* case alignment
* process_record_unicode_common → process_unicode_common
* Move song arrays into function where they're used, align preprocessor directives
* Swap the order of UC_WIN and UC_BSD
* Update Unicode docs
* Reorder Unicode mode stuff to match the order of input mode constants
* Fix capitalization in doc subtitle
* Readd BSD and OSX_RALT songs
* Reword BSD note in docs
* Readd BSD keycode description
* Reword explanation of input on different platforms
* Steal vomindoraan's input mode documentation
Co-Authored-By: vomindoraan (vomindoraan@gmail.com)
* Willingly give Drashna the rest of my Unicode doc improvements
* Wordsmithing
Co-Authored-By: drashna <drashna@live.com>
* Rearrange process_unicode_common functions
* Make Unicode input mode constants (UC_*) an enum
* Simplify unicode_input_start/finish code
* Make the key used for WinCompose configurable
* Remove UC_OSX_RALT in favor of setting the key with UNICODE_OSX_KEY
* Update Unicode input mode doc
* Add descriptions and rearrange definitions in process_unicode_common.h
* Add registry command to Unicode docs + misc updates
* Reword an explanation in Unicode docs
* Add TODO comment
* Remove trailing whitespace
* Improve Cycling documentation
* Add Unicode Input method Cycling support (#19)
* Standardize the Unicode EEPROM code
* Remove unicode init from process_record_* functions
* Add unicode init to where it belongs: matrix_init_quantum
* Move Unicode proccessing to unicode common
* Add audio feedback to input mode keys to drive konstantin up a wall
* Tap_code cleanup
* Update keycodes
* Update unicode documentation
* Update unicode keycodes for consistency/easier merge
* Add Audio Feedback section
* Remove Functions from feature page
And link to the file instead. Link to specific lines later on.
* Fix white spaces
Co-Authored-By: drashna <drashna@live.com>
* Fix spacing
Co-Authored-By: drashna <drashna@live.com>
* Because I missed it!
Co-Authored-By: drashna <drashna@live.com>
* Fix spacing
Co-Authored-By: drashna <drashna@live.com>
* SPAAAAAAAAAACing
Co-Authored-By: drashna <drashna@live.com>
* white spaces
Co-Authored-By: drashna <drashna@live.com>
* Add BSD for future compatibility
* Thought I fixed that!
Co-Authored-By: drashna <drashna@live.com>
* non-breaking
Co-Authored-By: drashna <drashna@live.com>
* Considered that
Co-Authored-By: drashna <drashna@live.com>
* Yuuup
Co-Authored-By: drashna <drashna@live.com>
* consistency
Co-Authored-By: drashna <drashna@live.com>
* white spaces .... copied from elsewhere
Co-Authored-By: drashna <drashna@live.com>
* white spaces
Co-Authored-By: drashna <drashna@live.com>
* white spaces
Co-Authored-By: drashna <drashna@live.com>
* Update keycode defines
* Fix Linux Song
* Update all of the songs
* Cleanup
* Move and update check to ensure only one unicode method is enabled
* Update quantum/quantum_keycodes.h
* Update documentation
* Wordsmithing and cleanup
* Format unicode_common (#13)
* case alignment
* process_record_unicode_common → process_unicode_common
* Move song arrays into function where they're used, align preprocessor directives
* Swap the order of UC_WIN and UC_BSD
* Update Unicode docs
* Reorder Unicode mode stuff to match the order of input mode constants
* Fix capitalization in doc subtitle
* Readd BSD and OSX_RALT songs
* Reword BSD note in docs
* Readd BSD keycode description
* Reword explanation of input on different platforms
* Steal vomindoraan's input mode documentation
Co-Authored-By: vomindoraan (vomindoraan@gmail.com)
* Willingly give Drashna the rest of my Unicode doc improvements
* Wordsmithing
Co-Authored-By: drashna <drashna@live.com>
* Rearrange process_unicode_common functions
* Make Unicode input mode constants (UC_*) an enum
* Simplify unicode_input_start/finish code
* Make the key used for WinCompose configurable
* Remove UC_OSX_RALT in favor of setting the key with UNICODE_OSX_KEY
* Update Unicode input mode doc
* Add descriptions and rearrange definitions in process_unicode_common.h
* Add registry command to Unicode docs + misc updates
* Reword an explanation in Unicode docs
* Add TODO comment
* Add cycle_unicode_input_mode and UNICODE_SELECTED_MODES macro
* Add an option for making cycle changes persistent
* Add debug prints to functions that change input_mode
* Use cycle_unicode_input_mode in whitefox/konstantin
* Add persist_unicode_input_mode function
* Add offset to cycle to allow stepping in reverse
* Add keycodes: UNICODE_MODE_FORWARD, UNICODE_MODE_REVERSE
Aliases: UC_MOD, UC_RMOD (respectively)
* REVERT ME: Undo changes to whitefox/konstantin to avoid conflicts
* Fix wrong constant name
* Revert "REVERT ME: Undo changes to whitefox/konstantin to avoid conflicts"
This reverts commit 42676bf251fc8e3823f5e614dad6e510ba47a2f3.
* Change dprintf text
* Give selected modes priority over EEPROM when !UNICODE_CYCLE_PERSIST
* Remove trailing whitespace
* Cleanup of RALT code and unicode compilation stuff
* Remove else for unicode handling
Diffstat (limited to 'quantum/process_keycode/process_unicode_common.c')
-rw-r--r-- | quantum/process_keycode/process_unicode_common.c | 200 |
1 files changed, 135 insertions, 65 deletions
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 @@ | |||
16 | 16 | ||
17 | #include "process_unicode_common.h" | 17 | #include "process_unicode_common.h" |
18 | #include "eeprom.h" | 18 | #include "eeprom.h" |
19 | #include <string.h> | ||
20 | #include <ctype.h> | 19 | #include <ctype.h> |
20 | #include <string.h> | ||
21 | 21 | ||
22 | static uint8_t input_mode; | 22 | unicode_config_t unicode_config; |
23 | uint8_t mods; | 23 | #if UNICODE_SELECTED_MODES != -1 |
24 | static uint8_t selected[] = { UNICODE_SELECTED_MODES }; | ||
25 | static uint8_t selected_count = sizeof selected / sizeof *selected; | ||
26 | static uint8_t selected_index; | ||
27 | #endif | ||
24 | 28 | ||
25 | void set_unicode_input_mode(uint8_t os_target) { | 29 | void unicode_input_mode_init(void) { |
26 | input_mode = os_target; | 30 | unicode_config.raw = eeprom_read_byte(EECONFIG_UNICODEMODE); |
27 | eeprom_update_byte(EECONFIG_UNICODEMODE, os_target); | 31 | #if UNICODE_SELECTED_MODES != -1 |
32 | #if UNICODE_CYCLE_PERSIST | ||
33 | // Find input_mode in selected modes | ||
34 | uint8_t i; | ||
35 | for (i = 0; i < selected_count; i++) { | ||
36 | if (selected[i] == unicode_config.input_mode) { | ||
37 | selected_index = i; | ||
38 | break; | ||
39 | } | ||
40 | } | ||
41 | if (i == selected_count) { | ||
42 | // Not found: input_mode isn't selected, change to one that is | ||
43 | unicode_config.input_mode = selected[selected_index = 0]; | ||
44 | } | ||
45 | #else | ||
46 | // Always change to the first selected input mode | ||
47 | unicode_config.input_mode = selected[selected_index = 0]; | ||
48 | #endif | ||
49 | #endif | ||
50 | dprintf("Unicode input mode init to: %u\n", unicode_config.input_mode); | ||
28 | } | 51 | } |
29 | 52 | ||
30 | uint8_t get_unicode_input_mode(void) { | 53 | uint8_t get_unicode_input_mode(void) { |
31 | return input_mode; | 54 | return unicode_config.input_mode; |
32 | } | 55 | } |
33 | 56 | ||
34 | void unicode_input_mode_init(void) { | 57 | void set_unicode_input_mode(uint8_t mode) { |
35 | static bool first_flag = false; | 58 | unicode_config.input_mode = mode; |
36 | if (!first_flag) { | 59 | persist_unicode_input_mode(); |
37 | input_mode = eeprom_read_byte(EECONFIG_UNICODEMODE); | 60 | dprintf("Unicode input mode set to: %u\n", unicode_config.input_mode); |
38 | first_flag = true; | 61 | } |
39 | } | 62 | |
63 | void cycle_unicode_input_mode(uint8_t offset) { | ||
64 | #if UNICODE_SELECTED_MODES != -1 | ||
65 | selected_index = (selected_index + offset) % selected_count; | ||
66 | unicode_config.input_mode = selected[selected_index]; | ||
67 | #if UNICODE_CYCLE_PERSIST | ||
68 | persist_unicode_input_mode(); | ||
69 | #endif | ||
70 | dprintf("Unicode input mode cycle to: %u\n", unicode_config.input_mode); | ||
71 | #endif | ||
72 | } | ||
73 | |||
74 | void persist_unicode_input_mode(void) { | ||
75 | eeprom_update_byte(EECONFIG_UNICODEMODE, unicode_config.input_mode); | ||
40 | } | 76 | } |
41 | 77 | ||
78 | static uint8_t saved_mods; | ||
79 | |||
42 | __attribute__((weak)) | 80 | __attribute__((weak)) |
43 | void unicode_input_start (void) { | 81 | void unicode_input_start(void) { |
44 | // save current mods | 82 | saved_mods = get_mods(); // Save current mods |
45 | mods = keyboard_report->mods; | 83 | clear_mods(); // Unregister mods to start from a clean state |
46 | 84 | ||
47 | // unregister all mods to start from clean state | 85 | switch (unicode_config.input_mode) { |
48 | if (mods & MOD_BIT(KC_LSFT)) unregister_code(KC_LSFT); | ||
49 | if (mods & MOD_BIT(KC_RSFT)) unregister_code(KC_RSFT); | ||
50 | if (mods & MOD_BIT(KC_LCTL)) unregister_code(KC_LCTL); | ||
51 | if (mods & MOD_BIT(KC_RCTL)) unregister_code(KC_RCTL); | ||
52 | if (mods & MOD_BIT(KC_LALT)) unregister_code(KC_LALT); | ||
53 | if (mods & MOD_BIT(KC_RALT)) unregister_code(KC_RALT); | ||
54 | if (mods & MOD_BIT(KC_LGUI)) unregister_code(KC_LGUI); | ||
55 | if (mods & MOD_BIT(KC_RGUI)) unregister_code(KC_RGUI); | ||
56 | |||
57 | switch(input_mode) { | ||
58 | case UC_OSX: | 86 | case UC_OSX: |
59 | register_code(KC_LALT); | 87 | register_code(UNICODE_OSX_KEY); |
60 | break; | ||
61 | case UC_OSX_RALT: | ||
62 | register_code(KC_RALT); | ||
63 | break; | 88 | break; |
64 | case UC_LNX: | 89 | case UC_LNX: |
65 | register_code(KC_LCTL); | 90 | register_code(KC_LCTL); |
66 | register_code(KC_LSFT); | 91 | register_code(KC_LSFT); |
67 | register_code(KC_U); | 92 | tap_code(KC_U); // TODO: Replace with tap_code16(LCTL(LSFT(KC_U))); and test |
68 | unregister_code(KC_U); | ||
69 | unregister_code(KC_LSFT); | 93 | unregister_code(KC_LSFT); |
70 | unregister_code(KC_LCTL); | 94 | unregister_code(KC_LCTL); |
71 | break; | 95 | break; |
72 | case UC_WIN: | 96 | case UC_WIN: |
73 | register_code(KC_LALT); | 97 | register_code(KC_LALT); |
74 | register_code(KC_PPLS); | 98 | tap_code(KC_PPLS); |
75 | unregister_code(KC_PPLS); | ||
76 | break; | 99 | break; |
77 | case UC_WINC: | 100 | case UC_WINC: |
78 | register_code(KC_RALT); | 101 | tap_code(UNICODE_WINC_KEY); |
79 | unregister_code(KC_RALT); | 102 | tap_code(KC_U); |
80 | register_code(KC_U); | 103 | break; |
81 | unregister_code(KC_U); | ||
82 | } | 104 | } |
105 | |||
83 | wait_ms(UNICODE_TYPE_DELAY); | 106 | wait_ms(UNICODE_TYPE_DELAY); |
84 | } | 107 | } |
85 | 108 | ||
86 | __attribute__((weak)) | 109 | __attribute__((weak)) |
87 | void unicode_input_finish (void) { | 110 | void unicode_input_finish(void) { |
88 | switch(input_mode) { | 111 | switch (unicode_config.input_mode) { |
89 | case UC_OSX: | 112 | case UC_OSX: |
90 | case UC_WIN: | 113 | unregister_code(UNICODE_OSX_KEY); |
91 | unregister_code(KC_LALT); | 114 | break; |
92 | break; | 115 | case UC_LNX: |
93 | case UC_OSX_RALT: | 116 | tap_code(KC_SPC); |
94 | unregister_code(KC_RALT); | 117 | break; |
95 | break; | 118 | case UC_WIN: |
96 | case UC_LNX: | 119 | unregister_code(KC_LALT); |
97 | register_code(KC_SPC); | 120 | break; |
98 | unregister_code(KC_SPC); | ||
99 | break; | ||
100 | } | 121 | } |
101 | 122 | ||
102 | // reregister previously set mods | 123 | set_mods(saved_mods); // Reregister previously set mods |
103 | if (mods & MOD_BIT(KC_LSFT)) register_code(KC_LSFT); | ||
104 | if (mods & MOD_BIT(KC_RSFT)) register_code(KC_RSFT); | ||
105 | if (mods & MOD_BIT(KC_LCTL)) register_code(KC_LCTL); | ||
106 | if (mods & MOD_BIT(KC_RCTL)) register_code(KC_RCTL); | ||
107 | if (mods & MOD_BIT(KC_LALT)) register_code(KC_LALT); | ||
108 | if (mods & MOD_BIT(KC_RALT)) register_code(KC_RALT); | ||
109 | if (mods & MOD_BIT(KC_LGUI)) register_code(KC_LGUI); | ||
110 | if (mods & MOD_BIT(KC_RGUI)) register_code(KC_RGUI); | ||
111 | } | 124 | } |
112 | 125 | ||
113 | __attribute__((weak)) | 126 | __attribute__((weak)) |
@@ -124,13 +137,12 @@ uint16_t hex_to_keycode(uint8_t hex) { | |||
124 | void register_hex(uint16_t hex) { | 137 | void register_hex(uint16_t hex) { |
125 | for(int i = 3; i >= 0; i--) { | 138 | for(int i = 3; i >= 0; i--) { |
126 | uint8_t digit = ((hex >> (i*4)) & 0xF); | 139 | uint8_t digit = ((hex >> (i*4)) & 0xF); |
127 | register_code(hex_to_keycode(digit)); | 140 | tap_code(hex_to_keycode(digit)); |
128 | unregister_code(hex_to_keycode(digit)); | ||
129 | } | 141 | } |
130 | } | 142 | } |
131 | 143 | ||
132 | void send_unicode_hex_string(const char *str) { | 144 | void send_unicode_hex_string(const char *str) { |
133 | if (!str) { return; } // Safety net | 145 | if (!str) { return; } |
134 | 146 | ||
135 | while (*str) { | 147 | while (*str) { |
136 | // Find the next code point (token) in the string | 148 | // Find the next code point (token) in the string |
@@ -153,3 +165,61 @@ void send_unicode_hex_string(const char *str) { | |||
153 | str += n; // Move to the first ' ' (or '\0') after the current token | 165 | str += n; // Move to the first ' ' (or '\0') after the current token |
154 | } | 166 | } |
155 | } | 167 | } |
168 | |||
169 | bool process_unicode_common(uint16_t keycode, keyrecord_t *record) { | ||
170 | if (record->event.pressed) { | ||
171 | switch (keycode) { | ||
172 | case UNICODE_MODE_FORWARD: | ||
173 | cycle_unicode_input_mode(+1); | ||
174 | break; | ||
175 | case UNICODE_MODE_REVERSE: | ||
176 | cycle_unicode_input_mode(-1); | ||
177 | break; | ||
178 | |||
179 | case UNICODE_MODE_OSX: | ||
180 | set_unicode_input_mode(UC_OSX); | ||
181 | #if defined(AUDIO_ENABLE) && defined(UNICODE_SONG_OSX) | ||
182 | static float song_osx[][2] = UNICODE_SONG_OSX; | ||
183 | PLAY_SONG(song_osx); | ||
184 | #endif | ||
185 | break; | ||
186 | case UNICODE_MODE_LNX: | ||
187 | set_unicode_input_mode(UC_LNX); | ||
188 | #if defined(AUDIO_ENABLE) && defined(UNICODE_SONG_LNX) | ||
189 | static float song_lnx[][2] = UNICODE_SONG_LNX; | ||
190 | PLAY_SONG(song_lnx); | ||
191 | #endif | ||
192 | break; | ||
193 | case UNICODE_MODE_WIN: | ||
194 | set_unicode_input_mode(UC_WIN); | ||
195 | #if defined(AUDIO_ENABLE) && defined(UNICODE_SONG_WIN) | ||
196 | static float song_win[][2] = UNICODE_SONG_WIN; | ||
197 | PLAY_SONG(song_win); | ||
198 | #endif | ||
199 | break; | ||
200 | case UNICODE_MODE_BSD: | ||
201 | set_unicode_input_mode(UC_BSD); | ||
202 | #if defined(AUDIO_ENABLE) && defined(UNICODE_SONG_BSD) | ||
203 | static float song_bsd[][2] = UNICODE_SONG_BSD; | ||
204 | PLAY_SONG(song_bsd); | ||
205 | #endif | ||
206 | break; | ||
207 | case UNICODE_MODE_WINC: | ||
208 | set_unicode_input_mode(UC_WINC); | ||
209 | #if defined(AUDIO_ENABLE) && defined(UNICODE_SONG_WINC) | ||
210 | static float song_winc[][2] = UNICODE_SONG_WINC; | ||
211 | PLAY_SONG(song_winc); | ||
212 | #endif | ||
213 | break; | ||
214 | } | ||
215 | } | ||
216 | #if defined(UNICODE_ENABLE) | ||
217 | return process_unicode(keycode, record); | ||
218 | #elif defined(UNICODEMAP_ENABLE) | ||
219 | return process_unicode_map(keycode, record); | ||
220 | #elif defined(UCIS_ENABLE) | ||
221 | return process_ucis(keycode, record); | ||
222 | #else | ||
223 | return true; | ||
224 | #endif | ||
225 | } | ||