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
15#define kEnableKeyMap "EnableKeyMapper"
16static int AZERTY_switch(int c);
17void Keymapper_hook(void* arg1, void* arg2, void* arg3, void* arg4, void* arg5, void* arg6);
18int Keymapper_getc();
19
20int Keymapper_getc()
21{
22 int c = bgetc();
23
24//execute_hook("Keymapper", &c, NULL, NULL, NULL, NULL, NULL);
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
198void Keymapper_hook(void* arg1, void* arg2, void* arg3, void* arg4, void* arg5, void* arg6)
199{
200int *ret = (int *)arg1;
201int c = *(int *)ret;
202
203
204if (match_map == NULL)
205match_map = XMLGetProperty(bootInfo->bootConfig.dictionary, (const char*)"KeyboardMap");
206
207if (match_map)
208{
209char *kMatchkey = 0;
210sprintf(kMatchkey, "%d",c);
211TagPtr match_key;
212if ((match_key = XMLGetProperty(match_map, (const char*)kMatchkey)))
213{
214kMatchkey = XMLCastString(match_key);
215c = strtoul((const char *)kMatchkey, NULL,10);
216if (c) goto out;
217}
218}
219
220if (map_kb_type == NULL)
221{
222TagPtr match_type;
223if ((match_type = XMLGetProperty(bootInfo->bootConfig.dictionary, (const char*)"KeyboardType")))
224map_kb_type = XMLCastString(match_type);
225else
226map_kb_type = "NONE"; // Default to QWERTY
227}
228
229if (strcmp(map_kb_type, "AZERTY") == 0)
230 c = AZERTY_switch(c);
231
232out:
233
234*ret = c;
235
236}
237
238void Keymapper_start()
239{
240bool enable = true;
241getBoolForKey(kEnableKeyMap, &enable, &bootInfo->bootConfig) ;
242
243if (enable)
244{
245//register_hook_callback("Keymapper", &Keymapper_hook);
246replace_function("_getc", &Keymapper_getc);
247}
248}

Archive Download this file

Revision: 1525