Subversion Repositories HelenOS

Rev

Rev 4153 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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