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 ********************************************************/
31 #include "parseutils.h"
33 #include <X11/keysym.h>
43 /***====================================================================***/
47 #define RepeatUndefined ~((unsigned)0)
49 #define _Key_Syms (1<<0)
50 #define _Key_Acts (1<<1)
51 #define _Key_Repeat (1<<2)
52 #define _Key_Behavior (1<<3)
53 #define _Key_Type_Dflt (1<<4)
54 #define _Key_Types (1<<5)
55 #define _Key_GroupInfo (1<<6)
56 #define _Key_VModMap (1<<7)
58 typedef struct _KeyInfo
61 unsigned long name; /* the 4 chars of the key name, as long */
62 unsigned char groupInfo;
63 unsigned char typesDefined;
64 unsigned char symsDefined;
65 unsigned char actsDefined;
66 short numLevels[XkbNumKbdGroups];
67 uint32_t *syms[XkbNumKbdGroups];
68 union xkb_action *acts[XkbNumKbdGroups];
69 uint32_t types[XkbNumKbdGroups];
71 struct xkb_behavior behavior;
72 unsigned short vmodmap;
73 unsigned long nameForOverlayKey;
74 unsigned long allowNone;
79 * Init the given key info to sane values.
82 InitKeyInfo(KeyInfo * info)
85 static char dflt[4] = "*";
87 info->defs.defined = 0;
88 info->defs.fileID = 0;
89 info->defs.merge = MergeOverride;
90 info->defs.next = NULL;
91 info->name = KeyNameToLong(dflt);
93 info->typesDefined = info->symsDefined = info->actsDefined = 0;
94 for (i = 0; i < XkbNumKbdGroups; i++)
96 info->numLevels[i] = 0;
97 info->types[i] = None;
101 info->dfltType = None;
102 info->behavior.type = XkbKB_Default;
103 info->behavior.data = 0;
105 info->nameForOverlayKey = 0;
106 info->repeat = RepeatUndefined;
111 * Free memory associated with this key info and reset to sane values.
114 FreeKeyInfo(KeyInfo * info)
118 info->defs.defined = 0;
119 info->defs.fileID = 0;
120 info->defs.merge = MergeOverride;
121 info->defs.next = NULL;
123 info->typesDefined = info->symsDefined = info->actsDefined = 0;
124 for (i = 0; i < XkbNumKbdGroups; i++)
126 info->numLevels[i] = 0;
127 info->types[i] = None;
129 info->syms[i] = NULL;
131 info->acts[i] = NULL;
133 info->dfltType = None;
134 info->behavior.type = XkbKB_Default;
135 info->behavior.data = 0;
137 info->nameForOverlayKey = 0;
138 info->repeat = RepeatUndefined;
143 * Copy old into new, optionally reset old to 0.
144 * If old is reset, new simply re-uses old's memory. Otherwise, the memory is
145 * newly allocated and new points to the new memory areas.
148 CopyKeyInfo(KeyInfo * old, KeyInfo * new, Bool clearOld)
153 new->defs.next = NULL;
156 for (i = 0; i < XkbNumKbdGroups; i++)
158 old->numLevels[i] = 0;
166 for (i = 0; i < XkbNumKbdGroups; i++)
168 width = new->numLevels[i];
169 if (old->syms[i] != NULL)
171 new->syms[i] = uTypedCalloc(width, uint32_t);
175 new->numLevels[i] = 0;
178 memcpy(new->syms[i], old->syms[i], width * sizeof(uint32_t));
180 if (old->acts[i] != NULL)
182 new->acts[i] = uTypedCalloc(width, union xkb_action);
188 memcpy(new->acts[i], old->acts[i],
189 width * sizeof(union xkb_action));
196 /***====================================================================***/
198 typedef struct _ModMapEntry
205 unsigned long keyName;
210 #define SYMBOLS_INIT_SIZE 110
211 #define SYMBOLS_CHUNK 20
212 typedef struct _SymbolsInfo
214 char *name; /* e.g. pc+us+inet(evdev) */
218 unsigned explicit_group;
226 uint32_t groupNames[XkbNumKbdGroups];
233 InitSymbolsInfo(SymbolsInfo * info, struct xkb_desc * xkb)
238 info->explicit_group = 0;
239 info->errorCount = 0;
241 info->merge = MergeOverride;
243 info->szKeys = SYMBOLS_INIT_SIZE;
245 info->keys = uTypedCalloc(SYMBOLS_INIT_SIZE, KeyInfo);
247 for (i = 0; i < XkbNumKbdGroups; i++)
248 info->groupNames[i] = None;
249 InitKeyInfo(&info->dflt);
250 InitVModInfo(&info->vmods, xkb);
252 info->aliases = NULL;
256 FreeSymbolsInfo(SymbolsInfo * info)
263 for (i = 0; i < info->nKeys; i++)
264 FreeKeyInfo(&info->keys[i]);
268 ClearCommonInfo(&info->modMap->defs);
270 ClearAliases(&info->aliases);
271 memset(info, 0, sizeof(SymbolsInfo));
275 ResizeKeyGroup(KeyInfo * key,
276 unsigned group, unsigned atLeastSize, Bool forceActions)
281 tooSmall = (key->numLevels[group] < atLeastSize);
283 newWidth = atLeastSize;
285 newWidth = key->numLevels[group];
287 if ((key->syms[group] == NULL) || tooSmall)
289 key->syms[group] = uTypedRecalloc(key->syms[group],
290 key->numLevels[group], newWidth,
292 if (!key->syms[group])
295 if (((forceActions) && (tooSmall || (key->acts[group] == NULL))) ||
296 (tooSmall && (key->acts[group] != NULL)))
298 key->acts[group] = uTypedRecalloc(key->acts[group],
299 key->numLevels[group], newWidth,
301 if (!key->acts[group])
304 key->numLevels[group] = newWidth;
309 MergeKeyGroups(SymbolsInfo * info,
310 KeyInfo * into, KeyInfo * from, unsigned group)
312 uint32_t *resultSyms;
313 union xkb_action *resultActs;
316 Bool report, clobber;
318 clobber = (from->defs.merge != MergeAugment);
319 report = (warningLevel > 9) ||
320 ((into->defs.fileID == from->defs.fileID) && (warningLevel > 0));
321 if (into->numLevels[group] >= from->numLevels[group])
323 resultSyms = into->syms[group];
324 resultActs = into->acts[group];
325 resultWidth = into->numLevels[group];
329 resultSyms = from->syms[group];
330 resultActs = from->acts[group];
331 resultWidth = from->numLevels[group];
333 if (resultSyms == NULL)
335 resultSyms = uTypedCalloc(resultWidth, uint32_t);
338 WSGO("Could not allocate symbols for group merge\n");
339 ACTION("Group %d of key %s not merged\n", group,
340 longText(into->name));
344 if ((resultActs == NULL) && (into->acts[group] || from->acts[group]))
346 resultActs = uTypedCalloc(resultWidth, union xkb_action);
349 WSGO("Could not allocate actions for group merge\n");
350 ACTION("Group %d of key %s not merged\n", group,
351 longText(into->name));
352 if (resultSyms != into->syms[group] &&
353 resultSyms != from->syms[group])
358 for (i = 0; i < resultWidth; i++)
360 uint32_t fromSym, toSym;
361 if (from->syms[group] && (i < from->numLevels[group]))
362 fromSym = from->syms[group][i];
365 if (into->syms[group] && (i < into->numLevels[group]))
366 toSym = into->syms[group][i];
369 if ((fromSym == NoSymbol) || (fromSym == toSym))
370 resultSyms[i] = toSym;
371 else if (toSym == NoSymbol)
372 resultSyms[i] = fromSym;
375 uint32_t use, ignore;
389 ("Multiple symbols for level %d/group %d on key %s\n",
390 i + 1, group + 1, longText(into->name));
391 ACTION("Using %s, ignoring %s\n",
392 XkbcKeysymText(use), XkbcKeysymText(ignore));
396 if (resultActs != NULL)
398 union xkb_action *fromAct, *toAct;
399 fromAct = (from->acts[group] ? &from->acts[group][i] : NULL);
400 toAct = (into->acts[group] ? &into->acts[group][i] : NULL);
401 if (((fromAct == NULL) || (fromAct->type == XkbSA_NoAction))
404 resultActs[i] = *toAct;
406 else if (((toAct == NULL) || (toAct->type == XkbSA_NoAction))
407 && (fromAct != NULL))
409 resultActs[i] = *fromAct;
413 union xkb_action *use, *ignore;
427 ("Multiple actions for level %d/group %d on key %s\n",
428 i + 1, group + 1, longText(into->name));
429 ACTION("Using %s, ignoring %s\n",
430 XkbcActionTypeText(use->type),
431 XkbcActionTypeText(ignore->type));
434 resultActs[i] = *use;
438 if (resultSyms != into->syms[group])
439 free(into->syms[group]);
440 if (resultSyms != from->syms[group])
441 free(from->syms[group]);
442 if (resultActs != into->acts[group])
443 free(into->acts[group]);
444 if (resultActs != from->acts[group])
445 free(from->acts[group]);
446 into->numLevels[group] = resultWidth;
447 into->syms[group] = resultSyms;
448 from->syms[group] = NULL;
449 into->acts[group] = resultActs;
450 from->acts[group] = NULL;
451 into->symsDefined |= (1 << group);
452 from->symsDefined &= ~(1 << group);
453 into->actsDefined |= (1 << group);
454 from->actsDefined &= ~(1 << group);
459 MergeKeys(SymbolsInfo * info, KeyInfo * into, KeyInfo * from)
462 unsigned collide = 0;
465 if (from->defs.merge == MergeReplace)
467 for (i = 0; i < XkbNumKbdGroups; i++)
469 if (into->numLevels[i] != 0)
476 memset(from, 0, sizeof(KeyInfo));
479 report = ((warningLevel > 9) ||
480 ((into->defs.fileID == from->defs.fileID)
481 && (warningLevel > 0)));
482 for (i = 0; i < XkbNumKbdGroups; i++)
484 if (from->numLevels[i] > 0)
486 if (into->numLevels[i] == 0)
488 into->numLevels[i] = from->numLevels[i];
489 into->syms[i] = from->syms[i];
490 into->acts[i] = from->acts[i];
491 into->symsDefined |= (1 << i);
492 from->syms[i] = NULL;
493 from->acts[i] = NULL;
494 from->numLevels[i] = 0;
495 from->symsDefined &= ~(1 << i);
497 into->defs.defined |= _Key_Syms;
499 into->defs.defined |= _Key_Acts;
506 collide |= _Key_Syms;
508 collide |= _Key_Acts;
510 MergeKeyGroups(info, into, from, (unsigned) i);
513 if (from->types[i] != None)
515 if ((into->types[i] != None) && (report) &&
516 (into->types[i] != from->types[i]))
518 uint32_t use, ignore;
519 collide |= _Key_Types;
520 if (from->defs.merge != MergeAugment)
522 use = from->types[i];
523 ignore = into->types[i];
527 use = into->types[i];
528 ignore = from->types[i];
531 ("Multiple definitions for group %d type of key %s\n",
532 i, longText(into->name));
533 ACTION("Using %s, ignoring %s\n",
535 XkbcAtomText(ignore));
537 if ((from->defs.merge != MergeAugment)
538 || (into->types[i] == None))
540 into->types[i] = from->types[i];
544 if (UseNewField(_Key_Behavior, &into->defs, &from->defs, &collide))
546 into->behavior = from->behavior;
547 into->nameForOverlayKey = from->nameForOverlayKey;
548 into->defs.defined |= _Key_Behavior;
550 if (UseNewField(_Key_VModMap, &into->defs, &from->defs, &collide))
552 into->vmodmap = from->vmodmap;
553 into->defs.defined |= _Key_VModMap;
555 if (UseNewField(_Key_Repeat, &into->defs, &from->defs, &collide))
557 into->repeat = from->repeat;
558 into->defs.defined |= _Key_Repeat;
560 if (UseNewField(_Key_Type_Dflt, &into->defs, &from->defs, &collide))
562 into->dfltType = from->dfltType;
563 into->defs.defined |= _Key_Type_Dflt;
565 if (UseNewField(_Key_GroupInfo, &into->defs, &from->defs, &collide))
567 into->groupInfo = from->groupInfo;
568 into->defs.defined |= _Key_GroupInfo;
572 WARN("Symbol map for key %s redefined\n",
573 longText(into->name));
574 ACTION("Using %s definition for conflicting fields\n",
575 (from->defs.merge == MergeAugment ? "first" : "last"));
581 AddKeySymbols(SymbolsInfo * info, KeyInfo * key, struct xkb_desc * xkb)
584 unsigned long real_name;
586 for (i = 0; i < info->nKeys; i++)
588 if (info->keys[i].name == key->name)
589 return MergeKeys(info, &info->keys[i], key);
591 if (FindKeyNameForAlias(xkb, key->name, &real_name))
593 for (i = 0; i < info->nKeys; i++)
595 if (info->keys[i].name == real_name)
596 return MergeKeys(info, &info->keys[i], key);
599 if (info->nKeys >= info->szKeys)
601 info->szKeys += SYMBOLS_CHUNK;
603 uTypedRecalloc(info->keys, info->nKeys, info->szKeys, KeyInfo);
606 WSGO("Could not allocate key symbols descriptions\n");
607 ACTION("Some key symbols definitions may be lost\n");
611 return CopyKeyInfo(key, &info->keys[info->nKeys++], True);
615 AddModMapEntry(SymbolsInfo * info, ModMapEntry * new)
620 clobber = (new->defs.merge != MergeAugment);
621 for (mm = info->modMap; mm != NULL; mm = (ModMapEntry *) mm->defs.next)
623 if (new->haveSymbol && mm->haveSymbol
624 && (new->u.keySym == mm->u.keySym))
626 unsigned use, ignore;
627 if (mm->modifier != new->modifier)
632 ignore = mm->modifier;
637 ignore = new->modifier;
640 ("%s added to symbol map for multiple modifiers\n",
641 XkbcKeysymText(new->u.keySym));
642 ACTION("Using %s, ignoring %s.\n",
643 XkbcModIndexText(use),
644 XkbcModIndexText(ignore));
649 if ((!new->haveSymbol) && (!mm->haveSymbol) &&
650 (new->u.keyName == mm->u.keyName))
652 unsigned use, ignore;
653 if (mm->modifier != new->modifier)
658 ignore = mm->modifier;
663 ignore = new->modifier;
665 ERROR("Key %s added to map for multiple modifiers\n",
666 longText(new->u.keyName));
667 ACTION("Using %s, ignoring %s.\n",
668 XkbcModIndexText(use),
669 XkbcModIndexText(ignore));
675 mm = uTypedAlloc(ModMapEntry);
678 WSGO("Could not allocate modifier map entry\n");
679 ACTION("Modifier map for %s will be incomplete\n",
680 XkbcModIndexText(new->modifier));
684 mm->defs.next = &info->modMap->defs;
689 /***====================================================================***/
692 MergeIncludedSymbols(SymbolsInfo * into, SymbolsInfo * from,
693 unsigned merge, struct xkb_desc * xkb)
698 if (from->errorCount > 0)
700 into->errorCount += from->errorCount;
703 if (into->name == NULL)
705 into->name = from->name;
708 for (i = 0; i < XkbNumKbdGroups; i++)
710 if (from->groupNames[i] != None)
712 if ((merge != MergeAugment) || (into->groupNames[i] == None))
713 into->groupNames[i] = from->groupNames[i];
716 for (i = 0, key = from->keys; i < from->nKeys; i++, key++)
718 if (merge != MergeDefault)
719 key->defs.merge = merge;
720 if (!AddKeySymbols(into, key, xkb))
723 if (from->modMap != NULL)
725 ModMapEntry *mm, *next;
726 for (mm = from->modMap; mm != NULL; mm = next)
728 if (merge != MergeDefault)
729 mm->defs.merge = merge;
730 if (!AddModMapEntry(into, mm))
732 next = (ModMapEntry *) mm->defs.next;
737 if (!MergeAliases(&into->aliases, &from->aliases, merge))
741 typedef void (*FileHandler) (XkbFile * /* rtrn */ ,
742 struct xkb_desc * /* xkb */ ,
743 unsigned /* merge */ ,
744 SymbolsInfo * /* included */
748 HandleIncludeSymbols(IncludeStmt * stmt,
749 struct xkb_desc * xkb, SymbolsInfo * info, FileHandler hndlr)
753 SymbolsInfo included;
757 if ((stmt->file == NULL) && (stmt->map == NULL))
761 memset(info, 0, sizeof(SymbolsInfo));
763 else if (ProcessIncludeFile(stmt, XkmSymbolsIndex, &rtrn, &newMerge))
765 InitSymbolsInfo(&included, xkb);
766 included.fileID = included.dflt.defs.fileID = rtrn->id;
767 included.merge = included.dflt.defs.merge = MergeOverride;
770 included.explicit_group = atoi(stmt->modifier) - 1;
774 included.explicit_group = info->explicit_group;
776 (*hndlr) (rtrn, xkb, MergeOverride, &included);
777 if (stmt->stmt != NULL)
780 included.name = stmt->stmt;
787 info->errorCount += 10;
790 if ((stmt->next != NULL) && (included.errorCount < 1))
794 SymbolsInfo next_incl;
796 for (next = stmt->next; next != NULL; next = next->next)
798 if ((next->file == NULL) && (next->map == NULL))
801 MergeIncludedSymbols(&included, info, next->merge, xkb);
802 FreeSymbolsInfo(info);
804 else if (ProcessIncludeFile(next, XkmSymbolsIndex, &rtrn, &op))
806 InitSymbolsInfo(&next_incl, xkb);
807 next_incl.fileID = next_incl.dflt.defs.fileID = rtrn->id;
808 next_incl.merge = next_incl.dflt.defs.merge = MergeOverride;
811 next_incl.explicit_group = atoi(next->modifier) - 1;
815 next_incl.explicit_group = info->explicit_group;
817 (*hndlr) (rtrn, xkb, MergeOverride, &next_incl);
818 MergeIncludedSymbols(&included, &next_incl, op, xkb);
819 FreeSymbolsInfo(&next_incl);
824 info->errorCount += 10;
833 MergeIncludedSymbols(info, &included, newMerge, xkb);
834 FreeSymbolsInfo(&included);
836 return (info->errorCount == 0);
843 GetGroupIndex(KeyInfo * key,
844 ExprDef * arrayNdx, unsigned what, unsigned *ndx_rtrn)
854 if (arrayNdx == NULL)
859 defined = key->symsDefined;
861 defined = key->actsDefined;
863 for (i = 0; i < XkbNumKbdGroups; i++)
865 if ((defined & (1 << i)) == 0)
871 ERROR("Too many groups of %s for key %s (max %d)\n", name,
872 longText(key->name), XkbNumKbdGroups + 1);
873 ACTION("Ignoring %s defined for extra groups\n", name);
876 if (!ExprResolveGroup(arrayNdx, &tmp))
878 ERROR("Illegal group index for %s of key %s\n", name,
879 longText(key->name));
880 ACTION("Definition with non-integer array index ignored\n");
883 *ndx_rtrn = tmp.uval - 1;
888 AddSymbolsToKey(KeyInfo * key,
889 struct xkb_desc * xkb,
891 ExprDef * arrayNdx, ExprDef * value, SymbolsInfo * info)
896 if (!GetGroupIndex(key, arrayNdx, SYMBOLS, &ndx))
900 key->symsDefined |= (1 << ndx);
903 if (value->op != ExprKeysymList)
905 ERROR("Expected a list of symbols, found %s\n",
906 exprOpText(value->op));
907 ACTION("Ignoring symbols for group %d of %s\n", ndx,
908 longText(key->name));
911 if (key->syms[ndx] != NULL)
913 WSGO("Symbols for key %s, group %d already defined\n",
914 longText(key->name), ndx);
917 nSyms = value->value.list.nSyms;
918 if (((key->numLevels[ndx] < nSyms) || (key->syms[ndx] == NULL)) &&
919 (!ResizeKeyGroup(key, ndx, nSyms, False)))
921 WSGO("Could not resize group %d of key %s\n", ndx,
922 longText(key->name));
923 ACTION("Symbols lost\n");
926 key->symsDefined |= (1 << ndx);
927 for (i = 0; i < nSyms; i++) {
928 if (!LookupKeysym(value->value.list.syms[i], &key->syms[ndx][i])) {
929 WSGO("Could not resolve keysym %s\n", value->value.list.syms[i]);
930 key->syms[ndx][i] = NoSymbol;
933 for (i = key->numLevels[ndx] - 1;
934 (i >= 0) && (key->syms[ndx][i] == NoSymbol); i--)
936 key->numLevels[ndx]--;
942 AddActionsToKey(KeyInfo * key,
943 struct xkb_desc * xkb,
945 ExprDef * arrayNdx, ExprDef * value, SymbolsInfo * info)
950 struct xkb_any_action *toAct;
952 if (!GetGroupIndex(key, arrayNdx, ACTIONS, &ndx))
957 key->actsDefined |= (1 << ndx);
960 if (value->op != ExprActionList)
962 WSGO("Bad expression type (%d) for action list value\n", value->op);
963 ACTION("Ignoring actions for group %d of %s\n", ndx,
964 longText(key->name));
967 if (key->acts[ndx] != NULL)
969 WSGO("Actions for key %s, group %d already defined\n",
970 longText(key->name), ndx);
973 for (nActs = 0, act = value->value.child; act != NULL; nActs++)
975 act = (ExprDef *) act->common.next;
979 WSGO("Action list but not actions in AddActionsToKey\n");
982 if (((key->numLevels[ndx] < nActs) || (key->acts[ndx] == NULL)) &&
983 (!ResizeKeyGroup(key, ndx, nActs, True)))
985 WSGO("Could not resize group %d of key %s\n", ndx,
986 longText(key->name));
987 ACTION("Actions lost\n");
990 key->actsDefined |= (1 << ndx);
992 toAct = (struct xkb_any_action *) key->acts[ndx];
993 act = value->value.child;
994 for (i = 0; i < nActs; i++, toAct++)
996 if (!HandleActionDef(act, xkb, toAct, MergeOverride, info->action))
998 ERROR("Illegal action definition for %s\n",
999 longText(key->name));
1000 ACTION("Action for group %d/level %d ignored\n", ndx + 1, i + 1);
1002 act = (ExprDef *) act->common.next;
1008 SetAllowNone(KeyInfo * key, ExprDef * arrayNdx, ExprDef * value)
1011 unsigned radio_groups = 0;
1013 if (arrayNdx == NULL)
1015 radio_groups = XkbAllRadioGroupsMask;
1019 if (!ExprResolveRadioGroup(arrayNdx, &tmp))
1021 ERROR("Illegal index in group name definition\n");
1022 ACTION("Definition with non-integer array index ignored\n");
1025 if ((tmp.uval < 1) || (tmp.uval > XkbMaxRadioGroups))
1027 ERROR("Illegal radio group specified (must be 1..%d)\n",
1028 XkbMaxRadioGroups + 1);
1029 ACTION("Value of \"allow none\" for group %d ignored\n",
1033 radio_groups |= (1 << (tmp.uval - 1));
1035 if (!ExprResolveBoolean(value, &tmp))
1037 ERROR("Illegal \"allow none\" value for %s\n",
1038 longText(key->name));
1039 ACTION("Non-boolean value ignored\n");
1043 key->allowNone |= radio_groups;
1045 key->allowNone &= ~radio_groups;
1050 static const LookupEntry lockingEntries[] = {
1051 {"true", XkbKB_Lock},
1052 {"yes", XkbKB_Lock},
1054 {"false", XkbKB_Default},
1055 {"no", XkbKB_Default},
1056 {"off", XkbKB_Default},
1057 {"permanent", XkbKB_Lock | XkbKB_Permanent},
1061 static const LookupEntry repeatEntries[] = {
1062 {"true", RepeatYes},
1065 {"false", RepeatNo},
1068 {"default", RepeatUndefined},
1073 SetSymbolsField(KeyInfo * key,
1074 struct xkb_desc * xkb,
1076 ExprDef * arrayNdx, ExprDef * value, SymbolsInfo * info)
1081 if (uStrCaseCmp(field, "type") == 0)
1084 if ((!ExprResolveString(value, &tmp))
1085 && (warningLevel > 0))
1087 WARN("The type field of a key symbol map must be a string\n");
1088 ACTION("Ignoring illegal type definition\n");
1090 if (arrayNdx == NULL)
1092 key->dfltType = xkb_intern_atom(tmp.str);
1093 key->defs.defined |= _Key_Type_Dflt;
1095 else if (!ExprResolveGroup(arrayNdx, &ndx))
1097 ERROR("Illegal group index for type of key %s\n",
1098 longText(key->name));
1099 ACTION("Definition with non-integer array index ignored\n");
1105 key->types[ndx.uval - 1] = xkb_intern_atom(tmp.str);
1106 key->typesDefined |= (1 << (ndx.uval - 1));
1110 else if (uStrCaseCmp(field, "symbols") == 0)
1111 return AddSymbolsToKey(key, xkb, field, arrayNdx, value, info);
1112 else if (uStrCaseCmp(field, "actions") == 0)
1113 return AddActionsToKey(key, xkb, field, arrayNdx, value, info);
1114 else if ((uStrCaseCmp(field, "vmods") == 0) ||
1115 (uStrCaseCmp(field, "virtualmods") == 0) ||
1116 (uStrCaseCmp(field, "virtualmodifiers") == 0))
1118 ok = ExprResolveVModMask(value, &tmp, xkb);
1121 key->vmodmap = (tmp.uval >> 8);
1122 key->defs.defined |= _Key_VModMap;
1126 ERROR("Expected a virtual modifier mask, found %s\n",
1127 exprOpText(value->op));
1128 ACTION("Ignoring virtual modifiers definition for key %s\n",
1129 longText(key->name));
1132 else if ((uStrCaseCmp(field, "locking") == 0)
1133 || (uStrCaseCmp(field, "lock") == 0)
1134 || (uStrCaseCmp(field, "locks") == 0))
1136 ok = ExprResolveEnum(value, &tmp, lockingEntries);
1138 key->behavior.type = tmp.uval;
1139 key->defs.defined |= _Key_Behavior;
1141 else if ((uStrCaseCmp(field, "radiogroup") == 0) ||
1142 (uStrCaseCmp(field, "permanentradiogroup") == 0))
1144 Bool permanent = False;
1145 if (uStrCaseCmp(field, "permanentradiogroup") == 0)
1147 if (ExprResolveString(value, &tmp)) {
1148 ok = (strcmp(tmp.str, "none") == 0);
1154 ok = ExprResolveInteger(value, &tmp);
1158 ERROR("Illegal radio group specification for %s\n",
1159 longText(key->name));
1160 ACTION("Non-integer radio group ignored\n");
1165 key->behavior.type = XkbKB_Default;
1166 key->behavior.data = 0;
1169 if ((tmp.uval < 1) || (tmp.uval > XkbMaxRadioGroups))
1172 ("Radio group specification for %s out of range (1..32)\n",
1173 longText(key->name));
1174 ACTION("Illegal radio group %d ignored\n", tmp.uval);
1177 key->behavior.type =
1178 XkbKB_RadioGroup | (permanent ? XkbKB_Permanent : 0);
1179 key->behavior.data = tmp.uval - 1;
1180 if (key->allowNone & (1 << (tmp.uval - 1)))
1181 key->behavior.data |= XkbKB_RGAllowNone;
1182 key->defs.defined |= _Key_Behavior;
1184 else if (uStrCaseEqual(field, "allownone"))
1186 ok = SetAllowNone(key, arrayNdx, value);
1188 else if (uStrCasePrefix("overlay", field) ||
1189 uStrCasePrefix("permanentoverlay", field))
1191 Bool permanent = False;
1194 if (uStrCasePrefix("permanent", field))
1197 which = &field[sizeof("permanentoverlay") - 1];
1201 which = &field[sizeof("overlay") - 1];
1203 if (sscanf(which, "%d", &overlayNdx) == 1)
1205 if (((overlayNdx < 1) || (overlayNdx > 2)) && (warningLevel > 0))
1207 ERROR("Illegal overlay %d specified for %s\n",
1208 overlayNdx, longText(key->name));
1209 ACTION("Ignored\n");
1213 else if (*which == '\0')
1215 else if (warningLevel > 0)
1217 ERROR("Illegal overlay \"%s\" specified for %s\n",
1218 which, longText(key->name));
1219 ACTION("Ignored\n");
1222 ok = ExprResolveKeyName(value, &tmp);
1225 ERROR("Illegal overlay key specification for %s\n",
1226 longText(key->name));
1227 ACTION("Overlay key must be specified by name\n");
1230 if (overlayNdx == 1)
1231 key->behavior.type = XkbKB_Overlay1;
1233 key->behavior.type = XkbKB_Overlay2;
1235 key->behavior.type |= XkbKB_Permanent;
1237 key->behavior.data = 0;
1238 key->nameForOverlayKey = KeyNameToLong(tmp.keyName.name);
1239 key->defs.defined |= _Key_Behavior;
1241 else if ((uStrCaseCmp(field, "repeating") == 0) ||
1242 (uStrCaseCmp(field, "repeats") == 0) ||
1243 (uStrCaseCmp(field, "repeat") == 0))
1245 ok = ExprResolveEnum(value, &tmp, repeatEntries);
1248 ERROR("Illegal repeat setting for %s\n",
1249 longText(key->name));
1250 ACTION("Non-boolean repeat setting ignored\n");
1253 key->repeat = tmp.uval;
1254 key->defs.defined |= _Key_Repeat;
1256 else if ((uStrCaseCmp(field, "groupswrap") == 0) ||
1257 (uStrCaseCmp(field, "wrapgroups") == 0))
1259 ok = ExprResolveBoolean(value, &tmp);
1262 ERROR("Illegal groupsWrap setting for %s\n",
1263 longText(key->name));
1264 ACTION("Non-boolean value ignored\n");
1268 key->groupInfo = XkbWrapIntoRange;
1270 key->groupInfo = XkbClampIntoRange;
1271 key->defs.defined |= _Key_GroupInfo;
1273 else if ((uStrCaseCmp(field, "groupsclamp") == 0) ||
1274 (uStrCaseCmp(field, "clampgroups") == 0))
1276 ok = ExprResolveBoolean(value, &tmp);
1279 ERROR("Illegal groupsClamp setting for %s\n",
1280 longText(key->name));
1281 ACTION("Non-boolean value ignored\n");
1285 key->groupInfo = XkbClampIntoRange;
1287 key->groupInfo = XkbWrapIntoRange;
1288 key->defs.defined |= _Key_GroupInfo;
1290 else if ((uStrCaseCmp(field, "groupsredirect") == 0) ||
1291 (uStrCaseCmp(field, "redirectgroups") == 0))
1293 if (!ExprResolveGroup(value, &tmp))
1295 ERROR("Illegal group index for redirect of key %s\n",
1296 longText(key->name));
1297 ACTION("Definition with non-integer group ignored\n");
1301 XkbSetGroupInfo(0, XkbRedirectIntoRange, tmp.uval - 1);
1302 key->defs.defined |= _Key_GroupInfo;
1306 ERROR("Unknown field %s in a symbol interpretation\n", field);
1307 ACTION("Definition ignored\n");
1314 SetGroupName(SymbolsInfo * info, ExprDef * arrayNdx, ExprDef * value)
1316 ExprResult tmp, name;
1318 if ((arrayNdx == NULL) && (warningLevel > 0))
1320 WARN("You must specify an index when specifying a group name\n");
1321 ACTION("Group name definition without array subscript ignored\n");
1324 if (!ExprResolveGroup(arrayNdx, &tmp))
1326 ERROR("Illegal index in group name definition\n");
1327 ACTION("Definition with non-integer array index ignored\n");
1330 if (!ExprResolveString(value, &name))
1332 ERROR("Group name must be a string\n");
1333 ACTION("Illegal name for group %d ignored\n", tmp.uval);
1336 info->groupNames[tmp.uval - 1 + info->explicit_group] =
1337 xkb_intern_atom(name.str);
1344 HandleSymbolsVar(VarDef * stmt, struct xkb_desc * xkb, SymbolsInfo * info)
1346 ExprResult elem, field, tmp;
1350 if (ExprResolveLhs(stmt->name, &elem, &field, &arrayNdx) == 0)
1351 return 0; /* internal error, already reported */
1352 if (elem.str && (uStrCaseCmp(elem.str, "key") == 0))
1354 ret = SetSymbolsField(&info->dflt, xkb, field.str, arrayNdx,
1357 else if ((elem.str == NULL) && ((uStrCaseCmp(field.str, "name") == 0) ||
1358 (uStrCaseCmp(field.str, "groupname") ==
1361 ret = SetGroupName(info, arrayNdx, stmt->value);
1363 else if ((elem.str == NULL)
1364 && ((uStrCaseCmp(field.str, "groupswrap") == 0)
1365 || (uStrCaseCmp(field.str, "wrapgroups") == 0)))
1367 if (!ExprResolveBoolean(stmt->value, &tmp))
1369 ERROR("Illegal setting for global groupsWrap\n");
1370 ACTION("Non-boolean value ignored\n");
1375 info->groupInfo = XkbWrapIntoRange;
1377 info->groupInfo = XkbClampIntoRange;
1381 else if ((elem.str == NULL)
1382 && ((uStrCaseCmp(field.str, "groupsclamp") == 0)
1383 || (uStrCaseCmp(field.str, "clampgroups") == 0)))
1385 if (!ExprResolveBoolean(stmt->value, &tmp))
1387 ERROR("Illegal setting for global groupsClamp\n");
1388 ACTION("Non-boolean value ignored\n");
1393 info->groupInfo = XkbClampIntoRange;
1395 info->groupInfo = XkbWrapIntoRange;
1399 else if ((elem.str == NULL)
1400 && ((uStrCaseCmp(field.str, "groupsredirect") == 0)
1401 || (uStrCaseCmp(field.str, "redirectgroups") == 0)))
1403 if (!ExprResolveGroup(stmt->value, &tmp))
1405 ERROR("Illegal group index for global groupsRedirect\n");
1406 ACTION("Definition with non-integer group ignored\n");
1410 info->groupInfo = XkbSetGroupInfo(0, XkbRedirectIntoRange,
1415 else if ((elem.str == NULL) && (uStrCaseCmp(field.str, "allownone") == 0))
1417 ret = SetAllowNone(&info->dflt, arrayNdx, stmt->value);
1420 ret = SetActionField(xkb, elem.str, field.str, arrayNdx, stmt->value,
1430 HandleSymbolsBody(VarDef * def,
1431 struct xkb_desc * xkb, KeyInfo * key, SymbolsInfo * info)
1434 ExprResult tmp, field;
1437 for (; def != NULL; def = (VarDef *) def->common.next)
1439 if ((def->name) && (def->name->type == ExprFieldRef))
1441 ok = HandleSymbolsVar(def, xkb, info);
1446 if (def->name == NULL)
1448 if ((def->value == NULL)
1449 || (def->value->op == ExprKeysymList))
1450 field.str = strdup("symbols");
1452 field.str = strdup("actions");
1457 ok = ExprResolveLhs(def->name, &tmp, &field, &arrayNdx);
1460 ok = SetSymbolsField(key, xkb, field.str, arrayNdx,
1469 SetExplicitGroup(SymbolsInfo * info, KeyInfo * key)
1471 unsigned group = info->explicit_group;
1476 if ((key->typesDefined | key->symsDefined | key->actsDefined) & ~1)
1479 WARN("For the map %s an explicit group specified\n", info->name);
1480 WARN("but key %s has more than one group defined\n",
1481 longText(key->name));
1482 ACTION("All groups except first one will be ignored\n");
1483 for (i = 1; i < XkbNumKbdGroups; i++)
1485 key->numLevels[i] = 0;
1487 key->syms[i] = NULL;
1489 key->acts[i] = NULL;
1493 key->typesDefined = key->symsDefined = key->actsDefined = 1 << group;
1495 key->numLevels[group] = key->numLevels[0];
1496 key->numLevels[0] = 0;
1497 key->syms[group] = key->syms[0];
1498 key->syms[0] = NULL;
1499 key->acts[group] = key->acts[0];
1500 key->acts[0] = NULL;
1501 key->types[group] = key->types[0];
1507 HandleSymbolsDef(SymbolsDef * stmt,
1508 struct xkb_desc * xkb, unsigned merge, SymbolsInfo * info)
1513 CopyKeyInfo(&info->dflt, &key, False);
1514 key.defs.merge = stmt->merge;
1515 key.name = KeyNameToLong(stmt->keyName);
1516 if (!HandleSymbolsBody((VarDef *) stmt->symbols, xkb, &key, info))
1522 if (!SetExplicitGroup(info, &key))
1528 if (!AddKeySymbols(info, &key, xkb))
1537 HandleModMapDef(ModMapDef * def,
1538 struct xkb_desc * xkb, unsigned merge, SymbolsInfo * info)
1545 if (!LookupModIndex(NULL, def->modifier, TypeInt, &rtrn))
1547 ERROR("Illegal modifier map definition\n");
1548 ACTION("Ignoring map for non-modifier \"%s\"\n",
1549 XkbcAtomText(def->modifier));
1553 tmp.modifier = rtrn.uval;
1554 for (key = def->keys; key != NULL; key = (ExprDef *) key->common.next)
1556 if ((key->op == ExprValue) && (key->type == TypeKeyName))
1558 tmp.haveSymbol = False;
1559 tmp.u.keyName = KeyNameToLong(key->value.keyName);
1561 else if (ExprResolveKeySym(key, &rtrn))
1563 tmp.haveSymbol = True;
1564 tmp.u.keySym = rtrn.uval;
1568 ERROR("Modmap entries may contain only key names or keysyms\n");
1569 ACTION("Illegal definition for %s modifier ignored\n",
1570 XkbcModIndexText(tmp.modifier));
1574 ok = AddModMapEntry(info, &tmp) && ok;
1580 HandleSymbolsFile(XkbFile * file,
1581 struct xkb_desc * xkb, unsigned merge, SymbolsInfo * info)
1586 info->name = _XkbDupString(file->name);
1590 switch (stmt->stmtType)
1593 if (!HandleIncludeSymbols((IncludeStmt *) stmt, xkb, info,
1597 case StmtSymbolsDef:
1598 if (!HandleSymbolsDef((SymbolsDef *) stmt, xkb, merge, info))
1602 if (!HandleSymbolsVar((VarDef *) stmt, xkb, info))
1606 if (!HandleVModDef((VModDef *) stmt, xkb, merge, &info->vmods))
1610 ERROR("Interpretation files may not include other types\n");
1611 ACTION("Ignoring definition of symbol interpretation\n");
1614 case StmtKeycodeDef:
1615 ERROR("Interpretation files may not include other types\n");
1616 ACTION("Ignoring definition of key name\n");
1620 if (!HandleModMapDef((ModMapDef *) stmt, xkb, merge, info))
1624 WSGO("Unexpected statement type %d in HandleSymbolsFile\n",
1629 if (info->errorCount > 10)
1632 ERROR("Too many errors\n");
1634 ACTION("Abandoning symbols file \"%s\"\n", file->topName);
1641 FindKeyForSymbol(struct xkb_desc * xkb, uint32_t sym, xkb_keycode_t *kc_rtrn)
1650 for (i = xkb->min_key_code; i <= (int) xkb->max_key_code; i++)
1652 if (j < (int) XkbKeyNumSyms(xkb, i))
1655 if (XkbKeySym(xkb, i, j) == sym)
1669 * Find the given name in the xkb->map->types and return its index.
1671 * @param name The atom to search for.
1672 * @param type_rtrn Set to the index of the name if found.
1674 * @return True if found, False otherwise.
1677 FindNamedType(struct xkb_desc * xkb, uint32_t name, unsigned *type_rtrn)
1681 if (xkb && xkb->map && xkb->map->types)
1683 for (n = 0; n < xkb->map->num_types; n++)
1685 if (xkb->map->types[n].name == (uint32_t) name)
1696 * Assign a type to the given sym and return the Atom for the type assigned.
1699 * - ONE_LEVEL for width 0/1
1700 * - ALPHABETIC for 2 shift levels, with lower/upercase
1701 * - KEYPAD for keypad keys.
1702 * - TWO_LEVEL for other 2 shift level keys.
1703 * and the same for four level keys.
1705 * @param width Number of sysms in syms.
1706 * @param syms The keysyms for the given key (must be size width).
1707 * @param typeNameRtrn Set to the Atom of the type name.
1709 * @returns True if a type could be found, False otherwise.
1712 FindAutomaticType(int width, uint32_t * syms, uint32_t * typeNameRtrn,
1716 if ((width == 1) || (width == 0))
1718 *typeNameRtrn = xkb_intern_atom("ONE_LEVEL");
1721 else if (width == 2)
1723 if (syms && XkbcKSIsLower(syms[0]) && XkbcKSIsUpper(syms[1]))
1725 *typeNameRtrn = xkb_intern_atom("ALPHABETIC");
1727 else if (syms && (XkbKSIsKeypad(syms[0]) || XkbKSIsKeypad(syms[1])))
1729 *typeNameRtrn = xkb_intern_atom("KEYPAD");
1734 *typeNameRtrn = xkb_intern_atom("TWO_LEVEL");
1738 else if (width <= 4)
1740 if (syms && XkbcKSIsLower(syms[0]) && XkbcKSIsUpper(syms[1]))
1741 if (XkbcKSIsLower(syms[2]) && XkbcKSIsUpper(syms[3]))
1743 xkb_intern_atom("FOUR_LEVEL_ALPHABETIC");
1745 *typeNameRtrn = xkb_intern_atom("FOUR_LEVEL_SEMIALPHABETIC");
1747 else if (syms && (XkbKSIsKeypad(syms[0]) || XkbKSIsKeypad(syms[1])))
1748 *typeNameRtrn = xkb_intern_atom("FOUR_LEVEL_KEYPAD");
1750 *typeNameRtrn = xkb_intern_atom("FOUR_LEVEL");
1751 /* XXX: why not set autoType here? */
1753 return ((width >= 0) && (width <= 4));
1757 * Ensure the given KeyInfo is in a coherent state, i.e. no gaps between the
1758 * groups, and reduce to one group if all groups are identical anyway.
1761 PrepareKeyDef(KeyInfo * key)
1763 int i, j, width, defined, lastGroup;
1766 defined = key->symsDefined | key->actsDefined | key->typesDefined;
1767 /* get highest group number */
1768 for (i = XkbNumKbdGroups - 1; i >= 0; i--)
1770 if (defined & (1 << i))
1778 /* If there are empty groups between non-empty ones fill them with data */
1779 /* from the first group. */
1780 /* We can make a wrong assumption here. But leaving gaps is worse. */
1781 for (i = lastGroup; i > 0; i--)
1783 if (defined & (1 << i))
1785 width = key->numLevels[0];
1786 if (key->typesDefined & 1)
1788 for (j = 0; j < width; j++)
1790 key->types[i] = key->types[0];
1792 key->typesDefined |= 1 << i;
1794 if ((key->actsDefined & 1) && key->acts[0])
1796 key->acts[i] = uTypedCalloc(width, union xkb_action);
1797 if (key->acts[i] == NULL)
1799 memcpy(key->acts[i], key->acts[0],
1800 width * sizeof(union xkb_action));
1801 key->actsDefined |= 1 << i;
1803 if ((key->symsDefined & 1) && key->syms[0])
1805 key->syms[i] = uTypedCalloc(width, uint32_t);
1806 if (key->syms[i] == NULL)
1808 memcpy(key->syms[i], key->syms[0], width * sizeof(uint32_t));
1809 key->symsDefined |= 1 << i;
1813 key->numLevels[i] = key->numLevels[0];
1816 /* If all groups are completely identical remove them all */
1817 /* exept the first one. */
1819 for (i = lastGroup; i > 0; i--)
1821 if ((key->numLevels[i] != key->numLevels[0]) ||
1822 (key->types[i] != key->types[0]))
1827 if ((key->syms[i] != key->syms[0]) &&
1828 (key->syms[i] == NULL || key->syms[0] == NULL ||
1829 memcmp(key->syms[i], key->syms[0],
1830 sizeof(uint32_t) * key->numLevels[0])))
1835 if ((key->acts[i] != key->acts[0]) &&
1836 (key->acts[i] == NULL || key->acts[0] == NULL ||
1837 memcmp(key->acts[i], key->acts[0],
1838 sizeof(union xkb_action) * key->numLevels[0])))
1846 for (i = lastGroup; i > 0; i--)
1848 key->numLevels[i] = 0;
1850 key->syms[i] = NULL;
1852 key->acts[i] = NULL;
1855 key->symsDefined &= 1;
1856 key->actsDefined &= 1;
1857 key->typesDefined &= 1;
1862 * Copy the KeyInfo into the keyboard description.
1864 * This function recurses.
1867 CopySymbolsDef(struct xkb_desc * xkb, KeyInfo *key, int start_from)
1870 xkb_keycode_t okc, kc;
1871 unsigned width, tmp, nGroups;
1872 struct xkb_key_type * type;
1873 Bool haveActions, autoType, useAlias;
1875 union xkb_action *outActs;
1876 unsigned types[XkbNumKbdGroups];
1878 useAlias = (start_from == 0);
1880 /* get the keycode for the key. */
1881 if (!FindNamedKey(xkb, key->name, &kc, useAlias, CreateKeyNames(xkb),
1884 if ((start_from == 0) && (warningLevel >= 5))
1886 WARN("Key %s not found in %s keycodes\n",
1887 longText(key->name),
1888 XkbcAtomText(xkb->names->keycodes));
1889 ACTION("Symbols ignored\n");
1894 haveActions = False;
1895 for (i = width = nGroups = 0; i < XkbNumKbdGroups; i++)
1897 if (((i + 1) > nGroups)
1898 && (((key->symsDefined | key->actsDefined) & (1 << i))
1899 || (key->typesDefined) & (1 << i)))
1904 /* Assign the type to the key, if it is missing. */
1905 if (key->types[i] == None)
1907 if (key->dfltType != None)
1908 key->types[i] = key->dfltType;
1909 else if (FindAutomaticType(key->numLevels[i], key->syms[i],
1910 &key->types[i], &autoType))
1915 if (warningLevel >= 5)
1917 WARN("No automatic type for %d symbols\n",
1918 (unsigned int) key->numLevels[i]);
1919 ACTION("Using %s for the %s key (keycode %d)\n",
1920 XkbcAtomText(key->types[i]),
1921 longText(key->name), kc);
1925 if (FindNamedType(xkb, key->types[i], &types[i]))
1927 if (!autoType || key->numLevels[i] > 2)
1928 xkb->server->explicit[kc] |= (1 << i);
1932 if (warningLevel >= 3)
1934 WARN("Type \"%s\" is not defined\n",
1935 XkbcAtomText(key->types[i]));
1936 ACTION("Using TWO_LEVEL for the %s key (keycode %d)\n",
1937 longText(key->name), kc);
1939 types[i] = XkbTwoLevelIndex;
1941 /* if the type specifies less syms than the key has, shrink the key */
1942 type = &xkb->map->types[types[i]];
1943 if (type->num_levels < key->numLevels[i])
1945 if (warningLevel > 0)
1948 ("Type \"%s\" has %d levels, but %s has %d symbols\n",
1949 XkbcAtomText(type->name),
1950 (unsigned int) type->num_levels,
1951 longText(key->name),
1952 (unsigned int) key->numLevels[i]);
1953 ACTION("Ignoring extra symbols\n");
1955 key->numLevels[i] = type->num_levels;
1957 if (key->numLevels[i] > width)
1958 width = key->numLevels[i];
1959 if (type->num_levels > width)
1960 width = type->num_levels;
1963 /* width is now the largest width found */
1965 i = width * nGroups;
1966 outSyms = XkbcResizeKeySyms(xkb, kc, i);
1967 if (outSyms == NULL)
1969 WSGO("Could not enlarge symbols for %s (keycode %d)\n",
1970 longText(key->name), kc);
1975 outActs = XkbcResizeKeyActions(xkb, kc, i);
1976 if (outActs == NULL)
1978 WSGO("Could not enlarge actions for %s (key %d)\n",
1979 longText(key->name), kc);
1982 xkb->server->explicit[kc] |= XkbExplicitInterpretMask;
1986 if (key->defs.defined & _Key_GroupInfo)
1989 i = xkb->map->key_sym_map[kc].group_info;
1991 xkb->map->key_sym_map[kc].group_info = XkbSetNumGroups(i, nGroups);
1992 xkb->map->key_sym_map[kc].width = width;
1993 for (i = 0; i < nGroups; i++)
1995 /* assign kt_index[i] to the index of the type in map->types.
1996 * kt_index[i] may have been set by a previous run (if we have two
1997 * layouts specified). Let's not overwrite it with the ONE_LEVEL
1998 * default group if we dont even have keys for this group anyway.
2000 * FIXME: There should be a better fix for this.
2002 if (key->numLevels[i])
2003 xkb->map->key_sym_map[kc].kt_index[i] = types[i];
2004 if (key->syms[i] != NULL)
2006 /* fill key to "width" symbols*/
2007 for (tmp = 0; tmp < width; tmp++)
2009 if (tmp < key->numLevels[i])
2010 outSyms[tmp] = key->syms[i][tmp];
2012 outSyms[tmp] = NoSymbol;
2013 if ((outActs != NULL) && (key->acts[i] != NULL))
2015 if (tmp < key->numLevels[i])
2016 outActs[tmp] = key->acts[i][tmp];
2018 outActs[tmp].type = XkbSA_NoAction;
2026 switch (key->behavior.type & XkbKB_OpMask)
2030 case XkbKB_Overlay1:
2031 case XkbKB_Overlay2:
2032 /* find key by name! */
2033 if (!FindNamedKey(xkb, key->nameForOverlayKey, &okc, True,
2034 CreateKeyNames(xkb), 0))
2036 if (warningLevel >= 1)
2038 WARN("Key %s not found in %s keycodes\n",
2039 longText(key->nameForOverlayKey),
2040 XkbcAtomText(xkb->names->keycodes));
2041 ACTION("Not treating %s as an overlay key \n",
2042 longText(key->name));
2046 key->behavior.data = okc;
2048 xkb->server->behaviors[kc] = key->behavior;
2049 xkb->server->explicit[kc] |= XkbExplicitBehaviorMask;
2052 if (key->defs.defined & _Key_VModMap)
2054 xkb->server->vmodmap[kc] = key->vmodmap;
2055 xkb->server->explicit[kc] |= XkbExplicitVModMapMask;
2057 if (key->repeat != RepeatUndefined)
2059 if (key->repeat == RepeatYes)
2060 xkb->ctrls->per_key_repeat[kc / 8] |= (1 << (kc % 8));
2062 xkb->ctrls->per_key_repeat[kc / 8] &= ~(1 << (kc % 8));
2063 xkb->server->explicit[kc] |= XkbExplicitAutoRepeatMask;
2066 if (nGroups > xkb->ctrls->num_groups)
2067 xkb->ctrls->num_groups = nGroups;
2069 /* do the same thing for the next key */
2070 CopySymbolsDef(xkb, key, kc + 1);
2075 CopyModMapDef(struct xkb_desc * xkb, ModMapEntry *entry)
2079 if ((!entry->haveSymbol)
2082 (xkb, entry->u.keyName, &kc, True, CreateKeyNames(xkb), 0)))
2084 if (warningLevel >= 5)
2086 WARN("Key %s not found in %s keycodes\n",
2087 longText(entry->u.keyName),
2088 XkbcAtomText(xkb->names->keycodes));
2089 ACTION("Modifier map entry for %s not updated\n",
2090 XkbcModIndexText(entry->modifier));
2094 else if (entry->haveSymbol
2095 && (!FindKeyForSymbol(xkb, entry->u.keySym, &kc)))
2097 if (warningLevel > 5)
2099 WARN("Key \"%s\" not found in %s symbol map\n",
2100 XkbcKeysymText(entry->u.keySym),
2101 XkbcAtomText(xkb->names->symbols));
2102 ACTION("Modifier map entry for %s not updated\n",
2103 XkbcModIndexText(entry->modifier));
2107 xkb->map->modmap[kc] |= (1 << entry->modifier);
2112 * Handle the xkb_symbols section of an xkb file.
2114 * @param file The parsed xkb_symbols section of the xkb file.
2115 * @param xkb Handle to the keyboard description to store the symbols in.
2116 * @param merge Merge strategy (e.g. MergeOverride).
2119 CompileSymbols(XkbFile *file, struct xkb_desc * xkb, unsigned merge)
2124 InitSymbolsInfo(&info, xkb);
2125 info.dflt.defs.fileID = file->id;
2126 info.dflt.defs.merge = merge;
2127 HandleSymbolsFile(file, xkb, merge, &info);
2129 if (info.nKeys == 0) {
2130 FreeSymbolsInfo(&info);
2134 if (info.errorCount == 0)
2138 /* alloc memory in the xkb struct */
2139 if (XkbcAllocNames(xkb, XkbSymbolsNameMask | XkbGroupNamesMask, 0, 0)
2142 WSGO("Can not allocate names in CompileSymbols\n");
2143 ACTION("Symbols not added\n");
2146 if (XkbcAllocClientMap(xkb, XkbKeySymsMask | XkbModifierMapMask, 0)
2149 WSGO("Could not allocate client map in CompileSymbols\n");
2150 ACTION("Symbols not added\n");
2153 if (XkbcAllocServerMap(xkb, XkbAllServerInfoMask, 32) != Success)
2155 WSGO("Could not allocate server map in CompileSymbols\n");
2156 ACTION("Symbols not added\n");
2159 if (XkbcAllocControls(xkb, XkbPerKeyRepeatMask) != Success)
2161 WSGO("Could not allocate controls in CompileSymbols\n");
2162 ACTION("Symbols not added\n");
2166 /* now copy info into xkb. */
2167 xkb->names->symbols = xkb_intern_atom(info.name);
2169 ApplyAliases(xkb, False, &info.aliases);
2170 for (i = 0; i < XkbNumKbdGroups; i++)
2172 if (info.groupNames[i] != None)
2173 xkb->names->groups[i] = info.groupNames[i];
2176 for (key = info.keys, i = 0; i < info.nKeys; i++, key++)
2181 for (key = info.keys, i = 0; i < info.nKeys; i++, key++)
2183 if (!CopySymbolsDef(xkb, key, 0))
2186 if (warningLevel > 3)
2188 for (i = xkb->min_key_code; i <= xkb->max_key_code; i++)
2190 if (xkb->names->keys[i].name[0] == '\0')
2192 if (XkbKeyNumGroups(xkb, i) < 1)
2195 memcpy(buf, xkb->names->keys[i].name, 4);
2198 ("No symbols defined for <%s> (keycode %d)\n",
2205 ModMapEntry *mm, *next;
2206 for (mm = info.modMap; mm != NULL; mm = next)
2208 if (!CopyModMapDef(xkb, mm))
2210 next = (ModMapEntry *) mm->defs.next;
2213 FreeSymbolsInfo(&info);
2217 FreeSymbolsInfo(&info);