Rev 3923 | Rev 4036 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3923 | Rev 3933 | ||
---|---|---|---|
Line 34... | Line 34... | ||
34 | #include <kbd.h> |
34 | #include <kbd.h> |
35 | #include <kbd/kbd.h> |
35 | #include <kbd/kbd.h> |
36 | #include <kbd/keycode.h> |
36 | #include <kbd/keycode.h> |
37 | #include <layout.h> |
37 | #include <layout.h> |
38 | 38 | ||
39 | static int map_normal[] = { |
39 | static char map_lcase[] = { |
40 | [KC_BACKTICK] = '`', |
- | |
41 | - | ||
42 | [KC_1] = '1', |
- | |
43 | [KC_2] = '2', |
- | |
44 | [KC_3] = '3', |
- | |
45 | [KC_4] = '4', |
- | |
46 | [KC_5] = '5', |
- | |
47 | [KC_6] = '6', |
- | |
48 | [KC_7] = '7', |
- | |
49 | [KC_8] = '8', |
- | |
50 | [KC_9] = '9', |
- | |
51 | [KC_0] = '0', |
- | |
52 | - | ||
53 | [KC_MINUS] = '[', |
- | |
54 | [KC_EQUALS] = ']', |
- | |
55 | [KC_BACKSPACE] = '\b', |
- | |
56 | - | ||
57 | [KC_TAB] = '\t', |
- | |
58 | - | ||
59 | [KC_Q] = '\'', |
- | |
60 | [KC_W] = ',', |
- | |
61 | [KC_E] = '.', |
- | |
62 | [KC_R] = 'p', |
40 | [KC_R] = 'p', |
63 | [KC_T] = 'y', |
41 | [KC_T] = 'y', |
64 | [KC_Y] = 'f', |
42 | [KC_Y] = 'f', |
65 | [KC_U] = 'g', |
43 | [KC_U] = 'g', |
66 | [KC_I] = 'c', |
44 | [KC_I] = 'c', |
67 | [KC_O] = 'r', |
45 | [KC_O] = 'r', |
68 | [KC_P] = 'l', |
46 | [KC_P] = 'l', |
69 | 47 | ||
70 | [KC_LBRACKET] = '/', |
- | |
71 | [KC_RBRACKET] = '=', |
- | |
72 | - | ||
73 | [KC_A] = 'a', |
48 | [KC_A] = 'a', |
74 | [KC_S] = 'o', |
49 | [KC_S] = 'o', |
75 | [KC_D] = 'e', |
50 | [KC_D] = 'e', |
76 | [KC_F] = 'u', |
51 | [KC_F] = 'u', |
77 | [KC_G] = 'i', |
52 | [KC_G] = 'i', |
Line 79... | Line 54... | ||
79 | [KC_J] = 'h', |
54 | [KC_J] = 'h', |
80 | [KC_K] = 't', |
55 | [KC_K] = 't', |
81 | [KC_L] = 'n', |
56 | [KC_L] = 'n', |
82 | 57 | ||
83 | [KC_SEMICOLON] = 's', |
58 | [KC_SEMICOLON] = 's', |
84 | [KC_QUOTE] = '-', |
- | |
85 | [KC_BACKSLASH] = '\\', |
- | |
86 | 59 | ||
87 | [KC_Z] = ';', |
- | |
88 | [KC_X] = 'q', |
60 | [KC_X] = 'q', |
89 | [KC_C] = 'j', |
61 | [KC_C] = 'j', |
90 | [KC_V] = 'k', |
62 | [KC_V] = 'k', |
91 | [KC_B] = 'x', |
63 | [KC_B] = 'x', |
92 | [KC_N] = 'b', |
64 | [KC_N] = 'b', |
93 | [KC_M] = 'm', |
65 | [KC_M] = 'm', |
94 | 66 | ||
95 | [KC_COMMA] = 'w', |
67 | [KC_COMMA] = 'w', |
96 | [KC_PERIOD] = 'v', |
68 | [KC_PERIOD] = 'v', |
97 | [KC_SLASH] = 'z', |
69 | [KC_SLASH] = 'z', |
- | 70 | }; |
|
- | 71 | ||
- | 72 | static char map_ucase[] = { |
|
- | 73 | [KC_R] = 'P', |
|
- | 74 | [KC_T] = 'Y', |
|
- | 75 | [KC_Y] = 'F', |
|
- | 76 | [KC_U] = 'G', |
|
- | 77 | [KC_I] = 'C', |
|
- | 78 | [KC_O] = 'R', |
|
- | 79 | [KC_P] = 'L', |
|
- | 80 | ||
- | 81 | [KC_A] = 'A', |
|
- | 82 | [KC_S] = 'O', |
|
- | 83 | [KC_D] = 'E', |
|
- | 84 | [KC_F] = 'U', |
|
- | 85 | [KC_G] = 'I', |
|
- | 86 | [KC_H] = 'D', |
|
- | 87 | [KC_J] = 'H', |
|
- | 88 | [KC_K] = 'T', |
|
- | 89 | [KC_L] = 'N', |
|
- | 90 | ||
- | 91 | [KC_SEMICOLON] = 'S', |
|
- | 92 | ||
- | 93 | [KC_X] = 'Q', |
|
- | 94 | [KC_C] = 'J', |
|
- | 95 | [KC_V] = 'K', |
|
- | 96 | [KC_B] = 'X', |
|
- | 97 | [KC_N] = 'B', |
|
- | 98 | [KC_M] = 'M', |
|
- | 99 | ||
- | 100 | [KC_COMMA] = 'W', |
|
- | 101 | [KC_PERIOD] = 'V', |
|
- | 102 | [KC_SLASH] = 'Z', |
|
- | 103 | }; |
|
- | 104 | ||
- | 105 | static char map_not_shifted[] = { |
|
- | 106 | [KC_BACKTICK] = '`', |
|
- | 107 | ||
- | 108 | [KC_1] = '1', |
|
- | 109 | [KC_2] = '2', |
|
- | 110 | [KC_3] = '3', |
|
- | 111 | [KC_4] = '4', |
|
- | 112 | [KC_5] = '5', |
|
- | 113 | [KC_6] = '6', |
|
- | 114 | [KC_7] = '7', |
|
- | 115 | [KC_8] = '8', |
|
- | 116 | [KC_9] = '9', |
|
- | 117 | [KC_0] = '0', |
|
- | 118 | ||
- | 119 | [KC_MINUS] = '[', |
|
- | 120 | [KC_EQUALS] = ']', |
|
- | 121 | ||
- | 122 | [KC_Q] = '\'', |
|
- | 123 | [KC_W] = ',', |
|
- | 124 | [KC_E] = '.', |
|
- | 125 | ||
- | 126 | [KC_LBRACKET] = '/', |
|
- | 127 | [KC_RBRACKET] = '=', |
|
- | 128 | ||
- | 129 | [KC_QUOTE] = '-', |
|
- | 130 | [KC_BACKSLASH] = '\\', |
|
98 | 131 | ||
- | 132 | [KC_Z] = ';', |
|
- | 133 | }; |
|
- | 134 | ||
- | 135 | static char map_shifted[] = { |
|
- | 136 | [KC_BACKTICK] = '~', |
|
- | 137 | ||
- | 138 | [KC_1] = '!', |
|
- | 139 | [KC_2] = '@', |
|
- | 140 | [KC_3] = '#', |
|
- | 141 | [KC_4] = '$', |
|
- | 142 | [KC_5] = '%', |
|
- | 143 | [KC_6] = '^', |
|
- | 144 | [KC_7] = '&', |
|
- | 145 | [KC_8] = '*', |
|
- | 146 | [KC_9] = '(', |
|
- | 147 | [KC_0] = ')', |
|
- | 148 | ||
- | 149 | [KC_MINUS] = '{', |
|
- | 150 | [KC_EQUALS] = '}', |
|
- | 151 | ||
- | 152 | [KC_Q] = '"', |
|
- | 153 | [KC_W] = '<', |
|
- | 154 | [KC_E] = '>', |
|
- | 155 | ||
- | 156 | [KC_LBRACKET] = '?', |
|
- | 157 | [KC_RBRACKET] = '+', |
|
- | 158 | ||
- | 159 | [KC_QUOTE] = '_', |
|
- | 160 | [KC_BACKSLASH] = '|', |
|
- | 161 | ||
- | 162 | [KC_Z] = ':', |
|
- | 163 | }; |
|
- | 164 | ||
- | 165 | static char map_neutral[] = { |
|
- | 166 | [KC_BACKSPACE] = '\b', |
|
- | 167 | [KC_TAB] = '\t', |
|
99 | [KC_ENTER] = '\n' |
168 | [KC_ENTER] = '\n' |
100 | }; |
169 | }; |
101 | 170 | ||
- | 171 | static int translate(unsigned int key, char *map, size_t map_length) |
|
- | 172 | { |
|
- | 173 | if (key >= map_length) return 0; |
|
- | 174 | return map[key]; |
|
- | 175 | } |
|
- | 176 | ||
102 | char layout_parse_ev(kbd_event_t *ev) |
177 | char layout_parse_ev(kbd_event_t *ev) |
103 | { |
178 | { |
- | 179 | char c; |
|
- | 180 | ||
- | 181 | /* Produce no characters when Ctrl or Alt is pressed. */ |
|
104 | if (ev->key >= sizeof(map_normal) / sizeof(int)) |
182 | if ((ev->mods & (KM_CTRL | KM_ALT)) != 0) |
105 | return 0; |
183 | return 0; |
106 | 184 | ||
- | 185 | c = translate(ev->key, map_neutral, sizeof(map_neutral) / sizeof(char)); |
|
- | 186 | if (c != 0) return c; |
|
- | 187 | ||
- | 188 | if (((ev->mods & KM_SHIFT) != 0) ^ ((ev->mods & KM_CAPS_LOCK) != 0)) |
|
- | 189 | c = translate(ev->key, map_ucase, sizeof(map_ucase) / sizeof(char)); |
|
- | 190 | else |
|
- | 191 | c = translate(ev->key, map_lcase, sizeof(map_lcase) / sizeof(char)); |
|
- | 192 | ||
107 | return map_normal[ev->key]; |
193 | if (c != 0) return c; |
- | 194 | ||
- | 195 | if ((ev->mods & KM_SHIFT) != 0) |
|
- | 196 | c = translate(ev->key, map_shifted, sizeof(map_shifted) / sizeof(char)); |
|
- | 197 | else |
|
- | 198 | c = translate(ev->key, map_not_shifted, sizeof(map_not_shifted) / sizeof(char)); |
|
- | 199 | ||
- | 200 | if (c != 0 ) return c; |
|
- | 201 | ||
108 | } |
202 | } |
109 | 203 | ||
- | 204 | ||
110 | /** |
205 | /** |
111 | * @} |
206 | * @} |
112 | */ |
207 | */ |