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 ********************************************************/
29 #include "xkbcomp-priv.h"
30 #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 static inline const char *
54 longText(unsigned long val)
58 LongToKeyName(val, buf);
59 return XkbcKeyNameText(buf);
62 typedef struct _KeyInfo {
63 unsigned short defined;
65 enum merge_mode merge;
67 unsigned long name; /* the 4 chars of the key name, as long */
68 unsigned char typesDefined;
69 unsigned char symsDefined;
70 unsigned char actsDefined;
71 unsigned int numLevels[XkbNumKbdGroups];
73 /* syms[group] -> Single array for all the keysyms in the group. */
74 darray_xkb_keysym_t syms[XkbNumKbdGroups];
76 * symsMapIndex[group][level] -> The index from which the syms for
77 * the level begin in the syms[group] array. Remember each keycode
78 * can have multiple keysyms in each level (that is, each key press
79 * can result in multiple keysyms).
81 darray(int) symsMapIndex[XkbNumKbdGroups];
83 * symsMapNumEntries[group][level] -> How many syms are in
84 * syms[group][symsMapIndex[group][level]].
86 darray(size_t) symsMapNumEntries[XkbNumKbdGroups];
88 darray_xkb_action acts[XkbNumKbdGroups];
90 xkb_atom_t types[XkbNumKbdGroups];
92 struct xkb_behavior behavior;
93 unsigned short vmodmap;
96 uint8_t out_of_range_group_action;
97 xkb_group_index_t out_of_range_group_number;
101 * Init the given key info to sane values.
104 InitKeyInfo(KeyInfo *keyi, unsigned file_id)
107 static const char dflt[4] = "*";
110 keyi->file_id = file_id;
111 keyi->merge = MERGE_OVERRIDE;
112 keyi->name = KeyNameToLong(dflt);
113 keyi->typesDefined = keyi->symsDefined = keyi->actsDefined = 0;
115 for (i = 0; i < XkbNumKbdGroups; i++) {
116 keyi->numLevels[i] = 0;
117 keyi->types[i] = XKB_ATOM_NONE;
118 darray_init(keyi->syms[i]);
119 darray_init(keyi->symsMapIndex[i]);
120 darray_init(keyi->symsMapNumEntries[i]);
121 darray_init(keyi->acts[i]);
124 keyi->dfltType = XKB_ATOM_NONE;
125 keyi->behavior.type = XkbKB_Default;
126 keyi->behavior.data = 0;
128 keyi->repeat = RepeatUndefined;
129 keyi->out_of_range_group_action = 0;
130 keyi->out_of_range_group_number = 0;
134 FreeKeyInfo(KeyInfo *keyi)
138 for (i = 0; i < XkbNumKbdGroups; i++) {
139 darray_free(keyi->syms[i]);
140 darray_free(keyi->symsMapIndex[i]);
141 darray_free(keyi->symsMapNumEntries[i]);
142 darray_free(keyi->acts[i]);
147 * Copy old into new, optionally reset old to 0.
148 * If old is reset, new simply re-uses old's memory. Otherwise, the memory is
149 * newly allocated and new points to the new memory areas.
152 CopyKeyInfo(KeyInfo * old, KeyInfo * new, bool clearOld)
159 for (i = 0; i < XkbNumKbdGroups; i++) {
160 old->numLevels[i] = 0;
161 darray_init(old->symsMapIndex[i]);
162 darray_init(old->symsMapNumEntries[i]);
163 darray_init(old->syms[i]);
164 darray_init(old->acts[i]);
168 for (i = 0; i < XkbNumKbdGroups; i++) {
169 darray_copy(new->syms[i], old->syms[i]);
170 darray_copy(new->symsMapIndex[i], old->symsMapIndex[i]);
171 darray_copy(new->symsMapNumEntries[i], old->symsMapNumEntries[i]);
172 darray_copy(new->acts[i], old->acts[i]);
179 /***====================================================================***/
181 typedef struct _ModMapEntry {
183 enum merge_mode merge;
187 unsigned long keyName;
192 typedef struct _SymbolsInfo {
193 char *name; /* e.g. pc+us+inet(evdev) */
196 enum merge_mode merge;
197 xkb_group_index_t explicit_group;
198 darray(KeyInfo) keys;
202 xkb_atom_t groupNames[XkbNumKbdGroups];
206 struct xkb_keymap *keymap;
210 InitSymbolsInfo(SymbolsInfo * info, struct xkb_keymap *keymap,
216 info->explicit_group = 0;
217 info->errorCount = 0;
218 info->file_id = file_id;
219 info->merge = MERGE_OVERRIDE;
220 darray_init(info->keys);
221 darray_growalloc(info->keys, 110);
222 list_init(&info->modMaps);
223 for (i = 0; i < XkbNumKbdGroups; i++)
224 info->groupNames[i] = XKB_ATOM_NONE;
225 InitKeyInfo(&info->dflt, file_id);
226 InitVModInfo(&info->vmods, keymap);
228 info->keymap = keymap;
232 FreeSymbolsInfo(SymbolsInfo * info)
235 ModMapEntry *mm, *next;
238 darray_foreach(keyi, info->keys) {
241 darray_free(info->keys);
242 list_foreach_safe(mm, next, &info->modMaps, entry)
244 memset(info, 0, sizeof(SymbolsInfo));
248 ResizeKeyGroup(KeyInfo *keyi, xkb_group_index_t group, unsigned int numLevels,
249 unsigned sizeSyms, bool forceActions)
253 if (darray_size(keyi->syms[group]) < sizeSyms)
254 darray_resize0(keyi->syms[group], sizeSyms);
256 if (darray_empty(keyi->symsMapIndex[group]) ||
257 keyi->numLevels[group] < numLevels) {
258 darray_resize(keyi->symsMapIndex[group], numLevels);
259 for (i = keyi->numLevels[group]; i < numLevels; i++)
260 darray_item(keyi->symsMapIndex[group], i) = -1;
263 if (darray_empty(keyi->symsMapNumEntries[group]) ||
264 keyi->numLevels[group] < numLevels)
265 darray_resize0(keyi->symsMapNumEntries[group], numLevels);
267 if ((forceActions && (keyi->numLevels[group] < numLevels ||
268 darray_empty(keyi->acts[group]))) ||
269 (keyi->numLevels[group] < numLevels && !darray_empty(keyi->acts[group])))
270 darray_resize0(keyi->acts[group], numLevels);
272 if (keyi->numLevels[group] < numLevels)
273 keyi->numLevels[group] = numLevels;
278 enum key_group_selector {
285 MergeKeyGroups(SymbolsInfo * info,
286 KeyInfo * into, KeyInfo * from, xkb_group_index_t group)
288 darray_xkb_keysym_t resultSyms;
289 enum key_group_selector using = NONE;
290 darray_xkb_action resultActs;
291 unsigned int resultWidth;
292 unsigned int resultSize = 0;
295 bool report, clobber;
296 int verbosity = xkb_get_log_verbosity(info->keymap->ctx);
298 clobber = (from->merge != MERGE_AUGMENT);
300 report = (verbosity > 9) ||
301 (into->file_id == from->file_id && verbosity > 0);
303 darray_init(resultSyms);
305 if (into->numLevels[group] >= from->numLevels[group]) {
306 resultActs = into->acts[group];
307 resultWidth = into->numLevels[group];
310 resultActs = from->acts[group];
311 resultWidth = from->numLevels[group];
312 darray_resize(into->symsMapIndex[group],
313 from->numLevels[group]);
314 darray_resize0(into->symsMapNumEntries[group],
315 from->numLevels[group]);
317 for (i = into->numLevels[group]; i < from->numLevels[group]; i++)
318 darray_item(into->symsMapIndex[group], i) = -1;
321 if (darray_empty(resultActs) && (!darray_empty(into->acts[group]) ||
322 !darray_empty(from->acts[group]))) {
323 darray_resize0(resultActs, resultWidth);
324 for (i = 0; i < resultWidth; i++) {
325 union xkb_action *fromAct = NULL, *toAct = NULL;
327 if (!darray_empty(from->acts[group]))
328 fromAct = &darray_item(from->acts[group], i);
330 if (!darray_empty(into->acts[group]))
331 toAct = &darray_item(into->acts[group], i);
333 if (((fromAct == NULL) || (fromAct->type == XkbSA_NoAction))
334 && (toAct != NULL)) {
335 darray_item(resultActs, i) = *toAct;
337 else if (((toAct == NULL) || (toAct->type == XkbSA_NoAction))
338 && (fromAct != NULL)) {
339 darray_item(resultActs, i) = *fromAct;
342 union xkb_action *use, *ignore;
352 log_warn(info->keymap->ctx,
353 "Multiple actions for level %d/group %u on key %s; "
354 "Using %s, ignoring %s\n",
355 i + 1, group + 1, longText(into->name),
356 XkbcActionTypeText(use->type),
357 XkbcActionTypeText(ignore->type));
359 darray_item(resultActs, i) = *use;
364 for (i = 0; i < resultWidth; i++) {
365 unsigned int fromSize = 0;
368 if (!darray_empty(from->symsMapNumEntries[group]) &&
369 i < from->numLevels[group])
370 fromSize = darray_item(from->symsMapNumEntries[group], i);
372 if (!darray_empty(into->symsMapNumEntries[group]) &&
373 i < into->numLevels[group])
374 toSize = darray_item(into->symsMapNumEntries[group], i);
377 resultSize += toSize;
380 else if (toSize == 0 || clobber) {
381 resultSize += fromSize;
385 resultSize += toSize;
394 resultSyms = from->syms[group];
395 darray_free(into->symsMapNumEntries[group]);
396 darray_free(into->symsMapIndex[group]);
397 into->symsMapNumEntries[group] = from->symsMapNumEntries[group];
398 into->symsMapIndex[group] = from->symsMapIndex[group];
399 darray_init(from->symsMapNumEntries[group]);
400 darray_init(from->symsMapIndex[group]);
403 else if (using == TO) {
404 resultSyms = into->syms[group];
408 darray_resize0(resultSyms, resultSize);
410 for (i = 0; i < resultWidth; i++) {
411 enum key_group_selector use = NONE;
412 unsigned int fromSize = 0;
413 unsigned int toSize = 0;
415 if (i < from->numLevels[group])
416 fromSize = darray_item(from->symsMapNumEntries[group], i);
418 if (i < into->numLevels[group])
419 toSize = darray_item(into->symsMapNumEntries[group], i);
421 if (fromSize == 0 && toSize == 0) {
422 darray_item(into->symsMapIndex[group], i) = -1;
423 darray_item(into->symsMapNumEntries[group], i) = 0;
429 else if (toSize == 0 || clobber)
434 if (toSize && fromSize && report) {
435 log_info(info->keymap->ctx,
436 "Multiple symbols for group %u, level %d on key %s; "
437 "Using %s, ignoring %s\n",
438 group + 1, i + 1, longText(into->name),
439 (use == FROM ? "from" : "to"),
440 (use == FROM ? "to" : "from"));
444 memcpy(darray_mem(resultSyms, cur_idx),
445 darray_mem(from->syms[group],
446 darray_item(from->symsMapIndex[group], i)),
447 darray_item(from->symsMapNumEntries[group],
448 i) * sizeof(xkb_keysym_t));
449 darray_item(into->symsMapIndex[group], i) = cur_idx;
450 darray_item(into->symsMapNumEntries[group], i) =
451 darray_item(from->symsMapNumEntries[group], i);
454 memcpy(darray_mem(resultSyms, cur_idx),
455 darray_mem(into->syms[group],
456 darray_item(into->symsMapIndex[group], i)),
457 darray_item(into->symsMapNumEntries[group],
458 i) * sizeof(xkb_keysym_t));
459 darray_item(into->symsMapIndex[group], i) = cur_idx;
461 cur_idx += darray_item(into->symsMapNumEntries[group], i);
465 if (!darray_same(resultActs, into->acts[group]))
466 darray_free(into->acts[group]);
467 if (!darray_same(resultActs, from->acts[group]))
468 darray_free(from->acts[group]);
469 into->numLevels[group] = resultWidth;
470 if (!darray_same(resultSyms, into->syms[group]))
471 darray_free(into->syms[group]);
472 into->syms[group] = resultSyms;
473 if (!darray_same(resultSyms, from->syms[group]))
474 darray_free(from->syms[group]);
475 darray_init(from->syms[group]);
476 darray_free(from->symsMapIndex[group]);
477 darray_free(from->symsMapNumEntries[group]);
478 into->acts[group] = resultActs;
479 darray_init(from->acts[group]);
480 if (!darray_empty(into->syms[group]))
481 into->symsDefined |= (1 << group);
482 from->symsDefined &= ~(1 << group);
483 into->actsDefined |= (1 << group);
484 from->actsDefined &= ~(1 << group);
490 UseNewKeyField(unsigned field, KeyInfo *old, KeyInfo *new, int verbosity,
493 if (!(old->defined & field))
496 if (new->defined & field) {
497 if ((old->file_id == new->file_id && verbosity > 0) || verbosity > 9)
500 if (new->merge != MERGE_AUGMENT)
509 MergeKeys(SymbolsInfo *info, KeyInfo *into, KeyInfo *from)
512 unsigned collide = 0;
514 int verbosity = xkb_get_log_verbosity(info->keymap->ctx);
516 if (from->merge == MERGE_REPLACE) {
517 for (i = 0; i < XkbNumKbdGroups; i++) {
518 if (into->numLevels[i] != 0) {
519 darray_free(into->syms[i]);
520 darray_free(into->acts[i]);
524 memset(from, 0, sizeof(KeyInfo));
528 report = (verbosity > 9 ||
529 (into->file_id == from->file_id && verbosity > 0));
531 for (i = 0; i < XkbNumKbdGroups; i++) {
532 if (from->numLevels[i] > 0) {
533 if (into->numLevels[i] == 0) {
534 into->numLevels[i] = from->numLevels[i];
535 into->syms[i] = from->syms[i];
536 into->symsMapIndex[i] = from->symsMapIndex[i];
537 into->symsMapNumEntries[i] = from->symsMapNumEntries[i];
538 into->acts[i] = from->acts[i];
539 into->symsDefined |= (1 << i);
540 darray_init(from->syms[i]);
541 darray_init(from->symsMapIndex[i]);
542 darray_init(from->symsMapNumEntries[i]);
543 darray_init(from->acts[i]);
544 from->numLevels[i] = 0;
545 from->symsDefined &= ~(1 << i);
546 if (!darray_empty(into->syms[i]))
547 into->defined |= _Key_Syms;
548 if (!darray_empty(into->acts[i]))
549 into->defined |= _Key_Acts;
553 if (!darray_empty(into->syms[i]))
554 collide |= _Key_Syms;
555 if (!darray_empty(into->acts[i]))
556 collide |= _Key_Acts;
558 MergeKeyGroups(info, into, from, (unsigned) i);
561 if (from->types[i] != XKB_ATOM_NONE) {
562 if ((into->types[i] != XKB_ATOM_NONE) && report &&
563 (into->types[i] != from->types[i])) {
564 xkb_atom_t use, ignore;
565 collide |= _Key_Types;
566 if (from->merge != MERGE_AUGMENT) {
567 use = from->types[i];
568 ignore = into->types[i];
571 use = into->types[i];
572 ignore = from->types[i];
575 log_warn(info->keymap->ctx,
576 "Multiple definitions for group %d type of key %s; "
577 "Using %s, ignoring %s\n",
578 i, longText(into->name),
579 xkb_atom_text(info->keymap->ctx, use),
580 xkb_atom_text(info->keymap->ctx, ignore));
583 if (from->merge != MERGE_AUGMENT ||
584 into->types[i] == XKB_ATOM_NONE) {
585 into->types[i] = from->types[i];
590 if (UseNewKeyField(_Key_Behavior, into, from, verbosity, &collide)) {
591 into->behavior = from->behavior;
592 into->defined |= _Key_Behavior;
594 if (UseNewKeyField(_Key_VModMap, into, from, verbosity, &collide)) {
595 into->vmodmap = from->vmodmap;
596 into->defined |= _Key_VModMap;
598 if (UseNewKeyField(_Key_Repeat, into, from, verbosity, &collide)) {
599 into->repeat = from->repeat;
600 into->defined |= _Key_Repeat;
602 if (UseNewKeyField(_Key_Type_Dflt, into, from, verbosity, &collide)) {
603 into->dfltType = from->dfltType;
604 into->defined |= _Key_Type_Dflt;
606 if (UseNewKeyField(_Key_GroupInfo, into, from, verbosity, &collide)) {
607 into->out_of_range_group_action = from->out_of_range_group_action;
608 into->out_of_range_group_number = from->out_of_range_group_number;
609 into->defined |= _Key_GroupInfo;
613 log_warn(info->keymap->ctx,
614 "Symbol map for key %s redefined; "
615 "Using %s definition for conflicting fields\n",
616 longText(into->name),
617 (from->merge == MERGE_AUGMENT ? "first" : "last"));
623 AddKeySymbols(SymbolsInfo *info, KeyInfo *keyi)
625 unsigned long real_name;
628 darray_foreach(iter, info->keys)
629 if (iter->name == keyi->name)
630 return MergeKeys(info, iter, keyi);
632 if (FindKeyNameForAlias(info->keymap, keyi->name, &real_name))
633 darray_foreach(iter, info->keys)
634 if (iter->name == real_name)
635 return MergeKeys(info, iter, keyi);
637 darray_resize0(info->keys, darray_size(info->keys) + 1);
638 new = &darray_item(info->keys, darray_size(info->keys) - 1);
639 return CopyKeyInfo(keyi, new, true);
643 AddModMapEntry(SymbolsInfo * info, ModMapEntry * new)
648 clobber = (new->merge != MERGE_AUGMENT);
649 list_foreach(mm, &info->modMaps, entry) {
650 if (new->haveSymbol && mm->haveSymbol
651 && (new->u.keySym == mm->u.keySym)) {
652 unsigned use, ignore;
653 if (mm->modifier != new->modifier) {
656 ignore = mm->modifier;
660 ignore = new->modifier;
662 log_err(info->keymap->ctx,
663 "%s added to symbol map for multiple modifiers; "
664 "Using %s, ignoring %s.\n",
665 XkbcKeysymText(new->u.keySym),
666 XkbcModIndexText(use),
667 XkbcModIndexText(ignore));
672 if ((!new->haveSymbol) && (!mm->haveSymbol) &&
673 (new->u.keyName == mm->u.keyName)) {
674 unsigned use, ignore;
675 if (mm->modifier != new->modifier) {
678 ignore = mm->modifier;
682 ignore = new->modifier;
684 log_err(info->keymap->ctx,
685 "Key %s added to map for multiple modifiers; "
686 "Using %s, ignoring %s.\n",
687 longText(new->u.keyName),
688 XkbcModIndexText(use),
689 XkbcModIndexText(ignore));
696 mm = malloc(sizeof(*mm));
698 log_wsgo(info->keymap->ctx,
699 "Could not allocate modifier map entry; "
700 "Modifier map for %s will be incomplete\n",
701 XkbcModIndexText(new->modifier));
706 list_add(&mm->entry, &info->modMaps);
710 /***====================================================================***/
713 MergeIncludedSymbols(SymbolsInfo *into, SymbolsInfo *from,
714 enum merge_mode merge)
718 ModMapEntry *mm, *next;
720 if (from->errorCount > 0) {
721 into->errorCount += from->errorCount;
724 if (into->name == NULL) {
725 into->name = from->name;
728 for (i = 0; i < XkbNumKbdGroups; i++) {
729 if (from->groupNames[i] != XKB_ATOM_NONE) {
730 if ((merge != MERGE_AUGMENT) ||
731 (into->groupNames[i] == XKB_ATOM_NONE))
732 into->groupNames[i] = from->groupNames[i];
736 darray_foreach(keyi, from->keys) {
737 if (merge != MERGE_DEFAULT)
740 if (!AddKeySymbols(into, keyi))
744 list_foreach_safe(mm, next, &from->modMaps, entry) {
745 if (merge != MERGE_DEFAULT)
747 if (!AddModMapEntry(into, mm))
751 list_init(&from->modMaps);
755 HandleSymbolsFile(SymbolsInfo *info, XkbFile *file, enum merge_mode merge);
758 HandleIncludeSymbols(SymbolsInfo *info, IncludeStmt *stmt)
760 enum merge_mode merge = MERGE_DEFAULT;
762 SymbolsInfo included, next_incl;
764 InitSymbolsInfo(&included, info->keymap, info->file_id);
767 included.name = stmt->stmt;
771 for (; stmt; stmt = stmt->next) {
772 if (!ProcessIncludeFile(info->keymap->ctx, stmt, FILE_TYPE_SYMBOLS,
774 info->errorCount += 10;
775 FreeSymbolsInfo(&included);
779 InitSymbolsInfo(&next_incl, info->keymap, rtrn->id);
780 next_incl.merge = next_incl.dflt.merge = MERGE_OVERRIDE;
782 next_incl.explicit_group = atoi(stmt->modifier) - 1;
784 next_incl.explicit_group = info->explicit_group;
786 HandleSymbolsFile(&next_incl, rtrn, MERGE_OVERRIDE);
788 MergeIncludedSymbols(&included, &next_incl, merge);
790 FreeSymbolsInfo(&next_incl);
794 MergeIncludedSymbols(info, &included, merge);
795 FreeSymbolsInfo(&included);
797 return (info->errorCount == 0);
804 GetGroupIndex(SymbolsInfo *info, KeyInfo *keyi, ExprDef *arrayNdx,
805 unsigned what, xkb_group_index_t *ndx_rtrn)
815 if (arrayNdx == NULL) {
819 defined = keyi->symsDefined;
821 defined = keyi->actsDefined;
823 for (i = 0; i < XkbNumKbdGroups; i++) {
824 if ((defined & (1 << i)) == 0) {
829 log_err(info->keymap->ctx,
830 "Too many groups of %s for key %s (max %u); "
831 "Ignoring %s defined for extra groups\n",
832 name, longText(keyi->name), XkbNumKbdGroups + 1, name);
835 if (!ExprResolveGroup(info->keymap->ctx, arrayNdx, &tmp)) {
836 log_err(info->keymap->ctx,
837 "Illegal group index for %s of key %s\n"
838 "Definition with non-integer array index ignored\n",
839 name, longText(keyi->name));
842 *ndx_rtrn = tmp.uval - 1;
847 AddSymbolsToKey(SymbolsInfo *info, KeyInfo *keyi, ExprDef *arrayNdx,
850 xkb_group_index_t ndx;
851 size_t nSyms, nLevels;
855 if (!GetGroupIndex(info, keyi, arrayNdx, SYMBOLS, &ndx))
858 keyi->symsDefined |= (1 << ndx);
861 if (value->op != ExprKeysymList) {
862 log_err(info->keymap->ctx,
863 "Expected a list of symbols, found %s; "
864 "Ignoring symbols for group %u of %s\n",
865 exprOpText(value->op), ndx + 1, longText(keyi->name));
868 if (!darray_empty(keyi->syms[ndx])) {
869 log_err(info->keymap->ctx,
870 "Symbols for key %s, group %u already defined; "
871 "Ignoring duplicate definition\n",
872 longText(keyi->name), ndx + 1);
875 nSyms = darray_size(value->value.list.syms);
876 nLevels = darray_size(value->value.list.symsMapIndex);
877 if ((keyi->numLevels[ndx] < nSyms || darray_empty(keyi->syms[ndx])) &&
878 (!ResizeKeyGroup(keyi, ndx, nLevels, nSyms, false))) {
879 log_wsgo(info->keymap->ctx,
880 "Could not resize group %u of key %s to contain %zu levels; "
882 ndx + 1, longText(keyi->name), nSyms);
885 keyi->symsDefined |= (1 << ndx);
886 for (i = 0; i < nLevels; i++) {
887 darray_item(keyi->symsMapIndex[ndx], i) =
888 darray_item(value->value.list.symsMapIndex, i);
889 darray_item(keyi->symsMapNumEntries[ndx], i) =
890 darray_item(value->value.list.symsNumEntries, i);
892 for (j = 0; j < darray_item(keyi->symsMapNumEntries[ndx], i); j++) {
893 /* FIXME: What's abort() doing here? */
894 if (darray_item(keyi->symsMapIndex[ndx], i) + j >= nSyms)
896 if (!LookupKeysym(darray_item(value->value.list.syms,
897 darray_item(value->value.list.symsMapIndex,
899 &darray_item(keyi->syms[ndx],
900 darray_item(keyi->symsMapIndex[ndx],
902 log_warn(info->keymap->ctx,
903 "Could not resolve keysym %s for key %s, group %u (%s), level %zu\n",
904 darray_item(value->value.list.syms, i),
905 longText(keyi->name),
907 xkb_atom_text(info->keymap->ctx,
908 info->groupNames[ndx]),
911 darray_item(keyi->syms[ndx],
912 darray_item(keyi->symsMapIndex[ndx],
913 i) + j) = XKB_KEY_NoSymbol;
914 darray_item(keyi->symsMapIndex[ndx], i) = -1;
915 darray_item(keyi->symsMapNumEntries[ndx], i) = 0;
918 if (darray_item(keyi->symsMapNumEntries[ndx], i) == 1 &&
919 darray_item(keyi->syms[ndx],
920 darray_item(keyi->symsMapIndex[ndx],
921 i) + j) == XKB_KEY_NoSymbol) {
922 darray_item(keyi->symsMapIndex[ndx], i) = -1;
923 darray_item(keyi->symsMapNumEntries[ndx], i) = 0;
927 for (j = keyi->numLevels[ndx] - 1;
928 j >= 0 && darray_item(keyi->symsMapNumEntries[ndx], j) == 0; j--)
929 keyi->numLevels[ndx]--;
934 AddActionsToKey(SymbolsInfo *info, KeyInfo *keyi, ExprDef *arrayNdx,
938 xkb_group_index_t ndx;
941 struct xkb_any_action *toAct;
943 if (!GetGroupIndex(info, keyi, arrayNdx, ACTIONS, &ndx))
947 keyi->actsDefined |= (1 << ndx);
951 if (value->op != ExprActionList) {
952 log_wsgo(info->keymap->ctx,
953 "Bad expression type (%d) for action list value; "
954 "Ignoring actions for group %u of %s\n",
955 value->op, ndx, longText(keyi->name));
959 if (!darray_empty(keyi->acts[ndx])) {
960 log_wsgo(info->keymap->ctx,
961 "Actions for key %s, group %u already defined\n",
962 longText(keyi->name), ndx);
966 for (nActs = 0, act = value->value.child; act != NULL; nActs++) {
967 act = (ExprDef *) act->common.next;
971 log_wsgo(info->keymap->ctx,
972 "Action list but not actions in AddActionsToKey\n");
976 if ((keyi->numLevels[ndx] < nActs || darray_empty(keyi->acts[ndx])) &&
977 !ResizeKeyGroup(keyi, ndx, nActs, nActs, true)) {
978 log_wsgo(info->keymap->ctx,
979 "Could not resize group %u of key %s; "
981 ndx, longText(keyi->name));
984 keyi->actsDefined |= (1 << ndx);
986 toAct = (struct xkb_any_action *) darray_mem(keyi->acts[ndx], 0);
987 act = value->value.child;
988 for (i = 0; i < nActs; i++, toAct++) {
989 if (!HandleActionDef(act, info->keymap, toAct, info->action)) {
990 log_err(info->keymap->ctx,
991 "Illegal action definition for %s; "
992 "Action for group %u/level %zu ignored\n",
993 longText(keyi->name), ndx + 1, i + 1);
995 act = (ExprDef *) act->common.next;
1001 static const LookupEntry lockingEntries[] = {
1002 { "true", XkbKB_Lock },
1003 { "yes", XkbKB_Lock },
1004 { "on", XkbKB_Lock },
1005 { "false", XkbKB_Default },
1006 { "no", XkbKB_Default },
1007 { "off", XkbKB_Default },
1008 { "permanent", XkbKB_Lock | XkbKB_Permanent },
1012 static const LookupEntry repeatEntries[] = {
1013 { "true", RepeatYes },
1014 { "yes", RepeatYes },
1015 { "on", RepeatYes },
1016 { "false", RepeatNo },
1018 { "off", RepeatNo },
1019 { "default", RepeatUndefined },
1024 SetSymbolsField(SymbolsInfo *info, KeyInfo *keyi, const char *field,
1025 ExprDef *arrayNdx, ExprDef *value)
1029 struct xkb_context *ctx = info->keymap->ctx;
1031 if (strcasecmp(field, "type") == 0) {
1033 if (!ExprResolveString(ctx, value, &tmp))
1034 log_lvl(info->keymap->ctx, 1,
1035 "The type field of a key symbol map must be a string; "
1036 "Ignoring illegal type definition\n");
1037 if (arrayNdx == NULL) {
1038 keyi->dfltType = xkb_atom_intern(ctx, tmp.str);
1039 keyi->defined |= _Key_Type_Dflt;
1041 else if (!ExprResolveGroup(ctx, arrayNdx, &ndx)) {
1042 log_err(info->keymap->ctx,
1043 "Illegal group index for type of key %s; "
1044 "Definition with non-integer array index ignored\n",
1045 longText(keyi->name));
1049 keyi->types[ndx.uval - 1] = xkb_atom_intern(ctx, tmp.str);
1050 keyi->typesDefined |= (1 << (ndx.uval - 1));
1053 else if (strcasecmp(field, "symbols") == 0)
1054 return AddSymbolsToKey(info, keyi, arrayNdx, value);
1055 else if (strcasecmp(field, "actions") == 0)
1056 return AddActionsToKey(info, keyi, arrayNdx, value);
1057 else if ((strcasecmp(field, "vmods") == 0) ||
1058 (strcasecmp(field, "virtualmods") == 0) ||
1059 (strcasecmp(field, "virtualmodifiers") == 0)) {
1060 ok = ExprResolveVModMask(info->keymap, value, &tmp);
1062 keyi->vmodmap = (tmp.uval >> 8);
1063 keyi->defined |= _Key_VModMap;
1066 log_err(info->keymap->ctx,
1067 "Expected a virtual modifier mask, found %s; "
1068 "Ignoring virtual modifiers definition for key %s\n",
1069 exprOpText(value->op), longText(keyi->name));
1072 else if ((strcasecmp(field, "locking") == 0) ||
1073 (strcasecmp(field, "lock") == 0) ||
1074 (strcasecmp(field, "locks") == 0)) {
1075 ok = ExprResolveEnum(ctx, value, &tmp, lockingEntries);
1077 keyi->behavior.type = tmp.uval;
1078 keyi->defined |= _Key_Behavior;
1080 else if ((strcasecmp(field, "radiogroup") == 0) ||
1081 (strcasecmp(field, "permanentradiogroup") == 0) ||
1082 (strcasecmp(field, "allownone") == 0)) {
1083 log_err(info->keymap->ctx,
1084 "Radio groups not supported; "
1085 "Ignoring radio group specification for key %s\n",
1086 longText(keyi->name));
1089 else if (uStrCasePrefix("overlay", field) ||
1090 uStrCasePrefix("permanentoverlay", field)) {
1091 log_err(info->keymap->ctx,
1092 "Overlays not supported; "
1093 "Ignoring overlay specification for key %s\n",
1094 longText(keyi->name));
1096 else if ((strcasecmp(field, "repeating") == 0) ||
1097 (strcasecmp(field, "repeats") == 0) ||
1098 (strcasecmp(field, "repeat") == 0)) {
1099 ok = ExprResolveEnum(ctx, value, &tmp, repeatEntries);
1101 log_err(info->keymap->ctx,
1102 "Illegal repeat setting for %s; "
1103 "Non-boolean repeat setting ignored\n",
1104 longText(keyi->name));
1107 keyi->repeat = tmp.uval;
1108 keyi->defined |= _Key_Repeat;
1110 else if ((strcasecmp(field, "groupswrap") == 0) ||
1111 (strcasecmp(field, "wrapgroups") == 0)) {
1112 ok = ExprResolveBoolean(ctx, value, &tmp);
1114 log_err(info->keymap->ctx,
1115 "Illegal groupsWrap setting for %s; "
1116 "Non-boolean value ignored\n",
1117 longText(keyi->name));
1121 keyi->out_of_range_group_action = XkbWrapIntoRange;
1123 keyi->out_of_range_group_action = XkbClampIntoRange;
1124 keyi->defined |= _Key_GroupInfo;
1126 else if ((strcasecmp(field, "groupsclamp") == 0) ||
1127 (strcasecmp(field, "clampgroups") == 0)) {
1128 ok = ExprResolveBoolean(ctx, value, &tmp);
1130 log_err(info->keymap->ctx,
1131 "Illegal groupsClamp setting for %s; "
1132 "Non-boolean value ignored\n",
1133 longText(keyi->name));
1137 keyi->out_of_range_group_action = XkbClampIntoRange;
1139 keyi->out_of_range_group_action = XkbWrapIntoRange;
1140 keyi->defined |= _Key_GroupInfo;
1142 else if ((strcasecmp(field, "groupsredirect") == 0) ||
1143 (strcasecmp(field, "redirectgroups") == 0)) {
1144 if (!ExprResolveGroup(ctx, value, &tmp)) {
1145 log_err(info->keymap->ctx,
1146 "Illegal group index for redirect of key %s; "
1147 "Definition with non-integer group ignored\n",
1148 longText(keyi->name));
1151 keyi->out_of_range_group_action = XkbRedirectIntoRange;
1152 keyi->out_of_range_group_number = tmp.uval - 1;
1153 keyi->defined |= _Key_GroupInfo;
1156 log_err(info->keymap->ctx,
1157 "Unknown field %s in a symbol interpretation; "
1158 "Definition ignored\n",
1166 SetGroupName(SymbolsInfo *info, ExprDef *arrayNdx, ExprDef *value)
1168 ExprResult tmp, name;
1171 log_lvl(info->keymap->ctx, 1,
1172 "You must specify an index when specifying a group name; "
1173 "Group name definition without array subscript ignored\n");
1177 if (!ExprResolveGroup(info->keymap->ctx, arrayNdx, &tmp)) {
1178 log_err(info->keymap->ctx,
1179 "Illegal index in group name definition; "
1180 "Definition with non-integer array index ignored\n");
1184 if (!ExprResolveString(info->keymap->ctx, value, &name)) {
1185 log_err(info->keymap->ctx,
1186 "Group name must be a string; "
1187 "Illegal name for group %d ignored\n", tmp.uval);
1191 info->groupNames[tmp.uval - 1 + info->explicit_group] =
1192 xkb_atom_intern(info->keymap->ctx, name.str);
1198 HandleSymbolsVar(SymbolsInfo *info, VarDef *stmt)
1200 ExprResult elem, field;
1204 if (ExprResolveLhs(info->keymap, stmt->name, &elem, &field,
1206 return 0; /* internal error, already reported */
1207 if (elem.str && (strcasecmp(elem.str, "key") == 0)) {
1208 ret = SetSymbolsField(info, &info->dflt, field.str, arrayNdx,
1211 else if ((elem.str == NULL) && ((strcasecmp(field.str, "name") == 0) ||
1212 (strcasecmp(field.str, "groupname") ==
1214 ret = SetGroupName(info, arrayNdx, stmt->value);
1216 else if ((elem.str == NULL)
1217 && ((strcasecmp(field.str, "groupswrap") == 0) ||
1218 (strcasecmp(field.str, "wrapgroups") == 0))) {
1219 log_err(info->keymap->ctx,
1220 "Global \"groupswrap\" not supported; Ignored\n");
1223 else if ((elem.str == NULL)
1224 && ((strcasecmp(field.str, "groupsclamp") == 0) ||
1225 (strcasecmp(field.str, "clampgroups") == 0))) {
1226 log_err(info->keymap->ctx,
1227 "Global \"groupsclamp\" not supported; Ignored\n");
1230 else if ((elem.str == NULL)
1231 && ((strcasecmp(field.str, "groupsredirect") == 0) ||
1232 (strcasecmp(field.str, "redirectgroups") == 0))) {
1233 log_err(info->keymap->ctx,
1234 "Global \"groupsredirect\" not supported; Ignored\n");
1237 else if ((elem.str == NULL) &&
1238 (strcasecmp(field.str, "allownone") == 0)) {
1239 log_err(info->keymap->ctx,
1240 "Radio groups not supported; "
1241 "Ignoring \"allownone\" specification\n");
1245 ret = SetActionField(info->keymap, elem.str, field.str, arrayNdx,
1246 stmt->value, &info->action);
1253 HandleSymbolsBody(SymbolsInfo *info, VarDef *def, KeyInfo *keyi)
1256 ExprResult tmp, field;
1259 for (; def != NULL; def = (VarDef *) def->common.next) {
1260 if ((def->name) && (def->name->type == ExprFieldRef)) {
1261 ok = HandleSymbolsVar(info, def);
1266 if (!def->value || (def->value->op == ExprKeysymList))
1267 field.str = "symbols";
1269 field.str = "actions";
1273 ok = ExprResolveLhs(info->keymap, def->name, &tmp, &field,
1278 ok = SetSymbolsField(info, keyi, field.str, arrayNdx,
1286 SetExplicitGroup(SymbolsInfo *info, KeyInfo *keyi)
1288 xkb_group_index_t group = info->explicit_group;
1293 if ((keyi->typesDefined | keyi->symsDefined | keyi->actsDefined) & ~1) {
1294 xkb_group_index_t i;
1295 log_warn(info->keymap->ctx,
1296 "For the map %s an explicit group specified\n",
1298 log_warn(info->keymap->ctx,
1299 "but key %s has more than one group defined; "
1300 "All groups except first one will be ignored\n",
1301 longText(keyi->name));
1302 for (i = 1; i < XkbNumKbdGroups; i++) {
1303 keyi->numLevels[i] = 0;
1304 darray_free(keyi->syms[i]);
1305 darray_free(keyi->acts[i]);
1309 keyi->typesDefined = keyi->symsDefined = keyi->actsDefined = 1 << group;
1311 keyi->numLevels[group] = keyi->numLevels[0];
1312 keyi->numLevels[0] = 0;
1313 keyi->syms[group] = keyi->syms[0];
1314 darray_init(keyi->syms[0]);
1315 keyi->symsMapIndex[group] = keyi->symsMapIndex[0];
1316 darray_init(keyi->symsMapIndex[0]);
1317 keyi->symsMapNumEntries[group] = keyi->symsMapNumEntries[0];
1318 darray_init(keyi->symsMapNumEntries[0]);
1319 keyi->acts[group] = keyi->acts[0];
1320 darray_init(keyi->acts[0]);
1321 keyi->types[group] = keyi->types[0];
1327 HandleSymbolsDef(SymbolsInfo *info, SymbolsDef *stmt)
1331 InitKeyInfo(&keyi, info->file_id);
1332 CopyKeyInfo(&info->dflt, &keyi, false);
1333 keyi.merge = stmt->merge;
1334 keyi.name = KeyNameToLong(stmt->keyName);
1335 if (!HandleSymbolsBody(info, (VarDef *) stmt->symbols, &keyi)) {
1340 if (!SetExplicitGroup(info, &keyi)) {
1345 if (!AddKeySymbols(info, &keyi)) {
1353 HandleModMapDef(SymbolsInfo *info, ModMapDef *def)
1359 struct xkb_context *ctx = info->keymap->ctx;
1361 if (!LookupModIndex(ctx, NULL, def->modifier, TypeInt, &rtrn)) {
1362 log_err(info->keymap->ctx,
1363 "Illegal modifier map definition; "
1364 "Ignoring map for non-modifier \"%s\"\n",
1365 xkb_atom_text(ctx, def->modifier));
1369 tmp.modifier = rtrn.uval;
1370 for (key = def->keys; key != NULL; key = (ExprDef *) key->common.next) {
1371 if ((key->op == ExprValue) && (key->type == TypeKeyName)) {
1372 tmp.haveSymbol = false;
1373 tmp.u.keyName = KeyNameToLong(key->value.keyName);
1375 else if (ExprResolveKeySym(ctx, key, &rtrn)) {
1376 tmp.haveSymbol = true;
1377 tmp.u.keySym = rtrn.uval;
1380 log_err(info->keymap->ctx,
1381 "Modmap entries may contain only key names or keysyms; "
1382 "Illegal definition for %s modifier ignored\n",
1383 XkbcModIndexText(tmp.modifier));
1387 ok = AddModMapEntry(info, &tmp) && ok;
1393 HandleSymbolsFile(SymbolsInfo *info, XkbFile *file, enum merge_mode merge)
1398 info->name = uDupString(file->name);
1402 switch (stmt->stmtType) {
1404 if (!HandleIncludeSymbols(info, (IncludeStmt *) stmt))
1407 case StmtSymbolsDef:
1408 if (!HandleSymbolsDef(info, (SymbolsDef *) stmt))
1412 if (!HandleSymbolsVar(info, (VarDef *) stmt))
1416 if (!HandleVModDef((VModDef *) stmt, info->keymap, merge,
1421 log_err(info->keymap->ctx,
1422 "Interpretation files may not include other types; "
1423 "Ignoring definition of symbol interpretation\n");
1426 case StmtKeycodeDef:
1427 log_err(info->keymap->ctx,
1428 "Interpretation files may not include other types; "
1429 "Ignoring definition of key name\n");
1433 if (!HandleModMapDef(info, (ModMapDef *) stmt))
1437 log_wsgo(info->keymap->ctx,
1438 "Unexpected statement type %d in HandleSymbolsFile\n",
1443 if (info->errorCount > 10) {
1444 log_err(info->keymap->ctx, "Abandoning symbols file \"%s\"\n",
1452 * Given a keysym @sym, return a key which generates it, or NULL.
1453 * This is used for example in a modifier map definition, such as:
1454 * modifier_map Lock { Caps_Lock };
1455 * where we want to add the Lock modifier to the modmap of the key
1456 * which matches the keysym Caps_Lock.
1457 * Since there can be many keys which generates the keysym, the key
1458 * is chosen first by lowest group in which the keysym appears, than
1459 * by lowest level and than by lowest key code.
1461 static struct xkb_key *
1462 FindKeyForSymbol(struct xkb_keymap *keymap, xkb_keysym_t sym)
1464 struct xkb_key *key, *ret = NULL;
1465 xkb_group_index_t group, min_group = UINT_MAX;
1466 unsigned int level, min_level = UINT_MAX;
1468 xkb_foreach_key(key, keymap) {
1469 for (group = 0; group < key->num_groups; group++) {
1470 for (level = 0; level < XkbKeyGroupWidth(keymap, key, group);
1472 if (XkbKeyNumSyms(key, group, level) != 1 ||
1473 (XkbKeySymEntry(key, group, level))[0] != sym)
1477 * If the keysym was found in a group or level > 0, we must
1478 * keep looking since we might find a key in which the keysym
1479 * is in a lower group or level.
1481 if (group < min_group ||
1482 (group == min_group && level < min_level)) {
1484 if (group == 0 && level == 0) {
1500 * Find the given name in the keymap->map->types and return its index.
1502 * @param atom The atom to search for.
1503 * @param type_rtrn Set to the index of the name if found.
1505 * @return true if found, false otherwise.
1508 FindNamedType(struct xkb_keymap *keymap, xkb_atom_t atom, unsigned *type_rtrn)
1511 const char *name = xkb_atom_text(keymap->ctx, atom);
1512 struct xkb_key_type *type;
1515 darray_foreach(type, keymap->types) {
1516 if (strcmp(type->name, name) == 0) {
1527 * Assign a type to the given sym and return the Atom for the type assigned.
1530 * - ONE_LEVEL for width 0/1
1531 * - ALPHABETIC for 2 shift levels, with lower/upercase
1532 * - KEYPAD for keypad keys.
1533 * - TWO_LEVEL for other 2 shift level keys.
1534 * and the same for four level keys.
1536 * @param width Number of sysms in syms.
1537 * @param syms The keysyms for the given key (must be size width).
1538 * @param typeNameRtrn Set to the Atom of the type name.
1540 * @returns true if a type could be found, false otherwise.
1542 * FIXME: I need to take the KeyInfo so I can look at symsMapIndex and
1543 * all that fun stuff rather than just assuming there's always one
1547 FindAutomaticType(struct xkb_keymap *keymap, int width,
1548 const xkb_keysym_t *syms, xkb_atom_t *typeNameRtrn,
1552 if ((width == 1) || (width == 0)) {
1553 *typeNameRtrn = xkb_atom_intern(keymap->ctx, "ONE_LEVEL");
1556 else if (width == 2) {
1557 if (syms && xkb_keysym_is_lower(syms[0]) &&
1558 xkb_keysym_is_upper(syms[1])) {
1559 *typeNameRtrn = xkb_atom_intern(keymap->ctx, "ALPHABETIC");
1561 else if (syms && (xkb_keysym_is_keypad(syms[0]) ||
1562 xkb_keysym_is_keypad(syms[1]))) {
1563 *typeNameRtrn = xkb_atom_intern(keymap->ctx, "KEYPAD");
1567 *typeNameRtrn = xkb_atom_intern(keymap->ctx, "TWO_LEVEL");
1571 else if (width <= 4) {
1572 if (syms && xkb_keysym_is_lower(syms[0]) &&
1573 xkb_keysym_is_upper(syms[1]))
1574 if (xkb_keysym_is_lower(syms[2]) && xkb_keysym_is_upper(syms[3]))
1576 xkb_atom_intern(keymap->ctx, "FOUR_LEVEL_ALPHABETIC");
1578 *typeNameRtrn = xkb_atom_intern(keymap->ctx,
1579 "FOUR_LEVEL_SEMIALPHABETIC");
1581 else if (syms && (xkb_keysym_is_keypad(syms[0]) ||
1582 xkb_keysym_is_keypad(syms[1])))
1583 *typeNameRtrn = xkb_atom_intern(keymap->ctx, "FOUR_LEVEL_KEYPAD");
1585 *typeNameRtrn = xkb_atom_intern(keymap->ctx, "FOUR_LEVEL");
1586 /* XXX: why not set autoType here? */
1588 return ((width >= 0) && (width <= 4));
1592 * Ensure the given KeyInfo is in a coherent state, i.e. no gaps between the
1593 * groups, and reduce to one group if all groups are identical anyway.
1596 PrepareKeyDef(KeyInfo *keyi)
1598 xkb_group_index_t i, lastGroup;
1599 int j, width, defined;
1602 defined = keyi->symsDefined | keyi->actsDefined | keyi->typesDefined;
1603 /* get highest group number */
1604 for (i = XkbNumKbdGroups - 1; i > 0; i--) {
1605 if (defined & (1 << i))
1613 /* If there are empty groups between non-empty ones fill them with data */
1614 /* from the first group. */
1615 /* We can make a wrong assumption here. But leaving gaps is worse. */
1616 for (i = lastGroup; i > 0; i--) {
1617 if (defined & (1 << i))
1619 width = keyi->numLevels[0];
1620 if (keyi->typesDefined & 1) {
1621 for (j = 0; j < width; j++) {
1622 keyi->types[i] = keyi->types[0];
1624 keyi->typesDefined |= 1 << i;
1626 if ((keyi->actsDefined & 1) && !darray_empty(keyi->acts[0])) {
1627 darray_copy(keyi->acts[i], keyi->acts[0]);
1628 keyi->actsDefined |= 1 << i;
1630 if ((keyi->symsDefined & 1) && !darray_empty(keyi->syms[0])) {
1631 darray_copy(keyi->syms[i], keyi->syms[0]);
1632 darray_copy(keyi->symsMapIndex[i], keyi->symsMapIndex[0]);
1633 darray_copy(keyi->symsMapNumEntries[i],
1634 keyi->symsMapNumEntries[0]);
1635 keyi->symsDefined |= 1 << i;
1638 keyi->numLevels[i] = keyi->numLevels[0];
1641 /* If all groups are completely identical remove them all */
1642 /* exept the first one. */
1644 for (i = lastGroup; i > 0; i--) {
1645 if ((keyi->numLevels[i] != keyi->numLevels[0]) ||
1646 (keyi->types[i] != keyi->types[0])) {
1650 if (!darray_same(keyi->syms[i], keyi->syms[0]) &&
1651 (darray_empty(keyi->syms[i]) || darray_empty(keyi->syms[0]) ||
1652 darray_size(keyi->syms[i]) != darray_size(keyi->syms[0]) ||
1653 memcmp(darray_mem(keyi->syms[i], 0),
1654 darray_mem(keyi->syms[0], 0),
1655 sizeof(xkb_keysym_t) * darray_size(keyi->syms[0])))) {
1659 if (!darray_same(keyi->symsMapIndex[i], keyi->symsMapIndex[0]) &&
1660 (darray_empty(keyi->symsMapIndex[i]) ||
1661 darray_empty(keyi->symsMapIndex[0]) ||
1662 memcmp(darray_mem(keyi->symsMapIndex[i], 0),
1663 darray_mem(keyi->symsMapIndex[0], 0),
1664 keyi->numLevels[0] * sizeof(int)))) {
1668 if (!darray_same(keyi->symsMapNumEntries[i],
1669 keyi->symsMapNumEntries[0]) &&
1670 (darray_empty(keyi->symsMapNumEntries[i]) ||
1671 darray_empty(keyi->symsMapNumEntries[0]) ||
1672 memcmp(darray_mem(keyi->symsMapNumEntries[i], 0),
1673 darray_mem(keyi->symsMapNumEntries[0], 0),
1674 keyi->numLevels[0] * sizeof(size_t)))) {
1678 if (!darray_same(keyi->acts[i], keyi->acts[0]) &&
1679 (darray_empty(keyi->acts[i]) || darray_empty(keyi->acts[0]) ||
1680 memcmp(darray_mem(keyi->acts[i], 0),
1681 darray_mem(keyi->acts[0], 0),
1682 keyi->numLevels[0] * sizeof(union xkb_action)))) {
1688 for (i = lastGroup; i > 0; i--) {
1689 keyi->numLevels[i] = 0;
1690 darray_free(keyi->syms[i]);
1691 darray_free(keyi->symsMapIndex[i]);
1692 darray_free(keyi->symsMapNumEntries[i]);
1693 darray_free(keyi->acts[i]);
1696 keyi->symsDefined &= 1;
1697 keyi->actsDefined &= 1;
1698 keyi->typesDefined &= 1;
1703 * Copy the KeyInfo into the keyboard description.
1705 * This function recurses.
1708 CopySymbolsDef(SymbolsInfo *info, KeyInfo *keyi,
1709 xkb_keycode_t start_from)
1711 struct xkb_keymap *keymap = info->keymap;
1713 struct xkb_key *key;
1714 size_t sizeSyms = 0;
1715 xkb_group_index_t i, nGroups;
1716 unsigned width, tmp;
1717 struct xkb_key_type * type;
1718 bool haveActions, autoType, useAlias;
1719 unsigned types[XkbNumKbdGroups];
1720 union xkb_action *outActs;
1721 unsigned int symIndex = 0;
1723 useAlias = (start_from == 0);
1725 key = FindNamedKey(keymap, keyi->name, useAlias,
1726 CreateKeyNames(keymap), start_from);
1728 if (start_from == 0)
1729 log_lvl(info->keymap->ctx, 5,
1730 "Key %s not found in keycodes; Symbols ignored\n",
1731 longText(keyi->name));
1734 kc = XkbKeyGetKeycode(keymap, key);
1736 haveActions = false;
1738 for (i = nGroups = 0; i < XkbNumKbdGroups; i++) {
1739 if (((i + 1) > nGroups)
1740 && (((keyi->symsDefined | keyi->actsDefined) & (1 << i))
1741 || (keyi->typesDefined) & (1 << i)))
1743 if (!darray_empty(keyi->acts[i]))
1746 /* Assign the type to the key, if it is missing. */
1747 if (keyi->types[i] == XKB_ATOM_NONE) {
1748 if (keyi->dfltType != XKB_ATOM_NONE)
1749 keyi->types[i] = keyi->dfltType;
1750 else if (FindAutomaticType(keymap, keyi->numLevels[i],
1751 darray_mem(keyi->syms[i], 0),
1752 &keyi->types[i], &autoType)) { }
1754 log_lvl(info->keymap->ctx, 5,
1755 "No automatic type for %d symbols; "
1756 "Using %s for the %s key (keycode %d)\n",
1758 xkb_atom_text(keymap->ctx, keyi->types[i]),
1759 longText(keyi->name), kc);
1761 if (FindNamedType(keymap, keyi->types[i], &types[i])) {
1762 if (!autoType || keyi->numLevels[i] > 2)
1763 key->explicit |= (1 << i);
1766 log_lvl(info->keymap->ctx, 3,
1767 "Type \"%s\" is not defined; "
1768 "Using TWO_LEVEL for the %s key (keycode %d)\n",
1769 xkb_atom_text(keymap->ctx, keyi->types[i]),
1770 longText(keyi->name), kc);
1771 types[i] = XkbTwoLevelIndex;
1774 /* if the type specifies fewer levels than the key has, shrink the key */
1775 type = &darray_item(keymap->types, types[i]);
1776 if (type->num_levels < keyi->numLevels[i]) {
1777 log_lvl(info->keymap->ctx, 1,
1778 "Type \"%s\" has %d levels, but %s has %d symbols; "
1779 "Ignoring extra symbols\n",
1780 type->name, type->num_levels,
1781 longText(keyi->name),
1782 keyi->numLevels[i]);
1783 keyi->numLevels[i] = type->num_levels;
1785 if (keyi->numLevels[i] > width)
1786 width = keyi->numLevels[i];
1787 if (type->num_levels > width)
1788 width = type->num_levels;
1789 sizeSyms += darray_size(keyi->syms[i]);
1792 darray_resize0(key->syms, sizeSyms);
1795 outActs = ResizeKeyActions(keymap, key, width * nGroups);
1796 if (outActs == NULL) {
1797 log_wsgo(info->keymap->ctx,
1798 "Could not enlarge actions for %s (key %d)\n",
1799 longText(keyi->name), kc);
1802 key->explicit |= XkbExplicitInterpretMask;
1807 key->num_groups = nGroups;
1808 if (keyi->defined & _Key_GroupInfo) {
1809 key->out_of_range_group_number = keyi->out_of_range_group_number;
1810 key->out_of_range_group_action = keyi->out_of_range_group_action;
1813 key->sym_index = calloc(nGroups * width, sizeof(*key->sym_index));
1814 key->num_syms = calloc(nGroups * width, sizeof(*key->num_syms));
1816 for (i = 0; i < nGroups; i++) {
1817 /* assign kt_index[i] to the index of the type in map->types.
1818 * kt_index[i] may have been set by a previous run (if we have two
1819 * layouts specified). Let's not overwrite it with the ONE_LEVEL
1820 * default group if we dont even have keys for this group anyway.
1822 * FIXME: There should be a better fix for this.
1824 if (keyi->numLevels[i])
1825 key->kt_index[i] = types[i];
1826 if (!darray_empty(keyi->syms[i])) {
1827 /* fill key to "width" symbols*/
1828 for (tmp = 0; tmp < width; tmp++) {
1829 if (tmp < keyi->numLevels[i] &&
1830 darray_item(keyi->symsMapNumEntries[i], tmp) != 0) {
1831 memcpy(darray_mem(key->syms, symIndex),
1832 darray_mem(keyi->syms[i],
1833 darray_item(keyi->symsMapIndex[i], tmp)),
1834 darray_item(keyi->symsMapNumEntries[i],
1835 tmp) * sizeof(xkb_keysym_t));
1836 key->sym_index[(i * width) + tmp] = symIndex;
1837 key->num_syms[(i * width) + tmp] =
1838 darray_item(keyi->symsMapNumEntries[i], tmp);
1839 symIndex += key->num_syms[(i * width) + tmp];
1842 key->sym_index[(i * width) + tmp] = -1;
1843 key->num_syms[(i * width) + tmp] = 0;
1845 if (outActs != NULL && !darray_empty(keyi->acts[i])) {
1846 if (tmp < keyi->numLevels[i])
1847 outActs[tmp] = darray_item(keyi->acts[i], tmp);
1849 outActs[tmp].type = XkbSA_NoAction;
1854 switch (keyi->behavior.type & XkbKB_OpMask) {
1859 key->behavior = keyi->behavior;
1860 key->explicit |= XkbExplicitBehaviorMask;
1863 if (keyi->defined & _Key_VModMap) {
1864 key->vmodmap = keyi->vmodmap;
1865 key->explicit |= XkbExplicitVModMapMask;
1867 if (keyi->repeat != RepeatUndefined) {
1868 key->repeats = keyi->repeat == RepeatYes;
1869 key->explicit |= XkbExplicitAutoRepeatMask;
1872 /* do the same thing for the next key */
1873 CopySymbolsDef(info, keyi, kc + 1);
1878 CopyModMapDef(SymbolsInfo *info, ModMapEntry *entry)
1880 struct xkb_key *key;
1881 struct xkb_keymap *keymap = info->keymap;
1883 if (!entry->haveSymbol) {
1884 key = FindNamedKey(keymap, entry->u.keyName, true,
1885 CreateKeyNames(keymap), 0);
1887 log_lvl(info->keymap->ctx, 5,
1888 "Key %s not found in keycodes; "
1889 "Modifier map entry for %s not updated\n",
1890 longText(entry->u.keyName),
1891 XkbcModIndexText(entry->modifier));
1896 key = FindKeyForSymbol(keymap, entry->u.keySym);
1898 log_lvl(info->keymap->ctx, 5,
1899 "Key \"%s\" not found in symbol map; "
1900 "Modifier map entry for %s not updated\n",
1901 XkbcKeysymText(entry->u.keySym),
1902 XkbcModIndexText(entry->modifier));
1907 key->modmap |= (1 << entry->modifier);
1912 * Handle the xkb_symbols section of an xkb file.
1914 * @param file The parsed xkb_symbols section of the xkb file.
1915 * @param keymap Handle to the keyboard description to store the symbols in.
1916 * @param merge Merge strategy (e.g. MERGE_OVERRIDE).
1919 CompileSymbols(XkbFile *file, struct xkb_keymap *keymap,
1920 enum merge_mode merge)
1922 xkb_group_index_t i;
1923 struct xkb_key *key;
1928 InitSymbolsInfo(&info, keymap, file->id);
1929 info.dflt.merge = merge;
1931 HandleSymbolsFile(&info, file, merge);
1933 if (darray_empty(info.keys))
1936 if (info.errorCount != 0)
1939 darray_resize0(keymap->acts, darray_size(keymap->acts) + 32 + 1);
1942 keymap->symbols_section_name = strdup(info.name);
1944 for (i = 0; i < XkbNumKbdGroups; i++) {
1945 if (info.groupNames[i] != XKB_ATOM_NONE) {
1946 keymap->group_names[i] = xkb_atom_text(keymap->ctx,
1947 info.groupNames[i]);
1952 darray_foreach(keyi, info.keys)
1953 PrepareKeyDef(keyi);
1956 darray_foreach(keyi, info.keys)
1957 if (!CopySymbolsDef(&info, keyi, 0))
1960 if (xkb_get_log_verbosity(keymap->ctx) > 3) {
1961 xkb_foreach_key(key, keymap) {
1962 if (key->name[0] == '\0')
1965 if (key->num_groups < 1)
1966 log_warn(info.keymap->ctx,
1967 "No symbols defined for <%.4s> (keycode %d)\n",
1968 key->name, XkbKeyGetKeycode(keymap, key));
1972 list_foreach(mm, &info.modMaps, entry)
1973 if (!CopyModMapDef(&info, mm))
1976 FreeSymbolsInfo(&info);
1980 FreeSymbolsInfo(&info);