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"
35 * The xkb_compat section
36 * =====================
37 * This section is the third to be processesed, after xkb_keycodes and
40 * Interpret statements
41 * --------------------
42 * Statements of the form:
43 * interpret Num_Lock+Any { ... }
45 * The body of the statment may include statements of the following
49 * action = LockMods(modifiers=NumLock);
51 * - virtual modifier statement:
52 * virtualModifier = NumLock;
57 * - useModMapMods statement:
58 * useModMapMods = level1;
60 * Indicator map statements
61 * ------------------------
62 * Statements of the form:
63 * indicator "Shift Lock" { ... }
65 * This statement specifies the behavior and binding of the indicator
66 * with the given name ("Shift Lock" above). The name should have been
67 * declared previously in the xkb_keycodes section (see Indicator name
68 * statement), and given an index there. If it wasn't, it is created
69 * with the next free index.
70 * The body of the statement describes the conditions of the keyboard
71 * state which will cause the indicator to be lit. It may include the
72 * following statements:
74 * - modifiers statment:
75 * modifiers = ScrollLock;
77 * If the given modifiers are in the required state (see below), the
80 * - whichModifierState statment:
81 * whichModState = Latched + Locked;
83 * Can be any combination of:
84 * base, latched, locked, effective
85 * any (i.e. all of the above)
86 * none (i.e. none of the above)
87 * compat (this is legal, but unused)
88 * This will cause the respective portion of the modifer state (see
89 * struct xkb_state) to be matched against the modifiers given in the
90 * "modifiers" statement.
92 * Here's a simple example:
93 * indicator "Num Lock" {
94 * modifiers = NumLock;
95 * whichModState = Locked;
97 * Whenever the NumLock modifier is locked, the Num Lock indicator
101 * groups = All - group1;
103 * If the given groups are in the required state (see below), the led
106 * - whichGroupState statment:
107 * whichGroupState = Effective;
109 * Can be any combination of:
110 * base, latched, locked, effective
111 * any (i.e. all of the above)
112 * none (i.e. none of the above)
113 * This will cause the respective portion of the group state (see
114 * struct xkb_state) to be matched against the groups given in the
115 * "groups" statement.
117 * Note: the above conditions are disjunctive, i.e. if any of them are
118 * satisfied the led is lit.
120 * Virtual modifier statements
121 * ---------------------------
122 * Statements of the form:
123 * virtual_modifiers LControl;
125 * Can appear in the xkb_types, xkb_compat, xkb_symbols sections.
130 * After all of the xkb_compat sections have been compiled, the following
131 * members of struct xkb_keymap are finalized:
132 * darray(struct xkb_sym_interpret) sym_interpret;
133 * struct xkb_indicator_map indicators[XkbNumIndicators];
134 * char *compat_section_name;
135 * TODO: virtual modifiers.
139 SI_FIELD_VIRTUAL_MOD = (1 << 0),
140 SI_FIELD_ACTION = (1 << 1),
141 SI_FIELD_AUTO_REPEAT = (1 << 2),
142 SI_FIELD_LEVEL_ONE_ONLY = (1 << 3),
145 typedef struct _SymInterpInfo {
146 enum si_field defined;
148 enum merge_mode merge;
151 struct xkb_sym_interpret interp;
155 LED_FIELD_MODS = (1 << 0),
156 LED_FIELD_GROUPS = (1 << 1),
157 LED_FIELD_CTRLS = (1 << 2),
160 typedef struct _LEDInfo {
161 enum led_field defined;
163 enum merge_mode merge;
166 unsigned char which_mods;
168 unsigned char which_groups;
173 typedef struct _CompatInfo {
181 darray(LEDInfo) leds;
184 struct xkb_keymap *keymap;
188 siText(SymInterpInfo *si, CompatInfo *info)
190 static char buf[128];
192 if (si == &info->dflt)
195 snprintf(buf, sizeof(buf), "%s+%s(%s)",
196 KeysymText(si->interp.sym),
197 SIMatchText(si->interp.match),
198 ModMaskText(si->interp.mods));
203 ReportSINotArray(CompatInfo *info, SymInterpInfo *si, const char *field)
205 return ReportNotArray(info->keymap, "symbol interpretation", field,
210 ReportSIBadType(CompatInfo *info, SymInterpInfo *si, const char *field,
213 return ReportBadType(info->keymap->ctx, "symbol interpretation", field,
214 siText(si, info), wanted);
218 ReportIndicatorBadType(CompatInfo *info, LEDInfo *led,
219 const char *field, const char *wanted)
221 return ReportBadType(info->keymap->ctx, "indicator map", field,
222 xkb_atom_text(info->keymap->ctx, led->name),
227 ReportIndicatorNotArray(CompatInfo *info, LEDInfo *led,
230 return ReportNotArray(info->keymap, "indicator map", field,
231 xkb_atom_text(info->keymap->ctx, led->name));
235 ClearIndicatorMapInfo(struct xkb_context *ctx, LEDInfo *info)
237 info->name = xkb_atom_intern(ctx, "default");
238 info->which_mods = 0;
240 info->which_groups = info->groups = 0;
245 InitCompatInfo(CompatInfo *info, struct xkb_keymap *keymap, unsigned file_id)
247 info->keymap = keymap;
249 info->file_id = file_id;
250 info->errorCount = 0;
252 list_init(&info->interps);
254 info->dflt.file_id = file_id;
255 info->dflt.defined = 0;
256 info->dflt.merge = MERGE_OVERRIDE;
257 info->dflt.interp.flags = 0;
258 info->dflt.interp.virtual_mod = XkbNoModifier;
259 memset(&info->dflt.interp.act, 0, sizeof(info->dflt.interp.act));
260 info->dflt.interp.act.type = XkbSA_NoAction;
261 ClearIndicatorMapInfo(keymap->ctx, &info->ledDflt);
262 info->ledDflt.file_id = file_id;
263 info->ledDflt.defined = 0;
264 info->ledDflt.merge = MERGE_OVERRIDE;
265 darray_init(info->leds);
266 InitVModInfo(&info->vmods, keymap);
270 ClearCompatInfo(CompatInfo *info)
272 SymInterpInfo *si, *next_si;
273 struct xkb_keymap *keymap = info->keymap;
277 info->dflt.defined = 0;
278 info->dflt.merge = MERGE_AUGMENT;
279 info->dflt.interp.flags = 0;
280 info->dflt.interp.virtual_mod = XkbNoModifier;
281 memset(&info->dflt.interp.act, 0, sizeof(info->dflt.interp.act));
282 info->dflt.interp.act.type = XkbSA_NoAction;
283 ClearIndicatorMapInfo(keymap->ctx, &info->ledDflt);
285 list_foreach_safe(si, next_si, &info->interps, entry)
287 darray_free(info->leds);
288 FreeActionInfo(info->act);
291 ClearVModInfo(&info->vmods, keymap);
294 static SymInterpInfo *
295 NextInterp(CompatInfo *info)
299 si = calloc(1, sizeof(*si));
303 list_append(&si->entry, &info->interps);
309 static SymInterpInfo *
310 FindMatchingInterp(CompatInfo *info, SymInterpInfo *new)
314 list_foreach(old, &info->interps, entry)
315 if (old->interp.sym == new->interp.sym &&
316 old->interp.mods == new->interp.mods &&
317 old->interp.match == new->interp.match)
324 UseNewInterpField(enum si_field field, SymInterpInfo *old, SymInterpInfo *new,
325 int verbosity, enum si_field *collide)
327 if (!(old->defined & field))
330 if (new->defined & field) {
331 if ((old->file_id == new->file_id && verbosity > 0) || verbosity > 9)
334 if (new->merge != MERGE_AUGMENT)
342 AddInterp(CompatInfo *info, SymInterpInfo *new)
344 enum si_field collide;
347 int verbosity = xkb_get_log_verbosity(info->keymap->ctx);
350 old = FindMatchingInterp(info, new);
352 if (new->merge == MERGE_REPLACE) {
354 if ((old->file_id == new->file_id && verbosity > 0) ||
356 log_warn(info->keymap->ctx,
357 "Multiple definitions for \"%s\"; "
358 "Earlier interpretation ignored\n",
365 if (UseNewInterpField(SI_FIELD_VIRTUAL_MOD, old, new, verbosity,
367 old->interp.virtual_mod = new->interp.virtual_mod;
368 old->defined |= SI_FIELD_VIRTUAL_MOD;
370 if (UseNewInterpField(SI_FIELD_ACTION, old, new, verbosity,
372 old->interp.act = new->interp.act;
373 old->defined |= SI_FIELD_ACTION;
375 if (UseNewInterpField(SI_FIELD_AUTO_REPEAT, old, new, verbosity,
377 old->interp.flags &= ~XkbSI_AutoRepeat;
378 old->interp.flags |= (new->interp.flags & XkbSI_AutoRepeat);
379 old->defined |= SI_FIELD_AUTO_REPEAT;
381 if (UseNewInterpField(SI_FIELD_LEVEL_ONE_ONLY, old, new, verbosity,
383 old->interp.match &= ~XkbSI_LevelOneOnly;
384 old->interp.match |= (new->interp.match & XkbSI_LevelOneOnly);
385 old->defined |= SI_FIELD_LEVEL_ONE_ONLY;
389 log_warn(info->keymap->ctx,
390 "Multiple interpretations of \"%s\"; "
391 "Using %s definition for duplicate fields\n",
393 (new->merge != MERGE_AUGMENT ? "last" : "first"));
400 new = NextInterp(info);
410 /***====================================================================***/
413 ResolveStateAndPredicate(ExprDef *expr, unsigned *pred_rtrn,
414 xkb_mod_mask_t *mods_rtrn, CompatInfo *info)
417 *pred_rtrn = XkbSI_AnyOfOrNone;
422 *pred_rtrn = XkbSI_Exactly;
423 if (expr->op == EXPR_ACTION_DECL) {
424 const char *pred_txt = xkb_atom_text(info->keymap->ctx,
425 expr->value.action.name);
426 if (istreq(pred_txt, "noneof"))
427 *pred_rtrn = XkbSI_NoneOf;
428 else if (istreq(pred_txt, "anyofornone"))
429 *pred_rtrn = XkbSI_AnyOfOrNone;
430 else if (istreq(pred_txt, "anyof"))
431 *pred_rtrn = XkbSI_AnyOf;
432 else if (istreq(pred_txt, "allof"))
433 *pred_rtrn = XkbSI_AllOf;
434 else if (istreq(pred_txt, "exactly"))
435 *pred_rtrn = XkbSI_Exactly;
437 log_err(info->keymap->ctx,
438 "Illegal modifier predicate \"%s\"; Ignored\n", pred_txt);
441 expr = expr->value.action.args;
443 else if (expr->op == EXPR_IDENT) {
444 const char *pred_txt = xkb_atom_text(info->keymap->ctx,
446 if (pred_txt && istreq(pred_txt, "any")) {
447 *pred_rtrn = XkbSI_AnyOf;
453 return ExprResolveModMask(info->keymap->ctx, expr, mods_rtrn);
456 /***====================================================================***/
459 UseNewLEDField(enum led_field field, LEDInfo *old, LEDInfo *new,
460 int verbosity, enum led_field *collide)
462 if (!(old->defined & field))
465 if (new->defined & field) {
466 if ((old->file_id == new->file_id && verbosity > 0) || verbosity > 9)
469 if (new->merge != MERGE_AUGMENT)
477 AddIndicatorMap(CompatInfo *info, LEDInfo *new)
480 enum led_field collide;
481 struct xkb_context *ctx = info->keymap->ctx;
482 int verbosity = xkb_get_log_verbosity(ctx);
484 darray_foreach(old, info->leds) {
485 if (old->name != new->name)
488 if (old->mods == new->mods &&
489 old->groups == new->groups &&
490 old->ctrls == new->ctrls &&
491 old->which_mods == new->which_mods &&
492 old->which_groups == new->which_groups) {
493 old->defined |= new->defined;
497 if (new->merge == MERGE_REPLACE) {
498 if ((old->file_id == new->file_id && verbosity > 0) ||
500 log_warn(info->keymap->ctx,
501 "Map for indicator %s redefined; "
502 "Earlier definition ignored\n",
503 xkb_atom_text(ctx, old->name));
509 if (UseNewLEDField(LED_FIELD_MODS, old, new, verbosity,
511 old->which_mods = new->which_mods;
512 old->mods = new->mods;
513 old->defined |= LED_FIELD_MODS;
515 if (UseNewLEDField(LED_FIELD_GROUPS, old, new, verbosity,
517 old->which_groups = new->which_groups;
518 old->groups = new->groups;
519 old->defined |= LED_FIELD_GROUPS;
521 if (UseNewLEDField(LED_FIELD_CTRLS, old, new, verbosity,
523 old->ctrls = new->ctrls;
524 old->defined |= LED_FIELD_CTRLS;
528 log_warn(info->keymap->ctx,
529 "Map for indicator %s redefined; "
530 "Using %s definition for duplicate fields\n",
531 xkb_atom_text(ctx, old->name),
532 (new->merge == MERGE_AUGMENT ? "first" : "last"));
538 darray_append(info->leds, *new);
543 MergeIncludedCompatMaps(CompatInfo *into, CompatInfo *from,
544 enum merge_mode merge)
546 SymInterpInfo *si, *next_si;
549 if (from->errorCount > 0) {
550 into->errorCount += from->errorCount;
554 if (into->name == NULL) {
555 into->name = from->name;
559 list_foreach_safe(si, next_si, &from->interps, entry) {
560 si->merge = (merge == MERGE_DEFAULT ? si->merge : merge);
561 if (!AddInterp(into, si))
565 darray_foreach(led, from->leds) {
566 led->merge = (merge == MERGE_DEFAULT ? led->merge : merge);
567 if (!AddIndicatorMap(into, led))
573 HandleCompatMapFile(CompatInfo *info, XkbFile *file, enum merge_mode merge);
576 HandleIncludeCompatMap(CompatInfo *info, IncludeStmt *stmt)
578 enum merge_mode merge = MERGE_DEFAULT;
580 CompatInfo included, next_incl;
582 InitCompatInfo(&included, info->keymap, info->file_id);
585 included.name = stmt->stmt;
589 for (; stmt; stmt = stmt->next_incl) {
590 if (!ProcessIncludeFile(info->keymap->ctx, stmt, FILE_TYPE_COMPAT,
592 info->errorCount += 10;
593 ClearCompatInfo(&included);
597 InitCompatInfo(&next_incl, info->keymap, rtrn->id);
598 next_incl.file_id = rtrn->id;
599 next_incl.dflt = info->dflt;
600 next_incl.dflt.file_id = rtrn->id;
601 next_incl.dflt.merge = merge;
602 next_incl.ledDflt.file_id = rtrn->id;
603 next_incl.ledDflt.merge = merge;
604 next_incl.act = info->act;
606 HandleCompatMapFile(&next_incl, rtrn, MERGE_OVERRIDE);
608 MergeIncludedCompatMaps(&included, &next_incl, merge);
610 next_incl.act = NULL;
612 ClearCompatInfo(&next_incl);
616 MergeIncludedCompatMaps(info, &included, merge);
617 ClearCompatInfo(&included);
619 return (info->errorCount == 0);
622 static const LookupEntry useModMapValues[] = {
631 SetInterpField(CompatInfo *info, SymInterpInfo *si, const char *field,
632 ExprDef *arrayNdx, ExprDef *value)
634 struct xkb_keymap *keymap = info->keymap;
637 if (istreq(field, "action")) {
639 return ReportSINotArray(info, si, field);
641 if (!HandleActionDef(value, keymap, &si->interp.act, info->act))
644 si->defined |= SI_FIELD_ACTION;
646 else if (istreq(field, "virtualmodifier") ||
647 istreq(field, "virtualmod")) {
649 return ReportSINotArray(info, si, field);
651 if (!ResolveVirtualModifier(value, keymap, &ndx, &info->vmods))
652 return ReportSIBadType(info, si, field, "virtual modifier");
654 si->interp.virtual_mod = ndx;
655 si->defined |= SI_FIELD_VIRTUAL_MOD;
657 else if (istreq(field, "repeat")) {
661 return ReportSINotArray(info, si, field);
663 if (!ExprResolveBoolean(keymap->ctx, value, &set))
664 return ReportSIBadType(info, si, field, "boolean");
667 si->interp.flags |= XkbSI_AutoRepeat;
669 si->interp.flags &= ~XkbSI_AutoRepeat;
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, useModMapValues))
686 return ReportSIBadType(info, si, field, "level specification");
689 si->interp.match |= XkbSI_LevelOneOnly;
691 si->interp.match &= ~XkbSI_LevelOneOnly;
693 si->defined |= SI_FIELD_LEVEL_ONE_ONLY;
696 return ReportBadField(keymap, "symbol interpretation", field,
703 static const LookupEntry modComponentNames[] = {
704 {"base", XkbIM_UseBase},
705 {"latched", XkbIM_UseLatched},
706 {"locked", XkbIM_UseLocked},
707 {"effective", XkbIM_UseEffective},
708 {"compat", XkbIM_UseCompat},
709 {"any", XkbIM_UseAnyMods},
714 static const LookupEntry groupComponentNames[] = {
715 {"base", XkbIM_UseBase},
716 {"latched", XkbIM_UseLatched},
717 {"locked", XkbIM_UseLocked},
718 {"effective", XkbIM_UseEffective},
719 {"any", XkbIM_UseAnyGroup},
724 static const LookupEntry groupNames[] = {
739 SetIndicatorMapField(CompatInfo *info, LEDInfo *led,
740 const char *field, ExprDef *arrayNdx, ExprDef *value)
743 struct xkb_keymap *keymap = info->keymap;
745 if (istreq(field, "modifiers") || istreq(field, "mods")) {
747 return ReportIndicatorNotArray(info, led, field);
749 if (!ExprResolveVModMask(keymap, value, &led->mods))
750 return ReportIndicatorBadType(info, led, field, "modifier mask");
752 led->defined |= LED_FIELD_MODS;
754 else if (istreq(field, "groups")) {
758 return ReportIndicatorNotArray(info, led, field);
760 if (!ExprResolveMask(keymap->ctx, value, &mask, groupNames))
761 return ReportIndicatorBadType(info, led, field, "group mask");
764 led->defined |= LED_FIELD_GROUPS;
766 else if (istreq(field, "controls") || istreq(field, "ctrls")) {
770 return ReportIndicatorNotArray(info, led, field);
772 if (!ExprResolveMask(keymap->ctx, value, &mask, ctrlNames))
773 return ReportIndicatorBadType(info, led, field,
777 led->defined |= LED_FIELD_CTRLS;
779 else if (istreq(field, "allowexplicit")) {
780 log_dbg(info->keymap->ctx,
781 "The \"allowExplicit\" field in indicator statements is unsupported; "
784 else if (istreq(field, "whichmodstate") ||
785 istreq(field, "whichmodifierstate")) {
789 return ReportIndicatorNotArray(info, led, field);
791 if (!ExprResolveMask(keymap->ctx, value, &mask, modComponentNames))
792 return ReportIndicatorBadType(info, led, field,
793 "mask of modifier state components");
795 led->which_mods = mask;
797 else if (istreq(field, "whichgroupstate")) {
801 return ReportIndicatorNotArray(info, led, field);
803 if (!ExprResolveMask(keymap->ctx, value, &mask, groupComponentNames))
804 return ReportIndicatorBadType(info, led, field,
805 "mask of group state components");
807 led->which_groups = mask;
809 else if (istreq(field, "driveskbd") ||
810 istreq(field, "driveskeyboard") ||
811 istreq(field, "leddriveskbd") ||
812 istreq(field, "leddriveskeyboard") ||
813 istreq(field, "indicatordriveskbd") ||
814 istreq(field, "indicatordriveskeyboard")) {
815 log_dbg(info->keymap->ctx,
816 "The \"%s\" field in indicator statements is unsupported; "
819 else if (istreq(field, "index")) {
820 /* Users should see this, it might cause unexpected behavior. */
821 log_err(info->keymap->ctx,
822 "The \"index\" field in indicator statements is unsupported; "
826 log_err(info->keymap->ctx,
827 "Unknown field %s in map for %s indicator; "
828 "Definition ignored\n",
829 field, xkb_atom_text(keymap->ctx, led->name));
837 HandleInterpVar(CompatInfo *info, VarDef *stmt)
839 const char *elem, *field;
843 if (!ExprResolveLhs(info->keymap->ctx, stmt->name, &elem, &field, &ndx))
845 else if (elem && istreq(elem, "interpret"))
846 ret = SetInterpField(info, &info->dflt, field, ndx, stmt->value);
847 else if (elem && istreq(elem, "indicator"))
848 ret = SetIndicatorMapField(info, &info->ledDflt, field, ndx,
851 ret = SetActionField(info->keymap, elem, field, ndx, stmt->value,
857 HandleInterpBody(CompatInfo *info, VarDef *def, SymInterpInfo *si)
860 const char *elem, *field;
863 for (; def; def = (VarDef *) def->common.next) {
864 if (def->name && def->name->op == EXPR_FIELD_REF) {
865 ok = HandleInterpVar(info, def);
869 ok = ExprResolveLhs(info->keymap->ctx, def->name, &elem, &field,
874 ok = SetInterpField(info, si, field, arrayNdx, def->value);
881 HandleInterpDef(CompatInfo *info, InterpDef *def, enum merge_mode merge)
886 if (!ResolveStateAndPredicate(def->match, &pred, &mods, info)) {
887 log_err(info->keymap->ctx,
888 "Couldn't determine matching modifiers; "
889 "Symbol interpretation ignored\n");
895 si.merge = merge = (def->merge == MERGE_DEFAULT ? merge : def->merge);
897 if (!LookupKeysym(def->sym, &si.interp.sym)) {
898 log_err(info->keymap->ctx,
899 "Could not resolve keysym %s; "
900 "Symbol interpretation ignored\n",
905 si.interp.match = pred & XkbSI_OpMask;
907 si.interp.mods = mods;
909 if (!HandleInterpBody(info, def->def, &si)) {
914 if (!AddInterp(info, &si)) {
923 HandleIndicatorMapDef(CompatInfo *info, IndicatorMapDef *def,
924 enum merge_mode merge)
930 if (def->merge != MERGE_DEFAULT)
935 led.name = def->name;
938 for (var = def->body; var != NULL; var = (VarDef *) var->common.next) {
939 const char *elem, *field;
941 if (!ExprResolveLhs(info->keymap->ctx, var->name, &elem, &field,
948 log_err(info->keymap->ctx,
949 "Cannot set defaults for \"%s\" element in indicator map; "
950 "Assignment to %s.%s ignored\n", elem, elem, field);
954 ok = SetIndicatorMapField(info, &led, field, arrayNdx,
960 return AddIndicatorMap(info, &led);
966 HandleCompatMapFile(CompatInfo *info, XkbFile *file, enum merge_mode merge)
971 merge = (merge == MERGE_DEFAULT ? MERGE_AUGMENT : merge);
974 info->name = strdup_safe(file->name);
976 for (stmt = file->defs; stmt; stmt = stmt->next) {
977 switch (stmt->type) {
979 ok = HandleIncludeCompatMap(info, (IncludeStmt *) stmt);
982 ok = HandleInterpDef(info, (InterpDef *) stmt, merge);
984 case STMT_GROUP_COMPAT:
985 log_dbg(info->keymap->ctx,
986 "The \"group\" statement in compat is unsupported; "
990 case STMT_INDICATOR_MAP:
991 ok = HandleIndicatorMapDef(info, (IndicatorMapDef *) stmt, merge);
994 ok = HandleInterpVar(info, (VarDef *) stmt);
997 ok = HandleVModDef((VModDef *) stmt, info->keymap, merge,
1001 log_err(info->keymap->ctx,
1002 "Interpretation files may not include other types; "
1003 "Ignoring %s\n", StmtTypeToString(stmt->type));
1011 if (info->errorCount > 10) {
1012 log_err(info->keymap->ctx,
1013 "Abandoning compatibility map \"%s\"\n", file->topName);
1020 CopyInterps(CompatInfo *info, bool needSymbol, unsigned pred)
1024 list_foreach(si, &info->interps, entry) {
1025 if (((si->interp.match & XkbSI_OpMask) != pred) ||
1026 (needSymbol && si->interp.sym == XKB_KEY_NoSymbol) ||
1027 (!needSymbol && si->interp.sym != XKB_KEY_NoSymbol))
1030 darray_append(info->keymap->sym_interpret, si->interp);
1035 CopyIndicatorMapDefs(CompatInfo *info)
1038 struct xkb_indicator_map *im;
1040 struct xkb_keymap *keymap = info->keymap;
1042 darray_foreach(led, info->leds) {
1043 const char *name = xkb_atom_text(keymap->ctx, led->name);
1046 * Find the indicator with the given name, if it was already
1047 * declared in keycodes.
1050 for (i = 0; i < XkbNumIndicators; i++) {
1051 if (streq_not_null(keymap->indicator_names[i], name)) {
1052 im = &keymap->indicators[i];
1057 /* Not previously declared; create it with next free index. */
1059 log_dbg(keymap->ctx,
1060 "Indicator name \"%s\" was not declared in the keycodes section; "
1061 "Adding new indicator\n", name);
1063 for (i = 0; i < XkbNumIndicators; i++) {
1064 if (keymap->indicator_names[i])
1067 keymap->indicator_names[i] = name;
1068 im = &keymap->indicators[i];
1072 /* Not place to put the it; ignore. */
1074 log_err(keymap->ctx,
1075 "Too many indicators (maximum is %d); "
1076 "Indicator name \"%s\" ignored\n",
1077 XkbNumIndicators, name);
1082 if (led->groups != 0 && led->which_groups == 0)
1083 im->which_groups = XkbIM_UseEffective;
1085 im->which_groups = led->which_groups;
1086 im->groups = led->groups;
1087 if (led->mods != 0 && led->which_mods == 0)
1088 im->which_mods = XkbIM_UseEffective;
1090 im->which_mods = led->which_mods;
1091 im->mods.mods = led->mods;
1092 im->ctrls = led->ctrls;
1099 CompileCompatMap(XkbFile *file, struct xkb_keymap *keymap,
1100 enum merge_mode merge)
1104 InitCompatInfo(&info, keymap, file->id);
1105 info.dflt.merge = merge;
1106 info.ledDflt.merge = merge;
1108 HandleCompatMapFile(&info, file, merge);
1110 if (info.errorCount != 0)
1114 keymap->compat_section_name = strdup(info.name);
1116 darray_init(keymap->sym_interpret);
1117 if (info.nInterps > 0) {
1118 darray_growalloc(keymap->sym_interpret, info.nInterps);
1119 CopyInterps(&info, true, XkbSI_Exactly);
1120 CopyInterps(&info, true, XkbSI_AllOf | XkbSI_NoneOf);
1121 CopyInterps(&info, true, XkbSI_AnyOf);
1122 CopyInterps(&info, true, XkbSI_AnyOfOrNone);
1123 CopyInterps(&info, false, XkbSI_Exactly);
1124 CopyInterps(&info, false, XkbSI_AllOf | XkbSI_NoneOf);
1125 CopyInterps(&info, false, XkbSI_AnyOf);
1126 CopyInterps(&info, false, XkbSI_AnyOfOrNone);
1129 if (!CopyIndicatorMapDefs(&info))
1132 ClearCompatInfo(&info);
1136 ClearCompatInfo(&info);
1141 ComputeEffectiveMask(struct xkb_keymap *keymap, struct xkb_mods *mods)
1144 xkb_mod_mask_t vmask = mods->mods >> XkbNumModifiers;
1146 /* The effective mask is only real mods for now. */
1147 mods->mask = mods->mods & 0xff;
1149 for (i = 0; i < XkbNumVirtualMods; i++) {
1150 if (!(vmask & (1 << i)))
1152 mods->mask |= keymap->vmods[i];
1157 UpdateActionMods(struct xkb_keymap *keymap, union xkb_action *act,
1158 xkb_mod_mask_t rmodmask)
1161 struct xkb_mods *mods;
1163 switch (act->type) {
1165 case XkbSA_LatchMods:
1166 case XkbSA_LockMods:
1167 flags = act->mods.flags;
1168 mods = &act->mods.mods;
1172 flags = act->iso.flags;
1173 mods = &act->iso.mods;
1180 if (flags & XkbSA_UseModMapMods) {
1181 /* XXX: what's that. */
1183 mods->mods |= rmodmask;
1185 ComputeEffectiveMask(keymap, mods);
1189 * Find an interpretation which applies to this particular level, either by
1190 * finding an exact match for the symbol and modifier combination, or a
1191 * generic XKB_KEY_NoSymbol match.
1193 static struct xkb_sym_interpret *
1194 FindInterpForKey(struct xkb_keymap *keymap, struct xkb_key *key,
1195 xkb_group_index_t group, xkb_level_index_t level)
1197 struct xkb_sym_interpret *ret = NULL;
1198 struct xkb_sym_interpret *interp;
1199 const xkb_keysym_t *syms;
1202 num_syms = xkb_key_get_syms_by_level(keymap, key, group, level, &syms);
1206 darray_foreach(interp, keymap->sym_interpret) {
1210 if ((num_syms > 1 || interp->sym != syms[0]) &&
1211 interp->sym != XKB_KEY_NoSymbol)
1214 if (level == 0 || !(interp->match & XkbSI_LevelOneOnly))
1219 switch (interp->match & XkbSI_OpMask) {
1221 found = !(interp->mods & mods);
1223 case XkbSI_AnyOfOrNone:
1224 found = (!mods || (interp->mods & mods));
1227 found = !!(interp->mods & mods);
1230 found = ((interp->mods & mods) == interp->mods);
1233 found = (interp->mods == mods);
1240 if (found && interp->sym != XKB_KEY_NoSymbol)
1242 else if (found && !ret)
1250 ApplyInterpsToKey(struct xkb_keymap *keymap, struct xkb_key *key)
1252 #define INTERP_SIZE (8 * 4)
1253 struct xkb_sym_interpret *interps[INTERP_SIZE];
1254 xkb_mod_mask_t vmodmask = 0;
1256 xkb_group_index_t group;
1257 xkb_level_index_t level;
1260 /* If we've been told not to bind interps to this key, then don't. */
1261 if (key->explicit & XkbExplicitInterpretMask)
1264 for (i = 0; i < INTERP_SIZE; i++)
1267 for (group = 0; group < key->num_groups; group++) {
1268 for (level = 0; level < XkbKeyGroupWidth(keymap, key, group);
1270 i = (group * key->width) + level;
1271 if (i >= INTERP_SIZE) /* XXX FIXME */
1273 interps[i] = FindInterpForKey(keymap, key, group, level);
1279 if (num_acts && !key->actions) {
1280 key->actions = calloc(key->num_groups * key->width,
1281 sizeof(*key->actions));
1286 for (group = 0; group < key->num_groups; group++) {
1287 for (level = 0; level < XkbKeyGroupWidth(keymap, key, group);
1289 struct xkb_sym_interpret *interp;
1291 i = (group * key->width) + level;
1292 interp = interps[i];
1294 /* Infer default key behaviours from the base level. */
1295 if (group == 0 && level == 0) {
1296 if (!(key->explicit & XkbExplicitAutoRepeatMask) &&
1297 (!interp || (interp->flags & XkbSI_AutoRepeat)))
1298 key->repeats = true;
1304 if ((group == 0 && level == 0) ||
1305 !(interp->match & XkbSI_LevelOneOnly)) {
1306 if (interp->virtual_mod != XkbNoModifier)
1307 vmodmask |= (1 << interp->virtual_mod);
1310 key->actions[i] = interp->act;
1314 if (!(key->explicit & XkbExplicitVModMapMask))
1315 key->vmodmap = vmodmask;
1322 * This collects a bunch of disparate functions which was done in the server
1323 * at various points that really should've been done within xkbcomp. Turns out
1324 * your actions and types are a lot more useful when any of your modifiers
1325 * other than Shift actually do something ...
1328 UpdateModifiersFromCompat(struct xkb_keymap *keymap)
1330 xkb_mod_index_t vmod;
1331 xkb_led_index_t led;
1333 struct xkb_key *key;
1335 /* Find all the interprets for the key and bind them to actions,
1336 * which will also update the vmodmap. */
1337 xkb_foreach_key(key, keymap)
1338 if (!ApplyInterpsToKey(keymap, key))
1341 /* Update keymap->vmods, the virtual -> real mod mapping. */
1342 for (vmod = 0; vmod < XkbNumVirtualMods; vmod++)
1343 keymap->vmods[vmod] = 0;
1345 xkb_foreach_key(key, keymap) {
1349 for (vmod = 0; vmod < XkbNumVirtualMods; vmod++) {
1350 if (!(key->vmodmap & (1 << vmod)))
1352 keymap->vmods[vmod] |= key->modmap;
1356 /* Now update the level masks for all the types to reflect the vmods. */
1357 for (i = 0; i < keymap->num_types; i++) {
1358 ComputeEffectiveMask(keymap, &keymap->types[i].mods);
1360 for (j = 0; j < keymap->types[i].num_entries; j++) {
1361 ComputeEffectiveMask(keymap, &keymap->types[i].map[j].mods);
1362 ComputeEffectiveMask(keymap, &keymap->types[i].map[j].preserve);
1366 /* Update action modifiers. */
1367 xkb_foreach_key(key, keymap) {
1371 for (i = 0; i < key->num_groups * key->width; i++)
1372 UpdateActionMods(keymap, &key->actions[i], key->modmap);
1375 /* Update vmod -> indicator maps. */
1376 for (led = 0; led < XkbNumIndicators; led++)
1377 ComputeEffectiveMask(keymap, &keymap->indicators[led].mods);
1379 /* Find maximum number of groups out of all keys in the keymap. */
1380 xkb_foreach_key(key, keymap)
1381 keymap->num_groups = MAX(keymap->num_groups, key->num_groups);