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 Ran Benita <ran234@gmail.com>
30 * Permission is hereby granted, free of charge, to any person obtaining a
31 * copy of this software and associated documentation files (the "Software"),
32 * to deal in the Software without restriction, including without limitation
33 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
34 * and/or sell copies of the Software, and to permit persons to whom the
35 * Software is furnished to do so, subject to the following conditions:
37 * The above copyright notice and this permission notice (including the next
38 * paragraph) shall be included in all copies or substantial portions of the
41 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
42 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
43 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
44 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
45 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
46 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
47 * DEALINGS IN THE SOFTWARE.
50 #include "xkbcomp-priv.h"
58 * The xkb_compat section
59 * =====================
60 * This section is the third to be processed, after xkb_keycodes and
63 * Interpret statements
64 * --------------------
65 * Statements of the form:
66 * interpret Num_Lock+Any { ... }
67 * interpret Shift_Lock+AnyOf(Shift+Lock) { ... }
69 * The xkb_symbols section (see symbols.c) allows the keymap author to do,
70 * among other things, the following for each key:
71 * - Bind an action, like SetMods or LockGroup, to the key. Actions, like
72 * symbols, are specified for each level of each group in the key
74 * - Add a virtual modifier to the key's virtual modifier mapping (vmodmap).
75 * - Specify whether the key should repeat or not.
77 * However, doing this for each key (or level) is tedious and inflexible.
78 * Interpret's are a mechanism to apply these settings to a bunch of
79 * keys/levels at once.
81 * Each interpret specifies a condition by which it attaches to certain
82 * levels. The condition consists of two parts:
83 * - A keysym. If the level has a different (or more than one) keysym, the
84 * match failes. Leaving out the keysym is equivalent to using the
85 * NoSymbol keysym, which always matches successfully.
86 * - A modifier predicate. The predicate consists of a matching operation
87 * and a mask of (real) modifiers. The modifers are matched against the
88 * key's modifier map (modmap). The matching operation can be one of the
90 * + AnyOfOrNone - The modmap must either be empty or include at least
91 * one of the specified modifiers.
92 * + AnyOf - The modmap must include at least one of the specified
94 * + NoneOf - The modmap must not include any of the specified modifiers.
95 * + AllOf - The modmap must include all of the specified modifiers (but
96 * may include others as well).
97 * + Exactly - The modmap must be exactly the same as the specified
99 * Leaving out the predicate is equivalent to usign AnyOfOrNone while
100 * specifying all modifiers. Leaving out just the matching condtition
101 * is equivalent to using Exactly.
102 * An interpret may also include "useModMapMods = level1;" - see below.
104 * If a level fulfils the conditions of several interpret's, only the
105 * most specific one is used:
106 * - A specific keysym will always match before a generic NoSymbol
108 * - If the keysyms are the same, the interpret with the more specific
109 * matching operation is used. The above list is sorted from least to
111 * - If both the keysyms and the matching operations are the same (but the
112 * modifiers are different), the first interpret is used.
114 * As described above, once an interpret "attaches" to a level, it can bind
115 * an action to that level, add one virtual modifier to the key's vmodmap,
116 * or set the key's repeat setting. You should note the following:
117 * - The key repeat is a property of the entire key; it is not level-specific.
118 * In order to avoid confusion, it is only inspected for the first level of
119 * the first group; the interpret's repeat setting is ignored when applied
121 * - If one of the above fields was set directly for a key in xkb_symbols,
122 * the explicit setting takes precedence over the interpret.
124 * The body of the statment may include statements of the following
125 * forms (all of which are optional):
127 * - useModMapMods statement:
128 * useModMapMods = level1;
130 * When set to 'level1', the interpret will only match levels which are
131 * the first level of the first group of the keys. This can be useful in
132 * conjunction with e.g. a virtualModifier statement.
134 * - action statement:
135 * action = LockMods(modifiers=NumLock);
137 * Bind this action to the matching levels.
139 * - virtual modifier statement:
140 * virtualModifier = NumLock;
142 * Add this virtual modifier to the key's vmodmap. The given virtual
143 * modifier must be declared at the top level of the file with a
144 * virtual_modifiers statement, e.g.:
145 * virtual_modifiers NumLock;
147 * - repeat statement:
150 * Set whether the key should repeat or not. Must be a boolean value.
153 * ------------------------
154 * Statements of the form:
155 * indicator "Shift Lock" { ... }
157 * This statement specifies the behavior and binding of the LED (a.k.a
158 * indicator) with the given name ("Shift Lock" above). The name should
159 * have been declared previously in the xkb_keycodes section (see Led
160 * name statement), and given an index there. If it wasn't, it is created
161 * with the next free index.
162 * The body of the statement describes the conditions of the keyboard
163 * state which will cause the LED to be lit. It may include the following
166 * - modifiers statment:
167 * modifiers = ScrollLock;
169 * If the given modifiers are in the required state (see below), the
172 * - whichModifierState statment:
173 * whichModState = Latched + Locked;
175 * Can be any combination of:
176 * base, latched, locked, effective
177 * any (i.e. all of the above)
178 * none (i.e. none of the above)
179 * compat (legacy value, treated as effective)
180 * This will cause the respective portion of the modifer state (see
181 * struct xkb_state) to be matched against the modifiers given in the
182 * "modifiers" statement.
184 * Here's a simple example:
185 * indicator "Num Lock" {
186 * modifiers = NumLock;
187 * whichModState = Locked;
189 * Whenever the NumLock modifier is locked, the Num Lock LED will light
193 * groups = All - group1;
195 * If the given groups are in the required state (see below), the led
198 * - whichGroupState statment:
199 * whichGroupState = Effective;
201 * Can be any combination of:
202 * base, latched, locked, effective
203 * any (i.e. all of the above)
204 * none (i.e. none of the above)
205 * This will cause the respective portion of the group state (see
206 * struct xkb_state) to be matched against the groups given in the
207 * "groups" statement.
209 * Note: the above conditions are disjunctive, i.e. if any of them are
210 * satisfied the led is lit.
212 * Virtual modifier statements
213 * ---------------------------
214 * Statements of the form:
215 * virtual_modifiers LControl;
217 * Can appear in the xkb_types, xkb_compat, xkb_symbols sections.
222 * After all of the xkb_compat sections have been compiled, the following
223 * members of struct xkb_keymap are finalized:
224 * darray(struct xkb_sym_interpret) sym_interprets;
225 * darray(struct xkb_led) leds;
226 * char *compat_section_name;
227 * TODO: virtual modifiers.
231 SI_FIELD_VIRTUAL_MOD = (1 << 0),
232 SI_FIELD_ACTION = (1 << 1),
233 SI_FIELD_AUTO_REPEAT = (1 << 2),
234 SI_FIELD_LEVEL_ONE_ONLY = (1 << 3),
238 enum si_field defined;
239 enum merge_mode merge;
241 struct xkb_sym_interpret interp;
245 LED_FIELD_MODS = (1 << 0),
246 LED_FIELD_GROUPS = (1 << 1),
247 LED_FIELD_CTRLS = (1 << 2),
251 enum led_field defined;
252 enum merge_mode merge;
260 SymInterpInfo default_interp;
261 darray(SymInterpInfo) interps;
263 darray(LedInfo) leds;
264 ActionsInfo *actions;
265 struct xkb_keymap *keymap;
269 siText(SymInterpInfo *si, CompatInfo *info)
271 char *buf = xkb_context_get_buffer(info->keymap->ctx, 128);
273 if (si == &info->default_interp)
276 snprintf(buf, 128, "%s+%s(%s)",
277 KeysymText(info->keymap->ctx, si->interp.sym),
278 SIMatchText(si->interp.match),
279 ModMaskText(info->keymap, si->interp.mods));
285 ReportSINotArray(CompatInfo *info, SymInterpInfo *si, const char *field)
287 return ReportNotArray(info->keymap->ctx, "symbol interpretation", field,
292 ReportSIBadType(CompatInfo *info, SymInterpInfo *si, const char *field,
295 return ReportBadType(info->keymap->ctx, "symbol interpretation", field,
296 siText(si, info), wanted);
300 ReportLedBadType(CompatInfo *info, LedInfo *ledi, const char *field,
303 return ReportBadType(info->keymap->ctx, "indicator map", field,
304 xkb_atom_text(info->keymap->ctx, ledi->led.name),
309 ReportLedNotArray(CompatInfo *info, LedInfo *ledi, const char *field)
311 return ReportNotArray(info->keymap->ctx, "indicator map", field,
312 xkb_atom_text(info->keymap->ctx, ledi->led.name));
316 InitCompatInfo(CompatInfo *info, struct xkb_keymap *keymap,
317 ActionsInfo *actions)
319 memset(info, 0, sizeof(*info));
320 info->keymap = keymap;
321 info->actions = actions;
322 info->default_interp.merge = MERGE_OVERRIDE;
323 info->default_interp.interp.virtual_mod = XKB_MOD_INVALID;
324 info->default_led.merge = MERGE_OVERRIDE;
328 ClearCompatInfo(CompatInfo *info)
331 darray_free(info->interps);
332 darray_free(info->leds);
335 static SymInterpInfo *
336 FindMatchingInterp(CompatInfo *info, SymInterpInfo *new)
340 darray_foreach(old, info->interps)
341 if (old->interp.sym == new->interp.sym &&
342 old->interp.mods == new->interp.mods &&
343 old->interp.match == new->interp.match)
350 UseNewInterpField(enum si_field field, SymInterpInfo *old, SymInterpInfo *new,
351 bool report, enum si_field *collide)
353 if (!(old->defined & field))
356 if (new->defined & field) {
360 if (new->merge != MERGE_AUGMENT)
368 AddInterp(CompatInfo *info, SymInterpInfo *new, bool same_file)
370 SymInterpInfo *old = FindMatchingInterp(info, new);
372 const int verbosity = xkb_context_get_log_verbosity(info->keymap->ctx);
373 const bool report = (same_file && verbosity > 0) || verbosity > 9;
374 enum si_field collide = 0;
376 if (new->merge == MERGE_REPLACE) {
378 log_warn(info->keymap->ctx,
379 "Multiple definitions for \"%s\"; "
380 "Earlier interpretation ignored\n",
386 if (UseNewInterpField(SI_FIELD_VIRTUAL_MOD, old, new, report,
388 old->interp.virtual_mod = new->interp.virtual_mod;
389 old->defined |= SI_FIELD_VIRTUAL_MOD;
391 if (UseNewInterpField(SI_FIELD_ACTION, old, new, report,
393 old->interp.action = new->interp.action;
394 old->defined |= SI_FIELD_ACTION;
396 if (UseNewInterpField(SI_FIELD_AUTO_REPEAT, old, new, report,
398 old->interp.repeat = new->interp.repeat;
399 old->defined |= SI_FIELD_AUTO_REPEAT;
401 if (UseNewInterpField(SI_FIELD_LEVEL_ONE_ONLY, old, new, report,
403 old->interp.level_one_only = new->interp.level_one_only;
404 old->defined |= SI_FIELD_LEVEL_ONE_ONLY;
408 log_warn(info->keymap->ctx,
409 "Multiple interpretations of \"%s\"; "
410 "Using %s definition for duplicate fields\n",
412 (new->merge != MERGE_AUGMENT ? "last" : "first"));
418 darray_append(info->interps, *new);
422 /***====================================================================***/
425 ResolveStateAndPredicate(ExprDef *expr, enum xkb_match_operation *pred_rtrn,
426 xkb_mod_mask_t *mods_rtrn, CompatInfo *info)
429 *pred_rtrn = MATCH_ANY_OR_NONE;
430 *mods_rtrn = MOD_REAL_MASK_ALL;
434 *pred_rtrn = MATCH_EXACTLY;
435 if (expr->op == EXPR_ACTION_DECL) {
436 const char *pred_txt = xkb_atom_text(info->keymap->ctx,
437 expr->value.action.name);
438 if (!LookupString(symInterpretMatchMaskNames, pred_txt, pred_rtrn)) {
439 log_err(info->keymap->ctx,
440 "Illegal modifier predicate \"%s\"; Ignored\n", pred_txt);
443 expr = expr->value.action.args;
445 else if (expr->op == EXPR_IDENT) {
446 const char *pred_txt = xkb_atom_text(info->keymap->ctx,
448 if (pred_txt && istreq(pred_txt, "any")) {
449 *pred_rtrn = MATCH_ANY;
450 *mods_rtrn = MOD_REAL_MASK_ALL;
455 return ExprResolveModMask(info->keymap, expr, MOD_REAL, mods_rtrn);
458 /***====================================================================***/
461 UseNewLEDField(enum led_field field, LedInfo *old, LedInfo *new,
462 bool report, enum led_field *collide)
464 if (!(old->defined & field))
467 if (new->defined & field) {
471 if (new->merge != MERGE_AUGMENT)
479 AddLedMap(CompatInfo *info, LedInfo *new, bool same_file)
482 enum led_field collide;
483 struct xkb_context *ctx = info->keymap->ctx;
484 const int verbosity = xkb_context_get_log_verbosity(ctx);
485 const bool report = (same_file && verbosity > 0) || verbosity > 9;
487 darray_foreach(old, info->leds) {
488 if (old->led.name != new->led.name)
491 if (old->led.mods.mods == new->led.mods.mods &&
492 old->led.groups == new->led.groups &&
493 old->led.ctrls == new->led.ctrls &&
494 old->led.which_mods == new->led.which_mods &&
495 old->led.which_groups == new->led.which_groups) {
496 old->defined |= new->defined;
500 if (new->merge == MERGE_REPLACE) {
502 log_warn(info->keymap->ctx,
503 "Map for indicator %s redefined; "
504 "Earlier definition ignored\n",
505 xkb_atom_text(ctx, old->led.name));
511 if (UseNewLEDField(LED_FIELD_MODS, old, new, report, &collide)) {
512 old->led.which_mods = new->led.which_mods;
513 old->led.mods = new->led.mods;
514 old->defined |= LED_FIELD_MODS;
516 if (UseNewLEDField(LED_FIELD_GROUPS, old, new, report, &collide)) {
517 old->led.which_groups = new->led.which_groups;
518 old->led.groups = new->led.groups;
519 old->defined |= LED_FIELD_GROUPS;
521 if (UseNewLEDField(LED_FIELD_CTRLS, old, new, report, &collide)) {
522 old->led.ctrls = new->led.ctrls;
523 old->defined |= LED_FIELD_CTRLS;
527 log_warn(info->keymap->ctx,
528 "Map for indicator %s redefined; "
529 "Using %s definition for duplicate fields\n",
530 xkb_atom_text(ctx, old->led.name),
531 (new->merge == MERGE_AUGMENT ? "first" : "last"));
537 darray_append(info->leds, *new);
542 MergeIncludedCompatMaps(CompatInfo *into, CompatInfo *from,
543 enum merge_mode merge)
548 if (from->errorCount > 0) {
549 into->errorCount += from->errorCount;
553 if (into->name == NULL) {
554 into->name = from->name;
558 darray_foreach(si, from->interps) {
559 si->merge = (merge == MERGE_DEFAULT ? si->merge : merge);
560 if (!AddInterp(into, si, false))
564 darray_foreach(ledi, from->leds) {
565 ledi->merge = (merge == MERGE_DEFAULT ? ledi->merge : merge);
566 if (!AddLedMap(into, ledi, false))
572 HandleCompatMapFile(CompatInfo *info, XkbFile *file, enum merge_mode merge);
575 HandleIncludeCompatMap(CompatInfo *info, IncludeStmt *include)
579 InitCompatInfo(&included, info->keymap, info->actions);
580 included.name = include->stmt;
581 include->stmt = NULL;
583 for (IncludeStmt *stmt = include; stmt; stmt = stmt->next_incl) {
584 CompatInfo next_incl;
587 file = ProcessIncludeFile(info->keymap->ctx, stmt, FILE_TYPE_COMPAT);
589 info->errorCount += 10;
590 ClearCompatInfo(&included);
594 InitCompatInfo(&next_incl, info->keymap, info->actions);
595 next_incl.default_interp = info->default_interp;
596 next_incl.default_interp.merge = stmt->merge;
597 next_incl.default_led = info->default_led;
598 next_incl.default_led.merge = stmt->merge;
600 HandleCompatMapFile(&next_incl, file, MERGE_OVERRIDE);
602 MergeIncludedCompatMaps(&included, &next_incl, stmt->merge);
604 ClearCompatInfo(&next_incl);
608 MergeIncludedCompatMaps(info, &included, include->merge);
609 ClearCompatInfo(&included);
611 return (info->errorCount == 0);
615 SetInterpField(CompatInfo *info, SymInterpInfo *si, const char *field,
616 ExprDef *arrayNdx, ExprDef *value)
618 struct xkb_keymap *keymap = info->keymap;
621 if (istreq(field, "action")) {
623 return ReportSINotArray(info, si, field);
625 if (!HandleActionDef(value, keymap, &si->interp.action, info->actions))
628 si->defined |= SI_FIELD_ACTION;
630 else if (istreq(field, "virtualmodifier") ||
631 istreq(field, "virtualmod")) {
633 return ReportSINotArray(info, si, field);
635 if (!ExprResolveMod(keymap, value, MOD_VIRT, &ndx))
636 return ReportSIBadType(info, si, field, "virtual modifier");
638 si->interp.virtual_mod = ndx;
639 si->defined |= SI_FIELD_VIRTUAL_MOD;
641 else if (istreq(field, "repeat")) {
645 return ReportSINotArray(info, si, field);
647 if (!ExprResolveBoolean(keymap->ctx, value, &set))
648 return ReportSIBadType(info, si, field, "boolean");
650 si->interp.repeat = set;
652 si->defined |= SI_FIELD_AUTO_REPEAT;
654 else if (istreq(field, "locking")) {
655 log_dbg(info->keymap->ctx,
656 "The \"locking\" field in symbol interpretation is unsupported; "
659 else if (istreq(field, "usemodmap") ||
660 istreq(field, "usemodmapmods")) {
664 return ReportSINotArray(info, si, field);
666 if (!ExprResolveEnum(keymap->ctx, value, &val, useModMapValueNames))
667 return ReportSIBadType(info, si, field, "level specification");
669 si->interp.level_one_only = !!val;
670 si->defined |= SI_FIELD_LEVEL_ONE_ONLY;
673 return ReportBadField(keymap->ctx, "symbol interpretation", field,
681 SetLedMapField(CompatInfo *info, LedInfo *ledi, const char *field,
682 ExprDef *arrayNdx, ExprDef *value)
685 struct xkb_keymap *keymap = info->keymap;
687 if (istreq(field, "modifiers") || istreq(field, "mods")) {
689 return ReportLedNotArray(info, ledi, field);
691 if (!ExprResolveModMask(keymap, value, MOD_BOTH, &ledi->led.mods.mods))
692 return ReportLedBadType(info, ledi, field, "modifier mask");
694 ledi->defined |= LED_FIELD_MODS;
696 else if (istreq(field, "groups")) {
700 return ReportLedNotArray(info, ledi, field);
702 if (!ExprResolveMask(keymap->ctx, value, &mask, groupMaskNames))
703 return ReportLedBadType(info, ledi, field, "group mask");
705 ledi->led.groups = mask;
706 ledi->defined |= LED_FIELD_GROUPS;
708 else if (istreq(field, "controls") || istreq(field, "ctrls")) {
712 return ReportLedNotArray(info, ledi, field);
714 if (!ExprResolveMask(keymap->ctx, value, &mask, ctrlMaskNames))
715 return ReportLedBadType(info, ledi, field, "controls mask");
717 ledi->led.ctrls = mask;
718 ledi->defined |= LED_FIELD_CTRLS;
720 else if (istreq(field, "allowexplicit")) {
721 log_dbg(info->keymap->ctx,
722 "The \"allowExplicit\" field in indicator statements is unsupported; "
725 else if (istreq(field, "whichmodstate") ||
726 istreq(field, "whichmodifierstate")) {
730 return ReportLedNotArray(info, ledi, field);
732 if (!ExprResolveMask(keymap->ctx, value, &mask,
733 modComponentMaskNames))
734 return ReportLedBadType(info, ledi, field,
735 "mask of modifier state components");
737 ledi->led.which_mods = mask;
739 else if (istreq(field, "whichgroupstate")) {
743 return ReportLedNotArray(info, ledi, field);
745 if (!ExprResolveMask(keymap->ctx, value, &mask,
746 groupComponentMaskNames))
747 return ReportLedBadType(info, ledi, field,
748 "mask of group state components");
750 ledi->led.which_groups = mask;
752 else if (istreq(field, "driveskbd") ||
753 istreq(field, "driveskeyboard") ||
754 istreq(field, "leddriveskbd") ||
755 istreq(field, "leddriveskeyboard") ||
756 istreq(field, "indicatordriveskbd") ||
757 istreq(field, "indicatordriveskeyboard")) {
758 log_dbg(info->keymap->ctx,
759 "The \"%s\" field in indicator statements is unsupported; "
762 else if (istreq(field, "index")) {
763 /* Users should see this, it might cause unexpected behavior. */
764 log_err(info->keymap->ctx,
765 "The \"index\" field in indicator statements is unsupported; "
769 log_err(info->keymap->ctx,
770 "Unknown field %s in map for %s indicator; "
771 "Definition ignored\n",
772 field, xkb_atom_text(keymap->ctx, ledi->led.name));
780 HandleGlobalVar(CompatInfo *info, VarDef *stmt)
782 const char *elem, *field;
786 if (!ExprResolveLhs(info->keymap->ctx, stmt->name, &elem, &field, &ndx))
788 else if (elem && istreq(elem, "interpret"))
789 ret = SetInterpField(info, &info->default_interp, field, ndx,
791 else if (elem && istreq(elem, "indicator"))
792 ret = SetLedMapField(info, &info->default_led, field, ndx,
795 ret = SetActionField(info->keymap, elem, field, ndx, stmt->value,
801 HandleInterpBody(CompatInfo *info, VarDef *def, SymInterpInfo *si)
804 const char *elem, *field;
807 for (; def; def = (VarDef *) def->common.next) {
808 if (def->name && def->name->op == EXPR_FIELD_REF) {
809 log_err(info->keymap->ctx,
810 "Cannot set a global default value from within an interpret statement; "
811 "Move statements to the global file scope\n");
816 ok = ExprResolveLhs(info->keymap->ctx, def->name, &elem, &field,
821 ok = SetInterpField(info, si, field, arrayNdx, def->value);
828 HandleInterpDef(CompatInfo *info, InterpDef *def, enum merge_mode merge)
830 enum xkb_match_operation pred;
834 if (!ResolveStateAndPredicate(def->match, &pred, &mods, info)) {
835 log_err(info->keymap->ctx,
836 "Couldn't determine matching modifiers; "
837 "Symbol interpretation ignored\n");
841 si = info->default_interp;
842 si.merge = merge = (def->merge == MERGE_DEFAULT ? merge : def->merge);
844 if (!LookupKeysym(def->sym, &si.interp.sym)) {
845 log_err(info->keymap->ctx,
846 "Could not resolve keysym %s; "
847 "Symbol interpretation ignored\n",
852 si.interp.match = pred;
853 si.interp.mods = mods;
855 if (!HandleInterpBody(info, def->def, &si)) {
860 if (!AddInterp(info, &si, true)) {
869 HandleLedMapDef(CompatInfo *info, LedMapDef *def, enum merge_mode merge)
875 if (def->merge != MERGE_DEFAULT)
878 ledi = info->default_led;
880 ledi.led.name = def->name;
883 for (var = def->body; var != NULL; var = (VarDef *) var->common.next) {
884 const char *elem, *field;
886 if (!ExprResolveLhs(info->keymap->ctx, var->name, &elem, &field,
893 log_err(info->keymap->ctx,
894 "Cannot set defaults for \"%s\" element in indicator map; "
895 "Assignment to %s.%s ignored\n", elem, elem, field);
899 ok = SetLedMapField(info, &ledi, field, arrayNdx, var->value) && ok;
904 return AddLedMap(info, &ledi, true);
910 HandleCompatMapFile(CompatInfo *info, XkbFile *file, enum merge_mode merge)
914 merge = (merge == MERGE_DEFAULT ? MERGE_AUGMENT : merge);
917 info->name = strdup_safe(file->name);
919 for (ParseCommon *stmt = file->defs; stmt; stmt = stmt->next) {
920 switch (stmt->type) {
922 ok = HandleIncludeCompatMap(info, (IncludeStmt *) stmt);
925 ok = HandleInterpDef(info, (InterpDef *) stmt, merge);
927 case STMT_GROUP_COMPAT:
928 log_dbg(info->keymap->ctx,
929 "The \"group\" statement in compat is unsupported; "
934 ok = HandleLedMapDef(info, (LedMapDef *) stmt, merge);
937 ok = HandleGlobalVar(info, (VarDef *) stmt);
940 ok = HandleVModDef(info->keymap, (VModDef *) stmt);
943 log_err(info->keymap->ctx,
944 "Compat files may not include other types; "
945 "Ignoring %s\n", stmt_type_to_string(stmt->type));
953 if (info->errorCount > 10) {
954 log_err(info->keymap->ctx,
955 "Abandoning compatibility map \"%s\"\n", file->topName);
961 /* Temporary struct for CopyInterps. */
963 darray(struct xkb_sym_interpret) sym_interprets;
967 CopyInterps(CompatInfo *info, bool needSymbol, enum xkb_match_operation pred,
968 struct collect *collect)
972 darray_foreach(si, info->interps)
973 if (si->interp.match == pred &&
974 (si->interp.sym != XKB_KEY_NoSymbol) == needSymbol)
975 darray_append(collect->sym_interprets, si->interp);
979 CopyLedMapDefs(CompatInfo *info)
984 struct xkb_keymap *keymap = info->keymap;
986 darray_foreach(ledi, info->leds) {
988 * Find the LED with the given name, if it was already declared
991 darray_enumerate(i, led, keymap->leds)
992 if (led->name == ledi->led.name)
995 /* Not previously declared; create it with next free index. */
996 if (i >= darray_size(keymap->leds)) {
998 "Indicator name \"%s\" was not declared in the keycodes section; "
999 "Adding new indicator\n",
1000 xkb_atom_text(keymap->ctx, ledi->led.name));
1002 darray_enumerate(i, led, keymap->leds)
1003 if (led->name == XKB_ATOM_NONE)
1006 if (i >= darray_size(keymap->leds)) {
1007 /* Not place to put it; ignore. */
1008 if (i >= XKB_MAX_LEDS) {
1009 log_err(keymap->ctx,
1010 "Too many indicators (maximum is %d); "
1011 "Indicator name \"%s\" ignored\n",
1013 xkb_atom_text(keymap->ctx, ledi->led.name));
1016 /* Add a new LED. */
1017 darray_resize(keymap->leds, i + 1);
1018 led = &darray_item(keymap->leds, i);
1023 if (led->groups != 0 && led->which_groups == 0)
1024 led->which_groups = XKB_STATE_LAYOUT_EFFECTIVE;
1025 if (led->mods.mods != 0 && led->which_mods == 0)
1026 led->which_mods = XKB_STATE_MODS_EFFECTIVE;
1031 CopyCompatToKeymap(struct xkb_keymap *keymap, CompatInfo *info)
1033 keymap->compat_section_name = strdup_safe(info->name);
1034 XkbEscapeMapName(keymap->compat_section_name);
1036 if (!darray_empty(info->interps)) {
1037 struct collect collect;
1038 darray_init(collect.sym_interprets);
1040 /* Most specific to least specific. */
1041 CopyInterps(info, true, MATCH_EXACTLY, &collect);
1042 CopyInterps(info, true, MATCH_ALL, &collect);
1043 CopyInterps(info, true, MATCH_NONE, &collect);
1044 CopyInterps(info, true, MATCH_ANY, &collect);
1045 CopyInterps(info, true, MATCH_ANY_OR_NONE, &collect);
1046 CopyInterps(info, false, MATCH_EXACTLY, &collect);
1047 CopyInterps(info, false, MATCH_ALL, &collect);
1048 CopyInterps(info, false, MATCH_NONE, &collect);
1049 CopyInterps(info, false, MATCH_ANY, &collect);
1050 CopyInterps(info, false, MATCH_ANY_OR_NONE, &collect);
1052 keymap->num_sym_interprets = darray_size(collect.sym_interprets);
1053 keymap->sym_interprets = darray_mem(collect.sym_interprets, 0);
1056 CopyLedMapDefs(info);
1062 CompileCompatMap(XkbFile *file, struct xkb_keymap *keymap,
1063 enum merge_mode merge)
1066 ActionsInfo *actions;
1068 actions = NewActionsInfo();
1072 InitCompatInfo(&info, keymap, actions);
1073 info.default_interp.merge = merge;
1074 info.default_led.merge = merge;
1076 HandleCompatMapFile(&info, file, merge);
1077 if (info.errorCount != 0)
1080 if (!CopyCompatToKeymap(keymap, &info))
1083 ClearCompatInfo(&info);
1084 FreeActionsInfo(actions);
1088 ClearCompatInfo(&info);
1089 FreeActionsInfo(actions);