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

Archive Download this file

Revision: 1119