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 struct xkb_context *ctx = keymap->ctx;
35 * Add predefined (AKA real, core, X11) modifiers.
36 * The order is important!
38 darray_appends_t(keymap->mods, struct xkb_mod,
39 { .name = xkb_atom_intern_literal(ctx, "Shift"), .type = MOD_REAL },
40 { .name = xkb_atom_intern_literal(ctx, "Lock"), .type = MOD_REAL },
41 { .name = xkb_atom_intern_literal(ctx, "Control"), .type = MOD_REAL },
42 { .name = xkb_atom_intern_literal(ctx, "Mod1"), .type = MOD_REAL },
43 { .name = xkb_atom_intern_literal(ctx, "Mod2"), .type = MOD_REAL },
44 { .name = xkb_atom_intern_literal(ctx, "Mod3"), .type = MOD_REAL },
45 { .name = xkb_atom_intern_literal(ctx, "Mod4"), .type = MOD_REAL },
46 { .name = xkb_atom_intern_literal(ctx, "Mod5"), .type = MOD_REAL });
50 xkb_keymap_new(struct xkb_context *ctx,
51 enum xkb_keymap_format format,
52 enum xkb_keymap_compile_flags flags)
54 struct xkb_keymap *keymap;
56 keymap = calloc(1, sizeof(*keymap));
61 keymap->ctx = xkb_context_ref(ctx);
63 keymap->format = format;
64 keymap->flags = flags;
66 update_builtin_keymap_fields(keymap);
72 XkbKeyByName(struct xkb_keymap *keymap, xkb_atom_t name, bool use_aliases)
76 xkb_foreach_key(key, keymap)
77 if (key->name == name)
81 xkb_atom_t new_name = XkbResolveKeyAlias(keymap, name);
82 if (new_name != XKB_ATOM_NONE)
83 return XkbKeyByName(keymap, new_name, false);
90 XkbResolveKeyAlias(struct xkb_keymap *keymap, xkb_atom_t name)
92 for (unsigned i = 0; i < keymap->num_key_aliases; i++)
93 if (keymap->key_aliases[i].alias == name)
94 return keymap->key_aliases[i].real;
100 XkbEscapeMapName(char *name)
103 * All latin-1 alphanumerics, plus parens, slash, minus, underscore and
106 static const unsigned char legal[] = {
107 0x00, 0x00, 0x00, 0x00, 0x00, 0xa7, 0xff, 0x83,
108 0xfe, 0xff, 0xff, 0x87, 0xfe, 0xff, 0xff, 0x07,
109 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
110 0xff, 0xff, 0x7f, 0xff, 0xff, 0xff, 0x7f, 0xff
117 if (!(legal[*name / 8] & (1 << (*name % 8))))