us_dvorak.c

00001 /*
00002  * Copyright (c) 2009 Jiri Svoboda
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  *
00009  * - Redistributions of source code must retain the above copyright
00010  *   notice, this list of conditions and the following disclaimer.
00011  * - Redistributions in binary form must reproduce the above copyright
00012  *   notice, this list of conditions and the following disclaimer in the
00013  *   documentation and/or other materials provided with the distribution.
00014  * - The name of the author may not be used to endorse or promote products
00015  *   derived from this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
00018  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00019  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
00020  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
00021  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
00022  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00023  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00024  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00025  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00026  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00027  */
00028 
00034 #include <kbd.h>
00035 #include <io/console.h>
00036 #include <io/keycode.h>
00037 #include <layout.h>
00038 
00039 static void layout_reset(void);
00040 static wchar_t layout_parse_ev(console_event_t *ev);
00041 
00042 layout_op_t us_dvorak_op = {
00043         layout_reset,
00044         layout_parse_ev
00045 };
00046 
00047 static wchar_t map_lcase[] = {
00048         [KC_R] = 'p',
00049         [KC_T] = 'y',
00050         [KC_Y] = 'f',
00051         [KC_U] = 'g',
00052         [KC_I] = 'c',
00053         [KC_O] = 'r',
00054         [KC_P] = 'l',
00055 
00056         [KC_A] = 'a',
00057         [KC_S] = 'o',
00058         [KC_D] = 'e',
00059         [KC_F] = 'u',
00060         [KC_G] = 'i',
00061         [KC_H] = 'd',
00062         [KC_J] = 'h',
00063         [KC_K] = 't',
00064         [KC_L] = 'n',
00065 
00066         [KC_SEMICOLON] = 's',
00067 
00068         [KC_X] = 'q',
00069         [KC_C] = 'j',
00070         [KC_V] = 'k',
00071         [KC_B] = 'x',
00072         [KC_N] = 'b',
00073         [KC_M] = 'm',
00074 
00075         [KC_COMMA] = 'w',
00076         [KC_PERIOD] = 'v',
00077         [KC_SLASH] = 'z',
00078 };
00079 
00080 static wchar_t map_ucase[] = {
00081         [KC_R] = 'P',
00082         [KC_T] = 'Y',
00083         [KC_Y] = 'F',
00084         [KC_U] = 'G',
00085         [KC_I] = 'C',
00086         [KC_O] = 'R',
00087         [KC_P] = 'L',
00088 
00089         [KC_A] = 'A',
00090         [KC_S] = 'O',
00091         [KC_D] = 'E',
00092         [KC_F] = 'U',
00093         [KC_G] = 'I',
00094         [KC_H] = 'D',
00095         [KC_J] = 'H',
00096         [KC_K] = 'T',
00097         [KC_L] = 'N',
00098 
00099         [KC_SEMICOLON] = 'S',
00100 
00101         [KC_X] = 'Q',
00102         [KC_C] = 'J',
00103         [KC_V] = 'K',
00104         [KC_B] = 'X',
00105         [KC_N] = 'B',
00106         [KC_M] = 'M',
00107 
00108         [KC_COMMA] = 'W',
00109         [KC_PERIOD] = 'V',
00110         [KC_SLASH] = 'Z',
00111 };
00112 
00113 static wchar_t map_not_shifted[] = {
00114         [KC_BACKTICK] = '`',
00115 
00116         [KC_1] = '1',
00117         [KC_2] = '2',
00118         [KC_3] = '3',
00119         [KC_4] = '4',
00120         [KC_5] = '5',
00121         [KC_6] = '6',
00122         [KC_7] = '7',
00123         [KC_8] = '8',
00124         [KC_9] = '9',
00125         [KC_0] = '0',
00126 
00127         [KC_MINUS] = '[',
00128         [KC_EQUALS] = ']',
00129 
00130         [KC_Q] = '\'',
00131         [KC_W] = ',',
00132         [KC_E] = '.',
00133 
00134         [KC_LBRACKET] = '/',
00135         [KC_RBRACKET] = '=',
00136 
00137         [KC_QUOTE] = '-',
00138         [KC_BACKSLASH] = '\\',
00139 
00140         [KC_Z] = ';',
00141 };
00142 
00143 static wchar_t map_shifted[] = {
00144         [KC_BACKTICK] = '~',
00145 
00146         [KC_1] = '!',
00147         [KC_2] = '@',
00148         [KC_3] = '#',
00149         [KC_4] = '$',
00150         [KC_5] = '%',
00151         [KC_6] = '^',
00152         [KC_7] = '&',
00153         [KC_8] = '*',
00154         [KC_9] = '(',
00155         [KC_0] = ')',
00156 
00157         [KC_MINUS] = '{',
00158         [KC_EQUALS] = '}',
00159 
00160         [KC_Q] = '"',
00161         [KC_W] = '<',
00162         [KC_E] = '>',
00163 
00164         [KC_LBRACKET] = '?',
00165         [KC_RBRACKET] = '+',
00166 
00167         [KC_QUOTE] = '_',
00168         [KC_BACKSLASH] = '|',
00169 
00170         [KC_Z] = ':',
00171 };
00172 
00173 static wchar_t map_neutral[] = {
00174         [KC_BACKSPACE] = '\b',
00175         [KC_TAB] = '\t',
00176         [KC_ENTER] = '\n',
00177         [KC_SPACE] = ' ',
00178 
00179         [KC_NSLASH] = '/',
00180         [KC_NTIMES] = '*',
00181         [KC_NMINUS] = '-',
00182         [KC_NPLUS] = '+',
00183         [KC_NENTER] = '\n'
00184 };
00185 
00186 static wchar_t map_numeric[] = {
00187         [KC_N7] = '7',
00188         [KC_N8] = '8',
00189         [KC_N9] = '9',
00190         [KC_N4] = '4',
00191         [KC_N5] = '5',
00192         [KC_N6] = '6',
00193         [KC_N1] = '1',
00194         [KC_N2] = '2',
00195         [KC_N3] = '3',
00196 
00197         [KC_N0] = '0',
00198         [KC_NPERIOD] = '.'
00199 };
00200 
00201 static wchar_t translate(unsigned int key, wchar_t *map, size_t map_length)
00202 {
00203         if (key >= map_length)
00204                 return 0;
00205         return map[key];
00206 }
00207 
00208 static void layout_reset(void)
00209 {
00210 }
00211 
00212 static wchar_t layout_parse_ev(console_event_t *ev)
00213 {
00214         wchar_t c;
00215 
00216         /* Produce no characters when Ctrl or Alt is pressed. */
00217         if ((ev->mods & (KM_CTRL | KM_ALT)) != 0)
00218                 return 0;
00219 
00220         c = translate(ev->key, map_neutral, sizeof(map_neutral) / sizeof(wchar_t));
00221         if (c != 0)
00222                 return c;
00223 
00224         if (((ev->mods & KM_SHIFT) != 0) ^ ((ev->mods & KM_CAPS_LOCK) != 0))
00225                 c = translate(ev->key, map_ucase, sizeof(map_ucase) / sizeof(wchar_t));
00226         else
00227                 c = translate(ev->key, map_lcase, sizeof(map_lcase) / sizeof(wchar_t));
00228 
00229         if (c != 0)
00230                 return c;
00231 
00232         if ((ev->mods & KM_SHIFT) != 0)
00233                 c = translate(ev->key, map_shifted, sizeof(map_shifted) / sizeof(wchar_t));
00234         else
00235                 c = translate(ev->key, map_not_shifted, sizeof(map_not_shifted) / sizeof(wchar_t));
00236 
00237         if (c != 0)
00238                 return c;
00239 
00240         if ((ev->mods & KM_NUM_LOCK) != 0)
00241                 c = translate(ev->key, map_numeric, sizeof(map_numeric) / sizeof(wchar_t));
00242         else
00243                 c = 0;
00244 
00245         return c;
00246 }
00247 

Generated on Thu Jun 2 07:45:50 2011 for HelenOS/USB by  doxygen 1.4.7