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"
35 /* Needed to work with the typechecker. */
36 typedef darray(xkb_keysym_t) darray_xkb_keysym_t;
37 typedef darray(union xkb_action) darray_xkb_action;
42 KEY_REPEAT_UNDEFINED = -1
46 KEY_FIELD_SYMS = (1 << 0),
47 KEY_FIELD_ACTS = (1 << 1),
48 KEY_FIELD_REPEAT = (1 << 2),
49 KEY_FIELD_TYPE_DFLT = (1 << 3),
50 KEY_FIELD_TYPES = (1 << 4),
51 KEY_FIELD_GROUPINFO = (1 << 5),
52 KEY_FIELD_VMODMAP = (1 << 6),
55 typedef struct _KeyInfo {
56 enum key_field defined;
58 enum merge_mode merge;
60 unsigned long name; /* the 4 chars of the key name, as long */
61 unsigned char typesDefined;
62 unsigned char symsDefined;
63 unsigned char actsDefined;
64 xkb_level_index_t numLevels[XKB_NUM_GROUPS];
66 /* syms[group] -> Single array for all the keysyms in the group. */
67 darray_xkb_keysym_t syms[XKB_NUM_GROUPS];
69 * symsMapIndex[group][level] -> The index from which the syms for
70 * the level begin in the syms[group] array. Remember each keycode
71 * can have multiple keysyms in each level (that is, each key press
72 * can result in multiple keysyms).
74 darray(int) symsMapIndex[XKB_NUM_GROUPS];
76 * symsMapNumEntries[group][level] -> How many syms are in
77 * syms[group][symsMapIndex[group][level]].
79 darray(size_t) symsMapNumEntries[XKB_NUM_GROUPS];
81 darray_xkb_action acts[XKB_NUM_GROUPS];
83 xkb_atom_t types[XKB_NUM_GROUPS];
84 enum key_repeat repeat;
85 xkb_mod_mask_t vmodmap;
88 enum xkb_range_exceed_type out_of_range_group_action;
89 xkb_group_index_t out_of_range_group_number;
93 * Init the given key info to sane values.
96 InitKeyInfo(KeyInfo *keyi, unsigned file_id)
99 static const char dflt[4] = "*";
102 keyi->file_id = file_id;
103 keyi->merge = MERGE_OVERRIDE;
104 keyi->name = KeyNameToLong(dflt);
105 keyi->typesDefined = keyi->symsDefined = keyi->actsDefined = 0;
107 for (i = 0; i < XKB_NUM_GROUPS; i++) {
108 keyi->numLevels[i] = 0;
109 keyi->types[i] = XKB_ATOM_NONE;
110 darray_init(keyi->syms[i]);
111 darray_init(keyi->symsMapIndex[i]);
112 darray_init(keyi->symsMapNumEntries[i]);
113 darray_init(keyi->acts[i]);
116 keyi->dfltType = XKB_ATOM_NONE;
118 keyi->repeat = KEY_REPEAT_UNDEFINED;
119 keyi->out_of_range_group_action = RANGE_WRAP;
120 keyi->out_of_range_group_number = 0;
124 ClearKeyInfo(KeyInfo *keyi)
128 for (i = 0; i < XKB_NUM_GROUPS; i++) {
129 darray_free(keyi->syms[i]);
130 darray_free(keyi->symsMapIndex[i]);
131 darray_free(keyi->symsMapNumEntries[i]);
132 darray_free(keyi->acts[i]);
137 * Copy old into new, optionally reset old to 0.
138 * If old is reset, new simply re-uses old's memory. Otherwise, the memory is
139 * newly allocated and new points to the new memory areas.
142 CopyKeyInfo(KeyInfo * old, KeyInfo * new, bool clearOld)
149 for (i = 0; i < XKB_NUM_GROUPS; i++) {
150 old->numLevels[i] = 0;
151 darray_init(old->symsMapIndex[i]);
152 darray_init(old->symsMapNumEntries[i]);
153 darray_init(old->syms[i]);
154 darray_init(old->acts[i]);
158 for (i = 0; i < XKB_NUM_GROUPS; i++) {
159 darray_copy(new->syms[i], old->syms[i]);
160 darray_copy(new->symsMapIndex[i], old->symsMapIndex[i]);
161 darray_copy(new->symsMapNumEntries[i], old->symsMapNumEntries[i]);
162 darray_copy(new->acts[i], old->acts[i]);
169 /***====================================================================***/
171 typedef struct _ModMapEntry {
173 enum merge_mode merge;
177 unsigned long keyName;
182 typedef struct _SymbolsInfo {
183 char *name; /* e.g. pc+us+inet(evdev) */
186 enum merge_mode merge;
187 xkb_group_index_t explicit_group;
188 darray(KeyInfo) keys;
191 ActionsInfo *actions;
192 xkb_atom_t groupNames[XKB_NUM_GROUPS];
196 struct xkb_keymap *keymap;
200 InitSymbolsInfo(SymbolsInfo *info, struct xkb_keymap *keymap,
201 unsigned file_id, ActionsInfo *actions)
206 info->explicit_group = 0;
207 info->errorCount = 0;
208 info->file_id = file_id;
209 info->merge = MERGE_OVERRIDE;
210 darray_init(info->keys);
211 darray_growalloc(info->keys, 110);
212 list_init(&info->modMaps);
213 for (i = 0; i < XKB_NUM_GROUPS; i++)
214 info->groupNames[i] = XKB_ATOM_NONE;
215 InitKeyInfo(&info->dflt, file_id);
216 InitVModInfo(&info->vmods, keymap);
217 info->actions = actions;
218 info->keymap = keymap;
222 ClearSymbolsInfo(SymbolsInfo * info)
225 ModMapEntry *mm, *next;
228 darray_foreach(keyi, info->keys)
230 darray_free(info->keys);
231 list_foreach_safe(mm, next, &info->modMaps, entry)
233 memset(info, 0, sizeof(SymbolsInfo));
237 ResizeKeyGroup(KeyInfo *keyi, xkb_group_index_t group,
238 xkb_level_index_t numLevels, unsigned sizeSyms,
243 if (darray_size(keyi->syms[group]) < sizeSyms)
244 darray_resize0(keyi->syms[group], sizeSyms);
246 if (darray_empty(keyi->symsMapIndex[group]) ||
247 keyi->numLevels[group] < numLevels) {
248 darray_resize(keyi->symsMapIndex[group], numLevels);
249 for (i = keyi->numLevels[group]; i < numLevels; i++)
250 darray_item(keyi->symsMapIndex[group], i) = -1;
253 if (darray_empty(keyi->symsMapNumEntries[group]) ||
254 keyi->numLevels[group] < numLevels)
255 darray_resize0(keyi->symsMapNumEntries[group], numLevels);
257 if ((forceActions && (keyi->numLevels[group] < numLevels ||
258 darray_empty(keyi->acts[group]))) ||
259 (keyi->numLevels[group] < numLevels && !darray_empty(keyi->acts[group])))
260 darray_resize0(keyi->acts[group], numLevels);
262 if (keyi->numLevels[group] < numLevels)
263 keyi->numLevels[group] = numLevels;
268 enum key_group_selector {
275 MergeKeyGroups(SymbolsInfo * info,
276 KeyInfo * into, KeyInfo * from, xkb_group_index_t group)
278 darray_xkb_keysym_t resultSyms;
279 enum key_group_selector using = NONE;
280 darray_xkb_action resultActs;
281 xkb_level_index_t resultWidth;
282 unsigned int resultSize = 0;
285 bool report, clobber;
286 int verbosity = xkb_get_log_verbosity(info->keymap->ctx);
288 clobber = (from->merge != MERGE_AUGMENT);
290 report = (verbosity > 9) ||
291 (into->file_id == from->file_id && verbosity > 0);
293 darray_init(resultSyms);
295 if (into->numLevels[group] >= from->numLevels[group]) {
296 resultActs = into->acts[group];
297 resultWidth = into->numLevels[group];
300 resultActs = from->acts[group];
301 resultWidth = from->numLevels[group];
302 darray_resize(into->symsMapIndex[group],
303 from->numLevels[group]);
304 darray_resize0(into->symsMapNumEntries[group],
305 from->numLevels[group]);
307 for (i = into->numLevels[group]; i < from->numLevels[group]; i++)
308 darray_item(into->symsMapIndex[group], i) = -1;
311 if (darray_empty(resultActs) && (!darray_empty(into->acts[group]) ||
312 !darray_empty(from->acts[group]))) {
313 darray_resize0(resultActs, resultWidth);
314 for (i = 0; i < resultWidth; i++) {
315 union xkb_action *fromAct = NULL, *toAct = NULL;
317 if (!darray_empty(from->acts[group]))
318 fromAct = &darray_item(from->acts[group], i);
320 if (!darray_empty(into->acts[group]))
321 toAct = &darray_item(into->acts[group], i);
323 if (((fromAct == NULL) || (fromAct->type == ACTION_TYPE_NONE))
324 && (toAct != NULL)) {
325 darray_item(resultActs, i) = *toAct;
327 else if (((toAct == NULL) || (toAct->type == ACTION_TYPE_NONE))
328 && (fromAct != NULL)) {
329 darray_item(resultActs, i) = *fromAct;
332 union xkb_action *use, *ignore;
342 log_warn(info->keymap->ctx,
343 "Multiple actions for level %d/group %u on key %s; "
344 "Using %s, ignoring %s\n",
345 i + 1, group + 1, LongKeyNameText(into->name),
346 ActionTypeText(use->type),
347 ActionTypeText(ignore->type));
349 darray_item(resultActs, i) = *use;
354 for (i = 0; i < resultWidth; i++) {
355 unsigned int fromSize = 0;
358 if (!darray_empty(from->symsMapNumEntries[group]) &&
359 i < from->numLevels[group])
360 fromSize = darray_item(from->symsMapNumEntries[group], i);
362 if (!darray_empty(into->symsMapNumEntries[group]) &&
363 i < into->numLevels[group])
364 toSize = darray_item(into->symsMapNumEntries[group], i);
367 resultSize += toSize;
370 else if (toSize == 0 || clobber) {
371 resultSize += fromSize;
375 resultSize += toSize;
384 resultSyms = from->syms[group];
385 darray_free(into->symsMapNumEntries[group]);
386 darray_free(into->symsMapIndex[group]);
387 into->symsMapNumEntries[group] = from->symsMapNumEntries[group];
388 into->symsMapIndex[group] = from->symsMapIndex[group];
389 darray_init(from->symsMapNumEntries[group]);
390 darray_init(from->symsMapIndex[group]);
393 else if (using == TO) {
394 resultSyms = into->syms[group];
398 darray_resize0(resultSyms, resultSize);
400 for (i = 0; i < resultWidth; i++) {
401 enum key_group_selector use = NONE;
402 unsigned int fromSize = 0;
403 unsigned int toSize = 0;
405 if (i < from->numLevels[group])
406 fromSize = darray_item(from->symsMapNumEntries[group], i);
408 if (i < into->numLevels[group])
409 toSize = darray_item(into->symsMapNumEntries[group], i);
411 if (fromSize == 0 && toSize == 0) {
412 darray_item(into->symsMapIndex[group], i) = -1;
413 darray_item(into->symsMapNumEntries[group], i) = 0;
419 else if (toSize == 0 || clobber)
424 if (toSize && fromSize && report) {
425 log_info(info->keymap->ctx,
426 "Multiple symbols for group %u, level %d on key %s; "
427 "Using %s, ignoring %s\n",
428 group + 1, i + 1, LongKeyNameText(into->name),
429 (use == FROM ? "from" : "to"),
430 (use == FROM ? "to" : "from"));
434 memcpy(darray_mem(resultSyms, cur_idx),
435 darray_mem(from->syms[group],
436 darray_item(from->symsMapIndex[group], i)),
437 darray_item(from->symsMapNumEntries[group],
438 i) * sizeof(xkb_keysym_t));
439 darray_item(into->symsMapIndex[group], i) = cur_idx;
440 darray_item(into->symsMapNumEntries[group], i) =
441 darray_item(from->symsMapNumEntries[group], i);
444 memcpy(darray_mem(resultSyms, cur_idx),
445 darray_mem(into->syms[group],
446 darray_item(into->symsMapIndex[group], i)),
447 darray_item(into->symsMapNumEntries[group],
448 i) * sizeof(xkb_keysym_t));
449 darray_item(into->symsMapIndex[group], i) = cur_idx;
451 cur_idx += darray_item(into->symsMapNumEntries[group], i);
455 if (!darray_same(resultActs, into->acts[group]))
456 darray_free(into->acts[group]);
457 if (!darray_same(resultActs, from->acts[group]))
458 darray_free(from->acts[group]);
459 into->numLevels[group] = resultWidth;
460 if (!darray_same(resultSyms, into->syms[group]))
461 darray_free(into->syms[group]);
462 into->syms[group] = resultSyms;
463 if (!darray_same(resultSyms, from->syms[group]))
464 darray_free(from->syms[group]);
465 darray_init(from->syms[group]);
466 darray_free(from->symsMapIndex[group]);
467 darray_free(from->symsMapNumEntries[group]);
468 into->acts[group] = resultActs;
469 darray_init(from->acts[group]);
470 if (!darray_empty(into->syms[group]))
471 into->symsDefined |= (1 << group);
472 from->symsDefined &= ~(1 << group);
473 into->actsDefined |= (1 << group);
474 from->actsDefined &= ~(1 << group);
480 UseNewKeyField(enum key_field field, KeyInfo *old, KeyInfo *new,
481 int verbosity, enum key_field *collide)
483 if (!(old->defined & field))
486 if (new->defined & field) {
487 if ((old->file_id == new->file_id && verbosity > 0) || verbosity > 9)
490 if (new->merge != MERGE_AUGMENT)
499 MergeKeys(SymbolsInfo *info, KeyInfo *into, KeyInfo *from)
502 enum key_field collide = 0;
504 int verbosity = xkb_get_log_verbosity(info->keymap->ctx);
506 if (from->merge == MERGE_REPLACE) {
507 for (i = 0; i < XKB_NUM_GROUPS; i++) {
508 if (into->numLevels[i] != 0) {
509 darray_free(into->syms[i]);
510 darray_free(into->acts[i]);
514 memset(from, 0, sizeof(KeyInfo));
518 report = (verbosity > 9 ||
519 (into->file_id == from->file_id && verbosity > 0));
521 for (i = 0; i < XKB_NUM_GROUPS; i++) {
522 if (from->numLevels[i] > 0) {
523 if (into->numLevels[i] == 0) {
524 into->numLevels[i] = from->numLevels[i];
525 into->syms[i] = from->syms[i];
526 into->symsMapIndex[i] = from->symsMapIndex[i];
527 into->symsMapNumEntries[i] = from->symsMapNumEntries[i];
528 into->acts[i] = from->acts[i];
529 into->symsDefined |= (1 << i);
530 darray_init(from->syms[i]);
531 darray_init(from->symsMapIndex[i]);
532 darray_init(from->symsMapNumEntries[i]);
533 darray_init(from->acts[i]);
534 from->numLevels[i] = 0;
535 from->symsDefined &= ~(1 << i);
536 if (!darray_empty(into->syms[i]))
537 into->defined |= KEY_FIELD_SYMS;
538 if (!darray_empty(into->acts[i]))
539 into->defined |= KEY_FIELD_ACTS;
543 if (!darray_empty(into->syms[i]))
544 collide |= KEY_FIELD_SYMS;
545 if (!darray_empty(into->acts[i]))
546 collide |= KEY_FIELD_ACTS;
548 MergeKeyGroups(info, into, from, (unsigned) i);
551 if (from->types[i] != XKB_ATOM_NONE) {
552 if ((into->types[i] != XKB_ATOM_NONE) && report &&
553 (into->types[i] != from->types[i])) {
554 xkb_atom_t use, ignore;
555 collide |= KEY_FIELD_TYPES;
556 if (from->merge != MERGE_AUGMENT) {
557 use = from->types[i];
558 ignore = into->types[i];
561 use = into->types[i];
562 ignore = from->types[i];
565 log_warn(info->keymap->ctx,
566 "Multiple definitions for group %d type of key %s; "
567 "Using %s, ignoring %s\n",
568 i, LongKeyNameText(into->name),
569 xkb_atom_text(info->keymap->ctx, use),
570 xkb_atom_text(info->keymap->ctx, ignore));
573 if (from->merge != MERGE_AUGMENT ||
574 into->types[i] == XKB_ATOM_NONE) {
575 into->types[i] = from->types[i];
580 if (UseNewKeyField(KEY_FIELD_VMODMAP, into, from, verbosity, &collide)) {
581 into->vmodmap = from->vmodmap;
582 into->defined |= KEY_FIELD_VMODMAP;
584 if (UseNewKeyField(KEY_FIELD_REPEAT, into, from, verbosity, &collide)) {
585 into->repeat = from->repeat;
586 into->defined |= KEY_FIELD_REPEAT;
588 if (UseNewKeyField(KEY_FIELD_TYPE_DFLT, into, from, verbosity, &collide)) {
589 into->dfltType = from->dfltType;
590 into->defined |= KEY_FIELD_TYPE_DFLT;
592 if (UseNewKeyField(KEY_FIELD_GROUPINFO, into, from, verbosity, &collide)) {
593 into->out_of_range_group_action = from->out_of_range_group_action;
594 into->out_of_range_group_number = from->out_of_range_group_number;
595 into->defined |= KEY_FIELD_GROUPINFO;
599 log_warn(info->keymap->ctx,
600 "Symbol map for key %s redefined; "
601 "Using %s definition for conflicting fields\n",
602 LongKeyNameText(into->name),
603 (from->merge == MERGE_AUGMENT ? "first" : "last"));
609 AddKeySymbols(SymbolsInfo *info, KeyInfo *keyi)
611 unsigned long real_name;
614 darray_foreach(iter, info->keys)
615 if (iter->name == keyi->name)
616 return MergeKeys(info, iter, keyi);
618 if (FindKeyNameForAlias(info->keymap, keyi->name, &real_name))
619 darray_foreach(iter, info->keys)
620 if (iter->name == real_name)
621 return MergeKeys(info, iter, keyi);
623 darray_resize0(info->keys, darray_size(info->keys) + 1);
624 new = &darray_item(info->keys, darray_size(info->keys) - 1);
625 return CopyKeyInfo(keyi, new, true);
629 AddModMapEntry(SymbolsInfo * info, ModMapEntry * new)
634 clobber = (new->merge != MERGE_AUGMENT);
635 list_foreach(mm, &info->modMaps, entry) {
636 if (new->haveSymbol && mm->haveSymbol
637 && (new->u.keySym == mm->u.keySym)) {
638 unsigned use, ignore;
639 if (mm->modifier != new->modifier) {
642 ignore = mm->modifier;
646 ignore = new->modifier;
648 log_err(info->keymap->ctx,
649 "%s added to symbol map for multiple modifiers; "
650 "Using %s, ignoring %s.\n",
651 KeysymText(new->u.keySym), ModIndexText(use),
652 ModIndexText(ignore));
657 if ((!new->haveSymbol) && (!mm->haveSymbol) &&
658 (new->u.keyName == mm->u.keyName)) {
659 unsigned use, ignore;
660 if (mm->modifier != new->modifier) {
663 ignore = mm->modifier;
667 ignore = new->modifier;
669 log_err(info->keymap->ctx,
670 "Key %s added to map for multiple modifiers; "
671 "Using %s, ignoring %s.\n",
672 LongKeyNameText(new->u.keyName), ModIndexText(use),
673 ModIndexText(ignore));
680 mm = malloc(sizeof(*mm));
682 log_wsgo(info->keymap->ctx,
683 "Could not allocate modifier map entry; "
684 "Modifier map for %s will be incomplete\n",
685 ModIndexText(new->modifier));
690 list_add(&mm->entry, &info->modMaps);
694 /***====================================================================***/
697 MergeIncludedSymbols(SymbolsInfo *into, SymbolsInfo *from,
698 enum merge_mode merge)
702 ModMapEntry *mm, *next;
704 if (from->errorCount > 0) {
705 into->errorCount += from->errorCount;
708 if (into->name == NULL) {
709 into->name = from->name;
712 for (i = 0; i < XKB_NUM_GROUPS; i++) {
713 if (from->groupNames[i] != XKB_ATOM_NONE) {
714 if ((merge != MERGE_AUGMENT) ||
715 (into->groupNames[i] == XKB_ATOM_NONE))
716 into->groupNames[i] = from->groupNames[i];
720 darray_foreach(keyi, from->keys) {
721 if (merge != MERGE_DEFAULT)
724 if (!AddKeySymbols(into, keyi))
728 list_foreach_safe(mm, next, &from->modMaps, entry) {
729 if (merge != MERGE_DEFAULT)
731 if (!AddModMapEntry(into, mm))
735 list_init(&from->modMaps);
739 HandleSymbolsFile(SymbolsInfo *info, XkbFile *file, enum merge_mode merge);
742 HandleIncludeSymbols(SymbolsInfo *info, IncludeStmt *stmt)
744 enum merge_mode merge = MERGE_DEFAULT;
746 SymbolsInfo included, next_incl;
748 InitSymbolsInfo(&included, info->keymap, info->file_id, info->actions);
751 included.name = stmt->stmt;
755 for (; stmt; stmt = stmt->next_incl) {
756 if (!ProcessIncludeFile(info->keymap->ctx, stmt, FILE_TYPE_SYMBOLS,
758 info->errorCount += 10;
759 ClearSymbolsInfo(&included);
763 InitSymbolsInfo(&next_incl, info->keymap, rtrn->id, info->actions);
764 next_incl.merge = next_incl.dflt.merge = MERGE_OVERRIDE;
766 next_incl.explicit_group = atoi(stmt->modifier) - 1;
768 next_incl.explicit_group = info->explicit_group;
770 HandleSymbolsFile(&next_incl, rtrn, MERGE_OVERRIDE);
772 MergeIncludedSymbols(&included, &next_incl, merge);
774 ClearSymbolsInfo(&next_incl);
778 MergeIncludedSymbols(info, &included, merge);
779 ClearSymbolsInfo(&included);
781 return (info->errorCount == 0);
788 GetGroupIndex(SymbolsInfo *info, KeyInfo *keyi, ExprDef *arrayNdx,
789 unsigned what, xkb_group_index_t *ndx_rtrn)
798 if (arrayNdx == NULL) {
802 defined = keyi->symsDefined;
804 defined = keyi->actsDefined;
806 for (i = 0; i < XKB_NUM_GROUPS; i++) {
807 if ((defined & (1 << i)) == 0) {
813 log_err(info->keymap->ctx,
814 "Too many groups of %s for key %s (max %u); "
815 "Ignoring %s defined for extra groups\n",
816 name, LongKeyNameText(keyi->name), XKB_NUM_GROUPS + 1, name);
820 if (!ExprResolveGroup(info->keymap->ctx, arrayNdx, ndx_rtrn)) {
821 log_err(info->keymap->ctx,
822 "Illegal group index for %s of key %s\n"
823 "Definition with non-integer array index ignored\n",
824 name, LongKeyNameText(keyi->name));
833 LookupKeysym(const char *str, xkb_keysym_t *sym_rtrn)
837 if (!str || istreq(str, "any") || istreq(str, "nosymbol")) {
838 *sym_rtrn = XKB_KEY_NoSymbol;
842 if (istreq(str, "none") || istreq(str, "voidsymbol")) {
843 *sym_rtrn = XKB_KEY_VoidSymbol;
847 sym = xkb_keysym_from_name(str);
848 if (sym != XKB_KEY_NoSymbol) {
857 AddSymbolsToKey(SymbolsInfo *info, KeyInfo *keyi, ExprDef *arrayNdx,
860 xkb_group_index_t ndx;
862 xkb_level_index_t nLevels;
866 if (!GetGroupIndex(info, keyi, arrayNdx, SYMBOLS, &ndx))
869 keyi->symsDefined |= (1 << ndx);
872 if (value->op != EXPR_KEYSYM_LIST) {
873 log_err(info->keymap->ctx,
874 "Expected a list of symbols, found %s; "
875 "Ignoring symbols for group %u of %s\n",
876 expr_op_type_to_string(value->op), ndx + 1,
877 LongKeyNameText(keyi->name));
880 if (!darray_empty(keyi->syms[ndx])) {
881 log_err(info->keymap->ctx,
882 "Symbols for key %s, group %u already defined; "
883 "Ignoring duplicate definition\n",
884 LongKeyNameText(keyi->name), ndx + 1);
887 nSyms = darray_size(value->value.list.syms);
888 nLevels = darray_size(value->value.list.symsMapIndex);
889 if ((keyi->numLevels[ndx] < nSyms || darray_empty(keyi->syms[ndx])) &&
890 (!ResizeKeyGroup(keyi, ndx, nLevels, nSyms, false))) {
891 log_wsgo(info->keymap->ctx,
892 "Could not resize group %u of key %s to contain %zu levels; "
894 ndx + 1, LongKeyNameText(keyi->name), nSyms);
897 keyi->symsDefined |= (1 << ndx);
898 for (i = 0; i < nLevels; i++) {
899 darray_item(keyi->symsMapIndex[ndx], i) =
900 darray_item(value->value.list.symsMapIndex, i);
901 darray_item(keyi->symsMapNumEntries[ndx], i) =
902 darray_item(value->value.list.symsNumEntries, i);
904 for (j = 0; j < darray_item(keyi->symsMapNumEntries[ndx], i); j++) {
905 /* FIXME: What's abort() doing here? */
906 if (darray_item(keyi->symsMapIndex[ndx], i) + j >= nSyms)
908 if (!LookupKeysym(darray_item(value->value.list.syms,
909 darray_item(value->value.list.symsMapIndex,
911 &darray_item(keyi->syms[ndx],
912 darray_item(keyi->symsMapIndex[ndx],
914 log_warn(info->keymap->ctx,
915 "Could not resolve keysym %s for key %s, group %u (%s), level %zu\n",
916 darray_item(value->value.list.syms, i),
917 LongKeyNameText(keyi->name),
919 xkb_atom_text(info->keymap->ctx,
920 info->groupNames[ndx]),
923 darray_item(keyi->syms[ndx],
924 darray_item(keyi->symsMapIndex[ndx],
925 i) + j) = XKB_KEY_NoSymbol;
926 darray_item(keyi->symsMapIndex[ndx], i) = -1;
927 darray_item(keyi->symsMapNumEntries[ndx], i) = 0;
930 if (darray_item(keyi->symsMapNumEntries[ndx], i) == 1 &&
931 darray_item(keyi->syms[ndx],
932 darray_item(keyi->symsMapIndex[ndx],
933 i) + j) == XKB_KEY_NoSymbol) {
934 darray_item(keyi->symsMapIndex[ndx], i) = -1;
935 darray_item(keyi->symsMapNumEntries[ndx], i) = 0;
939 for (j = keyi->numLevels[ndx] - 1;
940 j >= 0 && darray_item(keyi->symsMapNumEntries[ndx], j) == 0; j--)
941 keyi->numLevels[ndx]--;
946 AddActionsToKey(SymbolsInfo *info, KeyInfo *keyi, ExprDef *arrayNdx,
950 xkb_group_index_t ndx;
953 union xkb_action *toAct;
955 if (!GetGroupIndex(info, keyi, arrayNdx, ACTIONS, &ndx))
959 keyi->actsDefined |= (1 << ndx);
963 if (value->op != EXPR_ACTION_LIST) {
964 log_wsgo(info->keymap->ctx,
965 "Bad expression type (%d) for action list value; "
966 "Ignoring actions for group %u of %s\n",
967 value->op, ndx, LongKeyNameText(keyi->name));
971 if (!darray_empty(keyi->acts[ndx])) {
972 log_wsgo(info->keymap->ctx,
973 "Actions for key %s, group %u already defined\n",
974 LongKeyNameText(keyi->name), ndx);
978 for (nActs = 0, act = value->value.child; act != NULL; nActs++) {
979 act = (ExprDef *) act->common.next;
983 log_wsgo(info->keymap->ctx,
984 "Action list but not actions in AddActionsToKey\n");
988 if ((keyi->numLevels[ndx] < nActs || darray_empty(keyi->acts[ndx])) &&
989 !ResizeKeyGroup(keyi, ndx, nActs, nActs, true)) {
990 log_wsgo(info->keymap->ctx,
991 "Could not resize group %u of key %s; "
993 ndx, LongKeyNameText(keyi->name));
996 keyi->actsDefined |= (1 << ndx);
998 toAct = darray_mem(keyi->acts[ndx], 0);
999 act = value->value.child;
1000 for (i = 0; i < nActs; i++, toAct++) {
1001 if (!HandleActionDef(act, info->keymap, toAct, info->actions)) {
1002 log_err(info->keymap->ctx,
1003 "Illegal action definition for %s; "
1004 "Action for group %u/level %zu ignored\n",
1005 LongKeyNameText(keyi->name), ndx + 1, i + 1);
1007 act = (ExprDef *) act->common.next;
1013 static const LookupEntry repeatEntries[] = {
1014 { "true", KEY_REPEAT_YES },
1015 { "yes", KEY_REPEAT_YES },
1016 { "on", KEY_REPEAT_YES },
1017 { "false", KEY_REPEAT_NO },
1018 { "no", KEY_REPEAT_NO },
1019 { "off", KEY_REPEAT_NO },
1020 { "default", KEY_REPEAT_UNDEFINED },
1025 SetSymbolsField(SymbolsInfo *info, KeyInfo *keyi, const char *field,
1026 ExprDef *arrayNdx, ExprDef *value)
1029 struct xkb_context *ctx = info->keymap->ctx;
1031 if (istreq(field, "type")) {
1032 xkb_group_index_t ndx;
1035 if (!ExprResolveString(ctx, value, &val))
1037 "The type field of a key symbol map must be a string; "
1038 "Ignoring illegal type definition\n");
1040 if (arrayNdx == NULL) {
1041 keyi->dfltType = val;
1042 keyi->defined |= KEY_FIELD_TYPE_DFLT;
1044 else if (!ExprResolveGroup(ctx, arrayNdx, &ndx)) {
1046 "Illegal group index for type of key %s; "
1047 "Definition with non-integer array index ignored\n",
1048 LongKeyNameText(keyi->name));
1053 keyi->types[ndx] = val;
1054 keyi->typesDefined |= (1 << ndx);
1057 else if (istreq(field, "symbols"))
1058 return AddSymbolsToKey(info, keyi, arrayNdx, value);
1059 else if (istreq(field, "actions"))
1060 return AddActionsToKey(info, keyi, arrayNdx, value);
1061 else if (istreq(field, "vmods") ||
1062 istreq(field, "virtualmods") ||
1063 istreq(field, "virtualmodifiers")) {
1064 xkb_mod_mask_t mask;
1066 ok = ExprResolveVModMask(info->keymap, value, &mask);
1068 keyi->vmodmap = (mask >> XKB_NUM_CORE_MODS) & 0xffff;
1069 keyi->defined |= KEY_FIELD_VMODMAP;
1072 log_err(info->keymap->ctx,
1073 "Expected a virtual modifier mask, found %s; "
1074 "Ignoring virtual modifiers definition for key %s\n",
1075 expr_op_type_to_string(value->op),
1076 LongKeyNameText(keyi->name));
1079 else if (istreq(field, "locking") ||
1080 istreq(field, "lock") ||
1081 istreq(field, "locks")) {
1082 log_err(info->keymap->ctx,
1083 "Key behaviors not supported; "
1084 "Ignoring locking specification for key %s\n",
1085 LongKeyNameText(keyi->name));
1087 else if (istreq(field, "radiogroup") ||
1088 istreq(field, "permanentradiogroup") ||
1089 istreq(field, "allownone")) {
1090 log_err(info->keymap->ctx,
1091 "Radio groups not supported; "
1092 "Ignoring radio group specification for key %s\n",
1093 LongKeyNameText(keyi->name));
1095 else if (istreq_prefix("overlay", field) ||
1096 istreq_prefix("permanentoverlay", field)) {
1097 log_err(info->keymap->ctx,
1098 "Overlays not supported; "
1099 "Ignoring overlay specification for key %s\n",
1100 LongKeyNameText(keyi->name));
1102 else if (istreq(field, "repeating") ||
1103 istreq(field, "repeats") ||
1104 istreq(field, "repeat")) {
1107 ok = ExprResolveEnum(ctx, value, &val, repeatEntries);
1109 log_err(info->keymap->ctx,
1110 "Illegal repeat setting for %s; "
1111 "Non-boolean repeat setting ignored\n",
1112 LongKeyNameText(keyi->name));
1116 keyi->defined |= KEY_FIELD_REPEAT;
1118 else if (istreq(field, "groupswrap") ||
1119 istreq(field, "wrapgroups")) {
1122 if (!ExprResolveBoolean(ctx, value, &set)) {
1123 log_err(info->keymap->ctx,
1124 "Illegal groupsWrap setting for %s; "
1125 "Non-boolean value ignored\n",
1126 LongKeyNameText(keyi->name));
1131 keyi->out_of_range_group_action = RANGE_WRAP;
1133 keyi->out_of_range_group_action = RANGE_SATURATE;
1135 keyi->defined |= KEY_FIELD_GROUPINFO;
1137 else if (istreq(field, "groupsclamp") ||
1138 istreq(field, "clampgroups")) {
1141 if (!ExprResolveBoolean(ctx, value, &set)) {
1142 log_err(info->keymap->ctx,
1143 "Illegal groupsClamp setting for %s; "
1144 "Non-boolean value ignored\n",
1145 LongKeyNameText(keyi->name));
1150 keyi->out_of_range_group_action = RANGE_SATURATE;
1152 keyi->out_of_range_group_action = RANGE_WRAP;
1154 keyi->defined |= KEY_FIELD_GROUPINFO;
1156 else if (istreq(field, "groupsredirect") ||
1157 istreq(field, "redirectgroups")) {
1158 xkb_group_index_t grp;
1160 if (!ExprResolveGroup(ctx, value, &grp)) {
1161 log_err(info->keymap->ctx,
1162 "Illegal group index for redirect of key %s; "
1163 "Definition with non-integer group ignored\n",
1164 LongKeyNameText(keyi->name));
1168 keyi->out_of_range_group_action = RANGE_REDIRECT;
1169 keyi->out_of_range_group_number = grp - 1;
1170 keyi->defined |= KEY_FIELD_GROUPINFO;
1173 log_err(info->keymap->ctx,
1174 "Unknown field %s in a symbol interpretation; "
1175 "Definition ignored\n",
1184 SetGroupName(SymbolsInfo *info, ExprDef *arrayNdx, ExprDef *value)
1186 xkb_group_index_t grp;
1190 log_vrb(info->keymap->ctx, 1,
1191 "You must specify an index when specifying a group name; "
1192 "Group name definition without array subscript ignored\n");
1196 if (!ExprResolveGroup(info->keymap->ctx, arrayNdx, &grp)) {
1197 log_err(info->keymap->ctx,
1198 "Illegal index in group name definition; "
1199 "Definition with non-integer array index ignored\n");
1203 if (!ExprResolveString(info->keymap->ctx, value, &name)) {
1204 log_err(info->keymap->ctx,
1205 "Group name must be a string; "
1206 "Illegal name for group %d ignored\n", grp);
1210 info->groupNames[grp - 1 + info->explicit_group] = name;
1215 HandleSymbolsVar(SymbolsInfo *info, VarDef *stmt)
1217 const char *elem, *field;
1221 if (ExprResolveLhs(info->keymap->ctx, stmt->name, &elem, &field,
1223 return 0; /* internal error, already reported */
1224 if (elem && istreq(elem, "key")) {
1225 ret = SetSymbolsField(info, &info->dflt, field, arrayNdx,
1228 else if (!elem && (istreq(field, "name") ||
1229 istreq(field, "groupname"))) {
1230 ret = SetGroupName(info, arrayNdx, stmt->value);
1232 else if (!elem && (istreq(field, "groupswrap") ||
1233 istreq(field, "wrapgroups"))) {
1234 log_err(info->keymap->ctx,
1235 "Global \"groupswrap\" not supported; Ignored\n");
1238 else if (!elem && (istreq(field, "groupsclamp") ||
1239 istreq(field, "clampgroups"))) {
1240 log_err(info->keymap->ctx,
1241 "Global \"groupsclamp\" not supported; Ignored\n");
1244 else if (!elem && (istreq(field, "groupsredirect") ||
1245 istreq(field, "redirectgroups"))) {
1246 log_err(info->keymap->ctx,
1247 "Global \"groupsredirect\" not supported; Ignored\n");
1250 else if (!elem && istreq(field, "allownone")) {
1251 log_err(info->keymap->ctx,
1252 "Radio groups not supported; "
1253 "Ignoring \"allownone\" specification\n");
1257 ret = SetActionField(info->keymap, elem, field, arrayNdx, stmt->value,
1265 HandleSymbolsBody(SymbolsInfo *info, VarDef *def, KeyInfo *keyi)
1268 const char *elem, *field;
1271 for (; def; def = (VarDef *) def->common.next) {
1272 if (def->name && def->name->op == EXPR_FIELD_REF) {
1273 ok = HandleSymbolsVar(info, def);
1278 if (!def->value || def->value->op == EXPR_KEYSYM_LIST)
1285 ok = ExprResolveLhs(info->keymap->ctx, def->name, &elem, &field,
1290 ok = SetSymbolsField(info, keyi, field, arrayNdx, def->value);
1297 SetExplicitGroup(SymbolsInfo *info, KeyInfo *keyi)
1299 xkb_group_index_t group = info->explicit_group;
1304 if ((keyi->typesDefined | keyi->symsDefined | keyi->actsDefined) & ~1) {
1305 xkb_group_index_t i;
1306 log_warn(info->keymap->ctx,
1307 "For the map %s an explicit group specified, "
1308 "but key %s has more than one group defined; "
1309 "All groups except first one will be ignored\n",
1310 info->name, LongKeyNameText(keyi->name));
1311 for (i = 1; i < XKB_NUM_GROUPS; i++) {
1312 keyi->numLevels[i] = 0;
1313 darray_free(keyi->syms[i]);
1314 darray_free(keyi->acts[i]);
1318 keyi->typesDefined = keyi->symsDefined = keyi->actsDefined = 1 << group;
1320 keyi->numLevels[group] = keyi->numLevels[0];
1321 keyi->numLevels[0] = 0;
1322 keyi->syms[group] = keyi->syms[0];
1323 darray_init(keyi->syms[0]);
1324 keyi->symsMapIndex[group] = keyi->symsMapIndex[0];
1325 darray_init(keyi->symsMapIndex[0]);
1326 keyi->symsMapNumEntries[group] = keyi->symsMapNumEntries[0];
1327 darray_init(keyi->symsMapNumEntries[0]);
1328 keyi->acts[group] = keyi->acts[0];
1329 darray_init(keyi->acts[0]);
1330 keyi->types[group] = keyi->types[0];
1336 HandleSymbolsDef(SymbolsInfo *info, SymbolsDef *stmt)
1340 InitKeyInfo(&keyi, info->file_id);
1341 CopyKeyInfo(&info->dflt, &keyi, false);
1342 keyi.merge = stmt->merge;
1343 keyi.name = KeyNameToLong(stmt->keyName);
1344 if (!HandleSymbolsBody(info, (VarDef *) stmt->symbols, &keyi)) {
1349 if (!SetExplicitGroup(info, &keyi)) {
1354 if (!AddKeySymbols(info, &keyi)) {
1362 HandleModMapDef(SymbolsInfo *info, ModMapDef *def)
1366 xkb_mod_index_t ndx;
1368 struct xkb_context *ctx = info->keymap->ctx;
1370 if (!LookupModIndex(ctx, NULL, def->modifier, EXPR_TYPE_INT, &ndx)) {
1371 log_err(info->keymap->ctx,
1372 "Illegal modifier map definition; "
1373 "Ignoring map for non-modifier \"%s\"\n",
1374 xkb_atom_text(ctx, def->modifier));
1381 for (key = def->keys; key != NULL; key = (ExprDef *) key->common.next) {
1384 if (key->op == EXPR_VALUE && key->value_type == EXPR_TYPE_KEYNAME) {
1385 tmp.haveSymbol = false;
1386 tmp.u.keyName = KeyNameToLong(key->value.keyName);
1388 else if (ExprResolveKeySym(ctx, key, &sym)) {
1389 tmp.haveSymbol = true;
1393 log_err(info->keymap->ctx,
1394 "Modmap entries may contain only key names or keysyms; "
1395 "Illegal definition for %s modifier ignored\n",
1396 ModIndexText(tmp.modifier));
1400 ok = AddModMapEntry(info, &tmp) && ok;
1406 HandleSymbolsFile(SymbolsInfo *info, XkbFile *file, enum merge_mode merge)
1412 info->name = strdup_safe(file->name);
1415 for (stmt = file->defs; stmt; stmt = stmt->next) {
1416 switch (stmt->type) {
1418 ok = HandleIncludeSymbols(info, (IncludeStmt *) stmt);
1421 ok = HandleSymbolsDef(info, (SymbolsDef *) stmt);
1424 ok = HandleSymbolsVar(info, (VarDef *) stmt);
1427 ok = HandleVModDef((VModDef *) stmt, info->keymap, merge,
1431 ok = HandleModMapDef(info, (ModMapDef *) stmt);
1434 log_err(info->keymap->ctx,
1435 "Interpretation files may not include other types; "
1436 "Ignoring %s\n", stmt_type_to_string(stmt->type));
1444 if (info->errorCount > 10) {
1445 log_err(info->keymap->ctx, "Abandoning symbols file \"%s\"\n",
1453 * Given a keysym @sym, return a key which generates it, or NULL.
1454 * This is used for example in a modifier map definition, such as:
1455 * modifier_map Lock { Caps_Lock };
1456 * where we want to add the Lock modifier to the modmap of the key
1457 * which matches the keysym Caps_Lock.
1458 * Since there can be many keys which generates the keysym, the key
1459 * is chosen first by lowest group in which the keysym appears, than
1460 * by lowest level and than by lowest key code.
1462 static struct xkb_key *
1463 FindKeyForSymbol(struct xkb_keymap *keymap, xkb_keysym_t sym)
1465 struct xkb_key *key, *ret = NULL;
1466 xkb_group_index_t group, min_group = UINT32_MAX;
1467 xkb_level_index_t level, min_level = UINT16_MAX;
1469 xkb_foreach_key(key, keymap) {
1470 for (group = 0; group < key->num_groups; group++) {
1471 for (level = 0; level < XkbKeyGroupWidth(keymap, key, group);
1473 if (XkbKeyNumSyms(key, group, level) != 1 ||
1474 (XkbKeySymEntry(key, group, level))[0] != sym)
1478 * If the keysym was found in a group or level > 0, we must
1479 * keep looking since we might find a key in which the keysym
1480 * is in a lower group or level.
1482 if (group < min_group ||
1483 (group == min_group && level < min_level)) {
1485 if (group == 0 && level == 0) {
1501 * Find the given name in the keymap->map->types and return its index.
1503 * @param name The name to search for.
1504 * @param type_rtrn Set to the index of the name if found.
1506 * @return true if found, false otherwise.
1509 FindNamedType(struct xkb_keymap *keymap, xkb_atom_t name, unsigned *type_rtrn)
1513 for (i = 0; i < keymap->num_types; i++) {
1514 if (keymap->types[i].name == name) {
1524 * Assign a type to the given sym and return the Atom for the type assigned.
1527 * - ONE_LEVEL for width 0/1
1528 * - ALPHABETIC for 2 shift levels, with lower/upercase
1529 * - KEYPAD for keypad keys.
1530 * - TWO_LEVEL for other 2 shift level keys.
1531 * and the same for four level keys.
1533 * @param width Number of sysms in syms.
1534 * @param syms The keysyms for the given key (must be size width).
1535 * @param typeNameRtrn Set to the Atom of the type name.
1537 * @returns true if a type could be found, false otherwise.
1539 * FIXME: I need to take the KeyInfo so I can look at symsMapIndex and
1540 * all that fun stuff rather than just assuming there's always one
1544 FindAutomaticType(struct xkb_keymap *keymap, xkb_level_index_t width,
1545 const xkb_keysym_t *syms, xkb_atom_t *typeNameRtrn,
1549 if ((width == 1) || (width == 0)) {
1550 *typeNameRtrn = xkb_atom_intern(keymap->ctx, "ONE_LEVEL");
1553 else if (width == 2) {
1554 if (syms && xkb_keysym_is_lower(syms[0]) &&
1555 xkb_keysym_is_upper(syms[1])) {
1556 *typeNameRtrn = xkb_atom_intern(keymap->ctx, "ALPHABETIC");
1558 else if (syms && (xkb_keysym_is_keypad(syms[0]) ||
1559 xkb_keysym_is_keypad(syms[1]))) {
1560 *typeNameRtrn = xkb_atom_intern(keymap->ctx, "KEYPAD");
1564 *typeNameRtrn = xkb_atom_intern(keymap->ctx, "TWO_LEVEL");
1568 else if (width <= 4) {
1569 if (syms && xkb_keysym_is_lower(syms[0]) &&
1570 xkb_keysym_is_upper(syms[1]))
1571 if (xkb_keysym_is_lower(syms[2]) && xkb_keysym_is_upper(syms[3]))
1573 xkb_atom_intern(keymap->ctx, "FOUR_LEVEL_ALPHABETIC");
1575 *typeNameRtrn = xkb_atom_intern(keymap->ctx,
1576 "FOUR_LEVEL_SEMIALPHABETIC");
1578 else if (syms && (xkb_keysym_is_keypad(syms[0]) ||
1579 xkb_keysym_is_keypad(syms[1])))
1580 *typeNameRtrn = xkb_atom_intern(keymap->ctx, "FOUR_LEVEL_KEYPAD");
1582 *typeNameRtrn = xkb_atom_intern(keymap->ctx, "FOUR_LEVEL");
1583 /* XXX: why not set autoType here? */
1589 * Ensure the given KeyInfo is in a coherent state, i.e. no gaps between the
1590 * groups, and reduce to one group if all groups are identical anyway.
1593 PrepareKeyDef(KeyInfo *keyi)
1595 xkb_group_index_t i, lastGroup;
1596 unsigned int defined;
1597 xkb_level_index_t j, width;
1600 defined = keyi->symsDefined | keyi->actsDefined | keyi->typesDefined;
1601 /* get highest group number */
1602 for (i = XKB_NUM_GROUPS - 1; i > 0; i--) {
1603 if (defined & (1 << i))
1611 /* If there are empty groups between non-empty ones fill them with data */
1612 /* from the first group. */
1613 /* We can make a wrong assumption here. But leaving gaps is worse. */
1614 for (i = lastGroup; i > 0; i--) {
1615 if (defined & (1 << i))
1617 width = keyi->numLevels[0];
1618 if (keyi->typesDefined & 1) {
1619 for (j = 0; j < width; j++) {
1620 keyi->types[i] = keyi->types[0];
1622 keyi->typesDefined |= 1 << i;
1624 if ((keyi->actsDefined & 1) && !darray_empty(keyi->acts[0])) {
1625 darray_copy(keyi->acts[i], keyi->acts[0]);
1626 keyi->actsDefined |= 1 << i;
1628 if ((keyi->symsDefined & 1) && !darray_empty(keyi->syms[0])) {
1629 darray_copy(keyi->syms[i], keyi->syms[0]);
1630 darray_copy(keyi->symsMapIndex[i], keyi->symsMapIndex[0]);
1631 darray_copy(keyi->symsMapNumEntries[i],
1632 keyi->symsMapNumEntries[0]);
1633 keyi->symsDefined |= 1 << i;
1636 keyi->numLevels[i] = keyi->numLevels[0];
1639 /* If all groups are completely identical remove them all */
1640 /* exept the first one. */
1642 for (i = lastGroup; i > 0; i--) {
1643 if ((keyi->numLevels[i] != keyi->numLevels[0]) ||
1644 (keyi->types[i] != keyi->types[0])) {
1648 if (!darray_same(keyi->syms[i], keyi->syms[0]) &&
1649 (darray_empty(keyi->syms[i]) || darray_empty(keyi->syms[0]) ||
1650 darray_size(keyi->syms[i]) != darray_size(keyi->syms[0]) ||
1651 memcmp(darray_mem(keyi->syms[i], 0),
1652 darray_mem(keyi->syms[0], 0),
1653 sizeof(xkb_keysym_t) * darray_size(keyi->syms[0])))) {
1657 if (!darray_same(keyi->symsMapIndex[i], keyi->symsMapIndex[0]) &&
1658 (darray_empty(keyi->symsMapIndex[i]) ||
1659 darray_empty(keyi->symsMapIndex[0]) ||
1660 memcmp(darray_mem(keyi->symsMapIndex[i], 0),
1661 darray_mem(keyi->symsMapIndex[0], 0),
1662 keyi->numLevels[0] * sizeof(int)))) {
1666 if (!darray_same(keyi->symsMapNumEntries[i],
1667 keyi->symsMapNumEntries[0]) &&
1668 (darray_empty(keyi->symsMapNumEntries[i]) ||
1669 darray_empty(keyi->symsMapNumEntries[0]) ||
1670 memcmp(darray_mem(keyi->symsMapNumEntries[i], 0),
1671 darray_mem(keyi->symsMapNumEntries[0], 0),
1672 keyi->numLevels[0] * sizeof(size_t)))) {
1676 if (!darray_same(keyi->acts[i], keyi->acts[0]) &&
1677 (darray_empty(keyi->acts[i]) || darray_empty(keyi->acts[0]) ||
1678 memcmp(darray_mem(keyi->acts[i], 0),
1679 darray_mem(keyi->acts[0], 0),
1680 keyi->numLevels[0] * sizeof(union xkb_action)))) {
1686 for (i = lastGroup; i > 0; i--) {
1687 keyi->numLevels[i] = 0;
1688 darray_free(keyi->syms[i]);
1689 darray_free(keyi->symsMapIndex[i]);
1690 darray_free(keyi->symsMapNumEntries[i]);
1691 darray_free(keyi->acts[i]);
1694 keyi->symsDefined &= 1;
1695 keyi->actsDefined &= 1;
1696 keyi->typesDefined &= 1;
1701 * Copy the KeyInfo into the keyboard description.
1703 * This function recurses.
1706 CopySymbolsDef(SymbolsInfo *info, KeyInfo *keyi,
1707 xkb_keycode_t start_from)
1709 struct xkb_keymap *keymap = info->keymap;
1711 struct xkb_key *key;
1712 size_t sizeSyms = 0;
1713 xkb_group_index_t i, nGroups;
1714 xkb_level_index_t width, tmp;
1715 struct xkb_key_type * type;
1716 bool haveActions, autoType, useAlias;
1717 unsigned types[XKB_NUM_GROUPS];
1718 unsigned int symIndex = 0;
1720 useAlias = (start_from == 0);
1722 key = FindNamedKey(keymap, keyi->name, useAlias, start_from);
1724 if (start_from == 0)
1725 log_vrb(info->keymap->ctx, 5,
1726 "Key %s not found in keycodes; Symbols ignored\n",
1727 LongKeyNameText(keyi->name));
1730 kc = XkbKeyGetKeycode(keymap, key);
1732 haveActions = false;
1734 for (i = nGroups = 0; i < XKB_NUM_GROUPS; i++) {
1735 if (((i + 1) > nGroups)
1736 && (((keyi->symsDefined | keyi->actsDefined) & (1 << i))
1737 || (keyi->typesDefined) & (1 << i)))
1739 if (!darray_empty(keyi->acts[i]))
1742 /* Assign the type to the key, if it is missing. */
1743 if (keyi->types[i] == XKB_ATOM_NONE) {
1744 if (keyi->dfltType != XKB_ATOM_NONE)
1745 keyi->types[i] = keyi->dfltType;
1746 else if (FindAutomaticType(keymap, keyi->numLevels[i],
1747 darray_mem(keyi->syms[i], 0),
1748 &keyi->types[i], &autoType)) { }
1750 log_vrb(info->keymap->ctx, 5,
1751 "No automatic type for %d symbols; "
1752 "Using %s for the %s key (keycode %d)\n",
1754 xkb_atom_text(keymap->ctx, keyi->types[i]),
1755 LongKeyNameText(keyi->name), kc);
1757 if (FindNamedType(keymap, keyi->types[i], &types[i])) {
1758 if (!autoType || keyi->numLevels[i] > 2)
1759 key->explicit_groups |= (1 << i);
1762 log_vrb(info->keymap->ctx, 3,
1763 "Type \"%s\" is not defined; "
1764 "Using default type for the %s key (keycode %d)\n",
1765 xkb_atom_text(keymap->ctx, keyi->types[i]),
1766 LongKeyNameText(keyi->name), kc);
1768 * Index 0 is guaranteed to contain something, usually
1769 * ONE_LEVEL or at least some default one-level type.
1774 /* if the type specifies fewer levels than the key has, shrink the key */
1775 type = &keymap->types[types[i]];
1776 if (type->num_levels < keyi->numLevels[i]) {
1777 log_vrb(info->keymap->ctx, 1,
1778 "Type \"%s\" has %d levels, but %s has %d symbols; "
1779 "Ignoring extra symbols\n",
1780 xkb_atom_text(keymap->ctx, type->name),
1782 LongKeyNameText(keyi->name),
1783 keyi->numLevels[i]);
1784 keyi->numLevels[i] = type->num_levels;
1786 if (keyi->numLevels[i] > width)
1787 width = keyi->numLevels[i];
1788 if (type->num_levels > width)
1789 width = type->num_levels;
1790 sizeSyms += darray_size(keyi->syms[i]);
1793 darray_resize0(key->syms, sizeSyms);
1795 key->num_groups = nGroups;
1799 key->sym_index = calloc(nGroups * width, sizeof(*key->sym_index));
1801 key->num_syms = calloc(nGroups * width, sizeof(*key->num_syms));
1804 key->actions = calloc(nGroups * width, sizeof(*key->actions));
1805 key->explicit |= EXPLICIT_INTERP;
1808 key->out_of_range_group_number = keyi->out_of_range_group_number;
1809 key->out_of_range_group_action = keyi->out_of_range_group_action;
1811 for (i = 0; i < nGroups; i++) {
1812 /* assign kt_index[i] to the index of the type in map->types.
1813 * kt_index[i] may have been set by a previous run (if we have two
1814 * layouts specified). Let's not overwrite it with the ONE_LEVEL
1815 * default group if we dont even have keys for this group anyway.
1817 * FIXME: There should be a better fix for this.
1819 if (keyi->numLevels[i])
1820 key->kt_index[i] = types[i];
1821 if (!darray_empty(keyi->syms[i])) {
1822 /* fill key to "width" symbols*/
1823 for (tmp = 0; tmp < width; tmp++) {
1824 if (tmp < keyi->numLevels[i] &&
1825 darray_item(keyi->symsMapNumEntries[i], tmp) != 0) {
1826 memcpy(darray_mem(key->syms, symIndex),
1827 darray_mem(keyi->syms[i],
1828 darray_item(keyi->symsMapIndex[i], tmp)),
1829 darray_item(keyi->symsMapNumEntries[i],
1830 tmp) * sizeof(xkb_keysym_t));
1831 key->sym_index[(i * width) + tmp] = symIndex;
1832 key->num_syms[(i * width) + tmp] =
1833 darray_item(keyi->symsMapNumEntries[i], tmp);
1834 symIndex += key->num_syms[(i * width) + tmp];
1837 key->sym_index[(i * width) + tmp] = -1;
1838 key->num_syms[(i * width) + tmp] = 0;
1840 if (key->actions && !darray_empty(keyi->acts[i])) {
1841 if (tmp < keyi->numLevels[i])
1842 key->actions[tmp] = darray_item(keyi->acts[i], tmp);
1844 key->actions[tmp].type = ACTION_TYPE_NONE;
1850 if (keyi->defined & KEY_FIELD_VMODMAP) {
1851 key->vmodmap = keyi->vmodmap;
1852 key->explicit |= EXPLICIT_VMODMAP;
1855 if (keyi->repeat != KEY_REPEAT_UNDEFINED) {
1856 key->repeats = (keyi->repeat == KEY_REPEAT_YES);
1857 key->explicit |= EXPLICIT_REPEAT;
1860 /* do the same thing for the next key */
1861 CopySymbolsDef(info, keyi, kc + 1);
1866 CopyModMapDef(SymbolsInfo *info, ModMapEntry *entry)
1868 struct xkb_key *key;
1869 struct xkb_keymap *keymap = info->keymap;
1871 if (!entry->haveSymbol) {
1872 key = FindNamedKey(keymap, entry->u.keyName, true, 0);
1874 log_vrb(info->keymap->ctx, 5,
1875 "Key %s not found in keycodes; "
1876 "Modifier map entry for %s not updated\n",
1877 LongKeyNameText(entry->u.keyName),
1878 ModIndexText(entry->modifier));
1883 key = FindKeyForSymbol(keymap, entry->u.keySym);
1885 log_vrb(info->keymap->ctx, 5,
1886 "Key \"%s\" not found in symbol map; "
1887 "Modifier map entry for %s not updated\n",
1888 KeysymText(entry->u.keySym),
1889 ModIndexText(entry->modifier));
1894 key->modmap |= (1 << entry->modifier);
1899 * Handle the xkb_symbols section of an xkb file.
1901 * @param file The parsed xkb_symbols section of the xkb file.
1902 * @param keymap Handle to the keyboard description to store the symbols in.
1903 * @param merge Merge strategy (e.g. MERGE_OVERRIDE).
1906 CompileSymbols(XkbFile *file, struct xkb_keymap *keymap,
1907 enum merge_mode merge)
1909 xkb_group_index_t i;
1910 struct xkb_key *key;
1912 ActionsInfo *actions;
1916 actions = NewActionsInfo();
1920 InitSymbolsInfo(&info, keymap, file->id, actions);
1921 info.dflt.merge = merge;
1923 HandleSymbolsFile(&info, file, merge);
1925 if (darray_empty(info.keys))
1928 if (info.errorCount != 0)
1932 keymap->symbols_section_name = strdup(info.name);
1934 for (i = 0; i < XKB_NUM_GROUPS; i++)
1935 if (info.groupNames[i] != XKB_ATOM_NONE)
1936 keymap->group_names[i] = info.groupNames[i];
1939 darray_foreach(keyi, info.keys)
1940 PrepareKeyDef(keyi);
1943 darray_foreach(keyi, info.keys)
1944 if (!CopySymbolsDef(&info, keyi, 0))
1947 if (xkb_get_log_verbosity(keymap->ctx) > 3) {
1948 xkb_foreach_key(key, keymap) {
1949 if (key->name[0] == '\0')
1952 if (key->num_groups < 1)
1953 log_info(info.keymap->ctx,
1954 "No symbols defined for %s (keycode %d)\n",
1955 KeyNameText(key->name),
1956 XkbKeyGetKeycode(keymap, key));
1960 list_foreach(mm, &info.modMaps, entry)
1961 if (!CopyModMapDef(&info, mm))
1964 ClearSymbolsInfo(&info);
1965 FreeActionsInfo(actions);
1969 FreeActionsInfo(actions);
1970 ClearSymbolsInfo(&info);