*
********************************************************/
+/*
+ * Copyright © 2012 Ran Benita <ran234@gmail.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#include "config.h"
+
#include "xkbcomp-priv.h"
#include "text.h"
#include "expr.h"
#include "vmod.h"
#include "include.h"
-/*
- * The xkb_compat section
- * =====================
- * This section is the third to be processesed, after xkb_keycodes and
- * xkb_types.
- *
- * Interpret statements
- * --------------------
- * Statements of the form:
- * interpret Num_Lock+Any { ... }
- *
- * The body of the statment may include statements of the following
- * forms:
- *
- * - action statement:
- * action = LockMods(modifiers=NumLock);
- *
- * - virtual modifier statement:
- * virtualModifier = NumLock;
- *
- * - repeat statement:
- * repeat = True;
- *
- * - useModMapMods statement:
- * useModMapMods = level1;
- *
- * Indicator map statements
- * ------------------------
- * Statements of the form:
- * indicator "Shift Lock" { ... }
- *
- * This statement specifies the behavior and binding of the indicator
- * with the given name ("Shift Lock" above). The name should have been
- * declared previously in the xkb_keycodes section (see Indicator name
- * statement), and given an index there. If it wasn't, it is created
- * with the next free index.
- * The body of the statement describes the conditions of the keyboard
- * state which will cause the indicator to be lit. It may include the
- * following statements:
- *
- * - modifiers statment:
- * modifiers = ScrollLock;
- *
- * If the given modifiers are in the required state (see below), the
- * led is lit.
- *
- * - whichModifierState statment:
- * whichModState = Latched + Locked;
- *
- * Can be any combination of:
- * base, latched, locked, effective
- * any (i.e. all of the above)
- * none (i.e. none of the above)
- * compat (this is legal, but unused)
- * This will cause the respective portion of the modifer state (see
- * struct xkb_state) to be matched against the modifiers given in the
- * "modifiers" statement.
- *
- * Here's a simple example:
- * indicator "Num Lock" {
- * modifiers = NumLock;
- * whichModState = Locked;
- * };
- * Whenever the NumLock modifier is locked, the Num Lock indicator
- * will light up.
- *
- * - groups statment:
- * groups = All - group1;
- *
- * If the given groups are in the required state (see below), the led
- * is lit.
- *
- * - whichGroupState statment:
- * whichGroupState = Effective;
- *
- * Can be any combination of:
- * base, latched, locked, effective
- * any (i.e. all of the above)
- * none (i.e. none of the above)
- * This will cause the respective portion of the group state (see
- * struct xkb_state) to be matched against the groups given in the
- * "groups" statement.
- *
- * Note: the above conditions are disjunctive, i.e. if any of them are
- * satisfied the led is lit.
- *
- * Virtual modifier statements
- * ---------------------------
- * Statements of the form:
- * virtual_modifiers LControl;
- *
- * Can appear in the xkb_types, xkb_compat, xkb_symbols sections.
- * TODO
- *
- * Effect on keymap
- * ----------------
- * After all of the xkb_compat sections have been compiled, the following
- * members of struct xkb_keymap are finalized:
- * darray(struct xkb_sym_interpret) sym_interpret;
- * struct xkb_indicator_map indicators[XkbNumIndicators];
- * char *compat_section_name;
- * TODO: virtual modifiers.
- */
-
enum si_field {
- SI_FIELD_VIRTUAL_MOD = (1 << 0),
- SI_FIELD_ACTION = (1 << 1),
- SI_FIELD_AUTO_REPEAT = (1 << 2),
+ SI_FIELD_VIRTUAL_MOD = (1 << 0),
+ SI_FIELD_ACTION = (1 << 1),
+ SI_FIELD_AUTO_REPEAT = (1 << 2),
SI_FIELD_LEVEL_ONE_ONLY = (1 << 3),
};
-typedef struct _SymInterpInfo {
+typedef struct {
enum si_field defined;
- unsigned file_id;
enum merge_mode merge;
struct xkb_sym_interpret interp;
} SymInterpInfo;
enum led_field {
- LED_FIELD_MODS = (1 << 0),
- LED_FIELD_GROUPS = (1 << 1),
- LED_FIELD_CTRLS = (1 << 2),
+ LED_FIELD_MODS = (1 << 0),
+ LED_FIELD_GROUPS = (1 << 1),
+ LED_FIELD_CTRLS = (1 << 2),
};
-typedef struct _LEDInfo {
+typedef struct {
enum led_field defined;
- unsigned file_id;
enum merge_mode merge;
- xkb_atom_t name;
- unsigned char which_mods;
- xkb_mod_mask_t mods;
- unsigned char which_groups;
- uint32_t groups;
- unsigned int ctrls;
-} LEDInfo;
+ struct xkb_led led;
+} LedInfo;
-typedef struct _CompatInfo {
+typedef struct {
char *name;
- unsigned file_id;
int errorCount;
- SymInterpInfo dflt;
+ SymInterpInfo default_interp;
darray(SymInterpInfo) interps;
- LEDInfo ledDflt;
- darray(LEDInfo) leds;
- VModInfo vmods;
+ LedInfo default_led;
+ LedInfo leds[XKB_MAX_LEDS];
+ unsigned int num_leds;
ActionsInfo *actions;
- struct xkb_keymap *keymap;
+ struct xkb_mod_set mods;
+
+ struct xkb_context *ctx;
} CompatInfo;
static const char *
siText(SymInterpInfo *si, CompatInfo *info)
{
- static char buf[128];
+ char *buf = xkb_context_get_buffer(info->ctx, 128);
- if (si == &info->dflt)
+ if (si == &info->default_interp)
return "default";
- snprintf(buf, sizeof(buf), "%s+%s(%s)",
- KeysymText(si->interp.sym),
+ snprintf(buf, 128, "%s+%s(%s)",
+ KeysymText(info->ctx, si->interp.sym),
SIMatchText(si->interp.match),
- ModMaskText(si->interp.mods));
+ ModMaskText(info->ctx, &info->mods, si->interp.mods));
+
return buf;
}
static inline bool
ReportSINotArray(CompatInfo *info, SymInterpInfo *si, const char *field)
{
- return ReportNotArray(info->keymap, "symbol interpretation", field,
+ return ReportNotArray(info->ctx, "symbol interpretation", field,
siText(si, info));
}
ReportSIBadType(CompatInfo *info, SymInterpInfo *si, const char *field,
const char *wanted)
{
- return ReportBadType(info->keymap->ctx, "symbol interpretation", field,
+ return ReportBadType(info->ctx, XKB_ERROR_WRONG_FIELD_TYPE,
+ "symbol interpretation", field,
siText(si, info), wanted);
}
static inline bool
-ReportIndicatorBadType(CompatInfo *info, LEDInfo *led,
- const char *field, const char *wanted)
+ReportLedBadType(CompatInfo *info, LedInfo *ledi, const char *field,
+ const char *wanted)
{
- return ReportBadType(info->keymap->ctx, "indicator map", field,
- xkb_atom_text(info->keymap->ctx, led->name),
+ return ReportBadType(info->ctx, XKB_ERROR_WRONG_FIELD_TYPE,
+ "indicator map", field,
+ xkb_atom_text(info->ctx, ledi->led.name),
wanted);
}
static inline bool
-ReportIndicatorNotArray(CompatInfo *info, LEDInfo *led,
- const char *field)
+ReportLedNotArray(CompatInfo *info, LedInfo *ledi, const char *field)
{
- return ReportNotArray(info->keymap, "indicator map", field,
- xkb_atom_text(info->keymap->ctx, led->name));
+ return ReportNotArray(info->ctx, "indicator map", field,
+ xkb_atom_text(info->ctx, ledi->led.name));
}
static void
-ClearIndicatorMapInfo(struct xkb_context *ctx, LEDInfo *info)
+InitCompatInfo(CompatInfo *info, struct xkb_context *ctx,
+ ActionsInfo *actions, const struct xkb_mod_set *mods)
{
- info->name = xkb_atom_intern(ctx, "default");
- info->which_mods = 0;
- info->mods = 0;
- info->which_groups = info->groups = 0;
- info->ctrls = 0;
-}
-
-static void
-InitCompatInfo(CompatInfo *info, struct xkb_keymap *keymap, unsigned file_id,
- ActionsInfo *actions)
-{
- info->keymap = keymap;
- info->name = NULL;
- info->file_id = file_id;
- info->errorCount = 0;
- darray_init(info->interps);
+ memset(info, 0, sizeof(*info));
+ info->ctx = ctx;
info->actions = actions;
- info->dflt.file_id = file_id;
- info->dflt.defined = 0;
- info->dflt.merge = MERGE_OVERRIDE;
- info->dflt.interp.flags = 0;
- info->dflt.interp.virtual_mod = XKB_MOD_INVALID;
- memset(&info->dflt.interp.act, 0, sizeof(info->dflt.interp.act));
- info->dflt.interp.act.type = XkbSA_NoAction;
- ClearIndicatorMapInfo(keymap->ctx, &info->ledDflt);
- info->ledDflt.file_id = file_id;
- info->ledDflt.defined = 0;
- info->ledDflt.merge = MERGE_OVERRIDE;
- darray_init(info->leds);
- InitVModInfo(&info->vmods, keymap);
+ info->mods = *mods;
+ info->default_interp.merge = MERGE_OVERRIDE;
+ info->default_interp.interp.virtual_mod = XKB_MOD_INVALID;
+ info->default_led.merge = MERGE_OVERRIDE;
}
static void
ClearCompatInfo(CompatInfo *info)
{
- struct xkb_keymap *keymap = info->keymap;
-
free(info->name);
- info->name = NULL;
- info->dflt.defined = 0;
- info->dflt.merge = MERGE_AUGMENT;
- info->dflt.interp.flags = 0;
- info->dflt.interp.virtual_mod = XKB_MOD_INVALID;
- memset(&info->dflt.interp.act, 0, sizeof(info->dflt.interp.act));
- info->dflt.interp.act.type = XkbSA_NoAction;
- ClearIndicatorMapInfo(keymap->ctx, &info->ledDflt);
darray_free(info->interps);
- darray_free(info->leds);
- info->actions = NULL;
- info->keymap = NULL;
- ClearVModInfo(&info->vmods);
}
static SymInterpInfo *
}
static bool
-AddInterp(CompatInfo *info, SymInterpInfo *new)
+AddInterp(CompatInfo *info, SymInterpInfo *new, bool same_file)
{
- enum si_field collide = 0;
- SymInterpInfo *old;
-
- old = FindMatchingInterp(info, new);
+ SymInterpInfo *old = FindMatchingInterp(info, new);
if (old) {
- int verbosity = xkb_get_log_verbosity(info->keymap->ctx);
- bool report = ((old->file_id == new->file_id && verbosity > 0) ||
- verbosity > 9);
+ const int verbosity = xkb_context_get_log_verbosity(info->ctx);
+ const bool report = (same_file && verbosity > 0) || verbosity > 9;
+ enum si_field collide = 0;
if (new->merge == MERGE_REPLACE) {
if (report)
- log_warn(info->keymap->ctx,
+ log_warn(info->ctx, XKB_LOG_MESSAGE_NO_ID,
"Multiple definitions for \"%s\"; "
"Earlier interpretation ignored\n",
siText(new, info));
}
if (UseNewInterpField(SI_FIELD_ACTION, old, new, report,
&collide)) {
- old->interp.act = new->interp.act;
+ old->interp.action = new->interp.action;
old->defined |= SI_FIELD_ACTION;
}
if (UseNewInterpField(SI_FIELD_AUTO_REPEAT, old, new, report,
&collide)) {
- old->interp.flags &= ~XkbSI_AutoRepeat;
- old->interp.flags |= (new->interp.flags & XkbSI_AutoRepeat);
+ old->interp.repeat = new->interp.repeat;
old->defined |= SI_FIELD_AUTO_REPEAT;
}
if (UseNewInterpField(SI_FIELD_LEVEL_ONE_ONLY, old, new, report,
&collide)) {
- old->interp.match &= ~XkbSI_LevelOneOnly;
- old->interp.match |= (new->interp.match & XkbSI_LevelOneOnly);
+ old->interp.level_one_only = new->interp.level_one_only;
old->defined |= SI_FIELD_LEVEL_ONE_ONLY;
}
if (collide) {
- log_warn(info->keymap->ctx,
+ log_warn(info->ctx, XKB_LOG_MESSAGE_NO_ID,
"Multiple interpretations of \"%s\"; "
"Using %s definition for duplicate fields\n",
siText(new, info),
return true;
}
-
/***====================================================================***/
static bool
-ResolveStateAndPredicate(ExprDef *expr, unsigned *pred_rtrn,
+ResolveStateAndPredicate(ExprDef *expr, enum xkb_match_operation *pred_rtrn,
xkb_mod_mask_t *mods_rtrn, CompatInfo *info)
{
if (expr == NULL) {
- *pred_rtrn = XkbSI_AnyOfOrNone;
- *mods_rtrn = ~0;
+ *pred_rtrn = MATCH_ANY_OR_NONE;
+ *mods_rtrn = MOD_REAL_MASK_ALL;
return true;
}
- *pred_rtrn = XkbSI_Exactly;
- if (expr->op == EXPR_ACTION_DECL) {
- const char *pred_txt = xkb_atom_text(info->keymap->ctx,
- expr->value.action.name);
- if (istreq(pred_txt, "noneof"))
- *pred_rtrn = XkbSI_NoneOf;
- else if (istreq(pred_txt, "anyofornone"))
- *pred_rtrn = XkbSI_AnyOfOrNone;
- else if (istreq(pred_txt, "anyof"))
- *pred_rtrn = XkbSI_AnyOf;
- else if (istreq(pred_txt, "allof"))
- *pred_rtrn = XkbSI_AllOf;
- else if (istreq(pred_txt, "exactly"))
- *pred_rtrn = XkbSI_Exactly;
- else {
- log_err(info->keymap->ctx,
+ *pred_rtrn = MATCH_EXACTLY;
+ if (expr->expr.op == EXPR_ACTION_DECL) {
+ const char *pred_txt = xkb_atom_text(info->ctx, expr->action.name);
+ if (!LookupString(symInterpretMatchMaskNames, pred_txt, pred_rtrn) ||
+ !expr->action.args || expr->action.args->common.next) {
+ log_err(info->ctx, XKB_LOG_MESSAGE_NO_ID,
"Illegal modifier predicate \"%s\"; Ignored\n", pred_txt);
return false;
}
- expr = expr->value.action.args;
+ expr = expr->action.args;
}
- else if (expr->op == EXPR_IDENT) {
- const char *pred_txt = xkb_atom_text(info->keymap->ctx,
- expr->value.str);
+ else if (expr->expr.op == EXPR_IDENT) {
+ const char *pred_txt = xkb_atom_text(info->ctx, expr->ident.ident);
if (pred_txt && istreq(pred_txt, "any")) {
- *pred_rtrn = XkbSI_AnyOf;
- *mods_rtrn = 0xff;
+ *pred_rtrn = MATCH_ANY;
+ *mods_rtrn = MOD_REAL_MASK_ALL;
return true;
}
}
- return ExprResolveModMask(info->keymap->ctx, expr, mods_rtrn);
+ return ExprResolveModMask(info->ctx, expr, MOD_REAL, &info->mods,
+ mods_rtrn);
}
/***====================================================================***/
static bool
-UseNewLEDField(enum led_field field, LEDInfo *old, LEDInfo *new,
+UseNewLEDField(enum led_field field, LedInfo *old, LedInfo *new,
bool report, enum led_field *collide)
{
if (!(old->defined & field))
}
static bool
-AddIndicatorMap(CompatInfo *info, LEDInfo *new)
+AddLedMap(CompatInfo *info, LedInfo *new, bool same_file)
{
- LEDInfo *old;
enum led_field collide;
- struct xkb_context *ctx = info->keymap->ctx;
- int verbosity = xkb_get_log_verbosity(ctx);
+ const int verbosity = xkb_context_get_log_verbosity(info->ctx);
+ const bool report = (same_file && verbosity > 0) || verbosity > 9;
- darray_foreach(old, info->leds) {
- bool report;
+ for (xkb_led_index_t i = 0; i < info->num_leds; i++) {
+ LedInfo *old = &info->leds[i];
- if (old->name != new->name)
+ if (old->led.name != new->led.name)
continue;
- if (old->mods == new->mods &&
- old->groups == new->groups &&
- old->ctrls == new->ctrls &&
- old->which_mods == new->which_mods &&
- old->which_groups == new->which_groups) {
+ if (old->led.mods.mods == new->led.mods.mods &&
+ old->led.groups == new->led.groups &&
+ old->led.ctrls == new->led.ctrls &&
+ old->led.which_mods == new->led.which_mods &&
+ old->led.which_groups == new->led.which_groups) {
old->defined |= new->defined;
return true;
}
- report = ((old->file_id == new->file_id && verbosity > 0) ||
- verbosity > 9);
-
if (new->merge == MERGE_REPLACE) {
if (report)
- log_warn(info->keymap->ctx,
+ log_warn(info->ctx, XKB_LOG_MESSAGE_NO_ID,
"Map for indicator %s redefined; "
"Earlier definition ignored\n",
- xkb_atom_text(ctx, old->name));
+ xkb_atom_text(info->ctx, old->led.name));
*old = *new;
return true;
}
collide = 0;
if (UseNewLEDField(LED_FIELD_MODS, old, new, report, &collide)) {
- old->which_mods = new->which_mods;
- old->mods = new->mods;
+ old->led.which_mods = new->led.which_mods;
+ old->led.mods = new->led.mods;
old->defined |= LED_FIELD_MODS;
}
if (UseNewLEDField(LED_FIELD_GROUPS, old, new, report, &collide)) {
- old->which_groups = new->which_groups;
- old->groups = new->groups;
+ old->led.which_groups = new->led.which_groups;
+ old->led.groups = new->led.groups;
old->defined |= LED_FIELD_GROUPS;
}
if (UseNewLEDField(LED_FIELD_CTRLS, old, new, report, &collide)) {
- old->ctrls = new->ctrls;
+ old->led.ctrls = new->led.ctrls;
old->defined |= LED_FIELD_CTRLS;
}
if (collide) {
- log_warn(info->keymap->ctx,
+ log_warn(info->ctx, XKB_LOG_MESSAGE_NO_ID,
"Map for indicator %s redefined; "
"Using %s definition for duplicate fields\n",
- xkb_atom_text(ctx, old->name),
+ xkb_atom_text(info->ctx, old->led.name),
(new->merge == MERGE_AUGMENT ? "first" : "last"));
}
return true;
}
- darray_append(info->leds, *new);
+ if (info->num_leds >= XKB_MAX_LEDS) {
+ log_err(info->ctx, XKB_LOG_MESSAGE_NO_ID,
+ "Too many LEDs defined (maximum %d)\n",
+ XKB_MAX_LEDS);
+ return false;
+ }
+ info->leds[info->num_leds++] = *new;
return true;
}
MergeIncludedCompatMaps(CompatInfo *into, CompatInfo *from,
enum merge_mode merge)
{
- SymInterpInfo *si;
- LEDInfo *led;
-
if (from->errorCount > 0) {
into->errorCount += from->errorCount;
return;
}
+ into->mods = from->mods;
+
if (into->name == NULL) {
into->name = from->name;
from->name = NULL;
}
- darray_foreach(si, from->interps) {
- si->merge = (merge == MERGE_DEFAULT ? si->merge : merge);
- if (!AddInterp(into, si))
- into->errorCount++;
+ if (darray_empty(into->interps)) {
+ into->interps = from->interps;
+ darray_init(from->interps);
+ }
+ else {
+ SymInterpInfo *si;
+ darray_foreach(si, from->interps) {
+ si->merge = (merge == MERGE_DEFAULT ? si->merge : merge);
+ if (!AddInterp(into, si, false))
+ into->errorCount++;
+ }
}
- darray_foreach(led, from->leds) {
- led->merge = (merge == MERGE_DEFAULT ? led->merge : merge);
- if (!AddIndicatorMap(into, led))
- into->errorCount++;
+ if (into->num_leds == 0) {
+ memcpy(into->leds, from->leds, sizeof(*from->leds) * from->num_leds);
+ into->num_leds = from->num_leds;
+ from->num_leds = 0;
+ }
+ else {
+ for (xkb_led_index_t i = 0; i < from->num_leds; i++) {
+ LedInfo *ledi = &from->leds[i];
+ ledi->merge = (merge == MERGE_DEFAULT ? ledi->merge : merge);
+ if (!AddLedMap(into, ledi, false))
+ into->errorCount++;
+ }
}
}
HandleCompatMapFile(CompatInfo *info, XkbFile *file, enum merge_mode merge);
static bool
-HandleIncludeCompatMap(CompatInfo *info, IncludeStmt *stmt)
+HandleIncludeCompatMap(CompatInfo *info, IncludeStmt *include)
{
- enum merge_mode merge = MERGE_DEFAULT;
- XkbFile *rtrn;
- CompatInfo included, next_incl;
-
- InitCompatInfo(&included, info->keymap, info->file_id, info->actions);
- if (stmt->stmt) {
- free(included.name);
- included.name = stmt->stmt;
- stmt->stmt = NULL;
- }
+ CompatInfo included;
- for (; stmt; stmt = stmt->next_incl) {
- if (!ProcessIncludeFile(info->keymap->ctx, stmt, FILE_TYPE_COMPAT,
- &rtrn, &merge)) {
+ InitCompatInfo(&included, info->ctx, info->actions, &info->mods);
+ included.name = include->stmt;
+ include->stmt = NULL;
+
+ for (IncludeStmt *stmt = include; stmt; stmt = stmt->next_incl) {
+ CompatInfo next_incl;
+ XkbFile *file;
+
+ file = ProcessIncludeFile(info->ctx, stmt, FILE_TYPE_COMPAT);
+ if (!file) {
info->errorCount += 10;
ClearCompatInfo(&included);
return false;
}
- InitCompatInfo(&next_incl, info->keymap, rtrn->id, info->actions);
- next_incl.file_id = rtrn->id;
- next_incl.dflt = info->dflt;
- next_incl.dflt.file_id = rtrn->id;
- next_incl.dflt.merge = merge;
- next_incl.ledDflt.file_id = rtrn->id;
- next_incl.ledDflt.merge = merge;
+ InitCompatInfo(&next_incl, info->ctx, info->actions, &included.mods);
+ next_incl.default_interp = info->default_interp;
+ next_incl.default_interp.merge = stmt->merge;
+ next_incl.default_led = info->default_led;
+ next_incl.default_led.merge = stmt->merge;
- HandleCompatMapFile(&next_incl, rtrn, MERGE_OVERRIDE);
+ HandleCompatMapFile(&next_incl, file, MERGE_OVERRIDE);
- MergeIncludedCompatMaps(&included, &next_incl, merge);
+ MergeIncludedCompatMaps(&included, &next_incl, stmt->merge);
ClearCompatInfo(&next_incl);
- FreeXkbFile(rtrn);
+ FreeXkbFile(file);
}
- MergeIncludedCompatMaps(info, &included, merge);
+ MergeIncludedCompatMaps(info, &included, include->merge);
ClearCompatInfo(&included);
return (info->errorCount == 0);
}
-static const LookupEntry useModMapValues[] = {
- { "levelone", 1 },
- { "level1", 1 },
- { "anylevel", 0 },
- { "any", 0 },
- { NULL, 0 }
-};
-
static bool
SetInterpField(CompatInfo *info, SymInterpInfo *si, const char *field,
ExprDef *arrayNdx, ExprDef *value)
{
- struct xkb_keymap *keymap = info->keymap;
xkb_mod_index_t ndx;
if (istreq(field, "action")) {
if (arrayNdx)
return ReportSINotArray(info, si, field);
- if (!HandleActionDef(value, keymap, &si->interp.act, info->actions))
+ if (!HandleActionDef(info->ctx, info->actions, &info->mods,
+ value, &si->interp.action))
return false;
si->defined |= SI_FIELD_ACTION;
if (arrayNdx)
return ReportSINotArray(info, si, field);
- if (!ResolveVirtualModifier(value, keymap, &ndx, &info->vmods))
+ if (!ExprResolveMod(info->ctx, value, MOD_VIRT, &info->mods, &ndx))
return ReportSIBadType(info, si, field, "virtual modifier");
si->interp.virtual_mod = ndx;
if (arrayNdx)
return ReportSINotArray(info, si, field);
- if (!ExprResolveBoolean(keymap->ctx, value, &set))
+ if (!ExprResolveBoolean(info->ctx, value, &set))
return ReportSIBadType(info, si, field, "boolean");
- if (set)
- si->interp.flags |= XkbSI_AutoRepeat;
- else
- si->interp.flags &= ~XkbSI_AutoRepeat;
+ si->interp.repeat = set;
si->defined |= SI_FIELD_AUTO_REPEAT;
}
else if (istreq(field, "locking")) {
- log_dbg(info->keymap->ctx,
+ log_dbg(info->ctx, XKB_LOG_MESSAGE_NO_ID,
"The \"locking\" field in symbol interpretation is unsupported; "
"Ignored\n");
}
if (arrayNdx)
return ReportSINotArray(info, si, field);
- if (!ExprResolveEnum(keymap->ctx, value, &val, useModMapValues))
+ if (!ExprResolveEnum(info->ctx, value, &val, useModMapValueNames))
return ReportSIBadType(info, si, field, "level specification");
- if (val)
- si->interp.match |= XkbSI_LevelOneOnly;
- else
- si->interp.match &= ~XkbSI_LevelOneOnly;
-
+ si->interp.level_one_only = val;
si->defined |= SI_FIELD_LEVEL_ONE_ONLY;
}
else {
- return ReportBadField(keymap, "symbol interpretation", field,
+ return ReportBadField(info->ctx, "symbol interpretation", field,
siText(si, info));
}
return true;
}
-static const LookupEntry modComponentNames[] = {
- {"base", XkbIM_UseBase},
- {"latched", XkbIM_UseLatched},
- {"locked", XkbIM_UseLocked},
- {"effective", XkbIM_UseEffective},
- {"compat", XkbIM_UseCompat},
- {"any", XkbIM_UseAnyMods},
- {"none", 0},
- {NULL, 0}
-};
-
-static const LookupEntry groupComponentNames[] = {
- {"base", XkbIM_UseBase},
- {"latched", XkbIM_UseLatched},
- {"locked", XkbIM_UseLocked},
- {"effective", XkbIM_UseEffective},
- {"any", XkbIM_UseAnyGroup},
- {"none", 0},
- {NULL, 0}
-};
-
-static const LookupEntry groupNames[] = {
- {"group1", 0x01},
- {"group2", 0x02},
- {"group3", 0x04},
- {"group4", 0x08},
- {"group5", 0x10},
- {"group6", 0x20},
- {"group7", 0x40},
- {"group8", 0x80},
- {"none", 0x00},
- {"all", 0xff},
- {NULL, 0}
-};
-
static bool
-SetIndicatorMapField(CompatInfo *info, LEDInfo *led,
- const char *field, ExprDef *arrayNdx, ExprDef *value)
+SetLedMapField(CompatInfo *info, LedInfo *ledi, const char *field,
+ ExprDef *arrayNdx, ExprDef *value)
{
bool ok = true;
- struct xkb_keymap *keymap = info->keymap;
if (istreq(field, "modifiers") || istreq(field, "mods")) {
if (arrayNdx)
- return ReportIndicatorNotArray(info, led, field);
+ return ReportLedNotArray(info, ledi, field);
- if (!ExprResolveVModMask(keymap, value, &led->mods))
- return ReportIndicatorBadType(info, led, field, "modifier mask");
+ if (!ExprResolveModMask(info->ctx, value, MOD_BOTH,
+ &info->mods, &ledi->led.mods.mods))
+ return ReportLedBadType(info, ledi, field, "modifier mask");
- led->defined |= LED_FIELD_MODS;
+ ledi->defined |= LED_FIELD_MODS;
}
else if (istreq(field, "groups")) {
unsigned int mask;
if (arrayNdx)
- return ReportIndicatorNotArray(info, led, field);
+ return ReportLedNotArray(info, ledi, field);
- if (!ExprResolveMask(keymap->ctx, value, &mask, groupNames))
- return ReportIndicatorBadType(info, led, field, "group mask");
+ if (!ExprResolveMask(info->ctx, value, &mask, groupMaskNames))
+ return ReportLedBadType(info, ledi, field, "group mask");
- led->groups = mask;
- led->defined |= LED_FIELD_GROUPS;
+ ledi->led.groups = mask;
+ ledi->defined |= LED_FIELD_GROUPS;
}
else if (istreq(field, "controls") || istreq(field, "ctrls")) {
unsigned int mask;
if (arrayNdx)
- return ReportIndicatorNotArray(info, led, field);
+ return ReportLedNotArray(info, ledi, field);
- if (!ExprResolveMask(keymap->ctx, value, &mask, ctrlNames))
- return ReportIndicatorBadType(info, led, field,
- "controls mask");
+ if (!ExprResolveMask(info->ctx, value, &mask, ctrlMaskNames))
+ return ReportLedBadType(info, ledi, field, "controls mask");
- led->ctrls = mask;
- led->defined |= LED_FIELD_CTRLS;
+ ledi->led.ctrls = mask;
+ ledi->defined |= LED_FIELD_CTRLS;
}
else if (istreq(field, "allowexplicit")) {
- log_dbg(info->keymap->ctx,
+ log_dbg(info->ctx, XKB_LOG_MESSAGE_NO_ID,
"The \"allowExplicit\" field in indicator statements is unsupported; "
"Ignored\n");
}
unsigned int mask;
if (arrayNdx)
- return ReportIndicatorNotArray(info, led, field);
+ return ReportLedNotArray(info, ledi, field);
- if (!ExprResolveMask(keymap->ctx, value, &mask, modComponentNames))
- return ReportIndicatorBadType(info, led, field,
- "mask of modifier state components");
+ if (!ExprResolveMask(info->ctx, value, &mask,
+ modComponentMaskNames))
+ return ReportLedBadType(info, ledi, field,
+ "mask of modifier state components");
- led->which_mods = mask;
+ ledi->led.which_mods = mask;
}
else if (istreq(field, "whichgroupstate")) {
unsigned mask;
if (arrayNdx)
- return ReportIndicatorNotArray(info, led, field);
+ return ReportLedNotArray(info, ledi, field);
- if (!ExprResolveMask(keymap->ctx, value, &mask, groupComponentNames))
- return ReportIndicatorBadType(info, led, field,
- "mask of group state components");
+ if (!ExprResolveMask(info->ctx, value, &mask,
+ groupComponentMaskNames))
+ return ReportLedBadType(info, ledi, field,
+ "mask of group state components");
- led->which_groups = mask;
+ ledi->led.which_groups = mask;
}
else if (istreq(field, "driveskbd") ||
istreq(field, "driveskeyboard") ||
istreq(field, "leddriveskeyboard") ||
istreq(field, "indicatordriveskbd") ||
istreq(field, "indicatordriveskeyboard")) {
- log_dbg(info->keymap->ctx,
+ log_dbg(info->ctx, XKB_LOG_MESSAGE_NO_ID,
"The \"%s\" field in indicator statements is unsupported; "
"Ignored\n", field);
}
else if (istreq(field, "index")) {
/* Users should see this, it might cause unexpected behavior. */
- log_err(info->keymap->ctx,
+ log_err(info->ctx, XKB_LOG_MESSAGE_NO_ID,
"The \"index\" field in indicator statements is unsupported; "
"Ignored\n");
}
else {
- log_err(info->keymap->ctx,
+ log_err(info->ctx, XKB_LOG_MESSAGE_NO_ID,
"Unknown field %s in map for %s indicator; "
"Definition ignored\n",
- field, xkb_atom_text(keymap->ctx, led->name));
+ field, xkb_atom_text(info->ctx, ledi->led.name));
ok = false;
}
ExprDef *ndx;
bool ret;
- if (!ExprResolveLhs(info->keymap->ctx, stmt->name, &elem, &field, &ndx))
+ if (!ExprResolveLhs(info->ctx, stmt->name, &elem, &field, &ndx))
ret = false;
else if (elem && istreq(elem, "interpret"))
- ret = SetInterpField(info, &info->dflt, field, ndx, stmt->value);
+ ret = SetInterpField(info, &info->default_interp, field, ndx,
+ stmt->value);
else if (elem && istreq(elem, "indicator"))
- ret = SetIndicatorMapField(info, &info->ledDflt, field, ndx,
- stmt->value);
+ ret = SetLedMapField(info, &info->default_led, field, ndx,
+ stmt->value);
else
- ret = SetActionField(info->keymap, elem, field, ndx, stmt->value,
- info->actions);
+ ret = SetActionField(info->ctx, info->actions, &info->mods,
+ elem, field, ndx, stmt->value);
return ret;
}
ExprDef *arrayNdx;
for (; def; def = (VarDef *) def->common.next) {
- if (def->name && def->name->op == EXPR_FIELD_REF) {
- log_err(info->keymap->ctx,
+ if (def->name && def->name->expr.op == EXPR_FIELD_REF) {
+ log_err(info->ctx, XKB_LOG_MESSAGE_NO_ID,
"Cannot set a global default value from within an interpret statement; "
"Move statements to the global file scope\n");
ok = false;
continue;
}
- ok = ExprResolveLhs(info->keymap->ctx, def->name, &elem, &field,
- &arrayNdx);
+ ok = ExprResolveLhs(info->ctx, def->name, &elem, &field, &arrayNdx);
if (!ok)
continue;
static bool
HandleInterpDef(CompatInfo *info, InterpDef *def, enum merge_mode merge)
{
- unsigned pred, mods;
+ enum xkb_match_operation pred;
+ xkb_mod_mask_t mods;
SymInterpInfo si;
if (!ResolveStateAndPredicate(def->match, &pred, &mods, info)) {
- log_err(info->keymap->ctx,
+ log_err(info->ctx, XKB_LOG_MESSAGE_NO_ID,
"Couldn't determine matching modifiers; "
"Symbol interpretation ignored\n");
return false;
}
- si = info->dflt;
-
- si.merge = merge = (def->merge == MERGE_DEFAULT ? merge : def->merge);
-
- if (!LookupKeysym(def->sym, &si.interp.sym)) {
- log_err(info->keymap->ctx,
- "Could not resolve keysym %s; "
- "Symbol interpretation ignored\n",
- def->sym);
- return false;
- }
-
- si.interp.match = pred & XkbSI_OpMask;
-
+ si = info->default_interp;
+ si.merge = (def->merge == MERGE_DEFAULT ? merge : def->merge);
+ si.interp.sym = def->sym;
+ si.interp.match = pred;
si.interp.mods = mods;
if (!HandleInterpBody(info, def->def, &si)) {
return false;
}
- if (!AddInterp(info, &si)) {
+ if (!AddInterp(info, &si, true)) {
info->errorCount++;
return false;
}
}
static bool
-HandleIndicatorMapDef(CompatInfo *info, IndicatorMapDef *def,
- enum merge_mode merge)
+HandleLedMapDef(CompatInfo *info, LedMapDef *def, enum merge_mode merge)
{
- LEDInfo led;
+ LedInfo ledi;
VarDef *var;
bool ok;
if (def->merge != MERGE_DEFAULT)
merge = def->merge;
- led = info->ledDflt;
- led.merge = merge;
- led.name = def->name;
+ ledi = info->default_led;
+ ledi.merge = merge;
+ ledi.led.name = def->name;
ok = true;
for (var = def->body; var != NULL; var = (VarDef *) var->common.next) {
const char *elem, *field;
ExprDef *arrayNdx;
- if (!ExprResolveLhs(info->keymap->ctx, var->name, &elem, &field,
- &arrayNdx)) {
+ if (!ExprResolveLhs(info->ctx, var->name, &elem, &field, &arrayNdx)) {
ok = false;
continue;
}
if (elem) {
- log_err(info->keymap->ctx,
+ log_err(info->ctx, XKB_LOG_MESSAGE_NO_ID,
"Cannot set defaults for \"%s\" element in indicator map; "
"Assignment to %s.%s ignored\n", elem, elem, field);
ok = false;
}
else {
- ok = SetIndicatorMapField(info, &led, field, arrayNdx,
- var->value) && ok;
+ ok = SetLedMapField(info, &ledi, field, arrayNdx, var->value) && ok;
}
}
if (ok)
- return AddIndicatorMap(info, &led);
+ return AddLedMap(info, &ledi, true);
return false;
}
HandleCompatMapFile(CompatInfo *info, XkbFile *file, enum merge_mode merge)
{
bool ok;
- ParseCommon *stmt;
merge = (merge == MERGE_DEFAULT ? MERGE_AUGMENT : merge);
free(info->name);
info->name = strdup_safe(file->name);
- for (stmt = file->defs; stmt; stmt = stmt->next) {
+ for (ParseCommon *stmt = file->defs; stmt; stmt = stmt->next) {
switch (stmt->type) {
case STMT_INCLUDE:
ok = HandleIncludeCompatMap(info, (IncludeStmt *) stmt);
ok = HandleInterpDef(info, (InterpDef *) stmt, merge);
break;
case STMT_GROUP_COMPAT:
- log_dbg(info->keymap->ctx,
+ log_dbg(info->ctx, XKB_LOG_MESSAGE_NO_ID,
"The \"group\" statement in compat is unsupported; "
"Ignored\n");
ok = true;
break;
- case STMT_INDICATOR_MAP:
- ok = HandleIndicatorMapDef(info, (IndicatorMapDef *) stmt, merge);
+ case STMT_LED_MAP:
+ ok = HandleLedMapDef(info, (LedMapDef *) stmt, merge);
break;
case STMT_VAR:
ok = HandleGlobalVar(info, (VarDef *) stmt);
break;
case STMT_VMOD:
- ok = HandleVModDef((VModDef *) stmt, info->keymap, merge,
- &info->vmods);
+ ok = HandleVModDef(info->ctx, &info->mods, (VModDef *) stmt, merge);
break;
default:
- log_err(info->keymap->ctx,
- "Interpretation files may not include other types; "
+ log_err(info->ctx, XKB_LOG_MESSAGE_NO_ID,
+ "Compat files may not include other types; "
"Ignoring %s\n", stmt_type_to_string(stmt->type));
ok = false;
break;
info->errorCount++;
if (info->errorCount > 10) {
- log_err(info->keymap->ctx,
- "Abandoning compatibility map \"%s\"\n", file->topName);
+ log_err(info->ctx, XKB_LOG_MESSAGE_NO_ID,
+ "Abandoning compatibility map \"%s\"\n", file->name);
break;
}
}
}
+/* Temporary struct for CopyInterps. */
+struct collect {
+ darray(struct xkb_sym_interpret) sym_interprets;
+};
+
static void
-CopyInterps(CompatInfo *info, bool needSymbol, unsigned pred)
+CopyInterps(CompatInfo *info, bool needSymbol, enum xkb_match_operation pred,
+ struct collect *collect)
{
SymInterpInfo *si;
- darray_foreach(si, info->interps) {
- if (((si->interp.match & XkbSI_OpMask) != pred) ||
- (needSymbol && si->interp.sym == XKB_KEY_NoSymbol) ||
- (!needSymbol && si->interp.sym != XKB_KEY_NoSymbol))
- continue;
-
- darray_append(info->keymap->sym_interpret, si->interp);
- }
+ darray_foreach(si, info->interps)
+ if (si->interp.match == pred &&
+ (si->interp.sym != XKB_KEY_NoSymbol) == needSymbol)
+ darray_append(collect->sym_interprets, si->interp);
}
static void
-CopyIndicatorMapDefs(CompatInfo *info)
+CopyLedMapDefsToKeymap(struct xkb_keymap *keymap, CompatInfo *info)
{
- LEDInfo *led;
- struct xkb_indicator_map *im;
- xkb_led_index_t i;
- struct xkb_keymap *keymap = info->keymap;
+ for (xkb_led_index_t idx = 0; idx < info->num_leds; idx++) {
+ LedInfo *ledi = &info->leds[idx];
+ xkb_led_index_t i;
+ struct xkb_led *led;
- darray_foreach(led, info->leds) {
/*
- * Find the indicator with the given name, if it was already
- * declared in keycodes.
+ * Find the LED with the given name, if it was already declared
+ * in keycodes.
*/
- im = NULL;
- for (i = 0; i < XkbNumIndicators; i++) {
- if (keymap->indicator_names[i] == led->name) {
- im = &keymap->indicators[i];
+ xkb_leds_enumerate(i, led, keymap)
+ if (led->name == ledi->led.name)
break;
- }
- }
/* Not previously declared; create it with next free index. */
- if (!im) {
- log_dbg(keymap->ctx,
+ if (i >= keymap->num_leds) {
+ log_dbg(keymap->ctx, XKB_LOG_MESSAGE_NO_ID,
"Indicator name \"%s\" was not declared in the keycodes section; "
"Adding new indicator\n",
- xkb_atom_text(keymap->ctx, led->name));
-
- for (i = 0; i < XkbNumIndicators; i++) {
- if (keymap->indicator_names[i] != XKB_ATOM_NONE)
+ xkb_atom_text(keymap->ctx, ledi->led.name));
+
+ xkb_leds_enumerate(i, led, keymap)
+ if (led->name == XKB_ATOM_NONE)
+ break;
+
+ if (i >= keymap->num_leds) {
+ /* Not place to put it; ignore. */
+ if (i >= XKB_MAX_LEDS) {
+ log_err(keymap->ctx, XKB_LOG_MESSAGE_NO_ID,
+ "Too many indicators (maximum is %d); "
+ "Indicator name \"%s\" ignored\n",
+ XKB_MAX_LEDS,
+ xkb_atom_text(keymap->ctx, ledi->led.name));
continue;
+ }
- keymap->indicator_names[i] = led->name;
- im = &keymap->indicators[i];
- break;
- }
-
- /* Not place to put the it; ignore. */
- if (!im) {
- log_err(keymap->ctx,
- "Too many indicators (maximum is %d); "
- "Indicator name \"%s\" ignored\n",
- XkbNumIndicators,
- xkb_atom_text(keymap->ctx, led->name));
- continue;
+ /* Add a new LED. */
+ led = &keymap->leds[keymap->num_leds++];
}
}
+ *led = ledi->led;
if (led->groups != 0 && led->which_groups == 0)
- im->which_groups = XkbIM_UseEffective;
- else
- im->which_groups = led->which_groups;
- im->groups = led->groups;
- if (led->mods != 0 && led->which_mods == 0)
- im->which_mods = XkbIM_UseEffective;
- else
- im->which_mods = led->which_mods;
- im->mods.mods = led->mods;
- im->ctrls = led->ctrls;
+ led->which_groups = XKB_STATE_LAYOUT_EFFECTIVE;
+ if (led->mods.mods != 0 && led->which_mods == 0)
+ led->which_mods = XKB_STATE_MODS_EFFECTIVE;
}
}
CopyCompatToKeymap(struct xkb_keymap *keymap, CompatInfo *info)
{
keymap->compat_section_name = strdup_safe(info->name);
+ XkbEscapeMapName(keymap->compat_section_name);
+
+ keymap->mods = info->mods;
if (!darray_empty(info->interps)) {
+ struct collect collect;
+ darray_init(collect.sym_interprets);
+
/* Most specific to least specific. */
- CopyInterps(info, true, XkbSI_Exactly);
- CopyInterps(info, true, XkbSI_AllOf | XkbSI_NoneOf);
- CopyInterps(info, true, XkbSI_AnyOf);
- CopyInterps(info, true, XkbSI_AnyOfOrNone);
- CopyInterps(info, false, XkbSI_Exactly);
- CopyInterps(info, false, XkbSI_AllOf | XkbSI_NoneOf);
- CopyInterps(info, false, XkbSI_AnyOf);
- CopyInterps(info, false, XkbSI_AnyOfOrNone);
+ CopyInterps(info, true, MATCH_EXACTLY, &collect);
+ CopyInterps(info, true, MATCH_ALL, &collect);
+ CopyInterps(info, true, MATCH_NONE, &collect);
+ CopyInterps(info, true, MATCH_ANY, &collect);
+ CopyInterps(info, true, MATCH_ANY_OR_NONE, &collect);
+ CopyInterps(info, false, MATCH_EXACTLY, &collect);
+ CopyInterps(info, false, MATCH_ALL, &collect);
+ CopyInterps(info, false, MATCH_NONE, &collect);
+ CopyInterps(info, false, MATCH_ANY, &collect);
+ CopyInterps(info, false, MATCH_ANY_OR_NONE, &collect);
+
+ darray_steal(collect.sym_interprets,
+ &keymap->sym_interprets, &keymap->num_sym_interprets);
}
- CopyIndicatorMapDefs(info);
+ CopyLedMapDefsToKeymap(keymap, info);
return true;
}
if (!actions)
return false;
- InitCompatInfo(&info, keymap, file->id, actions);
- info.dflt.merge = merge;
- info.ledDflt.merge = merge;
+ InitCompatInfo(&info, keymap->ctx, actions, &keymap->mods);
+ info.default_interp.merge = merge;
+ info.default_led.merge = merge;
HandleCompatMapFile(&info, file, merge);
if (info.errorCount != 0)