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.
152 * Indicator map statements
153 * ------------------------
154 * Statements of the form:
155 * indicator "Shift Lock" { ... }
157 * This statement specifies the behavior and binding of the indicator
158 * with the given name ("Shift Lock" above). The name should have been
159 * declared previously in the xkb_keycodes section (see Indicator name
160 * 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 indicator to be lit. It may include the
164 * following statements:
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 indicator
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_indicator_map) indicators;
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;
256 struct xkb_indicator_map im;
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->dflt)
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 ReportIndicatorBadType(CompatInfo *info, LEDInfo *led,
304 const char *field, const char *wanted)
306 return ReportBadType(info->keymap->ctx, "indicator map", field,
307 xkb_atom_text(info->keymap->ctx, led->im.name),
312 ReportIndicatorNotArray(CompatInfo *info, LEDInfo *led,
315 return ReportNotArray(info->keymap, "indicator map", field,
316 xkb_atom_text(info->keymap->ctx, led->im.name));
320 InitCompatInfo(CompatInfo *info, struct xkb_keymap *keymap, unsigned file_id,
321 ActionsInfo *actions)
323 memset(info, 0, sizeof(*info));
324 info->keymap = keymap;
325 info->file_id = file_id;
326 info->actions = actions;
327 info->dflt.file_id = file_id;
328 info->dflt.merge = MERGE_OVERRIDE;
329 info->dflt.interp.virtual_mod = XKB_MOD_INVALID;
330 info->ledDflt.file_id = file_id;
331 info->ledDflt.merge = MERGE_OVERRIDE;
335 ClearCompatInfo(CompatInfo *info)
338 darray_free(info->interps);
339 darray_free(info->leds);
342 static SymInterpInfo *
343 FindMatchingInterp(CompatInfo *info, SymInterpInfo *new)
347 darray_foreach(old, info->interps)
348 if (old->interp.sym == new->interp.sym &&
349 old->interp.mods == new->interp.mods &&
350 old->interp.match == new->interp.match)
357 UseNewInterpField(enum si_field field, SymInterpInfo *old, SymInterpInfo *new,
358 bool report, enum si_field *collide)
360 if (!(old->defined & field))
363 if (new->defined & field) {
367 if (new->merge != MERGE_AUGMENT)
375 AddInterp(CompatInfo *info, SymInterpInfo *new)
377 enum si_field collide = 0;
380 old = FindMatchingInterp(info, new);
382 int verbosity = xkb_context_get_log_verbosity(info->keymap->ctx);
383 bool report = ((old->file_id == new->file_id && verbosity > 0) ||
386 if (new->merge == MERGE_REPLACE) {
388 log_warn(info->keymap->ctx,
389 "Multiple definitions for \"%s\"; "
390 "Earlier interpretation ignored\n",
396 if (UseNewInterpField(SI_FIELD_VIRTUAL_MOD, old, new, report,
398 old->interp.virtual_mod = new->interp.virtual_mod;
399 old->defined |= SI_FIELD_VIRTUAL_MOD;
401 if (UseNewInterpField(SI_FIELD_ACTION, old, new, report,
403 old->interp.action = new->interp.action;
404 old->defined |= SI_FIELD_ACTION;
406 if (UseNewInterpField(SI_FIELD_AUTO_REPEAT, old, new, report,
408 old->interp.repeat = new->interp.repeat;
409 old->defined |= SI_FIELD_AUTO_REPEAT;
411 if (UseNewInterpField(SI_FIELD_LEVEL_ONE_ONLY, old, new, report,
413 old->interp.level_one_only = new->interp.level_one_only;
414 old->defined |= SI_FIELD_LEVEL_ONE_ONLY;
418 log_warn(info->keymap->ctx,
419 "Multiple interpretations of \"%s\"; "
420 "Using %s definition for duplicate fields\n",
422 (new->merge != MERGE_AUGMENT ? "last" : "first"));
428 darray_append(info->interps, *new);
433 /***====================================================================***/
436 ResolveStateAndPredicate(ExprDef *expr, enum xkb_match_operation *pred_rtrn,
437 xkb_mod_mask_t *mods_rtrn, CompatInfo *info)
440 *pred_rtrn = MATCH_ANY_OR_NONE;
441 *mods_rtrn = MOD_REAL_MASK_ALL;
445 *pred_rtrn = MATCH_EXACTLY;
446 if (expr->op == EXPR_ACTION_DECL) {
447 const char *pred_txt = xkb_atom_text(info->keymap->ctx,
448 expr->value.action.name);
449 if (!LookupString(symInterpretMatchMaskNames, pred_txt, pred_rtrn)) {
450 log_err(info->keymap->ctx,
451 "Illegal modifier predicate \"%s\"; Ignored\n", pred_txt);
454 expr = expr->value.action.args;
456 else if (expr->op == EXPR_IDENT) {
457 const char *pred_txt = xkb_atom_text(info->keymap->ctx,
459 if (pred_txt && istreq(pred_txt, "any")) {
460 *pred_rtrn = MATCH_ANY;
461 *mods_rtrn = MOD_REAL_MASK_ALL;
466 return ExprResolveModMask(info->keymap, expr, MOD_REAL, mods_rtrn);
469 /***====================================================================***/
472 UseNewLEDField(enum led_field field, LEDInfo *old, LEDInfo *new,
473 bool report, enum led_field *collide)
475 if (!(old->defined & field))
478 if (new->defined & field) {
482 if (new->merge != MERGE_AUGMENT)
490 AddIndicatorMap(CompatInfo *info, LEDInfo *new)
493 enum led_field collide;
494 struct xkb_context *ctx = info->keymap->ctx;
495 int verbosity = xkb_context_get_log_verbosity(ctx);
497 darray_foreach(old, info->leds) {
500 if (old->im.name != new->im.name)
503 if (old->im.mods.mods == new->im.mods.mods &&
504 old->im.groups == new->im.groups &&
505 old->im.ctrls == new->im.ctrls &&
506 old->im.which_mods == new->im.which_mods &&
507 old->im.which_groups == new->im.which_groups) {
508 old->defined |= new->defined;
512 report = ((old->file_id == new->file_id && verbosity > 0) ||
515 if (new->merge == MERGE_REPLACE) {
517 log_warn(info->keymap->ctx,
518 "Map for indicator %s redefined; "
519 "Earlier definition ignored\n",
520 xkb_atom_text(ctx, old->im.name));
526 if (UseNewLEDField(LED_FIELD_MODS, old, new, report, &collide)) {
527 old->im.which_mods = new->im.which_mods;
528 old->im.mods = new->im.mods;
529 old->defined |= LED_FIELD_MODS;
531 if (UseNewLEDField(LED_FIELD_GROUPS, old, new, report, &collide)) {
532 old->im.which_groups = new->im.which_groups;
533 old->im.groups = new->im.groups;
534 old->defined |= LED_FIELD_GROUPS;
536 if (UseNewLEDField(LED_FIELD_CTRLS, old, new, report, &collide)) {
537 old->im.ctrls = new->im.ctrls;
538 old->defined |= LED_FIELD_CTRLS;
542 log_warn(info->keymap->ctx,
543 "Map for indicator %s redefined; "
544 "Using %s definition for duplicate fields\n",
545 xkb_atom_text(ctx, old->im.name),
546 (new->merge == MERGE_AUGMENT ? "first" : "last"));
552 darray_append(info->leds, *new);
557 MergeIncludedCompatMaps(CompatInfo *into, CompatInfo *from,
558 enum merge_mode merge)
563 if (from->errorCount > 0) {
564 into->errorCount += from->errorCount;
568 if (into->name == NULL) {
569 into->name = from->name;
573 darray_foreach(si, from->interps) {
574 si->merge = (merge == MERGE_DEFAULT ? si->merge : merge);
575 if (!AddInterp(into, si))
579 darray_foreach(led, from->leds) {
580 led->merge = (merge == MERGE_DEFAULT ? led->merge : merge);
581 if (!AddIndicatorMap(into, led))
587 HandleCompatMapFile(CompatInfo *info, XkbFile *file, enum merge_mode merge);
590 HandleIncludeCompatMap(CompatInfo *info, IncludeStmt *stmt)
592 enum merge_mode merge = MERGE_DEFAULT;
594 CompatInfo included, next_incl;
596 InitCompatInfo(&included, info->keymap, info->file_id, info->actions);
599 included.name = stmt->stmt;
603 for (; stmt; stmt = stmt->next_incl) {
604 if (!ProcessIncludeFile(info->keymap->ctx, stmt, FILE_TYPE_COMPAT,
606 info->errorCount += 10;
607 ClearCompatInfo(&included);
611 InitCompatInfo(&next_incl, info->keymap, rtrn->id, info->actions);
612 next_incl.file_id = rtrn->id;
613 next_incl.dflt = info->dflt;
614 next_incl.dflt.file_id = rtrn->id;
615 next_incl.dflt.merge = merge;
616 next_incl.ledDflt.file_id = rtrn->id;
617 next_incl.ledDflt.merge = merge;
619 HandleCompatMapFile(&next_incl, rtrn, MERGE_OVERRIDE);
621 MergeIncludedCompatMaps(&included, &next_incl, merge);
623 ClearCompatInfo(&next_incl);
627 MergeIncludedCompatMaps(info, &included, merge);
628 ClearCompatInfo(&included);
630 return (info->errorCount == 0);
634 SetInterpField(CompatInfo *info, SymInterpInfo *si, const char *field,
635 ExprDef *arrayNdx, ExprDef *value)
637 struct xkb_keymap *keymap = info->keymap;
640 if (istreq(field, "action")) {
642 return ReportSINotArray(info, si, field);
644 if (!HandleActionDef(value, keymap, &si->interp.action, info->actions))
647 si->defined |= SI_FIELD_ACTION;
649 else if (istreq(field, "virtualmodifier") ||
650 istreq(field, "virtualmod")) {
652 return ReportSINotArray(info, si, field);
654 if (!ExprResolveMod(keymap, value, MOD_VIRT, &ndx))
655 return ReportSIBadType(info, si, field, "virtual modifier");
657 si->interp.virtual_mod = ndx;
658 si->defined |= SI_FIELD_VIRTUAL_MOD;
660 else if (istreq(field, "repeat")) {
664 return ReportSINotArray(info, si, field);
666 if (!ExprResolveBoolean(keymap->ctx, value, &set))
667 return ReportSIBadType(info, si, field, "boolean");
669 si->interp.repeat = set;
671 si->defined |= SI_FIELD_AUTO_REPEAT;
673 else if (istreq(field, "locking")) {
674 log_dbg(info->keymap->ctx,
675 "The \"locking\" field in symbol interpretation is unsupported; "
678 else if (istreq(field, "usemodmap") ||
679 istreq(field, "usemodmapmods")) {
683 return ReportSINotArray(info, si, field);
685 if (!ExprResolveEnum(keymap->ctx, value, &val, useModMapValueNames))
686 return ReportSIBadType(info, si, field, "level specification");
688 si->interp.level_one_only = !!val;
689 si->defined |= SI_FIELD_LEVEL_ONE_ONLY;
692 return ReportBadField(keymap, "symbol interpretation", field,
700 SetIndicatorMapField(CompatInfo *info, LEDInfo *led,
701 const char *field, ExprDef *arrayNdx, ExprDef *value)
704 struct xkb_keymap *keymap = info->keymap;
706 if (istreq(field, "modifiers") || istreq(field, "mods")) {
708 return ReportIndicatorNotArray(info, led, field);
710 if (!ExprResolveModMask(keymap, value, MOD_BOTH, &led->im.mods.mods))
711 return ReportIndicatorBadType(info, led, field, "modifier mask");
713 led->defined |= LED_FIELD_MODS;
715 else if (istreq(field, "groups")) {
719 return ReportIndicatorNotArray(info, led, field);
721 if (!ExprResolveMask(keymap->ctx, value, &mask, groupMaskNames))
722 return ReportIndicatorBadType(info, led, field, "group mask");
724 led->im.groups = mask;
725 led->defined |= LED_FIELD_GROUPS;
727 else if (istreq(field, "controls") || istreq(field, "ctrls")) {
731 return ReportIndicatorNotArray(info, led, field);
733 if (!ExprResolveMask(keymap->ctx, value, &mask, ctrlMaskNames))
734 return ReportIndicatorBadType(info, led, field,
737 led->im.ctrls = mask;
738 led->defined |= LED_FIELD_CTRLS;
740 else if (istreq(field, "allowexplicit")) {
741 log_dbg(info->keymap->ctx,
742 "The \"allowExplicit\" field in indicator statements is unsupported; "
745 else if (istreq(field, "whichmodstate") ||
746 istreq(field, "whichmodifierstate")) {
750 return ReportIndicatorNotArray(info, led, field);
752 if (!ExprResolveMask(keymap->ctx, value, &mask,
753 modComponentMaskNames))
754 return ReportIndicatorBadType(info, led, field,
755 "mask of modifier state components");
757 led->im.which_mods = mask;
759 else if (istreq(field, "whichgroupstate")) {
763 return ReportIndicatorNotArray(info, led, field);
765 if (!ExprResolveMask(keymap->ctx, value, &mask,
766 groupComponentMaskNames))
767 return ReportIndicatorBadType(info, led, field,
768 "mask of group state components");
770 led->im.which_groups = mask;
772 else if (istreq(field, "driveskbd") ||
773 istreq(field, "driveskeyboard") ||
774 istreq(field, "leddriveskbd") ||
775 istreq(field, "leddriveskeyboard") ||
776 istreq(field, "indicatordriveskbd") ||
777 istreq(field, "indicatordriveskeyboard")) {
778 log_dbg(info->keymap->ctx,
779 "The \"%s\" field in indicator statements is unsupported; "
782 else if (istreq(field, "index")) {
783 /* Users should see this, it might cause unexpected behavior. */
784 log_err(info->keymap->ctx,
785 "The \"index\" field in indicator statements is unsupported; "
789 log_err(info->keymap->ctx,
790 "Unknown field %s in map for %s indicator; "
791 "Definition ignored\n",
792 field, xkb_atom_text(keymap->ctx, led->im.name));
800 HandleGlobalVar(CompatInfo *info, VarDef *stmt)
802 const char *elem, *field;
806 if (!ExprResolveLhs(info->keymap->ctx, stmt->name, &elem, &field, &ndx))
808 else if (elem && istreq(elem, "interpret"))
809 ret = SetInterpField(info, &info->dflt, field, ndx, stmt->value);
810 else if (elem && istreq(elem, "indicator"))
811 ret = SetIndicatorMapField(info, &info->ledDflt, field, ndx,
814 ret = SetActionField(info->keymap, elem, field, ndx, stmt->value,
820 HandleInterpBody(CompatInfo *info, VarDef *def, SymInterpInfo *si)
823 const char *elem, *field;
826 for (; def; def = (VarDef *) def->common.next) {
827 if (def->name && def->name->op == EXPR_FIELD_REF) {
828 log_err(info->keymap->ctx,
829 "Cannot set a global default value from within an interpret statement; "
830 "Move statements to the global file scope\n");
835 ok = ExprResolveLhs(info->keymap->ctx, def->name, &elem, &field,
840 ok = SetInterpField(info, si, field, arrayNdx, def->value);
847 HandleInterpDef(CompatInfo *info, InterpDef *def, enum merge_mode merge)
849 enum xkb_match_operation pred;
853 if (!ResolveStateAndPredicate(def->match, &pred, &mods, info)) {
854 log_err(info->keymap->ctx,
855 "Couldn't determine matching modifiers; "
856 "Symbol interpretation ignored\n");
861 si.merge = merge = (def->merge == MERGE_DEFAULT ? merge : def->merge);
863 if (!LookupKeysym(def->sym, &si.interp.sym)) {
864 log_err(info->keymap->ctx,
865 "Could not resolve keysym %s; "
866 "Symbol interpretation ignored\n",
871 si.interp.match = pred;
872 si.interp.mods = mods;
874 if (!HandleInterpBody(info, def->def, &si)) {
879 if (!AddInterp(info, &si)) {
888 HandleIndicatorMapDef(CompatInfo *info, IndicatorMapDef *def,
889 enum merge_mode merge)
895 if (def->merge != MERGE_DEFAULT)
900 led.im.name = def->name;
903 for (var = def->body; var != NULL; var = (VarDef *) var->common.next) {
904 const char *elem, *field;
906 if (!ExprResolveLhs(info->keymap->ctx, var->name, &elem, &field,
913 log_err(info->keymap->ctx,
914 "Cannot set defaults for \"%s\" element in indicator map; "
915 "Assignment to %s.%s ignored\n", elem, elem, field);
919 ok = SetIndicatorMapField(info, &led, field, arrayNdx,
925 return AddIndicatorMap(info, &led);
931 HandleCompatMapFile(CompatInfo *info, XkbFile *file, enum merge_mode merge)
936 merge = (merge == MERGE_DEFAULT ? MERGE_AUGMENT : merge);
939 info->name = strdup_safe(file->name);
941 for (stmt = file->defs; stmt; stmt = stmt->next) {
942 switch (stmt->type) {
944 ok = HandleIncludeCompatMap(info, (IncludeStmt *) stmt);
947 ok = HandleInterpDef(info, (InterpDef *) stmt, merge);
949 case STMT_GROUP_COMPAT:
950 log_dbg(info->keymap->ctx,
951 "The \"group\" statement in compat is unsupported; "
955 case STMT_INDICATOR_MAP:
956 ok = HandleIndicatorMapDef(info, (IndicatorMapDef *) stmt, merge);
959 ok = HandleGlobalVar(info, (VarDef *) stmt);
962 ok = HandleVModDef(info->keymap, (VModDef *) stmt);
965 log_err(info->keymap->ctx,
966 "Interpretation files may not include other types; "
967 "Ignoring %s\n", stmt_type_to_string(stmt->type));
975 if (info->errorCount > 10) {
976 log_err(info->keymap->ctx,
977 "Abandoning compatibility map \"%s\"\n", file->topName);
984 CopyInterps(CompatInfo *info, bool needSymbol, enum xkb_match_operation pred)
988 darray_foreach(si, info->interps)
989 if (si->interp.match == pred &&
990 (si->interp.sym != XKB_KEY_NoSymbol) == needSymbol)
991 darray_append(info->keymap->sym_interprets, si->interp);
995 CopyIndicatorMapDefs(CompatInfo *info)
999 struct xkb_indicator_map *im;
1000 struct xkb_keymap *keymap = info->keymap;
1002 darray_foreach(led, info->leds) {
1004 * Find the indicator with the given name, if it was already
1005 * declared in keycodes.
1007 darray_enumerate(i, im, keymap->indicators)
1008 if (im->name == led->im.name)
1011 /* Not previously declared; create it with next free index. */
1012 if (i >= darray_size(keymap->indicators)) {
1013 log_dbg(keymap->ctx,
1014 "Indicator name \"%s\" was not declared in the keycodes section; "
1015 "Adding new indicator\n",
1016 xkb_atom_text(keymap->ctx, led->im.name));
1018 darray_enumerate(i, im, keymap->indicators)
1019 if (im->name == XKB_ATOM_NONE)
1022 if (i >= darray_size(keymap->indicators)) {
1023 /* Not place to put it; ignore. */
1024 if (i >= XKB_MAX_LEDS) {
1025 log_err(keymap->ctx,
1026 "Too many indicators (maximum is %d); "
1027 "Indicator name \"%s\" ignored\n",
1029 xkb_atom_text(keymap->ctx, led->im.name));
1032 /* Add a new indicator. */
1033 darray_resize(keymap->indicators, i + 1);
1034 im = &darray_item(keymap->indicators, i);
1039 if (im->groups != 0 && im->which_groups == 0)
1040 im->which_groups = XKB_STATE_LAYOUT_EFFECTIVE;
1041 if (im->mods.mods != 0 && im->which_mods == 0)
1042 im->which_mods = XKB_STATE_MODS_EFFECTIVE;
1047 CopyCompatToKeymap(struct xkb_keymap *keymap, CompatInfo *info)
1049 keymap->compat_section_name = strdup_safe(info->name);
1051 if (!darray_empty(info->interps)) {
1052 /* Most specific to least specific. */
1053 CopyInterps(info, true, MATCH_EXACTLY);
1054 CopyInterps(info, true, MATCH_ALL);
1055 CopyInterps(info, true, MATCH_NONE);
1056 CopyInterps(info, true, MATCH_ANY);
1057 CopyInterps(info, true, MATCH_ANY_OR_NONE);
1058 CopyInterps(info, false, MATCH_EXACTLY);
1059 CopyInterps(info, false, MATCH_ALL);
1060 CopyInterps(info, false, MATCH_NONE);
1061 CopyInterps(info, false, MATCH_ANY);
1062 CopyInterps(info, false, MATCH_ANY_OR_NONE);
1065 CopyIndicatorMapDefs(info);
1071 CompileCompatMap(XkbFile *file, struct xkb_keymap *keymap,
1072 enum merge_mode merge)
1075 ActionsInfo *actions;
1077 actions = NewActionsInfo();
1081 InitCompatInfo(&info, keymap, file->id, actions);
1082 info.dflt.merge = merge;
1083 info.ledDflt.merge = merge;
1085 HandleCompatMapFile(&info, file, merge);
1086 if (info.errorCount != 0)
1089 if (!CopyCompatToKeymap(keymap, &info))
1092 ClearCompatInfo(&info);
1093 FreeActionsInfo(actions);
1097 ClearCompatInfo(&info);
1098 FreeActionsInfo(actions);