1 | /*␊ |
2 | * Keymapper.c␊ |
3 | * Chameleon␊ |
4 | *␊ |
5 | * Created by Cadet-petit Armel on 05/12/10. <armelcadetpetit@gmail.com>␊ |
6 | * Copyright 2010. All rights reserved.␊ |
7 | *␊ |
8 | */␊ |
9 | ␊ |
10 | #include "libsaio.h"␊ |
11 | #include "bootstruct.h"␊ |
12 | #include "xml.h"␊ |
13 | #include "modules.h"␊ |
14 | #include "Keylayout.h"␊ |
15 | ␊ |
16 | static int AZERTY_switch(int c);␊ |
17 | void Keymapper_hook(void* arg1, void* arg2, void* arg3, void* arg4, void* arg5, void* arg6);␊ |
18 | int Keymapper_getc(void);␊ |
19 | ␊ |
20 | int Keymapper_getc(void)␊ |
21 | {␉␊ |
22 | int c = bgetc();␉␉␊ |
23 | ␉␊ |
24 | ␉Keymapper_hook(&c, NULL, NULL, NULL, NULL, NULL);␊ |
25 | ␉␊ |
26 | if ((c & 0xff) == 0) ␉␉␊ |
27 | return c;␊ |
28 | else ␉␊ |
29 | ␉␉return (c & 0xff); ␊ |
30 | }␊ |
31 | ␊ |
32 | // CPARM's AZERTY_switch : A Basic QWERTY to AZERTY switcher␊ |
33 | static int AZERTY_switch(int c)␊ |
34 | {␉␉␊ |
35 | ␉switch (c) {␊ |
36 | ␉␉case 4209: //q to a␊ |
37 | ␉␉␉c = 7777;␊ |
38 | ␉␉␉break;␊ |
39 | ␉␉case 7777: // a to q␊ |
40 | ␉␉␉c = 4209;␊ |
41 | ␉␉␉break;␊ |
42 | ␉␉case 4177: // Q to A␊ |
43 | ␉␉␉c = 7745;␊ |
44 | ␉␉␉break;␊ |
45 | ␉␉case 7745: // A to Q␊ |
46 | ␉␉␉c = 4177;␊ |
47 | ␉␉␉break;␊ |
48 | ␉␉case 4471: // w to z␊ |
49 | ␉␉␉c = 11386;␊ |
50 | ␉␉␉break;␊ |
51 | ␉␉case 11386: // z to w␊ |
52 | ␉␉␉c = 4471;␊ |
53 | ␉␉␉break;␊ |
54 | ␉␉case 4439: // W to Z␊ |
55 | ␉␉␉c = 11354;␊ |
56 | ␉␉␉break;␊ |
57 | ␉␉case 11354: // Z to W␊ |
58 | ␉␉␉c = 4439;␊ |
59 | ␉␉␉break;␉␉␉␊ |
60 | ␉␉case 10043: // ; to m␊ |
61 | ␉␉␉c = 12909;␊ |
62 | ␉␉␉break;␊ |
63 | ␉␉case 10042: // : to M␊ |
64 | ␉␉␉c = 12877;␊ |
65 | ␉␉␉break;␊ |
66 | ␉␉case 12909: // m to ,␊ |
67 | ␉␉␉c = 13100;␊ |
68 | ␉␉␉break;␉␉␊ |
69 | ␉␉case 12877: // M to ? ␊ |
70 | ␉␉␉c = 13631;␊ |
71 | ␉␉␉break;␉␉␉␊ |
72 | ␉␉case 13100: // , to ;␊ |
73 | ␉␉␉c = 10043;␊ |
74 | ␉␉␉break;␉␉␉␊ |
75 | ␉␉case 13116: // < to .␊ |
76 | ␉␉␉c = 13358;␊ |
77 | ␉␉␉break;␊ |
78 | ␉␉case 13374: // > to /␊ |
79 | ␉␉␉c = 13615;␊ |
80 | ␉␉␉break;␊ |
81 | ␉␉case 13358: // . to :␊ |
82 | ␉␉␉c = 10042;␊ |
83 | ␉␉␉break;␊ |
84 | ␉␉case 22108: // \ to <␊ |
85 | ␉␉␉c = 13116;␊ |
86 | ␉␉␉break;␉␉␉␊ |
87 | ␉␉case 22140: // | to >␊ |
88 | ␉␉␉c = 13374;␊ |
89 | ␉␉␉break;␉␉␉␊ |
90 | ␉␉case 13615: // / to !␊ |
91 | ␉␉␉c = 545;␊ |
92 | ␉␉␉break;␊ |
93 | ␉␉case 10279: // ' to % ␊ |
94 | ␉␉␉c = 1573;␊ |
95 | ␉␉␉break;␊ |
96 | ␉␉case 10274: // " to $ ␊ |
97 | ␉␉␉c = 1316;␊ |
98 | ␉␉␉break;␊ |
99 | ␉␉␉␊ |
100 | ␉␉␉/* switch for main keyboard (num) */␊ |
101 | ␉␉case 10592: // to #␊ |
102 | ␉␉␉c = 1059;␊ |
103 | ␉␉␉break;␉␉␉␊ |
104 | ␉␉case 10622: // to @␊ |
105 | ␉␉␉c = 832;␊ |
106 | ␉␉␉break;␉␉␉␊ |
107 | ␉␉case 545: // ! to &␊ |
108 | ␉␉␉c = 2086;␊ |
109 | ␉␉␉break;␉␉␉␊ |
110 | ␉␉case 832: // @ to ~␊ |
111 | ␉␉␉c = 10622;␊ |
112 | ␉␉␉break;␊ |
113 | ␉␉case 1059: // # to "␊ |
114 | ␉␉␉c = 10274;␊ |
115 | ␉␉␉break;␉␉␉␊ |
116 | ␉␉case 1316: // $ to '␊ |
117 | ␉␉␉c = 10279;␊ |
118 | ␉␉␉break;␉␉␉␊ |
119 | ␉␉case 1573: // % to (␊ |
120 | ␉␉␉c = 2600;␊ |
121 | ␉␉␉break;␊ |
122 | ␉␉case 1886: // ^ to -␊ |
123 | ␉␉␉c = 3117;␊ |
124 | ␉␉␉break;␉␉␉␊ |
125 | ␉␉case 2086: // & to ยด␊ |
126 | ␉␉␉c = 10592;␊ |
127 | ␉␉␉break;␉␉␉␊ |
128 | ␉␉case 2346: // * to _␊ |
129 | ␉␉␉c = 3167;␊ |
130 | ␉␉␉break;␊ |
131 | ␉␉case 2600: // ( to ^␊ |
132 | ␉␉␉c = 1886;␊ |
133 | ␉␉␉break;␊ |
134 | ␉␉case 2857: // ) to @␊ |
135 | ␉␉␉c = 832;␊ |
136 | ␉␉␉break;␉␉␉␊ |
137 | ␉␉case 3117: // - to )␊ |
138 | ␉␉␉c = 2857;␊ |
139 | ␉␉␉break;␊ |
140 | ␉␉case 3167: // _ to ]␊ |
141 | ␉␉␉c = 7005;␊ |
142 | ␉␉␉break;␉␉␉␊ |
143 | ␉␉case 3389: // = to +␊ |
144 | ␉␉␉c = 3371;␊ |
145 | ␉␉␉break;␉␉␉␊ |
146 | ␉␉case 3371: // + to =␊ |
147 | ␉␉␉c = 3389;␊ |
148 | ␉␉␉break;␊ |
149 | ␉␉␉␊ |
150 | ␉␉␉/* switch for main keyboard (num) with alt pressed */␊ |
151 | ␉␉case 30720: // to & ␊ |
152 | ␉␉␉c = 2086;␊ |
153 | ␉␉␉break;␊ |
154 | ␉␉case 30976: // to ~ ␊ |
155 | ␉␉␉c = 10622;␊ |
156 | ␉␉␉break;␊ |
157 | ␉␉case 31232: // to #␊ |
158 | ␉␉␉c = 1059;␊ |
159 | ␉␉␉break;␉␉␉␊ |
160 | ␉␉case 31488: ␊ |
161 | ␉␉␉c = 6779;␊ |
162 | ␉␉␉break;␊ |
163 | ␉␉case 31744: ␊ |
164 | ␉␉␉c = 6747;␊ |
165 | ␉␉␉break;␊ |
166 | ␉␉case 32000: // to |␊ |
167 | ␉␉␉c = 11132;␊ |
168 | ␉␉␉break;␊ |
169 | ␉␉case 32256: ␊ |
170 | ␉␉␉c = 10592;␊ |
171 | ␉␉␉break;␉␉␉␊ |
172 | ␉␉case 32512: ␊ |
173 | ␉␉␉c = 11100;␊ |
174 | ␉␉␉break;␊ |
175 | ␉␉case 32768: ␊ |
176 | ␉␉␉c = 1886;␊ |
177 | ␉␉␉break;␊ |
178 | ␉␉case 33024:␊ |
179 | ␉␉␉c = 832;␊ |
180 | ␉␉␉break;␊ |
181 | ␉␉case 33280: // to {␊ |
182 | ␉␉␉c = 7005;␊ |
183 | ␉␉␉break;␉␉␉␊ |
184 | ␉␉case 33536: // to }␊ |
185 | ␉␉␉c = 7037;␊ |
186 | ␉␉␉break;␉␉␊ |
187 | ␉␉␉␊ |
188 | ␉␉default:␉␉␉␊ |
189 | ␉␉␉break;␊ |
190 | ␉}␊ |
191 | ␉return c;␊ |
192 | }␊ |
193 | ␊ |
194 | static char *map_kb_type = NULL;␉␊ |
195 | static TagPtr match_map = NULL;␊ |
196 | ␊ |
197 | // Faster method and no need to (re-)compile the map, everything is done with xml (i have a keymap maker made in cocoa and with a gui that i have don't released yet)␊ |
198 | void Keymapper_hook(void* arg1, void* arg2, void* arg3, void* arg4, void* arg5, void* arg6)␊ |
199 | {␊ |
200 | ␉int *ret = (int *)arg1;␊ |
201 | ␉int c = *(int *)ret;␊ |
202 | ␉char *kMatchkey = NULL;␊ |
203 | ␊ |
204 | ␉// Check for xml map in the config file␊ |
205 | ␉if (match_map == NULL)␉␉␉␉␊ |
206 | ␉␉match_map = XMLGetProperty(DEFAULT_BOOT_CONFIG_DICT, (const char*)"KeyboardMap");␊ |
207 | ␉␊ |
208 | ␉if (match_map)␊ |
209 | ␉{␊ |
210 | ␉␉kMatchkey = newStringWithFormat("%d",c); ␊ |
211 | if (!kMatchkey) {␊ |
212 | return;␊ |
213 | } ␊ |
214 | ␉␉TagPtr match_key;␊ |
215 | ␉␉if ((match_key = XMLGetProperty(match_map, (const char*)kMatchkey)))␊ |
216 | ␉␉{␊ |
217 | ␉␉␉kMatchkey = XMLCastString(match_key);␊ |
218 | ␉␉␉c = strtoul((const char *)kMatchkey, NULL,10);␉␉␊ |
219 | ␉␉␉if (c) goto out;␊ |
220 | ␉␉}␊ |
221 | ␉}␊ |
222 | ␉␊ |
223 | ␉// Check for built-in map␊ |
224 | ␉if (map_kb_type == NULL)␊ |
225 | ␉{␉␉␊ |
226 | ␉␉TagPtr match_type;␊ |
227 | ␉␉if ((match_type = XMLGetProperty(DEFAULT_BOOT_CONFIG_DICT, (const char*)"KeyboardType")))␊ |
228 | ␉␉␉map_kb_type = XMLCastString(match_type);␊ |
229 | ␉␉else ␊ |
230 | ␉␉␉map_kb_type = "NONE"; // Default to QWERTY␊ |
231 | ␉}␊ |
232 | ␉␊ |
233 | ␉if (map_kb_type && (strncmp(map_kb_type, "AZERTY",sizeof("AZERTY")) == 0))␉␉␊ |
234 | c = AZERTY_switch(c);␊ |
235 | ␉␊ |
236 | out:␊ |
237 | ␉␊ |
238 | ␉*ret = c;␊ |
239 | ␉if (kMatchkey) free(kMatchkey);␊ |
240 | }␊ |
241 | ␊ |
242 | void Keymapper_start(void);␊ |
243 | void Keymapper_start(void)␊ |
244 | {␊ |
245 | if (Keylayout_real_start()) ␊ |
246 | {␊ |
247 | return;␊ |
248 | } ␊ |
249 | ␊ |
250 | #ifdef TRUNK␉␊ |
251 | if (!replace_system_function("_getchar", &Keymapper_getc)) ␊ |
252 | {␊ |
253 | printf("no function getchar() to replace. Keymapper will not be used ! \n");␊ |
254 | ␊ |
255 | }␉␉␊ |
256 | #else␊ |
257 | if (replace_system_function("_getc", &Keymapper_getc) != EFI_SUCCESS) ␊ |
258 | {␊ |
259 | printf("no function getc() to replace. Keymapper will not be used ! \n");␊ |
260 | }␊ |
261 | #endif␊ |
262 | ␉␊ |
263 | } |