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 extern uint32_t tok_ONE_LEVEL;
44 extern uint32_t tok_TWO_LEVEL;
45 extern uint32_t tok_KEYPAD;
47 /***====================================================================***/
51 #define RepeatUndefined ~((unsigned)0)
53 #define _Key_Syms (1<<0)
54 #define _Key_Acts (1<<1)
55 #define _Key_Repeat (1<<2)
56 #define _Key_Behavior (1<<3)
57 #define _Key_Type_Dflt (1<<4)
58 #define _Key_Types (1<<5)
59 #define _Key_GroupInfo (1<<6)
60 #define _Key_VModMap (1<<7)
62 typedef struct _KeyInfo
65 unsigned long name; /* the 4 chars of the key name, as long */
66 unsigned char groupInfo;
67 unsigned char typesDefined;
68 unsigned char symsDefined;
69 unsigned char actsDefined;
70 short numLevels[XkbNumKbdGroups];
71 uint32_t *syms[XkbNumKbdGroups];
72 union xkb_action *acts[XkbNumKbdGroups];
73 uint32_t types[XkbNumKbdGroups];
75 struct xkb_behavior behavior;
76 unsigned short vmodmap;
77 unsigned long nameForOverlayKey;
78 unsigned long allowNone;
83 * Init the given key info to sane values.
86 InitKeyInfo(KeyInfo * info)
89 static char dflt[4] = "*";
91 info->defs.defined = 0;
92 info->defs.fileID = 0;
93 info->defs.merge = MergeOverride;
94 info->defs.next = NULL;
95 info->name = KeyNameToLong(dflt);
97 info->typesDefined = info->symsDefined = info->actsDefined = 0;
98 for (i = 0; i < XkbNumKbdGroups; i++)
100 info->numLevels[i] = 0;
101 info->types[i] = None;
102 info->syms[i] = NULL;
103 info->acts[i] = NULL;
105 info->dfltType = None;
106 info->behavior.type = XkbKB_Default;
107 info->behavior.data = 0;
109 info->nameForOverlayKey = 0;
110 info->repeat = RepeatUndefined;
116 * Free memory associated with this key info and reset to sane values.
119 FreeKeyInfo(KeyInfo * info)
123 info->defs.defined = 0;
124 info->defs.fileID = 0;
125 info->defs.merge = MergeOverride;
126 info->defs.next = NULL;
128 info->typesDefined = info->symsDefined = info->actsDefined = 0;
129 for (i = 0; i < XkbNumKbdGroups; i++)
131 info->numLevels[i] = 0;
132 info->types[i] = None;
134 info->syms[i] = NULL;
136 info->acts[i] = NULL;
138 info->dfltType = None;
139 info->behavior.type = XkbKB_Default;
140 info->behavior.data = 0;
142 info->nameForOverlayKey = 0;
143 info->repeat = RepeatUndefined;
149 * Copy old into new, optionally reset old to 0.
150 * If old is reset, new simply re-uses old's memory. Otherwise, the memory is
151 * newly allocated and new points to the new memory areas.
154 CopyKeyInfo(KeyInfo * old, KeyInfo * new, Bool clearOld)
159 new->defs.next = NULL;
162 for (i = 0; i < XkbNumKbdGroups; i++)
164 old->numLevels[i] = 0;
172 for (i = 0; i < XkbNumKbdGroups; i++)
174 width = new->numLevels[i];
175 if (old->syms[i] != NULL)
177 new->syms[i] = uTypedCalloc(width, uint32_t);
181 new->numLevels[i] = 0;
184 memcpy((char *) new->syms[i], (char *) old->syms[i],
185 width * sizeof(uint32_t));
187 if (old->acts[i] != NULL)
189 new->acts[i] = uTypedCalloc(width, union xkb_action);
195 memcpy((char *) new->acts[i], (char *) old->acts[i],
196 width * sizeof(union xkb_action));
203 /***====================================================================***/
205 typedef struct _ModMapEntry
212 unsigned long keyName;
217 #define SYMBOLS_INIT_SIZE 110
218 #define SYMBOLS_CHUNK 20
219 typedef struct _SymbolsInfo
221 char *name; /* e.g. pc+us+inet(evdev) */
225 unsigned explicit_group;
233 uint32_t groupNames[XkbNumKbdGroups];
240 InitSymbolsInfo(SymbolsInfo * info, struct xkb_desc * xkb)
244 tok_ONE_LEVEL = xkb_intern_atom("ONE_LEVEL");
245 tok_TWO_LEVEL = xkb_intern_atom("TWO_LEVEL");
246 tok_KEYPAD = xkb_intern_atom("KEYPAD");
248 info->explicit_group = 0;
249 info->errorCount = 0;
251 info->merge = MergeOverride;
253 info->szKeys = SYMBOLS_INIT_SIZE;
255 info->keys = uTypedCalloc(SYMBOLS_INIT_SIZE, KeyInfo);
257 for (i = 0; i < XkbNumKbdGroups; i++)
258 info->groupNames[i] = None;
259 InitKeyInfo(&info->dflt);
260 InitVModInfo(&info->vmods, xkb);
262 info->aliases = NULL;
267 FreeSymbolsInfo(SymbolsInfo * info)
274 for (i = 0; i < info->nKeys; i++)
275 FreeKeyInfo(&info->keys[i]);
279 ClearCommonInfo(&info->modMap->defs);
281 ClearAliases(&info->aliases);
282 bzero((char *) info, sizeof(SymbolsInfo));
287 ResizeKeyGroup(KeyInfo * key,
288 unsigned group, unsigned atLeastSize, Bool forceActions)
293 tooSmall = (key->numLevels[group] < atLeastSize);
295 newWidth = atLeastSize;
297 newWidth = key->numLevels[group];
299 if ((key->syms[group] == NULL) || tooSmall)
301 key->syms[group] = uTypedRecalloc(key->syms[group],
302 key->numLevels[group], newWidth,
304 if (!key->syms[group])
307 if (((forceActions) && (tooSmall || (key->acts[group] == NULL))) ||
308 (tooSmall && (key->acts[group] != NULL)))
310 key->acts[group] = uTypedRecalloc(key->acts[group],
311 key->numLevels[group], newWidth,
313 if (!key->acts[group])
316 key->numLevels[group] = newWidth;
321 MergeKeyGroups(SymbolsInfo * info,
322 KeyInfo * into, KeyInfo * from, unsigned group)
324 uint32_t *resultSyms;
325 union xkb_action *resultActs;
328 Bool report, clobber;
330 clobber = (from->defs.merge != MergeAugment);
331 report = (warningLevel > 9) ||
332 ((into->defs.fileID == from->defs.fileID) && (warningLevel > 0));
333 if (into->numLevels[group] >= from->numLevels[group])
335 resultSyms = into->syms[group];
336 resultActs = into->acts[group];
337 resultWidth = into->numLevels[group];
341 resultSyms = from->syms[group];
342 resultActs = from->acts[group];
343 resultWidth = from->numLevels[group];
345 if (resultSyms == NULL)
347 resultSyms = uTypedCalloc(resultWidth, uint32_t);
350 WSGO("Could not allocate symbols for group merge\n");
351 ACTION("Group %d of key %s not merged\n", group,
352 longText(into->name));
356 if ((resultActs == NULL) && (into->acts[group] || from->acts[group]))
358 resultActs = uTypedCalloc(resultWidth, union xkb_action);
361 WSGO("Could not allocate actions for group merge\n");
362 ACTION("Group %d of key %s not merged\n", group,
363 longText(into->name));
367 for (i = 0; i < resultWidth; i++)
369 uint32_t fromSym, toSym;
370 if (from->syms[group] && (i < from->numLevels[group]))
371 fromSym = from->syms[group][i];
374 if (into->syms[group] && (i < into->numLevels[group]))
375 toSym = into->syms[group][i];
378 if ((fromSym == NoSymbol) || (fromSym == toSym))
379 resultSyms[i] = toSym;
380 else if (toSym == NoSymbol)
381 resultSyms[i] = fromSym;
384 uint32_t use, ignore;
398 ("Multiple symbols for level %d/group %d on key %s\n",
399 i + 1, group + 1, longText(into->name));
400 ACTION("Using %s, ignoring %s\n",
401 XkbcKeysymText(use), XkbcKeysymText(ignore));
405 if (resultActs != NULL)
407 union xkb_action *fromAct, *toAct;
408 fromAct = (from->acts[group] ? &from->acts[group][i] : NULL);
409 toAct = (into->acts[group] ? &into->acts[group][i] : NULL);
410 if (((fromAct == NULL) || (fromAct->type == XkbSA_NoAction))
413 resultActs[i] = *toAct;
415 else if (((toAct == NULL) || (toAct->type == XkbSA_NoAction))
416 && (fromAct != NULL))
418 resultActs[i] = *fromAct;
422 union xkb_action *use, *ignore;
436 ("Multiple actions for level %d/group %d on key %s\n",
437 i + 1, group + 1, longText(into->name));
438 ACTION("Using %s, ignoring %s\n",
439 XkbcActionTypeText(use->type),
440 XkbcActionTypeText(ignore->type));
443 resultActs[i] = *use;
447 if (resultSyms != into->syms[group])
448 free(into->syms[group]);
449 if (resultSyms != from->syms[group])
450 free(from->syms[group]);
451 if (resultActs != into->acts[group])
452 free(into->acts[group]);
453 if (resultActs != from->acts[group])
454 free(from->acts[group]);
455 into->numLevels[group] = resultWidth;
456 into->syms[group] = resultSyms;
457 from->syms[group] = NULL;
458 into->acts[group] = resultActs;
459 from->acts[group] = NULL;
460 into->symsDefined |= (1 << group);
461 from->symsDefined &= ~(1 << group);
462 into->actsDefined |= (1 << group);
463 from->actsDefined &= ~(1 << group);
468 MergeKeys(SymbolsInfo * info, KeyInfo * into, KeyInfo * from)
471 unsigned collide = 0;
474 if (from->defs.merge == MergeReplace)
476 for (i = 0; i < XkbNumKbdGroups; i++)
478 if (into->numLevels[i] != 0)
485 bzero(from, sizeof(KeyInfo));
488 report = ((warningLevel > 9) ||
489 ((into->defs.fileID == from->defs.fileID)
490 && (warningLevel > 0)));
491 for (i = 0; i < XkbNumKbdGroups; i++)
493 if (from->numLevels[i] > 0)
495 if (into->numLevels[i] == 0)
497 into->numLevels[i] = from->numLevels[i];
498 into->syms[i] = from->syms[i];
499 into->acts[i] = from->acts[i];
500 into->symsDefined |= (1 << i);
501 from->syms[i] = NULL;
502 from->acts[i] = NULL;
503 from->numLevels[i] = 0;
504 from->symsDefined &= ~(1 << i);
506 into->defs.defined |= _Key_Syms;
508 into->defs.defined |= _Key_Acts;
515 collide |= _Key_Syms;
517 collide |= _Key_Acts;
519 MergeKeyGroups(info, into, from, (unsigned) i);
522 if (from->types[i] != None)
524 if ((into->types[i] != None) && (report) &&
525 (into->types[i] != from->types[i]))
527 uint32_t use, ignore;
528 collide |= _Key_Types;
529 if (from->defs.merge != MergeAugment)
531 use = from->types[i];
532 ignore = into->types[i];
536 use = into->types[i];
537 ignore = from->types[i];
540 ("Multiple definitions for group %d type of key %s\n",
541 i, longText(into->name));
542 ACTION("Using %s, ignoring %s\n",
544 XkbcAtomText(ignore));
546 if ((from->defs.merge != MergeAugment)
547 || (into->types[i] == None))
549 into->types[i] = from->types[i];
553 if (UseNewField(_Key_Behavior, &into->defs, &from->defs, &collide))
555 into->behavior = from->behavior;
556 into->nameForOverlayKey = from->nameForOverlayKey;
557 into->defs.defined |= _Key_Behavior;
559 if (UseNewField(_Key_VModMap, &into->defs, &from->defs, &collide))
561 into->vmodmap = from->vmodmap;
562 into->defs.defined |= _Key_VModMap;
564 if (UseNewField(_Key_Repeat, &into->defs, &from->defs, &collide))
566 into->repeat = from->repeat;
567 into->defs.defined |= _Key_Repeat;
569 if (UseNewField(_Key_Type_Dflt, &into->defs, &from->defs, &collide))
571 into->dfltType = from->dfltType;
572 into->defs.defined |= _Key_Type_Dflt;
574 if (UseNewField(_Key_GroupInfo, &into->defs, &from->defs, &collide))
576 into->groupInfo = from->groupInfo;
577 into->defs.defined |= _Key_GroupInfo;
581 WARN("Symbol map for key %s redefined\n",
582 longText(into->name));
583 ACTION("Using %s definition for conflicting fields\n",
584 (from->defs.merge == MergeAugment ? "first" : "last"));
590 AddKeySymbols(SymbolsInfo * info, KeyInfo * key, struct xkb_desc * xkb)
593 unsigned long real_name;
595 for (i = 0; i < info->nKeys; i++)
597 if (info->keys[i].name == key->name)
598 return MergeKeys(info, &info->keys[i], key);
600 if (FindKeyNameForAlias(xkb, key->name, &real_name))
602 for (i = 0; i < info->nKeys; i++)
604 if (info->keys[i].name == real_name)
605 return MergeKeys(info, &info->keys[i], key);
608 if (info->nKeys >= info->szKeys)
610 info->szKeys += SYMBOLS_CHUNK;
612 uTypedRecalloc(info->keys, info->nKeys, info->szKeys, KeyInfo);
615 WSGO("Could not allocate key symbols descriptions\n");
616 ACTION("Some key symbols definitions may be lost\n");
620 return CopyKeyInfo(key, &info->keys[info->nKeys++], True);
624 AddModMapEntry(SymbolsInfo * info, ModMapEntry * new)
629 clobber = (new->defs.merge != MergeAugment);
630 for (mm = info->modMap; mm != NULL; mm = (ModMapEntry *) mm->defs.next)
632 if (new->haveSymbol && mm->haveSymbol
633 && (new->u.keySym == mm->u.keySym))
635 unsigned use, ignore;
636 if (mm->modifier != new->modifier)
641 ignore = mm->modifier;
646 ignore = new->modifier;
649 ("%s added to symbol map for multiple modifiers\n",
650 XkbcKeysymText(new->u.keySym));
651 ACTION("Using %s, ignoring %s.\n",
652 XkbcModIndexText(use),
653 XkbcModIndexText(ignore));
658 if ((!new->haveSymbol) && (!mm->haveSymbol) &&
659 (new->u.keyName == mm->u.keyName))
661 unsigned use, ignore;
662 if (mm->modifier != new->modifier)
667 ignore = mm->modifier;
672 ignore = new->modifier;
674 ERROR("Key %s added to map for multiple modifiers\n",
675 longText(new->u.keyName));
676 ACTION("Using %s, ignoring %s.\n",
677 XkbcModIndexText(use),
678 XkbcModIndexText(ignore));
684 mm = uTypedAlloc(ModMapEntry);
687 WSGO("Could not allocate modifier map entry\n");
688 ACTION("Modifier map for %s will be incomplete\n",
689 XkbcModIndexText(new->modifier));
693 mm->defs.next = &info->modMap->defs;
698 /***====================================================================***/
701 MergeIncludedSymbols(SymbolsInfo * into, SymbolsInfo * from,
702 unsigned merge, struct xkb_desc * xkb)
707 if (from->errorCount > 0)
709 into->errorCount += from->errorCount;
712 if (into->name == NULL)
714 into->name = from->name;
717 for (i = 0; i < XkbNumKbdGroups; i++)
719 if (from->groupNames[i] != None)
721 if ((merge != MergeAugment) || (into->groupNames[i] == None))
722 into->groupNames[i] = from->groupNames[i];
725 for (i = 0, key = from->keys; i < from->nKeys; i++, key++)
727 if (merge != MergeDefault)
728 key->defs.merge = merge;
729 if (!AddKeySymbols(into, key, xkb))
732 if (from->modMap != NULL)
734 ModMapEntry *mm, *next;
735 for (mm = from->modMap; mm != NULL; mm = next)
737 if (merge != MergeDefault)
738 mm->defs.merge = merge;
739 if (!AddModMapEntry(into, mm))
741 next = (ModMapEntry *) mm->defs.next;
746 if (!MergeAliases(&into->aliases, &from->aliases, merge))
751 typedef void (*FileHandler) (XkbFile * /* rtrn */ ,
752 struct xkb_desc * /* xkb */ ,
753 unsigned /* merge */ ,
754 SymbolsInfo * /* included */
758 HandleIncludeSymbols(IncludeStmt * stmt,
759 struct xkb_desc * xkb, SymbolsInfo * info, FileHandler hndlr)
763 SymbolsInfo included;
767 if ((stmt->file == NULL) && (stmt->map == NULL))
771 bzero(info, sizeof(SymbolsInfo));
773 else if (ProcessIncludeFile(stmt, XkmSymbolsIndex, &rtrn, &newMerge))
775 InitSymbolsInfo(&included, xkb);
776 included.fileID = included.dflt.defs.fileID = rtrn->id;
777 included.merge = included.dflt.defs.merge = MergeOverride;
780 included.explicit_group = atoi(stmt->modifier) - 1;
784 included.explicit_group = info->explicit_group;
786 (*hndlr) (rtrn, xkb, MergeOverride, &included);
787 if (stmt->stmt != NULL)
790 included.name = stmt->stmt;
796 info->errorCount += 10;
799 if ((stmt->next != NULL) && (included.errorCount < 1))
803 SymbolsInfo next_incl;
805 for (next = stmt->next; next != NULL; next = next->next)
807 if ((next->file == NULL) && (next->map == NULL))
810 MergeIncludedSymbols(&included, info, next->merge, xkb);
811 FreeSymbolsInfo(info);
813 else if (ProcessIncludeFile(next, XkmSymbolsIndex, &rtrn, &op))
815 InitSymbolsInfo(&next_incl, xkb);
816 next_incl.fileID = next_incl.dflt.defs.fileID = rtrn->id;
817 next_incl.merge = next_incl.dflt.defs.merge = MergeOverride;
820 next_incl.explicit_group = atoi(next->modifier) - 1;
824 next_incl.explicit_group = info->explicit_group;
826 (*hndlr) (rtrn, xkb, MergeOverride, &next_incl);
827 MergeIncludedSymbols(&included, &next_incl, op, xkb);
828 FreeSymbolsInfo(&next_incl);
832 info->errorCount += 10;
841 MergeIncludedSymbols(info, &included, newMerge, xkb);
842 FreeSymbolsInfo(&included);
844 return (info->errorCount == 0);
851 GetGroupIndex(KeyInfo * key,
852 ExprDef * arrayNdx, unsigned what, unsigned *ndx_rtrn)
862 if (arrayNdx == NULL)
867 defined = key->symsDefined;
869 defined = key->actsDefined;
871 for (i = 0; i < XkbNumKbdGroups; i++)
873 if ((defined & (1 << i)) == 0)
879 ERROR("Too many groups of %s for key %s (max %d)\n", name,
880 longText(key->name), XkbNumKbdGroups + 1);
881 ACTION("Ignoring %s defined for extra groups\n", name);
884 if (!ExprResolveGroup(arrayNdx, &tmp))
886 ERROR("Illegal group index for %s of key %s\n", name,
887 longText(key->name));
888 ACTION("Definition with non-integer array index ignored\n");
891 *ndx_rtrn = tmp.uval - 1;
896 AddSymbolsToKey(KeyInfo * key,
897 struct xkb_desc * xkb,
899 ExprDef * arrayNdx, ExprDef * value, SymbolsInfo * info)
904 if (!GetGroupIndex(key, arrayNdx, SYMBOLS, &ndx))
908 key->symsDefined |= (1 << ndx);
911 if (value->op != ExprKeysymList)
913 ERROR("Expected a list of symbols, found %s\n",
914 exprOpText(value->op));
915 ACTION("Ignoring symbols for group %d of %s\n", ndx,
916 longText(key->name));
919 if (key->syms[ndx] != NULL)
921 WSGO("Symbols for key %s, group %d already defined\n",
922 longText(key->name), ndx);
925 nSyms = value->value.list.nSyms;
926 if (((key->numLevels[ndx] < nSyms) || (key->syms[ndx] == NULL)) &&
927 (!ResizeKeyGroup(key, ndx, nSyms, False)))
929 WSGO("Could not resize group %d of key %s\n", ndx,
930 longText(key->name));
931 ACTION("Symbols lost\n");
934 key->symsDefined |= (1 << ndx);
935 for (i = 0; i < nSyms; i++) {
936 if (!LookupKeysym(value->value.list.syms[i], &key->syms[ndx][i])) {
937 WSGO("Could not resolve keysym %s\n", value->value.list.syms[i]);
938 key->syms[ndx][i] = NoSymbol;
941 for (i = key->numLevels[ndx] - 1;
942 (i >= 0) && (key->syms[ndx][i] == NoSymbol); i--)
944 key->numLevels[ndx]--;
950 AddActionsToKey(KeyInfo * key,
951 struct xkb_desc * xkb,
953 ExprDef * arrayNdx, ExprDef * value, SymbolsInfo * info)
958 struct xkb_any_action *toAct;
960 if (!GetGroupIndex(key, arrayNdx, ACTIONS, &ndx))
965 key->actsDefined |= (1 << ndx);
968 if (value->op != ExprActionList)
970 WSGO("Bad expression type (%d) for action list value\n", value->op);
971 ACTION("Ignoring actions for group %d of %s\n", ndx,
972 longText(key->name));
975 if (key->acts[ndx] != NULL)
977 WSGO("Actions for key %s, group %d already defined\n",
978 longText(key->name), ndx);
981 for (nActs = 0, act = value->value.child; act != NULL; nActs++)
983 act = (ExprDef *) act->common.next;
987 WSGO("Action list but not actions in AddActionsToKey\n");
990 if (((key->numLevels[ndx] < nActs) || (key->acts[ndx] == NULL)) &&
991 (!ResizeKeyGroup(key, ndx, nActs, True)))
993 WSGO("Could not resize group %d of key %s\n", ndx,
994 longText(key->name));
995 ACTION("Actions lost\n");
998 key->actsDefined |= (1 << ndx);
1000 toAct = (struct xkb_any_action *) key->acts[ndx];
1001 act = value->value.child;
1002 for (i = 0; i < nActs; i++, toAct++)
1004 if (!HandleActionDef(act, xkb, toAct, MergeOverride, info->action))
1006 ERROR("Illegal action definition for %s\n",
1007 longText(key->name));
1008 ACTION("Action for group %d/level %d ignored\n", ndx + 1, i + 1);
1010 act = (ExprDef *) act->common.next;
1016 SetAllowNone(KeyInfo * key, ExprDef * arrayNdx, ExprDef * value)
1019 unsigned radio_groups = 0;
1021 if (arrayNdx == NULL)
1023 radio_groups = XkbAllRadioGroupsMask;
1027 if (!ExprResolveRadioGroup(arrayNdx, &tmp))
1029 ERROR("Illegal index in group name definition\n");
1030 ACTION("Definition with non-integer array index ignored\n");
1033 if ((tmp.uval < 1) || (tmp.uval > XkbMaxRadioGroups))
1035 ERROR("Illegal radio group specified (must be 1..%d)\n",
1036 XkbMaxRadioGroups + 1);
1037 ACTION("Value of \"allow none\" for group %d ignored\n",
1041 radio_groups |= (1 << (tmp.uval - 1));
1043 if (!ExprResolveBoolean(value, &tmp))
1045 ERROR("Illegal \"allow none\" value for %s\n",
1046 longText(key->name));
1047 ACTION("Non-boolean value ignored\n");
1051 key->allowNone |= radio_groups;
1053 key->allowNone &= ~radio_groups;
1058 static LookupEntry lockingEntries[] = {
1059 {"true", XkbKB_Lock},
1060 {"yes", XkbKB_Lock},
1062 {"false", XkbKB_Default},
1063 {"no", XkbKB_Default},
1064 {"off", XkbKB_Default},
1065 {"permanent", XkbKB_Lock | XkbKB_Permanent},
1069 static LookupEntry repeatEntries[] = {
1070 {"true", RepeatYes},
1073 {"false", RepeatNo},
1076 {"default", RepeatUndefined},
1081 SetSymbolsField(KeyInfo * key,
1082 struct xkb_desc * xkb,
1084 ExprDef * arrayNdx, ExprDef * value, SymbolsInfo * info)
1089 if (uStrCaseCmp(field, "type") == 0)
1092 if ((!ExprResolveString(value, &tmp))
1093 && (warningLevel > 0))
1095 WARN("The type field of a key symbol map must be a string\n");
1096 ACTION("Ignoring illegal type definition\n");
1098 if (arrayNdx == NULL)
1100 key->dfltType = xkb_intern_atom(tmp.str);
1101 key->defs.defined |= _Key_Type_Dflt;
1103 else if (!ExprResolveGroup(arrayNdx, &ndx))
1105 ERROR("Illegal group index for type of key %s\n",
1106 longText(key->name));
1107 ACTION("Definition with non-integer array index ignored\n");
1113 key->types[ndx.uval - 1] = xkb_intern_atom(tmp.str);
1114 key->typesDefined |= (1 << (ndx.uval - 1));
1118 else if (uStrCaseCmp(field, "symbols") == 0)
1119 return AddSymbolsToKey(key, xkb, field, arrayNdx, value, info);
1120 else if (uStrCaseCmp(field, "actions") == 0)
1121 return AddActionsToKey(key, xkb, field, arrayNdx, value, info);
1122 else if ((uStrCaseCmp(field, "vmods") == 0) ||
1123 (uStrCaseCmp(field, "virtualmods") == 0) ||
1124 (uStrCaseCmp(field, "virtualmodifiers") == 0))
1126 ok = ExprResolveVModMask(value, &tmp, xkb);
1129 key->vmodmap = (tmp.uval >> 8);
1130 key->defs.defined |= _Key_VModMap;
1134 ERROR("Expected a virtual modifier mask, found %s\n",
1135 exprOpText(value->op));
1136 ACTION("Ignoring virtual modifiers definition for key %s\n",
1137 longText(key->name));
1140 else if ((uStrCaseCmp(field, "locking") == 0)
1141 || (uStrCaseCmp(field, "lock") == 0)
1142 || (uStrCaseCmp(field, "locks") == 0))
1144 ok = ExprResolveEnum(value, &tmp, lockingEntries);
1146 key->behavior.type = tmp.uval;
1147 key->defs.defined |= _Key_Behavior;
1149 else if ((uStrCaseCmp(field, "radiogroup") == 0) ||
1150 (uStrCaseCmp(field, "permanentradiogroup") == 0))
1152 Bool permanent = False;
1153 if (uStrCaseCmp(field, "permanentradiogroup") == 0)
1155 if (ExprResolveString(value, &tmp)) {
1156 ok = (strcmp(tmp.str, "none") == 0);
1162 ok = ExprResolveInteger(value, &tmp);
1166 ERROR("Illegal radio group specification for %s\n",
1167 longText(key->name));
1168 ACTION("Non-integer radio group ignored\n");
1173 key->behavior.type = XkbKB_Default;
1174 key->behavior.data = 0;
1177 if ((tmp.uval < 1) || (tmp.uval > XkbMaxRadioGroups))
1180 ("Radio group specification for %s out of range (1..32)\n",
1181 longText(key->name));
1182 ACTION("Illegal radio group %d ignored\n", tmp.uval);
1185 key->behavior.type =
1186 XkbKB_RadioGroup | (permanent ? XkbKB_Permanent : 0);
1187 key->behavior.data = tmp.uval - 1;
1188 if (key->allowNone & (1 << (tmp.uval - 1)))
1189 key->behavior.data |= XkbKB_RGAllowNone;
1190 key->defs.defined |= _Key_Behavior;
1192 else if (uStrCaseEqual(field, "allownone"))
1194 ok = SetAllowNone(key, arrayNdx, value);
1196 else if (uStrCasePrefix("overlay", field) ||
1197 uStrCasePrefix("permanentoverlay", field))
1199 Bool permanent = False;
1202 if (uStrCasePrefix("permanent", field))
1205 which = &field[sizeof("permanentoverlay") - 1];
1209 which = &field[sizeof("overlay") - 1];
1211 if (sscanf(which, "%d", &overlayNdx) == 1)
1213 if (((overlayNdx < 1) || (overlayNdx > 2)) && (warningLevel > 0))
1215 ERROR("Illegal overlay %d specified for %s\n",
1216 overlayNdx, longText(key->name));
1217 ACTION("Ignored\n");
1221 else if (*which == '\0')
1223 else if (warningLevel > 0)
1225 ERROR("Illegal overlay \"%s\" specified for %s\n",
1226 which, longText(key->name));
1227 ACTION("Ignored\n");
1230 ok = ExprResolveKeyName(value, &tmp);
1233 ERROR("Illegal overlay key specification for %s\n",
1234 longText(key->name));
1235 ACTION("Overlay key must be specified by name\n");
1238 if (overlayNdx == 1)
1239 key->behavior.type = XkbKB_Overlay1;
1241 key->behavior.type = XkbKB_Overlay2;
1243 key->behavior.type |= XkbKB_Permanent;
1245 key->behavior.data = 0;
1246 key->nameForOverlayKey = KeyNameToLong(tmp.keyName.name);
1247 key->defs.defined |= _Key_Behavior;
1249 else if ((uStrCaseCmp(field, "repeating") == 0) ||
1250 (uStrCaseCmp(field, "repeats") == 0) ||
1251 (uStrCaseCmp(field, "repeat") == 0))
1253 ok = ExprResolveEnum(value, &tmp, repeatEntries);
1256 ERROR("Illegal repeat setting for %s\n",
1257 longText(key->name));
1258 ACTION("Non-boolean repeat setting ignored\n");
1261 key->repeat = tmp.uval;
1262 key->defs.defined |= _Key_Repeat;
1264 else if ((uStrCaseCmp(field, "groupswrap") == 0) ||
1265 (uStrCaseCmp(field, "wrapgroups") == 0))
1267 ok = ExprResolveBoolean(value, &tmp);
1270 ERROR("Illegal groupsWrap setting for %s\n",
1271 longText(key->name));
1272 ACTION("Non-boolean value ignored\n");
1276 key->groupInfo = XkbWrapIntoRange;
1278 key->groupInfo = XkbClampIntoRange;
1279 key->defs.defined |= _Key_GroupInfo;
1281 else if ((uStrCaseCmp(field, "groupsclamp") == 0) ||
1282 (uStrCaseCmp(field, "clampgroups") == 0))
1284 ok = ExprResolveBoolean(value, &tmp);
1287 ERROR("Illegal groupsClamp setting for %s\n",
1288 longText(key->name));
1289 ACTION("Non-boolean value ignored\n");
1293 key->groupInfo = XkbClampIntoRange;
1295 key->groupInfo = XkbWrapIntoRange;
1296 key->defs.defined |= _Key_GroupInfo;
1298 else if ((uStrCaseCmp(field, "groupsredirect") == 0) ||
1299 (uStrCaseCmp(field, "redirectgroups") == 0))
1301 if (!ExprResolveGroup(value, &tmp))
1303 ERROR("Illegal group index for redirect of key %s\n",
1304 longText(key->name));
1305 ACTION("Definition with non-integer group ignored\n");
1309 XkbSetGroupInfo(0, XkbRedirectIntoRange, tmp.uval - 1);
1310 key->defs.defined |= _Key_GroupInfo;
1314 ERROR("Unknown field %s in a symbol interpretation\n", field);
1315 ACTION("Definition ignored\n");
1322 SetGroupName(SymbolsInfo * info, ExprDef * arrayNdx, ExprDef * value)
1324 ExprResult tmp, name;
1326 if ((arrayNdx == NULL) && (warningLevel > 0))
1328 WARN("You must specify an index when specifying a group name\n");
1329 ACTION("Group name definition without array subscript ignored\n");
1332 if (!ExprResolveGroup(arrayNdx, &tmp))
1334 ERROR("Illegal index in group name definition\n");
1335 ACTION("Definition with non-integer array index ignored\n");
1338 if (!ExprResolveString(value, &name))
1340 ERROR("Group name must be a string\n");
1341 ACTION("Illegal name for group %d ignored\n", tmp.uval);
1344 info->groupNames[tmp.uval - 1 + info->explicit_group] =
1345 xkb_intern_atom(name.str);
1352 HandleSymbolsVar(VarDef * stmt, struct xkb_desc * xkb, SymbolsInfo * info)
1354 ExprResult elem, field, tmp;
1358 if (ExprResolveLhs(stmt->name, &elem, &field, &arrayNdx) == 0)
1359 return 0; /* internal error, already reported */
1360 if (elem.str && (uStrCaseCmp(elem.str, "key") == 0))
1362 ret = SetSymbolsField(&info->dflt, xkb, field.str, arrayNdx,
1365 else if ((elem.str == NULL) && ((uStrCaseCmp(field.str, "name") == 0) ||
1366 (uStrCaseCmp(field.str, "groupname") ==
1369 ret = SetGroupName(info, arrayNdx, stmt->value);
1371 else if ((elem.str == NULL)
1372 && ((uStrCaseCmp(field.str, "groupswrap") == 0)
1373 || (uStrCaseCmp(field.str, "wrapgroups") == 0)))
1375 if (!ExprResolveBoolean(stmt->value, &tmp))
1377 ERROR("Illegal setting for global groupsWrap\n");
1378 ACTION("Non-boolean value ignored\n");
1383 info->groupInfo = XkbWrapIntoRange;
1385 info->groupInfo = XkbClampIntoRange;
1389 else if ((elem.str == NULL)
1390 && ((uStrCaseCmp(field.str, "groupsclamp") == 0)
1391 || (uStrCaseCmp(field.str, "clampgroups") == 0)))
1393 if (!ExprResolveBoolean(stmt->value, &tmp))
1395 ERROR("Illegal setting for global groupsClamp\n");
1396 ACTION("Non-boolean value ignored\n");
1401 info->groupInfo = XkbClampIntoRange;
1403 info->groupInfo = XkbWrapIntoRange;
1407 else if ((elem.str == NULL)
1408 && ((uStrCaseCmp(field.str, "groupsredirect") == 0)
1409 || (uStrCaseCmp(field.str, "redirectgroups") == 0)))
1411 if (!ExprResolveGroup(stmt->value, &tmp))
1413 ERROR("Illegal group index for global groupsRedirect\n");
1414 ACTION("Definition with non-integer group ignored\n");
1418 info->groupInfo = XkbSetGroupInfo(0, XkbRedirectIntoRange,
1423 else if ((elem.str == NULL) && (uStrCaseCmp(field.str, "allownone") == 0))
1425 ret = SetAllowNone(&info->dflt, arrayNdx, stmt->value);
1428 ret = SetActionField(xkb, elem.str, field.str, arrayNdx, stmt->value,
1438 HandleSymbolsBody(VarDef * def,
1439 struct xkb_desc * xkb, KeyInfo * key, SymbolsInfo * info)
1442 ExprResult tmp, field;
1445 for (; def != NULL; def = (VarDef *) def->common.next)
1447 if ((def->name) && (def->name->type == ExprFieldRef))
1449 ok = HandleSymbolsVar(def, xkb, info);
1454 if (def->name == NULL)
1456 if ((def->value == NULL)
1457 || (def->value->op == ExprKeysymList))
1458 field.str = strdup("symbols");
1460 field.str = strdup("actions");
1465 ok = ExprResolveLhs(def->name, &tmp, &field, &arrayNdx);
1468 ok = SetSymbolsField(key, xkb, field.str, arrayNdx,
1477 SetExplicitGroup(SymbolsInfo * info, KeyInfo * key)
1479 unsigned group = info->explicit_group;
1484 if ((key->typesDefined | key->symsDefined | key->actsDefined) & ~1)
1487 WARN("For the map %s an explicit group specified\n", info->name);
1488 WARN("but key %s has more than one group defined\n",
1489 longText(key->name));
1490 ACTION("All groups except first one will be ignored\n");
1491 for (i = 1; i < XkbNumKbdGroups; i++)
1493 key->numLevels[i] = 0;
1495 key->syms[i] = (uint32_t *) NULL;
1497 key->acts[i] = (union xkb_action *) NULL;
1498 key->types[i] = (uint32_t) 0;
1501 key->typesDefined = key->symsDefined = key->actsDefined = 1 << group;
1503 key->numLevels[group] = key->numLevels[0];
1504 key->numLevels[0] = 0;
1505 key->syms[group] = key->syms[0];
1506 key->syms[0] = (uint32_t *) NULL;
1507 key->acts[group] = key->acts[0];
1508 key->acts[0] = (union xkb_action *) NULL;
1509 key->types[group] = key->types[0];
1510 key->types[0] = (uint32_t) 0;
1515 HandleSymbolsDef(SymbolsDef * stmt,
1516 struct xkb_desc * xkb, unsigned merge, SymbolsInfo * info)
1521 CopyKeyInfo(&info->dflt, &key, False);
1522 key.defs.merge = stmt->merge;
1523 key.name = KeyNameToLong(stmt->keyName);
1524 if (!HandleSymbolsBody((VarDef *) stmt->symbols, xkb, &key, info))
1530 if (!SetExplicitGroup(info, &key))
1536 if (!AddKeySymbols(info, &key, xkb))
1545 HandleModMapDef(ModMapDef * def,
1546 struct xkb_desc * xkb, unsigned merge, SymbolsInfo * info)
1553 if (!LookupModIndex(NULL, def->modifier, TypeInt, &rtrn))
1555 ERROR("Illegal modifier map definition\n");
1556 ACTION("Ignoring map for non-modifier \"%s\"\n",
1557 XkbcAtomText(def->modifier));
1561 tmp.modifier = rtrn.uval;
1562 for (key = def->keys; key != NULL; key = (ExprDef *) key->common.next)
1564 if ((key->op == ExprValue) && (key->type == TypeKeyName))
1566 tmp.haveSymbol = False;
1567 tmp.u.keyName = KeyNameToLong(key->value.keyName);
1569 else if (ExprResolveKeySym(key, &rtrn))
1571 tmp.haveSymbol = True;
1572 tmp.u.keySym = rtrn.uval;
1576 ERROR("Modmap entries may contain only key names or keysyms\n");
1577 ACTION("Illegal definition for %s modifier ignored\n",
1578 XkbcModIndexText(tmp.modifier));
1582 ok = AddModMapEntry(info, &tmp) && ok;
1588 HandleSymbolsFile(XkbFile * file,
1589 struct xkb_desc * xkb, unsigned merge, SymbolsInfo * info)
1593 info->name = _XkbDupString(file->name);
1597 switch (stmt->stmtType)
1600 if (!HandleIncludeSymbols((IncludeStmt *) stmt, xkb, info,
1604 case StmtSymbolsDef:
1605 if (!HandleSymbolsDef((SymbolsDef *) stmt, xkb, merge, info))
1609 if (!HandleSymbolsVar((VarDef *) stmt, xkb, info))
1613 if (!HandleVModDef((VModDef *) stmt, xkb, merge, &info->vmods))
1617 ERROR("Interpretation files may not include other types\n");
1618 ACTION("Ignoring definition of symbol interpretation\n");
1621 case StmtKeycodeDef:
1622 ERROR("Interpretation files may not include other types\n");
1623 ACTION("Ignoring definition of key name\n");
1627 if (!HandleModMapDef((ModMapDef *) stmt, xkb, merge, info))
1631 WSGO("Unexpected statement type %d in HandleSymbolsFile\n",
1636 if (info->errorCount > 10)
1639 ERROR("Too many errors\n");
1641 ACTION("Abandoning symbols file \"%s\"\n", file->topName);
1649 FindKeyForSymbol(struct xkb_desc * xkb, uint32_t sym, xkb_keycode_t *kc_rtrn)
1652 register Bool gotOne;
1658 for (i = xkb->min_key_code; i <= (int) xkb->max_key_code; i++)
1660 if (j < (int) XkbKeyNumSyms(xkb, i))
1663 if (XkbKeySym(xkb, i, j) == sym)
1677 * Find the given name in the xkb->map->types and return its index.
1679 * @param name The atom to search for.
1680 * @param type_rtrn Set to the index of the name if found.
1682 * @return True if found, False otherwise.
1685 FindNamedType(struct xkb_desc * xkb, uint32_t name, unsigned *type_rtrn)
1687 register unsigned n;
1689 if (xkb && xkb->map && xkb->map->types)
1691 for (n = 0; n < xkb->map->num_types; n++)
1693 if (xkb->map->types[n].name == (uint32_t) name)
1704 * Assign a type to the given sym and return the Atom for the type assigned.
1707 * - ONE_LEVEL for width 0/1
1708 * - ALPHABETIC for 2 shift levels, with lower/upercase
1709 * - KEYPAD for keypad keys.
1710 * - TWO_LEVEL for other 2 shift level keys.
1711 * and the same for four level keys.
1713 * @param width Number of sysms in syms.
1714 * @param syms The keysyms for the given key (must be size width).
1715 * @param typeNameRtrn Set to the Atom of the type name.
1717 * @returns True if a type could be found, False otherwise.
1720 FindAutomaticType(int width, uint32_t * syms, uint32_t * typeNameRtrn,
1724 if ((width == 1) || (width == 0))
1726 *typeNameRtrn = xkb_intern_atom("ONE_LEVEL");
1729 else if (width == 2)
1731 if (syms && XkbcKSIsLower(syms[0]) && XkbcKSIsUpper(syms[1]))
1733 *typeNameRtrn = xkb_intern_atom("ALPHABETIC");
1735 else if (syms && (XkbKSIsKeypad(syms[0]) || XkbKSIsKeypad(syms[1])))
1737 *typeNameRtrn = xkb_intern_atom("KEYPAD");
1742 *typeNameRtrn = xkb_intern_atom("TWO_LEVEL");
1746 else if (width <= 4)
1748 if (syms && XkbcKSIsLower(syms[0]) && XkbcKSIsUpper(syms[1]))
1749 if (XkbcKSIsLower(syms[2]) && XkbcKSIsUpper(syms[3]))
1751 xkb_intern_atom("FOUR_LEVEL_ALPHABETIC");
1753 *typeNameRtrn = xkb_intern_atom("FOUR_LEVEL_SEMIALPHABETIC");
1755 else if (syms && (XkbKSIsKeypad(syms[0]) || XkbKSIsKeypad(syms[1])))
1756 *typeNameRtrn = xkb_intern_atom("FOUR_LEVEL_KEYPAD");
1758 *typeNameRtrn = xkb_intern_atom("FOUR_LEVEL");
1759 /* XXX: why not set autoType here? */
1761 return ((width >= 0) && (width <= 4));
1765 * Ensure the given KeyInfo is in a coherent state, i.e. no gaps between the
1766 * groups, and reduce to one group if all groups are identical anyway.
1769 PrepareKeyDef(KeyInfo * key)
1771 int i, j, width, defined, lastGroup;
1774 defined = key->symsDefined | key->actsDefined | key->typesDefined;
1775 /* get highest group number */
1776 for (i = XkbNumKbdGroups - 1; i >= 0; i--)
1778 if (defined & (1 << i))
1786 /* If there are empty groups between non-empty ones fill them with data */
1787 /* from the first group. */
1788 /* We can make a wrong assumption here. But leaving gaps is worse. */
1789 for (i = lastGroup; i > 0; i--)
1791 if (defined & (1 << i))
1793 width = key->numLevels[0];
1794 if (key->typesDefined & 1)
1796 for (j = 0; j < width; j++)
1798 key->types[i] = key->types[0];
1800 key->typesDefined |= 1 << i;
1802 if ((key->actsDefined & 1) && key->acts[0])
1804 key->acts[i] = uTypedCalloc(width, union xkb_action);
1805 if (key->acts[i] == NULL)
1807 memcpy((void *) key->acts[i], (void *) key->acts[0],
1808 width * sizeof(union xkb_action));
1809 key->actsDefined |= 1 << i;
1811 if ((key->symsDefined & 1) && key->syms[0])
1813 key->syms[i] = uTypedCalloc(width, uint32_t);
1814 if (key->syms[i] == NULL)
1816 memcpy((void *) key->syms[i], (void *) key->syms[0],
1817 width * sizeof(uint32_t));
1818 key->symsDefined |= 1 << i;
1822 key->numLevels[i] = key->numLevels[0];
1825 /* If all groups are completely identical remove them all */
1826 /* exept the first one. */
1828 for (i = lastGroup; i > 0; i--)
1830 if ((key->numLevels[i] != key->numLevels[0]) ||
1831 (key->types[i] != key->types[0]))
1836 if ((key->syms[i] != key->syms[0]) &&
1837 (key->syms[i] == NULL || key->syms[0] == NULL ||
1838 memcmp((void *) key->syms[i], (void *) key->syms[0],
1839 sizeof(uint32_t) * key->numLevels[0])))
1844 if ((key->acts[i] != key->acts[0]) &&
1845 (key->acts[i] == NULL || key->acts[0] == NULL ||
1846 memcmp((void *) key->acts[i], (void *) key->acts[0],
1847 sizeof(union xkb_action) * key->numLevels[0])))
1855 for (i = lastGroup; i > 0; i--)
1857 key->numLevels[i] = 0;
1859 key->syms[i] = (uint32_t *) NULL;
1861 key->acts[i] = (union xkb_action *) NULL;
1862 key->types[i] = (uint32_t) 0;
1864 key->symsDefined &= 1;
1865 key->actsDefined &= 1;
1866 key->typesDefined &= 1;
1872 * Copy the KeyInfo into the keyboard description.
1874 * This function recurses.
1877 CopySymbolsDef(struct xkb_desc * xkb, KeyInfo *key, int start_from)
1880 xkb_keycode_t okc, kc;
1881 unsigned width, tmp, nGroups;
1882 struct xkb_key_type * type;
1883 Bool haveActions, autoType, useAlias;
1885 union xkb_action *outActs;
1886 unsigned types[XkbNumKbdGroups];
1888 useAlias = (start_from == 0);
1890 /* get the keycode for the key. */
1891 if (!FindNamedKey(xkb, key->name, &kc, useAlias, CreateKeyNames(xkb),
1894 if ((start_from == 0) && (warningLevel >= 5))
1896 WARN("Key %s not found in %s keycodes\n",
1897 longText(key->name),
1898 XkbcAtomText(xkb->names->keycodes));
1899 ACTION("Symbols ignored\n");
1904 haveActions = False;
1905 for (i = width = nGroups = 0; i < XkbNumKbdGroups; i++)
1907 if (((i + 1) > nGroups)
1908 && (((key->symsDefined | key->actsDefined) & (1 << i))
1909 || (key->typesDefined) & (1 << i)))
1914 /* Assign the type to the key, if it is missing. */
1915 if (key->types[i] == None)
1917 if (key->dfltType != None)
1918 key->types[i] = key->dfltType;
1919 else if (FindAutomaticType(key->numLevels[i], key->syms[i],
1920 &key->types[i], &autoType))
1925 if (warningLevel >= 5)
1927 WARN("No automatic type for %d symbols\n",
1928 (unsigned int) key->numLevels[i]);
1929 ACTION("Using %s for the %s key (keycode %d)\n",
1930 XkbcAtomText(key->types[i]),
1931 longText(key->name), kc);
1935 if (FindNamedType(xkb, key->types[i], &types[i]))
1937 if (!autoType || key->numLevels[i] > 2)
1938 xkb->server->explicit[kc] |= (1 << i);
1942 if (warningLevel >= 3)
1944 WARN("Type \"%s\" is not defined\n",
1945 XkbcAtomText(key->types[i]));
1946 ACTION("Using TWO_LEVEL for the %s key (keycode %d)\n",
1947 longText(key->name), kc);
1949 types[i] = XkbTwoLevelIndex;
1951 /* if the type specifies less syms than the key has, shrink the key */
1952 type = &xkb->map->types[types[i]];
1953 if (type->num_levels < key->numLevels[i])
1955 if (warningLevel > 0)
1958 ("Type \"%s\" has %d levels, but %s has %d symbols\n",
1959 XkbcAtomText(type->name),
1960 (unsigned int) type->num_levels,
1961 longText(key->name),
1962 (unsigned int) key->numLevels[i]);
1963 ACTION("Ignoring extra symbols\n");
1965 key->numLevels[i] = type->num_levels;
1967 if (key->numLevels[i] > width)
1968 width = key->numLevels[i];
1969 if (type->num_levels > width)
1970 width = type->num_levels;
1973 /* width is now the largest width found */
1975 i = width * nGroups;
1976 outSyms = XkbcResizeKeySyms(xkb, kc, i);
1977 if (outSyms == NULL)
1979 WSGO("Could not enlarge symbols for %s (keycode %d)\n",
1980 longText(key->name), kc);
1985 outActs = XkbcResizeKeyActions(xkb, kc, i);
1986 if (outActs == NULL)
1988 WSGO("Could not enlarge actions for %s (key %d)\n",
1989 longText(key->name), kc);
1992 xkb->server->explicit[kc] |= XkbExplicitInterpretMask;
1996 if (key->defs.defined & _Key_GroupInfo)
1999 i = xkb->map->key_sym_map[kc].group_info;
2001 xkb->map->key_sym_map[kc].group_info = XkbSetNumGroups(i, nGroups);
2002 xkb->map->key_sym_map[kc].width = width;
2003 for (i = 0; i < nGroups; i++)
2005 /* assign kt_index[i] to the index of the type in map->types.
2006 * kt_index[i] may have been set by a previous run (if we have two
2007 * layouts specified). Let's not overwrite it with the ONE_LEVEL
2008 * default group if we dont even have keys for this group anyway.
2010 * FIXME: There should be a better fix for this.
2012 if (key->numLevels[i])
2013 xkb->map->key_sym_map[kc].kt_index[i] = types[i];
2014 if (key->syms[i] != NULL)
2016 /* fill key to "width" symbols*/
2017 for (tmp = 0; tmp < width; tmp++)
2019 if (tmp < key->numLevels[i])
2020 outSyms[tmp] = key->syms[i][tmp];
2022 outSyms[tmp] = NoSymbol;
2023 if ((outActs != NULL) && (key->acts[i] != NULL))
2025 if (tmp < key->numLevels[i])
2026 outActs[tmp] = key->acts[i][tmp];
2028 outActs[tmp].type = XkbSA_NoAction;
2036 switch (key->behavior.type & XkbKB_OpMask)
2040 case XkbKB_Overlay1:
2041 case XkbKB_Overlay2:
2042 /* find key by name! */
2043 if (!FindNamedKey(xkb, key->nameForOverlayKey, &okc, True,
2044 CreateKeyNames(xkb), 0))
2046 if (warningLevel >= 1)
2048 WARN("Key %s not found in %s keycodes\n",
2049 longText(key->nameForOverlayKey),
2050 XkbcAtomText(xkb->names->keycodes));
2051 ACTION("Not treating %s as an overlay key \n",
2052 longText(key->name));
2056 key->behavior.data = okc;
2058 xkb->server->behaviors[kc] = key->behavior;
2059 xkb->server->explicit[kc] |= XkbExplicitBehaviorMask;
2062 if (key->defs.defined & _Key_VModMap)
2064 xkb->server->vmodmap[kc] = key->vmodmap;
2065 xkb->server->explicit[kc] |= XkbExplicitVModMapMask;
2067 if (key->repeat != RepeatUndefined)
2069 if (key->repeat == RepeatYes)
2070 xkb->ctrls->per_key_repeat[kc / 8] |= (1 << (kc % 8));
2072 xkb->ctrls->per_key_repeat[kc / 8] &= ~(1 << (kc % 8));
2073 xkb->server->explicit[kc] |= XkbExplicitAutoRepeatMask;
2076 if (nGroups > xkb->ctrls->num_groups)
2077 xkb->ctrls->num_groups = nGroups;
2079 /* do the same thing for the next key */
2080 CopySymbolsDef(xkb, key, kc + 1);
2085 CopyModMapDef(struct xkb_desc * xkb, ModMapEntry *entry)
2089 if ((!entry->haveSymbol)
2092 (xkb, entry->u.keyName, &kc, True, CreateKeyNames(xkb), 0)))
2094 if (warningLevel >= 5)
2096 WARN("Key %s not found in %s keycodes\n",
2097 longText(entry->u.keyName),
2098 XkbcAtomText(xkb->names->keycodes));
2099 ACTION("Modifier map entry for %s not updated\n",
2100 XkbcModIndexText(entry->modifier));
2104 else if (entry->haveSymbol
2105 && (!FindKeyForSymbol(xkb, entry->u.keySym, &kc)))
2107 if (warningLevel > 5)
2109 WARN("Key \"%s\" not found in %s symbol map\n",
2110 XkbcKeysymText(entry->u.keySym),
2111 XkbcAtomText(xkb->names->symbols));
2112 ACTION("Modifier map entry for %s not updated\n",
2113 XkbcModIndexText(entry->modifier));
2117 xkb->map->modmap[kc] |= (1 << entry->modifier);
2122 * Handle the xkb_symbols section of an xkb file.
2124 * @param file The parsed xkb_symbols section of the xkb file.
2125 * @param xkb Handle to the keyboard description to store the symbols in.
2126 * @param merge Merge strategy (e.g. MergeOverride).
2129 CompileSymbols(XkbFile *file, struct xkb_desc * xkb, unsigned merge)
2134 InitSymbolsInfo(&info, xkb);
2135 info.dflt.defs.fileID = file->id;
2136 info.dflt.defs.merge = merge;
2137 HandleSymbolsFile(file, xkb, merge, &info);
2139 if (info.nKeys == 0) {
2140 FreeSymbolsInfo(&info);
2144 if (info.errorCount == 0)
2148 /* alloc memory in the xkb struct */
2149 if (XkbcAllocNames(xkb, XkbSymbolsNameMask | XkbGroupNamesMask, 0, 0)
2152 WSGO("Can not allocate names in CompileSymbols\n");
2153 ACTION("Symbols not added\n");
2156 if (XkbcAllocClientMap(xkb, XkbKeySymsMask | XkbModifierMapMask, 0)
2159 WSGO("Could not allocate client map in CompileSymbols\n");
2160 ACTION("Symbols not added\n");
2163 if (XkbcAllocServerMap(xkb, XkbAllServerInfoMask, 32) != Success)
2165 WSGO("Could not allocate server map in CompileSymbols\n");
2166 ACTION("Symbols not added\n");
2169 if (XkbcAllocControls(xkb, XkbPerKeyRepeatMask) != Success)
2171 WSGO("Could not allocate controls in CompileSymbols\n");
2172 ACTION("Symbols not added\n");
2176 /* now copy info into xkb. */
2177 xkb->names->symbols = xkb_intern_atom(info.name);
2179 ApplyAliases(xkb, False, &info.aliases);
2180 for (i = 0; i < XkbNumKbdGroups; i++)
2182 if (info.groupNames[i] != None)
2183 xkb->names->groups[i] = info.groupNames[i];
2186 for (key = info.keys, i = 0; i < info.nKeys; i++, key++)
2191 for (key = info.keys, i = 0; i < info.nKeys; i++, key++)
2193 if (!CopySymbolsDef(xkb, key, 0))
2196 if (warningLevel > 3)
2198 for (i = xkb->min_key_code; i <= xkb->max_key_code; i++)
2200 if (xkb->names->keys[i].name[0] == '\0')
2202 if (XkbKeyNumGroups(xkb, i) < 1)
2205 memcpy(buf, xkb->names->keys[i].name, 4);
2208 ("No symbols defined for <%s> (keycode %d)\n",
2215 ModMapEntry *mm, *next;
2216 for (mm = info.modMap; mm != NULL; mm = next)
2218 if (!CopyModMapDef(xkb, mm))
2220 next = (ModMapEntry *) mm->defs.next;
2223 FreeSymbolsInfo(&info);
2227 FreeSymbolsInfo(&info);