Chameleon

Chameleon Svn Source Tree

Root/branches/cparm/i386/modules/Keymapper/Keymapper.c

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

Archive Download this file

Revision: 1595