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

Last change on this file was b987eb4, checked in by Jiri Svoboda <jiri@…>, 3 years ago

Translate keys to characters even if modifiers are pressed.

So that we can match Alt-key to menu accelerators. Of course
this means clients must check Ctrl and Alt state to determine
if they should insert characters, not just just kbd_event_t.c.

  • 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 * @{
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 char32_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 char32_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 char32_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 char32_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 char32_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 char32_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 char32_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 char32_t translate(unsigned int key, char32_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 char32_t us_dvorak_parse_ev(layout_t *state, kbd_event_t *ev)
224{
225 char32_t c;
226
227 c = translate(ev->key, map_neutral, sizeof(map_neutral) / sizeof(char32_t));
228 if (c != 0)
229 return c;
230
231 if (((ev->mods & KM_SHIFT) != 0) ^ ((ev->mods & KM_CAPS_LOCK) != 0))
232 c = translate(ev->key, map_ucase, sizeof(map_ucase) / sizeof(char32_t));
233 else
234 c = translate(ev->key, map_lcase, sizeof(map_lcase) / sizeof(char32_t));
235
236 if (c != 0)
237 return c;
238
239 if ((ev->mods & KM_SHIFT) != 0)
240 c = translate(ev->key, map_shifted, sizeof(map_shifted) / sizeof(char32_t));
241 else
242 c = translate(ev->key, map_not_shifted, sizeof(map_not_shifted) / sizeof(char32_t));
243
244 if (c != 0)
245 return c;
246
247 if ((ev->mods & KM_NUM_LOCK) != 0)
248 c = translate(ev->key, map_numeric, sizeof(map_numeric) / sizeof(char32_t));
249 else
250 c = 0;
251
252 return c;
253}
254
255/**
256 * @}
257 */
Note: See TracBrowser for help on using the repository browser.