source: mainline/uspace/srv/hid/input/layout/ar.c@ 1b20da0

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 1b20da0 was 1b20da0, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 7 years ago

style: Remove trailing whitespace on non-empty lines, in certain file types.

Command used: tools/srepl '\([^[:space:]]\)\s\+$' '\1' -- *.c *.h *.py *.sh *.s *.S *.ag

  • Property mode set to 100644
File size: 4.9 KB
RevLine 
[c928bb7]1/*
2 * Copyright (c) 2011 Jiri Svoboda
[a1eba300]3 * Copyright (c) 2012 Mohammed Q. Hussain
[c928bb7]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 * @brief Arabic keyboard layout (Based on US QWERTY layout's code).
32 * @{
33 */
34
35#include <errno.h>
36#include <io/console.h>
37#include <io/keycode.h>
38#include "../layout.h"
39#include "../kbd.h"
40
[b7fd2a0]41static errno_t ar_create(layout_t *);
[c928bb7]42static void ar_destroy(layout_t *);
43static wchar_t ar_parse_ev(layout_t *, kbd_event_t *ev);
44
45layout_ops_t ar_ops = {
46 .create = ar_create,
47 .destroy = ar_destroy,
48 .parse_ev = ar_parse_ev
49};
50
51static wchar_t map_not_shifted[] = {
52 [KC_BACKTICK] = L'ذ',
53
54 [KC_1] = '1',
55 [KC_2] = '2',
56 [KC_3] = '3',
57 [KC_4] = '4',
58 [KC_5] = '5',
59 [KC_6] = '6',
60 [KC_7] = '7',
61 [KC_8] = '8',
62 [KC_9] = '9',
63 [KC_0] = '0',
64
65 [KC_MINUS] = '-',
66 [KC_EQUALS] = '=',
67
68 [KC_LBRACKET] = L'ج',
69 [KC_RBRACKET] = L'د',
70
71 [KC_SEMICOLON] = L'ك',
72 [KC_QUOTE] = L'ط',
73 [KC_BACKSLASH] = '\\',
74
75 [KC_COMMA] = L'و',
76 [KC_PERIOD] = L'ز',
77 [KC_SLASH] = L'ظ',
78
79 [KC_Q] = L'ض',
80 [KC_W] = L'ص',
81 [KC_E] = L'ث',
82 [KC_R] = L'ق',
83 [KC_T] = L'ف',
84 [KC_Y] = L'غ',
85 [KC_U] = L'ع',
86 [KC_I] = L'ه',
87 [KC_O] = L'خ',
88 [KC_P] = L'ح',
89
90 [KC_A] = L'ش',
91 [KC_S] = L'س',
92 [KC_D] = L'ي',
93 [KC_F] = L'ب',
94 [KC_G] = L'ل',
95 [KC_H] = L'ا',
96 [KC_J] = L'ت',
97 [KC_K] = L'ن',
98 [KC_L] = L'م',
99
100 [KC_Z] = L'ئ',
101 [KC_X] = L'ء',
102 [KC_C] = L'ؤ',
103 [KC_V] = L'ر',
104 [KC_B] = L'ﻻ',
105 [KC_N] = L'ى',
106 [KC_M] = L'ة',
107};
108
109static wchar_t map_shifted[] = {
110 [KC_BACKTICK] = L'ّ',
111
112 [KC_1] = '!',
113 [KC_2] = '@',
114 [KC_3] = '#',
115 [KC_4] = '$',
116 [KC_5] = '%',
117 [KC_6] = '^',
118 [KC_7] = '&',
119 [KC_8] = '*',
120 [KC_9] = ')',
121 [KC_0] = '(',
122
123 [KC_MINUS] = '_',
124 [KC_EQUALS] = '+',
125
126 [KC_LBRACKET] = '<',
127 [KC_RBRACKET] = '>',
128
129 [KC_SEMICOLON] = ':',
130 [KC_QUOTE] = '"',
131 [KC_BACKSLASH] = '|',
132
133 [KC_COMMA] = ',',
134 [KC_PERIOD] = '.',
135 [KC_SLASH] = L'؟',
136
137 [KC_Q] = L'َ',
138 [KC_W] = L'ً',
139 [KC_E] = L'ُ',
140 [KC_R] = L'ٌ',
141 [KC_T] = L'ﻹ',
142 [KC_Y] = L'إ',
143 [KC_U] = L'`',
144 [KC_I] = L'÷',
145 [KC_O] = L'×',
146 [KC_P] = L'؛',
147
148 [KC_A] = L'ِ',
149 [KC_S] = L'ٍ',
150 [KC_D] = L']',
151 [KC_F] = L'[',
152 [KC_G] = L'ﻷ',
153 [KC_H] = L'أ',
154 [KC_J] = L'ـ',
155 [KC_K] = L'،',
156 [KC_L] = L'/',
157
158 [KC_Z] = L'~',
159 [KC_X] = L'ْ',
160 [KC_C] = L'}',
161 [KC_V] = L'{',
162 [KC_B] = L'ﻵ',
163 [KC_N] = L'آ',
164 [KC_M] = L'\'',
165};
166
167static wchar_t map_neutral[] = {
168 [KC_BACKSPACE] = '\b',
169 [KC_TAB] = '\t',
170 [KC_ENTER] = '\n',
171 [KC_SPACE] = ' ',
172
173 [KC_NSLASH] = '/',
174 [KC_NTIMES] = '*',
175 [KC_NMINUS] = '-',
176 [KC_NPLUS] = '+',
177 [KC_NENTER] = '\n'
178};
179
180static wchar_t map_numeric[] = {
181 [KC_N7] = '7',
182 [KC_N8] = '8',
183 [KC_N9] = '9',
184 [KC_N4] = '4',
185 [KC_N5] = '5',
186 [KC_N6] = '6',
187 [KC_N1] = '1',
188 [KC_N2] = '2',
189 [KC_N3] = '3',
190
191 [KC_N0] = '0',
192 [KC_NPERIOD] = '.'
193};
194
195static wchar_t translate(unsigned int key, wchar_t *map, size_t map_length)
196{
197 if (key >= map_length)
198 return 0;
199 return map[key];
200}
201
[b7fd2a0]202static errno_t ar_create(layout_t *state)
[c928bb7]203{
204 return EOK;
205}
206
207static void ar_destroy(layout_t *state)
208{
209}
210
211static wchar_t ar_parse_ev(layout_t *state, kbd_event_t *ev)
212{
213 wchar_t c;
214
215 /* Produce no characters when Ctrl or Alt is pressed. */
216 if ((ev->mods & (KM_CTRL | KM_ALT)) != 0)
217 return 0;
218
219 c = translate(ev->key, map_neutral, sizeof(map_neutral) / sizeof(wchar_t));
220 if (c != 0)
221 return c;
222
223 if ((ev->mods & KM_SHIFT) != 0)
224 c = translate(ev->key, map_shifted, sizeof(map_shifted) / sizeof(wchar_t));
225 else
226 c = translate(ev->key, map_not_shifted, sizeof(map_not_shifted) / sizeof(wchar_t));
227
228 if (c != 0)
229 return c;
230
231 if ((ev->mods & KM_NUM_LOCK) != 0)
232 c = translate(ev->key, map_numeric, sizeof(map_numeric) / sizeof(wchar_t));
233 else
234 c = 0;
235
236 return c;
237}
238
239/**
240 * @}
[1b20da0]241 */
Note: See TracBrowser for help on using the repository browser.