1 /************************************************************
2 Copyright (c) 1994 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 InitVModInfo(VModInfo *info, struct xkb_keymap *keymap)
32 ClearVModInfo(info, keymap);
37 ClearVModInfo(VModInfo *info, struct xkb_keymap *keymap)
41 info->newlyDefined = info->defined = info->available = 0;
43 if (XkbcAllocNames(keymap, 0, 0) != Success)
46 if (XkbcAllocServerMap(keymap, 0, 0) != Success)
49 info->keymap = keymap;
50 if (keymap && keymap->names)
53 for (i = 0, bit = 1; i < XkbNumVirtualMods; i++, bit <<= 1)
55 if (keymap->names->vmods[i] != NULL)
61 /***====================================================================***/
64 * Handle one entry in the virtualModifiers line (e.g. NumLock).
65 * If the entry is e.g. NumLock=Mod1, stmt->value is not NULL, and the
66 * XkbServerMap's vmod is set to the given modifier. Otherwise, the vmod is 0.
68 * @param stmt The statement specifying the name and (if any the value).
69 * @param mergeMode Merge strategy (e.g. MergeOverride)
72 HandleVModDef(VModDef *stmt, struct xkb_keymap *keymap, unsigned mergeMode,
77 struct xkb_server_map *srv = keymap->server;
78 struct xkb_names *names = keymap->names;
80 for (i = 0, bit = 1, nextFree = -1; i < XkbNumVirtualMods; i++, bit <<= 1)
82 if (info->defined & bit)
84 if (names->vmods[i] &&
85 strcmp(names->vmods[i], XkbcAtomText(stmt->name)) == 0)
86 { /* already defined */
87 info->available |= bit;
88 if (stmt->value == NULL)
93 const char *str2 = "";
94 if (!ExprResolveModMask(stmt->value, &mod))
96 str1 = XkbcAtomText(stmt->name);
97 ACTION("Declaration of %s ignored\n", str1);
100 if (mod.uval == srv->vmods[i])
103 str1 = XkbcAtomText(stmt->name);
104 WARN("Virtual modifier %s multiply defined\n", str1);
105 str1 = XkbcModMaskText(srv->vmods[i], true);
106 if (mergeMode == MergeOverride)
109 str1 = XkbcModMaskText(mod.uval, true);
111 ACTION("Using %s, ignoring %s\n", str1, str2);
112 if (mergeMode == MergeOverride)
113 srv->vmods[i] = mod.uval;
118 else if (nextFree < 0)
123 ERROR("Too many virtual modifiers defined (maximum %d)\n",
127 info->defined |= (1 << nextFree);
128 info->newlyDefined |= (1 << nextFree);
129 info->available |= (1 << nextFree);
130 names->vmods[nextFree] = xkb_atom_strdup(keymap->context, stmt->name);
131 if (stmt->value == NULL)
133 if (ExprResolveModMask(stmt->value, &mod))
135 srv->vmods[nextFree] = mod.uval;
138 ACTION("Declaration of %s ignored\n", XkbcAtomText(stmt->name));
143 * Returns the index of the given modifier in the xkb->names->vmods array.
145 * @param keymap Pointer to the xkb data structure.
146 * @param field The Atom of the modifier's name (e.g. Atom for LAlt)
147 * @param type Must be TypeInt, otherwise return false.
148 * @param val_rtrn Set to the index of the modifier that matches.
150 * @return true on success, false otherwise. If false is returned, val_rtrn is
154 LookupVModIndex(const struct xkb_keymap *keymap, xkb_atom_t field,
155 unsigned type, ExprResult * val_rtrn)
158 const char *name = XkbcAtomText(field);
160 if ((keymap == NULL) || (keymap->names == NULL) || (type != TypeInt))
164 /* For each named modifier, get the name and compare it to the one passed
165 * in. If we get a match, return the index of the modifier.
166 * The order of modifiers is the same as in the virtual_modifiers line in
167 * the xkb_types section.
169 for (i = 0; i < XkbNumVirtualMods; i++)
171 if (keymap->names->vmods[i] &&
172 strcmp(keymap->names->vmods[i], name) == 0)
182 * Get the mask for the given (virtual or core) modifier and set
183 * val_rtrn.uval to the mask value.
185 * @param priv Pointer to xkb data structure.
186 * @param val_rtrn Member uval is set to the mask returned.
188 * @return true on success, false otherwise. If false is returned, val_rtrn is
192 LookupVModMask(const void * priv, xkb_atom_t field, unsigned type,
193 ExprResult * val_rtrn)
195 if (LookupModMask(NULL, field, type, val_rtrn))
199 else if (LookupVModIndex(priv, field, type, val_rtrn))
201 unsigned ndx = val_rtrn->uval;
202 val_rtrn->uval = (1 << (XkbNumModifiers + ndx));
209 FindKeypadVMod(struct xkb_keymap *keymap)
214 name = xkb_atom_intern(keymap->context, "NumLock");
215 if (keymap && LookupVModIndex(keymap, name, TypeInt, &rtrn))
223 ResolveVirtualModifier(ExprDef *def, struct xkb_keymap *keymap,
224 ExprResult *val_rtrn, VModInfo *info)
226 struct xkb_names *names = keymap->names;
228 if (def->op == ExprIdent)
231 const char *name = XkbcAtomText(def->value.str);
232 for (i = 0, bit = 1; i < XkbNumVirtualMods; i++, bit <<= 1)
234 if ((info->available & bit) && names->vmods[i] &&
235 strcmp(names->vmods[i], name) == 0)
242 if (ExprResolveInteger(def, val_rtrn))
244 if (val_rtrn->uval < XkbNumVirtualMods)
246 ERROR("Illegal virtual modifier %d (must be 0..%d inclusive)\n",
247 val_rtrn->uval, XkbNumVirtualMods - 1);