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
35 #include <X11/extensions/XKB.h>
40 InitVModInfo(VModInfo * info, struct xkb_desc * xkb)
42 ClearVModInfo(info, xkb);
47 ClearVModInfo(VModInfo * info, struct xkb_desc * xkb)
51 if (XkbcAllocNames(xkb, XkbVirtualModNamesMask, 0) != Success)
53 if (XkbcAllocServerMap(xkb, XkbVirtualModsMask, 0) != Success)
56 info->newlyDefined = info->defined = info->available = 0;
57 if (xkb && xkb->names)
60 for (i = 0, bit = 1; i < XkbNumVirtualMods; i++, bit <<= 1)
62 if (xkb->names->vmods[i] != NULL)
68 /***====================================================================***/
71 * Handle one entry in the virtualModifiers line (e.g. NumLock).
72 * If the entry is e.g. NumLock=Mod1, stmt->value is not NULL, and the
73 * XkbServerMap's vmod is set to the given modifier. Otherwise, the vmod is 0.
75 * @param stmt The statement specifying the name and (if any the value).
76 * @param mergeMode Merge strategy (e.g. MergeOverride)
79 HandleVModDef(VModDef * stmt, struct xkb_desc *xkb, unsigned mergeMode,
84 struct xkb_server_map * srv;
85 struct xkb_names * names;
89 for (i = 0, bit = 1, nextFree = -1; i < XkbNumVirtualMods; i++, bit <<= 1)
91 if (info->defined & bit)
93 if (names->vmods[i] &&
94 strcmp(names->vmods[i], XkbcAtomText(stmt->name)) == 0)
95 { /* already defined */
96 info->available |= bit;
97 if (stmt->value == NULL)
102 const char *str2 = "";
103 if (!ExprResolveModMask(stmt->value, &mod))
105 str1 = XkbcAtomText(stmt->name);
106 ACTION("Declaration of %s ignored\n", str1);
109 if (mod.uval == srv->vmods[i])
112 str1 = XkbcAtomText(stmt->name);
113 WARN("Virtual modifier %s multiply defined\n", str1);
114 str1 = XkbcModMaskText(srv->vmods[i], True);
115 if (mergeMode == MergeOverride)
118 str1 = XkbcModMaskText(mod.uval, True);
120 ACTION("Using %s, ignoring %s\n", str1, str2);
121 if (mergeMode == MergeOverride)
122 srv->vmods[i] = mod.uval;
127 else if (nextFree < 0)
132 ERROR("Too many virtual modifiers defined (maximum %d)\n",
136 info->defined |= (1 << nextFree);
137 info->newlyDefined |= (1 << nextFree);
138 info->available |= (1 << nextFree);
139 names->vmods[nextFree] = XkbcAtomGetString(stmt->name);
140 if (stmt->value == NULL)
142 if (ExprResolveModMask(stmt->value, &mod))
144 srv->vmods[nextFree] = mod.uval;
147 ACTION("Declaration of %s ignored\n", XkbcAtomText(stmt->name));
152 * Returns the index of the given modifier in the xkb->names->vmods array.
154 * @param priv Pointer to the xkb data structure.
155 * @param field The Atom of the modifier's name (e.g. Atom for LAlt)
156 * @param type Must be TypeInt, otherwise return False.
157 * @param val_rtrn Set to the index of the modifier that matches.
159 * @return True on success, False otherwise. If False is returned, val_rtrn is
163 LookupVModIndex(const struct xkb_desc *xkb, xkb_atom_t field, unsigned type,
164 ExprResult * val_rtrn)
167 const char *name = XkbcAtomText(field);
169 if ((xkb == NULL) || (xkb->names == NULL) || (type != TypeInt))
173 /* For each named modifier, get the name and compare it to the one passed
174 * in. If we get a match, return the index of the modifier.
175 * The order of modifiers is the same as in the virtual_modifiers line in
176 * the xkb_types section.
178 for (i = 0; i < XkbNumVirtualMods; i++)
180 if (xkb->names->vmods[i] && strcmp(xkb->names->vmods[i], name) == 0)
190 * Get the mask for the given (virtual or core) modifier and set
191 * val_rtrn.uval to the mask value.
193 * @param priv Pointer to xkb data structure.
194 * @param val_rtrn Member uval is set to the mask returned.
196 * @return True on success, False otherwise. If False is returned, val_rtrn is
200 LookupVModMask(const void * priv, xkb_atom_t field, unsigned type,
201 ExprResult * val_rtrn)
203 if (LookupModMask(NULL, field, type, val_rtrn))
207 else if (LookupVModIndex(priv, field, type, val_rtrn))
209 unsigned ndx = val_rtrn->uval;
210 val_rtrn->uval = (1 << (XkbNumModifiers + ndx));
217 FindKeypadVMod(struct xkb_desc * xkb)
222 name = xkb_intern_atom("NumLock");
223 if ((xkb) && LookupVModIndex(xkb, name, TypeInt, &rtrn))
231 ResolveVirtualModifier(ExprDef * def, struct xkb_desc *xkb,
232 ExprResult * val_rtrn, VModInfo * info)
234 struct xkb_names * names;
237 if (def->op == ExprIdent)
240 const char *name = XkbcAtomText(def->value.str);
241 for (i = 0, bit = 1; i < XkbNumVirtualMods; i++, bit <<= 1)
243 if ((info->available & bit) && strcmp(names->vmods[i], name) == 0)
250 if (ExprResolveInteger(def, val_rtrn))
252 if (val_rtrn->uval < XkbNumVirtualMods)
254 ERROR("Illegal virtual modifier %d (must be 0..%d inclusive)\n",
255 val_rtrn->uval, XkbNumVirtualMods - 1);