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 * conjuction 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;
240 enum merge_mode merge;
242 struct xkb_sym_interpret interp;
246 LED_FIELD_MODS = (1 << 0),
247 LED_FIELD_GROUPS = (1 << 1),
248 LED_FIELD_CTRLS = (1 << 2),
252 enum led_field defined;
254 enum merge_mode merge;
263 SymInterpInfo default_interp;
264 darray(SymInterpInfo) interps;
266 darray(LedInfo) leds;
267 ActionsInfo *actions;
268 struct xkb_keymap *keymap;
272 siText(SymInterpInfo *si, CompatInfo *info)
274 char *buf = xkb_context_get_buffer(info->keymap->ctx, 128);
276 if (si == &info->default_interp)
279 snprintf(buf, 128, "%s+%s(%s)",
280 KeysymText(info->keymap->ctx, si->interp.sym),
281 SIMatchText(si->interp.match),
282 ModMaskText(info->keymap, si->interp.mods));
288 ReportSINotArray(CompatInfo *info, SymInterpInfo *si, const char *field)
290 return ReportNotArray(info->keymap, "symbol interpretation", field,
295 ReportSIBadType(CompatInfo *info, SymInterpInfo *si, const char *field,
298 return ReportBadType(info->keymap->ctx, "symbol interpretation", field,
299 siText(si, info), wanted);
303 ReportLedBadType(CompatInfo *info, LedInfo *ledi, const char *field,
306 return ReportBadType(info->keymap->ctx, "indicator map", field,
307 xkb_atom_text(info->keymap->ctx, ledi->led.name),
312 ReportLedNotArray(CompatInfo *info, LedInfo *ledi, const char *field)
314 return ReportNotArray(info->keymap, "indicator map", field,
315 xkb_atom_text(info->keymap->ctx, ledi->led.name));
319 InitCompatInfo(CompatInfo *info, struct xkb_keymap *keymap, unsigned file_id,
320 ActionsInfo *actions)
322 memset(info, 0, sizeof(*info));
323 info->keymap = keymap;
324 info->file_id = file_id;
325 info->actions = actions;
326 info->default_interp.file_id = file_id;
327 info->default_interp.merge = MERGE_OVERRIDE;
328 info->default_interp.interp.virtual_mod = XKB_MOD_INVALID;
329 info->default_led.file_id = file_id;
330 info->default_led.merge = MERGE_OVERRIDE;
334 ClearCompatInfo(CompatInfo *info)
337 darray_free(info->interps);
338 darray_free(info->leds);
341 static SymInterpInfo *
342 FindMatchingInterp(CompatInfo *info, SymInterpInfo *new)
346 darray_foreach(old, info->interps)
347 if (old->interp.sym == new->interp.sym &&
348 old->interp.mods == new->interp.mods &&
349 old->interp.match == new->interp.match)
356 UseNewInterpField(enum si_field field, SymInterpInfo *old, SymInterpInfo *new,
357 bool report, enum si_field *collide)
359 if (!(old->defined & field))
362 if (new->defined & field) {
366 if (new->merge != MERGE_AUGMENT)
374 AddInterp(CompatInfo *info, SymInterpInfo *new)
376 enum si_field collide = 0;
379 old = FindMatchingInterp(info, new);
381 int verbosity = xkb_context_get_log_verbosity(info->keymap->ctx);
382 bool report = ((old->file_id == new->file_id && verbosity > 0) ||
385 if (new->merge == MERGE_REPLACE) {
387 log_warn(info->keymap->ctx,
388 "Multiple definitions for \"%s\"; "
389 "Earlier interpretation ignored\n",
395 if (UseNewInterpField(SI_FIELD_VIRTUAL_MOD, old, new, report,
397 old->interp.virtual_mod = new->interp.virtual_mod;
398 old->defined |= SI_FIELD_VIRTUAL_MOD;
400 if (UseNewInterpField(SI_FIELD_ACTION, old, new, report,
402 old->interp.action = new->interp.action;
403 old->defined |= SI_FIELD_ACTION;
405 if (UseNewInterpField(SI_FIELD_AUTO_REPEAT, old, new, report,
407 old->interp.repeat = new->interp.repeat;
408 old->defined |= SI_FIELD_AUTO_REPEAT;
410 if (UseNewInterpField(SI_FIELD_LEVEL_ONE_ONLY, old, new, report,
412 old->interp.level_one_only = new->interp.level_one_only;
413 old->defined |= SI_FIELD_LEVEL_ONE_ONLY;
417 log_warn(info->keymap->ctx,
418 "Multiple interpretations of \"%s\"; "
419 "Using %s definition for duplicate fields\n",
421 (new->merge != MERGE_AUGMENT ? "last" : "first"));
427 darray_append(info->interps, *new);
432 /***====================================================================***/
435 ResolveStateAndPredicate(ExprDef *expr, enum xkb_match_operation *pred_rtrn,
436 xkb_mod_mask_t *mods_rtrn, CompatInfo *info)
439 *pred_rtrn = MATCH_ANY_OR_NONE;
440 *mods_rtrn = MOD_REAL_MASK_ALL;
444 *pred_rtrn = MATCH_EXACTLY;
445 if (expr->op == EXPR_ACTION_DECL) {
446 const char *pred_txt = xkb_atom_text(info->keymap->ctx,
447 expr->value.action.name);
448 if (!LookupString(symInterpretMatchMaskNames, pred_txt, pred_rtrn)) {
449 log_err(info->keymap->ctx,
450 "Illegal modifier predicate \"%s\"; Ignored\n", pred_txt);
453 expr = expr->value.action.args;
455 else if (expr->op == EXPR_IDENT) {
456 const char *pred_txt = xkb_atom_text(info->keymap->ctx,
458 if (pred_txt && istreq(pred_txt, "any")) {
459 *pred_rtrn = MATCH_ANY;
460 *mods_rtrn = MOD_REAL_MASK_ALL;
465 return ExprResolveModMask(info->keymap, expr, MOD_REAL, mods_rtrn);
468 /***====================================================================***/
471 UseNewLEDField(enum led_field field, LedInfo *old, LedInfo *new,
472 bool report, enum led_field *collide)
474 if (!(old->defined & field))
477 if (new->defined & field) {
481 if (new->merge != MERGE_AUGMENT)
489 AddLedMap(CompatInfo *info, LedInfo *new)
492 enum led_field collide;
493 struct xkb_context *ctx = info->keymap->ctx;
494 int verbosity = xkb_context_get_log_verbosity(ctx);
496 darray_foreach(old, info->leds) {
499 if (old->led.name != new->led.name)
502 if (old->led.mods.mods == new->led.mods.mods &&
503 old->led.groups == new->led.groups &&
504 old->led.ctrls == new->led.ctrls &&
505 old->led.which_mods == new->led.which_mods &&
506 old->led.which_groups == new->led.which_groups) {
507 old->defined |= new->defined;
511 report = ((old->file_id == new->file_id && verbosity > 0) ||
514 if (new->merge == MERGE_REPLACE) {
516 log_warn(info->keymap->ctx,
517 "Map for indicator %s redefined; "
518 "Earlier definition ignored\n",
519 xkb_atom_text(ctx, old->led.name));
525 if (UseNewLEDField(LED_FIELD_MODS, old, new, report, &collide)) {
526 old->led.which_mods = new->led.which_mods;
527 old->led.mods = new->led.mods;
528 old->defined |= LED_FIELD_MODS;
530 if (UseNewLEDField(LED_FIELD_GROUPS, old, new, report, &collide)) {
531 old->led.which_groups = new->led.which_groups;
532 old->led.groups = new->led.groups;
533 old->defined |= LED_FIELD_GROUPS;
535 if (UseNewLEDField(LED_FIELD_CTRLS, old, new, report, &collide)) {
536 old->led.ctrls = new->led.ctrls;
537 old->defined |= LED_FIELD_CTRLS;
541 log_warn(info->keymap->ctx,
542 "Map for indicator %s redefined; "
543 "Using %s definition for duplicate fields\n",
544 xkb_atom_text(ctx, old->led.name),
545 (new->merge == MERGE_AUGMENT ? "first" : "last"));
551 darray_append(info->leds, *new);
556 MergeIncludedCompatMaps(CompatInfo *into, CompatInfo *from,
557 enum merge_mode merge)
562 if (from->errorCount > 0) {
563 into->errorCount += from->errorCount;
567 if (into->name == NULL) {
568 into->name = from->name;
572 darray_foreach(si, from->interps) {
573 si->merge = (merge == MERGE_DEFAULT ? si->merge : merge);
574 if (!AddInterp(into, si))
578 darray_foreach(ledi, from->leds) {
579 ledi->merge = (merge == MERGE_DEFAULT ? ledi->merge : merge);
580 if (!AddLedMap(into, ledi))
586 HandleCompatMapFile(CompatInfo *info, XkbFile *file, enum merge_mode merge);
589 HandleIncludeCompatMap(CompatInfo *info, IncludeStmt *stmt)
591 enum merge_mode merge = MERGE_DEFAULT;
593 CompatInfo included, next_incl;
595 InitCompatInfo(&included, info->keymap, info->file_id, info->actions);
598 included.name = stmt->stmt;
602 for (; stmt; stmt = stmt->next_incl) {
603 if (!ProcessIncludeFile(info->keymap->ctx, stmt, FILE_TYPE_COMPAT,
605 info->errorCount += 10;
606 ClearCompatInfo(&included);
610 InitCompatInfo(&next_incl, info->keymap, rtrn->id, info->actions);
611 next_incl.file_id = rtrn->id;
612 next_incl.default_interp = info->default_interp;
613 next_incl.default_interp.file_id = rtrn->id;
614 next_incl.default_interp.merge = merge;
615 next_incl.default_led.file_id = rtrn->id;
616 next_incl.default_led.merge = merge;
618 HandleCompatMapFile(&next_incl, rtrn, MERGE_OVERRIDE);
620 MergeIncludedCompatMaps(&included, &next_incl, merge);
622 ClearCompatInfo(&next_incl);
626 MergeIncludedCompatMaps(info, &included, merge);
627 ClearCompatInfo(&included);
629 return (info->errorCount == 0);
633 SetInterpField(CompatInfo *info, SymInterpInfo *si, const char *field,
634 ExprDef *arrayNdx, ExprDef *value)
636 struct xkb_keymap *keymap = info->keymap;
639 if (istreq(field, "action")) {
641 return ReportSINotArray(info, si, field);
643 if (!HandleActionDef(value, keymap, &si->interp.action, info->actions))
646 si->defined |= SI_FIELD_ACTION;
648 else if (istreq(field, "virtualmodifier") ||
649 istreq(field, "virtualmod")) {
651 return ReportSINotArray(info, si, field);
653 if (!ExprResolveMod(keymap, value, MOD_VIRT, &ndx))
654 return ReportSIBadType(info, si, field, "virtual modifier");
656 si->interp.virtual_mod = ndx;
657 si->defined |= SI_FIELD_VIRTUAL_MOD;
659 else if (istreq(field, "repeat")) {
663 return ReportSINotArray(info, si, field);
665 if (!ExprResolveBoolean(keymap->ctx, value, &set))
666 return ReportSIBadType(info, si, field, "boolean");
668 si->interp.repeat = set;
670 si->defined |= SI_FIELD_AUTO_REPEAT;
672 else if (istreq(field, "locking")) {
673 log_dbg(info->keymap->ctx,
674 "The \"locking\" field in symbol interpretation is unsupported; "
677 else if (istreq(field, "usemodmap") ||
678 istreq(field, "usemodmapmods")) {
682 return ReportSINotArray(info, si, field);
684 if (!ExprResolveEnum(keymap->ctx, value, &val, useModMapValueNames))
685 return ReportSIBadType(info, si, field, "level specification");
687 si->interp.level_one_only = !!val;
688 si->defined |= SI_FIELD_LEVEL_ONE_ONLY;
691 return ReportBadField(keymap, "symbol interpretation", field,
699 SetLedMapField(CompatInfo *info, LedInfo *ledi, const char *field,
700 ExprDef *arrayNdx, ExprDef *value)
703 struct xkb_keymap *keymap = info->keymap;
705 if (istreq(field, "modifiers") || istreq(field, "mods")) {
707 return ReportLedNotArray(info, ledi, field);
709 if (!ExprResolveModMask(keymap, value, MOD_BOTH, &ledi->led.mods.mods))
710 return ReportLedBadType(info, ledi, field, "modifier mask");
712 ledi->defined |= LED_FIELD_MODS;
714 else if (istreq(field, "groups")) {
718 return ReportLedNotArray(info, ledi, field);
720 if (!ExprResolveMask(keymap->ctx, value, &mask, groupMaskNames))
721 return ReportLedBadType(info, ledi, field, "group mask");
723 ledi->led.groups = mask;
724 ledi->defined |= LED_FIELD_GROUPS;
726 else if (istreq(field, "controls") || istreq(field, "ctrls")) {
730 return ReportLedNotArray(info, ledi, field);
732 if (!ExprResolveMask(keymap->ctx, value, &mask, ctrlMaskNames))
733 return ReportLedBadType(info, ledi, field, "controls mask");
735 ledi->led.ctrls = mask;
736 ledi->defined |= LED_FIELD_CTRLS;
738 else if (istreq(field, "allowexplicit")) {
739 log_dbg(info->keymap->ctx,
740 "The \"allowExplicit\" field in indicator statements is unsupported; "
743 else if (istreq(field, "whichmodstate") ||
744 istreq(field, "whichmodifierstate")) {
748 return ReportLedNotArray(info, ledi, field);
750 if (!ExprResolveMask(keymap->ctx, value, &mask,
751 modComponentMaskNames))
752 return ReportLedBadType(info, ledi, field,
753 "mask of modifier state components");
755 ledi->led.which_mods = mask;
757 else if (istreq(field, "whichgroupstate")) {
761 return ReportLedNotArray(info, ledi, field);
763 if (!ExprResolveMask(keymap->ctx, value, &mask,
764 groupComponentMaskNames))
765 return ReportLedBadType(info, ledi, field,
766 "mask of group state components");
768 ledi->led.which_groups = mask;
770 else if (istreq(field, "driveskbd") ||
771 istreq(field, "driveskeyboard") ||
772 istreq(field, "leddriveskbd") ||
773 istreq(field, "leddriveskeyboard") ||
774 istreq(field, "indicatordriveskbd") ||
775 istreq(field, "indicatordriveskeyboard")) {
776 log_dbg(info->keymap->ctx,
777 "The \"%s\" field in indicator statements is unsupported; "
780 else if (istreq(field, "index")) {
781 /* Users should see this, it might cause unexpected behavior. */
782 log_err(info->keymap->ctx,
783 "The \"index\" field in indicator statements is unsupported; "
787 log_err(info->keymap->ctx,
788 "Unknown field %s in map for %s indicator; "
789 "Definition ignored\n",
790 field, xkb_atom_text(keymap->ctx, ledi->led.name));
798 HandleGlobalVar(CompatInfo *info, VarDef *stmt)
800 const char *elem, *field;
804 if (!ExprResolveLhs(info->keymap->ctx, stmt->name, &elem, &field, &ndx))
806 else if (elem && istreq(elem, "interpret"))
807 ret = SetInterpField(info, &info->default_interp, field, ndx,
809 else if (elem && istreq(elem, "indicator"))
810 ret = SetLedMapField(info, &info->default_led, field, ndx,
813 ret = SetActionField(info->keymap, elem, field, ndx, stmt->value,
819 HandleInterpBody(CompatInfo *info, VarDef *def, SymInterpInfo *si)
822 const char *elem, *field;
825 for (; def; def = (VarDef *) def->common.next) {
826 if (def->name && def->name->op == EXPR_FIELD_REF) {
827 log_err(info->keymap->ctx,
828 "Cannot set a global default value from within an interpret statement; "
829 "Move statements to the global file scope\n");
834 ok = ExprResolveLhs(info->keymap->ctx, def->name, &elem, &field,
839 ok = SetInterpField(info, si, field, arrayNdx, def->value);
846 HandleInterpDef(CompatInfo *info, InterpDef *def, enum merge_mode merge)
848 enum xkb_match_operation pred;
852 if (!ResolveStateAndPredicate(def->match, &pred, &mods, info)) {
853 log_err(info->keymap->ctx,
854 "Couldn't determine matching modifiers; "
855 "Symbol interpretation ignored\n");
859 si = info->default_interp;
860 si.merge = merge = (def->merge == MERGE_DEFAULT ? merge : def->merge);
862 if (!LookupKeysym(def->sym, &si.interp.sym)) {
863 log_err(info->keymap->ctx,
864 "Could not resolve keysym %s; "
865 "Symbol interpretation ignored\n",
870 si.interp.match = pred;
871 si.interp.mods = mods;
873 if (!HandleInterpBody(info, def->def, &si)) {
878 if (!AddInterp(info, &si)) {
887 HandleLedMapDef(CompatInfo *info, LedMapDef *def, enum merge_mode merge)
893 if (def->merge != MERGE_DEFAULT)
896 ledi = info->default_led;
898 ledi.led.name = def->name;
901 for (var = def->body; var != NULL; var = (VarDef *) var->common.next) {
902 const char *elem, *field;
904 if (!ExprResolveLhs(info->keymap->ctx, var->name, &elem, &field,
911 log_err(info->keymap->ctx,
912 "Cannot set defaults for \"%s\" element in indicator map; "
913 "Assignment to %s.%s ignored\n", elem, elem, field);
917 ok = SetLedMapField(info, &ledi, field, arrayNdx, var->value) && ok;
922 return AddLedMap(info, &ledi);
928 HandleCompatMapFile(CompatInfo *info, XkbFile *file, enum merge_mode merge)
933 merge = (merge == MERGE_DEFAULT ? MERGE_AUGMENT : merge);
936 info->name = strdup_safe(file->name);
938 for (stmt = file->defs; stmt; stmt = stmt->next) {
939 switch (stmt->type) {
941 ok = HandleIncludeCompatMap(info, (IncludeStmt *) stmt);
944 ok = HandleInterpDef(info, (InterpDef *) stmt, merge);
946 case STMT_GROUP_COMPAT:
947 log_dbg(info->keymap->ctx,
948 "The \"group\" statement in compat is unsupported; "
953 ok = HandleLedMapDef(info, (LedMapDef *) stmt, merge);
956 ok = HandleGlobalVar(info, (VarDef *) stmt);
959 ok = HandleVModDef(info->keymap, (VModDef *) stmt);
962 log_err(info->keymap->ctx,
963 "Interpretation files may not include other types; "
964 "Ignoring %s\n", stmt_type_to_string(stmt->type));
972 if (info->errorCount > 10) {
973 log_err(info->keymap->ctx,
974 "Abandoning compatibility map \"%s\"\n", file->topName);
981 CopyInterps(CompatInfo *info, bool needSymbol, enum xkb_match_operation pred)
985 darray_foreach(si, info->interps)
986 if (si->interp.match == pred &&
987 (si->interp.sym != XKB_KEY_NoSymbol) == needSymbol)
988 darray_append(info->keymap->sym_interprets, si->interp);
992 CopyLedMapDefs(CompatInfo *info)
997 struct xkb_keymap *keymap = info->keymap;
999 darray_foreach(ledi, info->leds) {
1001 * Find the LED with the given name, if it was already declared
1004 darray_enumerate(i, led, keymap->leds)
1005 if (led->name == ledi->led.name)
1008 /* Not previously declared; create it with next free index. */
1009 if (i >= darray_size(keymap->leds)) {
1010 log_dbg(keymap->ctx,
1011 "Indicator name \"%s\" was not declared in the keycodes section; "
1012 "Adding new indicator\n",
1013 xkb_atom_text(keymap->ctx, ledi->led.name));
1015 darray_enumerate(i, led, keymap->leds)
1016 if (led->name == XKB_ATOM_NONE)
1019 if (i >= darray_size(keymap->leds)) {
1020 /* Not place to put it; ignore. */
1021 if (i >= XKB_MAX_LEDS) {
1022 log_err(keymap->ctx,
1023 "Too many indicators (maximum is %d); "
1024 "Indicator name \"%s\" ignored\n",
1026 xkb_atom_text(keymap->ctx, ledi->led.name));
1029 /* Add a new LED. */
1030 darray_resize(keymap->leds, i + 1);
1031 led = &darray_item(keymap->leds, i);
1036 if (led->groups != 0 && led->which_groups == 0)
1037 led->which_groups = XKB_STATE_LAYOUT_EFFECTIVE;
1038 if (led->mods.mods != 0 && led->which_mods == 0)
1039 led->which_mods = XKB_STATE_MODS_EFFECTIVE;
1044 CopyCompatToKeymap(struct xkb_keymap *keymap, CompatInfo *info)
1046 keymap->compat_section_name = strdup_safe(info->name);
1048 if (!darray_empty(info->interps)) {
1049 /* Most specific to least specific. */
1050 CopyInterps(info, true, MATCH_EXACTLY);
1051 CopyInterps(info, true, MATCH_ALL);
1052 CopyInterps(info, true, MATCH_NONE);
1053 CopyInterps(info, true, MATCH_ANY);
1054 CopyInterps(info, true, MATCH_ANY_OR_NONE);
1055 CopyInterps(info, false, MATCH_EXACTLY);
1056 CopyInterps(info, false, MATCH_ALL);
1057 CopyInterps(info, false, MATCH_NONE);
1058 CopyInterps(info, false, MATCH_ANY);
1059 CopyInterps(info, false, MATCH_ANY_OR_NONE);
1062 CopyLedMapDefs(info);
1068 CompileCompatMap(XkbFile *file, struct xkb_keymap *keymap,
1069 enum merge_mode merge)
1072 ActionsInfo *actions;
1074 actions = NewActionsInfo();
1078 InitCompatInfo(&info, keymap, file->id, actions);
1079 info.default_interp.merge = merge;
1080 info.default_led.merge = merge;
1082 HandleCompatMapFile(&info, file, merge);
1083 if (info.errorCount != 0)
1086 if (!CopyCompatToKeymap(keymap, &info))
1089 ClearCompatInfo(&info);
1090 FreeActionsInfo(actions);
1094 ClearCompatInfo(&info);
1095 FreeActionsInfo(actions);