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

Archive Download this file

Revision: 789