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"
28 #include "parseutils.h"
32 typedef struct _SymInterpInfo {
33 unsigned short defined;
35 enum merge_mode merge;
38 struct xkb_sym_interpret interp;
41 #define _SI_VirtualMod (1 << 0)
42 #define _SI_Action (1 << 1)
43 #define _SI_AutoRepeat (1 << 2)
44 #define _SI_LockingKey (1 << 3)
45 #define _SI_LevelOneOnly (1 << 4)
47 typedef struct _LEDInfo {
48 unsigned short defined;
50 enum merge_mode merge;
54 unsigned char indicator;
56 unsigned char which_mods;
57 unsigned char real_mods;
59 unsigned char which_groups;
64 #define _LED_Index (1 << 0)
65 #define _LED_Mods (1 << 1)
66 #define _LED_Groups (1 << 2)
67 #define _LED_Ctrls (1 << 3)
68 #define _LED_Explicit (1 << 4)
69 #define _LED_Automatic (1 << 5)
70 #define _LED_DrivesKbd (1 << 6)
72 #define _LED_NotBound 255
74 typedef struct _GroupCompatInfo {
76 enum merge_mode merge;
78 unsigned char real_mods;
82 typedef struct _CompatInfo {
90 GroupCompatInfo groupCompat[XkbNumKbdGroups];
94 struct xkb_keymap *keymap;
98 siText(SymInterpInfo * si, CompatInfo * info)
100 static char buf[128];
102 if (si == &info->dflt) {
103 snprintf(buf, sizeof(buf), "default");
106 snprintf(buf, sizeof(buf), "%s+%s(%s)",
107 XkbcKeysymText(si->interp.sym),
108 XkbcSIMatchText(si->interp.match),
109 XkbcModMaskText(si->interp.mods, false));
115 ReportSINotArray(CompatInfo *info, SymInterpInfo *si, const char *field)
117 return ReportNotArray(info->keymap, "symbol interpretation", field,
122 ReportSIBadType(CompatInfo *info, SymInterpInfo *si, const char *field,
125 return ReportBadType(info->keymap, "symbol interpretation", field,
126 siText(si, info), wanted);
130 ReportIndicatorBadType(CompatInfo *info, LEDInfo *led,
131 const char *field, const char *wanted)
133 return ReportBadType(info->keymap, "indicator map", field,
134 xkb_atom_text(info->keymap->ctx, led->name),
139 ReportIndicatorNotArray(CompatInfo *info, LEDInfo *led,
142 return ReportNotArray(info->keymap, "indicator map", field,
143 xkb_atom_text(info->keymap->ctx, led->name));
147 ClearIndicatorMapInfo(struct xkb_context *ctx, LEDInfo * info)
149 info->name = xkb_atom_intern(ctx, "default");
150 info->indicator = _LED_NotBound;
151 info->flags = info->which_mods = info->real_mods = 0;
153 info->which_groups = info->groups = 0;
158 InitCompatInfo(CompatInfo *info, struct xkb_keymap *keymap, unsigned file_id)
162 info->keymap = keymap;
164 info->file_id = file_id;
165 info->errorCount = 0;
167 list_init(&info->interps);
169 info->dflt.file_id = file_id;
170 info->dflt.defined = 0;
171 info->dflt.merge = MERGE_OVERRIDE;
172 info->dflt.interp.flags = 0;
173 info->dflt.interp.virtual_mod = XkbNoModifier;
174 info->dflt.interp.act.type = XkbSA_NoAction;
175 for (i = 0; i < sizeof(info->dflt.interp.act.any.data); i++)
176 info->dflt.interp.act.any.data[i] = 0;
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)
191 ActionInfo *next_act;
192 SymInterpInfo *si, *next_si;
193 LEDInfo *led, *next_led;
194 struct xkb_keymap *keymap = info->keymap;
198 info->dflt.defined = 0;
199 info->dflt.merge = MERGE_AUGMENT;
200 info->dflt.interp.flags = 0;
201 info->dflt.interp.virtual_mod = XkbNoModifier;
202 info->dflt.interp.act.type = XkbSA_NoAction;
203 for (i = 0; i < sizeof(info->dflt.interp.act.any.data); i++)
204 info->dflt.interp.act.any.data[i] = 0;
205 ClearIndicatorMapInfo(keymap->ctx, &info->ledDflt);
207 list_foreach_safe(si, next_si, &info->interps, entry)
209 memset(&info->groupCompat[0], 0,
210 XkbNumKbdGroups * sizeof(GroupCompatInfo));
211 list_foreach_safe(led, next_led, &info->leds, entry)
214 next_act = info->act->next;
216 info->act = next_act;
219 ClearVModInfo(&info->vmods, keymap);
222 static SymInterpInfo *
223 NextInterp(CompatInfo * info)
227 si = calloc(1, sizeof(*si));
231 list_append(&si->entry, &info->interps);
237 static SymInterpInfo *
238 FindMatchingInterp(CompatInfo * info, SymInterpInfo * new)
242 list_foreach(old, &info->interps, entry)
243 if (old->interp.sym == new->interp.sym &&
244 old->interp.mods == new->interp.mods &&
245 old->interp.match == new->interp.match)
252 UseNewInterpField(unsigned field, SymInterpInfo *old, SymInterpInfo *new,
253 int verbosity, unsigned *collide)
255 if (!(old->defined & field))
258 if (new->defined & field) {
259 if ((old->file_id == new->file_id && verbosity > 0) || verbosity > 9)
262 if (new->merge != MERGE_AUGMENT)
270 AddInterp(CompatInfo * info, SymInterpInfo * new)
275 int verbosity = xkb_get_log_verbosity(info->keymap->ctx);
278 old = FindMatchingInterp(info, new);
280 if (new->merge == MERGE_REPLACE) {
282 if ((old->file_id == new->file_id && verbosity > 0) ||
284 log_warn(info->keymap->ctx,
285 "Multiple definitions for \"%s\"; "
286 "Earlier interpretation ignored\n",
293 if (UseNewInterpField(_SI_VirtualMod, old, new, verbosity,
295 old->interp.virtual_mod = new->interp.virtual_mod;
296 old->defined |= _SI_VirtualMod;
298 if (UseNewInterpField(_SI_Action, old, new, verbosity,
300 old->interp.act = new->interp.act;
301 old->defined |= _SI_Action;
303 if (UseNewInterpField(_SI_AutoRepeat, old, new, verbosity,
305 old->interp.flags &= ~XkbSI_AutoRepeat;
306 old->interp.flags |= (new->interp.flags & XkbSI_AutoRepeat);
307 old->defined |= _SI_AutoRepeat;
309 if (UseNewInterpField(_SI_LockingKey, old, new, verbosity,
311 old->interp.flags &= ~XkbSI_LockingKey;
312 old->interp.flags |= (new->interp.flags & XkbSI_LockingKey);
313 old->defined |= _SI_LockingKey;
315 if (UseNewInterpField(_SI_LevelOneOnly, old, new, verbosity,
317 old->interp.match &= ~XkbSI_LevelOneOnly;
318 old->interp.match |= (new->interp.match & XkbSI_LevelOneOnly);
319 old->defined |= _SI_LevelOneOnly;
323 log_warn(info->keymap->ctx,
324 "Multiple interpretations of \"%s\"; "
325 "Using %s definition for duplicate fields\n",
327 (new->merge != MERGE_AUGMENT ? "last" : "first"));
334 if ((new = NextInterp(info)) == NULL)
343 AddGroupCompat(CompatInfo *info, xkb_group_index_t group, GroupCompatInfo *new)
346 int verbosity = xkb_get_log_verbosity(info->keymap->ctx);
348 gc = &info->groupCompat[group];
349 if (gc->real_mods == new->real_mods && gc->vmods == new->vmods)
352 if ((gc->file_id == new->file_id && verbosity > 0) || verbosity > 9)
353 log_warn(info->keymap->ctx,
354 "Compat map for group %u redefined; "
355 "Using %s definition\n",
356 group + 1, (new->merge == MERGE_AUGMENT ? "old" : "new"));
358 if (new->defined && (new->merge != MERGE_AUGMENT || !gc->defined))
364 /***====================================================================***/
367 ResolveStateAndPredicate(ExprDef * expr,
369 unsigned *mods_rtrn, CompatInfo * info)
374 *pred_rtrn = XkbSI_AnyOfOrNone;
379 *pred_rtrn = XkbSI_Exactly;
380 if (expr->op == ExprActionDecl) {
381 const char *pred_txt = xkb_atom_text(info->keymap->ctx,
382 expr->value.action.name);
383 if (strcasecmp(pred_txt, "noneof") == 0)
384 *pred_rtrn = XkbSI_NoneOf;
385 else if (strcasecmp(pred_txt, "anyofornone") == 0)
386 *pred_rtrn = XkbSI_AnyOfOrNone;
387 else if (strcasecmp(pred_txt, "anyof") == 0)
388 *pred_rtrn = XkbSI_AnyOf;
389 else if (strcasecmp(pred_txt, "allof") == 0)
390 *pred_rtrn = XkbSI_AllOf;
391 else if (strcasecmp(pred_txt, "exactly") == 0)
392 *pred_rtrn = XkbSI_Exactly;
394 log_err(info->keymap->ctx,
395 "Illegal modifier predicate \"%s\"; Ignored\n", pred_txt);
398 expr = expr->value.action.args;
400 else if (expr->op == ExprIdent) {
401 const char *pred_txt = xkb_atom_text(info->keymap->ctx,
403 if ((pred_txt) && (strcasecmp(pred_txt, "any") == 0)) {
404 *pred_rtrn = XkbSI_AnyOf;
410 if (ExprResolveModMask(info->keymap->ctx, expr, &result)) {
411 *mods_rtrn = result.uval;
417 /***====================================================================***/
420 UseNewLEDField(unsigned field, LEDInfo *old, LEDInfo *new,
421 int verbosity, unsigned *collide)
423 if (!(old->defined & field))
426 if (new->defined & field) {
427 if ((old->file_id == new->file_id && verbosity > 0) || verbosity > 9)
430 if (new->merge != MERGE_AUGMENT)
438 AddIndicatorMap(CompatInfo *info, LEDInfo *new)
442 struct xkb_context *ctx = info->keymap->ctx;
443 int verbosity = xkb_get_log_verbosity(ctx);
445 list_foreach(old, &info->leds, entry) {
446 if (old->name == new->name) {
447 if ((old->real_mods == new->real_mods) &&
448 (old->vmods == new->vmods) &&
449 (old->groups == new->groups) &&
450 (old->ctrls == new->ctrls) &&
451 (old->which_mods == new->which_mods) &&
452 (old->which_groups == new->which_groups)) {
453 old->defined |= new->defined;
457 if (new->merge == MERGE_REPLACE) {
458 struct list entry = old->entry;
459 if ((old->file_id == new->file_id && verbosity > 0) ||
461 log_warn(info->keymap->ctx,
462 "Map for indicator %s redefined; "
463 "Earlier definition ignored\n",
464 xkb_atom_text(ctx, old->name));
471 if (UseNewLEDField(_LED_Index, old, new, verbosity,
473 old->indicator = new->indicator;
474 old->defined |= _LED_Index;
476 if (UseNewLEDField(_LED_Mods, old, new, verbosity,
478 old->which_mods = new->which_mods;
479 old->real_mods = new->real_mods;
480 old->vmods = new->vmods;
481 old->defined |= _LED_Mods;
483 if (UseNewLEDField(_LED_Groups, old, new, verbosity,
485 old->which_groups = new->which_groups;
486 old->groups = new->groups;
487 old->defined |= _LED_Groups;
489 if (UseNewLEDField(_LED_Ctrls, old, new, verbosity,
491 old->ctrls = new->ctrls;
492 old->defined |= _LED_Ctrls;
494 if (UseNewLEDField(_LED_Explicit, old, new, verbosity,
496 old->flags &= ~XkbIM_NoExplicit;
497 old->flags |= (new->flags & XkbIM_NoExplicit);
498 old->defined |= _LED_Explicit;
500 if (UseNewLEDField(_LED_Automatic, old, new, verbosity,
502 old->flags &= ~XkbIM_NoAutomatic;
503 old->flags |= (new->flags & XkbIM_NoAutomatic);
504 old->defined |= _LED_Automatic;
506 if (UseNewLEDField(_LED_DrivesKbd, old, new, verbosity,
508 old->flags &= ~XkbIM_LEDDrivesKB;
509 old->flags |= (new->flags & XkbIM_LEDDrivesKB);
510 old->defined |= _LED_DrivesKbd;
514 log_warn(info->keymap->ctx,
515 "Map for indicator %s redefined; "
516 "Using %s definition for duplicate fields\n",
517 xkb_atom_text(ctx, old->name),
518 (new->merge == MERGE_AUGMENT ? "first" : "last"));
526 old = malloc(sizeof(*old));
528 log_wsgo(info->keymap->ctx,
529 "Couldn't allocate indicator map; "
530 "Map for indicator %s not compiled\n",
531 xkb_atom_text(ctx, new->name));
536 list_append(&old->entry, &info->leds);
542 MergeIncludedCompatMaps(CompatInfo * into, CompatInfo * from,
543 enum merge_mode merge)
546 LEDInfo *led, *next_led;
547 GroupCompatInfo *gcm;
550 if (from->errorCount > 0) {
551 into->errorCount += from->errorCount;
554 if (into->name == NULL) {
555 into->name = from->name;
559 list_foreach(si, &from->interps, entry) {
560 if (merge != MERGE_DEFAULT)
562 if (!AddInterp(into, si))
566 for (i = 0, gcm = &from->groupCompat[0]; i < XkbNumKbdGroups;
568 if (merge != MERGE_DEFAULT)
570 if (!AddGroupCompat(into, i, gcm))
574 list_foreach_safe(led, next_led, &from->leds, entry) {
575 led->merge = (merge == MERGE_DEFAULT ? led->merge : merge);
576 if (!AddIndicatorMap(into, led))
582 HandleCompatMapFile(CompatInfo *info, XkbFile *file, enum merge_mode merge);
585 HandleIncludeCompatMap(CompatInfo *info, IncludeStmt *stmt)
587 enum merge_mode merge = MERGE_DEFAULT;
589 CompatInfo included, next_incl;
591 InitCompatInfo(&included, info->keymap, info->file_id);
594 included.name = stmt->stmt;
598 for (; stmt; stmt = stmt->next) {
599 if (!ProcessIncludeFile(info->keymap->ctx, stmt, FILE_TYPE_COMPAT,
601 info->errorCount += 10;
602 ClearCompatInfo(&included);
606 InitCompatInfo(&next_incl, info->keymap, rtrn->id);
607 next_incl.file_id = rtrn->id;
608 next_incl.dflt = info->dflt;
609 next_incl.dflt.file_id = rtrn->id;
610 next_incl.dflt.merge = merge;
611 next_incl.ledDflt.file_id = rtrn->id;
612 next_incl.ledDflt.merge = merge;
613 next_incl.act = info->act;
615 HandleCompatMapFile(&next_incl, rtrn, MERGE_OVERRIDE);
617 MergeIncludedCompatMaps(&included, &next_incl, merge);
619 next_incl.act = NULL;
621 ClearCompatInfo(&next_incl);
625 MergeIncludedCompatMaps(info, &included, merge);
626 ClearCompatInfo(&included);
628 return (info->errorCount == 0);
631 static const LookupEntry useModMapValues[] = {
640 SetInterpField(CompatInfo *info, SymInterpInfo *si, char *field,
641 ExprDef *arrayNdx, ExprDef *value)
645 struct xkb_keymap *keymap = info->keymap;
647 if (strcasecmp(field, "action") == 0) {
648 if (arrayNdx != NULL)
649 return ReportSINotArray(info, si, field);
650 ok = HandleActionDef(value, keymap, &si->interp.act.any,
653 si->defined |= _SI_Action;
655 else if ((strcasecmp(field, "virtualmodifier") == 0) ||
656 (strcasecmp(field, "virtualmod") == 0)) {
657 if (arrayNdx != NULL)
658 return ReportSINotArray(info, si, field);
659 ok = ResolveVirtualModifier(value, keymap, &tmp, &info->vmods);
661 si->interp.virtual_mod = tmp.uval;
662 si->defined |= _SI_VirtualMod;
665 return ReportSIBadType(info, si, field, "virtual modifier");
667 else if (strcasecmp(field, "repeat") == 0) {
668 if (arrayNdx != NULL)
669 return ReportSINotArray(info, si, field);
670 ok = ExprResolveBoolean(keymap->ctx, value, &tmp);
673 si->interp.flags |= XkbSI_AutoRepeat;
675 si->interp.flags &= ~XkbSI_AutoRepeat;
676 si->defined |= _SI_AutoRepeat;
679 return ReportSIBadType(info, si, field, "boolean");
681 else if (strcasecmp(field, "locking") == 0) {
682 if (arrayNdx != NULL)
683 return ReportSINotArray(info, si, field);
684 ok = ExprResolveBoolean(keymap->ctx, value, &tmp);
687 si->interp.flags |= XkbSI_LockingKey;
689 si->interp.flags &= ~XkbSI_LockingKey;
690 si->defined |= _SI_LockingKey;
693 return ReportSIBadType(info, si, field, "boolean");
695 else if ((strcasecmp(field, "usemodmap") == 0) ||
696 (strcasecmp(field, "usemodmapmods") == 0)) {
697 if (arrayNdx != NULL)
698 return ReportSINotArray(info, si, field);
699 ok = ExprResolveEnum(keymap->ctx, value, &tmp, useModMapValues);
702 si->interp.match |= XkbSI_LevelOneOnly;
704 si->interp.match &= ~XkbSI_LevelOneOnly;
705 si->defined |= _SI_LevelOneOnly;
708 return ReportSIBadType(info, si, field, "level specification");
711 ok = ReportBadField(keymap, "symbol interpretation", field,
717 static const LookupEntry modComponentNames[] = {
718 {"base", XkbIM_UseBase},
719 {"latched", XkbIM_UseLatched},
720 {"locked", XkbIM_UseLocked},
721 {"effective", XkbIM_UseEffective},
722 {"compat", XkbIM_UseCompat},
723 {"any", XkbIM_UseAnyMods},
727 static const LookupEntry groupComponentNames[] = {
728 {"base", XkbIM_UseBase},
729 {"latched", XkbIM_UseLatched},
730 {"locked", XkbIM_UseLocked},
731 {"effective", XkbIM_UseEffective},
732 {"any", XkbIM_UseAnyGroup},
737 static const LookupEntry groupNames[] = {
752 SetIndicatorMapField(CompatInfo *info, LEDInfo *led,
753 char *field, ExprDef *arrayNdx, ExprDef *value)
757 struct xkb_keymap *keymap = info->keymap;
759 if (strcasecmp(field, "modifiers") == 0 || strcasecmp(field, "mods") == 0) {
760 if (arrayNdx != NULL)
761 return ReportIndicatorNotArray(info, led, field);
763 if (!ExprResolveVModMask(keymap, value, &rtrn))
764 return ReportIndicatorBadType(info, led, field, "modifier mask");
766 led->real_mods = rtrn.uval & 0xff;
767 led->vmods = (rtrn.uval >> 8) & 0xff;
768 led->defined |= _LED_Mods;
770 else if (strcasecmp(field, "groups") == 0) {
771 if (arrayNdx != NULL)
772 return ReportIndicatorNotArray(info, led, field);
774 if (!ExprResolveMask(keymap->ctx, value, &rtrn, groupNames))
775 return ReportIndicatorBadType(info, led, field, "group mask");
777 led->groups = rtrn.uval;
778 led->defined |= _LED_Groups;
780 else if (strcasecmp(field, "controls") == 0 ||
781 strcasecmp(field, "ctrls") == 0) {
782 if (arrayNdx != NULL)
783 return ReportIndicatorNotArray(info, led, field);
785 if (!ExprResolveMask(keymap->ctx, value, &rtrn, ctrlNames))
786 return ReportIndicatorBadType(info, led, field,
789 led->ctrls = rtrn.uval;
790 led->defined |= _LED_Ctrls;
792 else if (strcasecmp(field, "allowexplicit") == 0) {
793 if (arrayNdx != NULL)
794 return ReportIndicatorNotArray(info, led, field);
796 if (!ExprResolveBoolean(keymap->ctx, value, &rtrn))
797 return ReportIndicatorBadType(info, led, field, "boolean");
800 led->flags &= ~XkbIM_NoExplicit;
802 led->flags |= XkbIM_NoExplicit;
803 led->defined |= _LED_Explicit;
805 else if (strcasecmp(field, "whichmodstate") == 0 ||
806 strcasecmp(field, "whichmodifierstate") == 0) {
807 if (arrayNdx != NULL)
808 return ReportIndicatorNotArray(info, led, field);
810 if (!ExprResolveMask(keymap->ctx, value, &rtrn, modComponentNames))
811 return ReportIndicatorBadType(info, led, field,
812 "mask of modifier state components");
814 led->which_mods = rtrn.uval;
816 else if (strcasecmp(field, "whichgroupstate") == 0) {
817 if (arrayNdx != NULL)
818 return ReportIndicatorNotArray(info, led, field);
820 if (!ExprResolveMask(keymap->ctx, value, &rtrn, groupComponentNames))
821 return ReportIndicatorBadType(info, led, field,
822 "mask of group state components");
824 led->which_groups = rtrn.uval;
826 else if (strcasecmp(field, "driveskbd") == 0 ||
827 strcasecmp(field, "driveskeyboard") == 0 ||
828 strcasecmp(field, "leddriveskbd") == 0 ||
829 strcasecmp(field, "leddriveskeyboard") == 0 ||
830 strcasecmp(field, "indicatordriveskbd") == 0 ||
831 strcasecmp(field, "indicatordriveskeyboard") == 0) {
832 if (arrayNdx != NULL)
833 return ReportIndicatorNotArray(info, led, field);
835 if (!ExprResolveBoolean(keymap->ctx, value, &rtrn))
836 return ReportIndicatorBadType(info, led, field, "boolean");
839 led->flags |= XkbIM_LEDDrivesKB;
841 led->flags &= ~XkbIM_LEDDrivesKB;
842 led->defined |= _LED_DrivesKbd;
844 else if (strcasecmp(field, "index") == 0) {
845 if (arrayNdx != NULL)
846 return ReportIndicatorNotArray(info, led, field);
848 if (!ExprResolveInteger(keymap->ctx, value, &rtrn))
849 return ReportIndicatorBadType(info, led, field,
852 if (rtrn.uval < 1 || rtrn.uval > 32) {
853 log_err(info->keymap->ctx,
854 "Illegal indicator index %d (range 1..%d); "
855 "Index definition for %s indicator ignored\n",
856 rtrn.uval, XkbNumIndicators,
857 xkb_atom_text(keymap->ctx, led->name));
861 led->indicator = rtrn.uval;
862 led->defined |= _LED_Index;
865 log_err(info->keymap->ctx,
866 "Unknown field %s in map for %s indicator; "
867 "Definition ignored\n",
868 field, xkb_atom_text(keymap->ctx, led->name));
876 HandleInterpVar(CompatInfo *info, VarDef *stmt)
878 ExprResult elem, field;
882 if (ExprResolveLhs(info->keymap, stmt->name, &elem, &field, &ndx) == 0)
883 ret = 0; /* internal error, already reported */
884 else if (elem.str && (strcasecmp(elem.str, "interpret") == 0))
885 ret = SetInterpField(info, &info->dflt, field.str, ndx, stmt->value);
886 else if (elem.str && (strcasecmp(elem.str, "indicator") == 0))
887 ret = SetIndicatorMapField(info, &info->ledDflt, field.str, ndx,
890 ret = SetActionField(info->keymap, elem.str, field.str, ndx,
891 stmt->value, &info->act);
898 HandleInterpBody(CompatInfo *info, VarDef *def, SymInterpInfo *si)
901 ExprResult tmp, field;
904 for (; def != NULL; def = (VarDef *) def->common.next) {
905 if ((def->name) && (def->name->type == ExprFieldRef)) {
906 ok = HandleInterpVar(info, def);
909 ok = ExprResolveLhs(info->keymap, def->name, &tmp, &field, &arrayNdx);
911 ok = SetInterpField(info, si, field.str, arrayNdx, def->value);
919 HandleInterpDef(CompatInfo *info, InterpDef *def, enum merge_mode merge)
924 if (!ResolveStateAndPredicate(def->match, &pred, &mods, info)) {
925 log_err(info->keymap->ctx,
926 "Couldn't determine matching modifiers; "
927 "Symbol interpretation ignored\n");
930 if (def->merge != MERGE_DEFAULT)
935 if (!LookupKeysym(def->sym, &si.interp.sym)) {
936 log_err(info->keymap->ctx,
937 "Could not resolve keysym %s; "
938 "Symbol interpretation ignored\n",
942 si.interp.match = pred & XkbSI_OpMask;
943 si.interp.mods = mods;
944 if (!HandleInterpBody(info, def->def, &si)) {
949 if (!AddInterp(info, &si)) {
957 HandleGroupCompatDef(CompatInfo *info, GroupCompatDef *def,
958 enum merge_mode merge)
963 if (def->merge != MERGE_DEFAULT)
965 if (def->group < 1 || def->group > XkbNumKbdGroups) {
966 log_err(info->keymap->ctx,
967 "Keyboard group must be in the range 1..%u; "
968 "Compatibility map for illegal group %u ignored\n",
969 XkbNumKbdGroups, def->group);
972 tmp.file_id = info->file_id;
974 if (!ExprResolveVModMask(info->keymap, def->def, &val)) {
975 log_err(info->keymap->ctx,
976 "Expected a modifier mask in group compatibility definition; "
977 "Ignoring illegal compatibility map for group %u\n",
981 tmp.real_mods = val.uval & 0xff;
982 tmp.vmods = (val.uval >> 8) & 0xffff;
984 return AddGroupCompat(info, def->group - 1, &tmp);
988 HandleIndicatorMapDef(CompatInfo *info, IndicatorMapDef *def,
989 enum merge_mode merge)
995 if (def->merge != MERGE_DEFAULT)
1000 led.name = def->name;
1003 for (var = def->body; var != NULL; var = (VarDef *) var->common.next) {
1004 ExprResult elem, field;
1006 if (!ExprResolveLhs(info->keymap, var->name, &elem, &field,
1012 if (elem.str != NULL) {
1013 log_err(info->keymap->ctx,
1014 "Cannot set defaults for \"%s\" element in indicator map; "
1015 "Assignment to %s.%s ignored\n",
1016 elem.str, elem.str, field.str);
1020 ok = SetIndicatorMapField(info, &led, field.str, arrayNdx,
1028 return AddIndicatorMap(info, &led);
1034 HandleCompatMapFile(CompatInfo *info, XkbFile *file, enum merge_mode merge)
1038 if (merge == MERGE_DEFAULT)
1039 merge = MERGE_AUGMENT;
1041 info->name = uDupString(file->name);
1045 switch (stmt->stmtType) {
1047 if (!HandleIncludeCompatMap(info, (IncludeStmt *) stmt))
1051 if (!HandleInterpDef(info, (InterpDef *) stmt, merge))
1054 case StmtGroupCompatDef:
1055 if (!HandleGroupCompatDef(info, (GroupCompatDef *) stmt, merge))
1058 case StmtIndicatorMapDef:
1059 if (!HandleIndicatorMapDef(info, (IndicatorMapDef *) stmt, merge))
1063 if (!HandleInterpVar(info, (VarDef *) stmt))
1067 if (!HandleVModDef((VModDef *) stmt, info->keymap, merge,
1071 case StmtKeycodeDef:
1072 log_err(info->keymap->ctx,
1073 "Interpretation files may not include other types; "
1074 "Ignoring definition of key name\n");
1078 log_wsgo(info->keymap->ctx,
1079 "Unexpected statement type %d in HandleCompatMapFile\n",
1084 if (info->errorCount > 10) {
1085 log_err(info->keymap->ctx,
1086 "Abandoning compatibility map \"%s\"\n", file->topName);
1093 CopyInterps(CompatInfo *info, bool needSymbol, unsigned pred)
1097 list_foreach(si, &info->interps, entry) {
1098 if (((si->interp.match & XkbSI_OpMask) != pred) ||
1099 (needSymbol && si->interp.sym == XKB_KEY_NoSymbol) ||
1100 (!needSymbol && si->interp.sym != XKB_KEY_NoSymbol))
1103 darray_append(info->keymap->sym_interpret, si->interp);
1108 BindIndicators(CompatInfo *info, struct list *unbound_leds)
1111 LEDInfo *led, *next_led;
1112 struct xkb_indicator_map *map;
1113 struct xkb_keymap *keymap = info->keymap;
1115 list_foreach(led, unbound_leds, entry) {
1116 if (led->indicator == _LED_NotBound) {
1117 for (i = 0; i < XkbNumIndicators; i++) {
1118 if (keymap->indicator_names[i] &&
1119 strcmp(keymap->indicator_names[i],
1120 xkb_atom_text(keymap->ctx, led->name)) == 0) {
1121 led->indicator = i + 1;
1128 list_foreach(led, unbound_leds, entry) {
1129 if (led->indicator == _LED_NotBound) {
1130 for (i = 0; i < XkbNumIndicators; i++) {
1131 if (keymap->indicator_names[i] == NULL) {
1132 keymap->indicator_names[i] =
1133 xkb_atom_strdup(keymap->ctx, led->name);
1134 led->indicator = i + 1;
1139 if (led->indicator == _LED_NotBound) {
1140 log_err(info->keymap->ctx,
1141 "No unnamed indicators found; "
1142 "Virtual indicator map \"%s\" not bound\n",
1143 xkb_atom_text(keymap->ctx, led->name));
1149 list_foreach_safe(led, next_led, unbound_leds, entry) {
1150 if (led->indicator == _LED_NotBound) {
1155 if (strcmp(keymap->indicator_names[led->indicator - 1],
1156 xkb_atom_text(keymap->ctx, led->name)) != 0) {
1157 const char *old = keymap->indicator_names[led->indicator - 1];
1158 log_err(info->keymap->ctx,
1159 "Multiple names bound to indicator %d; "
1160 "Using %s, ignoring %s\n",
1161 led->indicator, old,
1162 xkb_atom_text(keymap->ctx, led->name));
1167 map = &keymap->indicators[led->indicator - 1];
1168 map->flags = led->flags;
1169 map->which_groups = led->which_groups;
1170 map->groups = led->groups;
1171 map->which_mods = led->which_mods;
1172 map->mods.mask = led->real_mods;
1173 map->mods.real_mods = led->real_mods;
1174 map->mods.vmods = led->vmods;
1175 map->ctrls = led->ctrls;
1179 list_init(unbound_leds);
1183 CopyIndicatorMapDefs(CompatInfo *info)
1185 LEDInfo *led, *next_led;
1186 struct list unbound_leds;
1187 struct xkb_indicator_map *im;
1188 struct xkb_keymap *keymap = info->keymap;
1190 list_init(&unbound_leds);
1192 list_foreach_safe(led, next_led, &info->leds, entry) {
1193 if (led->groups != 0 && led->which_groups == 0)
1194 led->which_groups = XkbIM_UseEffective;
1196 if (led->which_mods == 0 && (led->real_mods || led->vmods))
1197 led->which_mods = XkbIM_UseEffective;
1199 if (led->indicator == _LED_NotBound) {
1200 list_append(&led->entry, &unbound_leds);
1204 im = &keymap->indicators[led->indicator - 1];
1205 im->flags = led->flags;
1206 im->which_groups = led->which_groups;
1207 im->groups = led->groups;
1208 im->which_mods = led->which_mods;
1209 im->mods.mask = led->real_mods;
1210 im->mods.real_mods = led->real_mods;
1211 im->mods.vmods = led->vmods;
1212 im->ctrls = led->ctrls;
1213 free(keymap->indicator_names[led->indicator - 1]);
1214 keymap->indicator_names[led->indicator - 1] =
1215 xkb_atom_strdup(keymap->ctx, led->name);
1218 list_init(&info->leds);
1220 BindIndicators(info, &unbound_leds);
1226 CompileCompatMap(XkbFile *file, struct xkb_keymap *keymap,
1227 enum merge_mode merge)
1229 xkb_group_index_t i;
1231 GroupCompatInfo *gcm;
1233 InitCompatInfo(&info, keymap, file->id);
1234 info.dflt.merge = merge;
1235 info.ledDflt.merge = merge;
1237 HandleCompatMapFile(&info, file, merge);
1239 if (info.errorCount != 0)
1242 darray_init(keymap->sym_interpret);
1243 darray_growalloc(keymap->sym_interpret, info.nInterps);
1246 keymap->compat_section_name = strdup(info.name);
1248 if (info.nInterps > 0) {
1249 CopyInterps(&info, true, XkbSI_Exactly);
1250 CopyInterps(&info, true, XkbSI_AllOf | XkbSI_NoneOf);
1251 CopyInterps(&info, true, XkbSI_AnyOf);
1252 CopyInterps(&info, true, XkbSI_AnyOfOrNone);
1253 CopyInterps(&info, false, XkbSI_Exactly);
1254 CopyInterps(&info, false, XkbSI_AllOf | XkbSI_NoneOf);
1255 CopyInterps(&info, false, XkbSI_AnyOf);
1256 CopyInterps(&info, false, XkbSI_AnyOfOrNone);
1259 for (i = 0, gcm = &info.groupCompat[0]; i < XkbNumKbdGroups;
1261 if (gcm->file_id != 0 || gcm->real_mods != 0 || gcm->vmods != 0) {
1262 keymap->groups[i].mask = gcm->real_mods;
1263 keymap->groups[i].real_mods = gcm->real_mods;
1264 keymap->groups[i].vmods = gcm->vmods;
1268 if (!CopyIndicatorMapDefs(&info))
1271 ClearCompatInfo(&info);
1275 ClearCompatInfo(&info);
1280 VModsToReal(struct xkb_keymap *keymap, uint32_t vmodmask)
1288 for (i = 0; i < XkbNumVirtualMods; i++) {
1289 if (!(vmodmask & (1 << i)))
1291 ret |= keymap->vmods[i];
1298 UpdateActionMods(struct xkb_keymap *keymap, union xkb_action *act,
1301 switch (act->type) {
1303 case XkbSA_LatchMods:
1304 case XkbSA_LockMods:
1305 if (act->mods.flags & XkbSA_UseModMapMods)
1306 act->mods.real_mods = rmodmask;
1307 act->mods.mask = act->mods.real_mods;
1308 act->mods.mask |= VModsToReal(keymap, act->mods.vmods);
1312 if (act->iso.flags & XkbSA_UseModMapMods)
1313 act->iso.real_mods = rmodmask;
1314 act->iso.mask = act->iso.real_mods;
1315 act->iso.mask |= VModsToReal(keymap, act->iso.vmods);
1324 * Find an interpretation which applies to this particular level, either by
1325 * finding an exact match for the symbol and modifier combination, or a
1326 * generic XKB_KEY_NoSymbol match.
1328 static struct xkb_sym_interpret *
1329 FindInterpForKey(struct xkb_keymap *keymap, struct xkb_key *key,
1330 xkb_group_index_t group, uint32_t level)
1332 struct xkb_sym_interpret *ret = NULL;
1333 struct xkb_sym_interpret *interp;
1334 const xkb_keysym_t *syms;
1337 num_syms = xkb_key_get_syms_by_level(keymap, key, group, level, &syms);
1341 darray_foreach(interp, keymap->sym_interpret) {
1345 if ((num_syms > 1 || interp->sym != syms[0]) &&
1346 interp->sym != XKB_KEY_NoSymbol)
1349 if (level == 0 || !(interp->match & XkbSI_LevelOneOnly))
1354 switch (interp->match & XkbSI_OpMask) {
1356 found = !(interp->mods & mods);
1358 case XkbSI_AnyOfOrNone:
1359 found = (!mods || (interp->mods & mods));
1362 found = !!(interp->mods & mods);
1365 found = ((interp->mods & mods) == interp->mods);
1368 found = (interp->mods == mods);
1375 if (found && interp->sym != XKB_KEY_NoSymbol)
1377 else if (found && !ret)
1387 ApplyInterpsToKey(struct xkb_keymap *keymap, struct xkb_key *key)
1389 #define INTERP_SIZE (8 * 4)
1390 struct xkb_sym_interpret *interps[INTERP_SIZE];
1391 union xkb_action *acts;
1392 uint32_t vmodmask = 0;
1394 xkb_group_index_t group;
1398 /* If we've been told not to bind interps to this key, then don't. */
1399 if (key->explicit & XkbExplicitInterpretMask)
1402 for (i = 0; i < INTERP_SIZE; i++)
1405 for (group = 0; group < key->num_groups; group++) {
1406 for (level = 0; level < XkbKeyGroupWidth(keymap, key, group);
1408 i = (group * key->width) + level;
1409 if (i >= INTERP_SIZE) /* XXX FIXME */
1411 interps[i] = FindInterpForKey(keymap, key, group, level);
1418 num_acts = key->num_groups * key->width;
1419 acts = XkbcResizeKeyActions(keymap, key, num_acts);
1420 if (num_acts && !acts)
1423 for (group = 0; group < key->num_groups; group++) {
1424 for (level = 0; level < XkbKeyGroupWidth(keymap, key, group);
1426 struct xkb_sym_interpret *interp;
1428 i = (group * key->width) + level;
1429 interp = interps[i];
1431 /* Infer default key behaviours from the base level. */
1432 if (group == 0 && level == 0) {
1433 if (!(key->explicit & XkbExplicitAutoRepeatMask) &&
1434 (!interp || (interp->flags & XkbSI_AutoRepeat)))
1435 key->repeats = true;
1436 if (!(key->explicit & XkbExplicitBehaviorMask) &&
1437 interp && (interp->flags & XkbSI_LockingKey))
1438 key->behavior.type = XkbKB_Lock;
1444 if ((group == 0 && level == 0) ||
1445 !(interp->match & XkbSI_LevelOneOnly)) {
1446 if (interp->virtual_mod != XkbNoModifier)
1447 vmodmask |= (1 << interp->virtual_mod);
1449 acts[i] = interp->act;
1453 if (!(key->explicit & XkbExplicitVModMapMask))
1454 key->vmodmap = vmodmask;
1461 * This collects a bunch of disparate functions which was done in the server
1462 * at various points that really should've been done within xkbcomp. Turns out
1463 * your actions and types are a lot more useful when any of your modifiers
1464 * other than Shift actually do something ...
1467 UpdateModifiersFromCompat(struct xkb_keymap *keymap)
1469 struct xkb_key *key;
1471 struct xkb_key_type *type;
1472 struct xkb_kt_map_entry *entry;
1474 /* Find all the interprets for the key and bind them to actions,
1475 * which will also update the vmodmap. */
1476 xkb_foreach_key(key, keymap)
1477 if (!ApplyInterpsToKey(keymap, key))
1480 /* Update keymap->vmods, the virtual -> real mod mapping. */
1481 for (i = 0; i < XkbNumVirtualMods; i++)
1482 keymap->vmods[i] = 0;
1483 xkb_foreach_key(key, keymap) {
1487 for (i = 0; i < XkbNumVirtualMods; i++) {
1488 if (!(key->vmodmap & (1 << i)))
1490 keymap->vmods[i] |= key->modmap;
1494 /* Now update the level masks for all the types to reflect the vmods. */
1495 darray_foreach(type, keymap->types) {
1498 type->mods.mask = type->mods.real_mods;
1499 type->mods.mask |= VModsToReal(keymap, type->mods.vmods);
1500 for (j = 0; j < XkbNumVirtualMods; j++) {
1501 if (!(type->mods.vmods & (1 << j)))
1503 mask |= keymap->vmods[j];
1506 darray_foreach(entry, type->map)
1507 entry->mods.mask = entry->mods.real_mods |
1508 VModsToReal(keymap, entry->mods.vmods);
1511 /* Update action modifiers. */
1512 xkb_foreach_key(key, keymap) {
1513 union xkb_action *acts = XkbKeyActionsPtr(keymap, key);
1514 for (i = 0; i < XkbKeyNumActions(key); i++) {
1515 if (acts[i].any.type == XkbSA_NoAction)
1517 UpdateActionMods(keymap, &acts[i], key->modmap);
1521 /* Update group modifiers. */
1522 for (i = 0; i < XkbNumKbdGroups; i++) {
1523 struct xkb_mods *group = &keymap->groups[i];
1524 group->mask = group->real_mods | VModsToReal(keymap, group->vmods);
1527 /* Update vmod -> indicator maps. */
1528 for (i = 0; i < XkbNumIndicators; i++) {
1529 struct xkb_mods *led = &keymap->indicators[i].mods;
1530 led->mask = led->real_mods | VModsToReal(keymap, led->vmods);