[f89979b] | 1 | /*
|
---|
[2f7a564] | 2 | * Copyright (c) 2011 Jiri Svoboda
|
---|
[f89979b] | 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 |
|
---|
[5f88293] | 29 | /** @addtogroup input
|
---|
[f89979b] | 30 | * @{
|
---|
[4f22731f] | 31 | */
|
---|
[f89979b] | 32 |
|
---|
[4122410] | 33 | /** @file
|
---|
| 34 | * @brief US Dvorak Simplified Keyboard layout
|
---|
| 35 | */
|
---|
| 36 |
|
---|
[2f7a564] | 37 | #include <errno.h>
|
---|
[215abc1] | 38 | #include <io/console.h>
|
---|
| 39 | #include <io/keycode.h>
|
---|
[b6a088f] | 40 | #include "../layout.h"
|
---|
| 41 | #include "../kbd.h"
|
---|
[f89979b] | 42 |
|
---|
[b7fd2a0] | 43 | static errno_t us_dvorak_create(layout_t *);
|
---|
[2f7a564] | 44 | static void us_dvorak_destroy(layout_t *);
|
---|
[28a5ebd] | 45 | static char32_t us_dvorak_parse_ev(layout_t *, kbd_event_t *ev);
|
---|
[0175246] | 46 |
|
---|
[2f7a564] | 47 | layout_ops_t us_dvorak_ops = {
|
---|
| 48 | .create = us_dvorak_create,
|
---|
| 49 | .destroy = us_dvorak_destroy,
|
---|
| 50 | .parse_ev = us_dvorak_parse_ev
|
---|
[0175246] | 51 | };
|
---|
| 52 |
|
---|
[28a5ebd] | 53 | static char32_t map_lcase[] = {
|
---|
[f89979b] | 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',
|
---|
[d1eece6] | 84 | };
|
---|
| 85 |
|
---|
[28a5ebd] | 86 | static char32_t map_ucase[] = {
|
---|
[d1eece6] | 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 |
|
---|
[28a5ebd] | 119 | static char32_t map_not_shifted[] = {
|
---|
[d1eece6] | 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 | };
|
---|
[f89979b] | 148 |
|
---|
[28a5ebd] | 149 | static char32_t map_shifted[] = {
|
---|
[d1eece6] | 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 |
|
---|
[28a5ebd] | 179 | static char32_t map_neutral[] = {
|
---|
[d1eece6] | 180 | [KC_BACKSPACE] = '\b',
|
---|
| 181 | [KC_TAB] = '\t',
|
---|
[2069690] | 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 |
|
---|
[28a5ebd] | 192 | static char32_t map_numeric[] = {
|
---|
[2069690] | 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] = '.'
|
---|
[f89979b] | 205 | };
|
---|
| 206 |
|
---|
[28a5ebd] | 207 | static char32_t translate(unsigned int key, char32_t *map, size_t map_length)
|
---|
[d1eece6] | 208 | {
|
---|
[4f22731f] | 209 | if (key >= map_length)
|
---|
| 210 | return 0;
|
---|
| 211 | return map[key];
|
---|
[d1eece6] | 212 | }
|
---|
| 213 |
|
---|
[b7fd2a0] | 214 | static errno_t us_dvorak_create(layout_t *state)
|
---|
[d15815e2] | 215 | {
|
---|
[2f7a564] | 216 | return EOK;
|
---|
[d15815e2] | 217 | }
|
---|
| 218 |
|
---|
[2f7a564] | 219 | static void us_dvorak_destroy(layout_t *state)
|
---|
| 220 | {
|
---|
| 221 | }
|
---|
| 222 |
|
---|
[28a5ebd] | 223 | static char32_t us_dvorak_parse_ev(layout_t *state, kbd_event_t *ev)
|
---|
[f89979b] | 224 | {
|
---|
[28a5ebd] | 225 | char32_t c;
|
---|
[d1eece6] | 226 |
|
---|
[28a5ebd] | 227 | c = translate(ev->key, map_neutral, sizeof(map_neutral) / sizeof(char32_t));
|
---|
[4f22731f] | 228 | if (c != 0)
|
---|
| 229 | return c;
|
---|
[d1eece6] | 230 |
|
---|
| 231 | if (((ev->mods & KM_SHIFT) != 0) ^ ((ev->mods & KM_CAPS_LOCK) != 0))
|
---|
[28a5ebd] | 232 | c = translate(ev->key, map_ucase, sizeof(map_ucase) / sizeof(char32_t));
|
---|
[d1eece6] | 233 | else
|
---|
[28a5ebd] | 234 | c = translate(ev->key, map_lcase, sizeof(map_lcase) / sizeof(char32_t));
|
---|
[d1eece6] | 235 |
|
---|
[4f22731f] | 236 | if (c != 0)
|
---|
| 237 | return c;
|
---|
[d1eece6] | 238 |
|
---|
| 239 | if ((ev->mods & KM_SHIFT) != 0)
|
---|
[28a5ebd] | 240 | c = translate(ev->key, map_shifted, sizeof(map_shifted) / sizeof(char32_t));
|
---|
[d1eece6] | 241 | else
|
---|
[28a5ebd] | 242 | c = translate(ev->key, map_not_shifted, sizeof(map_not_shifted) / sizeof(char32_t));
|
---|
[d1eece6] | 243 |
|
---|
[4f22731f] | 244 | if (c != 0)
|
---|
| 245 | return c;
|
---|
[2069690] | 246 |
|
---|
| 247 | if ((ev->mods & KM_NUM_LOCK) != 0)
|
---|
[28a5ebd] | 248 | c = translate(ev->key, map_numeric, sizeof(map_numeric) / sizeof(char32_t));
|
---|
[2069690] | 249 | else
|
---|
| 250 | c = 0;
|
---|
[d1eece6] | 251 |
|
---|
[2069690] | 252 | return c;
|
---|
[f89979b] | 253 | }
|
---|
| 254 |
|
---|
| 255 | /**
|
---|
| 256 | * @}
|
---|
[4f22731f] | 257 | */
|
---|