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));
355 for (i = 0; i < resultWidth; i++)
357 uint32_t fromSym, toSym;
358 if (from->syms[group] && (i < from->numLevels[group]))
359 fromSym = from->syms[group][i];
362 if (into->syms[group] && (i < into->numLevels[group]))
363 toSym = into->syms[group][i];
366 if ((fromSym == NoSymbol) || (fromSym == toSym))
367 resultSyms[i] = toSym;
368 else if (toSym == NoSymbol)
369 resultSyms[i] = fromSym;
372 uint32_t use, ignore;
386 ("Multiple symbols for level %d/group %d on key %s\n",
387 i + 1, group + 1, longText(into->name));
388 ACTION("Using %s, ignoring %s\n",
389 XkbcKeysymText(use), XkbcKeysymText(ignore));
393 if (resultActs != NULL)
395 union xkb_action *fromAct, *toAct;
396 fromAct = (from->acts[group] ? &from->acts[group][i] : NULL);
397 toAct = (into->acts[group] ? &into->acts[group][i] : NULL);
398 if (((fromAct == NULL) || (fromAct->type == XkbSA_NoAction))
401 resultActs[i] = *toAct;
403 else if (((toAct == NULL) || (toAct->type == XkbSA_NoAction))
404 && (fromAct != NULL))
406 resultActs[i] = *fromAct;
410 union xkb_action *use, *ignore;
424 ("Multiple actions for level %d/group %d on key %s\n",
425 i + 1, group + 1, longText(into->name));
426 ACTION("Using %s, ignoring %s\n",
427 XkbcActionTypeText(use->type),
428 XkbcActionTypeText(ignore->type));
431 resultActs[i] = *use;
435 if (resultSyms != into->syms[group])
436 free(into->syms[group]);
437 if (resultSyms != from->syms[group])
438 free(from->syms[group]);
439 if (resultActs != into->acts[group])
440 free(into->acts[group]);
441 if (resultActs != from->acts[group])
442 free(from->acts[group]);
443 into->numLevels[group] = resultWidth;
444 into->syms[group] = resultSyms;
445 from->syms[group] = NULL;
446 into->acts[group] = resultActs;
447 from->acts[group] = NULL;
448 into->symsDefined |= (1 << group);
449 from->symsDefined &= ~(1 << group);
450 into->actsDefined |= (1 << group);
451 from->actsDefined &= ~(1 << group);
456 MergeKeys(SymbolsInfo * info, KeyInfo * into, KeyInfo * from)
459 unsigned collide = 0;
462 if (from->defs.merge == MergeReplace)
464 for (i = 0; i < XkbNumKbdGroups; i++)
466 if (into->numLevels[i] != 0)
473 memset(from, 0, sizeof(KeyInfo));
476 report = ((warningLevel > 9) ||
477 ((into->defs.fileID == from->defs.fileID)
478 && (warningLevel > 0)));
479 for (i = 0; i < XkbNumKbdGroups; i++)
481 if (from->numLevels[i] > 0)
483 if (into->numLevels[i] == 0)
485 into->numLevels[i] = from->numLevels[i];
486 into->syms[i] = from->syms[i];
487 into->acts[i] = from->acts[i];
488 into->symsDefined |= (1 << i);
489 from->syms[i] = NULL;
490 from->acts[i] = NULL;
491 from->numLevels[i] = 0;
492 from->symsDefined &= ~(1 << i);
494 into->defs.defined |= _Key_Syms;
496 into->defs.defined |= _Key_Acts;
503 collide |= _Key_Syms;
505 collide |= _Key_Acts;
507 MergeKeyGroups(info, into, from, (unsigned) i);
510 if (from->types[i] != None)
512 if ((into->types[i] != None) && (report) &&
513 (into->types[i] != from->types[i]))
515 uint32_t use, ignore;
516 collide |= _Key_Types;
517 if (from->defs.merge != MergeAugment)
519 use = from->types[i];
520 ignore = into->types[i];
524 use = into->types[i];
525 ignore = from->types[i];
528 ("Multiple definitions for group %d type of key %s\n",
529 i, longText(into->name));
530 ACTION("Using %s, ignoring %s\n",
532 XkbcAtomText(ignore));
534 if ((from->defs.merge != MergeAugment)
535 || (into->types[i] == None))
537 into->types[i] = from->types[i];
541 if (UseNewField(_Key_Behavior, &into->defs, &from->defs, &collide))
543 into->behavior = from->behavior;
544 into->nameForOverlayKey = from->nameForOverlayKey;
545 into->defs.defined |= _Key_Behavior;
547 if (UseNewField(_Key_VModMap, &into->defs, &from->defs, &collide))
549 into->vmodmap = from->vmodmap;
550 into->defs.defined |= _Key_VModMap;
552 if (UseNewField(_Key_Repeat, &into->defs, &from->defs, &collide))
554 into->repeat = from->repeat;
555 into->defs.defined |= _Key_Repeat;
557 if (UseNewField(_Key_Type_Dflt, &into->defs, &from->defs, &collide))
559 into->dfltType = from->dfltType;
560 into->defs.defined |= _Key_Type_Dflt;
562 if (UseNewField(_Key_GroupInfo, &into->defs, &from->defs, &collide))
564 into->groupInfo = from->groupInfo;
565 into->defs.defined |= _Key_GroupInfo;
569 WARN("Symbol map for key %s redefined\n",
570 longText(into->name));
571 ACTION("Using %s definition for conflicting fields\n",
572 (from->defs.merge == MergeAugment ? "first" : "last"));
578 AddKeySymbols(SymbolsInfo * info, KeyInfo * key, struct xkb_desc * xkb)
581 unsigned long real_name;
583 for (i = 0; i < info->nKeys; i++)
585 if (info->keys[i].name == key->name)
586 return MergeKeys(info, &info->keys[i], key);
588 if (FindKeyNameForAlias(xkb, key->name, &real_name))
590 for (i = 0; i < info->nKeys; i++)
592 if (info->keys[i].name == real_name)
593 return MergeKeys(info, &info->keys[i], key);
596 if (info->nKeys >= info->szKeys)
598 info->szKeys += SYMBOLS_CHUNK;
600 uTypedRecalloc(info->keys, info->nKeys, info->szKeys, KeyInfo);
603 WSGO("Could not allocate key symbols descriptions\n");
604 ACTION("Some key symbols definitions may be lost\n");
608 return CopyKeyInfo(key, &info->keys[info->nKeys++], True);
612 AddModMapEntry(SymbolsInfo * info, ModMapEntry * new)
617 clobber = (new->defs.merge != MergeAugment);
618 for (mm = info->modMap; mm != NULL; mm = (ModMapEntry *) mm->defs.next)
620 if (new->haveSymbol && mm->haveSymbol
621 && (new->u.keySym == mm->u.keySym))
623 unsigned use, ignore;
624 if (mm->modifier != new->modifier)
629 ignore = mm->modifier;
634 ignore = new->modifier;
637 ("%s added to symbol map for multiple modifiers\n",
638 XkbcKeysymText(new->u.keySym));
639 ACTION("Using %s, ignoring %s.\n",
640 XkbcModIndexText(use),
641 XkbcModIndexText(ignore));
646 if ((!new->haveSymbol) && (!mm->haveSymbol) &&
647 (new->u.keyName == mm->u.keyName))
649 unsigned use, ignore;
650 if (mm->modifier != new->modifier)
655 ignore = mm->modifier;
660 ignore = new->modifier;
662 ERROR("Key %s added to map for multiple modifiers\n",
663 longText(new->u.keyName));
664 ACTION("Using %s, ignoring %s.\n",
665 XkbcModIndexText(use),
666 XkbcModIndexText(ignore));
672 mm = uTypedAlloc(ModMapEntry);
675 WSGO("Could not allocate modifier map entry\n");
676 ACTION("Modifier map for %s will be incomplete\n",
677 XkbcModIndexText(new->modifier));
681 mm->defs.next = &info->modMap->defs;
686 /***====================================================================***/
689 MergeIncludedSymbols(SymbolsInfo * into, SymbolsInfo * from,
690 unsigned merge, struct xkb_desc * xkb)
695 if (from->errorCount > 0)
697 into->errorCount += from->errorCount;
700 if (into->name == NULL)
702 into->name = from->name;
705 for (i = 0; i < XkbNumKbdGroups; i++)
707 if (from->groupNames[i] != None)
709 if ((merge != MergeAugment) || (into->groupNames[i] == None))
710 into->groupNames[i] = from->groupNames[i];
713 for (i = 0, key = from->keys; i < from->nKeys; i++, key++)
715 if (merge != MergeDefault)
716 key->defs.merge = merge;
717 if (!AddKeySymbols(into, key, xkb))
720 if (from->modMap != NULL)
722 ModMapEntry *mm, *next;
723 for (mm = from->modMap; mm != NULL; mm = next)
725 if (merge != MergeDefault)
726 mm->defs.merge = merge;
727 if (!AddModMapEntry(into, mm))
729 next = (ModMapEntry *) mm->defs.next;
734 if (!MergeAliases(&into->aliases, &from->aliases, merge))
738 typedef void (*FileHandler) (XkbFile * /* rtrn */ ,
739 struct xkb_desc * /* xkb */ ,
740 unsigned /* merge */ ,
741 SymbolsInfo * /* included */
745 HandleIncludeSymbols(IncludeStmt * stmt,
746 struct xkb_desc * xkb, SymbolsInfo * info, FileHandler hndlr)
750 SymbolsInfo included;
754 if ((stmt->file == NULL) && (stmt->map == NULL))
758 memset(info, 0, sizeof(SymbolsInfo));
760 else if (ProcessIncludeFile(stmt, XkmSymbolsIndex, &rtrn, &newMerge))
762 InitSymbolsInfo(&included, xkb);
763 included.fileID = included.dflt.defs.fileID = rtrn->id;
764 included.merge = included.dflt.defs.merge = MergeOverride;
767 included.explicit_group = atoi(stmt->modifier) - 1;
771 included.explicit_group = info->explicit_group;
773 (*hndlr) (rtrn, xkb, MergeOverride, &included);
774 if (stmt->stmt != NULL)
777 included.name = stmt->stmt;
783 info->errorCount += 10;
786 if ((stmt->next != NULL) && (included.errorCount < 1))
790 SymbolsInfo next_incl;
792 for (next = stmt->next; next != NULL; next = next->next)
794 if ((next->file == NULL) && (next->map == NULL))
797 MergeIncludedSymbols(&included, info, next->merge, xkb);
798 FreeSymbolsInfo(info);
800 else if (ProcessIncludeFile(next, XkmSymbolsIndex, &rtrn, &op))
802 InitSymbolsInfo(&next_incl, xkb);
803 next_incl.fileID = next_incl.dflt.defs.fileID = rtrn->id;
804 next_incl.merge = next_incl.dflt.defs.merge = MergeOverride;
807 next_incl.explicit_group = atoi(next->modifier) - 1;
811 next_incl.explicit_group = info->explicit_group;
813 (*hndlr) (rtrn, xkb, MergeOverride, &next_incl);
814 MergeIncludedSymbols(&included, &next_incl, op, xkb);
815 FreeSymbolsInfo(&next_incl);
819 info->errorCount += 10;
828 MergeIncludedSymbols(info, &included, newMerge, xkb);
829 FreeSymbolsInfo(&included);
831 return (info->errorCount == 0);
838 GetGroupIndex(KeyInfo * key,
839 ExprDef * arrayNdx, unsigned what, unsigned *ndx_rtrn)
849 if (arrayNdx == NULL)
854 defined = key->symsDefined;
856 defined = key->actsDefined;
858 for (i = 0; i < XkbNumKbdGroups; i++)
860 if ((defined & (1 << i)) == 0)
866 ERROR("Too many groups of %s for key %s (max %d)\n", name,
867 longText(key->name), XkbNumKbdGroups + 1);
868 ACTION("Ignoring %s defined for extra groups\n", name);
871 if (!ExprResolveGroup(arrayNdx, &tmp))
873 ERROR("Illegal group index for %s of key %s\n", name,
874 longText(key->name));
875 ACTION("Definition with non-integer array index ignored\n");
878 *ndx_rtrn = tmp.uval - 1;
883 AddSymbolsToKey(KeyInfo * key,
884 struct xkb_desc * xkb,
886 ExprDef * arrayNdx, ExprDef * value, SymbolsInfo * info)
891 if (!GetGroupIndex(key, arrayNdx, SYMBOLS, &ndx))
895 key->symsDefined |= (1 << ndx);
898 if (value->op != ExprKeysymList)
900 ERROR("Expected a list of symbols, found %s\n",
901 exprOpText(value->op));
902 ACTION("Ignoring symbols for group %d of %s\n", ndx,
903 longText(key->name));
906 if (key->syms[ndx] != NULL)
908 WSGO("Symbols for key %s, group %d already defined\n",
909 longText(key->name), ndx);
912 nSyms = value->value.list.nSyms;
913 if (((key->numLevels[ndx] < nSyms) || (key->syms[ndx] == NULL)) &&
914 (!ResizeKeyGroup(key, ndx, nSyms, False)))
916 WSGO("Could not resize group %d of key %s\n", ndx,
917 longText(key->name));
918 ACTION("Symbols lost\n");
921 key->symsDefined |= (1 << ndx);
922 for (i = 0; i < nSyms; i++) {
923 if (!LookupKeysym(value->value.list.syms[i], &key->syms[ndx][i])) {
924 WSGO("Could not resolve keysym %s\n", value->value.list.syms[i]);
925 key->syms[ndx][i] = NoSymbol;
928 for (i = key->numLevels[ndx] - 1;
929 (i >= 0) && (key->syms[ndx][i] == NoSymbol); i--)
931 key->numLevels[ndx]--;
937 AddActionsToKey(KeyInfo * key,
938 struct xkb_desc * xkb,
940 ExprDef * arrayNdx, ExprDef * value, SymbolsInfo * info)
945 struct xkb_any_action *toAct;
947 if (!GetGroupIndex(key, arrayNdx, ACTIONS, &ndx))
952 key->actsDefined |= (1 << ndx);
955 if (value->op != ExprActionList)
957 WSGO("Bad expression type (%d) for action list value\n", value->op);
958 ACTION("Ignoring actions for group %d of %s\n", ndx,
959 longText(key->name));
962 if (key->acts[ndx] != NULL)
964 WSGO("Actions for key %s, group %d already defined\n",
965 longText(key->name), ndx);
968 for (nActs = 0, act = value->value.child; act != NULL; nActs++)
970 act = (ExprDef *) act->common.next;
974 WSGO("Action list but not actions in AddActionsToKey\n");
977 if (((key->numLevels[ndx] < nActs) || (key->acts[ndx] == NULL)) &&
978 (!ResizeKeyGroup(key, ndx, nActs, True)))
980 WSGO("Could not resize group %d of key %s\n", ndx,
981 longText(key->name));
982 ACTION("Actions lost\n");
985 key->actsDefined |= (1 << ndx);
987 toAct = (struct xkb_any_action *) key->acts[ndx];
988 act = value->value.child;
989 for (i = 0; i < nActs; i++, toAct++)
991 if (!HandleActionDef(act, xkb, toAct, MergeOverride, info->action))
993 ERROR("Illegal action definition for %s\n",
994 longText(key->name));
995 ACTION("Action for group %d/level %d ignored\n", ndx + 1, i + 1);
997 act = (ExprDef *) act->common.next;
1003 SetAllowNone(KeyInfo * key, ExprDef * arrayNdx, ExprDef * value)
1006 unsigned radio_groups = 0;
1008 if (arrayNdx == NULL)
1010 radio_groups = XkbAllRadioGroupsMask;
1014 if (!ExprResolveRadioGroup(arrayNdx, &tmp))
1016 ERROR("Illegal index in group name definition\n");
1017 ACTION("Definition with non-integer array index ignored\n");
1020 if ((tmp.uval < 1) || (tmp.uval > XkbMaxRadioGroups))
1022 ERROR("Illegal radio group specified (must be 1..%d)\n",
1023 XkbMaxRadioGroups + 1);
1024 ACTION("Value of \"allow none\" for group %d ignored\n",
1028 radio_groups |= (1 << (tmp.uval - 1));
1030 if (!ExprResolveBoolean(value, &tmp))
1032 ERROR("Illegal \"allow none\" value for %s\n",
1033 longText(key->name));
1034 ACTION("Non-boolean value ignored\n");
1038 key->allowNone |= radio_groups;
1040 key->allowNone &= ~radio_groups;
1045 static const LookupEntry lockingEntries[] = {
1046 {"true", XkbKB_Lock},
1047 {"yes", XkbKB_Lock},
1049 {"false", XkbKB_Default},
1050 {"no", XkbKB_Default},
1051 {"off", XkbKB_Default},
1052 {"permanent", XkbKB_Lock | XkbKB_Permanent},
1056 static const LookupEntry repeatEntries[] = {
1057 {"true", RepeatYes},
1060 {"false", RepeatNo},
1063 {"default", RepeatUndefined},
1068 SetSymbolsField(KeyInfo * key,
1069 struct xkb_desc * xkb,
1071 ExprDef * arrayNdx, ExprDef * value, SymbolsInfo * info)
1076 if (uStrCaseCmp(field, "type") == 0)
1079 if ((!ExprResolveString(value, &tmp))
1080 && (warningLevel > 0))
1082 WARN("The type field of a key symbol map must be a string\n");
1083 ACTION("Ignoring illegal type definition\n");
1085 if (arrayNdx == NULL)
1087 key->dfltType = xkb_intern_atom(tmp.str);
1088 key->defs.defined |= _Key_Type_Dflt;
1090 else if (!ExprResolveGroup(arrayNdx, &ndx))
1092 ERROR("Illegal group index for type of key %s\n",
1093 longText(key->name));
1094 ACTION("Definition with non-integer array index ignored\n");
1100 key->types[ndx.uval - 1] = xkb_intern_atom(tmp.str);
1101 key->typesDefined |= (1 << (ndx.uval - 1));
1105 else if (uStrCaseCmp(field, "symbols") == 0)
1106 return AddSymbolsToKey(key, xkb, field, arrayNdx, value, info);
1107 else if (uStrCaseCmp(field, "actions") == 0)
1108 return AddActionsToKey(key, xkb, field, arrayNdx, value, info);
1109 else if ((uStrCaseCmp(field, "vmods") == 0) ||
1110 (uStrCaseCmp(field, "virtualmods") == 0) ||
1111 (uStrCaseCmp(field, "virtualmodifiers") == 0))
1113 ok = ExprResolveVModMask(value, &tmp, xkb);
1116 key->vmodmap = (tmp.uval >> 8);
1117 key->defs.defined |= _Key_VModMap;
1121 ERROR("Expected a virtual modifier mask, found %s\n",
1122 exprOpText(value->op));
1123 ACTION("Ignoring virtual modifiers definition for key %s\n",
1124 longText(key->name));
1127 else if ((uStrCaseCmp(field, "locking") == 0)
1128 || (uStrCaseCmp(field, "lock") == 0)
1129 || (uStrCaseCmp(field, "locks") == 0))
1131 ok = ExprResolveEnum(value, &tmp, lockingEntries);
1133 key->behavior.type = tmp.uval;
1134 key->defs.defined |= _Key_Behavior;
1136 else if ((uStrCaseCmp(field, "radiogroup") == 0) ||
1137 (uStrCaseCmp(field, "permanentradiogroup") == 0))
1139 Bool permanent = False;
1140 if (uStrCaseCmp(field, "permanentradiogroup") == 0)
1142 if (ExprResolveString(value, &tmp)) {
1143 ok = (strcmp(tmp.str, "none") == 0);
1149 ok = ExprResolveInteger(value, &tmp);
1153 ERROR("Illegal radio group specification for %s\n",
1154 longText(key->name));
1155 ACTION("Non-integer radio group ignored\n");
1160 key->behavior.type = XkbKB_Default;
1161 key->behavior.data = 0;
1164 if ((tmp.uval < 1) || (tmp.uval > XkbMaxRadioGroups))
1167 ("Radio group specification for %s out of range (1..32)\n",
1168 longText(key->name));
1169 ACTION("Illegal radio group %d ignored\n", tmp.uval);
1172 key->behavior.type =
1173 XkbKB_RadioGroup | (permanent ? XkbKB_Permanent : 0);
1174 key->behavior.data = tmp.uval - 1;
1175 if (key->allowNone & (1 << (tmp.uval - 1)))
1176 key->behavior.data |= XkbKB_RGAllowNone;
1177 key->defs.defined |= _Key_Behavior;
1179 else if (uStrCaseEqual(field, "allownone"))
1181 ok = SetAllowNone(key, arrayNdx, value);
1183 else if (uStrCasePrefix("overlay", field) ||
1184 uStrCasePrefix("permanentoverlay", field))
1186 Bool permanent = False;
1189 if (uStrCasePrefix("permanent", field))
1192 which = &field[sizeof("permanentoverlay") - 1];
1196 which = &field[sizeof("overlay") - 1];
1198 if (sscanf(which, "%d", &overlayNdx) == 1)
1200 if (((overlayNdx < 1) || (overlayNdx > 2)) && (warningLevel > 0))
1202 ERROR("Illegal overlay %d specified for %s\n",
1203 overlayNdx, longText(key->name));
1204 ACTION("Ignored\n");
1208 else if (*which == '\0')
1210 else if (warningLevel > 0)
1212 ERROR("Illegal overlay \"%s\" specified for %s\n",
1213 which, longText(key->name));
1214 ACTION("Ignored\n");
1217 ok = ExprResolveKeyName(value, &tmp);
1220 ERROR("Illegal overlay key specification for %s\n",
1221 longText(key->name));
1222 ACTION("Overlay key must be specified by name\n");
1225 if (overlayNdx == 1)
1226 key->behavior.type = XkbKB_Overlay1;
1228 key->behavior.type = XkbKB_Overlay2;
1230 key->behavior.type |= XkbKB_Permanent;
1232 key->behavior.data = 0;
1233 key->nameForOverlayKey = KeyNameToLong(tmp.keyName.name);
1234 key->defs.defined |= _Key_Behavior;
1236 else if ((uStrCaseCmp(field, "repeating") == 0) ||
1237 (uStrCaseCmp(field, "repeats") == 0) ||
1238 (uStrCaseCmp(field, "repeat") == 0))
1240 ok = ExprResolveEnum(value, &tmp, repeatEntries);
1243 ERROR("Illegal repeat setting for %s\n",
1244 longText(key->name));
1245 ACTION("Non-boolean repeat setting ignored\n");
1248 key->repeat = tmp.uval;
1249 key->defs.defined |= _Key_Repeat;
1251 else if ((uStrCaseCmp(field, "groupswrap") == 0) ||
1252 (uStrCaseCmp(field, "wrapgroups") == 0))
1254 ok = ExprResolveBoolean(value, &tmp);
1257 ERROR("Illegal groupsWrap setting for %s\n",
1258 longText(key->name));
1259 ACTION("Non-boolean value ignored\n");
1263 key->groupInfo = XkbWrapIntoRange;
1265 key->groupInfo = XkbClampIntoRange;
1266 key->defs.defined |= _Key_GroupInfo;
1268 else if ((uStrCaseCmp(field, "groupsclamp") == 0) ||
1269 (uStrCaseCmp(field, "clampgroups") == 0))
1271 ok = ExprResolveBoolean(value, &tmp);
1274 ERROR("Illegal groupsClamp setting for %s\n",
1275 longText(key->name));
1276 ACTION("Non-boolean value ignored\n");
1280 key->groupInfo = XkbClampIntoRange;
1282 key->groupInfo = XkbWrapIntoRange;
1283 key->defs.defined |= _Key_GroupInfo;
1285 else if ((uStrCaseCmp(field, "groupsredirect") == 0) ||
1286 (uStrCaseCmp(field, "redirectgroups") == 0))
1288 if (!ExprResolveGroup(value, &tmp))
1290 ERROR("Illegal group index for redirect of key %s\n",
1291 longText(key->name));
1292 ACTION("Definition with non-integer group ignored\n");
1296 XkbSetGroupInfo(0, XkbRedirectIntoRange, tmp.uval - 1);
1297 key->defs.defined |= _Key_GroupInfo;
1301 ERROR("Unknown field %s in a symbol interpretation\n", field);
1302 ACTION("Definition ignored\n");
1309 SetGroupName(SymbolsInfo * info, ExprDef * arrayNdx, ExprDef * value)
1311 ExprResult tmp, name;
1313 if ((arrayNdx == NULL) && (warningLevel > 0))
1315 WARN("You must specify an index when specifying a group name\n");
1316 ACTION("Group name definition without array subscript ignored\n");
1319 if (!ExprResolveGroup(arrayNdx, &tmp))
1321 ERROR("Illegal index in group name definition\n");
1322 ACTION("Definition with non-integer array index ignored\n");
1325 if (!ExprResolveString(value, &name))
1327 ERROR("Group name must be a string\n");
1328 ACTION("Illegal name for group %d ignored\n", tmp.uval);
1331 info->groupNames[tmp.uval - 1 + info->explicit_group] =
1332 xkb_intern_atom(name.str);
1339 HandleSymbolsVar(VarDef * stmt, struct xkb_desc * xkb, SymbolsInfo * info)
1341 ExprResult elem, field, tmp;
1345 if (ExprResolveLhs(stmt->name, &elem, &field, &arrayNdx) == 0)
1346 return 0; /* internal error, already reported */
1347 if (elem.str && (uStrCaseCmp(elem.str, "key") == 0))
1349 ret = SetSymbolsField(&info->dflt, xkb, field.str, arrayNdx,
1352 else if ((elem.str == NULL) && ((uStrCaseCmp(field.str, "name") == 0) ||
1353 (uStrCaseCmp(field.str, "groupname") ==
1356 ret = SetGroupName(info, arrayNdx, stmt->value);
1358 else if ((elem.str == NULL)
1359 && ((uStrCaseCmp(field.str, "groupswrap") == 0)
1360 || (uStrCaseCmp(field.str, "wrapgroups") == 0)))
1362 if (!ExprResolveBoolean(stmt->value, &tmp))
1364 ERROR("Illegal setting for global groupsWrap\n");
1365 ACTION("Non-boolean value ignored\n");
1370 info->groupInfo = XkbWrapIntoRange;
1372 info->groupInfo = XkbClampIntoRange;
1376 else if ((elem.str == NULL)
1377 && ((uStrCaseCmp(field.str, "groupsclamp") == 0)
1378 || (uStrCaseCmp(field.str, "clampgroups") == 0)))
1380 if (!ExprResolveBoolean(stmt->value, &tmp))
1382 ERROR("Illegal setting for global groupsClamp\n");
1383 ACTION("Non-boolean value ignored\n");
1388 info->groupInfo = XkbClampIntoRange;
1390 info->groupInfo = XkbWrapIntoRange;
1394 else if ((elem.str == NULL)
1395 && ((uStrCaseCmp(field.str, "groupsredirect") == 0)
1396 || (uStrCaseCmp(field.str, "redirectgroups") == 0)))
1398 if (!ExprResolveGroup(stmt->value, &tmp))
1400 ERROR("Illegal group index for global groupsRedirect\n");
1401 ACTION("Definition with non-integer group ignored\n");
1405 info->groupInfo = XkbSetGroupInfo(0, XkbRedirectIntoRange,
1410 else if ((elem.str == NULL) && (uStrCaseCmp(field.str, "allownone") == 0))
1412 ret = SetAllowNone(&info->dflt, arrayNdx, stmt->value);
1415 ret = SetActionField(xkb, elem.str, field.str, arrayNdx, stmt->value,
1425 HandleSymbolsBody(VarDef * def,
1426 struct xkb_desc * xkb, KeyInfo * key, SymbolsInfo * info)
1429 ExprResult tmp, field;
1432 for (; def != NULL; def = (VarDef *) def->common.next)
1434 if ((def->name) && (def->name->type == ExprFieldRef))
1436 ok = HandleSymbolsVar(def, xkb, info);
1441 if (def->name == NULL)
1443 if ((def->value == NULL)
1444 || (def->value->op == ExprKeysymList))
1445 field.str = strdup("symbols");
1447 field.str = strdup("actions");
1452 ok = ExprResolveLhs(def->name, &tmp, &field, &arrayNdx);
1455 ok = SetSymbolsField(key, xkb, field.str, arrayNdx,
1464 SetExplicitGroup(SymbolsInfo * info, KeyInfo * key)
1466 unsigned group = info->explicit_group;
1471 if ((key->typesDefined | key->symsDefined | key->actsDefined) & ~1)
1474 WARN("For the map %s an explicit group specified\n", info->name);
1475 WARN("but key %s has more than one group defined\n",
1476 longText(key->name));
1477 ACTION("All groups except first one will be ignored\n");
1478 for (i = 1; i < XkbNumKbdGroups; i++)
1480 key->numLevels[i] = 0;
1482 key->syms[i] = NULL;
1484 key->acts[i] = NULL;
1488 key->typesDefined = key->symsDefined = key->actsDefined = 1 << group;
1490 key->numLevels[group] = key->numLevels[0];
1491 key->numLevels[0] = 0;
1492 key->syms[group] = key->syms[0];
1493 key->syms[0] = NULL;
1494 key->acts[group] = key->acts[0];
1495 key->acts[0] = NULL;
1496 key->types[group] = key->types[0];
1502 HandleSymbolsDef(SymbolsDef * stmt,
1503 struct xkb_desc * xkb, unsigned merge, SymbolsInfo * info)
1508 CopyKeyInfo(&info->dflt, &key, False);
1509 key.defs.merge = stmt->merge;
1510 key.name = KeyNameToLong(stmt->keyName);
1511 if (!HandleSymbolsBody((VarDef *) stmt->symbols, xkb, &key, info))
1517 if (!SetExplicitGroup(info, &key))
1523 if (!AddKeySymbols(info, &key, xkb))
1532 HandleModMapDef(ModMapDef * def,
1533 struct xkb_desc * xkb, unsigned merge, SymbolsInfo * info)
1540 if (!LookupModIndex(NULL, def->modifier, TypeInt, &rtrn))
1542 ERROR("Illegal modifier map definition\n");
1543 ACTION("Ignoring map for non-modifier \"%s\"\n",
1544 XkbcAtomText(def->modifier));
1548 tmp.modifier = rtrn.uval;
1549 for (key = def->keys; key != NULL; key = (ExprDef *) key->common.next)
1551 if ((key->op == ExprValue) && (key->type == TypeKeyName))
1553 tmp.haveSymbol = False;
1554 tmp.u.keyName = KeyNameToLong(key->value.keyName);
1556 else if (ExprResolveKeySym(key, &rtrn))
1558 tmp.haveSymbol = True;
1559 tmp.u.keySym = rtrn.uval;
1563 ERROR("Modmap entries may contain only key names or keysyms\n");
1564 ACTION("Illegal definition for %s modifier ignored\n",
1565 XkbcModIndexText(tmp.modifier));
1569 ok = AddModMapEntry(info, &tmp) && ok;
1575 HandleSymbolsFile(XkbFile * file,
1576 struct xkb_desc * xkb, unsigned merge, SymbolsInfo * info)
1580 info->name = _XkbDupString(file->name);
1584 switch (stmt->stmtType)
1587 if (!HandleIncludeSymbols((IncludeStmt *) stmt, xkb, info,
1591 case StmtSymbolsDef:
1592 if (!HandleSymbolsDef((SymbolsDef *) stmt, xkb, merge, info))
1596 if (!HandleSymbolsVar((VarDef *) stmt, xkb, info))
1600 if (!HandleVModDef((VModDef *) stmt, xkb, merge, &info->vmods))
1604 ERROR("Interpretation files may not include other types\n");
1605 ACTION("Ignoring definition of symbol interpretation\n");
1608 case StmtKeycodeDef:
1609 ERROR("Interpretation files may not include other types\n");
1610 ACTION("Ignoring definition of key name\n");
1614 if (!HandleModMapDef((ModMapDef *) stmt, xkb, merge, info))
1618 WSGO("Unexpected statement type %d in HandleSymbolsFile\n",
1623 if (info->errorCount > 10)
1626 ERROR("Too many errors\n");
1628 ACTION("Abandoning symbols file \"%s\"\n", file->topName);
1635 FindKeyForSymbol(struct xkb_desc * xkb, uint32_t sym, xkb_keycode_t *kc_rtrn)
1644 for (i = xkb->min_key_code; i <= (int) xkb->max_key_code; i++)
1646 if (j < (int) XkbKeyNumSyms(xkb, i))
1649 if (XkbKeySym(xkb, i, j) == sym)
1663 * Find the given name in the xkb->map->types and return its index.
1665 * @param name The atom to search for.
1666 * @param type_rtrn Set to the index of the name if found.
1668 * @return True if found, False otherwise.
1671 FindNamedType(struct xkb_desc * xkb, uint32_t name, unsigned *type_rtrn)
1675 if (xkb && xkb->map && xkb->map->types)
1677 for (n = 0; n < xkb->map->num_types; n++)
1679 if (xkb->map->types[n].name == (uint32_t) name)
1690 * Assign a type to the given sym and return the Atom for the type assigned.
1693 * - ONE_LEVEL for width 0/1
1694 * - ALPHABETIC for 2 shift levels, with lower/upercase
1695 * - KEYPAD for keypad keys.
1696 * - TWO_LEVEL for other 2 shift level keys.
1697 * and the same for four level keys.
1699 * @param width Number of sysms in syms.
1700 * @param syms The keysyms for the given key (must be size width).
1701 * @param typeNameRtrn Set to the Atom of the type name.
1703 * @returns True if a type could be found, False otherwise.
1706 FindAutomaticType(int width, uint32_t * syms, uint32_t * typeNameRtrn,
1710 if ((width == 1) || (width == 0))
1712 *typeNameRtrn = xkb_intern_atom("ONE_LEVEL");
1715 else if (width == 2)
1717 if (syms && XkbcKSIsLower(syms[0]) && XkbcKSIsUpper(syms[1]))
1719 *typeNameRtrn = xkb_intern_atom("ALPHABETIC");
1721 else if (syms && (XkbKSIsKeypad(syms[0]) || XkbKSIsKeypad(syms[1])))
1723 *typeNameRtrn = xkb_intern_atom("KEYPAD");
1728 *typeNameRtrn = xkb_intern_atom("TWO_LEVEL");
1732 else if (width <= 4)
1734 if (syms && XkbcKSIsLower(syms[0]) && XkbcKSIsUpper(syms[1]))
1735 if (XkbcKSIsLower(syms[2]) && XkbcKSIsUpper(syms[3]))
1737 xkb_intern_atom("FOUR_LEVEL_ALPHABETIC");
1739 *typeNameRtrn = xkb_intern_atom("FOUR_LEVEL_SEMIALPHABETIC");
1741 else if (syms && (XkbKSIsKeypad(syms[0]) || XkbKSIsKeypad(syms[1])))
1742 *typeNameRtrn = xkb_intern_atom("FOUR_LEVEL_KEYPAD");
1744 *typeNameRtrn = xkb_intern_atom("FOUR_LEVEL");
1745 /* XXX: why not set autoType here? */
1747 return ((width >= 0) && (width <= 4));
1751 * Ensure the given KeyInfo is in a coherent state, i.e. no gaps between the
1752 * groups, and reduce to one group if all groups are identical anyway.
1755 PrepareKeyDef(KeyInfo * key)
1757 int i, j, width, defined, lastGroup;
1760 defined = key->symsDefined | key->actsDefined | key->typesDefined;
1761 /* get highest group number */
1762 for (i = XkbNumKbdGroups - 1; i >= 0; i--)
1764 if (defined & (1 << i))
1772 /* If there are empty groups between non-empty ones fill them with data */
1773 /* from the first group. */
1774 /* We can make a wrong assumption here. But leaving gaps is worse. */
1775 for (i = lastGroup; i > 0; i--)
1777 if (defined & (1 << i))
1779 width = key->numLevels[0];
1780 if (key->typesDefined & 1)
1782 for (j = 0; j < width; j++)
1784 key->types[i] = key->types[0];
1786 key->typesDefined |= 1 << i;
1788 if ((key->actsDefined & 1) && key->acts[0])
1790 key->acts[i] = uTypedCalloc(width, union xkb_action);
1791 if (key->acts[i] == NULL)
1793 memcpy(key->acts[i], key->acts[0],
1794 width * sizeof(union xkb_action));
1795 key->actsDefined |= 1 << i;
1797 if ((key->symsDefined & 1) && key->syms[0])
1799 key->syms[i] = uTypedCalloc(width, uint32_t);
1800 if (key->syms[i] == NULL)
1802 memcpy(key->syms[i], key->syms[0], width * sizeof(uint32_t));
1803 key->symsDefined |= 1 << i;
1807 key->numLevels[i] = key->numLevels[0];
1810 /* If all groups are completely identical remove them all */
1811 /* exept the first one. */
1813 for (i = lastGroup; i > 0; i--)
1815 if ((key->numLevels[i] != key->numLevels[0]) ||
1816 (key->types[i] != key->types[0]))
1821 if ((key->syms[i] != key->syms[0]) &&
1822 (key->syms[i] == NULL || key->syms[0] == NULL ||
1823 memcmp(key->syms[i], key->syms[0],
1824 sizeof(uint32_t) * key->numLevels[0])))
1829 if ((key->acts[i] != key->acts[0]) &&
1830 (key->acts[i] == NULL || key->acts[0] == NULL ||
1831 memcmp(key->acts[i], key->acts[0],
1832 sizeof(union xkb_action) * key->numLevels[0])))
1840 for (i = lastGroup; i > 0; i--)
1842 key->numLevels[i] = 0;
1844 key->syms[i] = NULL;
1846 key->acts[i] = NULL;
1849 key->symsDefined &= 1;
1850 key->actsDefined &= 1;
1851 key->typesDefined &= 1;
1856 * Copy the KeyInfo into the keyboard description.
1858 * This function recurses.
1861 CopySymbolsDef(struct xkb_desc * xkb, KeyInfo *key, int start_from)
1864 xkb_keycode_t okc, kc;
1865 unsigned width, tmp, nGroups;
1866 struct xkb_key_type * type;
1867 Bool haveActions, autoType, useAlias;
1869 union xkb_action *outActs;
1870 unsigned types[XkbNumKbdGroups];
1872 useAlias = (start_from == 0);
1874 /* get the keycode for the key. */
1875 if (!FindNamedKey(xkb, key->name, &kc, useAlias, CreateKeyNames(xkb),
1878 if ((start_from == 0) && (warningLevel >= 5))
1880 WARN("Key %s not found in %s keycodes\n",
1881 longText(key->name),
1882 XkbcAtomText(xkb->names->keycodes));
1883 ACTION("Symbols ignored\n");
1888 haveActions = False;
1889 for (i = width = nGroups = 0; i < XkbNumKbdGroups; i++)
1891 if (((i + 1) > nGroups)
1892 && (((key->symsDefined | key->actsDefined) & (1 << i))
1893 || (key->typesDefined) & (1 << i)))
1898 /* Assign the type to the key, if it is missing. */
1899 if (key->types[i] == None)
1901 if (key->dfltType != None)
1902 key->types[i] = key->dfltType;
1903 else if (FindAutomaticType(key->numLevels[i], key->syms[i],
1904 &key->types[i], &autoType))
1909 if (warningLevel >= 5)
1911 WARN("No automatic type for %d symbols\n",
1912 (unsigned int) key->numLevels[i]);
1913 ACTION("Using %s for the %s key (keycode %d)\n",
1914 XkbcAtomText(key->types[i]),
1915 longText(key->name), kc);
1919 if (FindNamedType(xkb, key->types[i], &types[i]))
1921 if (!autoType || key->numLevels[i] > 2)
1922 xkb->server->explicit[kc] |= (1 << i);
1926 if (warningLevel >= 3)
1928 WARN("Type \"%s\" is not defined\n",
1929 XkbcAtomText(key->types[i]));
1930 ACTION("Using TWO_LEVEL for the %s key (keycode %d)\n",
1931 longText(key->name), kc);
1933 types[i] = XkbTwoLevelIndex;
1935 /* if the type specifies less syms than the key has, shrink the key */
1936 type = &xkb->map->types[types[i]];
1937 if (type->num_levels < key->numLevels[i])
1939 if (warningLevel > 0)
1942 ("Type \"%s\" has %d levels, but %s has %d symbols\n",
1943 XkbcAtomText(type->name),
1944 (unsigned int) type->num_levels,
1945 longText(key->name),
1946 (unsigned int) key->numLevels[i]);
1947 ACTION("Ignoring extra symbols\n");
1949 key->numLevels[i] = type->num_levels;
1951 if (key->numLevels[i] > width)
1952 width = key->numLevels[i];
1953 if (type->num_levels > width)
1954 width = type->num_levels;
1957 /* width is now the largest width found */
1959 i = width * nGroups;
1960 outSyms = XkbcResizeKeySyms(xkb, kc, i);
1961 if (outSyms == NULL)
1963 WSGO("Could not enlarge symbols for %s (keycode %d)\n",
1964 longText(key->name), kc);
1969 outActs = XkbcResizeKeyActions(xkb, kc, i);
1970 if (outActs == NULL)
1972 WSGO("Could not enlarge actions for %s (key %d)\n",
1973 longText(key->name), kc);
1976 xkb->server->explicit[kc] |= XkbExplicitInterpretMask;
1980 if (key->defs.defined & _Key_GroupInfo)
1983 i = xkb->map->key_sym_map[kc].group_info;
1985 xkb->map->key_sym_map[kc].group_info = XkbSetNumGroups(i, nGroups);
1986 xkb->map->key_sym_map[kc].width = width;
1987 for (i = 0; i < nGroups; i++)
1989 /* assign kt_index[i] to the index of the type in map->types.
1990 * kt_index[i] may have been set by a previous run (if we have two
1991 * layouts specified). Let's not overwrite it with the ONE_LEVEL
1992 * default group if we dont even have keys for this group anyway.
1994 * FIXME: There should be a better fix for this.
1996 if (key->numLevels[i])
1997 xkb->map->key_sym_map[kc].kt_index[i] = types[i];
1998 if (key->syms[i] != NULL)
2000 /* fill key to "width" symbols*/
2001 for (tmp = 0; tmp < width; tmp++)
2003 if (tmp < key->numLevels[i])
2004 outSyms[tmp] = key->syms[i][tmp];
2006 outSyms[tmp] = NoSymbol;
2007 if ((outActs != NULL) && (key->acts[i] != NULL))
2009 if (tmp < key->numLevels[i])
2010 outActs[tmp] = key->acts[i][tmp];
2012 outActs[tmp].type = XkbSA_NoAction;
2020 switch (key->behavior.type & XkbKB_OpMask)
2024 case XkbKB_Overlay1:
2025 case XkbKB_Overlay2:
2026 /* find key by name! */
2027 if (!FindNamedKey(xkb, key->nameForOverlayKey, &okc, True,
2028 CreateKeyNames(xkb), 0))
2030 if (warningLevel >= 1)
2032 WARN("Key %s not found in %s keycodes\n",
2033 longText(key->nameForOverlayKey),
2034 XkbcAtomText(xkb->names->keycodes));
2035 ACTION("Not treating %s as an overlay key \n",
2036 longText(key->name));
2040 key->behavior.data = okc;
2042 xkb->server->behaviors[kc] = key->behavior;
2043 xkb->server->explicit[kc] |= XkbExplicitBehaviorMask;
2046 if (key->defs.defined & _Key_VModMap)
2048 xkb->server->vmodmap[kc] = key->vmodmap;
2049 xkb->server->explicit[kc] |= XkbExplicitVModMapMask;
2051 if (key->repeat != RepeatUndefined)
2053 if (key->repeat == RepeatYes)
2054 xkb->ctrls->per_key_repeat[kc / 8] |= (1 << (kc % 8));
2056 xkb->ctrls->per_key_repeat[kc / 8] &= ~(1 << (kc % 8));
2057 xkb->server->explicit[kc] |= XkbExplicitAutoRepeatMask;
2060 if (nGroups > xkb->ctrls->num_groups)
2061 xkb->ctrls->num_groups = nGroups;
2063 /* do the same thing for the next key */
2064 CopySymbolsDef(xkb, key, kc + 1);
2069 CopyModMapDef(struct xkb_desc * xkb, ModMapEntry *entry)
2073 if ((!entry->haveSymbol)
2076 (xkb, entry->u.keyName, &kc, True, CreateKeyNames(xkb), 0)))
2078 if (warningLevel >= 5)
2080 WARN("Key %s not found in %s keycodes\n",
2081 longText(entry->u.keyName),
2082 XkbcAtomText(xkb->names->keycodes));
2083 ACTION("Modifier map entry for %s not updated\n",
2084 XkbcModIndexText(entry->modifier));
2088 else if (entry->haveSymbol
2089 && (!FindKeyForSymbol(xkb, entry->u.keySym, &kc)))
2091 if (warningLevel > 5)
2093 WARN("Key \"%s\" not found in %s symbol map\n",
2094 XkbcKeysymText(entry->u.keySym),
2095 XkbcAtomText(xkb->names->symbols));
2096 ACTION("Modifier map entry for %s not updated\n",
2097 XkbcModIndexText(entry->modifier));
2101 xkb->map->modmap[kc] |= (1 << entry->modifier);
2106 * Handle the xkb_symbols section of an xkb file.
2108 * @param file The parsed xkb_symbols section of the xkb file.
2109 * @param xkb Handle to the keyboard description to store the symbols in.
2110 * @param merge Merge strategy (e.g. MergeOverride).
2113 CompileSymbols(XkbFile *file, struct xkb_desc * xkb, unsigned merge)
2118 InitSymbolsInfo(&info, xkb);
2119 info.dflt.defs.fileID = file->id;
2120 info.dflt.defs.merge = merge;
2121 HandleSymbolsFile(file, xkb, merge, &info);
2123 if (info.nKeys == 0) {
2124 FreeSymbolsInfo(&info);
2128 if (info.errorCount == 0)
2132 /* alloc memory in the xkb struct */
2133 if (XkbcAllocNames(xkb, XkbSymbolsNameMask | XkbGroupNamesMask, 0, 0)
2136 WSGO("Can not allocate names in CompileSymbols\n");
2137 ACTION("Symbols not added\n");
2140 if (XkbcAllocClientMap(xkb, XkbKeySymsMask | XkbModifierMapMask, 0)
2143 WSGO("Could not allocate client map in CompileSymbols\n");
2144 ACTION("Symbols not added\n");
2147 if (XkbcAllocServerMap(xkb, XkbAllServerInfoMask, 32) != Success)
2149 WSGO("Could not allocate server map in CompileSymbols\n");
2150 ACTION("Symbols not added\n");
2153 if (XkbcAllocControls(xkb, XkbPerKeyRepeatMask) != Success)
2155 WSGO("Could not allocate controls in CompileSymbols\n");
2156 ACTION("Symbols not added\n");
2160 /* now copy info into xkb. */
2161 xkb->names->symbols = xkb_intern_atom(info.name);
2163 ApplyAliases(xkb, False, &info.aliases);
2164 for (i = 0; i < XkbNumKbdGroups; i++)
2166 if (info.groupNames[i] != None)
2167 xkb->names->groups[i] = info.groupNames[i];
2170 for (key = info.keys, i = 0; i < info.nKeys; i++, key++)
2175 for (key = info.keys, i = 0; i < info.nKeys; i++, key++)
2177 if (!CopySymbolsDef(xkb, key, 0))
2180 if (warningLevel > 3)
2182 for (i = xkb->min_key_code; i <= xkb->max_key_code; i++)
2184 if (xkb->names->keys[i].name[0] == '\0')
2186 if (XkbKeyNumGroups(xkb, i) < 1)
2189 memcpy(buf, xkb->names->keys[i].name, 4);
2192 ("No symbols defined for <%s> (keycode %d)\n",
2199 ModMapEntry *mm, *next;
2200 for (mm = info.modMap; mm != NULL; mm = next)
2202 if (!CopyModMapDef(xkb, mm))
2204 next = (ModMapEntry *) mm->defs.next;
2207 FreeSymbolsInfo(&info);
2211 FreeSymbolsInfo(&info);