aboutsummaryrefslogtreecommitdiff
path: root/quantum/process_keycode/process_unicode_common.c
diff options
context:
space:
mode:
authorZay950 <Zay950@users.noreply.github.com>2017-03-29 12:00:38 -0700
committerGitHub <noreply@github.com>2017-03-29 12:00:38 -0700
commit2366ebfbbdeb6ec29cc9a0facda44d666305dd6e (patch)
tree883efed0b7260f3143f5a2a879bc3844a8255e0b /quantum/process_keycode/process_unicode_common.c
parent80c5ada3394c5ad8087df00ef878eb2cbcd87d70 (diff)
parent942f2ccee44bdb2e251553e9730cd8d59307d8b2 (diff)
downloadqmk_firmware-2366ebfbbdeb6ec29cc9a0facda44d666305dd6e.tar.gz
qmk_firmware-2366ebfbbdeb6ec29cc9a0facda44d666305dd6e.zip
Merge branch 'master' into to_push
Diffstat (limited to 'quantum/process_keycode/process_unicode_common.c')
-rw-r--r--quantum/process_keycode/process_unicode_common.c101
1 files changed, 101 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..6012b4f07
--- /dev/null
+++ b/quantum/process_keycode/process_unicode_common.c
@@ -0,0 +1,101 @@
1/* Copyright 2017 Jack Humbert
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#include "process_unicode_common.h"
18
19uint8_t mods;
20
21void set_unicode_input_mode(uint8_t os_target)
22{
23 input_mode = os_target;
24}
25
26uint8_t get_unicode_input_mode(void) {
27 return input_mode;
28}
29
30__attribute__((weak))
31void unicode_input_start (void) {
32 // save current mods
33 mods = keyboard_report->mods;
34
35 // unregister all mods to start from clean state
36 if (mods & MOD_BIT(KC_LSFT)) unregister_code(KC_LSFT);
37 if (mods & MOD_BIT(KC_RSFT)) unregister_code(KC_RSFT);
38 if (mods & MOD_BIT(KC_LCTL)) unregister_code(KC_LCTL);
39 if (mods & MOD_BIT(KC_RCTL)) unregister_code(KC_RCTL);
40 if (mods & MOD_BIT(KC_LALT)) unregister_code(KC_LALT);
41 if (mods & MOD_BIT(KC_RALT)) unregister_code(KC_RALT);
42 if (mods & MOD_BIT(KC_LGUI)) unregister_code(KC_LGUI);
43 if (mods & MOD_BIT(KC_RGUI)) unregister_code(KC_RGUI);
44
45 switch(input_mode) {
46 case UC_OSX:
47 register_code(KC_LALT);
48 break;
49 case UC_LNX:
50 register_code(KC_LCTL);
51 register_code(KC_LSFT);
52 register_code(KC_U);
53 unregister_code(KC_U);
54 unregister_code(KC_LSFT);
55 unregister_code(KC_LCTL);
56 break;
57 case UC_WIN:
58 register_code(KC_LALT);
59 register_code(KC_PPLS);
60 unregister_code(KC_PPLS);
61 break;
62 case UC_WINC:
63 register_code(KC_RALT);
64 unregister_code(KC_RALT);
65 register_code(KC_U);
66 unregister_code(KC_U);
67 }
68 wait_ms(UNICODE_TYPE_DELAY);
69}
70
71__attribute__((weak))
72void unicode_input_finish (void) {
73 switch(input_mode) {
74 case UC_OSX:
75 case UC_WIN:
76 unregister_code(KC_LALT);
77 break;
78 case UC_LNX:
79 register_code(KC_SPC);
80 unregister_code(KC_SPC);
81 break;
82 }
83
84 // reregister previously set mods
85 if (mods & MOD_BIT(KC_LSFT)) register_code(KC_LSFT);
86 if (mods & MOD_BIT(KC_RSFT)) register_code(KC_RSFT);
87 if (mods & MOD_BIT(KC_LCTL)) register_code(KC_LCTL);
88 if (mods & MOD_BIT(KC_RCTL)) register_code(KC_RCTL);
89 if (mods & MOD_BIT(KC_LALT)) register_code(KC_LALT);
90 if (mods & MOD_BIT(KC_RALT)) register_code(KC_RALT);
91 if (mods & MOD_BIT(KC_LGUI)) register_code(KC_LGUI);
92 if (mods & MOD_BIT(KC_RGUI)) register_code(KC_RGUI);
93}
94
95void register_hex(uint16_t hex) {
96 for(int i = 3; i >= 0; i--) {
97 uint8_t digit = ((hex >> (i*4)) & 0xF);
98 register_code(hex_to_keycode(digit));
99 unregister_code(hex_to_keycode(digit));
100 }
101}