2 * Copyright © 2012 Intel Corporation
3 * Copyright © 2012 Ran Benita <ran234@gmail.com>
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 (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
24 * Author: Daniel Stone <daniel@fooishbar.org>
30 update_builtin_keymap_fields(struct xkb_keymap *keymap)
32 /* Predefined (AKA real, core, X11) modifiers. The order is important! */
33 static const char *const builtin_mods[] = {
44 for (unsigned i = 0; i < ARRAY_SIZE(builtin_mods); i++) {
45 keymap->mods.mods[i].name = xkb_atom_intern(keymap->ctx,
47 strlen(builtin_mods[i]));
48 keymap->mods.mods[i].type = MOD_REAL;
50 keymap->mods.num_mods = ARRAY_SIZE(builtin_mods);
54 xkb_keymap_new(struct xkb_context *ctx,
55 enum xkb_keymap_format format,
56 enum xkb_keymap_compile_flags flags)
58 struct xkb_keymap *keymap;
60 keymap = calloc(1, sizeof(*keymap));
65 keymap->ctx = xkb_context_ref(ctx);
67 keymap->format = format;
68 keymap->flags = flags;
70 update_builtin_keymap_fields(keymap);
76 XkbKeyByName(struct xkb_keymap *keymap, xkb_atom_t name, bool use_aliases)
80 xkb_keys_foreach(key, keymap)
81 if (key->name == name)
85 xkb_atom_t new_name = XkbResolveKeyAlias(keymap, name);
86 if (new_name != XKB_ATOM_NONE)
87 return XkbKeyByName(keymap, new_name, false);
94 XkbResolveKeyAlias(const struct xkb_keymap *keymap, xkb_atom_t name)
96 for (unsigned i = 0; i < keymap->num_key_aliases; i++)
97 if (keymap->key_aliases[i].alias == name)
98 return keymap->key_aliases[i].real;
100 return XKB_ATOM_NONE;
104 XkbEscapeMapName(char *name)
107 * All latin-1 alphanumerics, plus parens, slash, minus, underscore and
110 static const unsigned char legal[] = {
111 0x00, 0x00, 0x00, 0x00, 0x00, 0xa7, 0xff, 0x83,
112 0xfe, 0xff, 0xff, 0x87, 0xfe, 0xff, 0xff, 0x07,
113 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
114 0xff, 0xff, 0x7f, 0xff, 0xff, 0xff, 0x7f, 0xff
121 unsigned char c = *name;
122 if (!(legal[c / 8] & (1 << (c % 8))))
129 XkbModNameToIndex(const struct xkb_mod_set *mods, xkb_atom_t name,
133 const struct xkb_mod *mod;
135 xkb_mods_enumerate(i, mod, mods)
136 if ((mod->type & type) && name == mod->name)
139 return XKB_MOD_INVALID;
143 XkbLevelsSameSyms(const struct xkb_level *a, const struct xkb_level *b)
145 if (a->num_syms != b->num_syms)
147 if (a->num_syms <= 1)
148 return a->u.sym == b->u.sym;
149 return memcmp(a->u.syms, b->u.syms, sizeof(*a->u.syms) * a->num_syms) == 0;