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 ********************************************************/
28 * Copyright © 2012 Intel Corporation
29 * Copyright © 2012 Ran Benita <ran234@gmail.com>
31 * Permission is hereby granted, free of charge, to any person obtaining a
32 * copy of this software and associated documentation files (the "Software"),
33 * to deal in the Software without restriction, including without limitation
34 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
35 * and/or sell copies of the Software, and to permit persons to whom the
36 * Software is furnished to do so, subject to the following conditions:
38 * The above copyright notice and this permission notice (including the next
39 * paragraph) shall be included in all copies or substantial portions of the
42 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
43 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
44 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
45 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
46 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
47 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
48 * DEALINGS IN THE SOFTWARE.
50 * Author: Daniel Stone <daniel@fooishbar.org>
51 * Ran Benita <ran234@gmail.com>
54 #include "xkbcomp-priv.h"
65 KEY_REPEAT_UNDEFINED = -1
69 GROUP_FIELD_SYMS = (1 << 0),
70 GROUP_FIELD_ACTS = (1 << 1),
71 GROUP_FIELD_TYPE = (1 << 2),
75 KEY_FIELD_REPEAT = (1 << 0),
76 KEY_FIELD_TYPE_DFLT = (1 << 1),
77 KEY_FIELD_GROUPINFO = (1 << 2),
78 KEY_FIELD_VMODMAP = (1 << 3),
82 enum group_field defined;
84 xkb_level_index_t numLevels;
85 darray(xkb_keysym_t) syms;
87 * symsMapIndex[level] -> The index from which the syms for the
88 * level begin in the syms array. Remember each keycode can have
89 * multiple keysyms in each level (that is, each key press can
90 * result in multiple keysyms).
92 darray(int) symsMapIndex;
94 * symsMapNumEntries[level] -> How many syms are in
95 * syms[symsMapIndex[level]].
97 darray(unsigned int) symsMapNumEntries;
98 darray(union xkb_action) acts;
102 typedef struct _KeyInfo {
103 enum key_field defined;
105 enum merge_mode merge;
107 unsigned long name; /* the 4 chars of the key name, as long */
109 GroupInfo groups[XKB_NUM_GROUPS];
111 enum key_repeat repeat;
112 xkb_mod_mask_t vmodmap;
115 enum xkb_range_exceed_type out_of_range_group_action;
116 xkb_group_index_t out_of_range_group_number;
120 InitGroupInfo(GroupInfo *groupi)
122 memset(groupi, 0, sizeof(*groupi));
126 ClearGroupInfo(GroupInfo *groupi)
128 darray_free(groupi->syms);
129 darray_free(groupi->symsMapIndex);
130 darray_free(groupi->symsMapNumEntries);
131 darray_free(groupi->acts);
132 InitGroupInfo(groupi);
136 InitKeyInfo(KeyInfo *keyi, unsigned file_id)
139 static const char dflt[4] = "*";
142 keyi->file_id = file_id;
143 keyi->merge = MERGE_OVERRIDE;
144 keyi->name = KeyNameToLong(dflt);
145 for (i = 0; i < XKB_NUM_GROUPS; i++)
146 InitGroupInfo(&keyi->groups[i]);
147 keyi->dfltType = XKB_ATOM_NONE;
149 keyi->repeat = KEY_REPEAT_UNDEFINED;
150 keyi->out_of_range_group_action = RANGE_WRAP;
151 keyi->out_of_range_group_number = 0;
155 ClearKeyInfo(KeyInfo *keyi)
159 for (i = 0; i < XKB_NUM_GROUPS; i++)
160 ClearGroupInfo(&keyi->groups[i]);
164 CopyKeyInfo(KeyInfo * old, KeyInfo * new, bool clearOld)
171 for (i = 0; i < XKB_NUM_GROUPS; i++) {
172 InitGroupInfo(&old->groups[i]);
176 for (i = 0; i < XKB_NUM_GROUPS; i++) {
177 GroupInfo *n = &new->groups[i], *o = &old->groups[i];
178 darray_copy(n->syms, o->syms);
179 darray_copy(n->symsMapIndex, o->symsMapIndex);
180 darray_copy(n->symsMapNumEntries, o->symsMapNumEntries);
181 darray_copy(n->acts, o->acts);
188 /***====================================================================***/
190 typedef struct _ModMapEntry {
191 enum merge_mode merge;
195 unsigned long keyName;
200 typedef struct _SymbolsInfo {
201 char *name; /* e.g. pc+us+inet(evdev) */
204 enum merge_mode merge;
205 xkb_group_index_t explicit_group;
206 darray(KeyInfo) keys;
209 ActionsInfo *actions;
210 xkb_atom_t groupNames[XKB_NUM_GROUPS];
211 darray(ModMapEntry) modMaps;
213 struct xkb_keymap *keymap;
217 InitSymbolsInfo(SymbolsInfo *info, struct xkb_keymap *keymap,
218 unsigned file_id, ActionsInfo *actions)
223 info->explicit_group = 0;
224 info->errorCount = 0;
225 info->file_id = file_id;
226 info->merge = MERGE_OVERRIDE;
227 darray_init(info->keys);
228 darray_growalloc(info->keys, 110);
229 darray_init(info->modMaps);
230 for (i = 0; i < XKB_NUM_GROUPS; i++)
231 info->groupNames[i] = XKB_ATOM_NONE;
232 InitKeyInfo(&info->dflt, file_id);
233 InitVModInfo(&info->vmods, keymap);
234 info->actions = actions;
235 info->keymap = keymap;
239 ClearSymbolsInfo(SymbolsInfo * info)
244 darray_foreach(keyi, info->keys)
246 darray_free(info->keys);
247 darray_free(info->modMaps);
248 memset(info, 0, sizeof(SymbolsInfo));
252 ResizeGroupInfo(GroupInfo *groupi, xkb_level_index_t numLevels,
253 unsigned sizeSyms, bool forceActions)
257 if (darray_size(groupi->syms) < sizeSyms)
258 darray_resize0(groupi->syms, sizeSyms);
260 if (darray_empty(groupi->symsMapIndex) ||
261 groupi->numLevels < numLevels) {
262 darray_resize(groupi->symsMapIndex, numLevels);
263 for (i = groupi->numLevels; i < numLevels; i++)
264 darray_item(groupi->symsMapIndex, i) = -1;
267 if (darray_empty(groupi->symsMapNumEntries) ||
268 groupi->numLevels < numLevels)
269 darray_resize0(groupi->symsMapNumEntries, numLevels);
271 if ((forceActions && (groupi->numLevels < numLevels ||
272 darray_empty(groupi->acts))) ||
273 (groupi->numLevels < numLevels && !darray_empty(groupi->acts)))
274 darray_resize0(groupi->acts, numLevels);
276 groupi->numLevels = MAX(groupi->numLevels, numLevels);
281 enum key_group_selector {
288 * Merge @from into @into, where both are groups with the same index
289 * for the same key, and have at least on level to merge.
290 * @group and @key_name are just for reporting.
293 MergeGroups(SymbolsInfo *info, GroupInfo *into, GroupInfo *from, bool clobber,
294 bool report, xkb_group_index_t group, unsigned long key_name)
297 unsigned int resultSize = 0;
298 enum key_group_selector using = NONE;
299 unsigned int cur_idx = 0;
302 /* First find the type of the merged group. */
303 if (into->type != from->type && from->type != XKB_ATOM_NONE) {
304 if (into->type == XKB_ATOM_NONE) {
305 into->type = from->type;
308 xkb_atom_t use, ignore;
310 use = (clobber ? from->type : into->type);
311 ignore = (clobber ? into->type : from->type);
314 log_warn(info->keymap->ctx,
315 "Multiple definitions for group %d type of key %s; "
316 "Using %s, ignoring %s\n",
317 group + 1, LongKeyNameText(key_name),
318 xkb_atom_text(info->keymap->ctx, use),
319 xkb_atom_text(info->keymap->ctx, ignore));
324 into->defined |= GROUP_FIELD_TYPE;
327 /* Now look at the levels. */
329 /* Easy case: @from is empty. Just stick with @into. */
330 if (from->numLevels == 0) {
335 /* Easy case: @into is empty. Just copy @from as-is. */
336 if (into->numLevels == 0) {
337 from->type = into->type;
344 * Hard case: need to start merging levels. The aim is to avoid
345 * copying/allocating where possible.
348 InitGroupInfo(&result);
350 if (into->numLevels >= from->numLevels) {
351 result.acts = into->acts;
352 result.numLevels = into->numLevels;
355 result.acts = from->acts;
356 result.numLevels = from->numLevels;
357 darray_resize(into->symsMapIndex, from->numLevels);
358 darray_resize0(into->symsMapNumEntries, from->numLevels);
359 for (i = into->numLevels; i < from->numLevels; i++)
360 darray_item(into->symsMapIndex, i) = -1;
363 if (darray_empty(result.acts) && (!darray_empty(into->acts) ||
364 !darray_empty(from->acts))) {
365 darray_resize0(result.acts, result.numLevels);
366 for (i = 0; i < result.numLevels; i++) {
367 union xkb_action *fromAct = NULL, *toAct = NULL;
369 if (!darray_empty(from->acts))
370 fromAct = &darray_item(from->acts, i);
372 if (!darray_empty(into->acts))
373 toAct = &darray_item(into->acts, i);
375 if (((fromAct == NULL) || (fromAct->type == ACTION_TYPE_NONE))
376 && (toAct != NULL)) {
377 darray_item(result.acts, i) = *toAct;
379 else if (((toAct == NULL) || (toAct->type == ACTION_TYPE_NONE))
380 && (fromAct != NULL)) {
381 darray_item(result.acts, i) = *fromAct;
384 union xkb_action *use, *ignore;
394 log_warn(info->keymap->ctx,
395 "Multiple actions for level %d/group %u on key %s; "
396 "Using %s, ignoring %s\n",
397 i + 1, group + 1, LongKeyNameText(key_name),
398 ActionTypeText(use->type),
399 ActionTypeText(ignore->type));
401 darray_item(result.acts, i) = *use;
406 for (i = 0; i < result.numLevels; i++) {
407 unsigned int fromSize = 0;
408 unsigned int toSize = 0;
410 if (!darray_empty(from->symsMapNumEntries) && i < from->numLevels)
411 fromSize = darray_item(from->symsMapNumEntries, i);
413 if (!darray_empty(into->symsMapNumEntries) && i < into->numLevels)
414 toSize = darray_item(into->symsMapNumEntries, i);
417 resultSize += toSize;
420 else if (toSize == 0 || clobber) {
421 resultSize += fromSize;
425 resultSize += toSize;
434 result.syms = from->syms;
435 darray_free(into->symsMapNumEntries);
436 darray_free(into->symsMapIndex);
437 into->symsMapNumEntries = from->symsMapNumEntries;
438 into->symsMapIndex = from->symsMapIndex;
439 darray_init(from->symsMapNumEntries);
440 darray_init(from->symsMapIndex);
443 else if (using == TO) {
444 result.syms = into->syms;
448 darray_resize0(result.syms, resultSize);
450 for (i = 0; i < result.numLevels; i++) {
451 enum key_group_selector use = NONE;
452 unsigned int fromSize = 0;
453 unsigned int toSize = 0;
455 if (i < from->numLevels)
456 fromSize = darray_item(from->symsMapNumEntries, i);
458 if (i < into->numLevels)
459 toSize = darray_item(into->symsMapNumEntries, i);
461 if (fromSize == 0 && toSize == 0) {
462 darray_item(into->symsMapIndex, i) = -1;
463 darray_item(into->symsMapNumEntries, i) = 0;
469 else if (toSize == 0 || clobber)
474 if (toSize && fromSize && report) {
475 log_info(info->keymap->ctx,
476 "Multiple symbols for group %u, level %d on key %s; "
477 "Using %s, ignoring %s\n",
478 group + 1, i + 1, LongKeyNameText(key_name),
479 (use == FROM ? "from" : "to"),
480 (use == FROM ? "to" : "from"));
484 memcpy(darray_mem(result.syms, cur_idx),
485 darray_mem(from->syms, darray_item(from->symsMapIndex, i)),
486 darray_item(from->symsMapNumEntries, i) * sizeof(xkb_keysym_t));
487 darray_item(into->symsMapIndex, i) = cur_idx;
488 darray_item(into->symsMapNumEntries, i) =
489 darray_item(from->symsMapNumEntries, i);
492 memcpy(darray_mem(result.syms, cur_idx),
493 darray_mem(into->syms, darray_item(into->symsMapIndex, i)),
494 darray_item(into->symsMapNumEntries, i) * sizeof(xkb_keysym_t));
495 darray_item(into->symsMapIndex, i) = cur_idx;
498 cur_idx += darray_item(into->symsMapNumEntries, i);
502 into->numLevels = result.numLevels;
504 if (!darray_same(result.acts, into->acts))
505 darray_free(into->acts);
506 if (!darray_same(result.acts, from->acts))
507 darray_free(from->acts);
508 into->acts = result.acts;
509 into->defined |= GROUP_FIELD_ACTS;
510 darray_init(from->acts);
511 from->defined &= ~GROUP_FIELD_ACTS;
513 if (!darray_same(result.syms, into->syms))
514 darray_free(into->syms);
515 if (!darray_same(result.syms, from->syms))
516 darray_free(from->syms);
517 into->syms = result.syms;
518 if (darray_empty(into->syms))
519 into->defined &= ~GROUP_FIELD_SYMS;
521 into->defined |= GROUP_FIELD_SYMS;
522 darray_init(from->syms);
523 from->defined &= ~GROUP_FIELD_SYMS;
525 darray_free(from->symsMapIndex);
526 darray_free(from->symsMapNumEntries);
532 UseNewKeyField(enum key_field field, enum key_field old, enum key_field new,
533 bool clobber, bool report, enum key_field *collide)
536 return (new & field);
550 /* Merge @from into @into, where both contain info for the same key. */
552 MergeKeys(SymbolsInfo *info, KeyInfo *into, KeyInfo *from)
555 enum key_field collide = 0;
556 bool clobber, report;
557 int verbosity = xkb_get_log_verbosity(info->keymap->ctx);
559 /* Forget about @into; just copy @from as-is. */
560 if (from->merge == MERGE_REPLACE) {
561 for (i = 0; i < XKB_NUM_GROUPS; i++)
562 if (into->groups[i].numLevels != 0)
563 ClearGroupInfo(&into->groups[i]);
565 InitKeyInfo(from, info->file_id);
569 clobber = (from->merge != MERGE_AUGMENT);
570 report = (verbosity > 9 ||
571 (into->file_id == from->file_id && verbosity > 0));
573 /* Start looking into the key groups. */
574 for (i = 0; i < XKB_NUM_GROUPS; i++)
575 MergeGroups(info, &into->groups[i], &from->groups[i], clobber,
576 report, i, into->name);
578 if (UseNewKeyField(KEY_FIELD_VMODMAP, into->defined, from->defined,
579 clobber, report, &collide)) {
580 into->vmodmap = from->vmodmap;
581 into->defined |= KEY_FIELD_VMODMAP;
583 if (UseNewKeyField(KEY_FIELD_REPEAT, into->defined, from->defined,
584 clobber, report, &collide)) {
585 into->repeat = from->repeat;
586 into->defined |= KEY_FIELD_REPEAT;
588 if (UseNewKeyField(KEY_FIELD_TYPE_DFLT, into->defined, from->defined,
589 clobber, report, &collide)) {
590 into->dfltType = from->dfltType;
591 into->defined |= KEY_FIELD_TYPE_DFLT;
593 if (UseNewKeyField(KEY_FIELD_GROUPINFO, into->defined, from->defined,
594 clobber, report, &collide)) {
595 into->out_of_range_group_action = from->out_of_range_group_action;
596 into->out_of_range_group_number = from->out_of_range_group_number;
597 into->defined |= KEY_FIELD_GROUPINFO;
601 log_warn(info->keymap->ctx,
602 "Symbol map for key %s redefined; "
603 "Using %s definition for conflicting fields\n",
604 LongKeyNameText(into->name),
605 (clobber ? "first" : "last"));
611 AddKeySymbols(SymbolsInfo *info, KeyInfo *keyi)
613 unsigned long real_name;
616 darray_foreach(iter, info->keys)
617 if (iter->name == keyi->name)
618 return MergeKeys(info, iter, keyi);
620 if (FindKeyNameForAlias(info->keymap, keyi->name, &real_name))
621 darray_foreach(iter, info->keys)
622 if (iter->name == real_name)
623 return MergeKeys(info, iter, keyi);
625 darray_resize0(info->keys, darray_size(info->keys) + 1);
626 new = &darray_item(info->keys, darray_size(info->keys) - 1);
627 return CopyKeyInfo(keyi, new, true);
631 AddModMapEntry(SymbolsInfo * info, ModMapEntry * new)
636 clobber = (new->merge != MERGE_AUGMENT);
637 darray_foreach(mm, info->modMaps) {
638 if (new->haveSymbol && mm->haveSymbol
639 && (new->u.keySym == mm->u.keySym)) {
640 unsigned use, ignore;
641 if (mm->modifier != new->modifier) {
644 ignore = mm->modifier;
648 ignore = new->modifier;
650 log_err(info->keymap->ctx,
651 "%s added to symbol map for multiple modifiers; "
652 "Using %s, ignoring %s.\n",
653 KeysymText(new->u.keySym), ModIndexText(use),
654 ModIndexText(ignore));
659 if ((!new->haveSymbol) && (!mm->haveSymbol) &&
660 (new->u.keyName == mm->u.keyName)) {
661 unsigned use, ignore;
662 if (mm->modifier != new->modifier) {
665 ignore = mm->modifier;
669 ignore = new->modifier;
671 log_err(info->keymap->ctx,
672 "Key %s added to map for multiple modifiers; "
673 "Using %s, ignoring %s.\n",
674 LongKeyNameText(new->u.keyName), ModIndexText(use),
675 ModIndexText(ignore));
682 darray_append(info->modMaps, *new);
686 /***====================================================================***/
689 MergeIncludedSymbols(SymbolsInfo *into, SymbolsInfo *from,
690 enum merge_mode merge)
696 if (from->errorCount > 0) {
697 into->errorCount += from->errorCount;
700 if (into->name == NULL) {
701 into->name = from->name;
704 for (i = 0; i < XKB_NUM_GROUPS; i++) {
705 if (from->groupNames[i] != XKB_ATOM_NONE) {
706 if ((merge != MERGE_AUGMENT) ||
707 (into->groupNames[i] == XKB_ATOM_NONE))
708 into->groupNames[i] = from->groupNames[i];
712 darray_foreach(keyi, from->keys) {
713 merge = (merge == MERGE_DEFAULT ? keyi->merge : merge);
714 if (!AddKeySymbols(into, keyi))
718 darray_foreach(mm, from->modMaps) {
719 mm->merge = (merge == MERGE_DEFAULT ? mm->merge : merge);
720 if (!AddModMapEntry(into, mm))
726 HandleSymbolsFile(SymbolsInfo *info, XkbFile *file, enum merge_mode merge);
729 HandleIncludeSymbols(SymbolsInfo *info, IncludeStmt *stmt)
731 enum merge_mode merge = MERGE_DEFAULT;
733 SymbolsInfo included, next_incl;
735 InitSymbolsInfo(&included, info->keymap, info->file_id, info->actions);
738 included.name = stmt->stmt;
742 for (; stmt; stmt = stmt->next_incl) {
743 if (!ProcessIncludeFile(info->keymap->ctx, stmt, FILE_TYPE_SYMBOLS,
745 info->errorCount += 10;
746 ClearSymbolsInfo(&included);
750 InitSymbolsInfo(&next_incl, info->keymap, rtrn->id, info->actions);
751 next_incl.merge = next_incl.dflt.merge = MERGE_OVERRIDE;
753 next_incl.explicit_group = atoi(stmt->modifier) - 1;
755 next_incl.explicit_group = info->explicit_group;
757 HandleSymbolsFile(&next_incl, rtrn, MERGE_OVERRIDE);
759 MergeIncludedSymbols(&included, &next_incl, merge);
761 ClearSymbolsInfo(&next_incl);
765 MergeIncludedSymbols(info, &included, merge);
766 ClearSymbolsInfo(&included);
768 return (info->errorCount == 0);
775 GetGroupIndex(SymbolsInfo *info, KeyInfo *keyi, ExprDef *arrayNdx,
776 unsigned what, xkb_group_index_t *ndx_rtrn)
778 const char *name = (what == SYMBOLS ? "symbols" : "actions");
780 if (arrayNdx == NULL) {
782 enum group_field field = (what == SYMBOLS ?
783 GROUP_FIELD_SYMS : GROUP_FIELD_ACTS);
785 for (i = 0; i < XKB_NUM_GROUPS; i++) {
786 if (!(keyi->groups[i].defined & field)) {
792 log_err(info->keymap->ctx,
793 "Too many groups of %s for key %s (max %u); "
794 "Ignoring %s defined for extra groups\n",
795 name, LongKeyNameText(keyi->name), XKB_NUM_GROUPS + 1, name);
799 if (!ExprResolveGroup(info->keymap->ctx, arrayNdx, ndx_rtrn)) {
800 log_err(info->keymap->ctx,
801 "Illegal group index for %s of key %s\n"
802 "Definition with non-integer array index ignored\n",
803 name, LongKeyNameText(keyi->name));
812 LookupKeysym(const char *str, xkb_keysym_t *sym_rtrn)
816 if (!str || istreq(str, "any") || istreq(str, "nosymbol")) {
817 *sym_rtrn = XKB_KEY_NoSymbol;
821 if (istreq(str, "none") || istreq(str, "voidsymbol")) {
822 *sym_rtrn = XKB_KEY_VoidSymbol;
826 sym = xkb_keysym_from_name(str);
827 if (sym != XKB_KEY_NoSymbol) {
836 AddSymbolsToKey(SymbolsInfo *info, KeyInfo *keyi, ExprDef *arrayNdx,
839 xkb_group_index_t ndx;
842 xkb_level_index_t nLevels;
846 if (!GetGroupIndex(info, keyi, arrayNdx, SYMBOLS, &ndx))
849 groupi = &keyi->groups[ndx];
852 groupi->defined |= GROUP_FIELD_SYMS;
856 if (value->op != EXPR_KEYSYM_LIST) {
857 log_err(info->keymap->ctx,
858 "Expected a list of symbols, found %s; "
859 "Ignoring symbols for group %u of %s\n",
860 expr_op_type_to_string(value->op), ndx + 1,
861 LongKeyNameText(keyi->name));
865 if (!darray_empty(groupi->syms)) {
866 log_err(info->keymap->ctx,
867 "Symbols for key %s, group %u already defined; "
868 "Ignoring duplicate definition\n",
869 LongKeyNameText(keyi->name), ndx + 1);
873 nSyms = darray_size(value->value.list.syms);
874 nLevels = darray_size(value->value.list.symsMapIndex);
876 if ((groupi->numLevels < nSyms || darray_empty(groupi->syms))) {
877 if (!ResizeGroupInfo(groupi, nLevels, nSyms, false)) {
878 log_wsgo(info->keymap->ctx,
879 "Could not resize group %u of key %s to contain %zu levels; "
881 ndx + 1, LongKeyNameText(keyi->name), nSyms);
886 groupi->defined |= GROUP_FIELD_SYMS;
888 for (i = 0; i < nLevels; i++) {
889 darray_item(groupi->symsMapIndex, i) =
890 darray_item(value->value.list.symsMapIndex, i);
891 darray_item(groupi->symsMapNumEntries, i) =
892 darray_item(value->value.list.symsNumEntries, i);
894 for (j = 0; j < darray_item(groupi->symsMapNumEntries, i); j++) {
895 /* FIXME: What's abort() doing here? */
896 if (darray_item(groupi->symsMapIndex, i) + j >= nSyms)
899 if (!LookupKeysym(darray_item(value->value.list.syms,
900 darray_item(value->value.list.symsMapIndex, i) + j),
901 &darray_item(groupi->syms,
902 darray_item(groupi->symsMapIndex, i) + j))) {
903 log_warn(info->keymap->ctx,
904 "Could not resolve keysym %s for key %s, group %u (%s), level %zu\n",
905 darray_item(value->value.list.syms, i),
906 LongKeyNameText(keyi->name),
908 xkb_atom_text(info->keymap->ctx,
909 info->groupNames[ndx]),
913 darray_item(groupi->syms,
914 darray_item(groupi->symsMapIndex, i) + j) = XKB_KEY_NoSymbol;
916 darray_item(groupi->symsMapIndex, i) = -1;
917 darray_item(groupi->symsMapNumEntries, i) = 0;
921 if (darray_item(groupi->symsMapNumEntries, i) == 1 &&
922 darray_item(groupi->syms,
923 darray_item(groupi->symsMapIndex, i) + j) == XKB_KEY_NoSymbol) {
924 darray_item(groupi->symsMapIndex, i) = -1;
925 darray_item(groupi->symsMapNumEntries, i) = 0;
930 for (j = groupi->numLevels - 1;
931 j >= 0 && darray_item(groupi->symsMapNumEntries, j) == 0; j--)
938 AddActionsToKey(SymbolsInfo *info, KeyInfo *keyi, ExprDef *arrayNdx,
942 xkb_group_index_t ndx;
946 union xkb_action *toAct;
948 if (!GetGroupIndex(info, keyi, arrayNdx, ACTIONS, &ndx))
951 groupi = &keyi->groups[ndx];
954 groupi->defined |= GROUP_FIELD_ACTS;
958 if (value->op != EXPR_ACTION_LIST) {
959 log_wsgo(info->keymap->ctx,
960 "Bad expression type (%d) for action list value; "
961 "Ignoring actions for group %u of %s\n",
962 value->op, ndx, LongKeyNameText(keyi->name));
966 if (!darray_empty(groupi->acts)) {
967 log_wsgo(info->keymap->ctx,
968 "Actions for key %s, group %u already defined\n",
969 LongKeyNameText(keyi->name), ndx);
973 for (nActs = 0, act = value->value.child; act != NULL; nActs++) {
974 act = (ExprDef *) act->common.next;
978 log_wsgo(info->keymap->ctx,
979 "Action list but not actions in AddActionsToKey\n");
983 if ((groupi->numLevels < nActs || darray_empty(groupi->acts))) {
984 if (!ResizeGroupInfo(&keyi->groups[ndx], nActs, nActs, true)) {
985 log_wsgo(info->keymap->ctx,
986 "Could not resize group %u of key %s; "
988 ndx, LongKeyNameText(keyi->name));
993 groupi->defined |= GROUP_FIELD_ACTS;
995 toAct = darray_mem(groupi->acts, 0);
996 act = value->value.child;
997 for (i = 0; i < nActs; i++, toAct++) {
998 if (!HandleActionDef(act, info->keymap, toAct, info->actions)) {
999 log_err(info->keymap->ctx,
1000 "Illegal action definition for %s; "
1001 "Action for group %u/level %u ignored\n",
1002 LongKeyNameText(keyi->name), ndx + 1, i + 1);
1004 act = (ExprDef *) act->common.next;
1010 static const LookupEntry repeatEntries[] = {
1011 { "true", KEY_REPEAT_YES },
1012 { "yes", KEY_REPEAT_YES },
1013 { "on", KEY_REPEAT_YES },
1014 { "false", KEY_REPEAT_NO },
1015 { "no", KEY_REPEAT_NO },
1016 { "off", KEY_REPEAT_NO },
1017 { "default", KEY_REPEAT_UNDEFINED },
1022 SetSymbolsField(SymbolsInfo *info, KeyInfo *keyi, const char *field,
1023 ExprDef *arrayNdx, ExprDef *value)
1026 struct xkb_context *ctx = info->keymap->ctx;
1028 if (istreq(field, "type")) {
1029 xkb_group_index_t ndx;
1032 if (!ExprResolveString(ctx, value, &val))
1034 "The type field of a key symbol map must be a string; "
1035 "Ignoring illegal type definition\n");
1037 if (arrayNdx == NULL) {
1038 keyi->dfltType = val;
1039 keyi->defined |= KEY_FIELD_TYPE_DFLT;
1041 else if (!ExprResolveGroup(ctx, arrayNdx, &ndx)) {
1043 "Illegal group index for type of key %s; "
1044 "Definition with non-integer array index ignored\n",
1045 LongKeyNameText(keyi->name));
1050 keyi->groups[ndx].type = val;
1051 keyi->groups[ndx].defined |= GROUP_FIELD_TYPE;
1054 else if (istreq(field, "symbols"))
1055 return AddSymbolsToKey(info, keyi, arrayNdx, value);
1056 else if (istreq(field, "actions"))
1057 return AddActionsToKey(info, keyi, arrayNdx, value);
1058 else if (istreq(field, "vmods") ||
1059 istreq(field, "virtualmods") ||
1060 istreq(field, "virtualmodifiers")) {
1061 xkb_mod_mask_t mask;
1063 ok = ExprResolveVModMask(info->keymap, value, &mask);
1065 keyi->vmodmap = (mask >> XKB_NUM_CORE_MODS) & 0xffff;
1066 keyi->defined |= KEY_FIELD_VMODMAP;
1069 log_err(info->keymap->ctx,
1070 "Expected a virtual modifier mask, found %s; "
1071 "Ignoring virtual modifiers definition for key %s\n",
1072 expr_op_type_to_string(value->op),
1073 LongKeyNameText(keyi->name));
1076 else if (istreq(field, "locking") ||
1077 istreq(field, "lock") ||
1078 istreq(field, "locks")) {
1079 log_err(info->keymap->ctx,
1080 "Key behaviors not supported; "
1081 "Ignoring locking specification for key %s\n",
1082 LongKeyNameText(keyi->name));
1084 else if (istreq(field, "radiogroup") ||
1085 istreq(field, "permanentradiogroup") ||
1086 istreq(field, "allownone")) {
1087 log_err(info->keymap->ctx,
1088 "Radio groups not supported; "
1089 "Ignoring radio group specification for key %s\n",
1090 LongKeyNameText(keyi->name));
1092 else if (istreq_prefix("overlay", field) ||
1093 istreq_prefix("permanentoverlay", field)) {
1094 log_err(info->keymap->ctx,
1095 "Overlays not supported; "
1096 "Ignoring overlay specification for key %s\n",
1097 LongKeyNameText(keyi->name));
1099 else if (istreq(field, "repeating") ||
1100 istreq(field, "repeats") ||
1101 istreq(field, "repeat")) {
1104 ok = ExprResolveEnum(ctx, value, &val, repeatEntries);
1106 log_err(info->keymap->ctx,
1107 "Illegal repeat setting for %s; "
1108 "Non-boolean repeat setting ignored\n",
1109 LongKeyNameText(keyi->name));
1113 keyi->defined |= KEY_FIELD_REPEAT;
1115 else if (istreq(field, "groupswrap") ||
1116 istreq(field, "wrapgroups")) {
1119 if (!ExprResolveBoolean(ctx, value, &set)) {
1120 log_err(info->keymap->ctx,
1121 "Illegal groupsWrap setting for %s; "
1122 "Non-boolean value ignored\n",
1123 LongKeyNameText(keyi->name));
1128 keyi->out_of_range_group_action = RANGE_WRAP;
1130 keyi->out_of_range_group_action = RANGE_SATURATE;
1132 keyi->defined |= KEY_FIELD_GROUPINFO;
1134 else if (istreq(field, "groupsclamp") ||
1135 istreq(field, "clampgroups")) {
1138 if (!ExprResolveBoolean(ctx, value, &set)) {
1139 log_err(info->keymap->ctx,
1140 "Illegal groupsClamp setting for %s; "
1141 "Non-boolean value ignored\n",
1142 LongKeyNameText(keyi->name));
1147 keyi->out_of_range_group_action = RANGE_SATURATE;
1149 keyi->out_of_range_group_action = RANGE_WRAP;
1151 keyi->defined |= KEY_FIELD_GROUPINFO;
1153 else if (istreq(field, "groupsredirect") ||
1154 istreq(field, "redirectgroups")) {
1155 xkb_group_index_t grp;
1157 if (!ExprResolveGroup(ctx, value, &grp)) {
1158 log_err(info->keymap->ctx,
1159 "Illegal group index for redirect of key %s; "
1160 "Definition with non-integer group ignored\n",
1161 LongKeyNameText(keyi->name));
1165 keyi->out_of_range_group_action = RANGE_REDIRECT;
1166 keyi->out_of_range_group_number = grp - 1;
1167 keyi->defined |= KEY_FIELD_GROUPINFO;
1170 log_err(info->keymap->ctx,
1171 "Unknown field %s in a symbol interpretation; "
1172 "Definition ignored\n",
1181 SetGroupName(SymbolsInfo *info, ExprDef *arrayNdx, ExprDef *value)
1183 xkb_group_index_t grp;
1187 log_vrb(info->keymap->ctx, 1,
1188 "You must specify an index when specifying a group name; "
1189 "Group name definition without array subscript ignored\n");
1193 if (!ExprResolveGroup(info->keymap->ctx, arrayNdx, &grp)) {
1194 log_err(info->keymap->ctx,
1195 "Illegal index in group name definition; "
1196 "Definition with non-integer array index ignored\n");
1200 if (!ExprResolveString(info->keymap->ctx, value, &name)) {
1201 log_err(info->keymap->ctx,
1202 "Group name must be a string; "
1203 "Illegal name for group %d ignored\n", grp);
1207 info->groupNames[grp - 1 + info->explicit_group] = name;
1212 HandleSymbolsVar(SymbolsInfo *info, VarDef *stmt)
1214 const char *elem, *field;
1218 if (ExprResolveLhs(info->keymap->ctx, stmt->name, &elem, &field,
1220 return 0; /* internal error, already reported */
1221 if (elem && istreq(elem, "key")) {
1222 ret = SetSymbolsField(info, &info->dflt, field, arrayNdx,
1225 else if (!elem && (istreq(field, "name") ||
1226 istreq(field, "groupname"))) {
1227 ret = SetGroupName(info, arrayNdx, stmt->value);
1229 else if (!elem && (istreq(field, "groupswrap") ||
1230 istreq(field, "wrapgroups"))) {
1231 log_err(info->keymap->ctx,
1232 "Global \"groupswrap\" not supported; Ignored\n");
1235 else if (!elem && (istreq(field, "groupsclamp") ||
1236 istreq(field, "clampgroups"))) {
1237 log_err(info->keymap->ctx,
1238 "Global \"groupsclamp\" not supported; Ignored\n");
1241 else if (!elem && (istreq(field, "groupsredirect") ||
1242 istreq(field, "redirectgroups"))) {
1243 log_err(info->keymap->ctx,
1244 "Global \"groupsredirect\" not supported; Ignored\n");
1247 else if (!elem && istreq(field, "allownone")) {
1248 log_err(info->keymap->ctx,
1249 "Radio groups not supported; "
1250 "Ignoring \"allownone\" specification\n");
1254 ret = SetActionField(info->keymap, elem, field, arrayNdx, stmt->value,
1262 HandleSymbolsBody(SymbolsInfo *info, VarDef *def, KeyInfo *keyi)
1265 const char *elem, *field;
1268 for (; def; def = (VarDef *) def->common.next) {
1269 if (def->name && def->name->op == EXPR_FIELD_REF) {
1270 ok = HandleSymbolsVar(info, def);
1275 if (!def->value || def->value->op == EXPR_KEYSYM_LIST)
1282 ok = ExprResolveLhs(info->keymap->ctx, def->name, &elem, &field,
1287 ok = SetSymbolsField(info, keyi, field, arrayNdx, def->value);
1294 SetExplicitGroup(SymbolsInfo *info, KeyInfo *keyi)
1296 xkb_group_index_t i;
1298 if (info->explicit_group == 0)
1301 for (i = 1; i < XKB_NUM_GROUPS; i++) {
1302 if (keyi->groups[i].defined) {
1303 log_warn(info->keymap->ctx,
1304 "For the map %s an explicit group specified, "
1305 "but key %s has more than one group defined; "
1306 "All groups except first one will be ignored\n",
1307 info->name, LongKeyNameText(keyi->name));
1311 if (i < XKB_NUM_GROUPS)
1312 for (i = 1; i < XKB_NUM_GROUPS; i++)
1313 ClearGroupInfo(&keyi->groups[i]);
1315 keyi->groups[info->explicit_group] = keyi->groups[0];
1316 InitGroupInfo(&keyi->groups[0]);
1321 HandleSymbolsDef(SymbolsInfo *info, SymbolsDef *stmt)
1325 InitKeyInfo(&keyi, info->file_id);
1326 CopyKeyInfo(&info->dflt, &keyi, false);
1327 keyi.merge = stmt->merge;
1328 keyi.name = KeyNameToLong(stmt->keyName);
1329 if (!HandleSymbolsBody(info, (VarDef *) stmt->symbols, &keyi)) {
1334 if (!SetExplicitGroup(info, &keyi)) {
1339 if (!AddKeySymbols(info, &keyi)) {
1347 HandleModMapDef(SymbolsInfo *info, ModMapDef *def)
1351 xkb_mod_index_t ndx;
1353 struct xkb_context *ctx = info->keymap->ctx;
1355 if (!LookupModIndex(ctx, NULL, def->modifier, EXPR_TYPE_INT, &ndx)) {
1356 log_err(info->keymap->ctx,
1357 "Illegal modifier map definition; "
1358 "Ignoring map for non-modifier \"%s\"\n",
1359 xkb_atom_text(ctx, def->modifier));
1366 for (key = def->keys; key != NULL; key = (ExprDef *) key->common.next) {
1369 if (key->op == EXPR_VALUE && key->value_type == EXPR_TYPE_KEYNAME) {
1370 tmp.haveSymbol = false;
1371 tmp.u.keyName = KeyNameToLong(key->value.keyName);
1373 else if (ExprResolveKeySym(ctx, key, &sym)) {
1374 tmp.haveSymbol = true;
1378 log_err(info->keymap->ctx,
1379 "Modmap entries may contain only key names or keysyms; "
1380 "Illegal definition for %s modifier ignored\n",
1381 ModIndexText(tmp.modifier));
1385 ok = AddModMapEntry(info, &tmp) && ok;
1391 HandleSymbolsFile(SymbolsInfo *info, XkbFile *file, enum merge_mode merge)
1397 info->name = strdup_safe(file->name);
1400 for (stmt = file->defs; stmt; stmt = stmt->next) {
1401 switch (stmt->type) {
1403 ok = HandleIncludeSymbols(info, (IncludeStmt *) stmt);
1406 ok = HandleSymbolsDef(info, (SymbolsDef *) stmt);
1409 ok = HandleSymbolsVar(info, (VarDef *) stmt);
1412 ok = HandleVModDef((VModDef *) stmt, info->keymap, merge,
1416 ok = HandleModMapDef(info, (ModMapDef *) stmt);
1419 log_err(info->keymap->ctx,
1420 "Interpretation files may not include other types; "
1421 "Ignoring %s\n", stmt_type_to_string(stmt->type));
1429 if (info->errorCount > 10) {
1430 log_err(info->keymap->ctx, "Abandoning symbols file \"%s\"\n",
1438 * Given a keysym @sym, return a key which generates it, or NULL.
1439 * This is used for example in a modifier map definition, such as:
1440 * modifier_map Lock { Caps_Lock };
1441 * where we want to add the Lock modifier to the modmap of the key
1442 * which matches the keysym Caps_Lock.
1443 * Since there can be many keys which generates the keysym, the key
1444 * is chosen first by lowest group in which the keysym appears, than
1445 * by lowest level and than by lowest key code.
1447 static struct xkb_key *
1448 FindKeyForSymbol(struct xkb_keymap *keymap, xkb_keysym_t sym)
1450 struct xkb_key *key, *ret = NULL;
1451 xkb_group_index_t group, min_group = UINT32_MAX;
1452 xkb_level_index_t level, min_level = UINT16_MAX;
1454 xkb_foreach_key(key, keymap) {
1455 for (group = 0; group < key->num_groups; group++) {
1456 for (level = 0; level < XkbKeyGroupWidth(keymap, key, group);
1458 if (XkbKeyNumSyms(key, group, level) != 1 ||
1459 (XkbKeySymEntry(key, group, level))[0] != sym)
1463 * If the keysym was found in a group or level > 0, we must
1464 * keep looking since we might find a key in which the keysym
1465 * is in a lower group or level.
1467 if (group < min_group ||
1468 (group == min_group && level < min_level)) {
1470 if (group == 0 && level == 0) {
1486 * Find the given name in the keymap->map->types and return its index.
1488 * @param name The name to search for.
1489 * @param type_rtrn Set to the index of the name if found.
1491 * @return true if found, false otherwise.
1494 FindNamedType(struct xkb_keymap *keymap, xkb_atom_t name, unsigned *type_rtrn)
1498 for (i = 0; i < keymap->num_types; i++) {
1499 if (keymap->types[i].name == name) {
1509 * Assign a type to the given sym and return the Atom for the type assigned.
1512 * - ONE_LEVEL for width 0/1
1513 * - ALPHABETIC for 2 shift levels, with lower/upercase
1514 * - KEYPAD for keypad keys.
1515 * - TWO_LEVEL for other 2 shift level keys.
1516 * and the same for four level keys.
1518 * @param width Number of sysms in syms.
1519 * @param syms The keysyms for the given key (must be size width).
1520 * @param typeNameRtrn Set to the Atom of the type name.
1522 * @returns true if a type could be found, false otherwise.
1524 * FIXME: I need to take the KeyInfo so I can look at symsMapIndex and
1525 * all that fun stuff rather than just assuming there's always one
1529 FindAutomaticType(struct xkb_keymap *keymap, xkb_level_index_t width,
1530 const xkb_keysym_t *syms, xkb_atom_t *typeNameRtrn,
1534 if ((width == 1) || (width == 0)) {
1535 *typeNameRtrn = xkb_atom_intern(keymap->ctx, "ONE_LEVEL");
1538 else if (width == 2) {
1539 if (syms && xkb_keysym_is_lower(syms[0]) &&
1540 xkb_keysym_is_upper(syms[1])) {
1541 *typeNameRtrn = xkb_atom_intern(keymap->ctx, "ALPHABETIC");
1543 else if (syms && (xkb_keysym_is_keypad(syms[0]) ||
1544 xkb_keysym_is_keypad(syms[1]))) {
1545 *typeNameRtrn = xkb_atom_intern(keymap->ctx, "KEYPAD");
1549 *typeNameRtrn = xkb_atom_intern(keymap->ctx, "TWO_LEVEL");
1553 else if (width <= 4) {
1554 if (syms && xkb_keysym_is_lower(syms[0]) &&
1555 xkb_keysym_is_upper(syms[1]))
1556 if (xkb_keysym_is_lower(syms[2]) && xkb_keysym_is_upper(syms[3]))
1558 xkb_atom_intern(keymap->ctx, "FOUR_LEVEL_ALPHABETIC");
1560 *typeNameRtrn = xkb_atom_intern(keymap->ctx,
1561 "FOUR_LEVEL_SEMIALPHABETIC");
1563 else if (syms && (xkb_keysym_is_keypad(syms[0]) ||
1564 xkb_keysym_is_keypad(syms[1])))
1565 *typeNameRtrn = xkb_atom_intern(keymap->ctx, "FOUR_LEVEL_KEYPAD");
1567 *typeNameRtrn = xkb_atom_intern(keymap->ctx, "FOUR_LEVEL");
1568 /* XXX: why not set autoType here? */
1574 * Ensure the given KeyInfo is in a coherent state, i.e. no gaps between the
1575 * groups, and reduce to one group if all groups are identical anyway.
1578 PrepareKeyDef(KeyInfo *keyi)
1580 xkb_group_index_t i, lastGroup;
1581 const GroupInfo *group0;
1584 /* get highest group number */
1585 for (i = XKB_NUM_GROUPS - 1; i > 0; i--)
1586 if (keyi->groups[i].defined)
1593 group0 = &keyi->groups[0];
1595 /* If there are empty groups between non-empty ones fill them with data */
1596 /* from the first group. */
1597 /* We can make a wrong assumption here. But leaving gaps is worse. */
1598 for (i = lastGroup; i > 0; i--) {
1599 GroupInfo *groupi = &keyi->groups[i];
1601 if (groupi->defined)
1604 if (group0->defined & GROUP_FIELD_TYPE) {
1605 groupi->type = group0->type;
1606 groupi->defined |= GROUP_FIELD_TYPE;
1608 if ((group0->defined & GROUP_FIELD_ACTS) &&
1609 !darray_empty(group0->acts)) {
1610 darray_copy(groupi->acts, group0->acts);
1611 groupi->defined |= GROUP_FIELD_ACTS;
1613 if ((group0->defined & GROUP_FIELD_SYMS) &&
1614 !darray_empty(group0->syms)) {
1615 darray_copy(groupi->syms, group0->syms);
1616 darray_copy(groupi->symsMapIndex, group0->symsMapIndex);
1617 darray_copy(groupi->symsMapNumEntries, group0->symsMapNumEntries);
1618 groupi->defined |= GROUP_FIELD_SYMS;
1620 if (group0->defined)
1621 groupi->numLevels = group0->numLevels;
1624 /* If all groups are completely identical remove them all */
1625 /* exept the first one. */
1627 for (i = lastGroup; i > 0; i--) {
1628 GroupInfo *groupi = &keyi->groups[i];
1630 if (groupi->numLevels != group0->numLevels ||
1631 groupi->type != group0->type) {
1635 if (!darray_same(groupi->syms, group0->syms) &&
1636 (darray_empty(groupi->syms) || darray_empty(group0->syms) ||
1637 darray_size(groupi->syms) != darray_size(group0->syms) ||
1638 memcmp(darray_mem(groupi->syms, 0),
1639 darray_mem(group0->syms, 0),
1640 sizeof(xkb_keysym_t) * darray_size(group0->syms)))) {
1644 if (!darray_same(groupi->symsMapIndex, group0->symsMapIndex) &&
1645 (darray_empty(groupi->symsMapIndex) ||
1646 darray_empty(group0->symsMapIndex) ||
1647 memcmp(darray_mem(groupi->symsMapIndex, 0),
1648 darray_mem(group0->symsMapIndex, 0),
1649 group0->numLevels * sizeof(int)))) {
1653 if (!darray_same(groupi->symsMapNumEntries,
1654 group0->symsMapNumEntries) &&
1655 (darray_empty(groupi->symsMapNumEntries) ||
1656 darray_empty(group0->symsMapNumEntries) ||
1657 memcmp(darray_mem(groupi->symsMapNumEntries, 0),
1658 darray_mem(group0->symsMapNumEntries, 0),
1659 group0->numLevels * sizeof(unsigned int)))) {
1663 if (!darray_same(groupi->acts, group0->acts) &&
1664 (darray_empty(groupi->acts) || darray_empty(group0->acts) ||
1665 memcmp(darray_mem(groupi->acts, 0),
1666 darray_mem(group0->acts, 0),
1667 group0->numLevels * sizeof(union xkb_action)))) {
1674 for (i = lastGroup; i > 0; i--)
1675 ClearGroupInfo(&keyi->groups[i]);
1679 * Copy the KeyInfo into the keyboard description.
1681 * This function recurses.
1684 CopySymbolsDef(SymbolsInfo *info, KeyInfo *keyi,
1685 xkb_keycode_t start_from)
1687 struct xkb_keymap *keymap = info->keymap;
1689 struct xkb_key *key;
1690 unsigned int sizeSyms = 0;
1691 xkb_group_index_t i, nGroups;
1692 xkb_level_index_t width, tmp;
1693 struct xkb_key_type * type;
1694 bool haveActions, autoType, useAlias;
1695 unsigned types[XKB_NUM_GROUPS];
1696 unsigned int symIndex = 0;
1698 useAlias = (start_from == 0);
1700 key = FindNamedKey(keymap, keyi->name, useAlias, start_from);
1702 if (start_from == 0)
1703 log_vrb(info->keymap->ctx, 5,
1704 "Key %s not found in keycodes; Symbols ignored\n",
1705 LongKeyNameText(keyi->name));
1708 kc = XkbKeyGetKeycode(keymap, key);
1710 haveActions = false;
1712 for (i = nGroups = 0; i < XKB_NUM_GROUPS; i++) {
1713 GroupInfo *groupi = &keyi->groups[i];
1715 if (i + 1 > nGroups && groupi->defined)
1718 if (!darray_empty(groupi->acts))
1723 /* Assign the type to the key, if it is missing. */
1724 if (groupi->type == XKB_ATOM_NONE) {
1725 if (keyi->dfltType != XKB_ATOM_NONE)
1726 groupi->type = keyi->dfltType;
1727 else if (FindAutomaticType(keymap, groupi->numLevels,
1728 darray_mem(groupi->syms, 0),
1729 &groupi->type, &autoType)) { }
1731 log_vrb(info->keymap->ctx, 5,
1732 "No automatic type for %d symbols; "
1733 "Using %s for the %s key (keycode %d)\n",
1735 xkb_atom_text(keymap->ctx, groupi->type),
1736 LongKeyNameText(keyi->name), kc);
1739 if (FindNamedType(keymap, groupi->type, &types[i])) {
1740 if (!autoType || groupi->numLevels > 2)
1741 key->explicit_groups |= (1 << i);
1744 log_vrb(info->keymap->ctx, 3,
1745 "Type \"%s\" is not defined; "
1746 "Using default type for the %s key (keycode %d)\n",
1747 xkb_atom_text(keymap->ctx, groupi->type),
1748 LongKeyNameText(keyi->name), kc);
1750 * Index 0 is guaranteed to contain something, usually
1751 * ONE_LEVEL or at least some default one-level type.
1756 /* if the type specifies fewer levels than the key has, shrink the key */
1757 type = &keymap->types[types[i]];
1758 if (type->num_levels < groupi->numLevels) {
1759 log_vrb(info->keymap->ctx, 1,
1760 "Type \"%s\" has %d levels, but %s has %d symbols; "
1761 "Ignoring extra symbols\n",
1762 xkb_atom_text(keymap->ctx, type->name),
1764 LongKeyNameText(keyi->name),
1766 groupi->numLevels = type->num_levels;
1769 width = MAX3(width, groupi->numLevels, type->num_levels);
1770 sizeSyms += darray_size(groupi->syms);
1773 key->syms = calloc(sizeSyms, sizeof(*key->syms));
1774 key->num_groups = nGroups;
1776 key->sym_index = calloc(nGroups * width, sizeof(*key->sym_index));
1777 key->num_syms = calloc(nGroups * width, sizeof(*key->num_syms));
1780 key->actions = calloc(nGroups * width, sizeof(*key->actions));
1781 key->explicit |= EXPLICIT_INTERP;
1784 key->out_of_range_group_number = keyi->out_of_range_group_number;
1785 key->out_of_range_group_action = keyi->out_of_range_group_action;
1787 for (i = 0; i < nGroups; i++) {
1788 GroupInfo *groupi = &keyi->groups[i];
1790 /* assign kt_index[i] to the index of the type in map->types.
1791 * kt_index[i] may have been set by a previous run (if we have two
1792 * layouts specified). Let's not overwrite it with the ONE_LEVEL
1793 * default group if we dont even have keys for this group anyway.
1795 * FIXME: There should be a better fix for this.
1797 if (groupi->numLevels)
1798 key->kt_index[i] = types[i];
1800 if (!darray_empty(groupi->syms)) {
1801 /* fill key to "width" symbols*/
1802 for (tmp = 0; tmp < width; tmp++) {
1803 if (tmp < groupi->numLevels &&
1804 darray_item(groupi->symsMapNumEntries, tmp) != 0) {
1805 memcpy(&key->syms[symIndex],
1806 darray_mem(groupi->syms,
1807 darray_item(groupi->symsMapIndex, tmp)),
1808 darray_item(groupi->symsMapNumEntries, tmp) * sizeof(xkb_keysym_t));
1809 key->sym_index[(i * width) + tmp] = symIndex;
1810 key->num_syms[(i * width) + tmp] =
1811 darray_item(groupi->symsMapNumEntries, tmp);
1812 symIndex += key->num_syms[(i * width) + tmp];
1815 key->sym_index[(i * width) + tmp] = -1;
1816 key->num_syms[(i * width) + tmp] = 0;
1819 if (key->actions && !darray_empty(groupi->acts)) {
1820 if (tmp < groupi->numLevels)
1821 key->actions[tmp] = darray_item(groupi->acts, tmp);
1823 key->actions[tmp].type = ACTION_TYPE_NONE;
1829 if (keyi->defined & KEY_FIELD_VMODMAP) {
1830 key->vmodmap = keyi->vmodmap;
1831 key->explicit |= EXPLICIT_VMODMAP;
1834 if (keyi->repeat != KEY_REPEAT_UNDEFINED) {
1835 key->repeats = (keyi->repeat == KEY_REPEAT_YES);
1836 key->explicit |= EXPLICIT_REPEAT;
1839 /* do the same thing for the next key */
1840 CopySymbolsDef(info, keyi, kc + 1);
1845 CopyModMapDef(SymbolsInfo *info, ModMapEntry *entry)
1847 struct xkb_key *key;
1848 struct xkb_keymap *keymap = info->keymap;
1850 if (!entry->haveSymbol) {
1851 key = FindNamedKey(keymap, entry->u.keyName, true, 0);
1853 log_vrb(info->keymap->ctx, 5,
1854 "Key %s not found in keycodes; "
1855 "Modifier map entry for %s not updated\n",
1856 LongKeyNameText(entry->u.keyName),
1857 ModIndexText(entry->modifier));
1862 key = FindKeyForSymbol(keymap, entry->u.keySym);
1864 log_vrb(info->keymap->ctx, 5,
1865 "Key \"%s\" not found in symbol map; "
1866 "Modifier map entry for %s not updated\n",
1867 KeysymText(entry->u.keySym),
1868 ModIndexText(entry->modifier));
1873 key->modmap |= (1 << entry->modifier);
1878 * Handle the xkb_symbols section of an xkb file.
1880 * @param file The parsed xkb_symbols section of the xkb file.
1881 * @param keymap Handle to the keyboard description to store the symbols in.
1882 * @param merge Merge strategy (e.g. MERGE_OVERRIDE).
1885 CompileSymbols(XkbFile *file, struct xkb_keymap *keymap,
1886 enum merge_mode merge)
1888 xkb_group_index_t i;
1889 struct xkb_key *key;
1891 ActionsInfo *actions;
1895 actions = NewActionsInfo();
1899 InitSymbolsInfo(&info, keymap, file->id, actions);
1900 info.dflt.merge = merge;
1902 HandleSymbolsFile(&info, file, merge);
1904 if (darray_empty(info.keys))
1907 if (info.errorCount != 0)
1911 keymap->symbols_section_name = strdup(info.name);
1913 for (i = 0; i < XKB_NUM_GROUPS; i++)
1914 if (info.groupNames[i] != XKB_ATOM_NONE)
1915 keymap->group_names[i] = info.groupNames[i];
1918 darray_foreach(keyi, info.keys)
1919 PrepareKeyDef(keyi);
1922 darray_foreach(keyi, info.keys)
1923 if (!CopySymbolsDef(&info, keyi, 0))
1926 if (xkb_get_log_verbosity(keymap->ctx) > 3) {
1927 xkb_foreach_key(key, keymap) {
1928 if (key->name[0] == '\0')
1931 if (key->num_groups < 1)
1932 log_info(info.keymap->ctx,
1933 "No symbols defined for %s (keycode %d)\n",
1934 KeyNameText(key->name),
1935 XkbKeyGetKeycode(keymap, key));
1939 darray_foreach(mm, info.modMaps)
1940 if (!CopyModMapDef(&info, mm))
1943 ClearSymbolsInfo(&info);
1944 FreeActionsInfo(actions);
1948 FreeActionsInfo(actions);
1949 ClearSymbolsInfo(&info);