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("symbol interpretation", field, siText(si, info));
121 ReportSIBadType(CompatInfo *info, SymInterpInfo *si, const char *field,
124 return ReportBadType("symbol interpretation", field, siText(si, info),
129 ReportIndicatorBadType(CompatInfo *info, LEDInfo *led,
130 const char *field, const char *wanted)
132 return ReportBadType("indicator map", field,
133 xkb_atom_text(info->keymap->ctx, led->name), wanted);
137 ReportIndicatorNotArray(CompatInfo *info, LEDInfo *led,
140 return ReportNotArray("indicator map", field,
141 xkb_atom_text(info->keymap->ctx, led->name));
145 ClearIndicatorMapInfo(struct xkb_context *ctx, LEDInfo * info)
147 info->name = xkb_atom_intern(ctx, "default");
148 info->indicator = _LED_NotBound;
149 info->flags = info->which_mods = info->real_mods = 0;
151 info->which_groups = info->groups = 0;
156 InitCompatInfo(CompatInfo *info, struct xkb_keymap *keymap, unsigned file_id)
160 info->keymap = keymap;
162 info->file_id = file_id;
163 info->errorCount = 0;
165 list_init(&info->interps);
167 info->dflt.file_id = file_id;
168 info->dflt.defined = 0;
169 info->dflt.merge = MERGE_OVERRIDE;
170 info->dflt.interp.flags = 0;
171 info->dflt.interp.virtual_mod = XkbNoModifier;
172 info->dflt.interp.act.type = XkbSA_NoAction;
173 for (i = 0; i < sizeof(info->dflt.interp.act.any.data); i++)
174 info->dflt.interp.act.any.data[i] = 0;
175 ClearIndicatorMapInfo(keymap->ctx, &info->ledDflt);
176 info->ledDflt.file_id = file_id;
177 info->ledDflt.defined = 0;
178 info->ledDflt.merge = MERGE_OVERRIDE;
179 memset(&info->groupCompat[0], 0,
180 XkbNumKbdGroups * sizeof(GroupCompatInfo));
181 list_init(&info->leds);
182 InitVModInfo(&info->vmods, keymap);
186 ClearCompatInfo(CompatInfo *info)
189 ActionInfo *next_act;
190 SymInterpInfo *si, *next_si;
191 LEDInfo *led, *next_led;
192 struct xkb_keymap *keymap = info->keymap;
196 info->dflt.defined = 0;
197 info->dflt.merge = MERGE_AUGMENT;
198 info->dflt.interp.flags = 0;
199 info->dflt.interp.virtual_mod = XkbNoModifier;
200 info->dflt.interp.act.type = XkbSA_NoAction;
201 for (i = 0; i < sizeof(info->dflt.interp.act.any.data); i++)
202 info->dflt.interp.act.any.data[i] = 0;
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(unsigned field, SymInterpInfo *old, SymInterpInfo *new,
251 int verbosity, unsigned *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)
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_VirtualMod, old, new, verbosity,
293 old->interp.virtual_mod = new->interp.virtual_mod;
294 old->defined |= _SI_VirtualMod;
296 if (UseNewInterpField(_SI_Action, old, new, verbosity,
298 old->interp.act = new->interp.act;
299 old->defined |= _SI_Action;
301 if (UseNewInterpField(_SI_AutoRepeat, old, new, verbosity,
303 old->interp.flags &= ~XkbSI_AutoRepeat;
304 old->interp.flags |= (new->interp.flags & XkbSI_AutoRepeat);
305 old->defined |= _SI_AutoRepeat;
307 if (UseNewInterpField(_SI_LockingKey, old, new, verbosity,
309 old->interp.flags &= ~XkbSI_LockingKey;
310 old->interp.flags |= (new->interp.flags & XkbSI_LockingKey);
311 old->defined |= _SI_LockingKey;
313 if (UseNewInterpField(_SI_LevelOneOnly, old, new, verbosity,
315 old->interp.match &= ~XkbSI_LevelOneOnly;
316 old->interp.match |= (new->interp.match & XkbSI_LevelOneOnly);
317 old->defined |= _SI_LevelOneOnly;
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->real_mods == new->real_mods && gc->vmods == new->vmods)
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 unsigned *mods_rtrn, CompatInfo * info)
372 *pred_rtrn = XkbSI_AnyOfOrNone;
377 *pred_rtrn = XkbSI_Exactly;
378 if (expr->op == ExprActionDecl) {
379 const char *pred_txt = xkb_atom_text(info->keymap->ctx,
380 expr->value.action.name);
381 if (strcasecmp(pred_txt, "noneof") == 0)
382 *pred_rtrn = XkbSI_NoneOf;
383 else if (strcasecmp(pred_txt, "anyofornone") == 0)
384 *pred_rtrn = XkbSI_AnyOfOrNone;
385 else if (strcasecmp(pred_txt, "anyof") == 0)
386 *pred_rtrn = XkbSI_AnyOf;
387 else if (strcasecmp(pred_txt, "allof") == 0)
388 *pred_rtrn = XkbSI_AllOf;
389 else if (strcasecmp(pred_txt, "exactly") == 0)
390 *pred_rtrn = XkbSI_Exactly;
392 log_err(info->keymap->ctx,
393 "Illegal modifier predicate \"%s\"; Ignored\n", pred_txt);
396 expr = expr->value.action.args;
398 else if (expr->op == ExprIdent) {
399 const char *pred_txt = xkb_atom_text(info->keymap->ctx,
401 if ((pred_txt) && (strcasecmp(pred_txt, "any") == 0)) {
402 *pred_rtrn = XkbSI_AnyOf;
408 if (ExprResolveModMask(info->keymap->ctx, expr, &result)) {
409 *mods_rtrn = result.uval;
415 /***====================================================================***/
418 UseNewLEDField(unsigned field, LEDInfo *old, LEDInfo *new,
419 int verbosity, unsigned *collide)
421 if (!(old->defined & field))
424 if (new->defined & field) {
425 if ((old->file_id == new->file_id && verbosity > 0) || verbosity > 9)
428 if (new->merge != MERGE_AUGMENT)
436 AddIndicatorMap(CompatInfo *info, LEDInfo *new)
440 struct xkb_context *ctx = info->keymap->ctx;
441 int verbosity = xkb_get_log_verbosity(ctx);
443 list_foreach(old, &info->leds, entry) {
444 if (old->name == new->name) {
445 if ((old->real_mods == new->real_mods) &&
446 (old->vmods == new->vmods) &&
447 (old->groups == new->groups) &&
448 (old->ctrls == new->ctrls) &&
449 (old->which_mods == new->which_mods) &&
450 (old->which_groups == new->which_groups)) {
451 old->defined |= new->defined;
455 if (new->merge == MERGE_REPLACE) {
456 struct list entry = old->entry;
457 if ((old->file_id == new->file_id && verbosity > 0) ||
459 log_warn(info->keymap->ctx,
460 "Map for indicator %s redefined; "
461 "Earlier definition ignored\n",
462 xkb_atom_text(ctx, old->name));
469 if (UseNewLEDField(_LED_Index, old, new, verbosity,
471 old->indicator = new->indicator;
472 old->defined |= _LED_Index;
474 if (UseNewLEDField(_LED_Mods, old, new, verbosity,
476 old->which_mods = new->which_mods;
477 old->real_mods = new->real_mods;
478 old->vmods = new->vmods;
479 old->defined |= _LED_Mods;
481 if (UseNewLEDField(_LED_Groups, old, new, verbosity,
483 old->which_groups = new->which_groups;
484 old->groups = new->groups;
485 old->defined |= _LED_Groups;
487 if (UseNewLEDField(_LED_Ctrls, old, new, verbosity,
489 old->ctrls = new->ctrls;
490 old->defined |= _LED_Ctrls;
492 if (UseNewLEDField(_LED_Explicit, old, new, verbosity,
494 old->flags &= ~XkbIM_NoExplicit;
495 old->flags |= (new->flags & XkbIM_NoExplicit);
496 old->defined |= _LED_Explicit;
498 if (UseNewLEDField(_LED_Automatic, old, new, verbosity,
500 old->flags &= ~XkbIM_NoAutomatic;
501 old->flags |= (new->flags & XkbIM_NoAutomatic);
502 old->defined |= _LED_Automatic;
504 if (UseNewLEDField(_LED_DrivesKbd, old, new, verbosity,
506 old->flags &= ~XkbIM_LEDDrivesKB;
507 old->flags |= (new->flags & XkbIM_LEDDrivesKB);
508 old->defined |= _LED_DrivesKbd;
512 log_warn(info->keymap->ctx,
513 "Map for indicator %s redefined; "
514 "Using %s definition for duplicate fields\n",
515 xkb_atom_text(ctx, old->name),
516 (new->merge == MERGE_AUGMENT ? "first" : "last"));
524 old = malloc(sizeof(*old));
526 log_wsgo(info->keymap->ctx,
527 "Couldn't allocate indicator map; "
528 "Map for indicator %s not compiled\n",
529 xkb_atom_text(ctx, new->name));
534 list_append(&old->entry, &info->leds);
540 MergeIncludedCompatMaps(CompatInfo * into, CompatInfo * from,
541 enum merge_mode merge)
544 LEDInfo *led, *next_led;
545 GroupCompatInfo *gcm;
548 if (from->errorCount > 0) {
549 into->errorCount += from->errorCount;
552 if (into->name == NULL) {
553 into->name = from->name;
557 list_foreach(si, &from->interps, entry) {
558 if (merge != MERGE_DEFAULT)
560 if (!AddInterp(into, si))
564 for (i = 0, gcm = &from->groupCompat[0]; i < XkbNumKbdGroups;
566 if (merge != MERGE_DEFAULT)
568 if (!AddGroupCompat(into, i, gcm))
572 list_foreach_safe(led, next_led, &from->leds, entry) {
573 led->merge = (merge == MERGE_DEFAULT ? led->merge : merge);
574 if (!AddIndicatorMap(into, led))
580 HandleCompatMapFile(CompatInfo *info, XkbFile *file, enum merge_mode merge);
583 HandleIncludeCompatMap(CompatInfo *info, IncludeStmt *stmt)
585 enum merge_mode merge = MERGE_DEFAULT;
587 CompatInfo included, next_incl;
589 InitCompatInfo(&included, info->keymap, info->file_id);
592 included.name = stmt->stmt;
596 for (; stmt; stmt = stmt->next) {
597 if (!ProcessIncludeFile(info->keymap->ctx, stmt, FILE_TYPE_COMPAT,
599 info->errorCount += 10;
600 ClearCompatInfo(&included);
604 InitCompatInfo(&next_incl, info->keymap, rtrn->id);
605 next_incl.file_id = rtrn->id;
606 next_incl.dflt = info->dflt;
607 next_incl.dflt.file_id = rtrn->id;
608 next_incl.dflt.merge = merge;
609 next_incl.ledDflt.file_id = rtrn->id;
610 next_incl.ledDflt.merge = merge;
611 next_incl.act = info->act;
613 HandleCompatMapFile(&next_incl, rtrn, MERGE_OVERRIDE);
615 MergeIncludedCompatMaps(&included, &next_incl, merge);
617 next_incl.act = NULL;
619 ClearCompatInfo(&next_incl);
623 MergeIncludedCompatMaps(info, &included, merge);
624 ClearCompatInfo(&included);
626 return (info->errorCount == 0);
629 static const LookupEntry useModMapValues[] = {
638 SetInterpField(CompatInfo *info, SymInterpInfo *si, char *field,
639 ExprDef *arrayNdx, ExprDef *value)
643 struct xkb_keymap *keymap = info->keymap;
645 if (strcasecmp(field, "action") == 0) {
646 if (arrayNdx != NULL)
647 return ReportSINotArray(info, si, field);
648 ok = HandleActionDef(value, keymap, &si->interp.act.any,
651 si->defined |= _SI_Action;
653 else if ((strcasecmp(field, "virtualmodifier") == 0) ||
654 (strcasecmp(field, "virtualmod") == 0)) {
655 if (arrayNdx != NULL)
656 return ReportSINotArray(info, si, field);
657 ok = ResolveVirtualModifier(value, keymap, &tmp, &info->vmods);
659 si->interp.virtual_mod = tmp.uval;
660 si->defined |= _SI_VirtualMod;
663 return ReportSIBadType(info, si, field, "virtual modifier");
665 else if (strcasecmp(field, "repeat") == 0) {
666 if (arrayNdx != NULL)
667 return ReportSINotArray(info, si, field);
668 ok = ExprResolveBoolean(keymap->ctx, value, &tmp);
671 si->interp.flags |= XkbSI_AutoRepeat;
673 si->interp.flags &= ~XkbSI_AutoRepeat;
674 si->defined |= _SI_AutoRepeat;
677 return ReportSIBadType(info, si, field, "boolean");
679 else if (strcasecmp(field, "locking") == 0) {
680 if (arrayNdx != NULL)
681 return ReportSINotArray(info, si, field);
682 ok = ExprResolveBoolean(keymap->ctx, value, &tmp);
685 si->interp.flags |= XkbSI_LockingKey;
687 si->interp.flags &= ~XkbSI_LockingKey;
688 si->defined |= _SI_LockingKey;
691 return ReportSIBadType(info, si, field, "boolean");
693 else if ((strcasecmp(field, "usemodmap") == 0) ||
694 (strcasecmp(field, "usemodmapmods") == 0)) {
695 if (arrayNdx != NULL)
696 return ReportSINotArray(info, si, field);
697 ok = ExprResolveEnum(keymap->ctx, value, &tmp, useModMapValues);
700 si->interp.match |= XkbSI_LevelOneOnly;
702 si->interp.match &= ~XkbSI_LevelOneOnly;
703 si->defined |= _SI_LevelOneOnly;
706 return ReportSIBadType(info, si, field, "level specification");
709 ok = ReportBadField("symbol interpretation", field, siText(si, info));
714 static const LookupEntry modComponentNames[] = {
715 {"base", XkbIM_UseBase},
716 {"latched", XkbIM_UseLatched},
717 {"locked", XkbIM_UseLocked},
718 {"effective", XkbIM_UseEffective},
719 {"compat", XkbIM_UseCompat},
720 {"any", XkbIM_UseAnyMods},
724 static const LookupEntry groupComponentNames[] = {
725 {"base", XkbIM_UseBase},
726 {"latched", XkbIM_UseLatched},
727 {"locked", XkbIM_UseLocked},
728 {"effective", XkbIM_UseEffective},
729 {"any", XkbIM_UseAnyGroup},
734 static const LookupEntry groupNames[] = {
749 SetIndicatorMapField(CompatInfo *info, LEDInfo *led,
750 char *field, ExprDef *arrayNdx, ExprDef *value)
754 struct xkb_keymap *keymap = info->keymap;
756 if (strcasecmp(field, "modifiers") == 0 || strcasecmp(field, "mods") == 0) {
757 if (arrayNdx != NULL)
758 return ReportIndicatorNotArray(info, led, field);
760 if (!ExprResolveVModMask(keymap, value, &rtrn))
761 return ReportIndicatorBadType(info, led, field, "modifier mask");
763 led->real_mods = rtrn.uval & 0xff;
764 led->vmods = (rtrn.uval >> 8) & 0xff;
765 led->defined |= _LED_Mods;
767 else if (strcasecmp(field, "groups") == 0) {
768 if (arrayNdx != NULL)
769 return ReportIndicatorNotArray(info, led, field);
771 if (!ExprResolveMask(keymap->ctx, value, &rtrn, groupNames))
772 return ReportIndicatorBadType(info, led, field, "group mask");
774 led->groups = rtrn.uval;
775 led->defined |= _LED_Groups;
777 else if (strcasecmp(field, "controls") == 0 ||
778 strcasecmp(field, "ctrls") == 0) {
779 if (arrayNdx != NULL)
780 return ReportIndicatorNotArray(info, led, field);
782 if (!ExprResolveMask(keymap->ctx, value, &rtrn, ctrlNames))
783 return ReportIndicatorBadType(info, led, field,
786 led->ctrls = rtrn.uval;
787 led->defined |= _LED_Ctrls;
789 else if (strcasecmp(field, "allowexplicit") == 0) {
790 if (arrayNdx != NULL)
791 return ReportIndicatorNotArray(info, led, field);
793 if (!ExprResolveBoolean(keymap->ctx, value, &rtrn))
794 return ReportIndicatorBadType(info, led, field, "boolean");
797 led->flags &= ~XkbIM_NoExplicit;
799 led->flags |= XkbIM_NoExplicit;
800 led->defined |= _LED_Explicit;
802 else if (strcasecmp(field, "whichmodstate") == 0 ||
803 strcasecmp(field, "whichmodifierstate") == 0) {
804 if (arrayNdx != NULL)
805 return ReportIndicatorNotArray(info, led, field);
807 if (!ExprResolveMask(keymap->ctx, value, &rtrn, modComponentNames))
808 return ReportIndicatorBadType(info, led, field,
809 "mask of modifier state components");
811 led->which_mods = rtrn.uval;
813 else if (strcasecmp(field, "whichgroupstate") == 0) {
814 if (arrayNdx != NULL)
815 return ReportIndicatorNotArray(info, led, field);
817 if (!ExprResolveMask(keymap->ctx, value, &rtrn, groupComponentNames))
818 return ReportIndicatorBadType(info, led, field,
819 "mask of group state components");
821 led->which_groups = rtrn.uval;
823 else if (strcasecmp(field, "driveskbd") == 0 ||
824 strcasecmp(field, "driveskeyboard") == 0 ||
825 strcasecmp(field, "leddriveskbd") == 0 ||
826 strcasecmp(field, "leddriveskeyboard") == 0 ||
827 strcasecmp(field, "indicatordriveskbd") == 0 ||
828 strcasecmp(field, "indicatordriveskeyboard") == 0) {
829 if (arrayNdx != NULL)
830 return ReportIndicatorNotArray(info, led, field);
832 if (!ExprResolveBoolean(keymap->ctx, value, &rtrn))
833 return ReportIndicatorBadType(info, led, field, "boolean");
836 led->flags |= XkbIM_LEDDrivesKB;
838 led->flags &= ~XkbIM_LEDDrivesKB;
839 led->defined |= _LED_DrivesKbd;
841 else if (strcasecmp(field, "index") == 0) {
842 if (arrayNdx != NULL)
843 return ReportIndicatorNotArray(info, led, field);
845 if (!ExprResolveInteger(keymap->ctx, value, &rtrn))
846 return ReportIndicatorBadType(info, led, field,
849 if (rtrn.uval < 1 || rtrn.uval > 32) {
850 log_err(info->keymap->ctx,
851 "Illegal indicator index %d (range 1..%d); "
852 "Index definition for %s indicator ignored\n",
853 rtrn.uval, XkbNumIndicators,
854 xkb_atom_text(keymap->ctx, led->name));
858 led->indicator = rtrn.uval;
859 led->defined |= _LED_Index;
862 log_err(info->keymap->ctx,
863 "Unknown field %s in map for %s indicator; "
864 "Definition ignored\n",
865 field, xkb_atom_text(keymap->ctx, led->name));
873 HandleInterpVar(CompatInfo *info, VarDef *stmt)
875 ExprResult elem, field;
879 if (ExprResolveLhs(info->keymap, stmt->name, &elem, &field, &ndx) == 0)
880 ret = 0; /* internal error, already reported */
881 else if (elem.str && (strcasecmp(elem.str, "interpret") == 0))
882 ret = SetInterpField(info, &info->dflt, field.str, ndx, stmt->value);
883 else if (elem.str && (strcasecmp(elem.str, "indicator") == 0))
884 ret = SetIndicatorMapField(info, &info->ledDflt, field.str, ndx,
887 ret = SetActionField(info->keymap, elem.str, field.str, ndx,
888 stmt->value, &info->act);
895 HandleInterpBody(CompatInfo *info, VarDef *def, SymInterpInfo *si)
898 ExprResult tmp, field;
901 for (; def != NULL; def = (VarDef *) def->common.next) {
902 if ((def->name) && (def->name->type == ExprFieldRef)) {
903 ok = HandleInterpVar(info, def);
906 ok = ExprResolveLhs(info->keymap, def->name, &tmp, &field, &arrayNdx);
908 ok = SetInterpField(info, si, field.str, arrayNdx, def->value);
916 HandleInterpDef(CompatInfo *info, InterpDef *def, enum merge_mode merge)
921 if (!ResolveStateAndPredicate(def->match, &pred, &mods, info)) {
922 log_err(info->keymap->ctx,
923 "Couldn't determine matching modifiers; "
924 "Symbol interpretation ignored\n");
927 if (def->merge != MERGE_DEFAULT)
932 if (!LookupKeysym(def->sym, &si.interp.sym)) {
933 log_err(info->keymap->ctx,
934 "Could not resolve keysym %s; "
935 "Symbol interpretation ignored\n",
939 si.interp.match = pred & XkbSI_OpMask;
940 si.interp.mods = mods;
941 if (!HandleInterpBody(info, def->def, &si)) {
946 if (!AddInterp(info, &si)) {
954 HandleGroupCompatDef(CompatInfo *info, GroupCompatDef *def,
955 enum merge_mode merge)
960 if (def->merge != MERGE_DEFAULT)
962 if (def->group < 1 || def->group > XkbNumKbdGroups) {
963 log_err(info->keymap->ctx,
964 "Keyboard group must be in the range 1..%u; "
965 "Compatibility map for illegal group %u ignored\n",
966 XkbNumKbdGroups, def->group);
969 tmp.file_id = info->file_id;
971 if (!ExprResolveVModMask(info->keymap, def->def, &val)) {
972 log_err(info->keymap->ctx,
973 "Expected a modifier mask in group compatibility definition; "
974 "Ignoring illegal compatibility map for group %u\n",
978 tmp.real_mods = val.uval & 0xff;
979 tmp.vmods = (val.uval >> 8) & 0xffff;
981 return AddGroupCompat(info, def->group - 1, &tmp);
985 HandleIndicatorMapDef(CompatInfo *info, IndicatorMapDef *def,
986 enum merge_mode merge)
992 if (def->merge != MERGE_DEFAULT)
997 led.name = def->name;
1000 for (var = def->body; var != NULL; var = (VarDef *) var->common.next) {
1001 ExprResult elem, field;
1003 if (!ExprResolveLhs(info->keymap, var->name, &elem, &field,
1009 if (elem.str != NULL) {
1010 log_err(info->keymap->ctx,
1011 "Cannot set defaults for \"%s\" element in indicator map; "
1012 "Assignment to %s.%s ignored\n",
1013 elem.str, elem.str, field.str);
1017 ok = SetIndicatorMapField(info, &led, field.str, arrayNdx,
1025 return AddIndicatorMap(info, &led);
1031 HandleCompatMapFile(CompatInfo *info, XkbFile *file, enum merge_mode merge)
1035 if (merge == MERGE_DEFAULT)
1036 merge = MERGE_AUGMENT;
1038 info->name = uDupString(file->name);
1042 switch (stmt->stmtType) {
1044 if (!HandleIncludeCompatMap(info, (IncludeStmt *) stmt))
1048 if (!HandleInterpDef(info, (InterpDef *) stmt, merge))
1051 case StmtGroupCompatDef:
1052 if (!HandleGroupCompatDef(info, (GroupCompatDef *) stmt, merge))
1055 case StmtIndicatorMapDef:
1056 if (!HandleIndicatorMapDef(info, (IndicatorMapDef *) stmt, merge))
1060 if (!HandleInterpVar(info, (VarDef *) stmt))
1064 if (!HandleVModDef((VModDef *) stmt, info->keymap, merge,
1068 case StmtKeycodeDef:
1069 log_err(info->keymap->ctx,
1070 "Interpretation files may not include other types; "
1071 "Ignoring definition of key name\n");
1075 log_wsgo(info->keymap->ctx,
1076 "Unexpected statement type %d in HandleCompatMapFile\n",
1081 if (info->errorCount > 10) {
1082 log_err(info->keymap->ctx,
1083 "Abandoning compatibility map \"%s\"\n", file->topName);
1090 CopyInterps(CompatInfo *info, bool needSymbol, unsigned pred)
1094 list_foreach(si, &info->interps, entry) {
1095 if (((si->interp.match & XkbSI_OpMask) != pred) ||
1096 (needSymbol && si->interp.sym == XKB_KEY_NoSymbol) ||
1097 (!needSymbol && si->interp.sym != XKB_KEY_NoSymbol))
1100 darray_append(info->keymap->sym_interpret, si->interp);
1105 BindIndicators(CompatInfo *info, struct list *unbound_leds)
1108 LEDInfo *led, *next_led;
1109 struct xkb_indicator_map *map;
1110 struct xkb_keymap *keymap = info->keymap;
1112 list_foreach(led, unbound_leds, entry) {
1113 if (led->indicator == _LED_NotBound) {
1114 for (i = 0; i < XkbNumIndicators; i++) {
1115 if (keymap->indicator_names[i] &&
1116 strcmp(keymap->indicator_names[i],
1117 xkb_atom_text(keymap->ctx, led->name)) == 0) {
1118 led->indicator = i + 1;
1125 list_foreach(led, unbound_leds, entry) {
1126 if (led->indicator == _LED_NotBound) {
1127 for (i = 0; i < XkbNumIndicators; i++) {
1128 if (keymap->indicator_names[i] == NULL) {
1129 keymap->indicator_names[i] =
1130 xkb_atom_strdup(keymap->ctx, led->name);
1131 led->indicator = i + 1;
1136 if (led->indicator == _LED_NotBound) {
1137 log_err(info->keymap->ctx,
1138 "No unnamed indicators found; "
1139 "Virtual indicator map \"%s\" not bound\n",
1140 xkb_atom_text(keymap->ctx, led->name));
1146 list_foreach_safe(led, next_led, unbound_leds, entry) {
1147 if (led->indicator == _LED_NotBound) {
1152 if (strcmp(keymap->indicator_names[led->indicator - 1],
1153 xkb_atom_text(keymap->ctx, led->name)) != 0) {
1154 const char *old = keymap->indicator_names[led->indicator - 1];
1155 log_err(info->keymap->ctx,
1156 "Multiple names bound to indicator %d; "
1157 "Using %s, ignoring %s\n",
1158 led->indicator, old,
1159 xkb_atom_text(keymap->ctx, led->name));
1164 map = &keymap->indicators[led->indicator - 1];
1165 map->flags = led->flags;
1166 map->which_groups = led->which_groups;
1167 map->groups = led->groups;
1168 map->which_mods = led->which_mods;
1169 map->mods.mask = led->real_mods;
1170 map->mods.real_mods = led->real_mods;
1171 map->mods.vmods = led->vmods;
1172 map->ctrls = led->ctrls;
1176 list_init(unbound_leds);
1180 CopyIndicatorMapDefs(CompatInfo *info)
1182 LEDInfo *led, *next_led;
1183 struct list unbound_leds;
1184 struct xkb_indicator_map *im;
1185 struct xkb_keymap *keymap = info->keymap;
1187 list_init(&unbound_leds);
1189 list_foreach_safe(led, next_led, &info->leds, entry) {
1190 if (led->groups != 0 && led->which_groups == 0)
1191 led->which_groups = XkbIM_UseEffective;
1193 if (led->which_mods == 0 && (led->real_mods || led->vmods))
1194 led->which_mods = XkbIM_UseEffective;
1196 if (led->indicator == _LED_NotBound) {
1197 list_append(&led->entry, &unbound_leds);
1201 im = &keymap->indicators[led->indicator - 1];
1202 im->flags = led->flags;
1203 im->which_groups = led->which_groups;
1204 im->groups = led->groups;
1205 im->which_mods = led->which_mods;
1206 im->mods.mask = led->real_mods;
1207 im->mods.real_mods = led->real_mods;
1208 im->mods.vmods = led->vmods;
1209 im->ctrls = led->ctrls;
1210 free(keymap->indicator_names[led->indicator - 1]);
1211 keymap->indicator_names[led->indicator - 1] =
1212 xkb_atom_strdup(keymap->ctx, led->name);
1215 list_init(&info->leds);
1217 BindIndicators(info, &unbound_leds);
1223 CompileCompatMap(XkbFile *file, struct xkb_keymap *keymap,
1224 enum merge_mode merge)
1226 xkb_group_index_t i;
1228 GroupCompatInfo *gcm;
1230 InitCompatInfo(&info, keymap, file->id);
1231 info.dflt.merge = merge;
1232 info.ledDflt.merge = merge;
1234 HandleCompatMapFile(&info, file, merge);
1236 if (info.errorCount != 0)
1239 darray_init(keymap->sym_interpret);
1240 darray_growalloc(keymap->sym_interpret, info.nInterps);
1243 keymap->compat_section_name = strdup(info.name);
1245 if (info.nInterps > 0) {
1246 CopyInterps(&info, true, XkbSI_Exactly);
1247 CopyInterps(&info, true, XkbSI_AllOf | XkbSI_NoneOf);
1248 CopyInterps(&info, true, XkbSI_AnyOf);
1249 CopyInterps(&info, true, XkbSI_AnyOfOrNone);
1250 CopyInterps(&info, false, XkbSI_Exactly);
1251 CopyInterps(&info, false, XkbSI_AllOf | XkbSI_NoneOf);
1252 CopyInterps(&info, false, XkbSI_AnyOf);
1253 CopyInterps(&info, false, XkbSI_AnyOfOrNone);
1256 for (i = 0, gcm = &info.groupCompat[0]; i < XkbNumKbdGroups;
1258 if (gcm->file_id != 0 || gcm->real_mods != 0 || gcm->vmods != 0) {
1259 keymap->groups[i].mask = gcm->real_mods;
1260 keymap->groups[i].real_mods = gcm->real_mods;
1261 keymap->groups[i].vmods = gcm->vmods;
1265 if (!CopyIndicatorMapDefs(&info))
1268 ClearCompatInfo(&info);
1272 ClearCompatInfo(&info);
1277 VModsToReal(struct xkb_keymap *keymap, uint32_t vmodmask)
1285 for (i = 0; i < XkbNumVirtualMods; i++) {
1286 if (!(vmodmask & (1 << i)))
1288 ret |= keymap->vmods[i];
1295 UpdateActionMods(struct xkb_keymap *keymap, union xkb_action *act,
1298 switch (act->type) {
1300 case XkbSA_LatchMods:
1301 case XkbSA_LockMods:
1302 if (act->mods.flags & XkbSA_UseModMapMods)
1303 act->mods.real_mods = rmodmask;
1304 act->mods.mask = act->mods.real_mods;
1305 act->mods.mask |= VModsToReal(keymap, act->mods.vmods);
1309 if (act->iso.flags & XkbSA_UseModMapMods)
1310 act->iso.real_mods = rmodmask;
1311 act->iso.mask = act->iso.real_mods;
1312 act->iso.mask |= VModsToReal(keymap, act->iso.vmods);
1321 * Find an interpretation which applies to this particular level, either by
1322 * finding an exact match for the symbol and modifier combination, or a
1323 * generic XKB_KEY_NoSymbol match.
1325 static struct xkb_sym_interpret *
1326 FindInterpForKey(struct xkb_keymap *keymap, struct xkb_key *key,
1327 xkb_group_index_t group, uint32_t level)
1329 struct xkb_sym_interpret *ret = NULL;
1330 struct xkb_sym_interpret *interp;
1331 const xkb_keysym_t *syms;
1334 num_syms = xkb_key_get_syms_by_level(keymap, key, group, level, &syms);
1338 darray_foreach(interp, keymap->sym_interpret) {
1342 if ((num_syms > 1 || interp->sym != syms[0]) &&
1343 interp->sym != XKB_KEY_NoSymbol)
1346 if (level == 0 || !(interp->match & XkbSI_LevelOneOnly))
1351 switch (interp->match & XkbSI_OpMask) {
1353 found = !(interp->mods & mods);
1355 case XkbSI_AnyOfOrNone:
1356 found = (!mods || (interp->mods & mods));
1359 found = !!(interp->mods & mods);
1362 found = ((interp->mods & mods) == interp->mods);
1365 found = (interp->mods == mods);
1372 if (found && interp->sym != XKB_KEY_NoSymbol)
1374 else if (found && !ret)
1384 ApplyInterpsToKey(struct xkb_keymap *keymap, struct xkb_key *key)
1386 #define INTERP_SIZE (8 * 4)
1387 struct xkb_sym_interpret *interps[INTERP_SIZE];
1388 union xkb_action *acts;
1389 uint32_t vmodmask = 0;
1391 xkb_group_index_t group;
1395 /* If we've been told not to bind interps to this key, then don't. */
1396 if (key->explicit & XkbExplicitInterpretMask)
1399 for (i = 0; i < INTERP_SIZE; i++)
1402 for (group = 0; group < key->num_groups; group++) {
1403 for (level = 0; level < XkbKeyGroupWidth(keymap, key, group);
1405 i = (group * key->width) + level;
1406 if (i >= INTERP_SIZE) /* XXX FIXME */
1408 interps[i] = FindInterpForKey(keymap, key, group, level);
1415 num_acts = key->num_groups * key->width;
1416 acts = XkbcResizeKeyActions(keymap, key, num_acts);
1417 if (num_acts && !acts)
1420 for (group = 0; group < key->num_groups; group++) {
1421 for (level = 0; level < XkbKeyGroupWidth(keymap, key, group);
1423 struct xkb_sym_interpret *interp;
1425 i = (group * key->width) + level;
1426 interp = interps[i];
1428 /* Infer default key behaviours from the base level. */
1429 if (group == 0 && level == 0) {
1430 if (!(key->explicit & XkbExplicitAutoRepeatMask) &&
1431 (!interp || (interp->flags & XkbSI_AutoRepeat)))
1432 key->repeats = true;
1433 if (!(key->explicit & XkbExplicitBehaviorMask) &&
1434 interp && (interp->flags & XkbSI_LockingKey))
1435 key->behavior.type = XkbKB_Lock;
1441 if ((group == 0 && level == 0) ||
1442 !(interp->match & XkbSI_LevelOneOnly)) {
1443 if (interp->virtual_mod != XkbNoModifier)
1444 vmodmask |= (1 << interp->virtual_mod);
1446 acts[i] = interp->act;
1450 if (!(key->explicit & XkbExplicitVModMapMask))
1451 key->vmodmap = vmodmask;
1458 * This collects a bunch of disparate functions which was done in the server
1459 * at various points that really should've been done within xkbcomp. Turns out
1460 * your actions and types are a lot more useful when any of your modifiers
1461 * other than Shift actually do something ...
1464 UpdateModifiersFromCompat(struct xkb_keymap *keymap)
1466 struct xkb_key *key;
1468 struct xkb_key_type *type;
1469 struct xkb_kt_map_entry *entry;
1471 /* Find all the interprets for the key and bind them to actions,
1472 * which will also update the vmodmap. */
1473 xkb_foreach_key(key, keymap)
1474 if (!ApplyInterpsToKey(keymap, key))
1477 /* Update keymap->vmods, the virtual -> real mod mapping. */
1478 for (i = 0; i < XkbNumVirtualMods; i++)
1479 keymap->vmods[i] = 0;
1480 xkb_foreach_key(key, keymap) {
1484 for (i = 0; i < XkbNumVirtualMods; i++) {
1485 if (!(key->vmodmap & (1 << i)))
1487 keymap->vmods[i] |= key->modmap;
1491 /* Now update the level masks for all the types to reflect the vmods. */
1492 darray_foreach(type, keymap->types) {
1495 type->mods.mask = type->mods.real_mods;
1496 type->mods.mask |= VModsToReal(keymap, type->mods.vmods);
1497 for (j = 0; j < XkbNumVirtualMods; j++) {
1498 if (!(type->mods.vmods & (1 << j)))
1500 mask |= keymap->vmods[j];
1503 darray_foreach(entry, type->map)
1504 entry->mods.mask = entry->mods.real_mods |
1505 VModsToReal(keymap, entry->mods.vmods);
1508 /* Update action modifiers. */
1509 xkb_foreach_key(key, keymap) {
1510 union xkb_action *acts = XkbKeyActionsPtr(keymap, key);
1511 for (i = 0; i < XkbKeyNumActions(key); i++) {
1512 if (acts[i].any.type == XkbSA_NoAction)
1514 UpdateActionMods(keymap, &acts[i], key->modmap);
1518 /* Update group modifiers. */
1519 for (i = 0; i < XkbNumKbdGroups; i++) {
1520 struct xkb_mods *group = &keymap->groups[i];
1521 group->mask = group->real_mods | VModsToReal(keymap, group->vmods);
1524 /* Update vmod -> indicator maps. */
1525 for (i = 0; i < XkbNumIndicators; i++) {
1526 struct xkb_mods *led = &keymap->indicators[i].mods;
1527 led->mask = led->real_mods | VModsToReal(keymap, led->vmods);