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"
34 * The xkb_keycodes section
35 * ========================
37 * This is the simplest section type, and is the first one to be
38 * compiled. The purpose of this is mostly to map between the
39 * hardware/evdev scancodes and xkb keycodes. Each key is given a name
40 * of up to 4 letters, by which it can be referred to later, e.g. in the
43 * Minimum/Maximum keycode
44 * -----------------------
45 * Statements of the form:
49 * The file may explicitly declare the minimum and/or maximum keycode
50 * contained therein (traditionally 8-255, inherited from old xfree86
51 * keycodes). If these are stated explicitly, they are enforced. If
52 * they are not stated, they are computed automatically.
56 * Statements of the form:
60 * The above would let 49 and 10 be valid keycodes in the keymap, and
61 * assign them the names TLDE and AE01 respectively. The format <WXYZ> is
62 * always used to refer to a key by name.
64 * [ The naming convention <AE01> just denoted the position of the key
65 * in the main alphanumric section of the keyboard, with the top left key
66 * (usually "~") acting as origin. <AE01> is the key in the first row
67 * second column (which is usually "1"). ]
69 * In the common case this just maps to the evdev scancodes from
70 * /usr/include/linux/input.h, e.g. the following definitions:
71 * #define KEY_GRAVE 41
73 * Similar definitions appear in the xf86-input-keyboard driver. Note
74 * that in all current keymaps there's a constant offset of 8 (for
75 * historical reasons).
77 * If there's a conflict, like the same name given to different keycodes,
78 * or same keycode given different names, it is resolved according to the
79 * merge mode which applies to the definitions.
81 * The reason for the 4 characters limit is that the name is sometimes
82 * converted to an unsigned long (in a direct mapping), instead of a char
83 * array (see KeyNameToLong, LongToKeyName).
87 * Statements of the form:
88 * alias <MENU> = <COMP>;
90 * Allows to refer to a previously defined key (here <COMP>) by another
91 * name (here <MENU>). Conflicts are handled similarly.
93 * Indicator name statements
94 * -------------------------
95 * Statements of the form:
96 * indicator 1 = "Caps Lock";
97 * indicator 2 = "Num Lock";
98 * indicator 3 = "Scroll Lock";
100 * Assigns a name the indicator (i.e. keyboard LED) with the given index.
101 * The amount of possible indicators is predetermined (XkbNumIndicators).
102 * The indicator may be referred by this name later in the compat section
105 * Effect on the keymap
106 * --------------------
107 * After all of the xkb_keycodes sections have been compiled, the
108 * following members of struct xkb_keymap are finalized:
109 * xkb_keycode_t min_key_code;
110 * xkb_keycode_t max_key_code;
111 * darray(struct xkb_key_alias) key_aliases;
112 * const char *indicator_names[XkbNumIndicators];
113 * char *keycodes_section_name;
114 * Further, the array of keys:
115 * darray(struct xkb_key) keys;
116 * had been resized to its final size (i.e. all of the xkb_key objects are
117 * referable by their keycode). However the objects themselves do not
118 * contain any useful information besides the key name at this point.
121 typedef struct _AliasInfo {
122 enum merge_mode merge;
130 typedef struct _IndicatorNameInfo {
131 enum merge_mode merge;
140 typedef struct _KeyNamesInfo {
141 char *name; /* e.g. evdev+aliases(qwerty) */
144 enum merge_mode merge;
146 xkb_keycode_t computedMin; /* lowest keycode stored */
147 xkb_keycode_t computedMax; /* highest keycode stored */
148 xkb_keycode_t explicitMin;
149 xkb_keycode_t explicitMax;
150 darray(unsigned long) names;
151 darray(unsigned int) files;
155 struct xkb_context *ctx;
159 ResizeKeyNameArrays(KeyNamesInfo *info, int newMax)
161 if (newMax < darray_size(info->names))
164 darray_resize0(info->names, newMax + 1);
165 darray_resize0(info->files, newMax + 1);
169 InitAliasInfo(AliasInfo *info, enum merge_mode merge, unsigned file_id,
170 char alias[XkbKeyNameLength], char real[XkbKeyNameLength])
172 memset(info, 0, sizeof(*info));
174 info->file_id = file_id;
175 info->alias = KeyNameToLong(alias);
176 info->real = KeyNameToLong(real);
180 InitIndicatorNameInfo(IndicatorNameInfo * ii, KeyNamesInfo * info)
182 ii->merge = info->merge;
183 ii->file_id = info->file_id;
185 ii->name = XKB_ATOM_NONE;
189 static IndicatorNameInfo *
190 NextIndicatorName(KeyNamesInfo * info)
192 IndicatorNameInfo *ii;
194 ii = malloc(sizeof(*ii));
198 InitIndicatorNameInfo(ii, info);
199 list_append(&ii->entry, &info->leds);
204 static IndicatorNameInfo *
205 FindIndicatorByIndex(KeyNamesInfo * info, xkb_led_index_t ndx)
207 IndicatorNameInfo *old;
209 list_foreach(old, &info->leds, entry)
216 static IndicatorNameInfo *
217 FindIndicatorByName(KeyNamesInfo * info, xkb_atom_t name)
219 IndicatorNameInfo *old;
221 list_foreach(old, &info->leds, entry)
222 if (old->name == name)
229 AddIndicatorName(KeyNamesInfo *info, enum merge_mode merge,
230 IndicatorNameInfo *new)
232 IndicatorNameInfo *old;
234 int verbosity = xkb_get_log_verbosity(info->ctx);
236 replace = (merge == MERGE_REPLACE) || (merge == MERGE_OVERRIDE);
238 old = FindIndicatorByName(info, new->name);
240 if ((old->file_id == new->file_id && verbosity > 0) ||
242 if (old->ndx == new->ndx) {
243 if (old->virtual != new->virtual) {
245 old->virtual = new->virtual;
246 log_warn(info->ctx, "Multiple indicators named %s; "
247 "Using %s instead of %s\n",
248 xkb_atom_text(info->ctx, new->name),
249 (old->virtual ? "virtual" : "real"),
250 (old->virtual ? "real" : "virtual"));
253 log_warn(info->ctx, "Multiple indicators named %s; "
254 "Identical definitions ignored\n",
255 xkb_atom_text(info->ctx, new->name));
260 log_warn(info->ctx, "Multiple indicators named %s; "
261 "Using %d, ignoring %d\n",
262 xkb_atom_text(info->ctx, new->name),
263 (replace ? old->ndx : new->ndx),
264 (replace ? new->ndx : old->ndx));
268 list_del(&old->entry);
274 old = FindIndicatorByIndex(info, new->ndx);
276 if ((old->file_id == new->file_id && verbosity > 0) ||
278 if (old->name == new->name && old->virtual == new->virtual) {
279 log_warn(info->ctx, "Multiple names for indicator %d; "
280 "Identical definitions ignored\n", new->ndx);
282 const char *oldType, *newType;
283 xkb_atom_t using, ignoring;
285 oldType = "virtual indicator";
287 oldType = "real indicator";
289 newType = "virtual indicator";
291 newType = "real indicator";
294 ignoring = old->name;
298 ignoring = new->name;
300 log_warn(info->ctx, "Multiple names for indicator %d; "
301 "Using %s %s, ignoring %s %s\n",
303 oldType, xkb_atom_text(info->ctx, using),
304 newType, xkb_atom_text(info->ctx, ignoring));
308 old->name = new->name;
309 old->virtual = new->virtual;
314 new = NextIndicatorName(info);
317 "Couldn't allocate name for indicator %d; Ignored\n",
321 new->name = old->name;
323 new->virtual = old->virtual;
328 ClearKeyNamesInfo(KeyNamesInfo * info)
330 AliasInfo *alias, *next_alias;
331 IndicatorNameInfo *ii, *next_ii;
335 info->merge = MERGE_DEFAULT;
336 info->computedMax = info->explicitMax = info->explicitMin = 0;
337 info->computedMin = XKB_KEYCODE_MAX;
338 darray_free(info->names);
339 darray_free(info->files);
340 list_foreach_safe(ii, next_ii, &info->leds, entry)
342 list_init(&info->leds);
343 list_foreach_safe(alias, next_alias, &info->aliases, entry)
345 list_init(&info->aliases);
349 InitKeyNamesInfo(KeyNamesInfo *info, struct xkb_context *ctx,
353 info->merge = MERGE_DEFAULT;
354 list_init(&info->leds);
355 list_init(&info->aliases);
356 info->file_id = file_id;
357 darray_init(info->names);
358 darray_init(info->files);
359 ClearKeyNamesInfo(info);
360 info->errorCount = 0;
365 FindKeyByLong(KeyNamesInfo * info, unsigned long name)
369 for (i = info->computedMin; i <= info->computedMax; i++)
370 if (darray_item(info->names, i) == name)
377 * Store the name of the key as a long in the info struct under the given
378 * keycode. If the same keys is referred to twice, print a warning.
379 * Note that the key's name is stored as a long, the keycode is the index.
382 AddKeyName(KeyNamesInfo *info, xkb_keycode_t kc, unsigned long name,
383 enum merge_mode merge, unsigned file_id, bool reportCollisions)
386 int verbosity = xkb_get_log_verbosity(info->ctx);
388 ResizeKeyNameArrays(info, kc);
390 if (kc < info->computedMin)
391 info->computedMin = kc;
392 if (kc > info->computedMax)
393 info->computedMax = kc;
395 if (reportCollisions)
396 reportCollisions = (verbosity > 7 ||
398 file_id == darray_item(info->files, kc)));
400 if (darray_item(info->names, kc) != 0) {
401 const char *lname = LongKeyNameText(darray_item(info->names, kc));
402 const char *kname = LongKeyNameText(name);
404 if (darray_item(info->names, kc) == name && reportCollisions) {
405 log_warn(info->ctx, "Multiple identical key name definitions; "
406 "Later occurences of \"%s = %d\" ignored\n", lname, kc);
410 if (merge == MERGE_AUGMENT) {
411 if (reportCollisions)
412 log_warn(info->ctx, "Multiple names for keycode %d; "
413 "Using %s, ignoring %s\n", kc, lname, kname);
417 if (reportCollisions)
418 log_warn(info->ctx, "Multiple names for keycode %d; "
419 "Using %s, ignoring %s\n", kc, kname, lname);
420 darray_item(info->names, kc) = 0;
421 darray_item(info->files, kc) = 0;
425 old = FindKeyByLong(info, name);
426 if (old != 0 && old != kc) {
427 const char *kname = LongKeyNameText(name);
429 if (merge == MERGE_OVERRIDE) {
430 darray_item(info->names, old) = 0;
431 darray_item(info->files, old) = 0;
432 if (reportCollisions)
433 log_warn(info->ctx, "Key name %s assigned to multiple keys; "
434 "Using %d, ignoring %d\n", kname, kc, old);
437 if (reportCollisions && verbosity > 3)
438 log_warn(info->ctx, "Key name %s assigned to multiple keys; "
439 "Using %d, ignoring %d\n", kname, old, kc);
444 darray_item(info->names, kc) = name;
445 darray_item(info->files, kc) = file_id;
449 /***====================================================================***/
452 HandleAliasDef(KeyNamesInfo *info, KeyAliasDef *def, enum merge_mode merge,
456 MergeAliases(KeyNamesInfo *into, KeyNamesInfo *from, enum merge_mode merge)
458 AliasInfo *alias, *next;
461 if (list_empty(&from->aliases))
464 if (list_empty(&into->aliases)) {
465 list_replace(&from->aliases, &into->aliases);
466 list_init(&from->aliases);
470 memset(&def, 0, sizeof(def));
472 list_foreach_safe(alias, next, &from->aliases, entry) {
473 def.merge = (merge == MERGE_DEFAULT) ? alias->merge : merge;
474 LongToKeyName(alias->alias, def.alias);
475 LongToKeyName(alias->real, def.real);
477 if (!HandleAliasDef(into, &def, def.merge, alias->file_id))
485 MergeIncludedKeycodes(KeyNamesInfo *into, KeyNamesInfo *from,
486 enum merge_mode merge)
489 IndicatorNameInfo *led;
491 if (from->errorCount > 0) {
492 into->errorCount += from->errorCount;
496 if (into->name == NULL) {
497 into->name = from->name;
501 ResizeKeyNameArrays(into, from->computedMax);
503 for (i = from->computedMin; i <= from->computedMax; i++) {
504 unsigned long name = darray_item(from->names, i);
508 if (!AddKeyName(into, i, name, merge, from->file_id, false))
512 list_foreach(led, &from->leds, entry) {
513 led->merge = (merge == MERGE_DEFAULT ? led->merge : merge);
514 if (!AddIndicatorName(into, led->merge, led))
518 if (!MergeAliases(into, from, merge))
521 if (from->explicitMin != 0)
522 if (into->explicitMin == 0 || into->explicitMin > from->explicitMin)
523 into->explicitMin = from->explicitMin;
525 if (from->explicitMax > 0)
526 if (into->explicitMax == 0 || into->explicitMax < from->explicitMax)
527 into->explicitMax = from->explicitMax;
531 HandleKeycodesFile(KeyNamesInfo *info, XkbFile *file, enum merge_mode merge);
534 * Handle the given include statement (e.g. "include "evdev+aliases(qwerty)").
536 * @param info Struct to store the key info in.
537 * @param stmt The include statement from the keymap file.
540 HandleIncludeKeycodes(KeyNamesInfo *info, IncludeStmt *stmt)
542 enum merge_mode merge = MERGE_DEFAULT;
544 KeyNamesInfo included, next_incl;
546 InitKeyNamesInfo(&included, info->ctx, info->file_id);
549 included.name = stmt->stmt;
553 for (; stmt; stmt = stmt->next_incl) {
554 if (!ProcessIncludeFile(info->ctx, stmt, FILE_TYPE_KEYCODES,
556 info->errorCount += 10;
557 ClearKeyNamesInfo(&included);
561 InitKeyNamesInfo(&next_incl, info->ctx, rtrn->id);
563 HandleKeycodesFile(&next_incl, rtrn, MERGE_OVERRIDE);
565 MergeIncludedKeycodes(&included, &next_incl, merge);
567 ClearKeyNamesInfo(&next_incl);
571 MergeIncludedKeycodes(info, &included, merge);
572 ClearKeyNamesInfo(&included);
574 return (info->errorCount == 0);
578 * Parse the given statement and store the output in the info struct.
582 HandleKeycodeDef(KeyNamesInfo *info, KeycodeDef *stmt, enum merge_mode merge)
584 if ((info->explicitMin != 0 && stmt->value < info->explicitMin) ||
585 (info->explicitMax != 0 && stmt->value > info->explicitMax)) {
586 log_err(info->ctx, "Illegal keycode %lu for name %s; "
587 "Must be in the range %d-%d inclusive\n",
588 stmt->value, KeyNameText(stmt->name), info->explicitMin,
589 info->explicitMax ? info->explicitMax : XKB_KEYCODE_MAX);
593 if (stmt->merge != MERGE_DEFAULT) {
594 if (stmt->merge == MERGE_REPLACE)
595 merge = MERGE_OVERRIDE;
600 return AddKeyName(info, stmt->value, KeyNameToLong(stmt->name), merge,
601 info->file_id, true);
605 HandleAliasCollision(KeyNamesInfo *info, AliasInfo *old, AliasInfo *new)
607 int verbosity = xkb_get_log_verbosity(info->ctx);
609 if (new->real == old->real) {
610 if ((new->file_id == old->file_id && verbosity > 0) || verbosity > 9)
611 log_warn(info->ctx, "Alias of %s for %s declared more than once; "
612 "First definition ignored\n",
613 LongKeyNameText(new->alias), LongKeyNameText(new->real));
616 unsigned long use, ignore;
618 if (new->merge == MERGE_AUGMENT) {
627 if ((old->file_id == new->file_id && verbosity > 0) || verbosity > 9)
628 log_warn(info->ctx, "Multiple definitions for alias %s; "
629 "Using %s, ignoring %s\n",
630 LongKeyNameText(old->alias), LongKeyNameText(use),
631 LongKeyNameText(ignore));
633 if (use != old->real)
637 old->file_id = new->file_id;
638 old->merge = new->merge;
642 HandleAliasDef(KeyNamesInfo *info, KeyAliasDef *def, enum merge_mode merge,
647 list_foreach(alias, &info->aliases, entry) {
648 if (alias->alias == KeyNameToLong(def->alias)) {
650 InitAliasInfo(&new, merge, file_id, def->alias, def->real);
651 HandleAliasCollision(info, alias, &new);
656 alias = calloc(1, sizeof(*alias));
658 log_wsgo(info->ctx, "Allocation failure in HandleAliasDef\n");
662 alias->file_id = file_id;
663 alias->merge = merge;
664 alias->alias = KeyNameToLong(def->alias);
665 alias->real = KeyNameToLong(def->real);
666 list_append(&alias->entry, &info->aliases);
671 #define MIN_KEYCODE_DEF 0
672 #define MAX_KEYCODE_DEF 1
675 * Handle the minimum/maximum statement of the xkb file.
676 * Sets explicitMin/Max of the info struct.
678 * @return 1 on success, 0 otherwise.
681 HandleKeyNameVar(KeyNamesInfo *info, VarDef *stmt)
683 const char *elem, *field;
688 if (!ExprResolveLhs(info->ctx, stmt->name, &elem, &field,
690 return false; /* internal error, already reported */
693 log_err(info->ctx, "Unknown element %s encountered; "
694 "Default for field %s ignored\n", elem, field);
698 if (istreq(field, "minimum")) {
699 which = MIN_KEYCODE_DEF;
701 else if (istreq(field, "maximum")) {
702 which = MAX_KEYCODE_DEF;
705 log_err(info->ctx, "Unknown field encountered; "
706 "Assigment to field %s ignored\n", field);
710 if (arrayNdx != NULL) {
711 log_err(info->ctx, "The %s setting is not an array; "
712 "Illegal array reference ignored\n", field);
716 if (!ExprResolveKeyCode(info->ctx, stmt->value, &kc)) {
717 log_err(info->ctx, "Illegal keycode encountered; "
718 "Assignment to field %s ignored\n", field);
722 if (kc > XKB_KEYCODE_MAX) {
724 "Illegal keycode %d (must be in the range %d-%d inclusive); "
725 "Value of \"%s\" not changed\n",
726 kc, 0, XKB_KEYCODE_MAX, field);
730 if (which == MIN_KEYCODE_DEF) {
731 if (info->explicitMax > 0 && info->explicitMax < kc) {
733 "Minimum key code (%d) must be <= maximum key code (%d); "
734 "Minimum key code value not changed\n",
735 kc, info->explicitMax);
739 if (info->computedMax > 0 && info->computedMin < kc) {
741 "Minimum key code (%d) must be <= lowest defined key (%d); "
742 "Minimum key code value not changed\n",
743 kc, info->computedMin);
747 info->explicitMin = kc;
749 else if (which == MAX_KEYCODE_DEF) {
750 if (info->explicitMin > 0 && info->explicitMin > kc) {
752 "Maximum code (%d) must be >= minimum key code (%d); "
753 "Maximum code value not changed\n",
754 kc, info->explicitMin);
758 if (info->computedMax > 0 && info->computedMax > kc) {
760 "Maximum code (%d) must be >= highest defined key (%d); "
761 "Maximum code value not changed\n",
762 kc, info->computedMax);
766 info->explicitMax = kc;
773 HandleIndicatorNameDef(KeyNamesInfo *info, IndicatorNameDef *def,
774 enum merge_mode merge)
776 IndicatorNameInfo ii;
779 if (def->ndx < 1 || def->ndx > XkbNumIndicators) {
782 "Name specified for illegal indicator index %d\n; Ignored\n",
787 InitIndicatorNameInfo(&ii, info);
789 if (!ExprResolveString(info->ctx, def->name, &str)) {
791 snprintf(buf, sizeof(buf), "%d", def->ndx);
793 return ReportBadType(info->ctx, "indicator", "name", buf,
797 ii.ndx = (xkb_led_index_t) def->ndx;
798 ii.name = xkb_atom_intern(info->ctx, str);
799 ii.virtual = def->virtual;
801 return AddIndicatorName(info, merge, &ii);
805 * Handle the xkb_keycodes section of a xkb file.
806 * All information about parsed keys is stored in the info struct.
808 * Such a section may have include statements, in which case this function is
809 * semi-recursive (it calls HandleIncludeKeycodes, which may call
810 * HandleKeycodesFile again).
812 * @param info Struct to contain the fully parsed key information.
813 * @param file The input file (parsed xkb_keycodes section)
814 * @param merge Merge strategy (MERGE_OVERRIDE, etc.)
817 HandleKeycodesFile(KeyNamesInfo *info, XkbFile *file, enum merge_mode merge)
823 info->name = strdup_safe(file->name);
825 for (stmt = file->defs; stmt; stmt = stmt->next) {
826 switch (stmt->type) {
827 case STMT_INCLUDE: /* e.g. include "evdev+aliases(qwerty)" */
828 ok = HandleIncludeKeycodes(info, (IncludeStmt *) stmt);
830 case STMT_KEYCODE: /* e.g. <ESC> = 9; */
831 ok = HandleKeycodeDef(info, (KeycodeDef *) stmt, merge);
833 case STMT_ALIAS: /* e.g. alias <MENU> = <COMP>; */
834 ok = HandleAliasDef(info, (KeyAliasDef *) stmt, merge,
837 case STMT_VAR: /* e.g. minimum, maximum */
838 ok = HandleKeyNameVar(info, (VarDef *) stmt);
840 case STMT_INDICATOR_NAME: /* e.g. indicator 1 = "Caps Lock"; */
841 ok = HandleIndicatorNameDef(info, (IndicatorNameDef *) stmt,
846 "Keycode files may define key and indicator names only; "
847 "Ignoring %s\n", StmtTypeToString(stmt->type));
855 if (info->errorCount > 10) {
856 log_err(info->ctx, "Abandoning keycodes file \"%s\"\n",
864 ApplyAliases(KeyNamesInfo *info, struct xkb_keymap *keymap)
868 struct xkb_key_alias *old, *a;
869 AliasInfo *alias, *next;
872 nOld = darray_size(keymap->key_aliases);
873 old = &darray_item(keymap->key_aliases, 0);
875 list_foreach(alias, &info->aliases, entry) {
876 key = FindNamedKey(keymap, alias->real, false, 0);
878 log_lvl(info->ctx, 5,
879 "Attempt to alias %s to non-existent key %s; Ignored\n",
880 LongKeyNameText(alias->alias),
881 LongKeyNameText(alias->real));
886 key = FindNamedKey(keymap, alias->alias, false, 0);
888 log_lvl(info->ctx, 5,
889 "Attempt to create alias with the name of a real key; "
890 "Alias \"%s = %s\" ignored\n",
891 LongKeyNameText(alias->alias),
892 LongKeyNameText(alias->real));
902 for (i = 0, a = old; i < nOld; i++, a++) {
905 if (KeyNameToLong(a->alias) == alias->alias)
908 InitAliasInfo(&old_alias, MERGE_AUGMENT, 0, a->alias, a->real);
909 HandleAliasCollision(info, &old_alias, alias);
910 old_alias.real = KeyNameToLong(a->real);
920 darray_resize0(keymap->key_aliases, nOld + nNew);
922 a = &darray_item(keymap->key_aliases, nOld);
923 list_foreach(alias, &info->aliases, entry) {
924 if (alias->alias != 0) {
925 LongToKeyName(alias->alias, a->alias);
926 LongToKeyName(alias->real, a->real);
932 list_foreach_safe(alias, next, &info->aliases, entry)
934 list_init(&info->aliases);
938 CopyKeyNamesToKeymap(struct xkb_keymap *keymap, KeyNamesInfo *info)
941 IndicatorNameInfo *ii;
943 if (info->explicitMin > 0)
944 keymap->min_key_code = info->explicitMin;
946 keymap->min_key_code = info->computedMin;
948 if (info->explicitMax > 0)
949 keymap->max_key_code = info->explicitMax;
951 keymap->max_key_code = info->computedMax;
953 darray_resize0(keymap->keys, keymap->max_key_code + 1);
954 for (kc = info->computedMin; kc <= info->computedMax; kc++)
955 LongToKeyName(darray_item(info->names, kc),
956 XkbKey(keymap, kc)->name);
958 keymap->keycodes_section_name = strdup_safe(info->name);
960 list_foreach(ii, &info->leds, entry)
961 keymap->indicator_names[ii->ndx - 1] =
962 xkb_atom_text(keymap->ctx, ii->name);
964 ApplyAliases(info, keymap);
970 * Compile the xkb_keycodes section, parse it's output, return the results.
972 * @param file The parsed XKB file (may have include statements requiring
974 * @param result The effective keycodes, as gathered from the file.
975 * @param merge Merge strategy.
977 * @return true on success, false otherwise.
980 CompileKeycodes(XkbFile *file, struct xkb_keymap *keymap,
981 enum merge_mode merge)
985 InitKeyNamesInfo(&info, keymap->ctx, file->id);
987 HandleKeycodesFile(&info, file, merge);
988 if (info.errorCount != 0)
991 if (!CopyKeyNamesToKeymap(keymap, &info))
994 ClearKeyNamesInfo(&info);
998 ClearKeyNamesInfo(&info);
1003 * Find the key with the given name.
1005 * @param keymap The keymap to search in.
1006 * @param name The 4-letter name of the key as a long.
1007 * @param use_aliases true if the key aliases should be searched too.
1008 * @param start_from Keycode to start searching from.
1010 * @return the key if it is found, NULL otherwise.
1013 FindNamedKey(struct xkb_keymap *keymap, unsigned long name,
1014 bool use_aliases, xkb_keycode_t start_from)
1016 struct xkb_key *key;
1018 if (start_from < keymap->min_key_code)
1019 start_from = keymap->min_key_code;
1020 else if (start_from > keymap->max_key_code)
1023 xkb_foreach_key_from(key, keymap, start_from)
1024 if (KeyNameToLong(key->name) == name)
1028 unsigned long new_name;
1029 if (FindKeyNameForAlias(keymap, name, &new_name))
1030 return FindNamedKey(keymap, new_name, false, 0);
1037 FindKeyNameForAlias(struct xkb_keymap *keymap, unsigned long lname,
1038 unsigned long *real_name)
1040 char name[XkbKeyNameLength];
1041 struct xkb_key_alias *a;
1043 LongToKeyName(lname, name);
1044 darray_foreach(a, keymap->key_aliases) {
1045 if (strncmp(name, a->alias, XkbKeyNameLength) == 0) {
1046 *real_name = KeyNameToLong(a->real);