1 /************************************************************
2 Copyright (c) 1994 by Silicon Graphics Computer Systems, Inc.
4 Permission to use, copy, modify, and distribute this
5 software and its documentation for any purpose and without
6 fee is hereby granted, provided that the above copyright
7 notice appear in all copies and that both that copyright
8 notice and this permission notice appear in supporting
9 documentation, and that the name of Silicon Graphics not be
10 used in advertising or publicity pertaining to distribution
11 of the software without specific prior written permission.
12 Silicon Graphics makes no representation about the suitability
13 of this software for any purpose. It is provided "as is"
14 without any express or implied warranty.
16 SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
17 SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
18 AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
19 GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
20 DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
21 DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
22 OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH
23 THE USE OR PERFORMANCE OF THIS SOFTWARE.
25 ********************************************************/
27 #include "xkbcomp-priv.h"
28 #include "parseutils.h"
34 /***====================================================================***/
36 /* Needed to work with the typechecker. */
37 typedef darray(xkb_keysym_t) darray_xkb_keysym_t;
41 #define RepeatUndefined ~((unsigned)0)
43 #define _Key_Syms (1<<0)
44 #define _Key_Acts (1<<1)
45 #define _Key_Repeat (1<<2)
46 #define _Key_Behavior (1<<3)
47 #define _Key_Type_Dflt (1<<4)
48 #define _Key_Types (1<<5)
49 #define _Key_GroupInfo (1<<6)
50 #define _Key_VModMap (1<<7)
52 typedef struct _KeyInfo
55 unsigned long name; /* the 4 chars of the key name, as long */
56 unsigned char groupInfo;
57 unsigned char typesDefined;
58 unsigned char symsDefined;
59 unsigned char actsDefined;
60 unsigned int numLevels[XkbNumKbdGroups];
62 /* syms[group] -> Single array for all the keysyms in the group. */
63 darray_xkb_keysym_t syms[XkbNumKbdGroups];
65 * symsMapIndex[group][level] -> The index from which the syms for
66 * the level begin in the syms[group] array. Remember each keycode
67 * can have multiple keysyms in each level (that is, each key press
68 * can result in multiple keysyms).
70 darray(int) symsMapIndex[XkbNumKbdGroups];
72 * symsMapNumEntries[group][level] -> How many syms are in
73 * syms[group][symsMapIndex[group][level]].
75 darray(size_t) symsMapNumEntries[XkbNumKbdGroups];
77 union xkb_action *acts[XkbNumKbdGroups];
78 xkb_atom_t types[XkbNumKbdGroups];
80 struct xkb_behavior behavior;
81 unsigned short vmodmap;
86 * Init the given key info to sane values.
89 InitKeyInfo(KeyInfo * info)
92 static const char dflt[4] = "*";
94 info->defs.defined = 0;
95 info->defs.fileID = 0;
96 info->defs.merge = MergeOverride;
97 info->defs.next = NULL;
98 info->name = KeyNameToLong(dflt);
100 info->typesDefined = info->symsDefined = info->actsDefined = 0;
101 for (i = 0; i < XkbNumKbdGroups; i++)
103 info->numLevels[i] = 0;
104 info->types[i] = XKB_ATOM_NONE;
105 darray_init(info->syms[i]);
106 darray_init(info->symsMapIndex[i]);
107 darray_init(info->symsMapNumEntries[i]);
108 info->acts[i] = NULL;
110 info->dfltType = XKB_ATOM_NONE;
111 info->behavior.type = XkbKB_Default;
112 info->behavior.data = 0;
114 info->repeat = RepeatUndefined;
118 * Free memory associated with this key info and reset to sane values.
121 FreeKeyInfo(KeyInfo * info)
125 info->defs.defined = 0;
126 info->defs.fileID = 0;
127 info->defs.merge = MergeOverride;
128 info->defs.next = NULL;
130 info->typesDefined = info->symsDefined = info->actsDefined = 0;
131 for (i = 0; i < XkbNumKbdGroups; i++)
133 info->numLevels[i] = 0;
134 info->types[i] = XKB_ATOM_NONE;
135 darray_free(info->syms[i]);
136 darray_free(info->symsMapIndex[i]);
137 darray_free(info->symsMapNumEntries[i]);
139 info->acts[i] = NULL;
141 info->dfltType = XKB_ATOM_NONE;
142 info->behavior.type = XkbKB_Default;
143 info->behavior.data = 0;
145 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;
165 darray_init(old->symsMapIndex[i]);
166 darray_init(old->symsMapNumEntries[i]);
167 darray_init(old->syms[i]);
174 for (i = 0; i < XkbNumKbdGroups; i++)
176 width = new->numLevels[i];
178 darray_copy(new->syms[i], old->syms[i]);
179 darray_copy(new->symsMapIndex[i], old->symsMapIndex[i]);
180 darray_copy(new->symsMapNumEntries[i], old->symsMapNumEntries[i]);
182 if (old->acts[i] != NULL)
184 new->acts[i] = uTypedCalloc(width, union xkb_action);
187 darray_free(new->syms[i]);
188 darray_free(new->symsMapIndex[i]);
189 darray_free(new->symsMapNumEntries[i]);
190 new->numLevels[i] = 0;
193 memcpy(new->acts[i], old->acts[i],
194 width * sizeof(union xkb_action));
201 /***====================================================================***/
203 typedef struct _ModMapEntry
210 unsigned long keyName;
215 typedef struct _SymbolsInfo
217 char *name; /* e.g. pc+us+inet(evdev) */
221 unsigned explicit_group;
222 darray(KeyInfo) keys;
226 xkb_atom_t groupNames[XkbNumKbdGroups];
233 InitSymbolsInfo(SymbolsInfo * info, struct xkb_keymap *keymap)
238 info->explicit_group = 0;
239 info->errorCount = 0;
241 info->merge = MergeOverride;
242 darray_init(info->keys);
243 darray_growalloc(info->keys, 110);
245 for (i = 0; i < XkbNumKbdGroups; i++)
246 info->groupNames[i] = XKB_ATOM_NONE;
247 InitKeyInfo(&info->dflt);
248 InitVModInfo(&info->vmods, keymap);
250 info->aliases = NULL;
254 FreeSymbolsInfo(SymbolsInfo * info)
259 darray_foreach(key, info->keys)
261 darray_free(info->keys);
263 ClearCommonInfo(&info->modMap->defs);
265 ClearAliases(&info->aliases);
266 memset(info, 0, sizeof(SymbolsInfo));
270 ResizeKeyGroup(KeyInfo * key, unsigned int group, unsigned int numLevels,
271 unsigned sizeSyms, bool forceActions)
275 if (darray_size(key->syms[group]) < sizeSyms)
276 darray_resize0(key->syms[group], sizeSyms);
278 if (darray_empty(key->symsMapIndex[group]) ||
279 key->numLevels[group] < numLevels)
281 darray_resize(key->symsMapIndex[group], numLevels);
282 for (i = key->numLevels[group]; i < numLevels; i++)
283 darray_item(key->symsMapIndex[group], i) = -1;
286 if (darray_empty(key->symsMapNumEntries[group]) ||
287 key->numLevels[group] < numLevels)
288 darray_resize0(key->symsMapNumEntries[group], numLevels);
291 (key->numLevels[group] < numLevels || (key->acts[group] == NULL))) ||
292 (key->numLevels[group] < numLevels && (key->acts[group] != NULL)))
294 key->acts[group] = uTypedRecalloc(key->acts[group],
295 key->numLevels[group],
298 if (!key->acts[group])
301 if (key->numLevels[group] < numLevels)
302 key->numLevels[group] = numLevels;
306 enum key_group_selector {
313 MergeKeyGroups(SymbolsInfo * info,
314 KeyInfo * into, KeyInfo * from, unsigned group)
316 darray_xkb_keysym_t resultSyms;
317 enum key_group_selector using = NONE;
318 union xkb_action *resultActs;
319 unsigned int resultWidth;
320 unsigned int resultSize = 0;
323 bool report, clobber;
325 clobber = (from->defs.merge != MergeAugment);
327 report = (warningLevel > 9) ||
328 ((into->defs.fileID == from->defs.fileID) && (warningLevel > 0));
330 darray_init(resultSyms);
332 if (into->numLevels[group] >= from->numLevels[group])
334 resultActs = into->acts[group];
335 resultWidth = into->numLevels[group];
339 resultActs = from->acts[group];
340 resultWidth = from->numLevels[group];
341 darray_resize(into->symsMapIndex[group],
342 from->numLevels[group]);
343 darray_resize0(into->symsMapNumEntries[group],
344 from->numLevels[group]);
346 for (i = into->numLevels[group]; i < from->numLevels[group]; i++)
347 darray_item(into->symsMapIndex[group], i) = -1;
350 if ((resultActs == NULL) && (into->acts[group] || from->acts[group]))
352 resultActs = uTypedCalloc(resultWidth, union xkb_action);
355 WSGO("Could not allocate actions for group merge\n");
356 ACTION("Group %d of key %s not merged\n", group,
357 longText(into->name));
360 for (i = 0; i < resultWidth; i++)
362 union xkb_action *fromAct, *toAct;
363 fromAct = (from->acts[group] ? &from->acts[group][i] : NULL);
364 toAct = (into->acts[group] ? &into->acts[group][i] : NULL);
365 if (((fromAct == NULL) || (fromAct->type == XkbSA_NoAction))
368 resultActs[i] = *toAct;
370 else if (((toAct == NULL) || (toAct->type == XkbSA_NoAction))
371 && (fromAct != NULL))
373 resultActs[i] = *fromAct;
377 union xkb_action *use, *ignore;
391 ("Multiple actions for level %d/group %d on key %s\n",
392 i + 1, group + 1, longText(into->name));
393 ACTION("Using %s, ignoring %s\n",
394 XkbcActionTypeText(use->type),
395 XkbcActionTypeText(ignore->type));
398 resultActs[i] = *use;
403 for (i = 0; i < resultWidth; i++)
405 unsigned int fromSize = 0;
408 if (!darray_empty(from->symsMapNumEntries[group]) &&
409 i < from->numLevels[group])
410 fromSize = darray_item(from->symsMapNumEntries[group], i);
412 if (!darray_empty(into->symsMapNumEntries[group]) &&
413 i < into->numLevels[group])
414 toSize = darray_item(into->symsMapNumEntries[group], i);
418 resultSize += toSize;
421 else if (toSize == 0 || clobber)
423 resultSize += fromSize;
428 resultSize += toSize;
438 resultSyms = from->syms[group];
441 else if (using == TO)
443 resultSyms = into->syms[group];
447 darray_resize0(resultSyms, resultSize);
449 for (i = 0; i < resultWidth; i++)
451 enum key_group_selector use = NONE;
452 unsigned int fromSize = 0;
453 unsigned int toSize = 0;
455 if (i < from->numLevels[group])
456 fromSize = darray_item(from->symsMapNumEntries[group], i);
458 if (i < into->numLevels[group])
459 toSize = darray_item(into->symsMapNumEntries[group], i);
461 if (fromSize == 0 && toSize == 0)
463 darray_item(into->symsMapIndex[group], i) = -1;
464 darray_item(into->symsMapNumEntries[group], i) = 0;
470 else if (toSize == 0 || clobber)
475 if (toSize && fromSize && report)
477 INFO("Multiple symbols for group %d, level %d on key %s\n",
478 group + 1, i + 1, longText(into->name));
479 ACTION("Using %s, ignoring %s\n",
480 (use == FROM ? "from" : "to"),
481 (use == FROM ? "to" : "from"));
486 memcpy(darray_mem(resultSyms, cur_idx),
487 darray_mem(from->syms[group],
488 darray_item(from->symsMapIndex[group], i)),
489 darray_item(from->symsMapNumEntries[group], i) * sizeof(xkb_keysym_t));
490 darray_item(into->symsMapIndex[group], i) = cur_idx;
491 darray_item(into->symsMapNumEntries[group], i) =
492 darray_item(from->symsMapNumEntries[group], i);
496 memcpy(darray_mem(resultSyms, cur_idx),
497 darray_mem(into->syms[group],
498 darray_item(into->symsMapIndex[group], i)),
499 darray_item(into->symsMapNumEntries[group], i) * sizeof(xkb_keysym_t));
500 darray_item(into->symsMapIndex[group], i) = cur_idx;
502 cur_idx += darray_item(into->symsMapNumEntries[group], i);
506 if (resultActs != into->acts[group])
507 free(into->acts[group]);
508 if (resultActs != from->acts[group])
509 free(from->acts[group]);
510 into->numLevels[group] = resultWidth;
511 if (!darray_same(resultSyms, into->syms[group]))
512 darray_free(into->syms[group]);
513 into->syms[group] = resultSyms;
514 if (!darray_same(resultSyms, from->syms[group]))
515 darray_free(from->syms[group]);
516 darray_init(from->syms[group]);
517 darray_free(from->symsMapIndex[group]);
518 darray_free(from->symsMapNumEntries[group]);
519 into->acts[group] = resultActs;
520 from->acts[group] = NULL;
521 if (!darray_empty(into->syms[group]))
522 into->symsDefined |= (1 << group);
523 from->symsDefined &= ~(1 << group);
524 into->actsDefined |= (1 << group);
525 from->actsDefined &= ~(1 << group);
531 MergeKeys(SymbolsInfo *info, struct xkb_keymap *keymap,
532 KeyInfo *into, KeyInfo *from)
535 unsigned collide = 0;
538 if (from->defs.merge == MergeReplace)
540 for (i = 0; i < XkbNumKbdGroups; i++)
542 if (into->numLevels[i] != 0)
544 darray_free(into->syms[i]);
549 memset(from, 0, sizeof(KeyInfo));
552 report = ((warningLevel > 9) ||
553 ((into->defs.fileID == from->defs.fileID)
554 && (warningLevel > 0)));
555 for (i = 0; i < XkbNumKbdGroups; i++)
557 if (from->numLevels[i] > 0)
559 if (into->numLevels[i] == 0)
561 into->numLevels[i] = from->numLevels[i];
562 into->syms[i] = from->syms[i];
563 into->symsMapIndex[i] = from->symsMapIndex[i];
564 into->symsMapNumEntries[i] = from->symsMapNumEntries[i];
565 into->acts[i] = from->acts[i];
566 into->symsDefined |= (1 << i);
567 darray_init(from->syms[i]);
568 darray_init(from->symsMapIndex[i]);
569 darray_init(from->symsMapNumEntries[i]);
570 from->acts[i] = NULL;
571 from->numLevels[i] = 0;
572 from->symsDefined &= ~(1 << i);
573 if (!darray_empty(into->syms[i]))
574 into->defs.defined |= _Key_Syms;
576 into->defs.defined |= _Key_Acts;
582 if (!darray_empty(into->syms[i]))
583 collide |= _Key_Syms;
585 collide |= _Key_Acts;
587 MergeKeyGroups(info, into, from, (unsigned) i);
590 if (from->types[i] != XKB_ATOM_NONE)
592 if ((into->types[i] != XKB_ATOM_NONE) && report &&
593 (into->types[i] != from->types[i]))
595 xkb_atom_t use, ignore;
596 collide |= _Key_Types;
597 if (from->defs.merge != MergeAugment)
599 use = from->types[i];
600 ignore = into->types[i];
604 use = into->types[i];
605 ignore = from->types[i];
608 ("Multiple definitions for group %d type of key %s\n",
609 i, longText(into->name));
610 ACTION("Using %s, ignoring %s\n",
611 xkb_atom_text(keymap->ctx, use),
612 xkb_atom_text(keymap->ctx, ignore));
614 if ((from->defs.merge != MergeAugment)
615 || (into->types[i] == XKB_ATOM_NONE))
617 into->types[i] = from->types[i];
621 if (UseNewField(_Key_Behavior, &into->defs, &from->defs, &collide))
623 into->behavior = from->behavior;
624 into->defs.defined |= _Key_Behavior;
626 if (UseNewField(_Key_VModMap, &into->defs, &from->defs, &collide))
628 into->vmodmap = from->vmodmap;
629 into->defs.defined |= _Key_VModMap;
631 if (UseNewField(_Key_Repeat, &into->defs, &from->defs, &collide))
633 into->repeat = from->repeat;
634 into->defs.defined |= _Key_Repeat;
636 if (UseNewField(_Key_Type_Dflt, &into->defs, &from->defs, &collide))
638 into->dfltType = from->dfltType;
639 into->defs.defined |= _Key_Type_Dflt;
641 if (UseNewField(_Key_GroupInfo, &into->defs, &from->defs, &collide))
643 into->groupInfo = from->groupInfo;
644 into->defs.defined |= _Key_GroupInfo;
648 WARN("Symbol map for key %s redefined\n",
649 longText(into->name));
650 ACTION("Using %s definition for conflicting fields\n",
651 (from->defs.merge == MergeAugment ? "first" : "last"));
657 AddKeySymbols(SymbolsInfo *info, KeyInfo *key, struct xkb_keymap *keymap)
659 unsigned long real_name;
662 darray_foreach(iter, info->keys)
663 if (iter->name == key->name)
664 return MergeKeys(info, keymap, iter, key);
666 if (FindKeyNameForAlias(keymap, key->name, &real_name))
667 darray_foreach(iter, info->keys)
668 if (iter->name == real_name)
669 return MergeKeys(info, keymap, iter, key);
671 darray_resize0(info->keys, darray_size(info->keys) + 1);
672 new = &darray_item(info->keys, darray_size(info->keys) - 1);
673 return CopyKeyInfo(key, new, true);
677 AddModMapEntry(SymbolsInfo * info, ModMapEntry * new)
682 clobber = (new->defs.merge != MergeAugment);
683 for (mm = info->modMap; mm != NULL; mm = (ModMapEntry *) mm->defs.next)
685 if (new->haveSymbol && mm->haveSymbol
686 && (new->u.keySym == mm->u.keySym))
688 unsigned use, ignore;
689 if (mm->modifier != new->modifier)
694 ignore = mm->modifier;
699 ignore = new->modifier;
702 ("%s added to symbol map for multiple modifiers\n",
703 XkbcKeysymText(new->u.keySym));
704 ACTION("Using %s, ignoring %s.\n",
705 XkbcModIndexText(use),
706 XkbcModIndexText(ignore));
711 if ((!new->haveSymbol) && (!mm->haveSymbol) &&
712 (new->u.keyName == mm->u.keyName))
714 unsigned use, ignore;
715 if (mm->modifier != new->modifier)
720 ignore = mm->modifier;
725 ignore = new->modifier;
727 ERROR("Key %s added to map for multiple modifiers\n",
728 longText(new->u.keyName));
729 ACTION("Using %s, ignoring %s.\n",
730 XkbcModIndexText(use),
731 XkbcModIndexText(ignore));
737 mm = uTypedAlloc(ModMapEntry);
740 WSGO("Could not allocate modifier map entry\n");
741 ACTION("Modifier map for %s will be incomplete\n",
742 XkbcModIndexText(new->modifier));
746 mm->defs.next = &info->modMap->defs;
751 /***====================================================================***/
754 MergeIncludedSymbols(SymbolsInfo *into, SymbolsInfo *from,
755 unsigned merge, struct xkb_keymap *keymap)
760 if (from->errorCount > 0)
762 into->errorCount += from->errorCount;
765 if (into->name == NULL)
767 into->name = from->name;
770 for (i = 0; i < XkbNumKbdGroups; i++)
772 if (from->groupNames[i] != XKB_ATOM_NONE)
774 if ((merge != MergeAugment) ||
775 (into->groupNames[i] == XKB_ATOM_NONE))
776 into->groupNames[i] = from->groupNames[i];
780 darray_foreach(key, from->keys) {
781 if (merge != MergeDefault)
782 key->defs.merge = merge;
784 if (!AddKeySymbols(into, key, keymap))
788 if (from->modMap != NULL)
790 ModMapEntry *mm, *next;
791 for (mm = from->modMap; mm != NULL; mm = next)
793 if (merge != MergeDefault)
794 mm->defs.merge = merge;
795 if (!AddModMapEntry(into, mm))
797 next = (ModMapEntry *) mm->defs.next;
802 if (!MergeAliases(&into->aliases, &from->aliases, merge))
807 HandleSymbolsFile(XkbFile *file, struct xkb_keymap *keymap,
808 unsigned merge, SymbolsInfo *info);
811 HandleIncludeSymbols(IncludeStmt *stmt, struct xkb_keymap *keymap,
816 SymbolsInfo included;
820 if ((stmt->file == NULL) && (stmt->map == NULL))
824 memset(info, 0, sizeof(SymbolsInfo));
826 else if (ProcessIncludeFile(keymap->ctx, stmt, XkmSymbolsIndex, &rtrn,
829 InitSymbolsInfo(&included, keymap);
830 included.fileID = included.dflt.defs.fileID = rtrn->id;
831 included.merge = included.dflt.defs.merge = MergeOverride;
834 included.explicit_group = atoi(stmt->modifier) - 1;
838 included.explicit_group = info->explicit_group;
840 HandleSymbolsFile(rtrn, keymap, MergeOverride, &included);
841 if (stmt->stmt != NULL)
844 included.name = stmt->stmt;
851 info->errorCount += 10;
854 if ((stmt->next != NULL) && (included.errorCount < 1))
858 SymbolsInfo next_incl;
860 for (next = stmt->next; next != NULL; next = next->next)
862 if ((next->file == NULL) && (next->map == NULL))
865 MergeIncludedSymbols(&included, info, next->merge, keymap);
866 FreeSymbolsInfo(info);
868 else if (ProcessIncludeFile(keymap->ctx, next, XkmSymbolsIndex,
871 InitSymbolsInfo(&next_incl, keymap);
872 next_incl.fileID = next_incl.dflt.defs.fileID = rtrn->id;
873 next_incl.merge = next_incl.dflt.defs.merge = MergeOverride;
876 next_incl.explicit_group = atoi(next->modifier) - 1;
880 next_incl.explicit_group = info->explicit_group;
882 HandleSymbolsFile(rtrn, keymap, MergeOverride, &next_incl);
883 MergeIncludedSymbols(&included, &next_incl, op, keymap);
884 FreeSymbolsInfo(&next_incl);
889 info->errorCount += 10;
890 FreeSymbolsInfo(&included);
897 info->errorCount += included.errorCount;
903 MergeIncludedSymbols(info, &included, newMerge, keymap);
904 FreeSymbolsInfo(&included);
906 return (info->errorCount == 0);
913 GetGroupIndex(KeyInfo *key, struct xkb_keymap *keymap,
914 ExprDef * arrayNdx, unsigned what, unsigned *ndx_rtrn)
924 if (arrayNdx == NULL)
929 defined = key->symsDefined;
931 defined = key->actsDefined;
933 for (i = 0; i < XkbNumKbdGroups; i++)
935 if ((defined & (1 << i)) == 0)
941 ERROR("Too many groups of %s for key %s (max %d)\n", name,
942 longText(key->name), XkbNumKbdGroups + 1);
943 ACTION("Ignoring %s defined for extra groups\n", name);
946 if (!ExprResolveGroup(keymap->ctx, arrayNdx, &tmp))
948 ERROR("Illegal group index for %s of key %s\n", name,
949 longText(key->name));
950 ACTION("Definition with non-integer array index ignored\n");
953 *ndx_rtrn = tmp.uval - 1;
958 AddSymbolsToKey(KeyInfo *key, struct xkb_keymap *keymap,
959 ExprDef *arrayNdx, ExprDef *value, SymbolsInfo *info)
961 unsigned ndx, nSyms, nLevels;
965 if (!GetGroupIndex(key, keymap, arrayNdx, SYMBOLS, &ndx))
969 key->symsDefined |= (1 << ndx);
972 if (value->op != ExprKeysymList)
974 ERROR("Expected a list of symbols, found %s\n", exprOpText(value->op));
975 ACTION("Ignoring symbols for group %d of %s\n", ndx + 1,
976 longText(key->name));
979 if (!darray_empty(key->syms[ndx]))
981 ERROR("Symbols for key %s, group %d already defined\n",
982 longText(key->name), ndx + 1);
983 ACTION("Ignoring duplicate definition\n");
986 nSyms = darray_size(value->value.list.syms);
987 nLevels = darray_size(value->value.list.symsMapIndex);
988 if ((key->numLevels[ndx] < nSyms || darray_empty(key->syms[ndx])) &&
989 (!ResizeKeyGroup(key, ndx, nLevels, nSyms, false)))
991 WSGO("Could not resize group %d of key %s to contain %d levels\n",
992 ndx + 1, longText(key->name), nSyms);
993 ACTION("Symbols lost\n");
996 key->symsDefined |= (1 << ndx);
997 for (i = 0; i < nLevels; i++) {
998 darray_item(key->symsMapIndex[ndx], i) =
999 darray_item(value->value.list.symsMapIndex, i);
1000 darray_item(key->symsMapNumEntries[ndx], i) =
1001 darray_item(value->value.list.symsNumEntries, i);
1003 for (j = 0; j < darray_item(key->symsMapNumEntries[ndx], i); j++) {
1004 /* FIXME: What's abort() doing here? */
1005 if (darray_item(key->symsMapIndex[ndx], i) + j >= nSyms)
1007 if (!LookupKeysym(darray_item(value->value.list.syms,
1008 darray_item(value->value.list.symsMapIndex, i) + j),
1009 &darray_item(key->syms[ndx],
1010 darray_item(key->symsMapIndex[ndx], i) + j))) {
1011 WARN("Could not resolve keysym %s for key %s, group %d (%s), level %d\n",
1012 darray_item(value->value.list.syms, i),
1013 longText(key->name),
1015 xkb_atom_text(keymap->ctx, info->groupNames[ndx]), nSyms);
1017 darray_item(key->syms[ndx],
1018 darray_item(key->symsMapIndex[ndx], i) + j) = XKB_KEY_NoSymbol;
1019 darray_item(key->symsMapIndex[ndx], i) = -1;
1020 darray_item(key->symsMapNumEntries[ndx], i) = 0;
1023 if (darray_item(key->symsMapNumEntries[ndx], i) == 1 &&
1024 darray_item(key->syms[ndx],
1025 darray_item(key->symsMapIndex[ndx], i) + j) == XKB_KEY_NoSymbol) {
1026 darray_item(key->symsMapIndex[ndx], i) = -1;
1027 darray_item(key->symsMapNumEntries[ndx], i) = 0;
1031 for (j = key->numLevels[ndx] - 1;
1032 j >= 0 && darray_item(key->symsMapNumEntries[ndx], j) == 0; j--)
1033 key->numLevels[ndx]--;
1038 AddActionsToKey(KeyInfo *key, struct xkb_keymap *keymap, ExprDef *arrayNdx,
1039 ExprDef *value, SymbolsInfo *info)
1042 unsigned ndx, nActs;
1044 struct xkb_any_action *toAct;
1046 if (!GetGroupIndex(key, keymap, arrayNdx, ACTIONS, &ndx))
1051 key->actsDefined |= (1 << ndx);
1054 if (value->op != ExprActionList)
1056 WSGO("Bad expression type (%d) for action list value\n", value->op);
1057 ACTION("Ignoring actions for group %d of %s\n", ndx,
1058 longText(key->name));
1061 if (key->acts[ndx] != NULL)
1063 WSGO("Actions for key %s, group %d already defined\n",
1064 longText(key->name), ndx);
1067 for (nActs = 0, act = value->value.child; act != NULL; nActs++)
1069 act = (ExprDef *) act->common.next;
1073 WSGO("Action list but not actions in AddActionsToKey\n");
1076 if (((key->numLevels[ndx] < nActs) || (key->acts[ndx] == NULL)) &&
1077 (!ResizeKeyGroup(key, ndx, nActs, nActs, true)))
1079 WSGO("Could not resize group %d of key %s\n", ndx,
1080 longText(key->name));
1081 ACTION("Actions lost\n");
1084 key->actsDefined |= (1 << ndx);
1086 toAct = (struct xkb_any_action *) key->acts[ndx];
1087 act = value->value.child;
1088 for (i = 0; i < nActs; i++, toAct++)
1090 if (!HandleActionDef(act, keymap, toAct, info->action))
1092 ERROR("Illegal action definition for %s\n",
1093 longText(key->name));
1094 ACTION("Action for group %d/level %d ignored\n", ndx + 1, i + 1);
1096 act = (ExprDef *) act->common.next;
1101 static const LookupEntry lockingEntries[] = {
1102 {"true", XkbKB_Lock},
1103 {"yes", XkbKB_Lock},
1105 {"false", XkbKB_Default},
1106 {"no", XkbKB_Default},
1107 {"off", XkbKB_Default},
1108 {"permanent", XkbKB_Lock | XkbKB_Permanent},
1112 static const LookupEntry repeatEntries[] = {
1113 {"true", RepeatYes},
1116 {"false", RepeatNo},
1119 {"default", RepeatUndefined},
1124 SetSymbolsField(KeyInfo *key, struct xkb_keymap *keymap, char *field,
1125 ExprDef *arrayNdx, ExprDef *value, SymbolsInfo *info)
1130 if (strcasecmp(field, "type") == 0)
1133 if ((!ExprResolveString(keymap->ctx, value, &tmp))
1134 && (warningLevel > 0))
1136 WARN("The type field of a key symbol map must be a string\n");
1137 ACTION("Ignoring illegal type definition\n");
1139 if (arrayNdx == NULL)
1141 key->dfltType = xkb_atom_intern(keymap->ctx, tmp.str);
1142 key->defs.defined |= _Key_Type_Dflt;
1144 else if (!ExprResolveGroup(keymap->ctx, arrayNdx, &ndx))
1146 ERROR("Illegal group index for type of key %s\n",
1147 longText(key->name));
1148 ACTION("Definition with non-integer array index ignored\n");
1154 key->types[ndx.uval - 1] = xkb_atom_intern(keymap->ctx, tmp.str);
1155 key->typesDefined |= (1 << (ndx.uval - 1));
1159 else if (strcasecmp(field, "symbols") == 0)
1160 return AddSymbolsToKey(key, keymap, arrayNdx, value, info);
1161 else if (strcasecmp(field, "actions") == 0)
1162 return AddActionsToKey(key, keymap, arrayNdx, value, info);
1163 else if ((strcasecmp(field, "vmods") == 0) ||
1164 (strcasecmp(field, "virtualmods") == 0) ||
1165 (strcasecmp(field, "virtualmodifiers") == 0))
1167 ok = ExprResolveVModMask(value, &tmp, keymap);
1170 key->vmodmap = (tmp.uval >> 8);
1171 key->defs.defined |= _Key_VModMap;
1175 ERROR("Expected a virtual modifier mask, found %s\n",
1176 exprOpText(value->op));
1177 ACTION("Ignoring virtual modifiers definition for key %s\n",
1178 longText(key->name));
1181 else if ((strcasecmp(field, "locking") == 0) ||
1182 (strcasecmp(field, "lock") == 0) ||
1183 (strcasecmp(field, "locks") == 0))
1185 ok = ExprResolveEnum(keymap->ctx, value, &tmp, lockingEntries);
1187 key->behavior.type = tmp.uval;
1188 key->defs.defined |= _Key_Behavior;
1190 else if ((strcasecmp(field, "radiogroup") == 0) ||
1191 (strcasecmp(field, "permanentradiogroup") == 0) ||
1192 (strcasecmp(field, "allownone") == 0))
1194 ERROR("Radio groups not supported\n");
1195 ACTION("Ignoring radio group specification for key %s\n", longText(key->name));
1198 else if (uStrCasePrefix("overlay", field) ||
1199 uStrCasePrefix("permanentoverlay", field))
1201 ERROR("Overlays not supported\n");
1202 ACTION("Ignoring overlay specification for key %s\n", longText(key->name));
1204 else if ((strcasecmp(field, "repeating") == 0) ||
1205 (strcasecmp(field, "repeats") == 0) ||
1206 (strcasecmp(field, "repeat") == 0))
1208 ok = ExprResolveEnum(keymap->ctx, value, &tmp, repeatEntries);
1211 ERROR("Illegal repeat setting for %s\n",
1212 longText(key->name));
1213 ACTION("Non-boolean repeat setting ignored\n");
1216 key->repeat = tmp.uval;
1217 key->defs.defined |= _Key_Repeat;
1219 else if ((strcasecmp(field, "groupswrap") == 0) ||
1220 (strcasecmp(field, "wrapgroups") == 0))
1222 ok = ExprResolveBoolean(keymap->ctx, value, &tmp);
1225 ERROR("Illegal groupsWrap setting for %s\n",
1226 longText(key->name));
1227 ACTION("Non-boolean value ignored\n");
1231 key->groupInfo = XkbWrapIntoRange;
1233 key->groupInfo = XkbClampIntoRange;
1234 key->defs.defined |= _Key_GroupInfo;
1236 else if ((strcasecmp(field, "groupsclamp") == 0) ||
1237 (strcasecmp(field, "clampgroups") == 0))
1239 ok = ExprResolveBoolean(keymap->ctx, value, &tmp);
1242 ERROR("Illegal groupsClamp setting for %s\n",
1243 longText(key->name));
1244 ACTION("Non-boolean value ignored\n");
1248 key->groupInfo = XkbClampIntoRange;
1250 key->groupInfo = XkbWrapIntoRange;
1251 key->defs.defined |= _Key_GroupInfo;
1253 else if ((strcasecmp(field, "groupsredirect") == 0) ||
1254 (strcasecmp(field, "redirectgroups") == 0))
1256 if (!ExprResolveGroup(keymap->ctx, value, &tmp))
1258 ERROR("Illegal group index for redirect of key %s\n",
1259 longText(key->name));
1260 ACTION("Definition with non-integer group ignored\n");
1264 XkbSetGroupInfo(0, XkbRedirectIntoRange, tmp.uval - 1);
1265 key->defs.defined |= _Key_GroupInfo;
1269 ERROR("Unknown field %s in a symbol interpretation\n", field);
1270 ACTION("Definition ignored\n");
1277 SetGroupName(SymbolsInfo *info, struct xkb_keymap *keymap, ExprDef *arrayNdx,
1280 ExprResult tmp, name;
1282 if ((arrayNdx == NULL) && (warningLevel > 0))
1284 WARN("You must specify an index when specifying a group name\n");
1285 ACTION("Group name definition without array subscript ignored\n");
1288 if (!ExprResolveGroup(keymap->ctx, arrayNdx, &tmp))
1290 ERROR("Illegal index in group name definition\n");
1291 ACTION("Definition with non-integer array index ignored\n");
1294 if (!ExprResolveString(keymap->ctx, value, &name))
1296 ERROR("Group name must be a string\n");
1297 ACTION("Illegal name for group %d ignored\n", tmp.uval);
1300 info->groupNames[tmp.uval - 1 + info->explicit_group] =
1301 xkb_atom_intern(keymap->ctx, name.str);
1308 HandleSymbolsVar(VarDef *stmt, struct xkb_keymap *keymap, SymbolsInfo *info)
1310 ExprResult elem, field;
1314 if (ExprResolveLhs(keymap, stmt->name, &elem, &field, &arrayNdx) == 0)
1315 return 0; /* internal error, already reported */
1316 if (elem.str && (strcasecmp(elem.str, "key") == 0))
1318 ret = SetSymbolsField(&info->dflt, keymap, field.str, arrayNdx,
1321 else if ((elem.str == NULL) && ((strcasecmp(field.str, "name") == 0) ||
1322 (strcasecmp(field.str, "groupname") ==
1325 ret = SetGroupName(info, keymap, arrayNdx, stmt->value);
1327 else if ((elem.str == NULL)
1328 && ((strcasecmp(field.str, "groupswrap") == 0) ||
1329 (strcasecmp(field.str, "wrapgroups") == 0)))
1331 ERROR("Global \"groupswrap\" not supported\n");
1332 ACTION("Ignored\n");
1335 else if ((elem.str == NULL)
1336 && ((strcasecmp(field.str, "groupsclamp") == 0) ||
1337 (strcasecmp(field.str, "clampgroups") == 0)))
1339 ERROR("Global \"groupsclamp\" not supported\n");
1340 ACTION("Ignored\n");
1343 else if ((elem.str == NULL)
1344 && ((strcasecmp(field.str, "groupsredirect") == 0) ||
1345 (strcasecmp(field.str, "redirectgroups") == 0)))
1347 ERROR("Global \"groupsredirect\" not supported\n");
1348 ACTION("Ignored\n");
1351 else if ((elem.str == NULL) && (strcasecmp(field.str, "allownone") == 0))
1353 ERROR("Radio groups not supported\n");
1354 ACTION("Ignoring \"allownone\" specification\n");
1358 ret = SetActionField(keymap, elem.str, field.str, arrayNdx,
1359 stmt->value, &info->action);
1368 HandleSymbolsBody(VarDef *def, struct xkb_keymap *keymap, KeyInfo *key,
1372 ExprResult tmp, field;
1375 for (; def != NULL; def = (VarDef *) def->common.next)
1377 if ((def->name) && (def->name->type == ExprFieldRef))
1379 ok = HandleSymbolsVar(def, keymap, info);
1384 if (def->name == NULL)
1386 if ((def->value == NULL)
1387 || (def->value->op == ExprKeysymList))
1388 field.str = strdup("symbols");
1390 field.str = strdup("actions");
1395 ok = ExprResolveLhs(keymap, def->name, &tmp, &field,
1399 ok = SetSymbolsField(key, keymap, field.str, arrayNdx,
1408 SetExplicitGroup(SymbolsInfo *info, KeyInfo *key)
1410 unsigned group = info->explicit_group;
1415 if ((key->typesDefined | key->symsDefined | key->actsDefined) & ~1)
1418 WARN("For the map %s an explicit group specified\n", info->name);
1419 WARN("but key %s has more than one group defined\n",
1420 longText(key->name));
1421 ACTION("All groups except first one will be ignored\n");
1422 for (i = 1; i < XkbNumKbdGroups; i++)
1424 key->numLevels[i] = 0;
1425 darray_free(key->syms[i]);
1427 key->acts[i] = NULL;
1431 key->typesDefined = key->symsDefined = key->actsDefined = 1 << group;
1433 key->numLevels[group] = key->numLevels[0];
1434 key->numLevels[0] = 0;
1435 key->syms[group] = key->syms[0];
1436 darray_init(key->syms[0]);
1437 key->symsMapIndex[group] = key->symsMapIndex[0];
1438 darray_init(key->symsMapIndex[0]);
1439 key->symsMapNumEntries[group] = key->symsMapNumEntries[0];
1440 darray_init(key->symsMapNumEntries[0]);
1441 key->acts[group] = key->acts[0];
1442 key->acts[0] = NULL;
1443 key->types[group] = key->types[0];
1449 HandleSymbolsDef(SymbolsDef *stmt, struct xkb_keymap *keymap,
1455 CopyKeyInfo(&info->dflt, &key, false);
1456 key.defs.merge = stmt->merge;
1457 key.name = KeyNameToLong(stmt->keyName);
1458 if (!HandleSymbolsBody((VarDef *) stmt->symbols, keymap, &key, info))
1464 if (!SetExplicitGroup(info, &key))
1470 if (!AddKeySymbols(info, &key, keymap))
1479 HandleModMapDef(ModMapDef *def, struct xkb_keymap *keymap, SymbolsInfo *info)
1486 if (!LookupModIndex(keymap->ctx, NULL, def->modifier, TypeInt, &rtrn))
1488 ERROR("Illegal modifier map definition\n");
1489 ACTION("Ignoring map for non-modifier \"%s\"\n",
1490 xkb_atom_text(keymap->ctx, def->modifier));
1494 tmp.modifier = rtrn.uval;
1495 for (key = def->keys; key != NULL; key = (ExprDef *) key->common.next)
1497 if ((key->op == ExprValue) && (key->type == TypeKeyName))
1499 tmp.haveSymbol = false;
1500 tmp.u.keyName = KeyNameToLong(key->value.keyName);
1502 else if (ExprResolveKeySym(keymap->ctx, key, &rtrn))
1504 tmp.haveSymbol = true;
1505 tmp.u.keySym = rtrn.uval;
1509 ERROR("Modmap entries may contain only key names or keysyms\n");
1510 ACTION("Illegal definition for %s modifier ignored\n",
1511 XkbcModIndexText(tmp.modifier));
1515 ok = AddModMapEntry(info, &tmp) && ok;
1521 HandleSymbolsFile(XkbFile *file, struct xkb_keymap *keymap,
1522 unsigned merge, SymbolsInfo *info)
1527 info->name = uDupString(file->name);
1531 switch (stmt->stmtType)
1534 if (!HandleIncludeSymbols((IncludeStmt *) stmt, keymap, info))
1537 case StmtSymbolsDef:
1538 if (!HandleSymbolsDef((SymbolsDef *) stmt, keymap, info))
1542 if (!HandleSymbolsVar((VarDef *) stmt, keymap, info))
1546 if (!HandleVModDef((VModDef *) stmt, keymap, merge, &info->vmods))
1550 ERROR("Interpretation files may not include other types\n");
1551 ACTION("Ignoring definition of symbol interpretation\n");
1554 case StmtKeycodeDef:
1555 ERROR("Interpretation files may not include other types\n");
1556 ACTION("Ignoring definition of key name\n");
1560 if (!HandleModMapDef((ModMapDef *) stmt, keymap, info))
1564 WSGO("Unexpected statement type %d in HandleSymbolsFile\n",
1569 if (info->errorCount > 10)
1572 ERROR("Too many errors\n");
1574 ACTION("Abandoning symbols file \"%s\"\n", file->topName);
1581 FindKeyForSymbol(struct xkb_keymap *keymap, xkb_keysym_t sym,
1582 xkb_keycode_t *kc_rtrn)
1585 unsigned int group, level;
1587 for (key = keymap->min_key_code; key <= keymap->max_key_code; key++)
1589 for (group = 0; group < XkbKeyNumGroups(keymap, key); group++)
1591 for (level = 0; level < XkbKeyGroupWidth(keymap, key, group);
1594 if (XkbKeyNumSyms(keymap, key, group, level) != 1 ||
1595 (XkbKeySymEntry(keymap, key, group, level))[0] != sym)
1607 * Find the given name in the keymap->map->types and return its index.
1609 * @param atom The atom to search for.
1610 * @param type_rtrn Set to the index of the name if found.
1612 * @return true if found, false otherwise.
1615 FindNamedType(struct xkb_keymap *keymap, xkb_atom_t atom, unsigned *type_rtrn)
1618 const char *name = xkb_atom_text(keymap->ctx, atom);
1619 struct xkb_key_type *type;
1621 if (keymap && keymap->map) {
1622 darray_foreach(type, keymap->map->types) {
1623 if (strcmp(type->name, name) == 0) {
1634 * Assign a type to the given sym and return the Atom for the type assigned.
1637 * - ONE_LEVEL for width 0/1
1638 * - ALPHABETIC for 2 shift levels, with lower/upercase
1639 * - KEYPAD for keypad keys.
1640 * - TWO_LEVEL for other 2 shift level keys.
1641 * and the same for four level keys.
1643 * @param width Number of sysms in syms.
1644 * @param syms The keysyms for the given key (must be size width).
1645 * @param typeNameRtrn Set to the Atom of the type name.
1647 * @returns true if a type could be found, false otherwise.
1650 FindAutomaticType(struct xkb_keymap *keymap, int width,
1651 const xkb_keysym_t *syms, xkb_atom_t *typeNameRtrn,
1655 if ((width == 1) || (width == 0))
1657 *typeNameRtrn = xkb_atom_intern(keymap->ctx, "ONE_LEVEL");
1660 else if (width == 2)
1662 if (syms && XkbcKSIsLower(syms[0]) && XkbcKSIsUpper(syms[1]))
1664 *typeNameRtrn = xkb_atom_intern(keymap->ctx, "ALPHABETIC");
1666 else if (syms && (XkbKSIsKeypad(syms[0]) || XkbKSIsKeypad(syms[1])))
1668 *typeNameRtrn = xkb_atom_intern(keymap->ctx, "KEYPAD");
1673 *typeNameRtrn = xkb_atom_intern(keymap->ctx, "TWO_LEVEL");
1677 else if (width <= 4)
1679 if (syms && XkbcKSIsLower(syms[0]) && XkbcKSIsUpper(syms[1]))
1680 if (XkbcKSIsLower(syms[2]) && XkbcKSIsUpper(syms[3]))
1682 xkb_atom_intern(keymap->ctx, "FOUR_LEVEL_ALPHABETIC");
1684 *typeNameRtrn = xkb_atom_intern(keymap->ctx,
1685 "FOUR_LEVEL_SEMIALPHABETIC");
1687 else if (syms && (XkbKSIsKeypad(syms[0]) || XkbKSIsKeypad(syms[1])))
1688 *typeNameRtrn = xkb_atom_intern(keymap->ctx, "FOUR_LEVEL_KEYPAD");
1690 *typeNameRtrn = xkb_atom_intern(keymap->ctx, "FOUR_LEVEL");
1691 /* XXX: why not set autoType here? */
1693 return ((width >= 0) && (width <= 4));
1697 * Ensure the given KeyInfo is in a coherent state, i.e. no gaps between the
1698 * groups, and reduce to one group if all groups are identical anyway.
1701 PrepareKeyDef(KeyInfo * key)
1703 int i, j, width, defined, lastGroup;
1706 defined = key->symsDefined | key->actsDefined | key->typesDefined;
1707 /* get highest group number */
1708 for (i = XkbNumKbdGroups - 1; i >= 0; i--)
1710 if (defined & (1 << i))
1718 /* If there are empty groups between non-empty ones fill them with data */
1719 /* from the first group. */
1720 /* We can make a wrong assumption here. But leaving gaps is worse. */
1721 for (i = lastGroup; i > 0; i--)
1723 if (defined & (1 << i))
1725 width = key->numLevels[0];
1726 if (key->typesDefined & 1)
1728 for (j = 0; j < width; j++)
1730 key->types[i] = key->types[0];
1732 key->typesDefined |= 1 << i;
1734 if ((key->actsDefined & 1) && key->acts[0])
1736 key->acts[i] = uTypedCalloc(width, union xkb_action);
1737 if (key->acts[i] == NULL)
1739 memcpy(key->acts[i], key->acts[0],
1740 width * sizeof(union xkb_action));
1741 key->actsDefined |= 1 << i;
1743 if ((key->symsDefined & 1) && !darray_empty(key->syms[0]))
1745 darray_copy(key->syms[i], key->syms[0]);
1746 darray_copy(key->symsMapIndex[i], key->symsMapIndex[0]);
1747 darray_copy(key->symsMapNumEntries[i], key->symsMapNumEntries[0]);
1748 key->symsDefined |= 1 << i;
1752 key->numLevels[i] = key->numLevels[0];
1755 /* If all groups are completely identical remove them all */
1756 /* exept the first one. */
1758 for (i = lastGroup; i > 0; i--)
1760 if ((key->numLevels[i] != key->numLevels[0]) ||
1761 (key->types[i] != key->types[0]))
1766 if (!darray_same(key->syms[i], key->syms[0]) &&
1767 (darray_empty(key->syms[i]) || darray_empty(key->syms[0]) ||
1768 darray_size(key->syms[i]) != darray_size(key->syms[0]) ||
1769 memcmp(darray_mem(key->syms[i], 0),
1770 darray_mem(key->syms[0], 0),
1771 sizeof(xkb_keysym_t) * darray_size(key->syms[0]))))
1776 if (!darray_same(key->symsMapIndex[i], key->symsMapIndex[0]) &&
1777 (darray_empty(key->symsMapIndex[i]) ||
1778 darray_empty(key->symsMapIndex[0]) ||
1779 memcmp(darray_mem(key->symsMapIndex[i], 0),
1780 darray_mem(key->symsMapIndex[0], 0),
1781 key->numLevels[0] * sizeof(int))))
1786 if (!darray_same(key->symsMapNumEntries[i], key->symsMapNumEntries[0]) &&
1787 (darray_empty(key->symsMapNumEntries[i]) ||
1788 darray_empty(key->symsMapNumEntries[0]) ||
1789 memcmp(darray_mem(key->symsMapNumEntries[i], 0),
1790 darray_mem(key->symsMapNumEntries[0], 0),
1791 key->numLevels[0] * sizeof(size_t))))
1796 if ((key->acts[i] != key->acts[0]) &&
1797 (key->acts[i] == NULL || key->acts[0] == NULL ||
1798 memcmp(key->acts[i], key->acts[0],
1799 sizeof(union xkb_action) * key->numLevels[0])))
1807 for (i = lastGroup; i > 0; i--)
1809 key->numLevels[i] = 0;
1810 darray_free(key->syms[i]);
1811 darray_free(key->symsMapIndex[i]);
1812 darray_free(key->symsMapNumEntries[i]);
1814 key->acts[i] = NULL;
1817 key->symsDefined &= 1;
1818 key->actsDefined &= 1;
1819 key->typesDefined &= 1;
1824 * Copy the KeyInfo into the keyboard description.
1826 * This function recurses.
1829 CopySymbolsDef(struct xkb_keymap *keymap, KeyInfo *key, int start_from)
1833 unsigned int sizeSyms = 0;
1834 unsigned width, tmp, nGroups;
1835 struct xkb_key_type * type;
1836 bool haveActions, autoType, useAlias;
1837 unsigned types[XkbNumKbdGroups];
1838 union xkb_action *outActs;
1839 unsigned int symIndex = 0;
1840 struct xkb_sym_map *sym_map;
1842 useAlias = (start_from == 0);
1844 /* get the keycode for the key. */
1845 if (!FindNamedKey(keymap, key->name, &kc, useAlias,
1846 CreateKeyNames(keymap), start_from))
1848 if ((start_from == 0) && (warningLevel >= 5))
1850 WARN("Key %s not found in keycodes\n", longText(key->name));
1851 ACTION("Symbols ignored\n");
1856 haveActions = false;
1857 for (i = width = nGroups = 0; i < XkbNumKbdGroups; i++)
1859 if (((i + 1) > nGroups)
1860 && (((key->symsDefined | key->actsDefined) & (1 << i))
1861 || (key->typesDefined) & (1 << i)))
1866 /* Assign the type to the key, if it is missing. */
1867 if (key->types[i] == XKB_ATOM_NONE)
1869 if (key->dfltType != XKB_ATOM_NONE)
1870 key->types[i] = key->dfltType;
1871 else if (FindAutomaticType(keymap, key->numLevels[i],
1872 darray_mem(key->syms[i], 0),
1873 &key->types[i], &autoType))
1878 if (warningLevel >= 5)
1880 WARN("No automatic type for %d symbols\n",
1881 (unsigned int) key->numLevels[i]);
1882 ACTION("Using %s for the %s key (keycode %d)\n",
1883 xkb_atom_text(keymap->ctx, key->types[i]),
1884 longText(key->name), kc);
1888 if (FindNamedType(keymap, key->types[i], &types[i]))
1890 if (!autoType || key->numLevels[i] > 2)
1891 keymap->server->explicit[kc] |= (1 << i);
1895 if (warningLevel >= 3)
1897 WARN("Type \"%s\" is not defined\n",
1898 xkb_atom_text(keymap->ctx, key->types[i]));
1899 ACTION("Using TWO_LEVEL for the %s key (keycode %d)\n",
1900 longText(key->name), kc);
1902 types[i] = XkbTwoLevelIndex;
1904 /* if the type specifies fewer levels than the key has, shrink the key */
1905 type = &darray_item(keymap->map->types, types[i]);
1906 if (type->num_levels < key->numLevels[i])
1908 if (warningLevel > 0)
1910 WARN("Type \"%s\" has %d levels, but %s has %d symbols\n",
1911 type->name, type->num_levels,
1912 xkb_atom_text(keymap->ctx, key->name), key->numLevels[i]);
1913 ACTION("Ignoring extra symbols\n");
1915 key->numLevels[i] = type->num_levels;
1917 if (key->numLevels[i] > width)
1918 width = key->numLevels[i];
1919 if (type->num_levels > width)
1920 width = type->num_levels;
1921 sizeSyms += darray_size(key->syms[i]);
1924 if (!XkbcResizeKeySyms(keymap, kc, sizeSyms))
1926 WSGO("Could not enlarge symbols for %s (keycode %d)\n",
1927 longText(key->name), kc);
1932 outActs = XkbcResizeKeyActions(keymap, kc, width * nGroups);
1933 if (outActs == NULL)
1935 WSGO("Could not enlarge actions for %s (key %d)\n",
1936 longText(key->name), kc);
1939 keymap->server->explicit[kc] |= XkbExplicitInterpretMask;
1944 sym_map = &darray_item(keymap->map->key_sym_map, kc);
1946 if (key->defs.defined & _Key_GroupInfo)
1949 i = sym_map->group_info;
1951 sym_map->group_info = XkbSetNumGroups(i, nGroups);
1952 sym_map->width = width;
1953 sym_map->sym_index = uTypedCalloc(nGroups * width, int);
1954 sym_map->num_syms = uTypedCalloc(nGroups * width, unsigned int);
1956 for (i = 0; i < nGroups; i++)
1958 /* assign kt_index[i] to the index of the type in map->types.
1959 * kt_index[i] may have been set by a previous run (if we have two
1960 * layouts specified). Let's not overwrite it with the ONE_LEVEL
1961 * default group if we dont even have keys for this group anyway.
1963 * FIXME: There should be a better fix for this.
1965 if (key->numLevels[i])
1966 sym_map->kt_index[i] = types[i];
1967 if (!darray_empty(key->syms[i]))
1969 /* fill key to "width" symbols*/
1970 for (tmp = 0; tmp < width; tmp++)
1972 if (tmp < key->numLevels[i] &&
1973 darray_item(key->symsMapNumEntries[i], tmp) != 0)
1975 memcpy(&sym_map->syms[symIndex],
1976 darray_mem(key->syms[i],
1977 darray_item(key->symsMapIndex[i], tmp)),
1978 darray_item(key->symsMapNumEntries[i], tmp) * sizeof(xkb_keysym_t));
1979 sym_map->sym_index[(i * width) + tmp] = symIndex;
1980 sym_map->num_syms[(i * width) + tmp] =
1981 darray_item(key->symsMapNumEntries[i], tmp);
1982 symIndex += sym_map->num_syms[(i * width) + tmp];
1986 sym_map->sym_index[(i * width) + tmp] = -1;
1987 sym_map->num_syms[(i * width) + tmp] = 0;
1989 if ((outActs != NULL) && (key->acts[i] != NULL))
1991 if (tmp < key->numLevels[i])
1992 outActs[tmp] = key->acts[i][tmp];
1994 outActs[tmp].type = XkbSA_NoAction;
1999 switch (key->behavior.type & XkbKB_OpMask)
2004 keymap->server->behaviors[kc] = key->behavior;
2005 keymap->server->explicit[kc] |= XkbExplicitBehaviorMask;
2008 if (key->defs.defined & _Key_VModMap)
2010 keymap->server->vmodmap[kc] = key->vmodmap;
2011 keymap->server->explicit[kc] |= XkbExplicitVModMapMask;
2013 if (key->repeat != RepeatUndefined)
2015 if (key->repeat == RepeatYes)
2016 keymap->ctrls->per_key_repeat[kc / 8] |= (1 << (kc % 8));
2018 keymap->ctrls->per_key_repeat[kc / 8] &= ~(1 << (kc % 8));
2019 keymap->server->explicit[kc] |= XkbExplicitAutoRepeatMask;
2022 if (nGroups > keymap->ctrls->num_groups)
2023 keymap->ctrls->num_groups = nGroups;
2025 /* do the same thing for the next key */
2026 CopySymbolsDef(keymap, key, kc + 1);
2031 CopyModMapDef(struct xkb_keymap *keymap, ModMapEntry *entry)
2035 if (!entry->haveSymbol &&
2036 !FindNamedKey(keymap, entry->u.keyName, &kc, true,
2037 CreateKeyNames(keymap), 0))
2039 if (warningLevel >= 5)
2041 WARN("Key %s not found in keycodes\n",
2042 longText(entry->u.keyName));
2043 ACTION("Modifier map entry for %s not updated\n",
2044 XkbcModIndexText(entry->modifier));
2048 else if (entry->haveSymbol &&
2049 !FindKeyForSymbol(keymap, entry->u.keySym, &kc))
2051 if (warningLevel > 5)
2053 WARN("Key \"%s\" not found in symbol map\n",
2054 XkbcKeysymText(entry->u.keySym));
2055 ACTION("Modifier map entry for %s not updated\n",
2056 XkbcModIndexText(entry->modifier));
2060 keymap->map->modmap[kc] |= (1 << entry->modifier);
2065 * Handle the xkb_symbols section of an xkb file.
2067 * @param file The parsed xkb_symbols section of the xkb file.
2068 * @param keymap Handle to the keyboard description to store the symbols in.
2069 * @param merge Merge strategy (e.g. MergeOverride).
2072 CompileSymbols(XkbFile *file, struct xkb_keymap *keymap, unsigned merge)
2078 InitSymbolsInfo(&info, keymap);
2079 info.dflt.defs.fileID = file->id;
2080 info.dflt.defs.merge = merge;
2082 HandleSymbolsFile(file, keymap, merge, &info);
2084 if (darray_empty(info.keys))
2087 if (info.errorCount != 0)
2090 /* alloc memory in the xkb struct */
2091 if (XkbcAllocNames(keymap, XkbGroupNamesMask, 0) != Success) {
2092 WSGO("Can not allocate names in CompileSymbols\n");
2093 ACTION("Symbols not added\n");
2097 if (XkbcAllocClientMap(keymap, XkbKeySymsMask | XkbModifierMapMask, 0)
2099 WSGO("Could not allocate client map in CompileSymbols\n");
2100 ACTION("Symbols not added\n");
2104 if (XkbcAllocServerMap(keymap, XkbAllServerInfoMask, 32) != Success) {
2105 WSGO("Could not allocate server map in CompileSymbols\n");
2106 ACTION("Symbols not added\n");
2110 if (XkbcAllocControls(keymap) != Success) {
2111 WSGO("Could not allocate controls in CompileSymbols\n");
2112 ACTION("Symbols not added\n");
2116 /* now copy info into xkb. */
2117 ApplyAliases(keymap, &info.aliases);
2119 for (i = 0; i < XkbNumKbdGroups; i++) {
2120 if (info.groupNames[i] != XKB_ATOM_NONE) {
2121 free(keymap->names->groups[i]);
2122 keymap->names->groups[i] = xkb_atom_strdup(keymap->ctx,
2123 info.groupNames[i]);
2128 darray_foreach(key, info.keys)
2132 darray_foreach(key, info.keys)
2133 if (!CopySymbolsDef(keymap, key, 0))
2136 if (warningLevel > 3) {
2137 for (i = keymap->min_key_code; i <= keymap->max_key_code; i++) {
2138 if (darray_item(keymap->names->keys, i).name[0] == '\0')
2141 if (XkbKeyNumGroups(keymap, i) < 1) {
2143 memcpy(buf, darray_item(keymap->names->keys, i).name, 4);
2145 WARN("No symbols defined for <%s> (keycode %d)\n", buf, i);
2151 ModMapEntry *mm, *next;
2152 for (mm = info.modMap; mm != NULL; mm = next) {
2153 if (!CopyModMapDef(keymap, mm))
2155 next = (ModMapEntry *) mm->defs.next;
2159 FreeSymbolsInfo(&info);
2163 FreeSymbolsInfo(&info);