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 ********************************************************/
31 #include "X11/extensions/XKBcommon.h"
32 #include "XKBcommonint.h"
34 #define mapSize(m) (sizeof(m) / sizeof(XkbKTMapEntryRec))
35 static XkbKTMapEntryRec map2Level[]= {
36 { True, ShiftMask, {1, ShiftMask, 0} }
39 static XkbKTMapEntryRec mapAlpha[]= {
40 { True, ShiftMask, { 1, ShiftMask, 0 } },
41 { True, LockMask, { 0, LockMask, 0 } }
44 static XkbModsRec preAlpha[]= {
46 { LockMask, LockMask, 0 }
49 #define NL_VMOD_MASK 0
50 static XkbKTMapEntryRec mapKeypad[]= {
51 { True, ShiftMask, { 1, ShiftMask, 0 } },
52 { False, 0, { 1, 0, NL_VMOD_MASK } }
55 static XkbKeyTypeRec canonicalTypes[XkbNumRequiredTypes] = {
62 { { ShiftMask, ShiftMask, 0 },
64 mapSize(map2Level), /* map_count */
68 { { ShiftMask|LockMask, ShiftMask|LockMask, 0 },
70 mapSize(mapAlpha), /* map_count */
74 { { ShiftMask, ShiftMask, NL_VMOD_MASK },
76 mapSize(mapKeypad), /* map_count */
83 XkbcInitCanonicalKeyTypes(XkbcDescPtr xkb, unsigned which, int keypadVMod)
86 XkbKeyTypePtr from,to;
92 rtrn= XkbcAllocClientMap(xkb, XkbKeyTypesMask, XkbNumRequiredTypes);
97 if ((which & XkbAllRequiredTypes) == 0)
101 from = canonicalTypes;
104 if (which & XkbOneLevelMask)
105 rtrn = XkbcCopyKeyType(&from[XkbOneLevelIndex], &to[XkbOneLevelIndex]);
107 if ((which & XkbTwoLevelMask) && (rtrn == Success))
108 rtrn = XkbcCopyKeyType(&from[XkbTwoLevelIndex], &to[XkbTwoLevelIndex]);
110 if ((which & XkbAlphabeticMask) && (rtrn == Success))
111 rtrn = XkbcCopyKeyType(&from[XkbAlphabeticIndex],
112 &to[XkbAlphabeticIndex]);
114 if ((which & XkbKeypadMask) && (rtrn == Success)) {
117 rtrn = XkbcCopyKeyType(&from[XkbKeypadIndex], &to[XkbKeypadIndex]);
118 type = &to[XkbKeypadIndex];
120 if ((keypadVMod >= 0) && (keypadVMod < XkbNumVirtualMods) &&
122 type->mods.vmods = (1 << keypadVMod);
123 type->map[0].active = True;
124 type->map[0].mods.mask = ShiftMask;
125 type->map[0].mods.real_mods = ShiftMask;
126 type->map[0].mods.vmods = 0;
127 type->map[0].level = 1;
128 type->map[1].active = False;
129 type->map[1].mods.mask = 0;
130 type->map[1].mods.real_mods = 0;
131 type->map[1].mods.vmods = (1 << keypadVMod);
132 type->map[1].level = 1;
140 XkbcVirtualModsToReal(XkbcDescPtr xkb, unsigned virtual_mask,
148 if (virtual_mask == 0) {
155 for (i = mask = 0, bit = 1; i < XkbNumVirtualMods; i++, bit <<= 1) {
156 if (virtual_mask & bit)
157 mask |= xkb->server->vmods[i];
165 * All latin-1 alphanumerics, plus parens, slash, minus, underscore and
168 static unsigned char componentSpecLegal[] = {
169 0x00, 0x00, 0x00, 0x00, 0x00, 0xa7, 0xff, 0x83,
170 0xfe, 0xff, 0xff, 0x87, 0xfe, 0xff, 0xff, 0x07,
171 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
172 0xff, 0xff, 0x7f, 0xff, 0xff, 0xff, 0x7f, 0xff
176 XkbcEnsureSafeMapName(char *name)
181 while (*name!='\0') {
182 if ((componentSpecLegal[(*name) / 8] & (1 << ((*name) % 8))) == 0)