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;
38 typedef darray(union xkb_action) darray_xkb_action;
42 #define RepeatUndefined ~((unsigned)0)
44 #define _Key_Syms (1<<0)
45 #define _Key_Acts (1<<1)
46 #define _Key_Repeat (1<<2)
47 #define _Key_Behavior (1<<3)
48 #define _Key_Type_Dflt (1<<4)
49 #define _Key_Types (1<<5)
50 #define _Key_GroupInfo (1<<6)
51 #define _Key_VModMap (1<<7)
53 typedef struct _KeyInfo
56 unsigned long name; /* the 4 chars of the key name, as long */
57 unsigned char groupInfo;
58 unsigned char typesDefined;
59 unsigned char symsDefined;
60 unsigned char actsDefined;
61 unsigned int numLevels[XkbNumKbdGroups];
63 /* syms[group] -> Single array for all the keysyms in the group. */
64 darray_xkb_keysym_t syms[XkbNumKbdGroups];
66 * symsMapIndex[group][level] -> The index from which the syms for
67 * the level begin in the syms[group] array. Remember each keycode
68 * can have multiple keysyms in each level (that is, each key press
69 * can result in multiple keysyms).
71 darray(int) symsMapIndex[XkbNumKbdGroups];
73 * symsMapNumEntries[group][level] -> How many syms are in
74 * syms[group][symsMapIndex[group][level]].
76 darray(size_t) symsMapNumEntries[XkbNumKbdGroups];
78 darray_xkb_action acts[XkbNumKbdGroups];
80 xkb_atom_t types[XkbNumKbdGroups];
82 struct xkb_behavior behavior;
83 unsigned short vmodmap;
88 * Init the given key info to sane values.
91 InitKeyInfo(KeyInfo * info)
94 static const char dflt[4] = "*";
96 info->defs.defined = 0;
97 info->defs.fileID = 0;
98 info->defs.merge = MergeOverride;
99 info->defs.next = NULL;
100 info->name = KeyNameToLong(dflt);
102 info->typesDefined = info->symsDefined = info->actsDefined = 0;
103 for (i = 0; i < XkbNumKbdGroups; i++)
105 info->numLevels[i] = 0;
106 info->types[i] = XKB_ATOM_NONE;
107 darray_init(info->syms[i]);
108 darray_init(info->symsMapIndex[i]);
109 darray_init(info->symsMapNumEntries[i]);
110 darray_init(info->acts[i]);
112 info->dfltType = XKB_ATOM_NONE;
113 info->behavior.type = XkbKB_Default;
114 info->behavior.data = 0;
116 info->repeat = RepeatUndefined;
120 * Free memory associated with this key info and reset to sane values.
123 FreeKeyInfo(KeyInfo * info)
127 info->defs.defined = 0;
128 info->defs.fileID = 0;
129 info->defs.merge = MergeOverride;
130 info->defs.next = NULL;
132 info->typesDefined = info->symsDefined = info->actsDefined = 0;
133 for (i = 0; i < XkbNumKbdGroups; i++)
135 info->numLevels[i] = 0;
136 info->types[i] = XKB_ATOM_NONE;
137 darray_free(info->syms[i]);
138 darray_free(info->symsMapIndex[i]);
139 darray_free(info->symsMapNumEntries[i]);
140 darray_free(info->acts[i]);
142 info->dfltType = XKB_ATOM_NONE;
143 info->behavior.type = XkbKB_Default;
144 info->behavior.data = 0;
146 info->repeat = RepeatUndefined;
150 * Copy old into new, optionally reset old to 0.
151 * If old is reset, new simply re-uses old's memory. Otherwise, the memory is
152 * newly allocated and new points to the new memory areas.
155 CopyKeyInfo(KeyInfo * old, KeyInfo * new, bool clearOld)
160 new->defs.next = NULL;
163 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]);
168 darray_init(old->acts[i]);
172 for (i = 0; i < XkbNumKbdGroups; i++) {
173 darray_copy(new->syms[i], old->syms[i]);
174 darray_copy(new->symsMapIndex[i], old->symsMapIndex[i]);
175 darray_copy(new->symsMapNumEntries[i], old->symsMapNumEntries[i]);
176 darray_copy(new->acts[i], old->acts[i]);
183 /***====================================================================***/
185 typedef struct _ModMapEntry
192 unsigned long keyName;
197 typedef struct _SymbolsInfo
199 char *name; /* e.g. pc+us+inet(evdev) */
203 unsigned explicit_group;
204 darray(KeyInfo) keys;
208 xkb_atom_t groupNames[XkbNumKbdGroups];
215 InitSymbolsInfo(SymbolsInfo * info, struct xkb_keymap *keymap)
220 info->explicit_group = 0;
221 info->errorCount = 0;
223 info->merge = MergeOverride;
224 darray_init(info->keys);
225 darray_growalloc(info->keys, 110);
227 for (i = 0; i < XkbNumKbdGroups; i++)
228 info->groupNames[i] = XKB_ATOM_NONE;
229 InitKeyInfo(&info->dflt);
230 InitVModInfo(&info->vmods, keymap);
232 info->aliases = NULL;
236 FreeSymbolsInfo(SymbolsInfo * info)
241 darray_foreach(key, info->keys)
243 darray_free(info->keys);
245 ClearCommonInfo(&info->modMap->defs);
247 ClearAliases(&info->aliases);
248 memset(info, 0, sizeof(SymbolsInfo));
252 ResizeKeyGroup(KeyInfo * key, unsigned int group, unsigned int numLevels,
253 unsigned sizeSyms, bool forceActions)
257 if (darray_size(key->syms[group]) < sizeSyms)
258 darray_resize0(key->syms[group], sizeSyms);
260 if (darray_empty(key->symsMapIndex[group]) ||
261 key->numLevels[group] < numLevels) {
262 darray_resize(key->symsMapIndex[group], numLevels);
263 for (i = key->numLevels[group]; i < numLevels; i++)
264 darray_item(key->symsMapIndex[group], i) = -1;
267 if (darray_empty(key->symsMapNumEntries[group]) ||
268 key->numLevels[group] < numLevels)
269 darray_resize0(key->symsMapNumEntries[group], numLevels);
271 if ((forceActions && (key->numLevels[group] < numLevels ||
272 darray_empty(key->acts[group]))) ||
273 (key->numLevels[group] < numLevels && !darray_empty(key->acts[group])))
274 darray_resize0(key->acts[group], numLevels);
276 if (key->numLevels[group] < numLevels)
277 key->numLevels[group] = numLevels;
282 enum key_group_selector {
289 MergeKeyGroups(SymbolsInfo * info,
290 KeyInfo * into, KeyInfo * from, unsigned group)
292 darray_xkb_keysym_t resultSyms;
293 enum key_group_selector using = NONE;
294 darray_xkb_action resultActs;
295 unsigned int resultWidth;
296 unsigned int resultSize = 0;
299 bool report, clobber;
301 clobber = (from->defs.merge != MergeAugment);
303 report = (warningLevel > 9) ||
304 ((into->defs.fileID == from->defs.fileID) && (warningLevel > 0));
306 darray_init(resultSyms);
308 if (into->numLevels[group] >= from->numLevels[group])
310 resultActs = into->acts[group];
311 resultWidth = into->numLevels[group];
315 resultActs = from->acts[group];
316 resultWidth = from->numLevels[group];
317 darray_resize(into->symsMapIndex[group],
318 from->numLevels[group]);
319 darray_resize0(into->symsMapNumEntries[group],
320 from->numLevels[group]);
322 for (i = into->numLevels[group]; i < from->numLevels[group]; i++)
323 darray_item(into->symsMapIndex[group], i) = -1;
326 if (darray_empty(resultActs) && (!darray_empty(into->acts[group]) ||
327 !darray_empty(from->acts[group])))
329 darray_resize0(resultActs, resultWidth);
330 for (i = 0; i < resultWidth; i++)
332 union xkb_action *fromAct = NULL, *toAct = NULL;
334 if (!darray_empty(from->acts[group]))
335 fromAct = &darray_item(from->acts[group], i);
337 if (!darray_empty(into->acts[group]))
338 toAct = &darray_item(into->acts[group], i);
340 if (((fromAct == NULL) || (fromAct->type == XkbSA_NoAction))
343 darray_item(resultActs, i) = *toAct;
345 else if (((toAct == NULL) || (toAct->type == XkbSA_NoAction))
346 && (fromAct != NULL))
348 darray_item(resultActs, i) = *fromAct;
352 union xkb_action *use, *ignore;
366 ("Multiple actions for level %d/group %d on key %s\n",
367 i + 1, group + 1, longText(into->name));
368 ACTION("Using %s, ignoring %s\n",
369 XkbcActionTypeText(use->type),
370 XkbcActionTypeText(ignore->type));
373 darray_item(resultActs, i) = *use;
378 for (i = 0; i < resultWidth; i++)
380 unsigned int fromSize = 0;
383 if (!darray_empty(from->symsMapNumEntries[group]) &&
384 i < from->numLevels[group])
385 fromSize = darray_item(from->symsMapNumEntries[group], i);
387 if (!darray_empty(into->symsMapNumEntries[group]) &&
388 i < into->numLevels[group])
389 toSize = darray_item(into->symsMapNumEntries[group], i);
393 resultSize += toSize;
396 else if (toSize == 0 || clobber)
398 resultSize += fromSize;
403 resultSize += toSize;
413 resultSyms = from->syms[group];
416 else if (using == TO)
418 resultSyms = into->syms[group];
422 darray_resize0(resultSyms, resultSize);
424 for (i = 0; i < resultWidth; i++)
426 enum key_group_selector use = NONE;
427 unsigned int fromSize = 0;
428 unsigned int toSize = 0;
430 if (i < from->numLevels[group])
431 fromSize = darray_item(from->symsMapNumEntries[group], i);
433 if (i < into->numLevels[group])
434 toSize = darray_item(into->symsMapNumEntries[group], i);
436 if (fromSize == 0 && toSize == 0)
438 darray_item(into->symsMapIndex[group], i) = -1;
439 darray_item(into->symsMapNumEntries[group], i) = 0;
445 else if (toSize == 0 || clobber)
450 if (toSize && fromSize && report)
452 INFO("Multiple symbols for group %d, level %d on key %s\n",
453 group + 1, i + 1, longText(into->name));
454 ACTION("Using %s, ignoring %s\n",
455 (use == FROM ? "from" : "to"),
456 (use == FROM ? "to" : "from"));
461 memcpy(darray_mem(resultSyms, cur_idx),
462 darray_mem(from->syms[group],
463 darray_item(from->symsMapIndex[group], i)),
464 darray_item(from->symsMapNumEntries[group], i) * sizeof(xkb_keysym_t));
465 darray_item(into->symsMapIndex[group], i) = cur_idx;
466 darray_item(into->symsMapNumEntries[group], i) =
467 darray_item(from->symsMapNumEntries[group], i);
471 memcpy(darray_mem(resultSyms, cur_idx),
472 darray_mem(into->syms[group],
473 darray_item(into->symsMapIndex[group], i)),
474 darray_item(into->symsMapNumEntries[group], i) * sizeof(xkb_keysym_t));
475 darray_item(into->symsMapIndex[group], i) = cur_idx;
477 cur_idx += darray_item(into->symsMapNumEntries[group], i);
481 if (!darray_same(resultActs, into->acts[group]))
482 darray_free(into->acts[group]);
483 if (!darray_same(resultActs, from->acts[group]))
484 darray_free(from->acts[group]);
485 into->numLevels[group] = resultWidth;
486 if (!darray_same(resultSyms, into->syms[group]))
487 darray_free(into->syms[group]);
488 into->syms[group] = resultSyms;
489 if (!darray_same(resultSyms, from->syms[group]))
490 darray_free(from->syms[group]);
491 darray_init(from->syms[group]);
492 darray_free(from->symsMapIndex[group]);
493 darray_free(from->symsMapNumEntries[group]);
494 into->acts[group] = resultActs;
495 darray_init(from->acts[group]);
496 if (!darray_empty(into->syms[group]))
497 into->symsDefined |= (1 << group);
498 from->symsDefined &= ~(1 << group);
499 into->actsDefined |= (1 << group);
500 from->actsDefined &= ~(1 << group);
506 MergeKeys(SymbolsInfo *info, struct xkb_keymap *keymap,
507 KeyInfo *into, KeyInfo *from)
510 unsigned collide = 0;
513 if (from->defs.merge == MergeReplace)
515 for (i = 0; i < XkbNumKbdGroups; i++)
517 if (into->numLevels[i] != 0)
519 darray_free(into->syms[i]);
520 darray_free(into->acts[i]);
524 memset(from, 0, sizeof(KeyInfo));
527 report = ((warningLevel > 9) ||
528 ((into->defs.fileID == from->defs.fileID)
529 && (warningLevel > 0)));
530 for (i = 0; i < XkbNumKbdGroups; i++)
532 if (from->numLevels[i] > 0)
534 if (into->numLevels[i] == 0)
536 into->numLevels[i] = from->numLevels[i];
537 into->syms[i] = from->syms[i];
538 into->symsMapIndex[i] = from->symsMapIndex[i];
539 into->symsMapNumEntries[i] = from->symsMapNumEntries[i];
540 into->acts[i] = from->acts[i];
541 into->symsDefined |= (1 << i);
542 darray_init(from->syms[i]);
543 darray_init(from->symsMapIndex[i]);
544 darray_init(from->symsMapNumEntries[i]);
545 darray_init(from->acts[i]);
546 from->numLevels[i] = 0;
547 from->symsDefined &= ~(1 << i);
548 if (!darray_empty(into->syms[i]))
549 into->defs.defined |= _Key_Syms;
550 if (!darray_empty(into->acts[i]))
551 into->defs.defined |= _Key_Acts;
557 if (!darray_empty(into->syms[i]))
558 collide |= _Key_Syms;
559 if (!darray_empty(into->acts[i]))
560 collide |= _Key_Acts;
562 MergeKeyGroups(info, into, from, (unsigned) i);
565 if (from->types[i] != XKB_ATOM_NONE)
567 if ((into->types[i] != XKB_ATOM_NONE) && report &&
568 (into->types[i] != from->types[i]))
570 xkb_atom_t use, ignore;
571 collide |= _Key_Types;
572 if (from->defs.merge != MergeAugment)
574 use = from->types[i];
575 ignore = into->types[i];
579 use = into->types[i];
580 ignore = from->types[i];
583 ("Multiple definitions for group %d type of key %s\n",
584 i, longText(into->name));
585 ACTION("Using %s, ignoring %s\n",
586 xkb_atom_text(keymap->ctx, use),
587 xkb_atom_text(keymap->ctx, ignore));
589 if ((from->defs.merge != MergeAugment)
590 || (into->types[i] == XKB_ATOM_NONE))
592 into->types[i] = from->types[i];
596 if (UseNewField(_Key_Behavior, &into->defs, &from->defs, &collide))
598 into->behavior = from->behavior;
599 into->defs.defined |= _Key_Behavior;
601 if (UseNewField(_Key_VModMap, &into->defs, &from->defs, &collide))
603 into->vmodmap = from->vmodmap;
604 into->defs.defined |= _Key_VModMap;
606 if (UseNewField(_Key_Repeat, &into->defs, &from->defs, &collide))
608 into->repeat = from->repeat;
609 into->defs.defined |= _Key_Repeat;
611 if (UseNewField(_Key_Type_Dflt, &into->defs, &from->defs, &collide))
613 into->dfltType = from->dfltType;
614 into->defs.defined |= _Key_Type_Dflt;
616 if (UseNewField(_Key_GroupInfo, &into->defs, &from->defs, &collide))
618 into->groupInfo = from->groupInfo;
619 into->defs.defined |= _Key_GroupInfo;
623 WARN("Symbol map for key %s redefined\n",
624 longText(into->name));
625 ACTION("Using %s definition for conflicting fields\n",
626 (from->defs.merge == MergeAugment ? "first" : "last"));
632 AddKeySymbols(SymbolsInfo *info, KeyInfo *key, struct xkb_keymap *keymap)
634 unsigned long real_name;
637 darray_foreach(iter, info->keys)
638 if (iter->name == key->name)
639 return MergeKeys(info, keymap, iter, key);
641 if (FindKeyNameForAlias(keymap, key->name, &real_name))
642 darray_foreach(iter, info->keys)
643 if (iter->name == real_name)
644 return MergeKeys(info, keymap, iter, key);
646 darray_resize0(info->keys, darray_size(info->keys) + 1);
647 new = &darray_item(info->keys, darray_size(info->keys) - 1);
648 return CopyKeyInfo(key, new, true);
652 AddModMapEntry(SymbolsInfo * info, ModMapEntry * new)
657 clobber = (new->defs.merge != MergeAugment);
658 for (mm = info->modMap; mm != NULL; mm = (ModMapEntry *) mm->defs.next)
660 if (new->haveSymbol && mm->haveSymbol
661 && (new->u.keySym == mm->u.keySym))
663 unsigned use, ignore;
664 if (mm->modifier != new->modifier)
669 ignore = mm->modifier;
674 ignore = new->modifier;
677 ("%s added to symbol map for multiple modifiers\n",
678 XkbcKeysymText(new->u.keySym));
679 ACTION("Using %s, ignoring %s.\n",
680 XkbcModIndexText(use),
681 XkbcModIndexText(ignore));
686 if ((!new->haveSymbol) && (!mm->haveSymbol) &&
687 (new->u.keyName == mm->u.keyName))
689 unsigned use, ignore;
690 if (mm->modifier != new->modifier)
695 ignore = mm->modifier;
700 ignore = new->modifier;
702 ERROR("Key %s added to map for multiple modifiers\n",
703 longText(new->u.keyName));
704 ACTION("Using %s, ignoring %s.\n",
705 XkbcModIndexText(use),
706 XkbcModIndexText(ignore));
712 mm = uTypedAlloc(ModMapEntry);
715 WSGO("Could not allocate modifier map entry\n");
716 ACTION("Modifier map for %s will be incomplete\n",
717 XkbcModIndexText(new->modifier));
721 mm->defs.next = &info->modMap->defs;
726 /***====================================================================***/
729 MergeIncludedSymbols(SymbolsInfo *into, SymbolsInfo *from,
730 unsigned merge, struct xkb_keymap *keymap)
735 if (from->errorCount > 0)
737 into->errorCount += from->errorCount;
740 if (into->name == NULL)
742 into->name = from->name;
745 for (i = 0; i < XkbNumKbdGroups; i++)
747 if (from->groupNames[i] != XKB_ATOM_NONE)
749 if ((merge != MergeAugment) ||
750 (into->groupNames[i] == XKB_ATOM_NONE))
751 into->groupNames[i] = from->groupNames[i];
755 darray_foreach(key, from->keys) {
756 if (merge != MergeDefault)
757 key->defs.merge = merge;
759 if (!AddKeySymbols(into, key, keymap))
763 if (from->modMap != NULL)
765 ModMapEntry *mm, *next;
766 for (mm = from->modMap; mm != NULL; mm = next)
768 if (merge != MergeDefault)
769 mm->defs.merge = merge;
770 if (!AddModMapEntry(into, mm))
772 next = (ModMapEntry *) mm->defs.next;
777 if (!MergeAliases(&into->aliases, &from->aliases, merge))
782 HandleSymbolsFile(XkbFile *file, struct xkb_keymap *keymap,
783 unsigned merge, SymbolsInfo *info);
786 HandleIncludeSymbols(IncludeStmt *stmt, struct xkb_keymap *keymap,
791 SymbolsInfo included;
795 if ((stmt->file == NULL) && (stmt->map == NULL))
799 memset(info, 0, sizeof(SymbolsInfo));
801 else if (ProcessIncludeFile(keymap->ctx, stmt, XkmSymbolsIndex, &rtrn,
804 InitSymbolsInfo(&included, keymap);
805 included.fileID = included.dflt.defs.fileID = rtrn->id;
806 included.merge = included.dflt.defs.merge = MergeOverride;
809 included.explicit_group = atoi(stmt->modifier) - 1;
813 included.explicit_group = info->explicit_group;
815 HandleSymbolsFile(rtrn, keymap, MergeOverride, &included);
816 if (stmt->stmt != NULL)
819 included.name = stmt->stmt;
826 info->errorCount += 10;
829 if ((stmt->next != NULL) && (included.errorCount < 1))
833 SymbolsInfo next_incl;
835 for (next = stmt->next; next != NULL; next = next->next)
837 if ((next->file == NULL) && (next->map == NULL))
840 MergeIncludedSymbols(&included, info, next->merge, keymap);
841 FreeSymbolsInfo(info);
843 else if (ProcessIncludeFile(keymap->ctx, next, XkmSymbolsIndex,
846 InitSymbolsInfo(&next_incl, keymap);
847 next_incl.fileID = next_incl.dflt.defs.fileID = rtrn->id;
848 next_incl.merge = next_incl.dflt.defs.merge = MergeOverride;
851 next_incl.explicit_group = atoi(next->modifier) - 1;
855 next_incl.explicit_group = info->explicit_group;
857 HandleSymbolsFile(rtrn, keymap, MergeOverride, &next_incl);
858 MergeIncludedSymbols(&included, &next_incl, op, keymap);
859 FreeSymbolsInfo(&next_incl);
864 info->errorCount += 10;
865 FreeSymbolsInfo(&included);
872 info->errorCount += included.errorCount;
878 MergeIncludedSymbols(info, &included, newMerge, keymap);
879 FreeSymbolsInfo(&included);
881 return (info->errorCount == 0);
888 GetGroupIndex(KeyInfo *key, struct xkb_keymap *keymap,
889 ExprDef * arrayNdx, unsigned what, unsigned *ndx_rtrn)
899 if (arrayNdx == NULL)
904 defined = key->symsDefined;
906 defined = key->actsDefined;
908 for (i = 0; i < XkbNumKbdGroups; i++)
910 if ((defined & (1 << i)) == 0)
916 ERROR("Too many groups of %s for key %s (max %d)\n", name,
917 longText(key->name), XkbNumKbdGroups + 1);
918 ACTION("Ignoring %s defined for extra groups\n", name);
921 if (!ExprResolveGroup(keymap->ctx, arrayNdx, &tmp))
923 ERROR("Illegal group index for %s of key %s\n", name,
924 longText(key->name));
925 ACTION("Definition with non-integer array index ignored\n");
928 *ndx_rtrn = tmp.uval - 1;
933 AddSymbolsToKey(KeyInfo *key, struct xkb_keymap *keymap,
934 ExprDef *arrayNdx, ExprDef *value, SymbolsInfo *info)
936 unsigned ndx, nSyms, nLevels;
940 if (!GetGroupIndex(key, keymap, arrayNdx, SYMBOLS, &ndx))
944 key->symsDefined |= (1 << ndx);
947 if (value->op != ExprKeysymList)
949 ERROR("Expected a list of symbols, found %s\n", exprOpText(value->op));
950 ACTION("Ignoring symbols for group %d of %s\n", ndx + 1,
951 longText(key->name));
954 if (!darray_empty(key->syms[ndx]))
956 ERROR("Symbols for key %s, group %d already defined\n",
957 longText(key->name), ndx + 1);
958 ACTION("Ignoring duplicate definition\n");
961 nSyms = darray_size(value->value.list.syms);
962 nLevels = darray_size(value->value.list.symsMapIndex);
963 if ((key->numLevels[ndx] < nSyms || darray_empty(key->syms[ndx])) &&
964 (!ResizeKeyGroup(key, ndx, nLevels, nSyms, false)))
966 WSGO("Could not resize group %d of key %s to contain %d levels\n",
967 ndx + 1, longText(key->name), nSyms);
968 ACTION("Symbols lost\n");
971 key->symsDefined |= (1 << ndx);
972 for (i = 0; i < nLevels; i++) {
973 darray_item(key->symsMapIndex[ndx], i) =
974 darray_item(value->value.list.symsMapIndex, i);
975 darray_item(key->symsMapNumEntries[ndx], i) =
976 darray_item(value->value.list.symsNumEntries, i);
978 for (j = 0; j < darray_item(key->symsMapNumEntries[ndx], i); j++) {
979 /* FIXME: What's abort() doing here? */
980 if (darray_item(key->symsMapIndex[ndx], i) + j >= nSyms)
982 if (!LookupKeysym(darray_item(value->value.list.syms,
983 darray_item(value->value.list.symsMapIndex, i) + j),
984 &darray_item(key->syms[ndx],
985 darray_item(key->symsMapIndex[ndx], i) + j))) {
986 WARN("Could not resolve keysym %s for key %s, group %d (%s), level %d\n",
987 darray_item(value->value.list.syms, i),
990 xkb_atom_text(keymap->ctx, info->groupNames[ndx]), nSyms);
992 darray_item(key->syms[ndx],
993 darray_item(key->symsMapIndex[ndx], i) + j) = XKB_KEY_NoSymbol;
994 darray_item(key->symsMapIndex[ndx], i) = -1;
995 darray_item(key->symsMapNumEntries[ndx], i) = 0;
998 if (darray_item(key->symsMapNumEntries[ndx], i) == 1 &&
999 darray_item(key->syms[ndx],
1000 darray_item(key->symsMapIndex[ndx], i) + j) == XKB_KEY_NoSymbol) {
1001 darray_item(key->symsMapIndex[ndx], i) = -1;
1002 darray_item(key->symsMapNumEntries[ndx], i) = 0;
1006 for (j = key->numLevels[ndx] - 1;
1007 j >= 0 && darray_item(key->symsMapNumEntries[ndx], j) == 0; j--)
1008 key->numLevels[ndx]--;
1013 AddActionsToKey(KeyInfo *key, struct xkb_keymap *keymap, ExprDef *arrayNdx,
1014 ExprDef *value, SymbolsInfo *info)
1017 unsigned ndx, nActs;
1019 struct xkb_any_action *toAct;
1021 if (!GetGroupIndex(key, keymap, arrayNdx, ACTIONS, &ndx))
1026 key->actsDefined |= (1 << ndx);
1029 if (value->op != ExprActionList)
1031 WSGO("Bad expression type (%d) for action list value\n", value->op);
1032 ACTION("Ignoring actions for group %d of %s\n", ndx,
1033 longText(key->name));
1036 if (!darray_empty(key->acts[ndx]))
1038 WSGO("Actions for key %s, group %d already defined\n",
1039 longText(key->name), ndx);
1042 for (nActs = 0, act = value->value.child; act != NULL; nActs++)
1044 act = (ExprDef *) act->common.next;
1048 WSGO("Action list but not actions in AddActionsToKey\n");
1051 if ((key->numLevels[ndx] < nActs || darray_empty(key->acts[ndx])) &&
1052 !ResizeKeyGroup(key, ndx, nActs, nActs, true))
1054 WSGO("Could not resize group %d of key %s\n", ndx,
1055 longText(key->name));
1056 ACTION("Actions lost\n");
1059 key->actsDefined |= (1 << ndx);
1061 toAct = (struct xkb_any_action *) darray_mem(key->acts[ndx], 0);
1062 act = value->value.child;
1063 for (i = 0; i < nActs; i++, toAct++)
1065 if (!HandleActionDef(act, keymap, toAct, info->action))
1067 ERROR("Illegal action definition for %s\n",
1068 longText(key->name));
1069 ACTION("Action for group %d/level %d ignored\n", ndx + 1, i + 1);
1071 act = (ExprDef *) act->common.next;
1076 static const LookupEntry lockingEntries[] = {
1077 {"true", XkbKB_Lock},
1078 {"yes", XkbKB_Lock},
1080 {"false", XkbKB_Default},
1081 {"no", XkbKB_Default},
1082 {"off", XkbKB_Default},
1083 {"permanent", XkbKB_Lock | XkbKB_Permanent},
1087 static const LookupEntry repeatEntries[] = {
1088 {"true", RepeatYes},
1091 {"false", RepeatNo},
1094 {"default", RepeatUndefined},
1099 SetSymbolsField(KeyInfo *key, struct xkb_keymap *keymap, char *field,
1100 ExprDef *arrayNdx, ExprDef *value, SymbolsInfo *info)
1105 if (strcasecmp(field, "type") == 0)
1108 if ((!ExprResolveString(keymap->ctx, value, &tmp))
1109 && (warningLevel > 0))
1111 WARN("The type field of a key symbol map must be a string\n");
1112 ACTION("Ignoring illegal type definition\n");
1114 if (arrayNdx == NULL)
1116 key->dfltType = xkb_atom_intern(keymap->ctx, tmp.str);
1117 key->defs.defined |= _Key_Type_Dflt;
1119 else if (!ExprResolveGroup(keymap->ctx, arrayNdx, &ndx))
1121 ERROR("Illegal group index for type of key %s\n",
1122 longText(key->name));
1123 ACTION("Definition with non-integer array index ignored\n");
1129 key->types[ndx.uval - 1] = xkb_atom_intern(keymap->ctx, tmp.str);
1130 key->typesDefined |= (1 << (ndx.uval - 1));
1134 else if (strcasecmp(field, "symbols") == 0)
1135 return AddSymbolsToKey(key, keymap, arrayNdx, value, info);
1136 else if (strcasecmp(field, "actions") == 0)
1137 return AddActionsToKey(key, keymap, arrayNdx, value, info);
1138 else if ((strcasecmp(field, "vmods") == 0) ||
1139 (strcasecmp(field, "virtualmods") == 0) ||
1140 (strcasecmp(field, "virtualmodifiers") == 0))
1142 ok = ExprResolveVModMask(value, &tmp, keymap);
1145 key->vmodmap = (tmp.uval >> 8);
1146 key->defs.defined |= _Key_VModMap;
1150 ERROR("Expected a virtual modifier mask, found %s\n",
1151 exprOpText(value->op));
1152 ACTION("Ignoring virtual modifiers definition for key %s\n",
1153 longText(key->name));
1156 else if ((strcasecmp(field, "locking") == 0) ||
1157 (strcasecmp(field, "lock") == 0) ||
1158 (strcasecmp(field, "locks") == 0))
1160 ok = ExprResolveEnum(keymap->ctx, value, &tmp, lockingEntries);
1162 key->behavior.type = tmp.uval;
1163 key->defs.defined |= _Key_Behavior;
1165 else if ((strcasecmp(field, "radiogroup") == 0) ||
1166 (strcasecmp(field, "permanentradiogroup") == 0) ||
1167 (strcasecmp(field, "allownone") == 0))
1169 ERROR("Radio groups not supported\n");
1170 ACTION("Ignoring radio group specification for key %s\n", longText(key->name));
1173 else if (uStrCasePrefix("overlay", field) ||
1174 uStrCasePrefix("permanentoverlay", field))
1176 ERROR("Overlays not supported\n");
1177 ACTION("Ignoring overlay specification for key %s\n", longText(key->name));
1179 else if ((strcasecmp(field, "repeating") == 0) ||
1180 (strcasecmp(field, "repeats") == 0) ||
1181 (strcasecmp(field, "repeat") == 0))
1183 ok = ExprResolveEnum(keymap->ctx, value, &tmp, repeatEntries);
1186 ERROR("Illegal repeat setting for %s\n",
1187 longText(key->name));
1188 ACTION("Non-boolean repeat setting ignored\n");
1191 key->repeat = tmp.uval;
1192 key->defs.defined |= _Key_Repeat;
1194 else if ((strcasecmp(field, "groupswrap") == 0) ||
1195 (strcasecmp(field, "wrapgroups") == 0))
1197 ok = ExprResolveBoolean(keymap->ctx, value, &tmp);
1200 ERROR("Illegal groupsWrap setting for %s\n",
1201 longText(key->name));
1202 ACTION("Non-boolean value ignored\n");
1206 key->groupInfo = XkbWrapIntoRange;
1208 key->groupInfo = XkbClampIntoRange;
1209 key->defs.defined |= _Key_GroupInfo;
1211 else if ((strcasecmp(field, "groupsclamp") == 0) ||
1212 (strcasecmp(field, "clampgroups") == 0))
1214 ok = ExprResolveBoolean(keymap->ctx, value, &tmp);
1217 ERROR("Illegal groupsClamp setting for %s\n",
1218 longText(key->name));
1219 ACTION("Non-boolean value ignored\n");
1223 key->groupInfo = XkbClampIntoRange;
1225 key->groupInfo = XkbWrapIntoRange;
1226 key->defs.defined |= _Key_GroupInfo;
1228 else if ((strcasecmp(field, "groupsredirect") == 0) ||
1229 (strcasecmp(field, "redirectgroups") == 0))
1231 if (!ExprResolveGroup(keymap->ctx, value, &tmp))
1233 ERROR("Illegal group index for redirect of key %s\n",
1234 longText(key->name));
1235 ACTION("Definition with non-integer group ignored\n");
1239 XkbSetGroupInfo(0, XkbRedirectIntoRange, tmp.uval - 1);
1240 key->defs.defined |= _Key_GroupInfo;
1244 ERROR("Unknown field %s in a symbol interpretation\n", field);
1245 ACTION("Definition ignored\n");
1252 SetGroupName(SymbolsInfo *info, struct xkb_keymap *keymap, ExprDef *arrayNdx,
1255 ExprResult tmp, name;
1257 if ((arrayNdx == NULL) && (warningLevel > 0))
1259 WARN("You must specify an index when specifying a group name\n");
1260 ACTION("Group name definition without array subscript ignored\n");
1263 if (!ExprResolveGroup(keymap->ctx, arrayNdx, &tmp))
1265 ERROR("Illegal index in group name definition\n");
1266 ACTION("Definition with non-integer array index ignored\n");
1269 if (!ExprResolveString(keymap->ctx, value, &name))
1271 ERROR("Group name must be a string\n");
1272 ACTION("Illegal name for group %d ignored\n", tmp.uval);
1275 info->groupNames[tmp.uval - 1 + info->explicit_group] =
1276 xkb_atom_intern(keymap->ctx, name.str);
1283 HandleSymbolsVar(VarDef *stmt, struct xkb_keymap *keymap, SymbolsInfo *info)
1285 ExprResult elem, field;
1289 if (ExprResolveLhs(keymap, stmt->name, &elem, &field, &arrayNdx) == 0)
1290 return 0; /* internal error, already reported */
1291 if (elem.str && (strcasecmp(elem.str, "key") == 0))
1293 ret = SetSymbolsField(&info->dflt, keymap, field.str, arrayNdx,
1296 else if ((elem.str == NULL) && ((strcasecmp(field.str, "name") == 0) ||
1297 (strcasecmp(field.str, "groupname") ==
1300 ret = SetGroupName(info, keymap, arrayNdx, stmt->value);
1302 else if ((elem.str == NULL)
1303 && ((strcasecmp(field.str, "groupswrap") == 0) ||
1304 (strcasecmp(field.str, "wrapgroups") == 0)))
1306 ERROR("Global \"groupswrap\" not supported\n");
1307 ACTION("Ignored\n");
1310 else if ((elem.str == NULL)
1311 && ((strcasecmp(field.str, "groupsclamp") == 0) ||
1312 (strcasecmp(field.str, "clampgroups") == 0)))
1314 ERROR("Global \"groupsclamp\" not supported\n");
1315 ACTION("Ignored\n");
1318 else if ((elem.str == NULL)
1319 && ((strcasecmp(field.str, "groupsredirect") == 0) ||
1320 (strcasecmp(field.str, "redirectgroups") == 0)))
1322 ERROR("Global \"groupsredirect\" not supported\n");
1323 ACTION("Ignored\n");
1326 else if ((elem.str == NULL) && (strcasecmp(field.str, "allownone") == 0))
1328 ERROR("Radio groups not supported\n");
1329 ACTION("Ignoring \"allownone\" specification\n");
1333 ret = SetActionField(keymap, elem.str, field.str, arrayNdx,
1334 stmt->value, &info->action);
1343 HandleSymbolsBody(VarDef *def, struct xkb_keymap *keymap, KeyInfo *key,
1347 ExprResult tmp, field;
1350 for (; def != NULL; def = (VarDef *) def->common.next)
1352 if ((def->name) && (def->name->type == ExprFieldRef))
1354 ok = HandleSymbolsVar(def, keymap, info);
1359 if (def->name == NULL)
1361 if ((def->value == NULL)
1362 || (def->value->op == ExprKeysymList))
1363 field.str = strdup("symbols");
1365 field.str = strdup("actions");
1370 ok = ExprResolveLhs(keymap, def->name, &tmp, &field,
1374 ok = SetSymbolsField(key, keymap, field.str, arrayNdx,
1383 SetExplicitGroup(SymbolsInfo *info, KeyInfo *key)
1385 unsigned group = info->explicit_group;
1390 if ((key->typesDefined | key->symsDefined | key->actsDefined) & ~1)
1393 WARN("For the map %s an explicit group specified\n", info->name);
1394 WARN("but key %s has more than one group defined\n",
1395 longText(key->name));
1396 ACTION("All groups except first one will be ignored\n");
1397 for (i = 1; i < XkbNumKbdGroups; i++)
1399 key->numLevels[i] = 0;
1400 darray_free(key->syms[i]);
1401 darray_free(key->acts[i]);
1405 key->typesDefined = key->symsDefined = key->actsDefined = 1 << group;
1407 key->numLevels[group] = key->numLevels[0];
1408 key->numLevels[0] = 0;
1409 key->syms[group] = key->syms[0];
1410 darray_init(key->syms[0]);
1411 key->symsMapIndex[group] = key->symsMapIndex[0];
1412 darray_init(key->symsMapIndex[0]);
1413 key->symsMapNumEntries[group] = key->symsMapNumEntries[0];
1414 darray_init(key->symsMapNumEntries[0]);
1415 key->acts[group] = key->acts[0];
1416 darray_init(key->acts[0]);
1417 key->types[group] = key->types[0];
1423 HandleSymbolsDef(SymbolsDef *stmt, struct xkb_keymap *keymap,
1429 CopyKeyInfo(&info->dflt, &key, false);
1430 key.defs.merge = stmt->merge;
1431 key.name = KeyNameToLong(stmt->keyName);
1432 if (!HandleSymbolsBody((VarDef *) stmt->symbols, keymap, &key, info))
1438 if (!SetExplicitGroup(info, &key))
1444 if (!AddKeySymbols(info, &key, keymap))
1453 HandleModMapDef(ModMapDef *def, struct xkb_keymap *keymap, SymbolsInfo *info)
1460 if (!LookupModIndex(keymap->ctx, NULL, def->modifier, TypeInt, &rtrn))
1462 ERROR("Illegal modifier map definition\n");
1463 ACTION("Ignoring map for non-modifier \"%s\"\n",
1464 xkb_atom_text(keymap->ctx, def->modifier));
1468 tmp.modifier = rtrn.uval;
1469 for (key = def->keys; key != NULL; key = (ExprDef *) key->common.next)
1471 if ((key->op == ExprValue) && (key->type == TypeKeyName))
1473 tmp.haveSymbol = false;
1474 tmp.u.keyName = KeyNameToLong(key->value.keyName);
1476 else if (ExprResolveKeySym(keymap->ctx, key, &rtrn))
1478 tmp.haveSymbol = true;
1479 tmp.u.keySym = rtrn.uval;
1483 ERROR("Modmap entries may contain only key names or keysyms\n");
1484 ACTION("Illegal definition for %s modifier ignored\n",
1485 XkbcModIndexText(tmp.modifier));
1489 ok = AddModMapEntry(info, &tmp) && ok;
1495 HandleSymbolsFile(XkbFile *file, struct xkb_keymap *keymap,
1496 unsigned merge, SymbolsInfo *info)
1501 info->name = uDupString(file->name);
1505 switch (stmt->stmtType)
1508 if (!HandleIncludeSymbols((IncludeStmt *) stmt, keymap, info))
1511 case StmtSymbolsDef:
1512 if (!HandleSymbolsDef((SymbolsDef *) stmt, keymap, info))
1516 if (!HandleSymbolsVar((VarDef *) stmt, keymap, info))
1520 if (!HandleVModDef((VModDef *) stmt, keymap, merge, &info->vmods))
1524 ERROR("Interpretation files may not include other types\n");
1525 ACTION("Ignoring definition of symbol interpretation\n");
1528 case StmtKeycodeDef:
1529 ERROR("Interpretation files may not include other types\n");
1530 ACTION("Ignoring definition of key name\n");
1534 if (!HandleModMapDef((ModMapDef *) stmt, keymap, info))
1538 WSGO("Unexpected statement type %d in HandleSymbolsFile\n",
1543 if (info->errorCount > 10)
1546 ERROR("Too many errors\n");
1548 ACTION("Abandoning symbols file \"%s\"\n", file->topName);
1555 FindKeyForSymbol(struct xkb_keymap *keymap, xkb_keysym_t sym,
1556 xkb_keycode_t *kc_rtrn)
1559 unsigned int group, level;
1561 for (key = keymap->min_key_code; key <= keymap->max_key_code; key++)
1563 for (group = 0; group < XkbKeyNumGroups(keymap, key); group++)
1565 for (level = 0; level < XkbKeyGroupWidth(keymap, key, group);
1568 if (XkbKeyNumSyms(keymap, key, group, level) != 1 ||
1569 (XkbKeySymEntry(keymap, key, group, level))[0] != sym)
1581 * Find the given name in the keymap->map->types and return its index.
1583 * @param atom The atom to search for.
1584 * @param type_rtrn Set to the index of the name if found.
1586 * @return true if found, false otherwise.
1589 FindNamedType(struct xkb_keymap *keymap, xkb_atom_t atom, unsigned *type_rtrn)
1592 const char *name = xkb_atom_text(keymap->ctx, atom);
1593 struct xkb_key_type *type;
1595 if (keymap && keymap->map) {
1596 darray_foreach(type, keymap->map->types) {
1597 if (strcmp(type->name, name) == 0) {
1608 * Assign a type to the given sym and return the Atom for the type assigned.
1611 * - ONE_LEVEL for width 0/1
1612 * - ALPHABETIC for 2 shift levels, with lower/upercase
1613 * - KEYPAD for keypad keys.
1614 * - TWO_LEVEL for other 2 shift level keys.
1615 * and the same for four level keys.
1617 * @param width Number of sysms in syms.
1618 * @param syms The keysyms for the given key (must be size width).
1619 * @param typeNameRtrn Set to the Atom of the type name.
1621 * @returns true if a type could be found, false otherwise.
1624 FindAutomaticType(struct xkb_keymap *keymap, int width,
1625 const xkb_keysym_t *syms, xkb_atom_t *typeNameRtrn,
1629 if ((width == 1) || (width == 0))
1631 *typeNameRtrn = xkb_atom_intern(keymap->ctx, "ONE_LEVEL");
1634 else if (width == 2)
1636 if (syms && XkbcKSIsLower(syms[0]) && XkbcKSIsUpper(syms[1]))
1638 *typeNameRtrn = xkb_atom_intern(keymap->ctx, "ALPHABETIC");
1640 else if (syms && (XkbKSIsKeypad(syms[0]) || XkbKSIsKeypad(syms[1])))
1642 *typeNameRtrn = xkb_atom_intern(keymap->ctx, "KEYPAD");
1647 *typeNameRtrn = xkb_atom_intern(keymap->ctx, "TWO_LEVEL");
1651 else if (width <= 4)
1653 if (syms && XkbcKSIsLower(syms[0]) && XkbcKSIsUpper(syms[1]))
1654 if (XkbcKSIsLower(syms[2]) && XkbcKSIsUpper(syms[3]))
1656 xkb_atom_intern(keymap->ctx, "FOUR_LEVEL_ALPHABETIC");
1658 *typeNameRtrn = xkb_atom_intern(keymap->ctx,
1659 "FOUR_LEVEL_SEMIALPHABETIC");
1661 else if (syms && (XkbKSIsKeypad(syms[0]) || XkbKSIsKeypad(syms[1])))
1662 *typeNameRtrn = xkb_atom_intern(keymap->ctx, "FOUR_LEVEL_KEYPAD");
1664 *typeNameRtrn = xkb_atom_intern(keymap->ctx, "FOUR_LEVEL");
1665 /* XXX: why not set autoType here? */
1667 return ((width >= 0) && (width <= 4));
1671 * Ensure the given KeyInfo is in a coherent state, i.e. no gaps between the
1672 * groups, and reduce to one group if all groups are identical anyway.
1675 PrepareKeyDef(KeyInfo * key)
1677 int i, j, width, defined, lastGroup;
1680 defined = key->symsDefined | key->actsDefined | key->typesDefined;
1681 /* get highest group number */
1682 for (i = XkbNumKbdGroups - 1; i >= 0; i--)
1684 if (defined & (1 << i))
1692 /* If there are empty groups between non-empty ones fill them with data */
1693 /* from the first group. */
1694 /* We can make a wrong assumption here. But leaving gaps is worse. */
1695 for (i = lastGroup; i > 0; i--)
1697 if (defined & (1 << i))
1699 width = key->numLevels[0];
1700 if (key->typesDefined & 1)
1702 for (j = 0; j < width; j++)
1704 key->types[i] = key->types[0];
1706 key->typesDefined |= 1 << i;
1708 if ((key->actsDefined & 1) && !darray_empty(key->acts[0]))
1710 darray_copy(key->acts[i], key->acts[0]);
1711 key->actsDefined |= 1 << i;
1713 if ((key->symsDefined & 1) && !darray_empty(key->syms[0]))
1715 darray_copy(key->syms[i], key->syms[0]);
1716 darray_copy(key->symsMapIndex[i], key->symsMapIndex[0]);
1717 darray_copy(key->symsMapNumEntries[i], key->symsMapNumEntries[0]);
1718 key->symsDefined |= 1 << i;
1722 key->numLevels[i] = key->numLevels[0];
1725 /* If all groups are completely identical remove them all */
1726 /* exept the first one. */
1728 for (i = lastGroup; i > 0; i--)
1730 if ((key->numLevels[i] != key->numLevels[0]) ||
1731 (key->types[i] != key->types[0]))
1736 if (!darray_same(key->syms[i], key->syms[0]) &&
1737 (darray_empty(key->syms[i]) || darray_empty(key->syms[0]) ||
1738 darray_size(key->syms[i]) != darray_size(key->syms[0]) ||
1739 memcmp(darray_mem(key->syms[i], 0),
1740 darray_mem(key->syms[0], 0),
1741 sizeof(xkb_keysym_t) * darray_size(key->syms[0]))))
1746 if (!darray_same(key->symsMapIndex[i], key->symsMapIndex[0]) &&
1747 (darray_empty(key->symsMapIndex[i]) ||
1748 darray_empty(key->symsMapIndex[0]) ||
1749 memcmp(darray_mem(key->symsMapIndex[i], 0),
1750 darray_mem(key->symsMapIndex[0], 0),
1751 key->numLevels[0] * sizeof(int))))
1756 if (!darray_same(key->symsMapNumEntries[i], key->symsMapNumEntries[0]) &&
1757 (darray_empty(key->symsMapNumEntries[i]) ||
1758 darray_empty(key->symsMapNumEntries[0]) ||
1759 memcmp(darray_mem(key->symsMapNumEntries[i], 0),
1760 darray_mem(key->symsMapNumEntries[0], 0),
1761 key->numLevels[0] * sizeof(size_t))))
1766 if (!darray_same(key->acts[i], key->acts[0]) &&
1767 (darray_empty(key->acts[i]) || darray_empty(key->acts[0]) ||
1768 memcmp(darray_mem(key->acts[i], 0),
1769 darray_mem(key->acts[0], 0),
1770 key->numLevels[0] * sizeof(union xkb_action))))
1778 for (i = lastGroup; i > 0; i--)
1780 key->numLevels[i] = 0;
1781 darray_free(key->syms[i]);
1782 darray_free(key->symsMapIndex[i]);
1783 darray_free(key->symsMapNumEntries[i]);
1784 darray_free(key->acts[i]);
1787 key->symsDefined &= 1;
1788 key->actsDefined &= 1;
1789 key->typesDefined &= 1;
1794 * Copy the KeyInfo into the keyboard description.
1796 * This function recurses.
1799 CopySymbolsDef(struct xkb_keymap *keymap, KeyInfo *key, int start_from)
1803 unsigned int sizeSyms = 0;
1804 unsigned width, tmp, nGroups;
1805 struct xkb_key_type * type;
1806 bool haveActions, autoType, useAlias;
1807 unsigned types[XkbNumKbdGroups];
1808 union xkb_action *outActs;
1809 unsigned int symIndex = 0;
1810 struct xkb_sym_map *sym_map;
1812 useAlias = (start_from == 0);
1814 /* get the keycode for the key. */
1815 if (!FindNamedKey(keymap, key->name, &kc, useAlias,
1816 CreateKeyNames(keymap), start_from))
1818 if ((start_from == 0) && (warningLevel >= 5))
1820 WARN("Key %s not found in keycodes\n", longText(key->name));
1821 ACTION("Symbols ignored\n");
1826 haveActions = false;
1827 for (i = width = nGroups = 0; i < XkbNumKbdGroups; i++)
1829 if (((i + 1) > nGroups)
1830 && (((key->symsDefined | key->actsDefined) & (1 << i))
1831 || (key->typesDefined) & (1 << i)))
1833 if (!darray_empty(key->acts[i]))
1836 /* Assign the type to the key, if it is missing. */
1837 if (key->types[i] == XKB_ATOM_NONE)
1839 if (key->dfltType != XKB_ATOM_NONE)
1840 key->types[i] = key->dfltType;
1841 else if (FindAutomaticType(keymap, key->numLevels[i],
1842 darray_mem(key->syms[i], 0),
1843 &key->types[i], &autoType))
1848 if (warningLevel >= 5)
1850 WARN("No automatic type for %d symbols\n",
1851 (unsigned int) key->numLevels[i]);
1852 ACTION("Using %s for the %s key (keycode %d)\n",
1853 xkb_atom_text(keymap->ctx, key->types[i]),
1854 longText(key->name), kc);
1858 if (FindNamedType(keymap, key->types[i], &types[i]))
1860 if (!autoType || key->numLevels[i] > 2)
1861 keymap->server->explicit[kc] |= (1 << i);
1865 if (warningLevel >= 3)
1867 WARN("Type \"%s\" is not defined\n",
1868 xkb_atom_text(keymap->ctx, key->types[i]));
1869 ACTION("Using TWO_LEVEL for the %s key (keycode %d)\n",
1870 longText(key->name), kc);
1872 types[i] = XkbTwoLevelIndex;
1874 /* if the type specifies fewer levels than the key has, shrink the key */
1875 type = &darray_item(keymap->map->types, types[i]);
1876 if (type->num_levels < key->numLevels[i])
1878 if (warningLevel > 0)
1880 WARN("Type \"%s\" has %d levels, but %s has %d symbols\n",
1881 type->name, type->num_levels,
1882 xkb_atom_text(keymap->ctx, key->name), key->numLevels[i]);
1883 ACTION("Ignoring extra symbols\n");
1885 key->numLevels[i] = type->num_levels;
1887 if (key->numLevels[i] > width)
1888 width = key->numLevels[i];
1889 if (type->num_levels > width)
1890 width = type->num_levels;
1891 sizeSyms += darray_size(key->syms[i]);
1894 if (!XkbcResizeKeySyms(keymap, kc, sizeSyms))
1896 WSGO("Could not enlarge symbols for %s (keycode %d)\n",
1897 longText(key->name), kc);
1902 outActs = XkbcResizeKeyActions(keymap, kc, width * nGroups);
1903 if (outActs == NULL)
1905 WSGO("Could not enlarge actions for %s (key %d)\n",
1906 longText(key->name), kc);
1909 keymap->server->explicit[kc] |= XkbExplicitInterpretMask;
1914 sym_map = &darray_item(keymap->map->key_sym_map, kc);
1916 if (key->defs.defined & _Key_GroupInfo)
1919 i = sym_map->group_info;
1921 sym_map->group_info = XkbSetNumGroups(i, nGroups);
1922 sym_map->width = width;
1923 sym_map->sym_index = uTypedCalloc(nGroups * width, int);
1924 sym_map->num_syms = uTypedCalloc(nGroups * width, unsigned int);
1926 for (i = 0; i < nGroups; i++)
1928 /* assign kt_index[i] to the index of the type in map->types.
1929 * kt_index[i] may have been set by a previous run (if we have two
1930 * layouts specified). Let's not overwrite it with the ONE_LEVEL
1931 * default group if we dont even have keys for this group anyway.
1933 * FIXME: There should be a better fix for this.
1935 if (key->numLevels[i])
1936 sym_map->kt_index[i] = types[i];
1937 if (!darray_empty(key->syms[i]))
1939 /* fill key to "width" symbols*/
1940 for (tmp = 0; tmp < width; tmp++)
1942 if (tmp < key->numLevels[i] &&
1943 darray_item(key->symsMapNumEntries[i], tmp) != 0)
1945 memcpy(darray_mem(sym_map->syms, symIndex),
1946 darray_mem(key->syms[i],
1947 darray_item(key->symsMapIndex[i], tmp)),
1948 darray_item(key->symsMapNumEntries[i], tmp) * sizeof(xkb_keysym_t));
1949 sym_map->sym_index[(i * width) + tmp] = symIndex;
1950 sym_map->num_syms[(i * width) + tmp] =
1951 darray_item(key->symsMapNumEntries[i], tmp);
1952 symIndex += sym_map->num_syms[(i * width) + tmp];
1956 sym_map->sym_index[(i * width) + tmp] = -1;
1957 sym_map->num_syms[(i * width) + tmp] = 0;
1959 if (outActs != NULL && !darray_empty(key->acts[i]))
1961 if (tmp < key->numLevels[i])
1962 outActs[tmp] = darray_item(key->acts[i], tmp);
1964 outActs[tmp].type = XkbSA_NoAction;
1969 switch (key->behavior.type & XkbKB_OpMask)
1974 keymap->server->behaviors[kc] = key->behavior;
1975 keymap->server->explicit[kc] |= XkbExplicitBehaviorMask;
1978 if (key->defs.defined & _Key_VModMap)
1980 keymap->server->vmodmap[kc] = key->vmodmap;
1981 keymap->server->explicit[kc] |= XkbExplicitVModMapMask;
1983 if (key->repeat != RepeatUndefined)
1985 if (key->repeat == RepeatYes)
1986 keymap->ctrls->per_key_repeat[kc / 8] |= (1 << (kc % 8));
1988 keymap->ctrls->per_key_repeat[kc / 8] &= ~(1 << (kc % 8));
1989 keymap->server->explicit[kc] |= XkbExplicitAutoRepeatMask;
1992 if (nGroups > keymap->ctrls->num_groups)
1993 keymap->ctrls->num_groups = nGroups;
1995 /* do the same thing for the next key */
1996 CopySymbolsDef(keymap, key, kc + 1);
2001 CopyModMapDef(struct xkb_keymap *keymap, ModMapEntry *entry)
2005 if (!entry->haveSymbol &&
2006 !FindNamedKey(keymap, entry->u.keyName, &kc, true,
2007 CreateKeyNames(keymap), 0))
2009 if (warningLevel >= 5)
2011 WARN("Key %s not found in keycodes\n",
2012 longText(entry->u.keyName));
2013 ACTION("Modifier map entry for %s not updated\n",
2014 XkbcModIndexText(entry->modifier));
2018 else if (entry->haveSymbol &&
2019 !FindKeyForSymbol(keymap, entry->u.keySym, &kc))
2021 if (warningLevel > 5)
2023 WARN("Key \"%s\" not found in symbol map\n",
2024 XkbcKeysymText(entry->u.keySym));
2025 ACTION("Modifier map entry for %s not updated\n",
2026 XkbcModIndexText(entry->modifier));
2030 keymap->map->modmap[kc] |= (1 << entry->modifier);
2035 * Handle the xkb_symbols section of an xkb file.
2037 * @param file The parsed xkb_symbols section of the xkb file.
2038 * @param keymap Handle to the keyboard description to store the symbols in.
2039 * @param merge Merge strategy (e.g. MergeOverride).
2042 CompileSymbols(XkbFile *file, struct xkb_keymap *keymap, unsigned merge)
2048 InitSymbolsInfo(&info, keymap);
2049 info.dflt.defs.fileID = file->id;
2050 info.dflt.defs.merge = merge;
2052 HandleSymbolsFile(file, keymap, merge, &info);
2054 if (darray_empty(info.keys))
2057 if (info.errorCount != 0)
2060 /* alloc memory in the xkb struct */
2061 if (XkbcAllocNames(keymap, XkbGroupNamesMask, 0) != Success) {
2062 WSGO("Can not allocate names in CompileSymbols\n");
2063 ACTION("Symbols not added\n");
2067 if (XkbcAllocClientMap(keymap, XkbKeySymsMask | XkbModifierMapMask, 0)
2069 WSGO("Could not allocate client map in CompileSymbols\n");
2070 ACTION("Symbols not added\n");
2074 if (XkbcAllocServerMap(keymap, XkbAllServerInfoMask, 32) != Success) {
2075 WSGO("Could not allocate server map in CompileSymbols\n");
2076 ACTION("Symbols not added\n");
2080 if (XkbcAllocControls(keymap) != Success) {
2081 WSGO("Could not allocate controls in CompileSymbols\n");
2082 ACTION("Symbols not added\n");
2086 /* now copy info into xkb. */
2087 ApplyAliases(keymap, &info.aliases);
2089 for (i = 0; i < XkbNumKbdGroups; i++) {
2090 if (info.groupNames[i] != XKB_ATOM_NONE) {
2091 free(keymap->names->groups[i]);
2092 keymap->names->groups[i] = xkb_atom_strdup(keymap->ctx,
2093 info.groupNames[i]);
2098 darray_foreach(key, info.keys)
2102 darray_foreach(key, info.keys)
2103 if (!CopySymbolsDef(keymap, key, 0))
2106 if (warningLevel > 3) {
2107 for (i = keymap->min_key_code; i <= keymap->max_key_code; i++) {
2108 if (darray_item(keymap->names->keys, i).name[0] == '\0')
2111 if (XkbKeyNumGroups(keymap, i) < 1) {
2113 memcpy(buf, darray_item(keymap->names->keys, i).name, 4);
2115 WARN("No symbols defined for <%s> (keycode %d)\n", buf, i);
2121 ModMapEntry *mm, *next;
2122 for (mm = info.modMap; mm != NULL; mm = next) {
2123 if (!CopyModMapDef(keymap, mm))
2125 next = (ModMapEntry *) mm->defs.next;
2129 FreeSymbolsInfo(&info);
2133 FreeSymbolsInfo(&info);