diff options
author | Jack Humbert <jack.humb@gmail.com> | 2016-05-18 23:47:16 -0400 |
---|---|---|
committer | Jack Humbert <jack.humb@gmail.com> | 2016-05-18 23:47:16 -0400 |
commit | b732b79b49b098dba8e14493c745075f336747d8 (patch) | |
tree | 069f529df73ba8bfbcf7003f5ddd3987ecaadc57 /quantum/quantum.c | |
parent | bf545061f2a71b054ccdca6f6261bb7c2ffa4957 (diff) | |
download | qmk_firmware-b732b79b49b098dba8e14493c745075f336747d8.tar.gz qmk_firmware-b732b79b49b098dba8e14493c745075f336747d8.zip |
adapts unicode to quantum.c (#333)
* Unicode
to have unicode input you need to:
- set your OS input method to UNICODE if needed
- enable unicode in your makefile
- copy the action_function from
keyboard/planck/keymaps/unicode/unicode.c to your keymap.c
set the target OS method in your keymap.c: void matrix_init_user() {
set_unicode_mode(UC_OSX); } you can then switch when you want with:
set_unicode_mode(UC_OSX); set_unicode_mode(UC_LNX);
set_unicode_mode(UC_WIN);
put some unicode codes in your keymap like so: UC(0x0061)
I did change the bit mask in quantum/keymap_common.c and .h
I’m afraid we will need uint32 to get a total support for all unicode
tables or relocate the handler as @mbarkhau did.
* rearranges keycode values, hooks-up unicode
* removes extra lalt ref
* adds unicode shortcuts and example
Diffstat (limited to 'quantum/quantum.c')
-rw-r--r-- | quantum/quantum.c | 79 |
1 files changed, 72 insertions, 7 deletions
diff --git a/quantum/quantum.c b/quantum/quantum.c index e4d7b91852..1e91ac04a4 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c @@ -23,6 +23,18 @@ int offset = 7; #ifdef AUDIO_ENABLE bool music_activated = false; + float music_scale[][2] = SONG(MUSIC_SCALE_SOUND); + + // music sequencer + static bool music_sequence_recording = false; + static bool music_sequence_playing = false; + static float music_sequence[16] = {0}; + static uint8_t music_sequence_count = 0; + static uint8_t music_sequence_position = 0; + + static uint16_t music_sequence_timer = 0; + static uint16_t music_sequence_interval = 100; + #endif #ifdef MIDI_ENABLE @@ -44,6 +56,10 @@ uint8_t chord_keys[CHORDING_MAX] = {0}; uint8_t chord_key_count = 0; uint8_t chord_key_down = 0; +#ifdef UNICODE_ENABLE + static uint8_t input_mode; +#endif + bool keys_chord(uint8_t keys[]) { uint8_t keys_size = sizeof(keys)/sizeof(keys[0]); bool pass = true; @@ -66,14 +82,25 @@ bool keys_chord(uint8_t keys[]) { return (pass && (in == keys_size)); } -static bool music_sequence_recording = false; -static bool music_sequence_playing = false; -static float music_sequence[16] = {0}; -static uint8_t music_sequence_count = 0; -static uint8_t music_sequence_position = 0; +#ifdef UNICODE_ENABLE + +uint16_t hex_to_keycode(uint8_t hex) +{ + if (hex == 0x0) { + return KC_0; + } else if (hex < 0xA) { + return KC_1 + (hex - 0x1); + } else { + return KC_A + (hex - 0xA); + } +} + +void set_unicode_mode(uint8_t os_target) +{ + input_mode = os_target; +} -static uint16_t music_sequence_timer = 0; -static uint16_t music_sequence_interval = 100; +#endif bool process_record_quantum(keyrecord_t *record) { @@ -347,6 +374,44 @@ bool process_record_quantum(keyrecord_t *record) { #endif +#ifdef UNICODE_ENABLE + + if (keycode > UNICODE(0) && record->event.pressed) { + uint16_t unicode = keycode & 0x7FFF; + switch(input_mode) { + case UC_OSX: + register_code(KC_LALT); + break; + case UC_LNX: + register_code(KC_LCTL); + register_code(KC_LSFT); + register_code(KC_U); + unregister_code(KC_U); + break; + case UC_WIN: + register_code(KC_LALT); + register_code(KC_PPLS); + unregister_code(KC_PPLS); + break; + } + for(int i = 3; i >= 0; i--) { + uint8_t digit = ((unicode >> (i*4)) & 0xF); + register_code(hex_to_keycode(digit)); + unregister_code(hex_to_keycode(digit)); + } + switch(input_mode) { + case UC_OSX: + case UC_WIN: + unregister_code(KC_LALT); + break; + case UC_LNX: + unregister_code(KC_LCTL); + unregister_code(KC_LSFT); + break; + } + } + +#endif return process_action_kb(record); } |