2 * Copyright 1985, 1987, 1990, 1998 The Open Group
3 * Copyright 2008 Dan Nicholson
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
19 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 * Except as contained in this notice, the names of the authors or their
23 * institutions shall not be used in advertising or otherwise to promote the
24 * sale, use or other dealings in this Software without prior written
25 * authorization from the authors.
33 #include "ks_tables.h"
36 xkb_keysym_get_name(xkb_keysym_t ks, char *buffer, size_t size)
39 const unsigned char *entry;
40 unsigned char val1, val2, val3, val4;
42 if ((ks & ((unsigned long) ~0x1fffffff)) != 0) {
43 snprintf(buffer, size, "Invalid");
47 /* Try to find it in our hash table. */
48 if (ks <= 0x1fffffff) {
50 val2 = (ks >> 16) & 0xff;
51 val3 = (ks >> 8) & 0xff;
57 while ((idx = hashKeysym[i])) {
58 entry = &_XkeyTable[idx];
60 if ((entry[0] == val1) && (entry[1] == val2) &&
61 (entry[2] == val3) && (entry[3] == val4)) {
62 snprintf(buffer, size, "%s", entry + 4);
75 if (ks >= 0x01000100 && ks <= 0x0110ffff)
76 /* Unnamed Unicode codepoint. */
77 snprintf(buffer, size, "U%lx", ks & 0xffffffUL);
79 /* Unnamed, non-Unicode, symbol (shouldn't generally happen). */
80 snprintf(buffer, size, "0x%08x", ks);
83 XKB_EXPORT xkb_keysym_t
84 xkb_keysym_from_name(const char *s)
90 const unsigned char *entry;
91 unsigned char sig1, sig2;
99 sig1 = (sig >> 8) & 0xff;
103 while ((idx = hashString[i])) {
104 entry = &_XkeyTable[idx];
106 if ((entry[0] == sig1) && (entry[1] == sig2) &&
107 !strcmp(s, (const char *) entry + 6)) {
108 val = (entry[2] << 24) | (entry[3] << 16) |
109 (entry[4] << 8) | entry[5];
111 val = XKB_KEY_VoidSymbol;
124 val = strtoul(&s[1], &tmp, 16);
125 if (tmp && *tmp != '\0')
126 return XKB_KEY_NoSymbol;
128 if (val < 0x20 || (val > 0x7e && val < 0xa0))
129 return XKB_KEY_NoSymbol;
133 return XKB_KEY_NoSymbol;
134 return val | 0x01000000;
136 else if (s[0] == '0' && s[1] == 'x') {
137 val = strtoul(&s[2], &tmp, 16);
138 if (tmp && *tmp != '\0')
139 return XKB_KEY_NoSymbol;
144 /* Stupid inconsistency between the headers and XKeysymDB: the former has
145 * no separating underscore, while some XF86* syms in the latter did.
146 * As a last ditch effort, try without. */
147 if (strncmp(s, "XF86_", 5) == 0) {
151 return XKB_KEY_NoSymbol;
152 memmove(&tmp[4], &tmp[5], strlen(s) - 5 + 1);
153 ret = xkb_keysym_from_name(tmp);
158 return XKB_KEY_NoSymbol;
167 static enum keysym_case
168 keysym_get_case(xkb_keysym_t ks)
170 unsigned set = (ks & (~0xff)) >> 8;
173 case 0: /* latin 1 */
174 if ((ks >= XKB_KEY_A && ks <= XKB_KEY_Z) ||
175 (ks >= XKB_KEY_Agrave && ks <= XKB_KEY_THORN && ks !=
178 if ((ks >= XKB_KEY_a && ks <= XKB_KEY_z) ||
179 (ks >= XKB_KEY_agrave && ks <= XKB_KEY_ydiaeresis))
183 case 1: /* latin 2 */
184 if ((ks >= XKB_KEY_Aogonek && ks <= XKB_KEY_Zabovedot && ks !=
186 (ks >= XKB_KEY_Racute && ks <= XKB_KEY_Tcedilla))
188 if ((ks >= XKB_KEY_aogonek && ks <= XKB_KEY_zabovedot && ks !=
190 (ks >= XKB_KEY_racute && ks <= XKB_KEY_tcedilla))
194 case 2: /* latin 3 */
195 if ((ks >= XKB_KEY_Hstroke && ks <= XKB_KEY_Jcircumflex) ||
196 (ks >= XKB_KEY_Cabovedot && ks <= XKB_KEY_Scircumflex))
198 if ((ks >= XKB_KEY_hstroke && ks <= XKB_KEY_jcircumflex) ||
199 (ks >= XKB_KEY_cabovedot && ks <= XKB_KEY_scircumflex))
203 case 3: /* latin 4 */
204 if ((ks >= XKB_KEY_Rcedilla && ks <= XKB_KEY_Tslash) ||
205 (ks == XKB_KEY_ENG) ||
206 (ks >= XKB_KEY_Amacron && ks <= XKB_KEY_Umacron))
208 if ((ks >= XKB_KEY_rcedilla && ks <= XKB_KEY_tslash) ||
209 (ks == XKB_KEY_eng) ||
210 (ks >= XKB_KEY_amacron && ks <= XKB_KEY_umacron))
214 case 6: /* Cyrillic */
215 if ((ks >= XKB_KEY_Serbian_DJE && ks <= XKB_KEY_Serbian_DZE) ||
216 (ks >= XKB_KEY_Cyrillic_YU && ks <= XKB_KEY_Cyrillic_HARDSIGN))
218 if ((ks >= XKB_KEY_Serbian_dje && ks <= XKB_KEY_Serbian_dze) ||
219 (ks >= XKB_KEY_Cyrillic_yu && ks <= XKB_KEY_Cyrillic_hardsign))
224 if ((ks >= XKB_KEY_Greek_ALPHAaccent &&
225 ks <= XKB_KEY_Greek_OMEGAaccent) ||
226 (ks >= XKB_KEY_Greek_ALPHA && ks <= XKB_KEY_Greek_OMEGA))
228 if ((ks >= XKB_KEY_Greek_alphaaccent &&
229 ks <= XKB_KEY_Greek_omegaaccent) ||
230 (ks >= XKB_KEY_Greek_alpha && ks <= XKB_KEY_Greek_OMEGA))
234 case 18: /* latin 8 */
235 if ((ks == XKB_KEY_Wcircumflex) ||
236 (ks == XKB_KEY_Ycircumflex) ||
237 (ks == XKB_KEY_Babovedot) ||
238 (ks == XKB_KEY_Dabovedot) ||
239 (ks == XKB_KEY_Fabovedot) ||
240 (ks == XKB_KEY_Mabovedot) ||
241 (ks == XKB_KEY_Pabovedot) ||
242 (ks == XKB_KEY_Sabovedot) ||
243 (ks == XKB_KEY_Tabovedot) ||
244 (ks == XKB_KEY_Wdiaeresis) ||
245 (ks == XKB_KEY_Ygrave))
247 if ((ks == XKB_KEY_wcircumflex) ||
248 (ks == XKB_KEY_ycircumflex) ||
249 (ks == XKB_KEY_babovedot) ||
250 (ks == XKB_KEY_dabovedot) ||
251 (ks == XKB_KEY_fabovedot) ||
252 (ks == XKB_KEY_mabovedot) ||
253 (ks == XKB_KEY_pabovedot) ||
254 (ks == XKB_KEY_sabovedot) ||
255 (ks == XKB_KEY_tabovedot) ||
256 (ks == XKB_KEY_wdiaeresis) ||
257 (ks == XKB_KEY_ygrave))
261 case 19: /* latin 9 */
262 if (ks == XKB_KEY_OE || ks == XKB_KEY_Ydiaeresis)
264 if (ks == XKB_KEY_oe)
273 xkb_keysym_is_lower(xkb_keysym_t keysym)
275 return keysym_get_case(keysym) == LOWERCASE;
279 xkb_keysym_is_upper(xkb_keysym_t keysym)
281 return keysym_get_case(keysym) == UPPERCASE;
285 xkb_keysym_is_keypad(xkb_keysym_t keysym)
287 return keysym >= XKB_KEY_KP_Space && keysym <= XKB_KEY_KP_Equal;