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;
115 * Free memory associated with this key info and reset to sane values.
118 FreeKeyInfo(KeyInfo * info)
122 info->defs.defined = 0;
123 info->defs.fileID = 0;
124 info->defs.merge = MergeOverride;
125 info->defs.next = NULL;
127 info->typesDefined = info->symsDefined = info->actsDefined = 0;
128 for (i = 0; i < XkbNumKbdGroups; i++)
130 info->numLevels[i] = 0;
131 info->types[i] = None;
133 info->syms[i] = NULL;
135 info->acts[i] = NULL;
137 info->dfltType = None;
138 info->behavior.type = XkbKB_Default;
139 info->behavior.data = 0;
141 info->nameForOverlayKey = 0;
142 info->repeat = RepeatUndefined;
147 * Copy old into new, optionally reset old to 0.
148 * If old is reset, new simply re-uses old's memory. Otherwise, the memory is
149 * newly allocated and new points to the new memory areas.
152 CopyKeyInfo(KeyInfo * old, KeyInfo * new, Bool clearOld)
157 new->defs.next = NULL;
160 for (i = 0; i < XkbNumKbdGroups; i++)
162 old->numLevels[i] = 0;
170 for (i = 0; i < XkbNumKbdGroups; i++)
172 width = new->numLevels[i];
173 if (old->syms[i] != NULL)
175 new->syms[i] = uTypedCalloc(width, uint32_t);
179 new->numLevels[i] = 0;
182 memcpy(new->syms[i], old->syms[i], width * sizeof(uint32_t));
184 if (old->acts[i] != NULL)
186 new->acts[i] = uTypedCalloc(width, union xkb_action);
192 memcpy(new->acts[i], old->acts[i],
193 width * sizeof(union xkb_action));
200 /***====================================================================***/
202 typedef struct _ModMapEntry
209 unsigned long keyName;
214 #define SYMBOLS_INIT_SIZE 110
215 #define SYMBOLS_CHUNK 20
216 typedef struct _SymbolsInfo
218 char *name; /* e.g. pc+us+inet(evdev) */
222 unsigned explicit_group;
230 uint32_t groupNames[XkbNumKbdGroups];
237 InitSymbolsInfo(SymbolsInfo * info, struct xkb_desc * xkb)
241 tok_ONE_LEVEL = xkb_intern_atom("ONE_LEVEL");
242 tok_TWO_LEVEL = xkb_intern_atom("TWO_LEVEL");
243 tok_KEYPAD = xkb_intern_atom("KEYPAD");
245 info->explicit_group = 0;
246 info->errorCount = 0;
248 info->merge = MergeOverride;
250 info->szKeys = SYMBOLS_INIT_SIZE;
252 info->keys = uTypedCalloc(SYMBOLS_INIT_SIZE, KeyInfo);
254 for (i = 0; i < XkbNumKbdGroups; i++)
255 info->groupNames[i] = None;
256 InitKeyInfo(&info->dflt);
257 InitVModInfo(&info->vmods, xkb);
259 info->aliases = NULL;
263 FreeSymbolsInfo(SymbolsInfo * info)
270 for (i = 0; i < info->nKeys; i++)
271 FreeKeyInfo(&info->keys[i]);
275 ClearCommonInfo(&info->modMap->defs);
277 ClearAliases(&info->aliases);
278 memset(info, 0, sizeof(SymbolsInfo));
282 ResizeKeyGroup(KeyInfo * key,
283 unsigned group, unsigned atLeastSize, Bool forceActions)
288 tooSmall = (key->numLevels[group] < atLeastSize);
290 newWidth = atLeastSize;
292 newWidth = key->numLevels[group];
294 if ((key->syms[group] == NULL) || tooSmall)
296 key->syms[group] = uTypedRecalloc(key->syms[group],
297 key->numLevels[group], newWidth,
299 if (!key->syms[group])
302 if (((forceActions) && (tooSmall || (key->acts[group] == NULL))) ||
303 (tooSmall && (key->acts[group] != NULL)))
305 key->acts[group] = uTypedRecalloc(key->acts[group],
306 key->numLevels[group], newWidth,
308 if (!key->acts[group])
311 key->numLevels[group] = newWidth;
316 MergeKeyGroups(SymbolsInfo * info,
317 KeyInfo * into, KeyInfo * from, unsigned group)
319 uint32_t *resultSyms;
320 union xkb_action *resultActs;
323 Bool report, clobber;
325 clobber = (from->defs.merge != MergeAugment);
326 report = (warningLevel > 9) ||
327 ((into->defs.fileID == from->defs.fileID) && (warningLevel > 0));
328 if (into->numLevels[group] >= from->numLevels[group])
330 resultSyms = into->syms[group];
331 resultActs = into->acts[group];
332 resultWidth = into->numLevels[group];
336 resultSyms = from->syms[group];
337 resultActs = from->acts[group];
338 resultWidth = from->numLevels[group];
340 if (resultSyms == NULL)
342 resultSyms = uTypedCalloc(resultWidth, uint32_t);
345 WSGO("Could not allocate symbols for group merge\n");
346 ACTION("Group %d of key %s not merged\n", group,
347 longText(into->name));
351 if ((resultActs == NULL) && (into->acts[group] || from->acts[group]))
353 resultActs = uTypedCalloc(resultWidth, union xkb_action);
356 WSGO("Could not allocate actions for group merge\n");
357 ACTION("Group %d of key %s not merged\n", group,
358 longText(into->name));
362 for (i = 0; i < resultWidth; i++)
364 uint32_t fromSym, toSym;
365 if (from->syms[group] && (i < from->numLevels[group]))
366 fromSym = from->syms[group][i];
369 if (into->syms[group] && (i < into->numLevels[group]))
370 toSym = into->syms[group][i];
373 if ((fromSym == NoSymbol) || (fromSym == toSym))
374 resultSyms[i] = toSym;
375 else if (toSym == NoSymbol)
376 resultSyms[i] = fromSym;
379 uint32_t use, ignore;
393 ("Multiple symbols for level %d/group %d on key %s\n",
394 i + 1, group + 1, longText(into->name));
395 ACTION("Using %s, ignoring %s\n",
396 XkbcKeysymText(use), XkbcKeysymText(ignore));
400 if (resultActs != NULL)
402 union xkb_action *fromAct, *toAct;
403 fromAct = (from->acts[group] ? &from->acts[group][i] : NULL);
404 toAct = (into->acts[group] ? &into->acts[group][i] : NULL);
405 if (((fromAct == NULL) || (fromAct->type == XkbSA_NoAction))
408 resultActs[i] = *toAct;
410 else if (((toAct == NULL) || (toAct->type == XkbSA_NoAction))
411 && (fromAct != NULL))
413 resultActs[i] = *fromAct;
417 union xkb_action *use, *ignore;
431 ("Multiple actions for level %d/group %d on key %s\n",
432 i + 1, group + 1, longText(into->name));
433 ACTION("Using %s, ignoring %s\n",
434 XkbcActionTypeText(use->type),
435 XkbcActionTypeText(ignore->type));
438 resultActs[i] = *use;
442 if (resultSyms != into->syms[group])
443 free(into->syms[group]);
444 if (resultSyms != from->syms[group])
445 free(from->syms[group]);
446 if (resultActs != into->acts[group])
447 free(into->acts[group]);
448 if (resultActs != from->acts[group])
449 free(from->acts[group]);
450 into->numLevels[group] = resultWidth;
451 into->syms[group] = resultSyms;
452 from->syms[group] = NULL;
453 into->acts[group] = resultActs;
454 from->acts[group] = NULL;
455 into->symsDefined |= (1 << group);
456 from->symsDefined &= ~(1 << group);
457 into->actsDefined |= (1 << group);
458 from->actsDefined &= ~(1 << group);
463 MergeKeys(SymbolsInfo * info, KeyInfo * into, KeyInfo * from)
466 unsigned collide = 0;
469 if (from->defs.merge == MergeReplace)
471 for (i = 0; i < XkbNumKbdGroups; i++)
473 if (into->numLevels[i] != 0)
480 memset(from, 0, sizeof(KeyInfo));
483 report = ((warningLevel > 9) ||
484 ((into->defs.fileID == from->defs.fileID)
485 && (warningLevel > 0)));
486 for (i = 0; i < XkbNumKbdGroups; i++)
488 if (from->numLevels[i] > 0)
490 if (into->numLevels[i] == 0)
492 into->numLevels[i] = from->numLevels[i];
493 into->syms[i] = from->syms[i];
494 into->acts[i] = from->acts[i];
495 into->symsDefined |= (1 << i);
496 from->syms[i] = NULL;
497 from->acts[i] = NULL;
498 from->numLevels[i] = 0;
499 from->symsDefined &= ~(1 << i);
501 into->defs.defined |= _Key_Syms;
503 into->defs.defined |= _Key_Acts;
510 collide |= _Key_Syms;
512 collide |= _Key_Acts;
514 MergeKeyGroups(info, into, from, (unsigned) i);
517 if (from->types[i] != None)
519 if ((into->types[i] != None) && (report) &&
520 (into->types[i] != from->types[i]))
522 uint32_t use, ignore;
523 collide |= _Key_Types;
524 if (from->defs.merge != MergeAugment)
526 use = from->types[i];
527 ignore = into->types[i];
531 use = into->types[i];
532 ignore = from->types[i];
535 ("Multiple definitions for group %d type of key %s\n",
536 i, longText(into->name));
537 ACTION("Using %s, ignoring %s\n",
539 XkbcAtomText(ignore));
541 if ((from->defs.merge != MergeAugment)
542 || (into->types[i] == None))
544 into->types[i] = from->types[i];
548 if (UseNewField(_Key_Behavior, &into->defs, &from->defs, &collide))
550 into->behavior = from->behavior;
551 into->nameForOverlayKey = from->nameForOverlayKey;
552 into->defs.defined |= _Key_Behavior;
554 if (UseNewField(_Key_VModMap, &into->defs, &from->defs, &collide))
556 into->vmodmap = from->vmodmap;
557 into->defs.defined |= _Key_VModMap;
559 if (UseNewField(_Key_Repeat, &into->defs, &from->defs, &collide))
561 into->repeat = from->repeat;
562 into->defs.defined |= _Key_Repeat;
564 if (UseNewField(_Key_Type_Dflt, &into->defs, &from->defs, &collide))
566 into->dfltType = from->dfltType;
567 into->defs.defined |= _Key_Type_Dflt;
569 if (UseNewField(_Key_GroupInfo, &into->defs, &from->defs, &collide))
571 into->groupInfo = from->groupInfo;
572 into->defs.defined |= _Key_GroupInfo;
576 WARN("Symbol map for key %s redefined\n",
577 longText(into->name));
578 ACTION("Using %s definition for conflicting fields\n",
579 (from->defs.merge == MergeAugment ? "first" : "last"));
585 AddKeySymbols(SymbolsInfo * info, KeyInfo * key, struct xkb_desc * xkb)
588 unsigned long real_name;
590 for (i = 0; i < info->nKeys; i++)
592 if (info->keys[i].name == key->name)
593 return MergeKeys(info, &info->keys[i], key);
595 if (FindKeyNameForAlias(xkb, key->name, &real_name))
597 for (i = 0; i < info->nKeys; i++)
599 if (info->keys[i].name == real_name)
600 return MergeKeys(info, &info->keys[i], key);
603 if (info->nKeys >= info->szKeys)
605 info->szKeys += SYMBOLS_CHUNK;
607 uTypedRecalloc(info->keys, info->nKeys, info->szKeys, KeyInfo);
610 WSGO("Could not allocate key symbols descriptions\n");
611 ACTION("Some key symbols definitions may be lost\n");
615 return CopyKeyInfo(key, &info->keys[info->nKeys++], True);
619 AddModMapEntry(SymbolsInfo * info, ModMapEntry * new)
624 clobber = (new->defs.merge != MergeAugment);
625 for (mm = info->modMap; mm != NULL; mm = (ModMapEntry *) mm->defs.next)
627 if (new->haveSymbol && mm->haveSymbol
628 && (new->u.keySym == mm->u.keySym))
630 unsigned use, ignore;
631 if (mm->modifier != new->modifier)
636 ignore = mm->modifier;
641 ignore = new->modifier;
644 ("%s added to symbol map for multiple modifiers\n",
645 XkbcKeysymText(new->u.keySym));
646 ACTION("Using %s, ignoring %s.\n",
647 XkbcModIndexText(use),
648 XkbcModIndexText(ignore));
653 if ((!new->haveSymbol) && (!mm->haveSymbol) &&
654 (new->u.keyName == mm->u.keyName))
656 unsigned use, ignore;
657 if (mm->modifier != new->modifier)
662 ignore = mm->modifier;
667 ignore = new->modifier;
669 ERROR("Key %s added to map for multiple modifiers\n",
670 longText(new->u.keyName));
671 ACTION("Using %s, ignoring %s.\n",
672 XkbcModIndexText(use),
673 XkbcModIndexText(ignore));
679 mm = uTypedAlloc(ModMapEntry);
682 WSGO("Could not allocate modifier map entry\n");
683 ACTION("Modifier map for %s will be incomplete\n",
684 XkbcModIndexText(new->modifier));
688 mm->defs.next = &info->modMap->defs;
693 /***====================================================================***/
696 MergeIncludedSymbols(SymbolsInfo * into, SymbolsInfo * from,
697 unsigned merge, struct xkb_desc * xkb)
702 if (from->errorCount > 0)
704 into->errorCount += from->errorCount;
707 if (into->name == NULL)
709 into->name = from->name;
712 for (i = 0; i < XkbNumKbdGroups; i++)
714 if (from->groupNames[i] != None)
716 if ((merge != MergeAugment) || (into->groupNames[i] == None))
717 into->groupNames[i] = from->groupNames[i];
720 for (i = 0, key = from->keys; i < from->nKeys; i++, key++)
722 if (merge != MergeDefault)
723 key->defs.merge = merge;
724 if (!AddKeySymbols(into, key, xkb))
727 if (from->modMap != NULL)
729 ModMapEntry *mm, *next;
730 for (mm = from->modMap; mm != NULL; mm = next)
732 if (merge != MergeDefault)
733 mm->defs.merge = merge;
734 if (!AddModMapEntry(into, mm))
736 next = (ModMapEntry *) mm->defs.next;
741 if (!MergeAliases(&into->aliases, &from->aliases, merge))
745 typedef void (*FileHandler) (XkbFile * /* rtrn */ ,
746 struct xkb_desc * /* xkb */ ,
747 unsigned /* merge */ ,
748 SymbolsInfo * /* included */
752 HandleIncludeSymbols(IncludeStmt * stmt,
753 struct xkb_desc * xkb, SymbolsInfo * info, FileHandler hndlr)
757 SymbolsInfo included;
761 if ((stmt->file == NULL) && (stmt->map == NULL))
765 memset(info, 0, sizeof(SymbolsInfo));
767 else if (ProcessIncludeFile(stmt, XkmSymbolsIndex, &rtrn, &newMerge))
769 InitSymbolsInfo(&included, xkb);
770 included.fileID = included.dflt.defs.fileID = rtrn->id;
771 included.merge = included.dflt.defs.merge = MergeOverride;
774 included.explicit_group = atoi(stmt->modifier) - 1;
778 included.explicit_group = info->explicit_group;
780 (*hndlr) (rtrn, xkb, MergeOverride, &included);
781 if (stmt->stmt != NULL)
784 included.name = stmt->stmt;
790 info->errorCount += 10;
793 if ((stmt->next != NULL) && (included.errorCount < 1))
797 SymbolsInfo next_incl;
799 for (next = stmt->next; next != NULL; next = next->next)
801 if ((next->file == NULL) && (next->map == NULL))
804 MergeIncludedSymbols(&included, info, next->merge, xkb);
805 FreeSymbolsInfo(info);
807 else if (ProcessIncludeFile(next, XkmSymbolsIndex, &rtrn, &op))
809 InitSymbolsInfo(&next_incl, xkb);
810 next_incl.fileID = next_incl.dflt.defs.fileID = rtrn->id;
811 next_incl.merge = next_incl.dflt.defs.merge = MergeOverride;
814 next_incl.explicit_group = atoi(next->modifier) - 1;
818 next_incl.explicit_group = info->explicit_group;
820 (*hndlr) (rtrn, xkb, MergeOverride, &next_incl);
821 MergeIncludedSymbols(&included, &next_incl, op, xkb);
822 FreeSymbolsInfo(&next_incl);
826 info->errorCount += 10;
835 MergeIncludedSymbols(info, &included, newMerge, xkb);
836 FreeSymbolsInfo(&included);
838 return (info->errorCount == 0);
845 GetGroupIndex(KeyInfo * key,
846 ExprDef * arrayNdx, unsigned what, unsigned *ndx_rtrn)
856 if (arrayNdx == NULL)
861 defined = key->symsDefined;
863 defined = key->actsDefined;
865 for (i = 0; i < XkbNumKbdGroups; i++)
867 if ((defined & (1 << i)) == 0)
873 ERROR("Too many groups of %s for key %s (max %d)\n", name,
874 longText(key->name), XkbNumKbdGroups + 1);
875 ACTION("Ignoring %s defined for extra groups\n", name);
878 if (!ExprResolveGroup(arrayNdx, &tmp))
880 ERROR("Illegal group index for %s of key %s\n", name,
881 longText(key->name));
882 ACTION("Definition with non-integer array index ignored\n");
885 *ndx_rtrn = tmp.uval - 1;
890 AddSymbolsToKey(KeyInfo * key,
891 struct xkb_desc * xkb,
893 ExprDef * arrayNdx, ExprDef * value, SymbolsInfo * info)
898 if (!GetGroupIndex(key, arrayNdx, SYMBOLS, &ndx))
902 key->symsDefined |= (1 << ndx);
905 if (value->op != ExprKeysymList)
907 ERROR("Expected a list of symbols, found %s\n",
908 exprOpText(value->op));
909 ACTION("Ignoring symbols for group %d of %s\n", ndx,
910 longText(key->name));
913 if (key->syms[ndx] != NULL)
915 WSGO("Symbols for key %s, group %d already defined\n",
916 longText(key->name), ndx);
919 nSyms = value->value.list.nSyms;
920 if (((key->numLevels[ndx] < nSyms) || (key->syms[ndx] == NULL)) &&
921 (!ResizeKeyGroup(key, ndx, nSyms, False)))
923 WSGO("Could not resize group %d of key %s\n", ndx,
924 longText(key->name));
925 ACTION("Symbols lost\n");
928 key->symsDefined |= (1 << ndx);
929 for (i = 0; i < nSyms; i++) {
930 if (!LookupKeysym(value->value.list.syms[i], &key->syms[ndx][i])) {
931 WSGO("Could not resolve keysym %s\n", value->value.list.syms[i]);
932 key->syms[ndx][i] = NoSymbol;
935 for (i = key->numLevels[ndx] - 1;
936 (i >= 0) && (key->syms[ndx][i] == NoSymbol); i--)
938 key->numLevels[ndx]--;
944 AddActionsToKey(KeyInfo * key,
945 struct xkb_desc * xkb,
947 ExprDef * arrayNdx, ExprDef * value, SymbolsInfo * info)
952 struct xkb_any_action *toAct;
954 if (!GetGroupIndex(key, arrayNdx, ACTIONS, &ndx))
959 key->actsDefined |= (1 << ndx);
962 if (value->op != ExprActionList)
964 WSGO("Bad expression type (%d) for action list value\n", value->op);
965 ACTION("Ignoring actions for group %d of %s\n", ndx,
966 longText(key->name));
969 if (key->acts[ndx] != NULL)
971 WSGO("Actions for key %s, group %d already defined\n",
972 longText(key->name), ndx);
975 for (nActs = 0, act = value->value.child; act != NULL; nActs++)
977 act = (ExprDef *) act->common.next;
981 WSGO("Action list but not actions in AddActionsToKey\n");
984 if (((key->numLevels[ndx] < nActs) || (key->acts[ndx] == NULL)) &&
985 (!ResizeKeyGroup(key, ndx, nActs, True)))
987 WSGO("Could not resize group %d of key %s\n", ndx,
988 longText(key->name));
989 ACTION("Actions lost\n");
992 key->actsDefined |= (1 << ndx);
994 toAct = (struct xkb_any_action *) key->acts[ndx];
995 act = value->value.child;
996 for (i = 0; i < nActs; i++, toAct++)
998 if (!HandleActionDef(act, xkb, toAct, MergeOverride, info->action))
1000 ERROR("Illegal action definition for %s\n",
1001 longText(key->name));
1002 ACTION("Action for group %d/level %d ignored\n", ndx + 1, i + 1);
1004 act = (ExprDef *) act->common.next;
1010 SetAllowNone(KeyInfo * key, ExprDef * arrayNdx, ExprDef * value)
1013 unsigned radio_groups = 0;
1015 if (arrayNdx == NULL)
1017 radio_groups = XkbAllRadioGroupsMask;
1021 if (!ExprResolveRadioGroup(arrayNdx, &tmp))
1023 ERROR("Illegal index in group name definition\n");
1024 ACTION("Definition with non-integer array index ignored\n");
1027 if ((tmp.uval < 1) || (tmp.uval > XkbMaxRadioGroups))
1029 ERROR("Illegal radio group specified (must be 1..%d)\n",
1030 XkbMaxRadioGroups + 1);
1031 ACTION("Value of \"allow none\" for group %d ignored\n",
1035 radio_groups |= (1 << (tmp.uval - 1));
1037 if (!ExprResolveBoolean(value, &tmp))
1039 ERROR("Illegal \"allow none\" value for %s\n",
1040 longText(key->name));
1041 ACTION("Non-boolean value ignored\n");
1045 key->allowNone |= radio_groups;
1047 key->allowNone &= ~radio_groups;
1052 static const LookupEntry lockingEntries[] = {
1053 {"true", XkbKB_Lock},
1054 {"yes", XkbKB_Lock},
1056 {"false", XkbKB_Default},
1057 {"no", XkbKB_Default},
1058 {"off", XkbKB_Default},
1059 {"permanent", XkbKB_Lock | XkbKB_Permanent},
1063 static const LookupEntry repeatEntries[] = {
1064 {"true", RepeatYes},
1067 {"false", RepeatNo},
1070 {"default", RepeatUndefined},
1075 SetSymbolsField(KeyInfo * key,
1076 struct xkb_desc * xkb,
1078 ExprDef * arrayNdx, ExprDef * value, SymbolsInfo * info)
1083 if (uStrCaseCmp(field, "type") == 0)
1086 if ((!ExprResolveString(value, &tmp))
1087 && (warningLevel > 0))
1089 WARN("The type field of a key symbol map must be a string\n");
1090 ACTION("Ignoring illegal type definition\n");
1092 if (arrayNdx == NULL)
1094 key->dfltType = xkb_intern_atom(tmp.str);
1095 key->defs.defined |= _Key_Type_Dflt;
1097 else if (!ExprResolveGroup(arrayNdx, &ndx))
1099 ERROR("Illegal group index for type of key %s\n",
1100 longText(key->name));
1101 ACTION("Definition with non-integer array index ignored\n");
1107 key->types[ndx.uval - 1] = xkb_intern_atom(tmp.str);
1108 key->typesDefined |= (1 << (ndx.uval - 1));
1112 else if (uStrCaseCmp(field, "symbols") == 0)
1113 return AddSymbolsToKey(key, xkb, field, arrayNdx, value, info);
1114 else if (uStrCaseCmp(field, "actions") == 0)
1115 return AddActionsToKey(key, xkb, field, arrayNdx, value, info);
1116 else if ((uStrCaseCmp(field, "vmods") == 0) ||
1117 (uStrCaseCmp(field, "virtualmods") == 0) ||
1118 (uStrCaseCmp(field, "virtualmodifiers") == 0))
1120 ok = ExprResolveVModMask(value, &tmp, xkb);
1123 key->vmodmap = (tmp.uval >> 8);
1124 key->defs.defined |= _Key_VModMap;
1128 ERROR("Expected a virtual modifier mask, found %s\n",
1129 exprOpText(value->op));
1130 ACTION("Ignoring virtual modifiers definition for key %s\n",
1131 longText(key->name));
1134 else if ((uStrCaseCmp(field, "locking") == 0)
1135 || (uStrCaseCmp(field, "lock") == 0)
1136 || (uStrCaseCmp(field, "locks") == 0))
1138 ok = ExprResolveEnum(value, &tmp, lockingEntries);
1140 key->behavior.type = tmp.uval;
1141 key->defs.defined |= _Key_Behavior;
1143 else if ((uStrCaseCmp(field, "radiogroup") == 0) ||
1144 (uStrCaseCmp(field, "permanentradiogroup") == 0))
1146 Bool permanent = False;
1147 if (uStrCaseCmp(field, "permanentradiogroup") == 0)
1149 if (ExprResolveString(value, &tmp)) {
1150 ok = (strcmp(tmp.str, "none") == 0);
1156 ok = ExprResolveInteger(value, &tmp);
1160 ERROR("Illegal radio group specification for %s\n",
1161 longText(key->name));
1162 ACTION("Non-integer radio group ignored\n");
1167 key->behavior.type = XkbKB_Default;
1168 key->behavior.data = 0;
1171 if ((tmp.uval < 1) || (tmp.uval > XkbMaxRadioGroups))
1174 ("Radio group specification for %s out of range (1..32)\n",
1175 longText(key->name));
1176 ACTION("Illegal radio group %d ignored\n", tmp.uval);
1179 key->behavior.type =
1180 XkbKB_RadioGroup | (permanent ? XkbKB_Permanent : 0);
1181 key->behavior.data = tmp.uval - 1;
1182 if (key->allowNone & (1 << (tmp.uval - 1)))
1183 key->behavior.data |= XkbKB_RGAllowNone;
1184 key->defs.defined |= _Key_Behavior;
1186 else if (uStrCaseEqual(field, "allownone"))
1188 ok = SetAllowNone(key, arrayNdx, value);
1190 else if (uStrCasePrefix("overlay", field) ||
1191 uStrCasePrefix("permanentoverlay", field))
1193 Bool permanent = False;
1196 if (uStrCasePrefix("permanent", field))
1199 which = &field[sizeof("permanentoverlay") - 1];
1203 which = &field[sizeof("overlay") - 1];
1205 if (sscanf(which, "%d", &overlayNdx) == 1)
1207 if (((overlayNdx < 1) || (overlayNdx > 2)) && (warningLevel > 0))
1209 ERROR("Illegal overlay %d specified for %s\n",
1210 overlayNdx, longText(key->name));
1211 ACTION("Ignored\n");
1215 else if (*which == '\0')
1217 else if (warningLevel > 0)
1219 ERROR("Illegal overlay \"%s\" specified for %s\n",
1220 which, longText(key->name));
1221 ACTION("Ignored\n");
1224 ok = ExprResolveKeyName(value, &tmp);
1227 ERROR("Illegal overlay key specification for %s\n",
1228 longText(key->name));
1229 ACTION("Overlay key must be specified by name\n");
1232 if (overlayNdx == 1)
1233 key->behavior.type = XkbKB_Overlay1;
1235 key->behavior.type = XkbKB_Overlay2;
1237 key->behavior.type |= XkbKB_Permanent;
1239 key->behavior.data = 0;
1240 key->nameForOverlayKey = KeyNameToLong(tmp.keyName.name);
1241 key->defs.defined |= _Key_Behavior;
1243 else if ((uStrCaseCmp(field, "repeating") == 0) ||
1244 (uStrCaseCmp(field, "repeats") == 0) ||
1245 (uStrCaseCmp(field, "repeat") == 0))
1247 ok = ExprResolveEnum(value, &tmp, repeatEntries);
1250 ERROR("Illegal repeat setting for %s\n",
1251 longText(key->name));
1252 ACTION("Non-boolean repeat setting ignored\n");
1255 key->repeat = tmp.uval;
1256 key->defs.defined |= _Key_Repeat;
1258 else if ((uStrCaseCmp(field, "groupswrap") == 0) ||
1259 (uStrCaseCmp(field, "wrapgroups") == 0))
1261 ok = ExprResolveBoolean(value, &tmp);
1264 ERROR("Illegal groupsWrap setting for %s\n",
1265 longText(key->name));
1266 ACTION("Non-boolean value ignored\n");
1270 key->groupInfo = XkbWrapIntoRange;
1272 key->groupInfo = XkbClampIntoRange;
1273 key->defs.defined |= _Key_GroupInfo;
1275 else if ((uStrCaseCmp(field, "groupsclamp") == 0) ||
1276 (uStrCaseCmp(field, "clampgroups") == 0))
1278 ok = ExprResolveBoolean(value, &tmp);
1281 ERROR("Illegal groupsClamp setting for %s\n",
1282 longText(key->name));
1283 ACTION("Non-boolean value ignored\n");
1287 key->groupInfo = XkbClampIntoRange;
1289 key->groupInfo = XkbWrapIntoRange;
1290 key->defs.defined |= _Key_GroupInfo;
1292 else if ((uStrCaseCmp(field, "groupsredirect") == 0) ||
1293 (uStrCaseCmp(field, "redirectgroups") == 0))
1295 if (!ExprResolveGroup(value, &tmp))
1297 ERROR("Illegal group index for redirect of key %s\n",
1298 longText(key->name));
1299 ACTION("Definition with non-integer group ignored\n");
1303 XkbSetGroupInfo(0, XkbRedirectIntoRange, tmp.uval - 1);
1304 key->defs.defined |= _Key_GroupInfo;
1308 ERROR("Unknown field %s in a symbol interpretation\n", field);
1309 ACTION("Definition ignored\n");
1316 SetGroupName(SymbolsInfo * info, ExprDef * arrayNdx, ExprDef * value)
1318 ExprResult tmp, name;
1320 if ((arrayNdx == NULL) && (warningLevel > 0))
1322 WARN("You must specify an index when specifying a group name\n");
1323 ACTION("Group name definition without array subscript ignored\n");
1326 if (!ExprResolveGroup(arrayNdx, &tmp))
1328 ERROR("Illegal index in group name definition\n");
1329 ACTION("Definition with non-integer array index ignored\n");
1332 if (!ExprResolveString(value, &name))
1334 ERROR("Group name must be a string\n");
1335 ACTION("Illegal name for group %d ignored\n", tmp.uval);
1338 info->groupNames[tmp.uval - 1 + info->explicit_group] =
1339 xkb_intern_atom(name.str);
1346 HandleSymbolsVar(VarDef * stmt, struct xkb_desc * xkb, SymbolsInfo * info)
1348 ExprResult elem, field, tmp;
1352 if (ExprResolveLhs(stmt->name, &elem, &field, &arrayNdx) == 0)
1353 return 0; /* internal error, already reported */
1354 if (elem.str && (uStrCaseCmp(elem.str, "key") == 0))
1356 ret = SetSymbolsField(&info->dflt, xkb, field.str, arrayNdx,
1359 else if ((elem.str == NULL) && ((uStrCaseCmp(field.str, "name") == 0) ||
1360 (uStrCaseCmp(field.str, "groupname") ==
1363 ret = SetGroupName(info, arrayNdx, stmt->value);
1365 else if ((elem.str == NULL)
1366 && ((uStrCaseCmp(field.str, "groupswrap") == 0)
1367 || (uStrCaseCmp(field.str, "wrapgroups") == 0)))
1369 if (!ExprResolveBoolean(stmt->value, &tmp))
1371 ERROR("Illegal setting for global groupsWrap\n");
1372 ACTION("Non-boolean value ignored\n");
1377 info->groupInfo = XkbWrapIntoRange;
1379 info->groupInfo = XkbClampIntoRange;
1383 else if ((elem.str == NULL)
1384 && ((uStrCaseCmp(field.str, "groupsclamp") == 0)
1385 || (uStrCaseCmp(field.str, "clampgroups") == 0)))
1387 if (!ExprResolveBoolean(stmt->value, &tmp))
1389 ERROR("Illegal setting for global groupsClamp\n");
1390 ACTION("Non-boolean value ignored\n");
1395 info->groupInfo = XkbClampIntoRange;
1397 info->groupInfo = XkbWrapIntoRange;
1401 else if ((elem.str == NULL)
1402 && ((uStrCaseCmp(field.str, "groupsredirect") == 0)
1403 || (uStrCaseCmp(field.str, "redirectgroups") == 0)))
1405 if (!ExprResolveGroup(stmt->value, &tmp))
1407 ERROR("Illegal group index for global groupsRedirect\n");
1408 ACTION("Definition with non-integer group ignored\n");
1412 info->groupInfo = XkbSetGroupInfo(0, XkbRedirectIntoRange,
1417 else if ((elem.str == NULL) && (uStrCaseCmp(field.str, "allownone") == 0))
1419 ret = SetAllowNone(&info->dflt, arrayNdx, stmt->value);
1422 ret = SetActionField(xkb, elem.str, field.str, arrayNdx, stmt->value,
1432 HandleSymbolsBody(VarDef * def,
1433 struct xkb_desc * xkb, KeyInfo * key, SymbolsInfo * info)
1436 ExprResult tmp, field;
1439 for (; def != NULL; def = (VarDef *) def->common.next)
1441 if ((def->name) && (def->name->type == ExprFieldRef))
1443 ok = HandleSymbolsVar(def, xkb, info);
1448 if (def->name == NULL)
1450 if ((def->value == NULL)
1451 || (def->value->op == ExprKeysymList))
1452 field.str = strdup("symbols");
1454 field.str = strdup("actions");
1459 ok = ExprResolveLhs(def->name, &tmp, &field, &arrayNdx);
1462 ok = SetSymbolsField(key, xkb, field.str, arrayNdx,
1471 SetExplicitGroup(SymbolsInfo * info, KeyInfo * key)
1473 unsigned group = info->explicit_group;
1478 if ((key->typesDefined | key->symsDefined | key->actsDefined) & ~1)
1481 WARN("For the map %s an explicit group specified\n", info->name);
1482 WARN("but key %s has more than one group defined\n",
1483 longText(key->name));
1484 ACTION("All groups except first one will be ignored\n");
1485 for (i = 1; i < XkbNumKbdGroups; i++)
1487 key->numLevels[i] = 0;
1489 key->syms[i] = NULL;
1491 key->acts[i] = NULL;
1495 key->typesDefined = key->symsDefined = key->actsDefined = 1 << group;
1497 key->numLevels[group] = key->numLevels[0];
1498 key->numLevels[0] = 0;
1499 key->syms[group] = key->syms[0];
1500 key->syms[0] = NULL;
1501 key->acts[group] = key->acts[0];
1502 key->acts[0] = NULL;
1503 key->types[group] = key->types[0];
1509 HandleSymbolsDef(SymbolsDef * stmt,
1510 struct xkb_desc * xkb, unsigned merge, SymbolsInfo * info)
1515 CopyKeyInfo(&info->dflt, &key, False);
1516 key.defs.merge = stmt->merge;
1517 key.name = KeyNameToLong(stmt->keyName);
1518 if (!HandleSymbolsBody((VarDef *) stmt->symbols, xkb, &key, info))
1524 if (!SetExplicitGroup(info, &key))
1530 if (!AddKeySymbols(info, &key, xkb))
1539 HandleModMapDef(ModMapDef * def,
1540 struct xkb_desc * xkb, unsigned merge, SymbolsInfo * info)
1547 if (!LookupModIndex(NULL, def->modifier, TypeInt, &rtrn))
1549 ERROR("Illegal modifier map definition\n");
1550 ACTION("Ignoring map for non-modifier \"%s\"\n",
1551 XkbcAtomText(def->modifier));
1555 tmp.modifier = rtrn.uval;
1556 for (key = def->keys; key != NULL; key = (ExprDef *) key->common.next)
1558 if ((key->op == ExprValue) && (key->type == TypeKeyName))
1560 tmp.haveSymbol = False;
1561 tmp.u.keyName = KeyNameToLong(key->value.keyName);
1563 else if (ExprResolveKeySym(key, &rtrn))
1565 tmp.haveSymbol = True;
1566 tmp.u.keySym = rtrn.uval;
1570 ERROR("Modmap entries may contain only key names or keysyms\n");
1571 ACTION("Illegal definition for %s modifier ignored\n",
1572 XkbcModIndexText(tmp.modifier));
1576 ok = AddModMapEntry(info, &tmp) && ok;
1582 HandleSymbolsFile(XkbFile * file,
1583 struct xkb_desc * xkb, unsigned merge, SymbolsInfo * info)
1587 info->name = _XkbDupString(file->name);
1591 switch (stmt->stmtType)
1594 if (!HandleIncludeSymbols((IncludeStmt *) stmt, xkb, info,
1598 case StmtSymbolsDef:
1599 if (!HandleSymbolsDef((SymbolsDef *) stmt, xkb, merge, info))
1603 if (!HandleSymbolsVar((VarDef *) stmt, xkb, info))
1607 if (!HandleVModDef((VModDef *) stmt, xkb, merge, &info->vmods))
1611 ERROR("Interpretation files may not include other types\n");
1612 ACTION("Ignoring definition of symbol interpretation\n");
1615 case StmtKeycodeDef:
1616 ERROR("Interpretation files may not include other types\n");
1617 ACTION("Ignoring definition of key name\n");
1621 if (!HandleModMapDef((ModMapDef *) stmt, xkb, merge, info))
1625 WSGO("Unexpected statement type %d in HandleSymbolsFile\n",
1630 if (info->errorCount > 10)
1633 ERROR("Too many errors\n");
1635 ACTION("Abandoning symbols file \"%s\"\n", file->topName);
1642 FindKeyForSymbol(struct xkb_desc * xkb, uint32_t sym, xkb_keycode_t *kc_rtrn)
1651 for (i = xkb->min_key_code; i <= (int) xkb->max_key_code; i++)
1653 if (j < (int) XkbKeyNumSyms(xkb, i))
1656 if (XkbKeySym(xkb, i, j) == sym)
1670 * Find the given name in the xkb->map->types and return its index.
1672 * @param name The atom to search for.
1673 * @param type_rtrn Set to the index of the name if found.
1675 * @return True if found, False otherwise.
1678 FindNamedType(struct xkb_desc * xkb, uint32_t name, unsigned *type_rtrn)
1682 if (xkb && xkb->map && xkb->map->types)
1684 for (n = 0; n < xkb->map->num_types; n++)
1686 if (xkb->map->types[n].name == (uint32_t) name)
1697 * Assign a type to the given sym and return the Atom for the type assigned.
1700 * - ONE_LEVEL for width 0/1
1701 * - ALPHABETIC for 2 shift levels, with lower/upercase
1702 * - KEYPAD for keypad keys.
1703 * - TWO_LEVEL for other 2 shift level keys.
1704 * and the same for four level keys.
1706 * @param width Number of sysms in syms.
1707 * @param syms The keysyms for the given key (must be size width).
1708 * @param typeNameRtrn Set to the Atom of the type name.
1710 * @returns True if a type could be found, False otherwise.
1713 FindAutomaticType(int width, uint32_t * syms, uint32_t * typeNameRtrn,
1717 if ((width == 1) || (width == 0))
1719 *typeNameRtrn = xkb_intern_atom("ONE_LEVEL");
1722 else if (width == 2)
1724 if (syms && XkbcKSIsLower(syms[0]) && XkbcKSIsUpper(syms[1]))
1726 *typeNameRtrn = xkb_intern_atom("ALPHABETIC");
1728 else if (syms && (XkbKSIsKeypad(syms[0]) || XkbKSIsKeypad(syms[1])))
1730 *typeNameRtrn = xkb_intern_atom("KEYPAD");
1735 *typeNameRtrn = xkb_intern_atom("TWO_LEVEL");
1739 else if (width <= 4)
1741 if (syms && XkbcKSIsLower(syms[0]) && XkbcKSIsUpper(syms[1]))
1742 if (XkbcKSIsLower(syms[2]) && XkbcKSIsUpper(syms[3]))
1744 xkb_intern_atom("FOUR_LEVEL_ALPHABETIC");
1746 *typeNameRtrn = xkb_intern_atom("FOUR_LEVEL_SEMIALPHABETIC");
1748 else if (syms && (XkbKSIsKeypad(syms[0]) || XkbKSIsKeypad(syms[1])))
1749 *typeNameRtrn = xkb_intern_atom("FOUR_LEVEL_KEYPAD");
1751 *typeNameRtrn = xkb_intern_atom("FOUR_LEVEL");
1752 /* XXX: why not set autoType here? */
1754 return ((width >= 0) && (width <= 4));
1758 * Ensure the given KeyInfo is in a coherent state, i.e. no gaps between the
1759 * groups, and reduce to one group if all groups are identical anyway.
1762 PrepareKeyDef(KeyInfo * key)
1764 int i, j, width, defined, lastGroup;
1767 defined = key->symsDefined | key->actsDefined | key->typesDefined;
1768 /* get highest group number */
1769 for (i = XkbNumKbdGroups - 1; i >= 0; i--)
1771 if (defined & (1 << i))
1779 /* If there are empty groups between non-empty ones fill them with data */
1780 /* from the first group. */
1781 /* We can make a wrong assumption here. But leaving gaps is worse. */
1782 for (i = lastGroup; i > 0; i--)
1784 if (defined & (1 << i))
1786 width = key->numLevels[0];
1787 if (key->typesDefined & 1)
1789 for (j = 0; j < width; j++)
1791 key->types[i] = key->types[0];
1793 key->typesDefined |= 1 << i;
1795 if ((key->actsDefined & 1) && key->acts[0])
1797 key->acts[i] = uTypedCalloc(width, union xkb_action);
1798 if (key->acts[i] == NULL)
1800 memcpy(key->acts[i], key->acts[0],
1801 width * sizeof(union xkb_action));
1802 key->actsDefined |= 1 << i;
1804 if ((key->symsDefined & 1) && key->syms[0])
1806 key->syms[i] = uTypedCalloc(width, uint32_t);
1807 if (key->syms[i] == NULL)
1809 memcpy(key->syms[i], key->syms[0], width * sizeof(uint32_t));
1810 key->symsDefined |= 1 << i;
1814 key->numLevels[i] = key->numLevels[0];
1817 /* If all groups are completely identical remove them all */
1818 /* exept the first one. */
1820 for (i = lastGroup; i > 0; i--)
1822 if ((key->numLevels[i] != key->numLevels[0]) ||
1823 (key->types[i] != key->types[0]))
1828 if ((key->syms[i] != key->syms[0]) &&
1829 (key->syms[i] == NULL || key->syms[0] == NULL ||
1830 memcmp(key->syms[i], key->syms[0],
1831 sizeof(uint32_t) * key->numLevels[0])))
1836 if ((key->acts[i] != key->acts[0]) &&
1837 (key->acts[i] == NULL || key->acts[0] == NULL ||
1838 memcmp(key->acts[i], key->acts[0],
1839 sizeof(union xkb_action) * key->numLevels[0])))
1847 for (i = lastGroup; i > 0; i--)
1849 key->numLevels[i] = 0;
1851 key->syms[i] = NULL;
1853 key->acts[i] = NULL;
1856 key->symsDefined &= 1;
1857 key->actsDefined &= 1;
1858 key->typesDefined &= 1;
1863 * Copy the KeyInfo into the keyboard description.
1865 * This function recurses.
1868 CopySymbolsDef(struct xkb_desc * xkb, KeyInfo *key, int start_from)
1871 xkb_keycode_t okc, kc;
1872 unsigned width, tmp, nGroups;
1873 struct xkb_key_type * type;
1874 Bool haveActions, autoType, useAlias;
1876 union xkb_action *outActs;
1877 unsigned types[XkbNumKbdGroups];
1879 useAlias = (start_from == 0);
1881 /* get the keycode for the key. */
1882 if (!FindNamedKey(xkb, key->name, &kc, useAlias, CreateKeyNames(xkb),
1885 if ((start_from == 0) && (warningLevel >= 5))
1887 WARN("Key %s not found in %s keycodes\n",
1888 longText(key->name),
1889 XkbcAtomText(xkb->names->keycodes));
1890 ACTION("Symbols ignored\n");
1895 haveActions = False;
1896 for (i = width = nGroups = 0; i < XkbNumKbdGroups; i++)
1898 if (((i + 1) > nGroups)
1899 && (((key->symsDefined | key->actsDefined) & (1 << i))
1900 || (key->typesDefined) & (1 << i)))
1905 /* Assign the type to the key, if it is missing. */
1906 if (key->types[i] == None)
1908 if (key->dfltType != None)
1909 key->types[i] = key->dfltType;
1910 else if (FindAutomaticType(key->numLevels[i], key->syms[i],
1911 &key->types[i], &autoType))
1916 if (warningLevel >= 5)
1918 WARN("No automatic type for %d symbols\n",
1919 (unsigned int) key->numLevels[i]);
1920 ACTION("Using %s for the %s key (keycode %d)\n",
1921 XkbcAtomText(key->types[i]),
1922 longText(key->name), kc);
1926 if (FindNamedType(xkb, key->types[i], &types[i]))
1928 if (!autoType || key->numLevels[i] > 2)
1929 xkb->server->explicit[kc] |= (1 << i);
1933 if (warningLevel >= 3)
1935 WARN("Type \"%s\" is not defined\n",
1936 XkbcAtomText(key->types[i]));
1937 ACTION("Using TWO_LEVEL for the %s key (keycode %d)\n",
1938 longText(key->name), kc);
1940 types[i] = XkbTwoLevelIndex;
1942 /* if the type specifies less syms than the key has, shrink the key */
1943 type = &xkb->map->types[types[i]];
1944 if (type->num_levels < key->numLevels[i])
1946 if (warningLevel > 0)
1949 ("Type \"%s\" has %d levels, but %s has %d symbols\n",
1950 XkbcAtomText(type->name),
1951 (unsigned int) type->num_levels,
1952 longText(key->name),
1953 (unsigned int) key->numLevels[i]);
1954 ACTION("Ignoring extra symbols\n");
1956 key->numLevels[i] = type->num_levels;
1958 if (key->numLevels[i] > width)
1959 width = key->numLevels[i];
1960 if (type->num_levels > width)
1961 width = type->num_levels;
1964 /* width is now the largest width found */
1966 i = width * nGroups;
1967 outSyms = XkbcResizeKeySyms(xkb, kc, i);
1968 if (outSyms == NULL)
1970 WSGO("Could not enlarge symbols for %s (keycode %d)\n",
1971 longText(key->name), kc);
1976 outActs = XkbcResizeKeyActions(xkb, kc, i);
1977 if (outActs == NULL)
1979 WSGO("Could not enlarge actions for %s (key %d)\n",
1980 longText(key->name), kc);
1983 xkb->server->explicit[kc] |= XkbExplicitInterpretMask;
1987 if (key->defs.defined & _Key_GroupInfo)
1990 i = xkb->map->key_sym_map[kc].group_info;
1992 xkb->map->key_sym_map[kc].group_info = XkbSetNumGroups(i, nGroups);
1993 xkb->map->key_sym_map[kc].width = width;
1994 for (i = 0; i < nGroups; i++)
1996 /* assign kt_index[i] to the index of the type in map->types.
1997 * kt_index[i] may have been set by a previous run (if we have two
1998 * layouts specified). Let's not overwrite it with the ONE_LEVEL
1999 * default group if we dont even have keys for this group anyway.
2001 * FIXME: There should be a better fix for this.
2003 if (key->numLevels[i])
2004 xkb->map->key_sym_map[kc].kt_index[i] = types[i];
2005 if (key->syms[i] != NULL)
2007 /* fill key to "width" symbols*/
2008 for (tmp = 0; tmp < width; tmp++)
2010 if (tmp < key->numLevels[i])
2011 outSyms[tmp] = key->syms[i][tmp];
2013 outSyms[tmp] = NoSymbol;
2014 if ((outActs != NULL) && (key->acts[i] != NULL))
2016 if (tmp < key->numLevels[i])
2017 outActs[tmp] = key->acts[i][tmp];
2019 outActs[tmp].type = XkbSA_NoAction;
2027 switch (key->behavior.type & XkbKB_OpMask)
2031 case XkbKB_Overlay1:
2032 case XkbKB_Overlay2:
2033 /* find key by name! */
2034 if (!FindNamedKey(xkb, key->nameForOverlayKey, &okc, True,
2035 CreateKeyNames(xkb), 0))
2037 if (warningLevel >= 1)
2039 WARN("Key %s not found in %s keycodes\n",
2040 longText(key->nameForOverlayKey),
2041 XkbcAtomText(xkb->names->keycodes));
2042 ACTION("Not treating %s as an overlay key \n",
2043 longText(key->name));
2047 key->behavior.data = okc;
2049 xkb->server->behaviors[kc] = key->behavior;
2050 xkb->server->explicit[kc] |= XkbExplicitBehaviorMask;
2053 if (key->defs.defined & _Key_VModMap)
2055 xkb->server->vmodmap[kc] = key->vmodmap;
2056 xkb->server->explicit[kc] |= XkbExplicitVModMapMask;
2058 if (key->repeat != RepeatUndefined)
2060 if (key->repeat == RepeatYes)
2061 xkb->ctrls->per_key_repeat[kc / 8] |= (1 << (kc % 8));
2063 xkb->ctrls->per_key_repeat[kc / 8] &= ~(1 << (kc % 8));
2064 xkb->server->explicit[kc] |= XkbExplicitAutoRepeatMask;
2067 if (nGroups > xkb->ctrls->num_groups)
2068 xkb->ctrls->num_groups = nGroups;
2070 /* do the same thing for the next key */
2071 CopySymbolsDef(xkb, key, kc + 1);
2076 CopyModMapDef(struct xkb_desc * xkb, ModMapEntry *entry)
2080 if ((!entry->haveSymbol)
2083 (xkb, entry->u.keyName, &kc, True, CreateKeyNames(xkb), 0)))
2085 if (warningLevel >= 5)
2087 WARN("Key %s not found in %s keycodes\n",
2088 longText(entry->u.keyName),
2089 XkbcAtomText(xkb->names->keycodes));
2090 ACTION("Modifier map entry for %s not updated\n",
2091 XkbcModIndexText(entry->modifier));
2095 else if (entry->haveSymbol
2096 && (!FindKeyForSymbol(xkb, entry->u.keySym, &kc)))
2098 if (warningLevel > 5)
2100 WARN("Key \"%s\" not found in %s symbol map\n",
2101 XkbcKeysymText(entry->u.keySym),
2102 XkbcAtomText(xkb->names->symbols));
2103 ACTION("Modifier map entry for %s not updated\n",
2104 XkbcModIndexText(entry->modifier));
2108 xkb->map->modmap[kc] |= (1 << entry->modifier);
2113 * Handle the xkb_symbols section of an xkb file.
2115 * @param file The parsed xkb_symbols section of the xkb file.
2116 * @param xkb Handle to the keyboard description to store the symbols in.
2117 * @param merge Merge strategy (e.g. MergeOverride).
2120 CompileSymbols(XkbFile *file, struct xkb_desc * xkb, unsigned merge)
2125 InitSymbolsInfo(&info, xkb);
2126 info.dflt.defs.fileID = file->id;
2127 info.dflt.defs.merge = merge;
2128 HandleSymbolsFile(file, xkb, merge, &info);
2130 if (info.nKeys == 0) {
2131 FreeSymbolsInfo(&info);
2135 if (info.errorCount == 0)
2139 /* alloc memory in the xkb struct */
2140 if (XkbcAllocNames(xkb, XkbSymbolsNameMask | XkbGroupNamesMask, 0, 0)
2143 WSGO("Can not allocate names in CompileSymbols\n");
2144 ACTION("Symbols not added\n");
2147 if (XkbcAllocClientMap(xkb, XkbKeySymsMask | XkbModifierMapMask, 0)
2150 WSGO("Could not allocate client map in CompileSymbols\n");
2151 ACTION("Symbols not added\n");
2154 if (XkbcAllocServerMap(xkb, XkbAllServerInfoMask, 32) != Success)
2156 WSGO("Could not allocate server map in CompileSymbols\n");
2157 ACTION("Symbols not added\n");
2160 if (XkbcAllocControls(xkb, XkbPerKeyRepeatMask) != Success)
2162 WSGO("Could not allocate controls in CompileSymbols\n");
2163 ACTION("Symbols not added\n");
2167 /* now copy info into xkb. */
2168 xkb->names->symbols = xkb_intern_atom(info.name);
2170 ApplyAliases(xkb, False, &info.aliases);
2171 for (i = 0; i < XkbNumKbdGroups; i++)
2173 if (info.groupNames[i] != None)
2174 xkb->names->groups[i] = info.groupNames[i];
2177 for (key = info.keys, i = 0; i < info.nKeys; i++, key++)
2182 for (key = info.keys, i = 0; i < info.nKeys; i++, key++)
2184 if (!CopySymbolsDef(xkb, key, 0))
2187 if (warningLevel > 3)
2189 for (i = xkb->min_key_code; i <= xkb->max_key_code; i++)
2191 if (xkb->names->keys[i].name[0] == '\0')
2193 if (XkbKeyNumGroups(xkb, i) < 1)
2196 memcpy(buf, xkb->names->keys[i].name, 4);
2199 ("No symbols defined for <%s> (keycode %d)\n",
2206 ModMapEntry *mm, *next;
2207 for (mm = info.modMap; mm != NULL; mm = next)
2209 if (!CopyModMapDef(xkb, mm))
2211 next = (ModMapEntry *) mm->defs.next;
2214 FreeSymbolsInfo(&info);
2218 FreeSymbolsInfo(&info);