1 | /*
|
---|
2 | * Copyright (c) 2011 Jiri Svoboda
|
---|
3 | * Copyright (c) 2012 Mohammed Q. Hussain
|
---|
4 | * All rights reserved.
|
---|
5 | *
|
---|
6 | * Redistribution and use in source and binary forms, with or without
|
---|
7 | * modification, are permitted provided that the following conditions
|
---|
8 | * are met:
|
---|
9 | *
|
---|
10 | * - Redistributions of source code must retain the above copyright
|
---|
11 | * notice, this list of conditions and the following disclaimer.
|
---|
12 | * - Redistributions in binary form must reproduce the above copyright
|
---|
13 | * notice, this list of conditions and the following disclaimer in the
|
---|
14 | * documentation and/or other materials provided with the distribution.
|
---|
15 | * - The name of the author may not be used to endorse or promote products
|
---|
16 | * derived from this software without specific prior written permission.
|
---|
17 | *
|
---|
18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
23 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
28 | */
|
---|
29 |
|
---|
30 | /** @addtogroup input
|
---|
31 | * @{
|
---|
32 | */
|
---|
33 |
|
---|
34 | /** @file
|
---|
35 | * @brief Arabic keyboard layout (Based on US QWERTY layout's code)
|
---|
36 | */
|
---|
37 |
|
---|
38 | #include <errno.h>
|
---|
39 | #include <io/console.h>
|
---|
40 | #include <io/keycode.h>
|
---|
41 | #include "../layout.h"
|
---|
42 | #include "../kbd.h"
|
---|
43 |
|
---|
44 | static errno_t ar_create(layout_t *);
|
---|
45 | static void ar_destroy(layout_t *);
|
---|
46 | static char32_t ar_parse_ev(layout_t *, kbd_event_t *ev);
|
---|
47 |
|
---|
48 | layout_ops_t ar_ops = {
|
---|
49 | .create = ar_create,
|
---|
50 | .destroy = ar_destroy,
|
---|
51 | .parse_ev = ar_parse_ev
|
---|
52 | };
|
---|
53 |
|
---|
54 | static char32_t map_not_shifted[] = {
|
---|
55 | [KC_BACKTICK] = L'ذ',
|
---|
56 |
|
---|
57 | [KC_1] = '1',
|
---|
58 | [KC_2] = '2',
|
---|
59 | [KC_3] = '3',
|
---|
60 | [KC_4] = '4',
|
---|
61 | [KC_5] = '5',
|
---|
62 | [KC_6] = '6',
|
---|
63 | [KC_7] = '7',
|
---|
64 | [KC_8] = '8',
|
---|
65 | [KC_9] = '9',
|
---|
66 | [KC_0] = '0',
|
---|
67 |
|
---|
68 | [KC_MINUS] = '-',
|
---|
69 | [KC_EQUALS] = '=',
|
---|
70 |
|
---|
71 | [KC_LBRACKET] = L'ج',
|
---|
72 | [KC_RBRACKET] = L'د',
|
---|
73 |
|
---|
74 | [KC_SEMICOLON] = L'ك',
|
---|
75 | [KC_QUOTE] = L'ط',
|
---|
76 | [KC_BACKSLASH] = '\\',
|
---|
77 |
|
---|
78 | [KC_COMMA] = L'و',
|
---|
79 | [KC_PERIOD] = L'ز',
|
---|
80 | [KC_SLASH] = L'ظ',
|
---|
81 |
|
---|
82 | [KC_Q] = L'ض',
|
---|
83 | [KC_W] = L'ص',
|
---|
84 | [KC_E] = L'ث',
|
---|
85 | [KC_R] = L'ق',
|
---|
86 | [KC_T] = L'ف',
|
---|
87 | [KC_Y] = L'غ',
|
---|
88 | [KC_U] = L'ع',
|
---|
89 | [KC_I] = L'ه',
|
---|
90 | [KC_O] = L'خ',
|
---|
91 | [KC_P] = L'ح',
|
---|
92 |
|
---|
93 | [KC_A] = L'ش',
|
---|
94 | [KC_S] = L'س',
|
---|
95 | [KC_D] = L'ي',
|
---|
96 | [KC_F] = L'ب',
|
---|
97 | [KC_G] = L'ل',
|
---|
98 | [KC_H] = L'ا',
|
---|
99 | [KC_J] = L'ت',
|
---|
100 | [KC_K] = L'ن',
|
---|
101 | [KC_L] = L'م',
|
---|
102 |
|
---|
103 | [KC_Z] = L'ئ',
|
---|
104 | [KC_X] = L'ء',
|
---|
105 | [KC_C] = L'ؤ',
|
---|
106 | [KC_V] = L'ر',
|
---|
107 | [KC_B] = L'ﻻ',
|
---|
108 | [KC_N] = L'ى',
|
---|
109 | [KC_M] = L'ة',
|
---|
110 | };
|
---|
111 |
|
---|
112 | static char32_t map_shifted[] = {
|
---|
113 | [KC_BACKTICK] = L'ّ',
|
---|
114 |
|
---|
115 | [KC_1] = '!',
|
---|
116 | [KC_2] = '@',
|
---|
117 | [KC_3] = '#',
|
---|
118 | [KC_4] = '$',
|
---|
119 | [KC_5] = '%',
|
---|
120 | [KC_6] = '^',
|
---|
121 | [KC_7] = '&',
|
---|
122 | [KC_8] = '*',
|
---|
123 | [KC_9] = ')',
|
---|
124 | [KC_0] = '(',
|
---|
125 |
|
---|
126 | [KC_MINUS] = '_',
|
---|
127 | [KC_EQUALS] = '+',
|
---|
128 |
|
---|
129 | [KC_LBRACKET] = '<',
|
---|
130 | [KC_RBRACKET] = '>',
|
---|
131 |
|
---|
132 | [KC_SEMICOLON] = ':',
|
---|
133 | [KC_QUOTE] = '"',
|
---|
134 | [KC_BACKSLASH] = '|',
|
---|
135 |
|
---|
136 | [KC_COMMA] = ',',
|
---|
137 | [KC_PERIOD] = '.',
|
---|
138 | [KC_SLASH] = L'؟',
|
---|
139 |
|
---|
140 | [KC_Q] = L'َ',
|
---|
141 | [KC_W] = L'ً',
|
---|
142 | [KC_E] = L'ُ',
|
---|
143 | [KC_R] = L'ٌ',
|
---|
144 | [KC_T] = L'ﻹ',
|
---|
145 | [KC_Y] = L'إ',
|
---|
146 | [KC_U] = L'`',
|
---|
147 | [KC_I] = L'÷',
|
---|
148 | [KC_O] = L'×',
|
---|
149 | [KC_P] = L'؛',
|
---|
150 |
|
---|
151 | [KC_A] = L'ِ',
|
---|
152 | [KC_S] = L'ٍ',
|
---|
153 | [KC_D] = L']',
|
---|
154 | [KC_F] = L'[',
|
---|
155 | [KC_G] = L'ﻷ',
|
---|
156 | [KC_H] = L'أ',
|
---|
157 | [KC_J] = L'ـ',
|
---|
158 | [KC_K] = L'،',
|
---|
159 | [KC_L] = L'/',
|
---|
160 |
|
---|
161 | [KC_Z] = L'~',
|
---|
162 | [KC_X] = L'ْ',
|
---|
163 | [KC_C] = L'}',
|
---|
164 | [KC_V] = L'{',
|
---|
165 | [KC_B] = L'ﻵ',
|
---|
166 | [KC_N] = L'آ',
|
---|
167 | [KC_M] = L'\'',
|
---|
168 | };
|
---|
169 |
|
---|
170 | static char32_t map_neutral[] = {
|
---|
171 | [KC_BACKSPACE] = '\b',
|
---|
172 | [KC_TAB] = '\t',
|
---|
173 | [KC_ENTER] = '\n',
|
---|
174 | [KC_SPACE] = ' ',
|
---|
175 |
|
---|
176 | [KC_NSLASH] = '/',
|
---|
177 | [KC_NTIMES] = '*',
|
---|
178 | [KC_NMINUS] = '-',
|
---|
179 | [KC_NPLUS] = '+',
|
---|
180 | [KC_NENTER] = '\n'
|
---|
181 | };
|
---|
182 |
|
---|
183 | static char32_t map_numeric[] = {
|
---|
184 | [KC_N7] = '7',
|
---|
185 | [KC_N8] = '8',
|
---|
186 | [KC_N9] = '9',
|
---|
187 | [KC_N4] = '4',
|
---|
188 | [KC_N5] = '5',
|
---|
189 | [KC_N6] = '6',
|
---|
190 | [KC_N1] = '1',
|
---|
191 | [KC_N2] = '2',
|
---|
192 | [KC_N3] = '3',
|
---|
193 |
|
---|
194 | [KC_N0] = '0',
|
---|
195 | [KC_NPERIOD] = '.'
|
---|
196 | };
|
---|
197 |
|
---|
198 | static char32_t translate(unsigned int key, char32_t *map, size_t map_length)
|
---|
199 | {
|
---|
200 | if (key >= map_length)
|
---|
201 | return 0;
|
---|
202 | return map[key];
|
---|
203 | }
|
---|
204 |
|
---|
205 | static errno_t ar_create(layout_t *state)
|
---|
206 | {
|
---|
207 | return EOK;
|
---|
208 | }
|
---|
209 |
|
---|
210 | static void ar_destroy(layout_t *state)
|
---|
211 | {
|
---|
212 | }
|
---|
213 |
|
---|
214 | static char32_t ar_parse_ev(layout_t *state, kbd_event_t *ev)
|
---|
215 | {
|
---|
216 | char32_t c;
|
---|
217 |
|
---|
218 | c = translate(ev->key, map_neutral, sizeof(map_neutral) / sizeof(char32_t));
|
---|
219 | if (c != 0)
|
---|
220 | return c;
|
---|
221 |
|
---|
222 | if ((ev->mods & KM_SHIFT) != 0)
|
---|
223 | c = translate(ev->key, map_shifted, sizeof(map_shifted) / sizeof(char32_t));
|
---|
224 | else
|
---|
225 | c = translate(ev->key, map_not_shifted, sizeof(map_not_shifted) / sizeof(char32_t));
|
---|
226 |
|
---|
227 | if (c != 0)
|
---|
228 | return c;
|
---|
229 |
|
---|
230 | if ((ev->mods & KM_NUM_LOCK) != 0)
|
---|
231 | c = translate(ev->key, map_numeric, sizeof(map_numeric) / sizeof(char32_t));
|
---|
232 | else
|
---|
233 | c = 0;
|
---|
234 |
|
---|
235 | return c;
|
---|
236 | }
|
---|
237 |
|
---|
238 | /**
|
---|
239 | * @}
|
---|
240 | */
|
---|