diff options
| author | Gergely Nagy <algernon@madhouse-project.org> | 2016-08-13 10:43:22 +0200 |
|---|---|---|
| committer | Gergely Nagy <algernon@madhouse-project.org> | 2016-08-15 10:08:53 +0200 |
| commit | 63e5782d2cdf0ee282ad434c773463d9da9db6b3 (patch) | |
| tree | c8d95a1ea486d13c18322c007f94dd570f569179 /quantum/process_keycode/process_unicode.c | |
| parent | bc8976d27781a45c735eb98d3110e7df6f8a0bad (diff) | |
| download | qmk_firmware-63e5782d2cdf0ee282ad434c773463d9da9db6b3.tar.gz qmk_firmware-63e5782d2cdf0ee282ad434c773463d9da9db6b3.zip | |
process_unicode: Small refactor & linux fix
This moves the unicode input start / end sequences into their own
functions, so keymaps and other functionality can build on it too.
At the same time, it changes how the Linux variant works, to match
reality: CTRL+SHIFT must be unregistered too, and we close the thing
with a Space instead.
Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
Diffstat (limited to 'quantum/process_keycode/process_unicode.c')
| -rw-r--r-- | quantum/process_keycode/process_unicode.c | 76 |
1 files changed, 45 insertions, 31 deletions
diff --git a/quantum/process_keycode/process_unicode.c b/quantum/process_keycode/process_unicode.c index 3fcac15ce..55e47f179 100644 --- a/quantum/process_keycode/process_unicode.c +++ b/quantum/process_keycode/process_unicode.c | |||
| @@ -18,40 +18,54 @@ void set_unicode_input_mode(uint8_t os_target) | |||
| 18 | input_mode = os_target; | 18 | input_mode = os_target; |
| 19 | } | 19 | } |
| 20 | 20 | ||
| 21 | void unicode_input_start (void) { | ||
| 22 | switch(input_mode) { | ||
| 23 | case UC_OSX: | ||
| 24 | register_code(KC_LALT); | ||
| 25 | break; | ||
| 26 | case UC_LNX: | ||
| 27 | register_code(KC_LCTL); | ||
| 28 | register_code(KC_LSFT); | ||
| 29 | register_code(KC_U); | ||
| 30 | unregister_code(KC_U); | ||
| 31 | unregister_code(KC_LSFT); | ||
| 32 | unregister_code(KC_LCTL); | ||
| 33 | break; | ||
| 34 | case UC_WIN: | ||
| 35 | register_code(KC_LALT); | ||
| 36 | register_code(KC_PPLS); | ||
| 37 | unregister_code(KC_PPLS); | ||
| 38 | break; | ||
| 39 | } | ||
| 40 | } | ||
| 41 | |||
| 42 | void unicode_input_finish (void) { | ||
| 43 | switch(input_mode) { | ||
| 44 | case UC_OSX: | ||
| 45 | case UC_WIN: | ||
| 46 | unregister_code(KC_LALT); | ||
| 47 | break; | ||
| 48 | case UC_LNX: | ||
| 49 | register_code(KC_SPC); | ||
| 50 | unregister_code(KC_SPC); | ||
| 51 | break; | ||
| 52 | } | ||
| 53 | } | ||
| 54 | |||
| 55 | void register_hex(uint16_t hex) { | ||
| 56 | for(int i = 3; i >= 0; i--) { | ||
| 57 | uint8_t digit = ((hex >> (i*4)) & 0xF); | ||
| 58 | register_code(hex_to_keycode(digit)); | ||
| 59 | unregister_code(hex_to_keycode(digit)); | ||
| 60 | } | ||
| 61 | } | ||
| 62 | |||
| 21 | bool process_unicode(uint16_t keycode, keyrecord_t *record) { | 63 | bool process_unicode(uint16_t keycode, keyrecord_t *record) { |
| 22 | if (keycode > QK_UNICODE && record->event.pressed) { | 64 | if (keycode > QK_UNICODE && record->event.pressed) { |
| 23 | uint16_t unicode = keycode & 0x7FFF; | 65 | uint16_t unicode = keycode & 0x7FFF; |
| 24 | switch(input_mode) { | 66 | unicode_input_start(); |
| 25 | case UC_OSX: | 67 | register_hex(unicode); |
| 26 | register_code(KC_LALT); | 68 | unicode_input_finish(); |
| 27 | break; | ||
| 28 | case UC_LNX: | ||
| 29 | register_code(KC_LCTL); | ||
| 30 | register_code(KC_LSFT); | ||
| 31 | register_code(KC_U); | ||
| 32 | unregister_code(KC_U); | ||
| 33 | break; | ||
| 34 | case UC_WIN: | ||
| 35 | register_code(KC_LALT); | ||
| 36 | register_code(KC_PPLS); | ||
| 37 | unregister_code(KC_PPLS); | ||
| 38 | break; | ||
| 39 | } | ||
| 40 | for(int i = 3; i >= 0; i--) { | ||
| 41 | uint8_t digit = ((unicode >> (i*4)) & 0xF); | ||
| 42 | register_code(hex_to_keycode(digit)); | ||
| 43 | unregister_code(hex_to_keycode(digit)); | ||
| 44 | } | ||
| 45 | switch(input_mode) { | ||
| 46 | case UC_OSX: | ||
| 47 | case UC_WIN: | ||
| 48 | unregister_code(KC_LALT); | ||
| 49 | break; | ||
| 50 | case UC_LNX: | ||
| 51 | unregister_code(KC_LCTL); | ||
| 52 | unregister_code(KC_LSFT); | ||
| 53 | break; | ||
| 54 | } | ||
| 55 | } | 69 | } |
| 56 | return true; | 70 | return true; |
| 57 | } \ No newline at end of file | 71 | } \ No newline at end of file |
