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

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since a1b9f63 was 4122410, checked in by Jakub Jermar <jakub@…>, 7 years ago

Improve Doxygen documentaion

This is stil WiP. A number of libraries, drivers and services were
converted to using a more hierarchical and decentralized scheme when it
comes to specifying to which doxygen group they belong.

  • Property mode set to 100644
File size: 5.2 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
47layout_ops_t us_dvorak_ops = {
48 .create = us_dvorak_create,
49 .destroy = us_dvorak_destroy,
50 .parse_ev = us_dvorak_parse_ev
51};
52
53static wchar_t map_lcase[] = {
54 [KC_R] = 'p',
55 [KC_T] = 'y',
56 [KC_Y] = 'f',
57 [KC_U] = 'g',
58 [KC_I] = 'c',
59 [KC_O] = 'r',
60 [KC_P] = 'l',
61
62 [KC_A] = 'a',
63 [KC_S] = 'o',
64 [KC_D] = 'e',
65 [KC_F] = 'u',
66 [KC_G] = 'i',
67 [KC_H] = 'd',
68 [KC_J] = 'h',
69 [KC_K] = 't',
70 [KC_L] = 'n',
71
72 [KC_SEMICOLON] = 's',
73
74 [KC_X] = 'q',
75 [KC_C] = 'j',
76 [KC_V] = 'k',
77 [KC_B] = 'x',
78 [KC_N] = 'b',
79 [KC_M] = 'm',
80
81 [KC_COMMA] = 'w',
82 [KC_PERIOD] = 'v',
83 [KC_SLASH] = 'z',
84};
85
86static wchar_t map_ucase[] = {
87 [KC_R] = 'P',
88 [KC_T] = 'Y',
89 [KC_Y] = 'F',
90 [KC_U] = 'G',
91 [KC_I] = 'C',
92 [KC_O] = 'R',
93 [KC_P] = 'L',
94
95 [KC_A] = 'A',
96 [KC_S] = 'O',
97 [KC_D] = 'E',
98 [KC_F] = 'U',
99 [KC_G] = 'I',
100 [KC_H] = 'D',
101 [KC_J] = 'H',
102 [KC_K] = 'T',
103 [KC_L] = 'N',
104
105 [KC_SEMICOLON] = 'S',
106
107 [KC_X] = 'Q',
108 [KC_C] = 'J',
109 [KC_V] = 'K',
110 [KC_B] = 'X',
111 [KC_N] = 'B',
112 [KC_M] = 'M',
113
114 [KC_COMMA] = 'W',
115 [KC_PERIOD] = 'V',
116 [KC_SLASH] = 'Z',
117};
118
119static wchar_t map_not_shifted[] = {
120 [KC_BACKTICK] = '`',
121
122 [KC_1] = '1',
123 [KC_2] = '2',
124 [KC_3] = '3',
125 [KC_4] = '4',
126 [KC_5] = '5',
127 [KC_6] = '6',
128 [KC_7] = '7',
129 [KC_8] = '8',
130 [KC_9] = '9',
131 [KC_0] = '0',
132
133 [KC_MINUS] = '[',
134 [KC_EQUALS] = ']',
135
136 [KC_Q] = '\'',
137 [KC_W] = ',',
138 [KC_E] = '.',
139
140 [KC_LBRACKET] = '/',
141 [KC_RBRACKET] = '=',
142
143 [KC_QUOTE] = '-',
144 [KC_BACKSLASH] = '\\',
145
146 [KC_Z] = ';',
147};
148
149static wchar_t map_shifted[] = {
150 [KC_BACKTICK] = '~',
151
152 [KC_1] = '!',
153 [KC_2] = '@',
154 [KC_3] = '#',
155 [KC_4] = '$',
156 [KC_5] = '%',
157 [KC_6] = '^',
158 [KC_7] = '&',
159 [KC_8] = '*',
160 [KC_9] = '(',
161 [KC_0] = ')',
162
163 [KC_MINUS] = '{',
164 [KC_EQUALS] = '}',
165
166 [KC_Q] = '"',
167 [KC_W] = '<',
168 [KC_E] = '>',
169
170 [KC_LBRACKET] = '?',
171 [KC_RBRACKET] = '+',
172
173 [KC_QUOTE] = '_',
174 [KC_BACKSLASH] = '|',
175
176 [KC_Z] = ':',
177};
178
179static wchar_t map_neutral[] = {
180 [KC_BACKSPACE] = '\b',
181 [KC_TAB] = '\t',
182 [KC_ENTER] = '\n',
183 [KC_SPACE] = ' ',
184
185 [KC_NSLASH] = '/',
186 [KC_NTIMES] = '*',
187 [KC_NMINUS] = '-',
188 [KC_NPLUS] = '+',
189 [KC_NENTER] = '\n'
190};
191
192static wchar_t map_numeric[] = {
193 [KC_N7] = '7',
194 [KC_N8] = '8',
195 [KC_N9] = '9',
196 [KC_N4] = '4',
197 [KC_N5] = '5',
198 [KC_N6] = '6',
199 [KC_N1] = '1',
200 [KC_N2] = '2',
201 [KC_N3] = '3',
202
203 [KC_N0] = '0',
204 [KC_NPERIOD] = '.'
205};
206
207static wchar_t translate(unsigned int key, wchar_t *map, size_t map_length)
208{
209 if (key >= map_length)
210 return 0;
211 return map[key];
212}
213
214static errno_t us_dvorak_create(layout_t *state)
215{
216 return EOK;
217}
218
219static void us_dvorak_destroy(layout_t *state)
220{
221}
222
223static wchar_t us_dvorak_parse_ev(layout_t *state, kbd_event_t *ev)
224{
225 wchar_t c;
226
227 /* Produce no characters when Ctrl or Alt is pressed. */
228 if ((ev->mods & (KM_CTRL | KM_ALT)) != 0)
229 return 0;
230
231 c = translate(ev->key, map_neutral, sizeof(map_neutral) / sizeof(wchar_t));
232 if (c != 0)
233 return c;
234
235 if (((ev->mods & KM_SHIFT) != 0) ^ ((ev->mods & KM_CAPS_LOCK) != 0))
236 c = translate(ev->key, map_ucase, sizeof(map_ucase) / sizeof(wchar_t));
237 else
238 c = translate(ev->key, map_lcase, sizeof(map_lcase) / sizeof(wchar_t));
239
240 if (c != 0)
241 return c;
242
243 if ((ev->mods & KM_SHIFT) != 0)
244 c = translate(ev->key, map_shifted, sizeof(map_shifted) / sizeof(wchar_t));
245 else
246 c = translate(ev->key, map_not_shifted, sizeof(map_not_shifted) / sizeof(wchar_t));
247
248 if (c != 0)
249 return c;
250
251 if ((ev->mods & KM_NUM_LOCK) != 0)
252 c = translate(ev->key, map_numeric, sizeof(map_numeric) / sizeof(wchar_t));
253 else
254 c = 0;
255
256 return c;
257}
258
259/**
260 * @}
261 */
Note: See TracBrowser for help on using the repository browser.