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 SI_FIELD_VIRTUAL_MOD = (1 << 0),
36 SI_FIELD_ACTION = (1 << 1),
37 SI_FIELD_AUTO_REPEAT = (1 << 2),
38 SI_FIELD_LOCKING_KEY = (1 << 3),
39 SI_FIELD_LEVEL_ONE_ONLY = (1 << 4),
42 typedef struct _SymInterpInfo {
43 enum si_field defined;
45 enum merge_mode merge;
48 struct xkb_sym_interpret interp;
52 LED_FIELD_INDEX = (1 << 0),
53 LED_FIELD_MODS = (1 << 1),
54 LED_FIELD_GROUPS = (1 << 2),
55 LED_FIELD_CTRLS = (1 << 3),
56 LED_FIELD_EXPLICIT = (1 << 4),
57 LED_FIELD_AUTOMATIC = (1 << 5),
58 LED_FIELD_DRIVES_KBD = (1 << 6),
61 typedef struct _LEDInfo {
62 enum led_field defined;
64 enum merge_mode merge;
68 xkb_led_index_t indicator;
70 unsigned char which_mods;
72 unsigned char which_groups;
77 typedef struct _GroupCompatInfo {
79 enum merge_mode merge;
84 typedef struct _CompatInfo {
92 GroupCompatInfo groupCompat[XkbNumKbdGroups];
96 struct xkb_keymap *keymap;
100 siText(SymInterpInfo * si, CompatInfo * info)
102 static char buf[128];
104 if (si == &info->dflt) {
105 snprintf(buf, sizeof(buf), "default");
108 snprintf(buf, sizeof(buf), "%s+%s(%s)",
109 KeysymText(si->interp.sym),
110 SIMatchText(si->interp.match),
111 ModMaskText(si->interp.mods));
117 ReportSINotArray(CompatInfo *info, SymInterpInfo *si, const char *field)
119 return ReportNotArray(info->keymap, "symbol interpretation", field,
124 ReportSIBadType(CompatInfo *info, SymInterpInfo *si, const char *field,
127 return ReportBadType(info->keymap->ctx, "symbol interpretation", field,
128 siText(si, info), wanted);
132 ReportIndicatorBadType(CompatInfo *info, LEDInfo *led,
133 const char *field, const char *wanted)
135 return ReportBadType(info->keymap->ctx, "indicator map", field,
136 xkb_atom_text(info->keymap->ctx, led->name),
141 ReportIndicatorNotArray(CompatInfo *info, LEDInfo *led,
144 return ReportNotArray(info->keymap, "indicator map", field,
145 xkb_atom_text(info->keymap->ctx, led->name));
149 ClearIndicatorMapInfo(struct xkb_context *ctx, LEDInfo * info)
151 info->name = xkb_atom_intern(ctx, "default");
152 info->indicator = XKB_LED_INVALID;
154 info->which_mods = 0;
156 info->which_groups = info->groups = 0;
161 InitCompatInfo(CompatInfo *info, struct xkb_keymap *keymap, unsigned file_id)
163 info->keymap = keymap;
165 info->file_id = file_id;
166 info->errorCount = 0;
168 list_init(&info->interps);
170 info->dflt.file_id = file_id;
171 info->dflt.defined = 0;
172 info->dflt.merge = MERGE_OVERRIDE;
173 info->dflt.interp.flags = 0;
174 info->dflt.interp.virtual_mod = XkbNoModifier;
175 memset(&info->dflt.interp.act, 0, sizeof(info->dflt.interp.act));
176 info->dflt.interp.act.type = XkbSA_NoAction;
177 ClearIndicatorMapInfo(keymap->ctx, &info->ledDflt);
178 info->ledDflt.file_id = file_id;
179 info->ledDflt.defined = 0;
180 info->ledDflt.merge = MERGE_OVERRIDE;
181 memset(&info->groupCompat[0], 0,
182 XkbNumKbdGroups * sizeof(GroupCompatInfo));
183 list_init(&info->leds);
184 InitVModInfo(&info->vmods, keymap);
188 ClearCompatInfo(CompatInfo *info)
190 ActionInfo *next_act;
191 SymInterpInfo *si, *next_si;
192 LEDInfo *led, *next_led;
193 struct xkb_keymap *keymap = info->keymap;
197 info->dflt.defined = 0;
198 info->dflt.merge = MERGE_AUGMENT;
199 info->dflt.interp.flags = 0;
200 info->dflt.interp.virtual_mod = XkbNoModifier;
201 memset(&info->dflt.interp.act, 0, sizeof(info->dflt.interp.act));
202 info->dflt.interp.act.type = XkbSA_NoAction;
203 ClearIndicatorMapInfo(keymap->ctx, &info->ledDflt);
205 list_foreach_safe(si, next_si, &info->interps, entry)
207 memset(&info->groupCompat[0], 0,
208 XkbNumKbdGroups * sizeof(GroupCompatInfo));
209 list_foreach_safe(led, next_led, &info->leds, entry)
212 next_act = info->act->next;
214 info->act = next_act;
217 ClearVModInfo(&info->vmods, keymap);
220 static SymInterpInfo *
221 NextInterp(CompatInfo * info)
225 si = calloc(1, sizeof(*si));
229 list_append(&si->entry, &info->interps);
235 static SymInterpInfo *
236 FindMatchingInterp(CompatInfo * info, SymInterpInfo * new)
240 list_foreach(old, &info->interps, entry)
241 if (old->interp.sym == new->interp.sym &&
242 old->interp.mods == new->interp.mods &&
243 old->interp.match == new->interp.match)
250 UseNewInterpField(enum si_field field, SymInterpInfo *old, SymInterpInfo *new,
251 int verbosity, enum si_field *collide)
253 if (!(old->defined & field))
256 if (new->defined & field) {
257 if ((old->file_id == new->file_id && verbosity > 0) || verbosity > 9)
260 if (new->merge != MERGE_AUGMENT)
268 AddInterp(CompatInfo * info, SymInterpInfo * new)
270 enum si_field collide;
273 int verbosity = xkb_get_log_verbosity(info->keymap->ctx);
276 old = FindMatchingInterp(info, new);
278 if (new->merge == MERGE_REPLACE) {
280 if ((old->file_id == new->file_id && verbosity > 0) ||
282 log_warn(info->keymap->ctx,
283 "Multiple definitions for \"%s\"; "
284 "Earlier interpretation ignored\n",
291 if (UseNewInterpField(SI_FIELD_VIRTUAL_MOD, old, new, verbosity,
293 old->interp.virtual_mod = new->interp.virtual_mod;
294 old->defined |= SI_FIELD_VIRTUAL_MOD;
296 if (UseNewInterpField(SI_FIELD_ACTION, old, new, verbosity,
298 old->interp.act = new->interp.act;
299 old->defined |= SI_FIELD_ACTION;
301 if (UseNewInterpField(SI_FIELD_AUTO_REPEAT, old, new, verbosity,
303 old->interp.flags &= ~XkbSI_AutoRepeat;
304 old->interp.flags |= (new->interp.flags & XkbSI_AutoRepeat);
305 old->defined |= SI_FIELD_AUTO_REPEAT;
307 if (UseNewInterpField(SI_FIELD_LOCKING_KEY, old, new, verbosity,
309 old->interp.flags &= ~XkbSI_LockingKey;
310 old->interp.flags |= (new->interp.flags & XkbSI_LockingKey);
311 old->defined |= SI_FIELD_LOCKING_KEY;
313 if (UseNewInterpField(SI_FIELD_LEVEL_ONE_ONLY, old, new, verbosity,
315 old->interp.match &= ~XkbSI_LevelOneOnly;
316 old->interp.match |= (new->interp.match & XkbSI_LevelOneOnly);
317 old->defined |= SI_FIELD_LEVEL_ONE_ONLY;
321 log_warn(info->keymap->ctx,
322 "Multiple interpretations of \"%s\"; "
323 "Using %s definition for duplicate fields\n",
325 (new->merge != MERGE_AUGMENT ? "last" : "first"));
332 if ((new = NextInterp(info)) == NULL)
341 AddGroupCompat(CompatInfo *info, xkb_group_index_t group, GroupCompatInfo *new)
344 int verbosity = xkb_get_log_verbosity(info->keymap->ctx);
346 gc = &info->groupCompat[group];
347 if (gc->mods == new->mods)
350 if ((gc->file_id == new->file_id && verbosity > 0) || verbosity > 9)
351 log_warn(info->keymap->ctx,
352 "Compat map for group %u redefined; "
353 "Using %s definition\n",
354 group + 1, (new->merge == MERGE_AUGMENT ? "old" : "new"));
356 if (new->defined && (new->merge != MERGE_AUGMENT || !gc->defined))
362 /***====================================================================***/
365 ResolveStateAndPredicate(ExprDef * expr,
367 xkb_mod_mask_t *mods_rtrn, CompatInfo * info)
370 *pred_rtrn = XkbSI_AnyOfOrNone;
375 *pred_rtrn = XkbSI_Exactly;
376 if (expr->op == EXPR_ACTION_DECL) {
377 const char *pred_txt = xkb_atom_text(info->keymap->ctx,
378 expr->value.action.name);
379 if (istreq(pred_txt, "noneof"))
380 *pred_rtrn = XkbSI_NoneOf;
381 else if (istreq(pred_txt, "anyofornone"))
382 *pred_rtrn = XkbSI_AnyOfOrNone;
383 else if (istreq(pred_txt, "anyof"))
384 *pred_rtrn = XkbSI_AnyOf;
385 else if (istreq(pred_txt, "allof"))
386 *pred_rtrn = XkbSI_AllOf;
387 else if (istreq(pred_txt, "exactly"))
388 *pred_rtrn = XkbSI_Exactly;
390 log_err(info->keymap->ctx,
391 "Illegal modifier predicate \"%s\"; Ignored\n", pred_txt);
394 expr = expr->value.action.args;
396 else if (expr->op == EXPR_IDENT) {
397 const char *pred_txt = xkb_atom_text(info->keymap->ctx,
399 if (pred_txt && istreq(pred_txt, "any")) {
400 *pred_rtrn = XkbSI_AnyOf;
406 return ExprResolveModMask(info->keymap->ctx, expr, mods_rtrn);
409 /***====================================================================***/
412 UseNewLEDField(enum led_field field, LEDInfo *old, LEDInfo *new,
413 int verbosity, enum led_field *collide)
415 if (!(old->defined & field))
418 if (new->defined & field) {
419 if ((old->file_id == new->file_id && verbosity > 0) || verbosity > 9)
422 if (new->merge != MERGE_AUGMENT)
430 AddIndicatorMap(CompatInfo *info, LEDInfo *new)
433 enum led_field collide;
434 struct xkb_context *ctx = info->keymap->ctx;
435 int verbosity = xkb_get_log_verbosity(ctx);
437 list_foreach(old, &info->leds, entry) {
438 if (old->name == new->name) {
439 if ((old->mods == new->mods) &&
440 (old->groups == new->groups) &&
441 (old->ctrls == new->ctrls) &&
442 (old->which_mods == new->which_mods) &&
443 (old->which_groups == new->which_groups)) {
444 old->defined |= new->defined;
448 if (new->merge == MERGE_REPLACE) {
449 struct list entry = old->entry;
450 if ((old->file_id == new->file_id && verbosity > 0) ||
452 log_warn(info->keymap->ctx,
453 "Map for indicator %s redefined; "
454 "Earlier definition ignored\n",
455 xkb_atom_text(ctx, old->name));
462 if (UseNewLEDField(LED_FIELD_INDEX, old, new, verbosity,
464 old->indicator = new->indicator;
465 old->defined |= LED_FIELD_INDEX;
467 if (UseNewLEDField(LED_FIELD_MODS, old, new, verbosity,
469 old->which_mods = new->which_mods;
470 old->mods = new->mods;
471 old->defined |= LED_FIELD_MODS;
473 if (UseNewLEDField(LED_FIELD_GROUPS, old, new, verbosity,
475 old->which_groups = new->which_groups;
476 old->groups = new->groups;
477 old->defined |= LED_FIELD_GROUPS;
479 if (UseNewLEDField(LED_FIELD_CTRLS, old, new, verbosity,
481 old->ctrls = new->ctrls;
482 old->defined |= LED_FIELD_CTRLS;
484 if (UseNewLEDField(LED_FIELD_EXPLICIT, old, new, verbosity,
486 old->flags &= ~XkbIM_NoExplicit;
487 old->flags |= (new->flags & XkbIM_NoExplicit);
488 old->defined |= LED_FIELD_EXPLICIT;
490 if (UseNewLEDField(LED_FIELD_AUTOMATIC, old, new, verbosity,
492 old->flags &= ~XkbIM_NoAutomatic;
493 old->flags |= (new->flags & XkbIM_NoAutomatic);
494 old->defined |= LED_FIELD_AUTOMATIC;
496 if (UseNewLEDField(LED_FIELD_DRIVES_KBD, old, new, verbosity,
498 old->flags &= ~XkbIM_LEDDrivesKB;
499 old->flags |= (new->flags & XkbIM_LEDDrivesKB);
500 old->defined |= LED_FIELD_DRIVES_KBD;
504 log_warn(info->keymap->ctx,
505 "Map for indicator %s redefined; "
506 "Using %s definition for duplicate fields\n",
507 xkb_atom_text(ctx, old->name),
508 (new->merge == MERGE_AUGMENT ? "first" : "last"));
516 old = malloc(sizeof(*old));
518 log_wsgo(info->keymap->ctx,
519 "Couldn't allocate indicator map; "
520 "Map for indicator %s not compiled\n",
521 xkb_atom_text(ctx, new->name));
526 list_append(&old->entry, &info->leds);
532 MergeIncludedCompatMaps(CompatInfo * into, CompatInfo * from,
533 enum merge_mode merge)
536 LEDInfo *led, *next_led;
537 GroupCompatInfo *gcm;
540 if (from->errorCount > 0) {
541 into->errorCount += from->errorCount;
544 if (into->name == NULL) {
545 into->name = from->name;
549 list_foreach(si, &from->interps, entry) {
550 if (merge != MERGE_DEFAULT)
552 if (!AddInterp(into, si))
556 for (i = 0, gcm = &from->groupCompat[0]; i < XkbNumKbdGroups;
558 if (merge != MERGE_DEFAULT)
560 if (!AddGroupCompat(into, i, gcm))
564 list_foreach_safe(led, next_led, &from->leds, entry) {
565 led->merge = (merge == MERGE_DEFAULT ? led->merge : merge);
566 if (!AddIndicatorMap(into, led))
572 HandleCompatMapFile(CompatInfo *info, XkbFile *file, enum merge_mode merge);
575 HandleIncludeCompatMap(CompatInfo *info, IncludeStmt *stmt)
577 enum merge_mode merge = MERGE_DEFAULT;
579 CompatInfo included, next_incl;
581 InitCompatInfo(&included, info->keymap, info->file_id);
584 included.name = stmt->stmt;
588 for (; stmt; stmt = stmt->next_incl) {
589 if (!ProcessIncludeFile(info->keymap->ctx, stmt, FILE_TYPE_COMPAT,
591 info->errorCount += 10;
592 ClearCompatInfo(&included);
596 InitCompatInfo(&next_incl, info->keymap, rtrn->id);
597 next_incl.file_id = rtrn->id;
598 next_incl.dflt = info->dflt;
599 next_incl.dflt.file_id = rtrn->id;
600 next_incl.dflt.merge = merge;
601 next_incl.ledDflt.file_id = rtrn->id;
602 next_incl.ledDflt.merge = merge;
603 next_incl.act = info->act;
605 HandleCompatMapFile(&next_incl, rtrn, MERGE_OVERRIDE);
607 MergeIncludedCompatMaps(&included, &next_incl, merge);
609 next_incl.act = NULL;
611 ClearCompatInfo(&next_incl);
615 MergeIncludedCompatMaps(info, &included, merge);
616 ClearCompatInfo(&included);
618 return (info->errorCount == 0);
621 static const LookupEntry useModMapValues[] = {
630 SetInterpField(CompatInfo *info, SymInterpInfo *si, const char *field,
631 ExprDef *arrayNdx, ExprDef *value)
633 struct xkb_keymap *keymap = info->keymap;
636 if (istreq(field, "action")) {
638 return ReportSINotArray(info, si, field);
640 if (!HandleActionDef(value, keymap, &si->interp.act, info->act))
643 si->defined |= SI_FIELD_ACTION;
645 else if (istreq(field, "virtualmodifier") ||
646 istreq(field, "virtualmod")) {
648 return ReportSINotArray(info, si, field);
650 if (!ResolveVirtualModifier(value, keymap, &ndx, &info->vmods))
651 return ReportSIBadType(info, si, field, "virtual modifier");
653 si->interp.virtual_mod = ndx;
654 si->defined |= SI_FIELD_VIRTUAL_MOD;
656 else if (istreq(field, "repeat")) {
660 return ReportSINotArray(info, si, field);
662 if (!ExprResolveBoolean(keymap->ctx, value, &set))
663 return ReportSIBadType(info, si, field, "boolean");
666 si->interp.flags |= XkbSI_AutoRepeat;
668 si->interp.flags &= ~XkbSI_AutoRepeat;
670 si->defined |= SI_FIELD_AUTO_REPEAT;
672 else if (istreq(field, "locking")) {
676 return ReportSINotArray(info, si, field);
678 if (!ExprResolveBoolean(keymap->ctx, value, &set))
679 return ReportSIBadType(info, si, field, "boolean");
682 si->interp.flags |= XkbSI_LockingKey;
684 si->interp.flags &= ~XkbSI_LockingKey;
686 si->defined |= SI_FIELD_LOCKING_KEY;
688 else if (istreq(field, "usemodmap") ||
689 istreq(field, "usemodmapmods")) {
693 return ReportSINotArray(info, si, field);
695 if (!ExprResolveEnum(keymap->ctx, value, &val, useModMapValues))
696 return ReportSIBadType(info, si, field, "level specification");
699 si->interp.match |= XkbSI_LevelOneOnly;
701 si->interp.match &= ~XkbSI_LevelOneOnly;
703 si->defined |= SI_FIELD_LEVEL_ONE_ONLY;
706 return ReportBadField(keymap, "symbol interpretation", field,
713 static const LookupEntry modComponentNames[] = {
714 {"base", XkbIM_UseBase},
715 {"latched", XkbIM_UseLatched},
716 {"locked", XkbIM_UseLocked},
717 {"effective", XkbIM_UseEffective},
718 {"compat", XkbIM_UseCompat},
719 {"any", XkbIM_UseAnyMods},
723 static const LookupEntry groupComponentNames[] = {
724 {"base", XkbIM_UseBase},
725 {"latched", XkbIM_UseLatched},
726 {"locked", XkbIM_UseLocked},
727 {"effective", XkbIM_UseEffective},
728 {"any", XkbIM_UseAnyGroup},
733 static const LookupEntry groupNames[] = {
748 SetIndicatorMapField(CompatInfo *info, LEDInfo *led,
749 const char *field, ExprDef *arrayNdx, ExprDef *value)
752 struct xkb_keymap *keymap = info->keymap;
754 if (istreq(field, "modifiers") || istreq(field, "mods")) {
756 return ReportIndicatorNotArray(info, led, field);
758 if (!ExprResolveVModMask(keymap, value, &led->mods))
759 return ReportIndicatorBadType(info, led, field, "modifier mask");
761 led->defined |= LED_FIELD_MODS;
763 else if (istreq(field, "groups")) {
767 return ReportIndicatorNotArray(info, led, field);
769 if (!ExprResolveMask(keymap->ctx, value, &mask, groupNames))
770 return ReportIndicatorBadType(info, led, field, "group mask");
773 led->defined |= LED_FIELD_GROUPS;
775 else if (istreq(field, "controls") || istreq(field, "ctrls")) {
779 return ReportIndicatorNotArray(info, led, field);
781 if (!ExprResolveMask(keymap->ctx, value, &mask, ctrlNames))
782 return ReportIndicatorBadType(info, led, field,
786 led->defined |= LED_FIELD_CTRLS;
788 else if (istreq(field, "allowexplicit")) {
792 return ReportIndicatorNotArray(info, led, field);
794 if (!ExprResolveBoolean(keymap->ctx, value, &set))
795 return ReportIndicatorBadType(info, led, field, "boolean");
798 led->flags &= ~XkbIM_NoExplicit;
800 led->flags |= XkbIM_NoExplicit;
802 led->defined |= LED_FIELD_EXPLICIT;
804 else if (istreq(field, "whichmodstate") ||
805 istreq(field, "whichmodifierstate")) {
809 return ReportIndicatorNotArray(info, led, field);
811 if (!ExprResolveMask(keymap->ctx, value, &mask, modComponentNames))
812 return ReportIndicatorBadType(info, led, field,
813 "mask of modifier state components");
815 led->which_mods = mask;
817 else if (istreq(field, "whichgroupstate")) {
821 return ReportIndicatorNotArray(info, led, field);
823 if (!ExprResolveMask(keymap->ctx, value, &mask, groupComponentNames))
824 return ReportIndicatorBadType(info, led, field,
825 "mask of group state components");
827 led->which_groups = mask;
829 else if (istreq(field, "driveskbd") ||
830 istreq(field, "driveskeyboard") ||
831 istreq(field, "leddriveskbd") ||
832 istreq(field, "leddriveskeyboard") ||
833 istreq(field, "indicatordriveskbd") ||
834 istreq(field, "indicatordriveskeyboard")) {
838 return ReportIndicatorNotArray(info, led, field);
840 if (!ExprResolveBoolean(keymap->ctx, value, &set))
841 return ReportIndicatorBadType(info, led, field, "boolean");
844 led->flags |= XkbIM_LEDDrivesKB;
846 led->flags &= ~XkbIM_LEDDrivesKB;
848 led->defined |= LED_FIELD_DRIVES_KBD;
850 else if (istreq(field, "index")) {
854 return ReportIndicatorNotArray(info, led, field);
856 if (!ExprResolveInteger(keymap->ctx, value, &ndx))
857 return ReportIndicatorBadType(info, led, field,
860 if (ndx < 1 || ndx > 32) {
861 log_err(info->keymap->ctx,
862 "Illegal indicator index %d (range 1..%d); "
863 "Index definition for %s indicator ignored\n",
864 ndx, XkbNumIndicators,
865 xkb_atom_text(keymap->ctx, led->name));
869 led->indicator = (xkb_led_index_t) ndx;
870 led->defined |= LED_FIELD_INDEX;
873 log_err(info->keymap->ctx,
874 "Unknown field %s in map for %s indicator; "
875 "Definition ignored\n",
876 field, xkb_atom_text(keymap->ctx, led->name));
884 HandleInterpVar(CompatInfo *info, VarDef *stmt)
886 const char *elem, *field;
890 if (!ExprResolveLhs(info->keymap->ctx, stmt->name, &elem, &field, &ndx))
891 ret = 0; /* internal error, already reported */
892 else if (elem && istreq(elem, "interpret"))
893 ret = SetInterpField(info, &info->dflt, field, ndx, stmt->value);
894 else if (elem && istreq(elem, "indicator"))
895 ret = SetIndicatorMapField(info, &info->ledDflt, field, ndx,
898 ret = SetActionField(info->keymap, elem, field, ndx, stmt->value,
904 HandleInterpBody(CompatInfo *info, VarDef *def, SymInterpInfo *si)
907 const char *elem, *field;
910 for (; def != NULL; def = (VarDef *) def->common.next) {
911 if (def->name && def->name->op == EXPR_FIELD_REF) {
912 ok = HandleInterpVar(info, def);
915 ok = ExprResolveLhs(info->keymap->ctx, def->name, &elem, &field,
918 ok = SetInterpField(info, si, field, arrayNdx, def->value);
925 HandleInterpDef(CompatInfo *info, InterpDef *def, enum merge_mode merge)
930 if (!ResolveStateAndPredicate(def->match, &pred, &mods, info)) {
931 log_err(info->keymap->ctx,
932 "Couldn't determine matching modifiers; "
933 "Symbol interpretation ignored\n");
936 if (def->merge != MERGE_DEFAULT)
941 if (!LookupKeysym(def->sym, &si.interp.sym)) {
942 log_err(info->keymap->ctx,
943 "Could not resolve keysym %s; "
944 "Symbol interpretation ignored\n",
948 si.interp.match = pred & XkbSI_OpMask;
949 si.interp.mods = mods;
950 if (!HandleInterpBody(info, def->def, &si)) {
955 if (!AddInterp(info, &si)) {
963 HandleGroupCompatDef(CompatInfo *info, GroupCompatDef *def,
964 enum merge_mode merge)
968 merge = (def->merge == MERGE_DEFAULT ? merge : def->merge);
970 if (def->group < 1 || def->group > XkbNumKbdGroups) {
971 log_err(info->keymap->ctx,
972 "Keyboard group must be in the range 1..%u; "
973 "Compatibility map for illegal group %u ignored\n",
974 XkbNumKbdGroups, def->group);
978 tmp.file_id = info->file_id;
981 if (!ExprResolveVModMask(info->keymap, def->def, &tmp.mods)) {
982 log_err(info->keymap->ctx,
983 "Expected a modifier mask in group compatibility definition; "
984 "Ignoring illegal compatibility map for group %u\n",
990 return AddGroupCompat(info, def->group - 1, &tmp);
994 HandleIndicatorMapDef(CompatInfo *info, IndicatorMapDef *def,
995 enum merge_mode merge)
1001 if (def->merge != MERGE_DEFAULT)
1004 led = info->ledDflt;
1006 led.name = def->name;
1009 for (var = def->body; var != NULL; var = (VarDef *) var->common.next) {
1010 const char *elem, *field;
1012 if (!ExprResolveLhs(info->keymap->ctx, var->name, &elem, &field,
1019 log_err(info->keymap->ctx,
1020 "Cannot set defaults for \"%s\" element in indicator map; "
1021 "Assignment to %s.%s ignored\n", elem, elem, field);
1025 ok = SetIndicatorMapField(info, &led, field, arrayNdx,
1031 return AddIndicatorMap(info, &led);
1037 HandleCompatMapFile(CompatInfo *info, XkbFile *file, enum merge_mode merge)
1042 merge = (merge == MERGE_DEFAULT ? MERGE_AUGMENT : merge);
1045 info->name = strdup_safe(file->name);
1047 for (stmt = file->defs; stmt; stmt = stmt->next) {
1048 switch (stmt->type) {
1050 ok = HandleIncludeCompatMap(info, (IncludeStmt *) stmt);
1053 ok = HandleInterpDef(info, (InterpDef *) stmt, merge);
1055 case STMT_GROUP_COMPAT:
1056 ok = HandleGroupCompatDef(info, (GroupCompatDef *) stmt, merge);
1058 case STMT_INDICATOR_MAP:
1059 ok = HandleIndicatorMapDef(info, (IndicatorMapDef *) stmt, merge);
1062 ok = HandleInterpVar(info, (VarDef *) stmt);
1065 ok = HandleVModDef((VModDef *) stmt, info->keymap, merge,
1069 log_err(info->keymap->ctx,
1070 "Interpretation files may not include other types; "
1071 "Ignoring %s\n", StmtTypeToString(stmt->type));
1079 if (info->errorCount > 10) {
1080 log_err(info->keymap->ctx,
1081 "Abandoning compatibility map \"%s\"\n", file->topName);
1088 CopyInterps(CompatInfo *info, bool needSymbol, unsigned pred)
1092 list_foreach(si, &info->interps, entry) {
1093 if (((si->interp.match & XkbSI_OpMask) != pred) ||
1094 (needSymbol && si->interp.sym == XKB_KEY_NoSymbol) ||
1095 (!needSymbol && si->interp.sym != XKB_KEY_NoSymbol))
1098 darray_append(info->keymap->sym_interpret, si->interp);
1103 BindIndicators(CompatInfo *info, struct list *unbound_leds)
1106 LEDInfo *led, *next_led;
1107 struct xkb_indicator_map *map;
1108 struct xkb_keymap *keymap = info->keymap;
1110 list_foreach(led, unbound_leds, entry) {
1111 if (led->indicator == XKB_LED_INVALID) {
1112 for (i = 0; i < XkbNumIndicators; i++) {
1113 if (keymap->indicator_names[i] &&
1114 streq(keymap->indicator_names[i],
1115 xkb_atom_text(keymap->ctx, led->name))) {
1116 led->indicator = i + 1;
1123 list_foreach(led, unbound_leds, entry) {
1124 if (led->indicator == XKB_LED_INVALID) {
1125 for (i = 0; i < XkbNumIndicators; i++) {
1126 if (keymap->indicator_names[i] == NULL) {
1127 keymap->indicator_names[i] =
1128 xkb_atom_text(keymap->ctx, led->name);
1129 led->indicator = i + 1;
1134 if (led->indicator == XKB_LED_INVALID) {
1135 log_err(info->keymap->ctx,
1136 "No unnamed indicators found; "
1137 "Virtual indicator map \"%s\" not bound\n",
1138 xkb_atom_text(keymap->ctx, led->name));
1144 list_foreach_safe(led, next_led, unbound_leds, entry) {
1145 if (led->indicator == XKB_LED_INVALID) {
1150 if (!streq(keymap->indicator_names[led->indicator - 1],
1151 xkb_atom_text(keymap->ctx, led->name))) {
1152 const char *old = keymap->indicator_names[led->indicator - 1];
1153 log_err(info->keymap->ctx,
1154 "Multiple names bound to indicator %d; "
1155 "Using %s, ignoring %s\n",
1156 led->indicator, old,
1157 xkb_atom_text(keymap->ctx, led->name));
1162 map = &keymap->indicators[led->indicator - 1];
1163 map->flags = led->flags;
1164 map->which_groups = led->which_groups;
1165 map->groups = led->groups;
1166 map->which_mods = led->which_mods;
1167 map->mods.mods = led->mods;
1168 map->ctrls = led->ctrls;
1172 list_init(unbound_leds);
1176 CopyIndicatorMapDefs(CompatInfo *info)
1178 LEDInfo *led, *next_led;
1179 struct list unbound_leds;
1180 struct xkb_indicator_map *im;
1181 struct xkb_keymap *keymap = info->keymap;
1183 list_init(&unbound_leds);
1185 list_foreach_safe(led, next_led, &info->leds, entry) {
1186 if (led->groups != 0 && led->which_groups == 0)
1187 led->which_groups = XkbIM_UseEffective;
1189 if (led->which_mods == 0 && led->mods)
1190 led->which_mods = XkbIM_UseEffective;
1192 if (led->indicator == XKB_LED_INVALID) {
1193 list_append(&led->entry, &unbound_leds);
1197 im = &keymap->indicators[led->indicator - 1];
1198 im->flags = led->flags;
1199 im->which_groups = led->which_groups;
1200 im->groups = led->groups;
1201 im->which_mods = led->which_mods;
1202 im->mods.mods = led->mods;
1203 im->ctrls = led->ctrls;
1204 keymap->indicator_names[led->indicator - 1] =
1205 xkb_atom_text(keymap->ctx, led->name);
1208 list_init(&info->leds);
1210 BindIndicators(info, &unbound_leds);
1216 CompileCompatMap(XkbFile *file, struct xkb_keymap *keymap,
1217 enum merge_mode merge)
1219 xkb_group_index_t i;
1221 GroupCompatInfo *gcm;
1223 InitCompatInfo(&info, keymap, file->id);
1224 info.dflt.merge = merge;
1225 info.ledDflt.merge = merge;
1227 HandleCompatMapFile(&info, file, merge);
1229 if (info.errorCount != 0)
1232 darray_init(keymap->sym_interpret);
1233 darray_growalloc(keymap->sym_interpret, info.nInterps);
1236 keymap->compat_section_name = strdup(info.name);
1238 if (info.nInterps > 0) {
1239 CopyInterps(&info, true, XkbSI_Exactly);
1240 CopyInterps(&info, true, XkbSI_AllOf | XkbSI_NoneOf);
1241 CopyInterps(&info, true, XkbSI_AnyOf);
1242 CopyInterps(&info, true, XkbSI_AnyOfOrNone);
1243 CopyInterps(&info, false, XkbSI_Exactly);
1244 CopyInterps(&info, false, XkbSI_AllOf | XkbSI_NoneOf);
1245 CopyInterps(&info, false, XkbSI_AnyOf);
1246 CopyInterps(&info, false, XkbSI_AnyOfOrNone);
1249 for (i = 0, gcm = &info.groupCompat[0]; i < XkbNumKbdGroups;
1251 if (gcm->file_id != 0 || gcm->mods != 0)
1252 keymap->groups[i].mods = gcm->mods;
1255 if (!CopyIndicatorMapDefs(&info))
1258 ClearCompatInfo(&info);
1262 ClearCompatInfo(&info);
1267 ComputeEffectiveMask(struct xkb_keymap *keymap, struct xkb_mods *mods)
1270 xkb_mod_mask_t vmask = mods->mods >> XkbNumModifiers;
1272 /* The effective mask is only real mods for now. */
1273 mods->mask = mods->mods & 0xff;
1275 for (i = 0; i < XkbNumVirtualMods; i++) {
1276 if (!(vmask & (1 << i)))
1278 mods->mask |= keymap->vmods[i];
1283 UpdateActionMods(struct xkb_keymap *keymap, union xkb_action *act,
1284 xkb_mod_mask_t rmodmask)
1287 struct xkb_mods *mods;
1289 switch (act->type) {
1291 case XkbSA_LatchMods:
1292 case XkbSA_LockMods:
1293 flags = act->mods.flags;
1294 mods = &act->mods.mods;
1298 flags = act->iso.flags;
1299 mods = &act->iso.mods;
1306 if (flags & XkbSA_UseModMapMods) {
1307 /* XXX: what's that. */
1309 mods->mods |= rmodmask;
1311 ComputeEffectiveMask(keymap, mods);
1315 * Find an interpretation which applies to this particular level, either by
1316 * finding an exact match for the symbol and modifier combination, or a
1317 * generic XKB_KEY_NoSymbol match.
1319 static struct xkb_sym_interpret *
1320 FindInterpForKey(struct xkb_keymap *keymap, struct xkb_key *key,
1321 xkb_group_index_t group, xkb_level_index_t level)
1323 struct xkb_sym_interpret *ret = NULL;
1324 struct xkb_sym_interpret *interp;
1325 const xkb_keysym_t *syms;
1328 num_syms = xkb_key_get_syms_by_level(keymap, key, group, level, &syms);
1332 darray_foreach(interp, keymap->sym_interpret) {
1336 if ((num_syms > 1 || interp->sym != syms[0]) &&
1337 interp->sym != XKB_KEY_NoSymbol)
1340 if (level == 0 || !(interp->match & XkbSI_LevelOneOnly))
1345 switch (interp->match & XkbSI_OpMask) {
1347 found = !(interp->mods & mods);
1349 case XkbSI_AnyOfOrNone:
1350 found = (!mods || (interp->mods & mods));
1353 found = !!(interp->mods & mods);
1356 found = ((interp->mods & mods) == interp->mods);
1359 found = (interp->mods == mods);
1366 if (found && interp->sym != XKB_KEY_NoSymbol)
1368 else if (found && !ret)
1378 ApplyInterpsToKey(struct xkb_keymap *keymap, struct xkb_key *key)
1380 #define INTERP_SIZE (8 * 4)
1381 struct xkb_sym_interpret *interps[INTERP_SIZE];
1382 xkb_mod_mask_t vmodmask = 0;
1384 xkb_group_index_t group;
1385 xkb_level_index_t level;
1388 /* If we've been told not to bind interps to this key, then don't. */
1389 if (key->explicit & XkbExplicitInterpretMask)
1392 for (i = 0; i < INTERP_SIZE; i++)
1395 for (group = 0; group < key->num_groups; group++) {
1396 for (level = 0; level < XkbKeyGroupWidth(keymap, key, group);
1398 i = (group * key->width) + level;
1399 if (i >= INTERP_SIZE) /* XXX FIXME */
1401 interps[i] = FindInterpForKey(keymap, key, group, level);
1407 if (num_acts && !key->actions) {
1408 key->actions = calloc(key->num_groups * key->width,
1409 sizeof(*key->actions));
1414 for (group = 0; group < key->num_groups; group++) {
1415 for (level = 0; level < XkbKeyGroupWidth(keymap, key, group);
1417 struct xkb_sym_interpret *interp;
1419 i = (group * key->width) + level;
1420 interp = interps[i];
1422 /* Infer default key behaviours from the base level. */
1423 if (group == 0 && level == 0) {
1424 if (!(key->explicit & XkbExplicitAutoRepeatMask) &&
1425 (!interp || (interp->flags & XkbSI_AutoRepeat)))
1426 key->repeats = true;
1432 if ((group == 0 && level == 0) ||
1433 !(interp->match & XkbSI_LevelOneOnly)) {
1434 if (interp->virtual_mod != XkbNoModifier)
1435 vmodmask |= (1 << interp->virtual_mod);
1438 key->actions[i] = interp->act;
1442 if (!(key->explicit & XkbExplicitVModMapMask))
1443 key->vmodmap = vmodmask;
1450 * This collects a bunch of disparate functions which was done in the server
1451 * at various points that really should've been done within xkbcomp. Turns out
1452 * your actions and types are a lot more useful when any of your modifiers
1453 * other than Shift actually do something ...
1456 UpdateModifiersFromCompat(struct xkb_keymap *keymap)
1458 xkb_mod_index_t vmod;
1459 xkb_group_index_t grp;
1460 xkb_led_index_t led;
1462 struct xkb_key *key;
1464 /* Find all the interprets for the key and bind them to actions,
1465 * which will also update the vmodmap. */
1466 xkb_foreach_key(key, keymap)
1467 if (!ApplyInterpsToKey(keymap, key))
1470 /* Update keymap->vmods, the virtual -> real mod mapping. */
1471 for (vmod = 0; vmod < XkbNumVirtualMods; vmod++)
1472 keymap->vmods[vmod] = 0;
1474 xkb_foreach_key(key, keymap) {
1478 for (vmod = 0; vmod < XkbNumVirtualMods; vmod++) {
1479 if (!(key->vmodmap & (1 << vmod)))
1481 keymap->vmods[vmod] |= key->modmap;
1485 /* Now update the level masks for all the types to reflect the vmods. */
1486 for (i = 0; i < keymap->num_types; i++) {
1487 ComputeEffectiveMask(keymap, &keymap->types[i].mods);
1489 for (j = 0; j < keymap->types[i].num_entries; j++) {
1490 ComputeEffectiveMask(keymap, &keymap->types[i].map[j].mods);
1491 ComputeEffectiveMask(keymap, &keymap->types[i].map[j].preserve);
1495 /* Update action modifiers. */
1496 xkb_foreach_key(key, keymap) {
1500 for (i = 0; i < key->num_groups * key->width; i++)
1501 UpdateActionMods(keymap, &key->actions[i], key->modmap);
1504 /* Update group modifiers. */
1505 for (grp = 0; grp < XkbNumKbdGroups; grp++)
1506 ComputeEffectiveMask(keymap, &keymap->groups[grp]);
1508 /* Update vmod -> indicator maps. */
1509 for (led = 0; led < XkbNumIndicators; led++)
1510 ComputeEffectiveMask(keymap, &keymap->indicators[led].mods);