source: mainline/uspace/srv/hid/input/layout/us_dvorak.c@ 3e1bc35

Last change on this file since 3e1bc35 was 3e1bc35, checked in by Matthieu Riolo <matthieu.riolo@…>, 6 years ago

Adding makefiles which build the layouts as dynamic library. All *.c files addedd to the directory uspace/srv/hid/input/layout will be treated as such

  • Property mode set to 100644
File size: 5.4 KB
Line 
1/*
2 * Copyright (c) 2011 Jiri Svoboda
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup input
30 * @{
31 */
32
33/** @file
34 * @brief US Dvorak Simplified Keyboard layout
35 */
36
37#include <errno.h>
38#include <io/console.h>
39#include <io/keycode.h>
40#include "../layout.h"
41#include "../kbd.h"
42
43static errno_t us_dvorak_create(layout_t *);
44static void us_dvorak_destroy(layout_t *);
45static wchar_t us_dvorak_parse_ev(layout_t *, kbd_event_t *ev);
46
47#ifdef CONFIG_KB_LAYOUT_us_dvorak
48
49layout_ops_t layout_default = {
50 .create = us_dvorak_create,
51 .destroy = us_dvorak_destroy,
52 .parse_ev = us_dvorak_parse_ev
53};
54
55#else
56
57layout_ops_t get_layout(void);
58layout_ops_t get_layout(void) {
59 layout_ops_t layout_default = {
60 .create = us_dvorak_create,
61 .destroy = us_dvorak_destroy,
62 .parse_ev = us_dvorak_parse_ev
63 };
64 return layout_default;
65}
66
67#endif
68
69static wchar_t map_lcase[] = {
70 [KC_R] = 'p',
71 [KC_T] = 'y',
72 [KC_Y] = 'f',
73 [KC_U] = 'g',
74 [KC_I] = 'c',
75 [KC_O] = 'r',
76 [KC_P] = 'l',
77
78 [KC_A] = 'a',
79 [KC_S] = 'o',
80 [KC_D] = 'e',
81 [KC_F] = 'u',
82 [KC_G] = 'i',
83 [KC_H] = 'd',
84 [KC_J] = 'h',
85 [KC_K] = 't',
86 [KC_L] = 'n',
87
88 [KC_SEMICOLON] = 's',
89
90 [KC_X] = 'q',
91 [KC_C] = 'j',
92 [KC_V] = 'k',
93 [KC_B] = 'x',
94 [KC_N] = 'b',
95 [KC_M] = 'm',
96
97 [KC_COMMA] = 'w',
98 [KC_PERIOD] = 'v',
99 [KC_SLASH] = 'z',
100};
101
102static wchar_t map_ucase[] = {
103 [KC_R] = 'P',
104 [KC_T] = 'Y',
105 [KC_Y] = 'F',
106 [KC_U] = 'G',
107 [KC_I] = 'C',
108 [KC_O] = 'R',
109 [KC_P] = 'L',
110
111 [KC_A] = 'A',
112 [KC_S] = 'O',
113 [KC_D] = 'E',
114 [KC_F] = 'U',
115 [KC_G] = 'I',
116 [KC_H] = 'D',
117 [KC_J] = 'H',
118 [KC_K] = 'T',
119 [KC_L] = 'N',
120
121 [KC_SEMICOLON] = 'S',
122
123 [KC_X] = 'Q',
124 [KC_C] = 'J',
125 [KC_V] = 'K',
126 [KC_B] = 'X',
127 [KC_N] = 'B',
128 [KC_M] = 'M',
129
130 [KC_COMMA] = 'W',
131 [KC_PERIOD] = 'V',
132 [KC_SLASH] = 'Z',
133};
134
135static wchar_t map_not_shifted[] = {
136 [KC_BACKTICK] = '`',
137
138 [KC_1] = '1',
139 [KC_2] = '2',
140 [KC_3] = '3',
141 [KC_4] = '4',
142 [KC_5] = '5',
143 [KC_6] = '6',
144 [KC_7] = '7',
145 [KC_8] = '8',
146 [KC_9] = '9',
147 [KC_0] = '0',
148
149 [KC_MINUS] = '[',
150 [KC_EQUALS] = ']',
151
152 [KC_Q] = '\'',
153 [KC_W] = ',',
154 [KC_E] = '.',
155
156 [KC_LBRACKET] = '/',
157 [KC_RBRACKET] = '=',
158
159 [KC_QUOTE] = '-',
160 [KC_BACKSLASH] = '\\',
161
162 [KC_Z] = ';',
163};
164
165static wchar_t map_shifted[] = {
166 [KC_BACKTICK] = '~',
167
168 [KC_1] = '!',
169 [KC_2] = '@',
170 [KC_3] = '#',
171 [KC_4] = '$',
172 [KC_5] = '%',
173 [KC_6] = '^',
174 [KC_7] = '&',
175 [KC_8] = '*',
176 [KC_9] = '(',
177 [KC_0] = ')',
178
179 [KC_MINUS] = '{',
180 [KC_EQUALS] = '}',
181
182 [KC_Q] = '"',
183 [KC_W] = '<',
184 [KC_E] = '>',
185
186 [KC_LBRACKET] = '?',
187 [KC_RBRACKET] = '+',
188
189 [KC_QUOTE] = '_',
190 [KC_BACKSLASH] = '|',
191
192 [KC_Z] = ':',
193};
194
195static wchar_t map_neutral[] = {
196 [KC_BACKSPACE] = '\b',
197 [KC_TAB] = '\t',
198 [KC_ENTER] = '\n',
199 [KC_SPACE] = ' ',
200
201 [KC_NSLASH] = '/',
202 [KC_NTIMES] = '*',
203 [KC_NMINUS] = '-',
204 [KC_NPLUS] = '+',
205 [KC_NENTER] = '\n'
206};
207
208static wchar_t map_numeric[] = {
209 [KC_N7] = '7',
210 [KC_N8] = '8',
211 [KC_N9] = '9',
212 [KC_N4] = '4',
213 [KC_N5] = '5',
214 [KC_N6] = '6',
215 [KC_N1] = '1',
216 [KC_N2] = '2',
217 [KC_N3] = '3',
218
219 [KC_N0] = '0',
220 [KC_NPERIOD] = '.'
221};
222
223static wchar_t translate(unsigned int key, wchar_t *map, size_t map_length)
224{
225 if (key >= map_length)
226 return 0;
227 return map[key];
228}
229
230static errno_t us_dvorak_create(layout_t *state)
231{
232 return EOK;
233}
234
235static void us_dvorak_destroy(layout_t *state)
236{
237}
238
239static wchar_t us_dvorak_parse_ev(layout_t *state, kbd_event_t *ev)
240{
241 wchar_t c;
242
243 /* Produce no characters when Ctrl or Alt is pressed. */
244 if ((ev->mods & (KM_CTRL | KM_ALT)) != 0)
245 return 0;
246
247 c = translate(ev->key, map_neutral, sizeof(map_neutral) / sizeof(wchar_t));
248 if (c != 0)
249 return c;
250
251 if (((ev->mods & KM_SHIFT) != 0) ^ ((ev->mods & KM_CAPS_LOCK) != 0))
252 c = translate(ev->key, map_ucase, sizeof(map_ucase) / sizeof(wchar_t));
253 else
254 c = translate(ev->key, map_lcase, sizeof(map_lcase) / sizeof(wchar_t));
255
256 if (c != 0)
257 return c;
258
259 if ((ev->mods & KM_SHIFT) != 0)
260 c = translate(ev->key, map_shifted, sizeof(map_shifted) / sizeof(wchar_t));
261 else
262 c = translate(ev->key, map_not_shifted, sizeof(map_not_shifted) / sizeof(wchar_t));
263
264 if (c != 0)
265 return c;
266
267 if ((ev->mods & KM_NUM_LOCK) != 0)
268 c = translate(ev->key, map_numeric, sizeof(map_numeric) / sizeof(wchar_t));
269 else
270 c = 0;
271
272 return c;
273}
274
275/**
276 * @}
277 */
Note: See TracBrowser for help on using the repository browser.