]> git.donarmstrong.com Git - qmk_firmware.git/blob - quantum/process_keycode/process_unicode_common.c
unique variable name
[qmk_firmware.git] / quantum / process_keycode / process_unicode_common.c
1 #include "process_unicode_common.h"
2
3 void set_unicode_input_mode(uint8_t os_target)
4 {
5   input_mode = os_target;
6 }
7
8 uint8_t get_unicode_input_mode(void) {
9   return input_mode;
10 }
11
12 __attribute__((weak))
13 void unicode_input_start (void) {
14   // save current mods
15   unicode_mods = keyboard_report->mods;
16
17   // unregister all mods to start from clean state
18   if (unicode_mods & MOD_BIT(KC_LSFT)) unregister_code(KC_LSFT);
19   if (unicode_mods & MOD_BIT(KC_RSFT)) unregister_code(KC_RSFT);
20   if (unicode_mods & MOD_BIT(KC_LCTL)) unregister_code(KC_LCTL);
21   if (unicode_mods & MOD_BIT(KC_RCTL)) unregister_code(KC_RCTL);
22   if (unicode_mods & MOD_BIT(KC_LALT)) unregister_code(KC_LALT);
23   if (unicode_mods & MOD_BIT(KC_RALT)) unregister_code(KC_RALT);
24   if (unicode_mods & MOD_BIT(KC_LGUI)) unregister_code(KC_LGUI);
25   if (unicode_mods & MOD_BIT(KC_RGUI)) unregister_code(KC_RGUI);
26
27   switch(input_mode) {
28   case UC_OSX:
29     register_code(KC_LALT);
30     break;
31   case UC_LNX:
32     register_code(KC_LCTL);
33     register_code(KC_LSFT);
34     register_code(KC_U);
35     unregister_code(KC_U);
36     unregister_code(KC_LSFT);
37     unregister_code(KC_LCTL);
38     break;
39   case UC_WIN:
40     register_code(KC_LALT);
41     register_code(KC_PPLS);
42     unregister_code(KC_PPLS);
43     break;
44   case UC_WINC:
45     register_code(KC_RALT);
46     unregister_code(KC_RALT);
47     register_code(KC_U);
48     unregister_code(KC_U);
49   }
50   wait_ms(UNICODE_TYPE_DELAY);
51 }
52
53 __attribute__((weak))
54 void unicode_input_finish (void) {
55   switch(input_mode) {
56     case UC_OSX:
57     case UC_WIN:
58       unregister_code(KC_LALT);
59       break;
60     case UC_LNX:
61       register_code(KC_SPC);
62       unregister_code(KC_SPC);
63       break;
64   }
65
66   // reregister previously set unicode_mods
67   if (unicode_mods & MOD_BIT(KC_LSFT)) register_code(KC_LSFT);
68   if (unicode_mods & MOD_BIT(KC_RSFT)) register_code(KC_RSFT);
69   if (unicode_mods & MOD_BIT(KC_LCTL)) register_code(KC_LCTL);
70   if (unicode_mods & MOD_BIT(KC_RCTL)) register_code(KC_RCTL);
71   if (unicode_mods & MOD_BIT(KC_LALT)) register_code(KC_LALT);
72   if (unicode_mods & MOD_BIT(KC_RALT)) register_code(KC_RALT);
73   if (unicode_mods & MOD_BIT(KC_LGUI)) register_code(KC_LGUI);
74   if (unicode_mods & MOD_BIT(KC_RGUI)) register_code(KC_RGUI);
75 }
76
77 void register_hex(uint16_t hex) {
78   for(int i = 3; i >= 0; i--) {
79     uint8_t digit = ((hex >> (i*4)) & 0xF);
80     register_code(hex_to_keycode(digit));
81     unregister_code(hex_to_keycode(digit));
82   }
83 }