1 /************************************************************
2 * Copyright (c) 1994 by Silicon Graphics Computer Systems, Inc.
4 * Permission to use, copy, modify, and distribute this
5 * software and its documentation for any purpose and without
6 * fee is hereby granted, provided that the above copyright
7 * notice appear in all copies and that both that copyright
8 * notice and this permission notice appear in supporting
9 * documentation, and that the name of Silicon Graphics not be
10 * used in advertising or publicity pertaining to distribution
11 * of the software without specific prior written permission.
12 * Silicon Graphics makes no representation about the suitability
13 * of this software for any purpose. It is provided "as is"
14 * without any express or implied warranty.
16 * SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
17 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
18 * AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
19 * GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
20 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
21 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
22 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH
23 * THE USE OR PERFORMANCE OF THIS SOFTWARE.
25 ********************************************************/
27 #include "xkbcomp-priv.h"
29 #include "parseutils.h"
32 * The xkb_keycodes section
33 * ========================
35 * This is the simplest section type, and is the first one to be
36 * compiled. The purpose of this is mostly to map between the
37 * hardware/evdev scancodes and xkb keycodes. Each key is given a name
38 * of up to 4 letters, by which it can be referred to later, e.g. in the
41 * Minimum/Maximum keycode
42 * -----------------------
43 * Statements of the form:
47 * The file may explicitly declare the minimum and/or maximum keycode
48 * contained therein (traditionally 8-255, inherited from old xfree86
49 * keycodes). If these are stated explicitly, they are enforced. If
50 * they are not stated, they are computed automatically.
54 * Statements of the form:
58 * The above would let 49 and 10 be valid keycodes in the keymap, and
59 * assign them the names TLDE and AE01 respectively. The format <WXYZ> is
60 * always used to refer to a key by name.
62 * [ The naming convention <AE01> just denoted the position of the key
63 * in the main alphanumric section of the keyboard, with the top left key
64 * (usually "~") acting as origin. <AE01> is the key in the first row
65 * second column (which is usually "1"). ]
67 * In the common case this just maps to the evdev scancodes from
68 * /usr/include/linux/input.h, e.g. the following definitions:
69 * #define KEY_GRAVE 41
71 * Similar definitions appear in the xf86-input-keyboard driver. Note
72 * that in all current keymaps there's a constant offset of 8 (for
73 * historical reasons).
75 * If there's a conflict, like the same name given to different keycodes,
76 * or same keycode given different names, it is resolved according to the
77 * merge mode which applies to the definitions.
79 * The reason for the 4 characters limit is that the name is sometimes
80 * converted to an unsigned long (in a direct mapping), instead of a char
81 * array (see KeyNameToLong, LongToKeyName).
85 * Statements of the form:
86 * alias <MENU> = <COMP>;
88 * Allows to refer to a previously defined key (here <COMP>) by another
89 * name (here <MENU>). Conflicts are handled similarly.
91 * Indicator name statements
92 * -------------------------
93 * Statements of the form:
94 * indicator 1 = "Caps Lock";
95 * indicator 2 = "Num Lock";
96 * indicator 3 = "Scroll Lock";
98 * Assigns a name the indicator (i.e. keyboard LED) with the given index.
99 * The amount of possible indicators is predetermined (XkbNumIndicators).
100 * The indicator may be referred by this name later in the compat section
103 * Effect on the keymap
104 * --------------------
105 * After all of keycodes sections have been compiled, the following members
106 * of struct xkb_keymap are finalized:
107 * xkb_keycode_t min_key_code;
108 * xkb_keycode_t max_key_code;
109 * darray(struct xkb_key_alias) key_aliases;
110 * const char *indicator_names[XkbNumIndicators];
111 * char *keycodes_section_name;
112 * Further, the array of keys:
113 * darray(struct xkb_key) keys;
114 * had been resized to its final size (i.e. all of the xkb_key objects are
115 * referable by their keycode). However the objects themselves do not
116 * contain any useful information besides the key name at this point.
119 typedef struct _AliasInfo {
120 enum merge_mode merge;
124 char alias[XkbKeyNameLength];
125 char real[XkbKeyNameLength];
128 typedef struct _IndicatorNameInfo {
129 enum merge_mode merge;
138 typedef struct _KeyNamesInfo {
139 char *name; /* e.g. evdev+aliases(qwerty) */
142 enum merge_mode merge;
143 xkb_keycode_t computedMin; /* lowest keycode stored */
144 xkb_keycode_t computedMax; /* highest keycode stored */
145 xkb_keycode_t explicitMin;
146 xkb_keycode_t explicitMax;
147 darray(unsigned long) names;
148 darray(unsigned int) files;
152 struct xkb_keymap *keymap;
156 ResizeKeyNameArrays(KeyNamesInfo *info, int newMax)
158 if (newMax < darray_size(info->names))
161 darray_resize0(info->names, newMax + 1);
162 darray_resize0(info->files, newMax + 1);
166 InitAliasInfo(AliasInfo *info, enum merge_mode merge, unsigned file_id,
167 char *alias, char *real)
169 memset(info, 0, sizeof(*info));
171 info->file_id = file_id;
172 strncpy(info->alias, alias, XkbKeyNameLength);
173 strncpy(info->real, real, XkbKeyNameLength);
177 InitIndicatorNameInfo(IndicatorNameInfo * ii, KeyNamesInfo * info)
179 ii->merge = info->merge;
180 ii->file_id = info->file_id;
182 ii->name = XKB_ATOM_NONE;
186 static IndicatorNameInfo *
187 NextIndicatorName(KeyNamesInfo * info)
189 IndicatorNameInfo *ii;
191 ii = malloc(sizeof(*ii));
195 InitIndicatorNameInfo(ii, info);
196 list_append(&ii->entry, &info->leds);
201 static IndicatorNameInfo *
202 FindIndicatorByIndex(KeyNamesInfo * info, xkb_led_index_t ndx)
204 IndicatorNameInfo *old;
206 list_foreach(old, &info->leds, entry)
213 static IndicatorNameInfo *
214 FindIndicatorByName(KeyNamesInfo * info, xkb_atom_t name)
216 IndicatorNameInfo *old;
218 list_foreach(old, &info->leds, entry)
219 if (old->name == name)
226 AddIndicatorName(KeyNamesInfo *info, enum merge_mode merge,
227 IndicatorNameInfo *new)
229 IndicatorNameInfo *old;
231 int verbosity = xkb_get_log_verbosity(info->keymap->ctx);
233 replace = (merge == MERGE_REPLACE) || (merge == MERGE_OVERRIDE);
235 old = FindIndicatorByName(info, new->name);
237 if ((old->file_id == new->file_id && verbosity > 0) ||
239 if (old->ndx == new->ndx) {
240 if (old->virtual != new->virtual) {
242 old->virtual = new->virtual;
243 log_warn(info->keymap->ctx, "Multiple indicators named %s; "
244 "Using %s instead of %s\n",
245 xkb_atom_text(info->keymap->ctx, new->name),
246 (old->virtual ? "virtual" : "real"),
247 (old->virtual ? "real" : "virtual"));
250 log_warn(info->keymap->ctx, "Multiple indicators named %s; "
251 "Identical definitions ignored\n",
252 xkb_atom_text(info->keymap->ctx, new->name));
257 log_warn(info->keymap->ctx, "Multiple indicators named %s; "
258 "Using %d, ignoring %d\n",
259 xkb_atom_text(info->keymap->ctx, new->name),
260 (replace ? old->ndx : new->ndx),
261 (replace ? new->ndx : old->ndx));
265 list_del(&old->entry);
271 old = FindIndicatorByIndex(info, new->ndx);
273 if ((old->file_id == new->file_id && verbosity > 0) ||
275 if (old->name == new->name && old->virtual == new->virtual) {
276 log_warn(info->keymap->ctx,
277 "Multiple names for indicator %d; "
278 "Identical definitions ignored\n", new->ndx);
280 const char *oldType, *newType;
281 xkb_atom_t using, ignoring;
283 oldType = "virtual indicator";
285 oldType = "real indicator";
287 newType = "virtual indicator";
289 newType = "real indicator";
292 ignoring = old->name;
296 ignoring = new->name;
298 log_warn(info->keymap->ctx,
299 "Multiple names for indicator %d; "
300 "Using %s %s, ignoring %s %s\n",
302 oldType, xkb_atom_text(info->keymap->ctx, using),
303 newType, xkb_atom_text(info->keymap->ctx, ignoring));
307 old->name = new->name;
308 old->virtual = new->virtual;
313 new = NextIndicatorName(info);
315 log_wsgo(info->keymap->ctx,
316 "Couldn't allocate name for indicator %d; Ignored\n",
320 new->name = old->name;
322 new->virtual = old->virtual;
327 ClearKeyNamesInfo(KeyNamesInfo * info)
329 AliasInfo *alias, *next_alias;
330 IndicatorNameInfo *ii, *next_ii;
334 info->merge = MERGE_DEFAULT;
335 info->computedMax = info->explicitMax = info->explicitMin = 0;
336 info->computedMin = XKB_KEYCODE_MAX;
337 darray_free(info->names);
338 darray_free(info->files);
339 list_foreach_safe(ii, next_ii, &info->leds, entry)
341 list_init(&info->leds);
342 list_foreach_safe(alias, next_alias, &info->aliases, entry)
344 list_init(&info->aliases);
348 InitKeyNamesInfo(KeyNamesInfo *info, struct xkb_keymap *keymap,
352 info->merge = MERGE_DEFAULT;
353 list_init(&info->leds);
354 list_init(&info->aliases);
355 info->file_id = file_id;
356 darray_init(info->names);
357 darray_init(info->files);
358 ClearKeyNamesInfo(info);
359 info->errorCount = 0;
360 info->keymap = keymap;
364 FindKeyByLong(KeyNamesInfo * info, unsigned long name)
368 for (i = info->computedMin; i <= info->computedMax; i++)
369 if (darray_item(info->names, i) == name)
376 * Store the name of the key as a long in the info struct under the given
377 * keycode. If the same keys is referred to twice, print a warning.
378 * Note that the key's name is stored as a long, the keycode is the index.
381 AddKeyName(KeyNamesInfo * info,
382 xkb_keycode_t kc, char name[XkbKeyNameLength],
383 enum merge_mode merge, unsigned file_id, bool reportCollisions)
387 int verbosity = xkb_get_log_verbosity(info->keymap->ctx);
389 ResizeKeyNameArrays(info, kc);
391 if (kc < info->computedMin)
392 info->computedMin = kc;
393 if (kc > info->computedMax)
394 info->computedMax = kc;
395 lval = KeyNameToLong(name);
397 if (reportCollisions)
398 reportCollisions = (verbosity > 7 ||
400 file_id == darray_item(info->files, kc)));
402 if (darray_item(info->names, kc) != 0) {
403 const char *lname = LongKeyNameText(darray_item(info->names, kc));
404 const char *kname = KeyNameText(name);
406 if (darray_item(info->names, kc) == lval && reportCollisions) {
407 log_warn(info->keymap->ctx,
408 "Multiple identical key name definitions; "
409 "Later occurences of \"%s = %d\" ignored\n", lname, kc);
413 if (merge == MERGE_AUGMENT) {
414 if (reportCollisions)
415 log_warn(info->keymap->ctx,
416 "Multiple names for keycode %d; "
417 "Using %s, ignoring %s\n", kc, lname, kname);
421 if (reportCollisions)
422 log_warn(info->keymap->ctx,
423 "Multiple names for keycode %d; "
424 "Using %s, ignoring %s\n", kc, kname, lname);
425 darray_item(info->names, kc) = 0;
426 darray_item(info->files, kc) = 0;
430 old = FindKeyByLong(info, lval);
431 if (old != 0 && old != kc) {
432 const char *kname = KeyNameText(name);
434 if (merge == MERGE_OVERRIDE) {
435 darray_item(info->names, old) = 0;
436 darray_item(info->files, old) = 0;
437 if (reportCollisions)
438 log_warn(info->keymap->ctx,
439 "Key name %s assigned to multiple keys; "
440 "Using %d, ignoring %d\n", kname, kc, old);
443 if (reportCollisions && verbosity > 3)
444 log_warn(info->keymap->ctx,
445 "Key name %s assigned to multiple keys; "
446 "Using %d, ignoring %d\n", kname, old, kc);
451 darray_item(info->names, kc) = lval;
452 darray_item(info->files, kc) = file_id;
456 /***====================================================================***/
459 HandleAliasDef(KeyNamesInfo *info, KeyAliasDef *def, enum merge_mode merge,
463 MergeAliases(KeyNamesInfo *into, KeyNamesInfo *from, enum merge_mode merge)
465 AliasInfo *alias, *next;
468 if (list_empty(&from->aliases))
471 if (list_empty(&into->aliases)) {
472 list_replace(&from->aliases, &into->aliases);
473 list_init(&from->aliases);
477 memset(&def, 0, sizeof(def));
479 list_foreach_safe(alias, next, &from->aliases, entry) {
480 def.merge = (merge == MERGE_DEFAULT) ? alias->merge : merge;
481 strncpy(def.alias, alias->alias, XkbKeyNameLength);
482 strncpy(def.real, alias->real, XkbKeyNameLength);
484 if (!HandleAliasDef(into, &def, def.merge, alias->file_id))
492 MergeIncludedKeycodes(KeyNamesInfo *into, KeyNamesInfo *from,
493 enum merge_mode merge)
496 char buf[XkbKeyNameLength];
497 IndicatorNameInfo *led;
499 if (from->errorCount > 0) {
500 into->errorCount += from->errorCount;
503 if (into->name == NULL) {
504 into->name = from->name;
508 ResizeKeyNameArrays(into, from->computedMax);
510 for (i = from->computedMin; i <= from->computedMax; i++) {
511 if (darray_item(from->names, i) == 0)
513 LongToKeyName(darray_item(from->names, i), buf);
514 if (!AddKeyName(into, i, buf, merge, from->file_id, false))
518 list_foreach(led, &from->leds, entry) {
519 led->merge = (merge == MERGE_DEFAULT ? led->merge : merge);
520 if (!AddIndicatorName(into, led->merge, led))
524 if (!MergeAliases(into, from, merge))
526 if (from->explicitMin != 0) {
527 if ((into->explicitMin == 0)
528 || (into->explicitMin > from->explicitMin))
529 into->explicitMin = from->explicitMin;
531 if (from->explicitMax > 0) {
532 if ((into->explicitMax == 0)
533 || (into->explicitMax < from->explicitMax))
534 into->explicitMax = from->explicitMax;
539 HandleKeycodesFile(KeyNamesInfo *info, XkbFile *file, enum merge_mode merge);
542 * Handle the given include statement (e.g. "include "evdev+aliases(qwerty)").
544 * @param info Struct to store the key info in.
545 * @param stmt The include statement from the keymap file.
548 HandleIncludeKeycodes(KeyNamesInfo *info, IncludeStmt *stmt)
550 enum merge_mode merge = MERGE_DEFAULT;
552 KeyNamesInfo included, next_incl;
554 /* XXX: What's that? */
555 if (stmt->file && streq(stmt->file, "computed")) {
556 info->keymap->flags |= AutoKeyNames;
557 info->explicitMin = 0;
558 info->explicitMax = XKB_KEYCODE_MAX;
559 return (info->errorCount == 0);
562 InitKeyNamesInfo(&included, info->keymap, info->file_id);
565 included.name = stmt->stmt;
569 for (; stmt; stmt = stmt->next_incl) {
570 if (!ProcessIncludeFile(info->keymap->ctx, stmt, FILE_TYPE_KEYCODES,
572 info->errorCount += 10;
573 ClearKeyNamesInfo(&included);
577 InitKeyNamesInfo(&next_incl, info->keymap, rtrn->id);
579 HandleKeycodesFile(&next_incl, rtrn, MERGE_OVERRIDE);
581 MergeIncludedKeycodes(&included, &next_incl, merge);
583 ClearKeyNamesInfo(&next_incl);
587 MergeIncludedKeycodes(info, &included, merge);
588 ClearKeyNamesInfo(&included);
590 return (info->errorCount == 0);
594 * Parse the given statement and store the output in the info struct.
598 HandleKeycodeDef(KeyNamesInfo *info, KeycodeDef *stmt, enum merge_mode merge)
600 if ((info->explicitMin != 0 && stmt->value < info->explicitMin) ||
601 (info->explicitMax != 0 && stmt->value > info->explicitMax)) {
602 log_err(info->keymap->ctx,
603 "Illegal keycode %lu for name %s; "
604 "Must be in the range %d-%d inclusive\n",
605 stmt->value, KeyNameText(stmt->name), info->explicitMin,
606 info->explicitMax ? info->explicitMax : XKB_KEYCODE_MAX);
609 if (stmt->merge != MERGE_DEFAULT) {
610 if (stmt->merge == MERGE_REPLACE)
611 merge = MERGE_OVERRIDE;
615 return AddKeyName(info, stmt->value, stmt->name, merge, info->file_id,
620 HandleAliasCollision(KeyNamesInfo *info, AliasInfo *old, AliasInfo *new)
622 int verbosity = xkb_get_log_verbosity(info->keymap->ctx);
624 if (strncmp(new->real, old->real, XkbKeyNameLength) == 0) {
625 if ((new->file_id == old->file_id && verbosity > 0) || verbosity > 9)
626 log_warn(info->keymap->ctx,
627 "Alias of %s for %s declared more than once; "
628 "First definition ignored\n",
629 KeyNameText(new->alias), KeyNameText(new->real));
634 if (new->merge == MERGE_AUGMENT) {
643 if ((old->file_id == new->file_id && verbosity > 0) || verbosity > 9)
644 log_warn(info->keymap->ctx,
645 "Multiple definitions for alias %s; "
646 "Using %s, ignoring %s\n",
647 KeyNameText(old->alias), KeyNameText(use),
648 KeyNameText(ignore));
650 if (use != old->real)
651 strncpy(old->real, use, XkbKeyNameLength);
654 old->file_id = new->file_id;
655 old->merge = new->merge;
659 HandleAliasDef(KeyNamesInfo *info, KeyAliasDef *def, enum merge_mode merge,
664 list_foreach(alias, &info->aliases, entry) {
665 if (strncmp(alias->alias, def->alias, XkbKeyNameLength) == 0) {
667 InitAliasInfo(&new, merge, file_id, def->alias, def->real);
668 HandleAliasCollision(info, alias, &new);
673 alias = calloc(1, sizeof(*alias));
675 log_wsgo(info->keymap->ctx, "Allocation failure in HandleAliasDef\n");
679 alias->file_id = file_id;
680 alias->merge = merge;
681 strncpy(alias->alias, def->alias, XkbKeyNameLength);
682 strncpy(alias->real, def->real, XkbKeyNameLength);
683 list_append(&alias->entry, &info->aliases);
688 #define MIN_KEYCODE_DEF 0
689 #define MAX_KEYCODE_DEF 1
692 * Handle the minimum/maximum statement of the xkb file.
693 * Sets explicitMin/Max of the info struct.
695 * @return 1 on success, 0 otherwise.
698 HandleKeyNameVar(KeyNamesInfo *info, VarDef *stmt)
700 const char *elem, *field;
705 if (!ExprResolveLhs(info->keymap->ctx, stmt->name, &elem, &field,
707 return false; /* internal error, already reported */
710 log_err(info->keymap->ctx,
711 "Unknown element %s encountered; "
712 "Default for field %s ignored\n", elem, field);
716 if (istreq(field, "minimum"))
717 which = MIN_KEYCODE_DEF;
718 else if (istreq(field, "maximum"))
719 which = MAX_KEYCODE_DEF;
721 log_err(info->keymap->ctx,
722 "Unknown field encountered; "
723 "Assigment to field %s ignored\n", field);
727 if (arrayNdx != NULL) {
728 log_err(info->keymap->ctx,
729 "The %s setting is not an array; "
730 "Illegal array reference ignored\n", field);
734 if (ExprResolveKeyCode(info->keymap->ctx, stmt->value, &kc) == 0) {
735 log_err(info->keymap->ctx,
736 "Illegal keycode encountered; "
737 "Assignment to field %s ignored\n", field);
741 if (kc > XKB_KEYCODE_MAX) {
742 log_err(info->keymap->ctx,
743 "Illegal keycode %d (must be in the range %d-%d inclusive); "
744 "Value of \"%s\" not changed\n",
745 kc, 0, XKB_KEYCODE_MAX, field);
749 if (which == MIN_KEYCODE_DEF) {
750 if (info->explicitMax > 0 && info->explicitMax < kc) {
751 log_err(info->keymap->ctx,
752 "Minimum key code (%d) must be <= maximum key code (%d); "
753 "Minimum key code value not changed\n",
754 kc, info->explicitMax);
758 if (info->computedMax > 0 && info->computedMin < kc) {
759 log_err(info->keymap->ctx,
760 "Minimum key code (%d) must be <= lowest defined key (%d); "
761 "Minimum key code value not changed\n",
762 kc, info->computedMin);
766 info->explicitMin = kc;
769 if (which == MAX_KEYCODE_DEF) {
770 if (info->explicitMin > 0 && info->explicitMin > kc) {
771 log_err(info->keymap->ctx,
772 "Maximum code (%d) must be >= minimum key code (%d); "
773 "Maximum code value not changed\n",
774 kc, info->explicitMin);
778 if (info->computedMax > 0 && info->computedMax > kc) {
779 log_err(info->keymap->ctx,
780 "Maximum code (%d) must be >= highest defined key (%d); "
781 "Maximum code value not changed\n",
782 kc, info->computedMax);
786 info->explicitMax = kc;
793 HandleIndicatorNameDef(KeyNamesInfo *info, IndicatorNameDef *def,
794 enum merge_mode merge)
796 IndicatorNameInfo ii;
799 if (def->ndx < 1 || def->ndx > XkbNumIndicators) {
801 log_err(info->keymap->ctx,
802 "Name specified for illegal indicator index %d\n; Ignored\n",
807 InitIndicatorNameInfo(&ii, info);
808 ii.ndx = (xkb_led_index_t) def->ndx;
810 if (!ExprResolveString(info->keymap->ctx, def->name, &str)) {
812 snprintf(buf, sizeof(buf), "%d", def->ndx);
814 return ReportBadType(info->keymap, "indicator", "name", buf,
818 ii.name = xkb_atom_intern(info->keymap->ctx, str);
819 ii.virtual = def->virtual;
821 return AddIndicatorName(info, merge, &ii);
825 * Handle the xkb_keycodes section of a xkb file.
826 * All information about parsed keys is stored in the info struct.
828 * Such a section may have include statements, in which case this function is
829 * semi-recursive (it calls HandleIncludeKeycodes, which may call
830 * HandleKeycodesFile again).
832 * @param info Struct to contain the fully parsed key information.
833 * @param file The input file (parsed xkb_keycodes section)
834 * @param merge Merge strategy (MERGE_OVERRIDE, etc.)
837 HandleKeycodesFile(KeyNamesInfo *info, XkbFile *file, enum merge_mode merge)
843 info->name = strdup_safe(file->name);
845 for (stmt = file->defs; stmt; stmt = stmt->next) {
846 switch (stmt->type) {
847 case STMT_INCLUDE: /* e.g. include "evdev+aliases(qwerty)" */
848 ok = HandleIncludeKeycodes(info, (IncludeStmt *) stmt);
850 case STMT_KEYCODE: /* e.g. <ESC> = 9; */
851 ok = HandleKeycodeDef(info, (KeycodeDef *) stmt, merge);
853 case STMT_ALIAS: /* e.g. alias <MENU> = <COMP>; */
854 ok = HandleAliasDef(info, (KeyAliasDef *) stmt, merge,
857 case STMT_VAR: /* e.g. minimum, maximum */
858 ok = HandleKeyNameVar(info, (VarDef *) stmt);
860 case STMT_INDICATOR_NAME: /* e.g. indicator 1 = "Caps Lock"; */
861 ok = HandleIndicatorNameDef(info, (IndicatorNameDef *) stmt,
865 log_err(info->keymap->ctx,
866 "Keycode files may define key and indicator names only; "
867 "Ignoring %s\n", StmtTypeToString(stmt->type));
875 if (info->errorCount > 10) {
876 log_err(info->keymap->ctx, "Abandoning keycodes file \"%s\"\n",
884 ApplyAliases(KeyNamesInfo *info)
888 struct xkb_key_alias *old, *a;
889 AliasInfo *alias, *next;
891 struct xkb_keymap *keymap = info->keymap;
893 nOld = darray_size(keymap->key_aliases);
894 old = &darray_item(keymap->key_aliases, 0);
896 list_foreach(alias, &info->aliases, entry) {
899 lname = KeyNameToLong(alias->real);
900 key = FindNamedKey(keymap, lname, false, CreateKeyNames(keymap), 0);
902 log_lvl(info->keymap->ctx, 5,
903 "Attempt to alias %s to non-existent key %s; Ignored\n",
904 KeyNameText(alias->alias), KeyNameText(alias->real));
905 alias->alias[0] = '\0';
909 lname = KeyNameToLong(alias->alias);
910 key = FindNamedKey(keymap, lname, false, false, 0);
912 log_lvl(info->keymap->ctx, 5,
913 "Attempt to create alias with the name of a real key; "
914 "Alias \"%s = %s\" ignored\n",
915 KeyNameText(alias->alias), KeyNameText(alias->real));
916 alias->alias[0] = '\0';
925 for (i = 0, a = old; i < nOld; i++, a++) {
928 if (strncmp(a->alias, alias->alias, XkbKeyNameLength) != 0)
931 InitAliasInfo(&old_alias, MERGE_AUGMENT, 0, a->alias, a->real);
932 HandleAliasCollision(info, &old_alias, alias);
933 strncpy(old_alias.real, a->real, XkbKeyNameLength);
934 alias->alias[0] = '\0';
943 darray_resize0(keymap->key_aliases, nOld + nNew);
945 a = &darray_item(keymap->key_aliases, nOld);
946 list_foreach(alias, &info->aliases, entry) {
947 if (alias->alias[0] != '\0') {
948 strncpy(a->alias, alias->alias, XkbKeyNameLength);
949 strncpy(a->real, alias->real, XkbKeyNameLength);
955 list_foreach_safe(alias, next, &info->aliases, entry)
957 list_init(&info->aliases);
962 * Compile the xkb_keycodes section, parse it's output, return the results.
964 * @param file The parsed XKB file (may have include statements requiring
966 * @param result The effective keycodes, as gathered from the file.
967 * @param merge Merge strategy.
969 * @return true on success, false otherwise.
972 CompileKeycodes(XkbFile *file, struct xkb_keymap *keymap,
973 enum merge_mode merge)
976 KeyNamesInfo info; /* contains all the info after parsing */
977 IndicatorNameInfo *ii;
979 InitKeyNamesInfo(&info, keymap, file->id);
981 HandleKeycodesFile(&info, file, merge);
983 /* all the keys are now stored in info */
985 if (info.errorCount != 0)
988 if (info.explicitMin > 0) /* if "minimum" statement was present */
989 keymap->min_key_code = info.explicitMin;
991 keymap->min_key_code = info.computedMin;
993 if (info.explicitMax > 0) /* if "maximum" statement was present */
994 keymap->max_key_code = info.explicitMax;
996 keymap->max_key_code = info.computedMax;
998 darray_resize0(keymap->keys, keymap->max_key_code + 1);
999 for (kc = info.computedMin; kc <= info.computedMax; kc++)
1000 LongToKeyName(darray_item(info.names, kc),
1001 XkbKey(keymap, kc)->name);
1004 keymap->keycodes_section_name = strdup(info.name);
1006 list_foreach(ii, &info.leds, entry) {
1007 keymap->indicator_names[ii->ndx - 1] =
1008 xkb_atom_text(keymap->ctx, ii->name);
1011 ApplyAliases(&info);
1013 ClearKeyNamesInfo(&info);
1017 ClearKeyNamesInfo(&info);