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

Archive Download this file

Revision: 2006