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 ********************************************************/
27 #define DEBUG_VAR debugFlags
36 #include <X11/extensions/XKB.h>
41 InitVModInfo(VModInfo * info, struct xkb_desc * xkb)
43 ClearVModInfo(info, xkb);
49 ClearVModInfo(VModInfo * info, struct xkb_desc * xkb)
53 if (XkbcAllocNames(xkb, XkbVirtualModNamesMask, 0, 0) != Success)
55 if (XkbcAllocServerMap(xkb, XkbVirtualModsMask, 0) != Success)
58 info->newlyDefined = info->defined = info->available = 0;
59 if (xkb && xkb->names)
62 for (i = 0, bit = 1; i < XkbNumVirtualMods; i++, bit <<= 1)
64 if (xkb->names->vmods[i] != None)
71 /***====================================================================***/
74 * Handle one entry in the virtualModifiers line (e.g. NumLock).
75 * If the entry is e.g. NumLock=Mod1, stmt->value is not NULL, and the
76 * XkbServerMap's vmod is set to the given modifier. Otherwise, the vmod is 0.
78 * @param stmt The statement specifying the name and (if any the value).
79 * @param mergeMode Merge strategy (e.g. MergeOverride)
82 HandleVModDef(VModDef * stmt, unsigned mergeMode, VModInfo * info)
84 register int i, bit, nextFree;
86 struct xkb_server_map * srv;
87 struct xkb_names * names;
89 srv = info->xkb->server;
90 names = info->xkb->names;
91 for (i = 0, bit = 1, nextFree = -1; i < XkbNumVirtualMods; i++, bit <<= 1)
93 if (info->defined & bit)
95 if (names->vmods[i] == stmt->name)
96 { /* already defined */
97 info->available |= bit;
98 if (stmt->value == NULL)
103 const char *str2 = "";
104 if (!ExprResolveModMask(stmt->value, &mod, NULL, NULL))
106 str1 = XkbcAtomText(stmt->name);
107 ACTION("Declaration of %s ignored\n", str1);
110 if (mod.uval == srv->vmods[i])
113 str1 = XkbcAtomText(stmt->name);
114 WARN("Virtual modifier %s multiply defined\n", str1);
115 str1 = XkbcModMaskText(srv->vmods[i], True);
116 if (mergeMode == MergeOverride)
119 str1 = XkbcModMaskText(mod.uval, True);
121 ACTION("Using %s, ignoring %s\n", str1, str2);
122 if (mergeMode == MergeOverride)
123 srv->vmods[i] = mod.uval;
128 else if (nextFree < 0)
133 ERROR("Too many virtual modifiers defined (maximum %d)\n",
137 info->defined |= (1 << nextFree);
138 info->newlyDefined |= (1 << nextFree);
139 info->available |= (1 << nextFree);
140 names->vmods[nextFree] = stmt->name;
141 if (stmt->value == NULL)
143 if (ExprResolveModMask(stmt->value, &mod, NULL, NULL))
145 srv->vmods[nextFree] = mod.uval;
148 ACTION("Declaration of %s ignored\n", XkbcAtomText(stmt->name));
153 * Returns the index of the given modifier in the xkb->names->vmods array.
155 * @param priv Pointer to the xkb data structure.
156 * @param elem Must be None, otherwise return False.
157 * @param field The Atom of the modifier's name (e.g. Atom for LAlt)
158 * @param type Must be TypeInt, otherwise return False.
159 * @param val_rtrn Set to the index of the modifier that matches.
161 * @return True on success, False otherwise. If False is returned, val_rtrn is
165 LookupVModIndex(char * priv,
166 uint32_t elem, uint32_t field, unsigned type, ExprResult * val_rtrn)
169 struct xkb_desc * xkb;
171 xkb = (struct xkb_desc *) priv;
172 if ((xkb == NULL) || (xkb->names == NULL) || (elem != None)
173 || (type != TypeInt))
177 /* For each named modifier, get the name and compare it to the one passed
178 * in. If we get a match, return the index of the modifier.
179 * The order of modifiers is the same as in the virtual_modifiers line in
180 * the xkb_types section.
182 for (i = 0; i < XkbNumVirtualMods; i++)
184 if (xkb->names->vmods[i] == field)
194 * Get the mask for the given modifier and set val_rtrn.uval to the mask.
195 * Note that the mask returned is always > 512.
197 * @param priv Pointer to xkb data structure.
198 * @param val_rtrn Set to the mask returned.
200 * @return True on success, False otherwise. If False is returned, val_rtrn is
204 LookupVModMask(char * priv,
205 uint32_t elem, uint32_t field, unsigned type, ExprResult * val_rtrn)
207 if (LookupVModIndex(priv, elem, field, type, val_rtrn))
209 register unsigned ndx = val_rtrn->uval;
210 val_rtrn->uval = (1 << (XkbNumModifiers + ndx));
217 FindKeypadVMod(struct xkb_desc * xkb)
222 name = XkbcInternAtom("NumLock", False);
223 if ((xkb) && LookupVModIndex((char *) xkb, None, name, TypeInt, &rtrn))
231 ResolveVirtualModifier(ExprDef * def, ExprResult * val_rtrn, VModInfo * info)
233 struct xkb_names * names;
235 names = info->xkb->names;
236 if (def->op == ExprIdent)
239 for (i = 0, bit = 1; i < XkbNumVirtualMods; i++, bit <<= 1)
241 if ((info->available & bit) && names->vmods[i] == def->value.str)
248 if (ExprResolveInteger(def, val_rtrn, NULL, NULL))
250 if (val_rtrn->uval < XkbNumVirtualMods)
252 ERROR("Illegal virtual modifier %d (must be 0..%d inclusive)\n",
253 val_rtrn->uval, XkbNumVirtualMods - 1);