1 /************************************************************
2 Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.
4 Permission to use, copy, modify, and distribute this
5 software and its documentation for any purpose and without
6 fee is hereby granted, provided that the above copyright
7 notice appear in all copies and that both that copyright
8 notice and this permission notice appear in supporting
9 documentation, and that the name of Silicon Graphics not be
10 used in advertising or publicity pertaining to distribution
11 of the software without specific prior written permission.
12 Silicon Graphics makes no representation about the suitability
13 of this software for any purpose. It is provided "as is"
14 without any express or implied warranty.
16 SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
17 SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
18 AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
19 GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
20 DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
21 DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
22 OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH
23 THE USE OR PERFORMANCE OF THIS SOFTWARE.
25 ********************************************************/
30 XkbcCanonicaliseComponent(char *name, const char *old)
39 if (old && strchr(old, '%'))
42 if (name[0] == '+' || name[0] == '|') {
44 tmp = malloc(strlen(name) + strlen(old) + 1);
47 sprintf(tmp, "%s%s", old, name);
52 memmove(name, &name[1], strlen(&name[1]) + 1);
56 for (i = 0; name[i]; i++) {
59 tmp = malloc(strlen(name) + strlen(old));
62 strncpy(tmp, name, i);
64 strcat(tmp + i + strlen(old), &name[i + 1]);
70 memmove(&name[i - 1], &name[i + 1], strlen(&name[i + 1]) + 1);
80 xkb_canonicalise_components(struct xkb_component_names * names,
81 const struct xkb_component_names * old)
83 names->keycodes = XkbcCanonicaliseComponent(names->keycodes,
84 old ? old->keycodes : NULL);
85 names->compat = XkbcCanonicaliseComponent(names->compat,
86 old ? old->compat : NULL);
87 names->symbols = XkbcCanonicaliseComponent(names->symbols,
88 old ? old->symbols : NULL);
89 names->types = XkbcCanonicaliseComponent(names->types,
90 old ? old->types : NULL);
94 VirtualModsToReal(struct xkb_keymap *xkb, unsigned virtual_mask,
102 if (virtual_mask == 0) {
109 for (i = mask = 0, bit = 1; i < XkbNumVirtualMods; i++, bit <<= 1) {
110 if (virtual_mask & bit)
111 mask |= xkb->server->vmods[i];
119 XkbcComputeEffectiveMap(struct xkb_keymap * xkb, struct xkb_key_type * type,
120 unsigned char *map_rtrn)
124 struct xkb_kt_map_entry * entry = NULL;
126 if (!xkb || !type || !xkb->server)
129 if (type->mods.vmods != 0) {
130 if (!VirtualModsToReal(xkb, type->mods.vmods, &tmp))
133 type->mods.mask = tmp | type->mods.real_mods;
135 for (i = 0; i < type->map_count; i++, entry++) {
137 if (entry->mods.vmods != 0) {
138 if (!VirtualModsToReal(xkb, entry->mods.vmods, &tmp))
141 entry->active = false;
145 entry->active = true;
146 entry->mods.mask = (entry->mods.real_mods | tmp) & type->mods.mask;
150 type->mods.mask = type->mods.real_mods;
153 memset(map_rtrn, 0, type->mods.mask + 1);
154 if (entry && entry->active)
155 for (i = 0; i < type->map_count; i++)
156 map_rtrn[type->map[i].mods.mask] = type->map[i].level;