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

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 74017ce was b6a088f, checked in by Martin Decky <martin@…>, 13 years ago

use local includes within the input server

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