diff options
Diffstat (limited to 'quantum/process_keycode/process_unicode_common.c')
| -rw-r--r-- | quantum/process_keycode/process_unicode_common.c | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/quantum/process_keycode/process_unicode_common.c b/quantum/process_keycode/process_unicode_common.c new file mode 100644 index 000000000..31bc3b7ab --- /dev/null +++ b/quantum/process_keycode/process_unicode_common.c | |||
| @@ -0,0 +1,85 @@ | |||
| 1 | #include "process_unicode_common.h" | ||
| 2 | |||
| 3 | uint8_t mods; | ||
| 4 | |||
| 5 | void set_unicode_input_mode(uint8_t os_target) | ||
| 6 | { | ||
| 7 | input_mode = os_target; | ||
| 8 | } | ||
| 9 | |||
| 10 | uint8_t get_unicode_input_mode(void) { | ||
| 11 | return input_mode; | ||
| 12 | } | ||
| 13 | |||
| 14 | __attribute__((weak)) | ||
| 15 | void unicode_input_start (void) { | ||
| 16 | // save current mods | ||
| 17 | mods = keyboard_report->mods; | ||
| 18 | |||
| 19 | // unregister all mods to start from clean state | ||
| 20 | if (mods & MOD_BIT(KC_LSFT)) unregister_code(KC_LSFT); | ||
| 21 | if (mods & MOD_BIT(KC_RSFT)) unregister_code(KC_RSFT); | ||
| 22 | if (mods & MOD_BIT(KC_LCTL)) unregister_code(KC_LCTL); | ||
| 23 | if (mods & MOD_BIT(KC_RCTL)) unregister_code(KC_RCTL); | ||
| 24 | if (mods & MOD_BIT(KC_LALT)) unregister_code(KC_LALT); | ||
| 25 | if (mods & MOD_BIT(KC_RALT)) unregister_code(KC_RALT); | ||
| 26 | if (mods & MOD_BIT(KC_LGUI)) unregister_code(KC_LGUI); | ||
| 27 | if (mods & MOD_BIT(KC_RGUI)) unregister_code(KC_RGUI); | ||
| 28 | |||
| 29 | switch(input_mode) { | ||
| 30 | case UC_OSX: | ||
| 31 | register_code(KC_LALT); | ||
| 32 | break; | ||
| 33 | case UC_LNX: | ||
| 34 | register_code(KC_LCTL); | ||
| 35 | register_code(KC_LSFT); | ||
| 36 | register_code(KC_U); | ||
| 37 | unregister_code(KC_U); | ||
| 38 | unregister_code(KC_LSFT); | ||
| 39 | unregister_code(KC_LCTL); | ||
| 40 | break; | ||
| 41 | case UC_WIN: | ||
| 42 | register_code(KC_LALT); | ||
| 43 | register_code(KC_PPLS); | ||
| 44 | unregister_code(KC_PPLS); | ||
| 45 | break; | ||
| 46 | case UC_WINC: | ||
| 47 | register_code(KC_RALT); | ||
| 48 | unregister_code(KC_RALT); | ||
| 49 | register_code(KC_U); | ||
| 50 | unregister_code(KC_U); | ||
| 51 | } | ||
| 52 | wait_ms(UNICODE_TYPE_DELAY); | ||
| 53 | } | ||
| 54 | |||
| 55 | __attribute__((weak)) | ||
| 56 | void unicode_input_finish (void) { | ||
| 57 | switch(input_mode) { | ||
| 58 | case UC_OSX: | ||
| 59 | case UC_WIN: | ||
| 60 | unregister_code(KC_LALT); | ||
| 61 | break; | ||
| 62 | case UC_LNX: | ||
| 63 | register_code(KC_SPC); | ||
| 64 | unregister_code(KC_SPC); | ||
| 65 | break; | ||
| 66 | } | ||
| 67 | |||
| 68 | // reregister previously set mods | ||
| 69 | if (mods & MOD_BIT(KC_LSFT)) register_code(KC_LSFT); | ||
| 70 | if (mods & MOD_BIT(KC_RSFT)) register_code(KC_RSFT); | ||
| 71 | if (mods & MOD_BIT(KC_LCTL)) register_code(KC_LCTL); | ||
| 72 | if (mods & MOD_BIT(KC_RCTL)) register_code(KC_RCTL); | ||
| 73 | if (mods & MOD_BIT(KC_LALT)) register_code(KC_LALT); | ||
| 74 | if (mods & MOD_BIT(KC_RALT)) register_code(KC_RALT); | ||
| 75 | if (mods & MOD_BIT(KC_LGUI)) register_code(KC_LGUI); | ||
| 76 | if (mods & MOD_BIT(KC_RGUI)) register_code(KC_RGUI); | ||
| 77 | } | ||
| 78 | |||
| 79 | void register_hex(uint16_t hex) { | ||
| 80 | for(int i = 3; i >= 0; i--) { | ||
| 81 | uint8_t digit = ((hex >> (i*4)) & 0xF); | ||
| 82 | register_code(hex_to_keycode(digit)); | ||
| 83 | unregister_code(hex_to_keycode(digit)); | ||
| 84 | } | ||
| 85 | } \ No newline at end of file | ||
