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;
139 typedef struct _KeyNamesInfo {
140 char *name; /* e.g. evdev+aliases(qwerty) */
143 enum merge_mode merge;
145 xkb_keycode_t computedMin; /* lowest keycode stored */
146 xkb_keycode_t computedMax; /* highest keycode stored */
147 xkb_keycode_t explicitMin;
148 xkb_keycode_t explicitMax;
149 darray(unsigned long) names;
150 darray(unsigned int) files;
154 struct xkb_context *ctx;
158 ResizeKeyNameArrays(KeyNamesInfo *info, int newMax)
160 if (newMax < darray_size(info->names))
163 darray_resize0(info->names, newMax + 1);
164 darray_resize0(info->files, newMax + 1);
168 InitAliasInfo(AliasInfo *info, enum merge_mode merge, unsigned file_id,
169 char alias[XkbKeyNameLength], char real[XkbKeyNameLength])
171 memset(info, 0, sizeof(*info));
173 info->file_id = file_id;
174 info->alias = KeyNameToLong(alias);
175 info->real = KeyNameToLong(real);
179 InitIndicatorNameInfo(IndicatorNameInfo * ii, KeyNamesInfo * info)
181 ii->merge = info->merge;
182 ii->file_id = info->file_id;
184 ii->name = XKB_ATOM_NONE;
187 static IndicatorNameInfo *
188 NextIndicatorName(KeyNamesInfo * info)
190 IndicatorNameInfo *ii;
192 ii = malloc(sizeof(*ii));
196 InitIndicatorNameInfo(ii, info);
197 list_append(&ii->entry, &info->leds);
202 static IndicatorNameInfo *
203 FindIndicatorByIndex(KeyNamesInfo * info, xkb_led_index_t ndx)
205 IndicatorNameInfo *old;
207 list_foreach(old, &info->leds, entry)
214 static IndicatorNameInfo *
215 FindIndicatorByName(KeyNamesInfo * info, xkb_atom_t name)
217 IndicatorNameInfo *old;
219 list_foreach(old, &info->leds, entry)
220 if (old->name == name)
227 AddIndicatorName(KeyNamesInfo *info, enum merge_mode merge,
228 IndicatorNameInfo *new)
230 IndicatorNameInfo *old;
231 bool replace, report;
232 int verbosity = xkb_get_log_verbosity(info->ctx);
234 replace = (merge == MERGE_REPLACE) || (merge == MERGE_OVERRIDE);
236 old = FindIndicatorByName(info, new->name);
238 report = ((old->file_id == new->file_id && verbosity > 0) ||
241 if (old->ndx == new->ndx) {
243 log_warn(info->ctx, "Multiple indicators named %s; "
244 "Identical definitions ignored\n",
245 xkb_atom_text(info->ctx, new->name));
250 log_warn(info->ctx, "Multiple indicators named %s; "
251 "Using %d, ignoring %d\n",
252 xkb_atom_text(info->ctx, new->name),
253 (replace ? old->ndx : new->ndx),
254 (replace ? new->ndx : old->ndx));
257 list_del(&old->entry);
262 old = FindIndicatorByIndex(info, new->ndx);
264 report = ((old->file_id == new->file_id && verbosity > 0) ||
267 if (old->name == new->name) {
269 log_warn(info->ctx, "Multiple names for indicator %d; "
270 "Identical definitions ignored\n", new->ndx);
274 log_warn(info->ctx, "Multiple names for indicator %d; "
275 "Using %s, ignoring %s\n", new->ndx,
276 xkb_atom_text(info->ctx, new->name),
277 xkb_atom_text(info->ctx, old->name));
278 old->name = new->name;
282 log_warn(info->ctx, "Multiple names for indicator %d; "
283 "Using %s, ignoring %s\n", new->ndx,
284 xkb_atom_text(info->ctx, old->name),
285 xkb_atom_text(info->ctx, new->name));
292 new = NextIndicatorName(info);
295 "Couldn't allocate name for indicator %d; Ignored\n",
299 new->name = old->name;
305 ClearKeyNamesInfo(KeyNamesInfo * info)
307 AliasInfo *alias, *next_alias;
308 IndicatorNameInfo *ii, *next_ii;
312 info->merge = MERGE_DEFAULT;
313 info->computedMax = info->explicitMax = info->explicitMin = 0;
314 info->computedMin = XKB_KEYCODE_MAX;
315 darray_free(info->names);
316 darray_free(info->files);
317 list_foreach_safe(ii, next_ii, &info->leds, entry)
319 list_init(&info->leds);
320 list_foreach_safe(alias, next_alias, &info->aliases, entry)
322 list_init(&info->aliases);
326 InitKeyNamesInfo(KeyNamesInfo *info, struct xkb_context *ctx,
330 info->merge = MERGE_DEFAULT;
331 list_init(&info->leds);
332 list_init(&info->aliases);
333 info->file_id = file_id;
334 darray_init(info->names);
335 darray_init(info->files);
336 ClearKeyNamesInfo(info);
337 info->errorCount = 0;
342 FindKeyByLong(KeyNamesInfo * info, unsigned long name)
346 for (i = info->computedMin; i <= info->computedMax; i++)
347 if (darray_item(info->names, i) == name)
354 * Store the name of the key as a long in the info struct under the given
355 * keycode. If the same keys is referred to twice, print a warning.
356 * Note that the key's name is stored as a long, the keycode is the index.
359 AddKeyName(KeyNamesInfo *info, xkb_keycode_t kc, unsigned long name,
360 enum merge_mode merge, unsigned file_id, bool reportCollisions)
363 int verbosity = xkb_get_log_verbosity(info->ctx);
365 ResizeKeyNameArrays(info, kc);
367 if (kc < info->computedMin)
368 info->computedMin = kc;
369 if (kc > info->computedMax)
370 info->computedMax = kc;
372 if (reportCollisions)
373 reportCollisions = (verbosity > 7 ||
375 file_id == darray_item(info->files, kc)));
377 if (darray_item(info->names, kc) != 0) {
378 const char *lname = LongKeyNameText(darray_item(info->names, kc));
379 const char *kname = LongKeyNameText(name);
381 if (darray_item(info->names, kc) == name && reportCollisions) {
382 log_warn(info->ctx, "Multiple identical key name definitions; "
383 "Later occurences of \"%s = %d\" ignored\n", lname, kc);
387 if (merge == MERGE_AUGMENT) {
388 if (reportCollisions)
389 log_warn(info->ctx, "Multiple names for keycode %d; "
390 "Using %s, ignoring %s\n", kc, lname, kname);
394 if (reportCollisions)
395 log_warn(info->ctx, "Multiple names for keycode %d; "
396 "Using %s, ignoring %s\n", kc, kname, lname);
397 darray_item(info->names, kc) = 0;
398 darray_item(info->files, kc) = 0;
402 old = FindKeyByLong(info, name);
403 if (old != 0 && old != kc) {
404 const char *kname = LongKeyNameText(name);
406 if (merge == MERGE_OVERRIDE) {
407 darray_item(info->names, old) = 0;
408 darray_item(info->files, old) = 0;
409 if (reportCollisions)
410 log_warn(info->ctx, "Key name %s assigned to multiple keys; "
411 "Using %d, ignoring %d\n", kname, kc, old);
414 if (reportCollisions && verbosity > 3)
415 log_warn(info->ctx, "Key name %s assigned to multiple keys; "
416 "Using %d, ignoring %d\n", kname, old, kc);
421 darray_item(info->names, kc) = name;
422 darray_item(info->files, kc) = file_id;
426 /***====================================================================***/
429 HandleAliasDef(KeyNamesInfo *info, KeyAliasDef *def, enum merge_mode merge,
433 MergeAliases(KeyNamesInfo *into, KeyNamesInfo *from, enum merge_mode merge)
435 AliasInfo *alias, *next;
438 if (list_empty(&from->aliases))
441 if (list_empty(&into->aliases)) {
442 list_replace(&from->aliases, &into->aliases);
443 list_init(&from->aliases);
447 memset(&def, 0, sizeof(def));
449 list_foreach_safe(alias, next, &from->aliases, entry) {
450 def.merge = (merge == MERGE_DEFAULT) ? alias->merge : merge;
451 LongToKeyName(alias->alias, def.alias);
452 LongToKeyName(alias->real, def.real);
454 if (!HandleAliasDef(into, &def, def.merge, alias->file_id))
462 MergeIncludedKeycodes(KeyNamesInfo *into, KeyNamesInfo *from,
463 enum merge_mode merge)
466 IndicatorNameInfo *led;
468 if (from->errorCount > 0) {
469 into->errorCount += from->errorCount;
473 if (into->name == NULL) {
474 into->name = from->name;
478 ResizeKeyNameArrays(into, from->computedMax);
480 for (i = from->computedMin; i <= from->computedMax; i++) {
481 unsigned long name = darray_item(from->names, i);
485 if (!AddKeyName(into, i, name, merge, from->file_id, false))
489 list_foreach(led, &from->leds, entry) {
490 led->merge = (merge == MERGE_DEFAULT ? led->merge : merge);
491 if (!AddIndicatorName(into, led->merge, led))
495 if (!MergeAliases(into, from, merge))
498 if (from->explicitMin != 0)
499 if (into->explicitMin == 0 || into->explicitMin > from->explicitMin)
500 into->explicitMin = from->explicitMin;
502 if (from->explicitMax > 0)
503 if (into->explicitMax == 0 || into->explicitMax < from->explicitMax)
504 into->explicitMax = from->explicitMax;
508 HandleKeycodesFile(KeyNamesInfo *info, XkbFile *file, enum merge_mode merge);
511 * Handle the given include statement (e.g. "include "evdev+aliases(qwerty)").
513 * @param info Struct to store the key info in.
514 * @param stmt The include statement from the keymap file.
517 HandleIncludeKeycodes(KeyNamesInfo *info, IncludeStmt *stmt)
519 enum merge_mode merge = MERGE_DEFAULT;
521 KeyNamesInfo included, next_incl;
523 InitKeyNamesInfo(&included, info->ctx, info->file_id);
526 included.name = stmt->stmt;
530 for (; stmt; stmt = stmt->next_incl) {
531 if (!ProcessIncludeFile(info->ctx, stmt, FILE_TYPE_KEYCODES,
533 info->errorCount += 10;
534 ClearKeyNamesInfo(&included);
538 InitKeyNamesInfo(&next_incl, info->ctx, rtrn->id);
540 HandleKeycodesFile(&next_incl, rtrn, MERGE_OVERRIDE);
542 MergeIncludedKeycodes(&included, &next_incl, merge);
544 ClearKeyNamesInfo(&next_incl);
548 MergeIncludedKeycodes(info, &included, merge);
549 ClearKeyNamesInfo(&included);
551 return (info->errorCount == 0);
555 * Parse the given statement and store the output in the info struct.
559 HandleKeycodeDef(KeyNamesInfo *info, KeycodeDef *stmt, enum merge_mode merge)
561 if ((info->explicitMin != 0 && stmt->value < info->explicitMin) ||
562 (info->explicitMax != 0 && stmt->value > info->explicitMax)) {
563 log_err(info->ctx, "Illegal keycode %lu for name %s; "
564 "Must be in the range %d-%d inclusive\n",
565 stmt->value, KeyNameText(stmt->name), info->explicitMin,
566 info->explicitMax ? info->explicitMax : XKB_KEYCODE_MAX);
570 if (stmt->merge != MERGE_DEFAULT) {
571 if (stmt->merge == MERGE_REPLACE)
572 merge = MERGE_OVERRIDE;
577 return AddKeyName(info, stmt->value, KeyNameToLong(stmt->name), merge,
578 info->file_id, true);
582 HandleAliasCollision(KeyNamesInfo *info, AliasInfo *old, AliasInfo *new)
584 int verbosity = xkb_get_log_verbosity(info->ctx);
586 if (new->real == old->real) {
587 if ((new->file_id == old->file_id && verbosity > 0) || verbosity > 9)
588 log_warn(info->ctx, "Alias of %s for %s declared more than once; "
589 "First definition ignored\n",
590 LongKeyNameText(new->alias), LongKeyNameText(new->real));
593 unsigned long use, ignore;
595 if (new->merge == MERGE_AUGMENT) {
604 if ((old->file_id == new->file_id && verbosity > 0) || verbosity > 9)
605 log_warn(info->ctx, "Multiple definitions for alias %s; "
606 "Using %s, ignoring %s\n",
607 LongKeyNameText(old->alias), LongKeyNameText(use),
608 LongKeyNameText(ignore));
610 if (use != old->real)
614 old->file_id = new->file_id;
615 old->merge = new->merge;
619 HandleAliasDef(KeyNamesInfo *info, KeyAliasDef *def, enum merge_mode merge,
624 list_foreach(alias, &info->aliases, entry) {
625 if (alias->alias == KeyNameToLong(def->alias)) {
627 InitAliasInfo(&new, merge, file_id, def->alias, def->real);
628 HandleAliasCollision(info, alias, &new);
633 alias = calloc(1, sizeof(*alias));
635 log_wsgo(info->ctx, "Allocation failure in HandleAliasDef\n");
639 alias->file_id = file_id;
640 alias->merge = merge;
641 alias->alias = KeyNameToLong(def->alias);
642 alias->real = KeyNameToLong(def->real);
643 list_append(&alias->entry, &info->aliases);
648 #define MIN_KEYCODE_DEF 0
649 #define MAX_KEYCODE_DEF 1
652 * Handle the minimum/maximum statement of the xkb file.
653 * Sets explicitMin/Max of the info struct.
655 * @return 1 on success, 0 otherwise.
658 HandleKeyNameVar(KeyNamesInfo *info, VarDef *stmt)
660 const char *elem, *field;
665 if (!ExprResolveLhs(info->ctx, stmt->name, &elem, &field,
667 return false; /* internal error, already reported */
670 log_err(info->ctx, "Unknown element %s encountered; "
671 "Default for field %s ignored\n", elem, field);
675 if (istreq(field, "minimum")) {
676 which = MIN_KEYCODE_DEF;
678 else if (istreq(field, "maximum")) {
679 which = MAX_KEYCODE_DEF;
682 log_err(info->ctx, "Unknown field encountered; "
683 "Assigment to field %s ignored\n", field);
687 if (arrayNdx != NULL) {
688 log_err(info->ctx, "The %s setting is not an array; "
689 "Illegal array reference ignored\n", field);
693 if (!ExprResolveKeyCode(info->ctx, stmt->value, &kc)) {
694 log_err(info->ctx, "Illegal keycode encountered; "
695 "Assignment to field %s ignored\n", field);
699 if (kc > XKB_KEYCODE_MAX) {
701 "Illegal keycode %d (must be in the range %d-%d inclusive); "
702 "Value of \"%s\" not changed\n",
703 kc, 0, XKB_KEYCODE_MAX, field);
707 if (which == MIN_KEYCODE_DEF) {
708 if (info->explicitMax > 0 && info->explicitMax < kc) {
710 "Minimum key code (%d) must be <= maximum key code (%d); "
711 "Minimum key code value not changed\n",
712 kc, info->explicitMax);
716 if (info->computedMax > 0 && info->computedMin < kc) {
718 "Minimum key code (%d) must be <= lowest defined key (%d); "
719 "Minimum key code value not changed\n",
720 kc, info->computedMin);
724 info->explicitMin = kc;
726 else if (which == MAX_KEYCODE_DEF) {
727 if (info->explicitMin > 0 && info->explicitMin > kc) {
729 "Maximum code (%d) must be >= minimum key code (%d); "
730 "Maximum code value not changed\n",
731 kc, info->explicitMin);
735 if (info->computedMax > 0 && info->computedMax > kc) {
737 "Maximum code (%d) must be >= highest defined key (%d); "
738 "Maximum code value not changed\n",
739 kc, info->computedMax);
743 info->explicitMax = kc;
750 HandleIndicatorNameDef(KeyNamesInfo *info, IndicatorNameDef *def,
751 enum merge_mode merge)
753 IndicatorNameInfo ii;
756 if (def->ndx < 1 || def->ndx > XkbNumIndicators) {
759 "Name specified for illegal indicator index %d\n; Ignored\n",
764 InitIndicatorNameInfo(&ii, info);
766 if (!ExprResolveString(info->ctx, def->name, &str)) {
768 snprintf(buf, sizeof(buf), "%d", def->ndx);
770 return ReportBadType(info->ctx, "indicator", "name", buf,
774 ii.ndx = (xkb_led_index_t) def->ndx;
775 ii.name = xkb_atom_intern(info->ctx, str);
777 return AddIndicatorName(info, merge, &ii);
781 * Handle the xkb_keycodes section of a xkb file.
782 * All information about parsed keys is stored in the info struct.
784 * Such a section may have include statements, in which case this function is
785 * semi-recursive (it calls HandleIncludeKeycodes, which may call
786 * HandleKeycodesFile again).
788 * @param info Struct to contain the fully parsed key information.
789 * @param file The input file (parsed xkb_keycodes section)
790 * @param merge Merge strategy (MERGE_OVERRIDE, etc.)
793 HandleKeycodesFile(KeyNamesInfo *info, XkbFile *file, enum merge_mode merge)
799 info->name = strdup_safe(file->name);
801 for (stmt = file->defs; stmt; stmt = stmt->next) {
802 switch (stmt->type) {
803 case STMT_INCLUDE: /* e.g. include "evdev+aliases(qwerty)" */
804 ok = HandleIncludeKeycodes(info, (IncludeStmt *) stmt);
806 case STMT_KEYCODE: /* e.g. <ESC> = 9; */
807 ok = HandleKeycodeDef(info, (KeycodeDef *) stmt, merge);
809 case STMT_ALIAS: /* e.g. alias <MENU> = <COMP>; */
810 ok = HandleAliasDef(info, (KeyAliasDef *) stmt, merge,
813 case STMT_VAR: /* e.g. minimum, maximum */
814 ok = HandleKeyNameVar(info, (VarDef *) stmt);
816 case STMT_INDICATOR_NAME: /* e.g. indicator 1 = "Caps Lock"; */
817 ok = HandleIndicatorNameDef(info, (IndicatorNameDef *) stmt,
822 "Keycode files may define key and indicator names only; "
823 "Ignoring %s\n", stmt_type_to_string(stmt->type));
831 if (info->errorCount > 10) {
832 log_err(info->ctx, "Abandoning keycodes file \"%s\"\n",
840 ApplyAliases(KeyNamesInfo *info, struct xkb_keymap *keymap)
844 struct xkb_key_alias *old, *a;
845 AliasInfo *alias, *next;
848 nOld = darray_size(keymap->key_aliases);
849 old = &darray_item(keymap->key_aliases, 0);
851 list_foreach(alias, &info->aliases, entry) {
852 key = FindNamedKey(keymap, alias->real, false, 0);
854 log_lvl(info->ctx, 5,
855 "Attempt to alias %s to non-existent key %s; Ignored\n",
856 LongKeyNameText(alias->alias),
857 LongKeyNameText(alias->real));
862 key = FindNamedKey(keymap, alias->alias, false, 0);
864 log_lvl(info->ctx, 5,
865 "Attempt to create alias with the name of a real key; "
866 "Alias \"%s = %s\" ignored\n",
867 LongKeyNameText(alias->alias),
868 LongKeyNameText(alias->real));
878 for (i = 0, a = old; i < nOld; i++, a++) {
881 if (KeyNameToLong(a->alias) == alias->alias)
884 InitAliasInfo(&old_alias, MERGE_AUGMENT, 0, a->alias, a->real);
885 HandleAliasCollision(info, &old_alias, alias);
886 old_alias.real = KeyNameToLong(a->real);
896 darray_resize0(keymap->key_aliases, nOld + nNew);
898 a = &darray_item(keymap->key_aliases, nOld);
899 list_foreach(alias, &info->aliases, entry) {
900 if (alias->alias != 0) {
901 LongToKeyName(alias->alias, a->alias);
902 LongToKeyName(alias->real, a->real);
908 list_foreach_safe(alias, next, &info->aliases, entry)
910 list_init(&info->aliases);
914 CopyKeyNamesToKeymap(struct xkb_keymap *keymap, KeyNamesInfo *info)
917 IndicatorNameInfo *ii;
919 if (info->explicitMin > 0)
920 keymap->min_key_code = info->explicitMin;
922 keymap->min_key_code = info->computedMin;
924 if (info->explicitMax > 0)
925 keymap->max_key_code = info->explicitMax;
927 keymap->max_key_code = info->computedMax;
929 darray_resize0(keymap->keys, keymap->max_key_code + 1);
930 for (kc = info->computedMin; kc <= info->computedMax; kc++)
931 LongToKeyName(darray_item(info->names, kc),
932 XkbKey(keymap, kc)->name);
934 keymap->keycodes_section_name = strdup_safe(info->name);
936 list_foreach(ii, &info->leds, entry)
937 keymap->indicator_names[ii->ndx - 1] =
938 xkb_atom_text(keymap->ctx, ii->name);
940 ApplyAliases(info, keymap);
946 * Compile the xkb_keycodes section, parse it's output, return the results.
948 * @param file The parsed XKB file (may have include statements requiring
950 * @param result The effective keycodes, as gathered from the file.
951 * @param merge Merge strategy.
953 * @return true on success, false otherwise.
956 CompileKeycodes(XkbFile *file, struct xkb_keymap *keymap,
957 enum merge_mode merge)
961 InitKeyNamesInfo(&info, keymap->ctx, file->id);
963 HandleKeycodesFile(&info, file, merge);
964 if (info.errorCount != 0)
967 if (!CopyKeyNamesToKeymap(keymap, &info))
970 ClearKeyNamesInfo(&info);
974 ClearKeyNamesInfo(&info);
979 * Find the key with the given name.
981 * @param keymap The keymap to search in.
982 * @param name The 4-letter name of the key as a long.
983 * @param use_aliases true if the key aliases should be searched too.
984 * @param start_from Keycode to start searching from.
986 * @return the key if it is found, NULL otherwise.
989 FindNamedKey(struct xkb_keymap *keymap, unsigned long name,
990 bool use_aliases, xkb_keycode_t start_from)
994 if (start_from < keymap->min_key_code)
995 start_from = keymap->min_key_code;
996 else if (start_from > keymap->max_key_code)
999 xkb_foreach_key_from(key, keymap, start_from)
1000 if (KeyNameToLong(key->name) == name)
1004 unsigned long new_name;
1005 if (FindKeyNameForAlias(keymap, name, &new_name))
1006 return FindNamedKey(keymap, new_name, false, 0);
1013 FindKeyNameForAlias(struct xkb_keymap *keymap, unsigned long lname,
1014 unsigned long *real_name)
1016 char name[XkbKeyNameLength];
1017 struct xkb_key_alias *a;
1019 LongToKeyName(lname, name);
1020 darray_foreach(a, keymap->key_aliases) {
1021 if (strncmp(name, a->alias, XkbKeyNameLength) == 0) {
1022 *real_name = KeyNameToLong(a->real);