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(size_t) 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;
302 InitGroupInfo(&result);
304 if (into->numLevels >= from->numLevels) {
305 result.acts = into->acts;
306 result.numLevels = into->numLevels;
309 result.acts = from->acts;
310 result.numLevels = from->numLevels;
311 darray_resize(into->symsMapIndex, from->numLevels);
312 darray_resize0(into->symsMapNumEntries, from->numLevels);
313 for (i = into->numLevels; i < from->numLevels; i++)
314 darray_item(into->symsMapIndex, i) = -1;
317 if (darray_empty(result.acts) && (!darray_empty(into->acts) ||
318 !darray_empty(from->acts))) {
319 darray_resize0(result.acts, result.numLevels);
320 for (i = 0; i < result.numLevels; i++) {
321 union xkb_action *fromAct = NULL, *toAct = NULL;
323 if (!darray_empty(from->acts))
324 fromAct = &darray_item(from->acts, i);
326 if (!darray_empty(into->acts))
327 toAct = &darray_item(into->acts, i);
329 if (((fromAct == NULL) || (fromAct->type == ACTION_TYPE_NONE))
330 && (toAct != NULL)) {
331 darray_item(result.acts, i) = *toAct;
333 else if (((toAct == NULL) || (toAct->type == ACTION_TYPE_NONE))
334 && (fromAct != NULL)) {
335 darray_item(result.acts, i) = *fromAct;
338 union xkb_action *use, *ignore;
348 log_warn(info->keymap->ctx,
349 "Multiple actions for level %d/group %u on key %s; "
350 "Using %s, ignoring %s\n",
351 i + 1, group + 1, LongKeyNameText(key_name),
352 ActionTypeText(use->type),
353 ActionTypeText(ignore->type));
355 darray_item(result.acts, i) = *use;
360 for (i = 0; i < result.numLevels; i++) {
361 unsigned int fromSize = 0;
362 unsigned int toSize = 0;
364 if (!darray_empty(from->symsMapNumEntries) && i < from->numLevels)
365 fromSize = darray_item(from->symsMapNumEntries, i);
367 if (!darray_empty(into->symsMapNumEntries) && i < into->numLevels)
368 toSize = darray_item(into->symsMapNumEntries, i);
371 resultSize += toSize;
374 else if (toSize == 0 || clobber) {
375 resultSize += fromSize;
379 resultSize += toSize;
388 result.syms = from->syms;
389 darray_free(into->symsMapNumEntries);
390 darray_free(into->symsMapIndex);
391 into->symsMapNumEntries = from->symsMapNumEntries;
392 into->symsMapIndex = from->symsMapIndex;
393 darray_init(from->symsMapNumEntries);
394 darray_init(from->symsMapIndex);
397 else if (using == TO) {
398 result.syms = into->syms;
402 darray_resize0(result.syms, resultSize);
404 for (i = 0; i < result.numLevels; i++) {
405 enum key_group_selector use = NONE;
406 unsigned int fromSize = 0;
407 unsigned int toSize = 0;
409 if (i < from->numLevels)
410 fromSize = darray_item(from->symsMapNumEntries, i);
412 if (i < into->numLevels)
413 toSize = darray_item(into->symsMapNumEntries, i);
415 if (fromSize == 0 && toSize == 0) {
416 darray_item(into->symsMapIndex, i) = -1;
417 darray_item(into->symsMapNumEntries, i) = 0;
423 else if (toSize == 0 || clobber)
428 if (toSize && fromSize && report) {
429 log_info(info->keymap->ctx,
430 "Multiple symbols for group %u, level %d on key %s; "
431 "Using %s, ignoring %s\n",
432 group + 1, i + 1, LongKeyNameText(key_name),
433 (use == FROM ? "from" : "to"),
434 (use == FROM ? "to" : "from"));
438 memcpy(darray_mem(result.syms, cur_idx),
439 darray_mem(from->syms, darray_item(from->symsMapIndex, i)),
440 darray_item(from->symsMapNumEntries, i) * sizeof(xkb_keysym_t));
441 darray_item(into->symsMapIndex, i) = cur_idx;
442 darray_item(into->symsMapNumEntries, i) =
443 darray_item(from->symsMapNumEntries, i);
446 memcpy(darray_mem(result.syms, cur_idx),
447 darray_mem(into->syms, darray_item(into->symsMapIndex, i)),
448 darray_item(into->symsMapNumEntries, i) * sizeof(xkb_keysym_t));
449 darray_item(into->symsMapIndex, i) = cur_idx;
452 cur_idx += darray_item(into->symsMapNumEntries, i);
456 into->numLevels = result.numLevels;
458 if (!darray_same(result.acts, into->acts))
459 darray_free(into->acts);
460 if (!darray_same(result.acts, from->acts))
461 darray_free(from->acts);
462 into->acts = result.acts;
463 into->defined |= GROUP_FIELD_ACTS;
464 darray_init(from->acts);
465 from->defined &= ~GROUP_FIELD_ACTS;
467 if (!darray_same(result.syms, into->syms))
468 darray_free(into->syms);
469 if (!darray_same(result.syms, from->syms))
470 darray_free(from->syms);
471 into->syms = result.syms;
472 if (darray_empty(into->syms))
473 into->defined &= ~GROUP_FIELD_SYMS;
475 into->defined |= GROUP_FIELD_SYMS;
476 darray_init(from->syms);
477 from->defined &= ~GROUP_FIELD_SYMS;
479 darray_free(from->symsMapIndex);
480 darray_free(from->symsMapNumEntries);
486 UseNewKeyField(enum key_field field, enum key_field old, enum key_field new,
487 bool clobber, bool report, enum key_field *collide)
490 return (new & field);
504 /* Merge @from into @into, where both contain info for the same key. */
506 MergeKeys(SymbolsInfo *info, KeyInfo *into, KeyInfo *from)
509 enum key_field collide = 0;
510 bool clobber, report;
511 int verbosity = xkb_get_log_verbosity(info->keymap->ctx);
513 /* Forget about @into; just copy @from as-is. */
514 if (from->merge == MERGE_REPLACE) {
515 for (i = 0; i < XKB_NUM_GROUPS; i++)
516 if (into->groups[i].numLevels != 0)
517 ClearGroupInfo(&into->groups[i]);
519 InitKeyInfo(from, info->file_id);
523 clobber = (from->merge != MERGE_AUGMENT);
524 report = (verbosity > 9 ||
525 (into->file_id == from->file_id && verbosity > 0));
527 /* Start looking into the key groups. */
528 for (i = 0; i < XKB_NUM_GROUPS; i++) {
529 GroupInfo *into_group = &into->groups[i];
530 GroupInfo *from_group = &from->groups[i];
532 /* Has any interesting symbols/actions? */
533 if (from_group->numLevels > 0) {
534 if (into_group->numLevels == 0) {
535 /* Easy case: the group in @into is empty. Just copy. */
537 into_group->numLevels = from_group->numLevels;
538 into_group->syms = from_group->syms;
539 into_group->symsMapIndex = from_group->symsMapIndex;
540 into_group->symsMapNumEntries = from_group->symsMapNumEntries;
541 into_group->acts = from_group->acts;
542 into_group->defined |= (from_group->defined &
543 (GROUP_FIELD_SYMS | GROUP_FIELD_ACTS));
545 from_group->numLevels = 0;
546 darray_init(from_group->syms);
547 darray_init(from_group->symsMapIndex);
548 darray_init(from_group->symsMapNumEntries);
549 darray_init(from_group->acts);
550 from_group->defined &= ~(GROUP_FIELD_SYMS | GROUP_FIELD_ACTS);
553 /* Hard case; both groups are non-empty. Merge. */
554 MergeGroups(info, into_group, from_group, clobber,
555 report, i, into->name);
559 if (from_group->type != XKB_ATOM_NONE) {
560 if (into_group->type != XKB_ATOM_NONE && report &&
561 into_group->type != from_group->type) {
562 xkb_atom_t use, ignore;
564 use = (clobber ? from_group->type : into_group->type);
565 ignore = (clobber ? into_group->type : from_group->type);
567 log_warn(info->keymap->ctx,
568 "Multiple definitions for group %d type of key %s; "
569 "Using %s, ignoring %s\n",
570 i + 1, LongKeyNameText(into->name),
571 xkb_atom_text(info->keymap->ctx, use),
572 xkb_atom_text(info->keymap->ctx, ignore));
575 if (clobber || into_group->type == XKB_ATOM_NONE)
576 into_group->type = from_group->type;
580 if (UseNewKeyField(KEY_FIELD_VMODMAP, into->defined, from->defined,
581 clobber, report, &collide)) {
582 into->vmodmap = from->vmodmap;
583 into->defined |= KEY_FIELD_VMODMAP;
585 if (UseNewKeyField(KEY_FIELD_REPEAT, into->defined, from->defined,
586 clobber, report, &collide)) {
587 into->repeat = from->repeat;
588 into->defined |= KEY_FIELD_REPEAT;
590 if (UseNewKeyField(KEY_FIELD_TYPE_DFLT, into->defined, from->defined,
591 clobber, report, &collide)) {
592 into->dfltType = from->dfltType;
593 into->defined |= KEY_FIELD_TYPE_DFLT;
595 if (UseNewKeyField(KEY_FIELD_GROUPINFO, into->defined, from->defined,
596 clobber, report, &collide)) {
597 into->out_of_range_group_action = from->out_of_range_group_action;
598 into->out_of_range_group_number = from->out_of_range_group_number;
599 into->defined |= KEY_FIELD_GROUPINFO;
603 log_warn(info->keymap->ctx,
604 "Symbol map for key %s redefined; "
605 "Using %s definition for conflicting fields\n",
606 LongKeyNameText(into->name),
607 (clobber ? "first" : "last"));
613 AddKeySymbols(SymbolsInfo *info, KeyInfo *keyi)
615 unsigned long real_name;
618 darray_foreach(iter, info->keys)
619 if (iter->name == keyi->name)
620 return MergeKeys(info, iter, keyi);
622 if (FindKeyNameForAlias(info->keymap, keyi->name, &real_name))
623 darray_foreach(iter, info->keys)
624 if (iter->name == real_name)
625 return MergeKeys(info, iter, keyi);
627 darray_resize0(info->keys, darray_size(info->keys) + 1);
628 new = &darray_item(info->keys, darray_size(info->keys) - 1);
629 return CopyKeyInfo(keyi, new, true);
633 AddModMapEntry(SymbolsInfo * info, ModMapEntry * new)
638 clobber = (new->merge != MERGE_AUGMENT);
639 darray_foreach(mm, info->modMaps) {
640 if (new->haveSymbol && mm->haveSymbol
641 && (new->u.keySym == mm->u.keySym)) {
642 unsigned use, ignore;
643 if (mm->modifier != new->modifier) {
646 ignore = mm->modifier;
650 ignore = new->modifier;
652 log_err(info->keymap->ctx,
653 "%s added to symbol map for multiple modifiers; "
654 "Using %s, ignoring %s.\n",
655 KeysymText(new->u.keySym), ModIndexText(use),
656 ModIndexText(ignore));
661 if ((!new->haveSymbol) && (!mm->haveSymbol) &&
662 (new->u.keyName == mm->u.keyName)) {
663 unsigned use, ignore;
664 if (mm->modifier != new->modifier) {
667 ignore = mm->modifier;
671 ignore = new->modifier;
673 log_err(info->keymap->ctx,
674 "Key %s added to map for multiple modifiers; "
675 "Using %s, ignoring %s.\n",
676 LongKeyNameText(new->u.keyName), ModIndexText(use),
677 ModIndexText(ignore));
684 darray_append(info->modMaps, *new);
688 /***====================================================================***/
691 MergeIncludedSymbols(SymbolsInfo *into, SymbolsInfo *from,
692 enum merge_mode merge)
698 if (from->errorCount > 0) {
699 into->errorCount += from->errorCount;
702 if (into->name == NULL) {
703 into->name = from->name;
706 for (i = 0; i < XKB_NUM_GROUPS; i++) {
707 if (from->groupNames[i] != XKB_ATOM_NONE) {
708 if ((merge != MERGE_AUGMENT) ||
709 (into->groupNames[i] == XKB_ATOM_NONE))
710 into->groupNames[i] = from->groupNames[i];
714 darray_foreach(keyi, from->keys) {
715 merge = (merge == MERGE_DEFAULT ? keyi->merge : merge);
716 if (!AddKeySymbols(into, keyi))
720 darray_foreach(mm, from->modMaps) {
721 mm->merge = (merge == MERGE_DEFAULT ? mm->merge : merge);
722 if (!AddModMapEntry(into, mm))
728 HandleSymbolsFile(SymbolsInfo *info, XkbFile *file, enum merge_mode merge);
731 HandleIncludeSymbols(SymbolsInfo *info, IncludeStmt *stmt)
733 enum merge_mode merge = MERGE_DEFAULT;
735 SymbolsInfo included, next_incl;
737 InitSymbolsInfo(&included, info->keymap, info->file_id, info->actions);
740 included.name = stmt->stmt;
744 for (; stmt; stmt = stmt->next_incl) {
745 if (!ProcessIncludeFile(info->keymap->ctx, stmt, FILE_TYPE_SYMBOLS,
747 info->errorCount += 10;
748 ClearSymbolsInfo(&included);
752 InitSymbolsInfo(&next_incl, info->keymap, rtrn->id, info->actions);
753 next_incl.merge = next_incl.dflt.merge = MERGE_OVERRIDE;
755 next_incl.explicit_group = atoi(stmt->modifier) - 1;
757 next_incl.explicit_group = info->explicit_group;
759 HandleSymbolsFile(&next_incl, rtrn, MERGE_OVERRIDE);
761 MergeIncludedSymbols(&included, &next_incl, merge);
763 ClearSymbolsInfo(&next_incl);
767 MergeIncludedSymbols(info, &included, merge);
768 ClearSymbolsInfo(&included);
770 return (info->errorCount == 0);
777 GetGroupIndex(SymbolsInfo *info, KeyInfo *keyi, ExprDef *arrayNdx,
778 unsigned what, xkb_group_index_t *ndx_rtrn)
780 const char *name = (what == SYMBOLS ? "symbols" : "actions");
782 if (arrayNdx == NULL) {
784 enum group_field field = (what == SYMBOLS ?
785 GROUP_FIELD_SYMS : GROUP_FIELD_ACTS);
787 for (i = 0; i < XKB_NUM_GROUPS; i++) {
788 if (!(keyi->groups[i].defined & field)) {
794 log_err(info->keymap->ctx,
795 "Too many groups of %s for key %s (max %u); "
796 "Ignoring %s defined for extra groups\n",
797 name, LongKeyNameText(keyi->name), XKB_NUM_GROUPS + 1, name);
801 if (!ExprResolveGroup(info->keymap->ctx, arrayNdx, ndx_rtrn)) {
802 log_err(info->keymap->ctx,
803 "Illegal group index for %s of key %s\n"
804 "Definition with non-integer array index ignored\n",
805 name, LongKeyNameText(keyi->name));
814 LookupKeysym(const char *str, xkb_keysym_t *sym_rtrn)
818 if (!str || istreq(str, "any") || istreq(str, "nosymbol")) {
819 *sym_rtrn = XKB_KEY_NoSymbol;
823 if (istreq(str, "none") || istreq(str, "voidsymbol")) {
824 *sym_rtrn = XKB_KEY_VoidSymbol;
828 sym = xkb_keysym_from_name(str);
829 if (sym != XKB_KEY_NoSymbol) {
838 AddSymbolsToKey(SymbolsInfo *info, KeyInfo *keyi, ExprDef *arrayNdx,
841 xkb_group_index_t ndx;
844 xkb_level_index_t nLevels;
848 if (!GetGroupIndex(info, keyi, arrayNdx, SYMBOLS, &ndx))
851 groupi = &keyi->groups[ndx];
854 groupi->defined |= GROUP_FIELD_SYMS;
858 if (value->op != EXPR_KEYSYM_LIST) {
859 log_err(info->keymap->ctx,
860 "Expected a list of symbols, found %s; "
861 "Ignoring symbols for group %u of %s\n",
862 expr_op_type_to_string(value->op), ndx + 1,
863 LongKeyNameText(keyi->name));
867 if (!darray_empty(groupi->syms)) {
868 log_err(info->keymap->ctx,
869 "Symbols for key %s, group %u already defined; "
870 "Ignoring duplicate definition\n",
871 LongKeyNameText(keyi->name), ndx + 1);
875 nSyms = darray_size(value->value.list.syms);
876 nLevels = darray_size(value->value.list.symsMapIndex);
878 if ((groupi->numLevels < nSyms || darray_empty(groupi->syms))) {
879 if (!ResizeGroupInfo(groupi, nLevels, nSyms, false)) {
880 log_wsgo(info->keymap->ctx,
881 "Could not resize group %u of key %s to contain %zu levels; "
883 ndx + 1, LongKeyNameText(keyi->name), nSyms);
888 groupi->defined |= GROUP_FIELD_SYMS;
890 for (i = 0; i < nLevels; i++) {
891 darray_item(groupi->symsMapIndex, i) =
892 darray_item(value->value.list.symsMapIndex, i);
893 darray_item(groupi->symsMapNumEntries, i) =
894 darray_item(value->value.list.symsNumEntries, i);
896 for (j = 0; j < darray_item(groupi->symsMapNumEntries, i); j++) {
897 /* FIXME: What's abort() doing here? */
898 if (darray_item(groupi->symsMapIndex, i) + j >= nSyms)
901 if (!LookupKeysym(darray_item(value->value.list.syms,
902 darray_item(value->value.list.symsMapIndex, i) + j),
903 &darray_item(groupi->syms,
904 darray_item(groupi->symsMapIndex, i) + j))) {
905 log_warn(info->keymap->ctx,
906 "Could not resolve keysym %s for key %s, group %u (%s), level %zu\n",
907 darray_item(value->value.list.syms, i),
908 LongKeyNameText(keyi->name),
910 xkb_atom_text(info->keymap->ctx,
911 info->groupNames[ndx]),
915 darray_item(groupi->syms,
916 darray_item(groupi->symsMapIndex, i) + j) = XKB_KEY_NoSymbol;
918 darray_item(groupi->symsMapIndex, i) = -1;
919 darray_item(groupi->symsMapNumEntries, i) = 0;
923 if (darray_item(groupi->symsMapNumEntries, i) == 1 &&
924 darray_item(groupi->syms,
925 darray_item(groupi->symsMapIndex, i) + j) == XKB_KEY_NoSymbol) {
926 darray_item(groupi->symsMapIndex, i) = -1;
927 darray_item(groupi->symsMapNumEntries, i) = 0;
932 for (j = groupi->numLevels - 1;
933 j >= 0 && darray_item(groupi->symsMapNumEntries, j) == 0; j--)
940 AddActionsToKey(SymbolsInfo *info, KeyInfo *keyi, ExprDef *arrayNdx,
944 xkb_group_index_t ndx;
948 union xkb_action *toAct;
950 if (!GetGroupIndex(info, keyi, arrayNdx, ACTIONS, &ndx))
953 groupi = &keyi->groups[ndx];
956 groupi->defined |= GROUP_FIELD_ACTS;
960 if (value->op != EXPR_ACTION_LIST) {
961 log_wsgo(info->keymap->ctx,
962 "Bad expression type (%d) for action list value; "
963 "Ignoring actions for group %u of %s\n",
964 value->op, ndx, LongKeyNameText(keyi->name));
968 if (!darray_empty(groupi->acts)) {
969 log_wsgo(info->keymap->ctx,
970 "Actions for key %s, group %u already defined\n",
971 LongKeyNameText(keyi->name), ndx);
975 for (nActs = 0, act = value->value.child; act != NULL; nActs++) {
976 act = (ExprDef *) act->common.next;
980 log_wsgo(info->keymap->ctx,
981 "Action list but not actions in AddActionsToKey\n");
985 if ((groupi->numLevels < nActs || darray_empty(groupi->acts))) {
986 if (!ResizeGroupInfo(&keyi->groups[ndx], nActs, nActs, true)) {
987 log_wsgo(info->keymap->ctx,
988 "Could not resize group %u of key %s; "
990 ndx, LongKeyNameText(keyi->name));
995 groupi->defined |= GROUP_FIELD_ACTS;
997 toAct = darray_mem(groupi->acts, 0);
998 act = value->value.child;
999 for (i = 0; i < nActs; i++, toAct++) {
1000 if (!HandleActionDef(act, info->keymap, toAct, info->actions)) {
1001 log_err(info->keymap->ctx,
1002 "Illegal action definition for %s; "
1003 "Action for group %u/level %zu ignored\n",
1004 LongKeyNameText(keyi->name), ndx + 1, i + 1);
1006 act = (ExprDef *) act->common.next;
1012 static const LookupEntry repeatEntries[] = {
1013 { "true", KEY_REPEAT_YES },
1014 { "yes", KEY_REPEAT_YES },
1015 { "on", KEY_REPEAT_YES },
1016 { "false", KEY_REPEAT_NO },
1017 { "no", KEY_REPEAT_NO },
1018 { "off", KEY_REPEAT_NO },
1019 { "default", KEY_REPEAT_UNDEFINED },
1024 SetSymbolsField(SymbolsInfo *info, KeyInfo *keyi, const char *field,
1025 ExprDef *arrayNdx, ExprDef *value)
1028 struct xkb_context *ctx = info->keymap->ctx;
1030 if (istreq(field, "type")) {
1031 xkb_group_index_t ndx;
1034 if (!ExprResolveString(ctx, value, &val))
1036 "The type field of a key symbol map must be a string; "
1037 "Ignoring illegal type definition\n");
1039 if (arrayNdx == NULL) {
1040 keyi->dfltType = val;
1041 keyi->defined |= KEY_FIELD_TYPE_DFLT;
1043 else if (!ExprResolveGroup(ctx, arrayNdx, &ndx)) {
1045 "Illegal group index for type of key %s; "
1046 "Definition with non-integer array index ignored\n",
1047 LongKeyNameText(keyi->name));
1052 keyi->groups[ndx].type = val;
1053 keyi->groups[ndx].defined |= GROUP_FIELD_TYPE;
1056 else if (istreq(field, "symbols"))
1057 return AddSymbolsToKey(info, keyi, arrayNdx, value);
1058 else if (istreq(field, "actions"))
1059 return AddActionsToKey(info, keyi, arrayNdx, value);
1060 else if (istreq(field, "vmods") ||
1061 istreq(field, "virtualmods") ||
1062 istreq(field, "virtualmodifiers")) {
1063 xkb_mod_mask_t mask;
1065 ok = ExprResolveVModMask(info->keymap, value, &mask);
1067 keyi->vmodmap = (mask >> XKB_NUM_CORE_MODS) & 0xffff;
1068 keyi->defined |= KEY_FIELD_VMODMAP;
1071 log_err(info->keymap->ctx,
1072 "Expected a virtual modifier mask, found %s; "
1073 "Ignoring virtual modifiers definition for key %s\n",
1074 expr_op_type_to_string(value->op),
1075 LongKeyNameText(keyi->name));
1078 else if (istreq(field, "locking") ||
1079 istreq(field, "lock") ||
1080 istreq(field, "locks")) {
1081 log_err(info->keymap->ctx,
1082 "Key behaviors not supported; "
1083 "Ignoring locking specification for key %s\n",
1084 LongKeyNameText(keyi->name));
1086 else if (istreq(field, "radiogroup") ||
1087 istreq(field, "permanentradiogroup") ||
1088 istreq(field, "allownone")) {
1089 log_err(info->keymap->ctx,
1090 "Radio groups not supported; "
1091 "Ignoring radio group specification for key %s\n",
1092 LongKeyNameText(keyi->name));
1094 else if (istreq_prefix("overlay", field) ||
1095 istreq_prefix("permanentoverlay", field)) {
1096 log_err(info->keymap->ctx,
1097 "Overlays not supported; "
1098 "Ignoring overlay specification for key %s\n",
1099 LongKeyNameText(keyi->name));
1101 else if (istreq(field, "repeating") ||
1102 istreq(field, "repeats") ||
1103 istreq(field, "repeat")) {
1106 ok = ExprResolveEnum(ctx, value, &val, repeatEntries);
1108 log_err(info->keymap->ctx,
1109 "Illegal repeat setting for %s; "
1110 "Non-boolean repeat setting ignored\n",
1111 LongKeyNameText(keyi->name));
1115 keyi->defined |= KEY_FIELD_REPEAT;
1117 else if (istreq(field, "groupswrap") ||
1118 istreq(field, "wrapgroups")) {
1121 if (!ExprResolveBoolean(ctx, value, &set)) {
1122 log_err(info->keymap->ctx,
1123 "Illegal groupsWrap setting for %s; "
1124 "Non-boolean value ignored\n",
1125 LongKeyNameText(keyi->name));
1130 keyi->out_of_range_group_action = RANGE_WRAP;
1132 keyi->out_of_range_group_action = RANGE_SATURATE;
1134 keyi->defined |= KEY_FIELD_GROUPINFO;
1136 else if (istreq(field, "groupsclamp") ||
1137 istreq(field, "clampgroups")) {
1140 if (!ExprResolveBoolean(ctx, value, &set)) {
1141 log_err(info->keymap->ctx,
1142 "Illegal groupsClamp setting for %s; "
1143 "Non-boolean value ignored\n",
1144 LongKeyNameText(keyi->name));
1149 keyi->out_of_range_group_action = RANGE_SATURATE;
1151 keyi->out_of_range_group_action = RANGE_WRAP;
1153 keyi->defined |= KEY_FIELD_GROUPINFO;
1155 else if (istreq(field, "groupsredirect") ||
1156 istreq(field, "redirectgroups")) {
1157 xkb_group_index_t grp;
1159 if (!ExprResolveGroup(ctx, value, &grp)) {
1160 log_err(info->keymap->ctx,
1161 "Illegal group index for redirect of key %s; "
1162 "Definition with non-integer group ignored\n",
1163 LongKeyNameText(keyi->name));
1167 keyi->out_of_range_group_action = RANGE_REDIRECT;
1168 keyi->out_of_range_group_number = grp - 1;
1169 keyi->defined |= KEY_FIELD_GROUPINFO;
1172 log_err(info->keymap->ctx,
1173 "Unknown field %s in a symbol interpretation; "
1174 "Definition ignored\n",
1183 SetGroupName(SymbolsInfo *info, ExprDef *arrayNdx, ExprDef *value)
1185 xkb_group_index_t grp;
1189 log_vrb(info->keymap->ctx, 1,
1190 "You must specify an index when specifying a group name; "
1191 "Group name definition without array subscript ignored\n");
1195 if (!ExprResolveGroup(info->keymap->ctx, arrayNdx, &grp)) {
1196 log_err(info->keymap->ctx,
1197 "Illegal index in group name definition; "
1198 "Definition with non-integer array index ignored\n");
1202 if (!ExprResolveString(info->keymap->ctx, value, &name)) {
1203 log_err(info->keymap->ctx,
1204 "Group name must be a string; "
1205 "Illegal name for group %d ignored\n", grp);
1209 info->groupNames[grp - 1 + info->explicit_group] = name;
1214 HandleSymbolsVar(SymbolsInfo *info, VarDef *stmt)
1216 const char *elem, *field;
1220 if (ExprResolveLhs(info->keymap->ctx, stmt->name, &elem, &field,
1222 return 0; /* internal error, already reported */
1223 if (elem && istreq(elem, "key")) {
1224 ret = SetSymbolsField(info, &info->dflt, field, arrayNdx,
1227 else if (!elem && (istreq(field, "name") ||
1228 istreq(field, "groupname"))) {
1229 ret = SetGroupName(info, arrayNdx, stmt->value);
1231 else if (!elem && (istreq(field, "groupswrap") ||
1232 istreq(field, "wrapgroups"))) {
1233 log_err(info->keymap->ctx,
1234 "Global \"groupswrap\" not supported; Ignored\n");
1237 else if (!elem && (istreq(field, "groupsclamp") ||
1238 istreq(field, "clampgroups"))) {
1239 log_err(info->keymap->ctx,
1240 "Global \"groupsclamp\" not supported; Ignored\n");
1243 else if (!elem && (istreq(field, "groupsredirect") ||
1244 istreq(field, "redirectgroups"))) {
1245 log_err(info->keymap->ctx,
1246 "Global \"groupsredirect\" not supported; Ignored\n");
1249 else if (!elem && istreq(field, "allownone")) {
1250 log_err(info->keymap->ctx,
1251 "Radio groups not supported; "
1252 "Ignoring \"allownone\" specification\n");
1256 ret = SetActionField(info->keymap, elem, field, arrayNdx, stmt->value,
1264 HandleSymbolsBody(SymbolsInfo *info, VarDef *def, KeyInfo *keyi)
1267 const char *elem, *field;
1270 for (; def; def = (VarDef *) def->common.next) {
1271 if (def->name && def->name->op == EXPR_FIELD_REF) {
1272 ok = HandleSymbolsVar(info, def);
1277 if (!def->value || def->value->op == EXPR_KEYSYM_LIST)
1284 ok = ExprResolveLhs(info->keymap->ctx, def->name, &elem, &field,
1289 ok = SetSymbolsField(info, keyi, field, arrayNdx, def->value);
1296 SetExplicitGroup(SymbolsInfo *info, KeyInfo *keyi)
1298 xkb_group_index_t i;
1300 if (info->explicit_group == 0)
1303 for (i = 1; i < XKB_NUM_GROUPS; i++) {
1304 if (keyi->groups[i].defined) {
1305 log_warn(info->keymap->ctx,
1306 "For the map %s an explicit group specified, "
1307 "but key %s has more than one group defined; "
1308 "All groups except first one will be ignored\n",
1309 info->name, LongKeyNameText(keyi->name));
1313 if (i < XKB_NUM_GROUPS)
1314 for (i = 1; i < XKB_NUM_GROUPS; i++)
1315 ClearGroupInfo(&keyi->groups[i]);
1317 keyi->groups[info->explicit_group] = keyi->groups[0];
1318 InitGroupInfo(&keyi->groups[0]);
1323 HandleSymbolsDef(SymbolsInfo *info, SymbolsDef *stmt)
1327 InitKeyInfo(&keyi, info->file_id);
1328 CopyKeyInfo(&info->dflt, &keyi, false);
1329 keyi.merge = stmt->merge;
1330 keyi.name = KeyNameToLong(stmt->keyName);
1331 if (!HandleSymbolsBody(info, (VarDef *) stmt->symbols, &keyi)) {
1336 if (!SetExplicitGroup(info, &keyi)) {
1341 if (!AddKeySymbols(info, &keyi)) {
1349 HandleModMapDef(SymbolsInfo *info, ModMapDef *def)
1353 xkb_mod_index_t ndx;
1355 struct xkb_context *ctx = info->keymap->ctx;
1357 if (!LookupModIndex(ctx, NULL, def->modifier, EXPR_TYPE_INT, &ndx)) {
1358 log_err(info->keymap->ctx,
1359 "Illegal modifier map definition; "
1360 "Ignoring map for non-modifier \"%s\"\n",
1361 xkb_atom_text(ctx, def->modifier));
1368 for (key = def->keys; key != NULL; key = (ExprDef *) key->common.next) {
1371 if (key->op == EXPR_VALUE && key->value_type == EXPR_TYPE_KEYNAME) {
1372 tmp.haveSymbol = false;
1373 tmp.u.keyName = KeyNameToLong(key->value.keyName);
1375 else if (ExprResolveKeySym(ctx, key, &sym)) {
1376 tmp.haveSymbol = true;
1380 log_err(info->keymap->ctx,
1381 "Modmap entries may contain only key names or keysyms; "
1382 "Illegal definition for %s modifier ignored\n",
1383 ModIndexText(tmp.modifier));
1387 ok = AddModMapEntry(info, &tmp) && ok;
1393 HandleSymbolsFile(SymbolsInfo *info, XkbFile *file, enum merge_mode merge)
1399 info->name = strdup_safe(file->name);
1402 for (stmt = file->defs; stmt; stmt = stmt->next) {
1403 switch (stmt->type) {
1405 ok = HandleIncludeSymbols(info, (IncludeStmt *) stmt);
1408 ok = HandleSymbolsDef(info, (SymbolsDef *) stmt);
1411 ok = HandleSymbolsVar(info, (VarDef *) stmt);
1414 ok = HandleVModDef((VModDef *) stmt, info->keymap, merge,
1418 ok = HandleModMapDef(info, (ModMapDef *) stmt);
1421 log_err(info->keymap->ctx,
1422 "Interpretation files may not include other types; "
1423 "Ignoring %s\n", stmt_type_to_string(stmt->type));
1431 if (info->errorCount > 10) {
1432 log_err(info->keymap->ctx, "Abandoning symbols file \"%s\"\n",
1440 * Given a keysym @sym, return a key which generates it, or NULL.
1441 * This is used for example in a modifier map definition, such as:
1442 * modifier_map Lock { Caps_Lock };
1443 * where we want to add the Lock modifier to the modmap of the key
1444 * which matches the keysym Caps_Lock.
1445 * Since there can be many keys which generates the keysym, the key
1446 * is chosen first by lowest group in which the keysym appears, than
1447 * by lowest level and than by lowest key code.
1449 static struct xkb_key *
1450 FindKeyForSymbol(struct xkb_keymap *keymap, xkb_keysym_t sym)
1452 struct xkb_key *key, *ret = NULL;
1453 xkb_group_index_t group, min_group = UINT32_MAX;
1454 xkb_level_index_t level, min_level = UINT16_MAX;
1456 xkb_foreach_key(key, keymap) {
1457 for (group = 0; group < key->num_groups; group++) {
1458 for (level = 0; level < XkbKeyGroupWidth(keymap, key, group);
1460 if (XkbKeyNumSyms(key, group, level) != 1 ||
1461 (XkbKeySymEntry(key, group, level))[0] != sym)
1465 * If the keysym was found in a group or level > 0, we must
1466 * keep looking since we might find a key in which the keysym
1467 * is in a lower group or level.
1469 if (group < min_group ||
1470 (group == min_group && level < min_level)) {
1472 if (group == 0 && level == 0) {
1488 * Find the given name in the keymap->map->types and return its index.
1490 * @param name The name to search for.
1491 * @param type_rtrn Set to the index of the name if found.
1493 * @return true if found, false otherwise.
1496 FindNamedType(struct xkb_keymap *keymap, xkb_atom_t name, unsigned *type_rtrn)
1500 for (i = 0; i < keymap->num_types; i++) {
1501 if (keymap->types[i].name == name) {
1511 * Assign a type to the given sym and return the Atom for the type assigned.
1514 * - ONE_LEVEL for width 0/1
1515 * - ALPHABETIC for 2 shift levels, with lower/upercase
1516 * - KEYPAD for keypad keys.
1517 * - TWO_LEVEL for other 2 shift level keys.
1518 * and the same for four level keys.
1520 * @param width Number of sysms in syms.
1521 * @param syms The keysyms for the given key (must be size width).
1522 * @param typeNameRtrn Set to the Atom of the type name.
1524 * @returns true if a type could be found, false otherwise.
1526 * FIXME: I need to take the KeyInfo so I can look at symsMapIndex and
1527 * all that fun stuff rather than just assuming there's always one
1531 FindAutomaticType(struct xkb_keymap *keymap, xkb_level_index_t width,
1532 const xkb_keysym_t *syms, xkb_atom_t *typeNameRtrn,
1536 if ((width == 1) || (width == 0)) {
1537 *typeNameRtrn = xkb_atom_intern(keymap->ctx, "ONE_LEVEL");
1540 else if (width == 2) {
1541 if (syms && xkb_keysym_is_lower(syms[0]) &&
1542 xkb_keysym_is_upper(syms[1])) {
1543 *typeNameRtrn = xkb_atom_intern(keymap->ctx, "ALPHABETIC");
1545 else if (syms && (xkb_keysym_is_keypad(syms[0]) ||
1546 xkb_keysym_is_keypad(syms[1]))) {
1547 *typeNameRtrn = xkb_atom_intern(keymap->ctx, "KEYPAD");
1551 *typeNameRtrn = xkb_atom_intern(keymap->ctx, "TWO_LEVEL");
1555 else if (width <= 4) {
1556 if (syms && xkb_keysym_is_lower(syms[0]) &&
1557 xkb_keysym_is_upper(syms[1]))
1558 if (xkb_keysym_is_lower(syms[2]) && xkb_keysym_is_upper(syms[3]))
1560 xkb_atom_intern(keymap->ctx, "FOUR_LEVEL_ALPHABETIC");
1562 *typeNameRtrn = xkb_atom_intern(keymap->ctx,
1563 "FOUR_LEVEL_SEMIALPHABETIC");
1565 else if (syms && (xkb_keysym_is_keypad(syms[0]) ||
1566 xkb_keysym_is_keypad(syms[1])))
1567 *typeNameRtrn = xkb_atom_intern(keymap->ctx, "FOUR_LEVEL_KEYPAD");
1569 *typeNameRtrn = xkb_atom_intern(keymap->ctx, "FOUR_LEVEL");
1570 /* XXX: why not set autoType here? */
1576 * Ensure the given KeyInfo is in a coherent state, i.e. no gaps between the
1577 * groups, and reduce to one group if all groups are identical anyway.
1580 PrepareKeyDef(KeyInfo *keyi)
1582 xkb_group_index_t i, lastGroup;
1583 const GroupInfo *group0;
1586 /* get highest group number */
1587 for (i = XKB_NUM_GROUPS - 1; i > 0; i--)
1588 if (keyi->groups[i].defined)
1595 group0 = &keyi->groups[0];
1597 /* If there are empty groups between non-empty ones fill them with data */
1598 /* from the first group. */
1599 /* We can make a wrong assumption here. But leaving gaps is worse. */
1600 for (i = lastGroup; i > 0; i--) {
1601 GroupInfo *groupi = &keyi->groups[i];
1603 if (groupi->defined)
1606 if (group0->defined & GROUP_FIELD_TYPE) {
1607 groupi->type = group0->type;
1608 groupi->defined |= GROUP_FIELD_TYPE;
1610 if ((group0->defined & GROUP_FIELD_ACTS) &&
1611 !darray_empty(group0->acts)) {
1612 darray_copy(groupi->acts, group0->acts);
1613 groupi->defined |= GROUP_FIELD_ACTS;
1615 if ((group0->defined & GROUP_FIELD_SYMS) &&
1616 !darray_empty(group0->syms)) {
1617 darray_copy(groupi->syms, group0->syms);
1618 darray_copy(groupi->symsMapIndex, group0->symsMapIndex);
1619 darray_copy(groupi->symsMapNumEntries, group0->symsMapNumEntries);
1620 groupi->defined |= GROUP_FIELD_SYMS;
1622 if (group0->defined)
1623 groupi->numLevels = group0->numLevels;
1626 /* If all groups are completely identical remove them all */
1627 /* exept the first one. */
1629 for (i = lastGroup; i > 0; i--) {
1630 GroupInfo *groupi = &keyi->groups[i];
1632 if (groupi->numLevels != group0->numLevels ||
1633 groupi->type != group0->type) {
1637 if (!darray_same(groupi->syms, group0->syms) &&
1638 (darray_empty(groupi->syms) || darray_empty(group0->syms) ||
1639 darray_size(groupi->syms) != darray_size(group0->syms) ||
1640 memcmp(darray_mem(groupi->syms, 0),
1641 darray_mem(group0->syms, 0),
1642 sizeof(xkb_keysym_t) * darray_size(group0->syms)))) {
1646 if (!darray_same(groupi->symsMapIndex, group0->symsMapIndex) &&
1647 (darray_empty(groupi->symsMapIndex) ||
1648 darray_empty(group0->symsMapIndex) ||
1649 memcmp(darray_mem(groupi->symsMapIndex, 0),
1650 darray_mem(group0->symsMapIndex, 0),
1651 group0->numLevels * sizeof(int)))) {
1655 if (!darray_same(groupi->symsMapNumEntries,
1656 group0->symsMapNumEntries) &&
1657 (darray_empty(groupi->symsMapNumEntries) ||
1658 darray_empty(group0->symsMapNumEntries) ||
1659 memcmp(darray_mem(groupi->symsMapNumEntries, 0),
1660 darray_mem(group0->symsMapNumEntries, 0),
1661 group0->numLevels * sizeof(size_t)))) {
1665 if (!darray_same(groupi->acts, group0->acts) &&
1666 (darray_empty(groupi->acts) || darray_empty(group0->acts) ||
1667 memcmp(darray_mem(groupi->acts, 0),
1668 darray_mem(group0->acts, 0),
1669 group0->numLevels * sizeof(union xkb_action)))) {
1676 for (i = lastGroup; i > 0; i--)
1677 ClearGroupInfo(&keyi->groups[i]);
1681 * Copy the KeyInfo into the keyboard description.
1683 * This function recurses.
1686 CopySymbolsDef(SymbolsInfo *info, KeyInfo *keyi,
1687 xkb_keycode_t start_from)
1689 struct xkb_keymap *keymap = info->keymap;
1691 struct xkb_key *key;
1692 size_t sizeSyms = 0;
1693 xkb_group_index_t i, nGroups;
1694 xkb_level_index_t width, tmp;
1695 struct xkb_key_type * type;
1696 bool haveActions, autoType, useAlias;
1697 unsigned types[XKB_NUM_GROUPS];
1698 unsigned int symIndex = 0;
1700 useAlias = (start_from == 0);
1702 key = FindNamedKey(keymap, keyi->name, useAlias, start_from);
1704 if (start_from == 0)
1705 log_vrb(info->keymap->ctx, 5,
1706 "Key %s not found in keycodes; Symbols ignored\n",
1707 LongKeyNameText(keyi->name));
1710 kc = XkbKeyGetKeycode(keymap, key);
1712 haveActions = false;
1714 for (i = nGroups = 0; i < XKB_NUM_GROUPS; i++) {
1715 GroupInfo *groupi = &keyi->groups[i];
1717 if (i + 1 > nGroups && groupi->defined)
1720 if (!darray_empty(groupi->acts))
1725 /* Assign the type to the key, if it is missing. */
1726 if (groupi->type == XKB_ATOM_NONE) {
1727 if (keyi->dfltType != XKB_ATOM_NONE)
1728 groupi->type = keyi->dfltType;
1729 else if (FindAutomaticType(keymap, groupi->numLevels,
1730 darray_mem(groupi->syms, 0),
1731 &groupi->type, &autoType)) { }
1733 log_vrb(info->keymap->ctx, 5,
1734 "No automatic type for %d symbols; "
1735 "Using %s for the %s key (keycode %d)\n",
1737 xkb_atom_text(keymap->ctx, groupi->type),
1738 LongKeyNameText(keyi->name), kc);
1741 if (FindNamedType(keymap, groupi->type, &types[i])) {
1742 if (!autoType || groupi->numLevels > 2)
1743 key->explicit_groups |= (1 << i);
1746 log_vrb(info->keymap->ctx, 3,
1747 "Type \"%s\" is not defined; "
1748 "Using default type for the %s key (keycode %d)\n",
1749 xkb_atom_text(keymap->ctx, groupi->type),
1750 LongKeyNameText(keyi->name), kc);
1752 * Index 0 is guaranteed to contain something, usually
1753 * ONE_LEVEL or at least some default one-level type.
1758 /* if the type specifies fewer levels than the key has, shrink the key */
1759 type = &keymap->types[types[i]];
1760 if (type->num_levels < groupi->numLevels) {
1761 log_vrb(info->keymap->ctx, 1,
1762 "Type \"%s\" has %d levels, but %s has %d symbols; "
1763 "Ignoring extra symbols\n",
1764 xkb_atom_text(keymap->ctx, type->name),
1766 LongKeyNameText(keyi->name),
1768 groupi->numLevels = type->num_levels;
1771 width = MAX3(width, groupi->numLevels, type->num_levels);
1772 sizeSyms += darray_size(groupi->syms);
1775 darray_resize0(key->syms, sizeSyms);
1777 key->num_groups = nGroups;
1781 key->sym_index = calloc(nGroups * width, sizeof(*key->sym_index));
1783 key->num_syms = calloc(nGroups * width, sizeof(*key->num_syms));
1786 key->actions = calloc(nGroups * width, sizeof(*key->actions));
1787 key->explicit |= EXPLICIT_INTERP;
1790 key->out_of_range_group_number = keyi->out_of_range_group_number;
1791 key->out_of_range_group_action = keyi->out_of_range_group_action;
1793 for (i = 0; i < nGroups; i++) {
1794 GroupInfo *groupi = &keyi->groups[i];
1796 /* assign kt_index[i] to the index of the type in map->types.
1797 * kt_index[i] may have been set by a previous run (if we have two
1798 * layouts specified). Let's not overwrite it with the ONE_LEVEL
1799 * default group if we dont even have keys for this group anyway.
1801 * FIXME: There should be a better fix for this.
1803 if (groupi->numLevels)
1804 key->kt_index[i] = types[i];
1806 if (!darray_empty(groupi->syms)) {
1807 /* fill key to "width" symbols*/
1808 for (tmp = 0; tmp < width; tmp++) {
1809 if (tmp < groupi->numLevels &&
1810 darray_item(groupi->symsMapNumEntries, tmp) != 0) {
1811 memcpy(darray_mem(key->syms, symIndex),
1812 darray_mem(groupi->syms,
1813 darray_item(groupi->symsMapIndex, tmp)),
1814 darray_item(groupi->symsMapNumEntries, tmp) * sizeof(xkb_keysym_t));
1815 key->sym_index[(i * width) + tmp] = symIndex;
1816 key->num_syms[(i * width) + tmp] =
1817 darray_item(groupi->symsMapNumEntries, tmp);
1818 symIndex += key->num_syms[(i * width) + tmp];
1821 key->sym_index[(i * width) + tmp] = -1;
1822 key->num_syms[(i * width) + tmp] = 0;
1825 if (key->actions && !darray_empty(groupi->acts)) {
1826 if (tmp < groupi->numLevels)
1827 key->actions[tmp] = darray_item(groupi->acts, tmp);
1829 key->actions[tmp].type = ACTION_TYPE_NONE;
1835 if (keyi->defined & KEY_FIELD_VMODMAP) {
1836 key->vmodmap = keyi->vmodmap;
1837 key->explicit |= EXPLICIT_VMODMAP;
1840 if (keyi->repeat != KEY_REPEAT_UNDEFINED) {
1841 key->repeats = (keyi->repeat == KEY_REPEAT_YES);
1842 key->explicit |= EXPLICIT_REPEAT;
1845 /* do the same thing for the next key */
1846 CopySymbolsDef(info, keyi, kc + 1);
1851 CopyModMapDef(SymbolsInfo *info, ModMapEntry *entry)
1853 struct xkb_key *key;
1854 struct xkb_keymap *keymap = info->keymap;
1856 if (!entry->haveSymbol) {
1857 key = FindNamedKey(keymap, entry->u.keyName, true, 0);
1859 log_vrb(info->keymap->ctx, 5,
1860 "Key %s not found in keycodes; "
1861 "Modifier map entry for %s not updated\n",
1862 LongKeyNameText(entry->u.keyName),
1863 ModIndexText(entry->modifier));
1868 key = FindKeyForSymbol(keymap, entry->u.keySym);
1870 log_vrb(info->keymap->ctx, 5,
1871 "Key \"%s\" not found in symbol map; "
1872 "Modifier map entry for %s not updated\n",
1873 KeysymText(entry->u.keySym),
1874 ModIndexText(entry->modifier));
1879 key->modmap |= (1 << entry->modifier);
1884 * Handle the xkb_symbols section of an xkb file.
1886 * @param file The parsed xkb_symbols section of the xkb file.
1887 * @param keymap Handle to the keyboard description to store the symbols in.
1888 * @param merge Merge strategy (e.g. MERGE_OVERRIDE).
1891 CompileSymbols(XkbFile *file, struct xkb_keymap *keymap,
1892 enum merge_mode merge)
1894 xkb_group_index_t i;
1895 struct xkb_key *key;
1897 ActionsInfo *actions;
1901 actions = NewActionsInfo();
1905 InitSymbolsInfo(&info, keymap, file->id, actions);
1906 info.dflt.merge = merge;
1908 HandleSymbolsFile(&info, file, merge);
1910 if (darray_empty(info.keys))
1913 if (info.errorCount != 0)
1917 keymap->symbols_section_name = strdup(info.name);
1919 for (i = 0; i < XKB_NUM_GROUPS; i++)
1920 if (info.groupNames[i] != XKB_ATOM_NONE)
1921 keymap->group_names[i] = info.groupNames[i];
1924 darray_foreach(keyi, info.keys)
1925 PrepareKeyDef(keyi);
1928 darray_foreach(keyi, info.keys)
1929 if (!CopySymbolsDef(&info, keyi, 0))
1932 if (xkb_get_log_verbosity(keymap->ctx) > 3) {
1933 xkb_foreach_key(key, keymap) {
1934 if (key->name[0] == '\0')
1937 if (key->num_groups < 1)
1938 log_info(info.keymap->ctx,
1939 "No symbols defined for %s (keycode %d)\n",
1940 KeyNameText(key->name),
1941 XkbKeyGetKeycode(keymap, key));
1945 darray_foreach(mm, info.modMaps)
1946 if (!CopyModMapDef(&info, mm))
1949 ClearSymbolsInfo(&info);
1950 FreeActionsInfo(actions);
1954 FreeActionsInfo(actions);
1955 ClearSymbolsInfo(&info);