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

Archive Download this file

Revision: 1468