X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Fxkbcomp%2Faction.c;h=1410aab5183ee86c2764b326be7411f3ca90d6c4;hb=ef81d04eef4b1a60ff42bd9ccbe2918b0a5420ec;hp=0d376886e5af13e028be31adfd78cf8c752c8204;hpb=4c34bda15a4f8c8a16fa03d40bcf989db23023dd;p=platform%2Fupstream%2Flibxkbcommon.git diff --git a/src/xkbcomp/action.c b/src/xkbcomp/action.c index 0d37688..1410aab 100644 --- a/src/xkbcomp/action.c +++ b/src/xkbcomp/action.c @@ -24,162 +24,177 @@ * ********************************************************/ -#include "action.h" +/* + * Copyright © 2012 Intel Corporation + * Copyright © 2012 Ran Benita + * + * 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. + * + * Author: Daniel Stone + * Ran Benita + */ -static const ExprDef constTrue = { - .common = { .type = STMT_EXPR, .next = NULL }, - .op = EXPR_VALUE, - .value_type = EXPR_TYPE_BOOLEAN, - .value = { .ival = 1 }, -}; +#include "config.h" -static const ExprDef constFalse = { - .common = { .type = STMT_EXPR, .next = NULL }, - .op = EXPR_VALUE, - .value_type = EXPR_TYPE_BOOLEAN, - .value = { .ival = 0 }, -}; +#include "xkbcomp-priv.h" +#include "text.h" +#include "expr.h" +#include "action.h" -/***====================================================================***/ +static const ExprBoolean constTrue = { + .expr = { + .common = { .type = STMT_EXPR, .next = NULL }, + .op = EXPR_VALUE, + .value_type = EXPR_TYPE_BOOLEAN, + }, + .set = true, +}; -static const LookupEntry actionStrings[] = { - { "noaction", XkbSA_NoAction }, - { "setmods", XkbSA_SetMods }, - { "latchmods", XkbSA_LatchMods }, - { "lockmods", XkbSA_LockMods }, - { "setgroup", XkbSA_SetGroup }, - { "latchgroup", XkbSA_LatchGroup }, - { "lockgroup", XkbSA_LockGroup }, - { "moveptr", XkbSA_MovePtr }, - { "movepointer", XkbSA_MovePtr }, - { "ptrbtn", XkbSA_PtrBtn }, - { "pointerbutton", XkbSA_PtrBtn }, - { "lockptrbtn", XkbSA_LockPtrBtn }, - { "lockpointerbutton", XkbSA_LockPtrBtn }, - { "lockptrbutton", XkbSA_LockPtrBtn }, - { "lockpointerbtn", XkbSA_LockPtrBtn }, - { "setptrdflt", XkbSA_SetPtrDflt }, - { "setpointerdefault", XkbSA_SetPtrDflt }, - { "isolock", XkbSA_ISOLock }, - { "terminate", XkbSA_Terminate }, - { "terminateserver", XkbSA_Terminate }, - { "switchscreen", XkbSA_SwitchScreen }, - { "setcontrols", XkbSA_SetControls }, - { "lockcontrols", XkbSA_LockControls }, - { "actionmessage", XkbSA_ActionMessage }, - { "messageaction", XkbSA_ActionMessage }, - { "message", XkbSA_ActionMessage }, - { "redirect", XkbSA_RedirectKey }, - { "redirectkey", XkbSA_RedirectKey }, - { "devbtn", XkbSA_DeviceBtn }, - { "devicebtn", XkbSA_DeviceBtn }, - { "devbutton", XkbSA_DeviceBtn }, - { "devicebutton", XkbSA_DeviceBtn }, - { "lockdevbtn", XkbSA_DeviceBtn }, - { "lockdevicebtn", XkbSA_LockDeviceBtn }, - { "lockdevbutton", XkbSA_LockDeviceBtn }, - { "lockdevicebutton", XkbSA_LockDeviceBtn }, - { "devval", XkbSA_DeviceValuator }, - { "deviceval", XkbSA_DeviceValuator }, - { "devvaluator", XkbSA_DeviceValuator }, - { "devicevaluator", XkbSA_DeviceValuator }, - { "private", PrivateAction }, - { NULL, 0 } +static const ExprBoolean constFalse = { + .expr = { + .common = { .type = STMT_EXPR, .next = NULL }, + .op = EXPR_VALUE, + .value_type = EXPR_TYPE_BOOLEAN, + }, + .set = false, }; -static const LookupEntry fieldStrings[] = { - { "clearLocks", F_ClearLocks }, - { "latchToLock", F_LatchToLock }, - { "genKeyEvent", F_GenKeyEvent }, - { "generateKeyEvent", F_GenKeyEvent }, - { "report", F_Report }, - { "default", F_Default }, - { "affect", F_Affect }, - { "increment", F_Increment }, - { "modifiers", F_Modifiers }, - { "mods", F_Modifiers }, - { "group", F_Group }, - { "x", F_X }, - { "y", F_Y }, - { "accel", F_Accel }, - { "accelerate", F_Accel }, - { "repeat", F_Accel }, - { "button", F_Button }, - { "value", F_Value }, - { "controls", F_Controls }, - { "ctrls", F_Controls }, - { "type", F_Type }, - { "count", F_Count }, - { "screen", F_Screen }, - { "same", F_Same }, - { "sameServer", F_Same }, - { "data", F_Data }, - { "device", F_Device }, - { "dev", F_Device }, - { "key", F_Keycode }, - { "keycode", F_Keycode }, - { "kc", F_Keycode }, - { "clearmods", F_ModsToClear }, - { "clearmodifiers", F_ModsToClear }, - { NULL, 0 } +enum action_field { + ACTION_FIELD_CLEAR_LOCKS, + ACTION_FIELD_LATCH_TO_LOCK, + ACTION_FIELD_GEN_KEY_EVENT, + ACTION_FIELD_REPORT, + ACTION_FIELD_DEFAULT, + ACTION_FIELD_AFFECT, + ACTION_FIELD_INCREMENT, + ACTION_FIELD_MODIFIERS, + ACTION_FIELD_GROUP, + ACTION_FIELD_X, + ACTION_FIELD_Y, + ACTION_FIELD_ACCEL, + ACTION_FIELD_BUTTON, + ACTION_FIELD_VALUE, + ACTION_FIELD_CONTROLS, + ACTION_FIELD_TYPE, + ACTION_FIELD_COUNT, + ACTION_FIELD_SCREEN, + ACTION_FIELD_SAME, + ACTION_FIELD_DATA, + ACTION_FIELD_DEVICE, + ACTION_FIELD_KEYCODE, + ACTION_FIELD_MODS_TO_CLEAR, }; -static bool -stringToValue(const LookupEntry tab[], const char *string, - unsigned int *value_rtrn) +ActionsInfo * +NewActionsInfo(void) { - const LookupEntry *entry; + enum xkb_action_type type; + ActionsInfo *info; - if (!string) - return false; + info = calloc(1, sizeof(*info)); + if (!info) + return NULL; - for (entry = tab; entry->name; entry++) { - if (istreq(entry->name, string)) { - *value_rtrn = entry->value; - return true; - } - } + for (type = 0; type < _ACTION_TYPE_NUM_ENTRIES; type++) + info->actions[type].type = type; - return false; -} + /* Apply some "factory defaults". */ -static const char * -valueToString(const LookupEntry tab[], unsigned int value) -{ - const LookupEntry *entry; + /* Increment default button. */ + info->actions[ACTION_TYPE_PTR_DEFAULT].dflt.flags = 0; + info->actions[ACTION_TYPE_PTR_DEFAULT].dflt.value = 1; + info->actions[ACTION_TYPE_PTR_MOVE].ptr.flags = ACTION_ACCEL; + info->actions[ACTION_TYPE_SWITCH_VT].screen.flags = ACTION_SAME_SCREEN; - for (entry = tab; entry->name; entry++) - if (entry->value == value) - return entry->name; + return info; +} - return "unknown"; +void +FreeActionsInfo(ActionsInfo *info) +{ + free(info); } +static const LookupEntry fieldStrings[] = { + { "clearLocks", ACTION_FIELD_CLEAR_LOCKS }, + { "latchToLock", ACTION_FIELD_LATCH_TO_LOCK }, + { "genKeyEvent", ACTION_FIELD_GEN_KEY_EVENT }, + { "generateKeyEvent", ACTION_FIELD_GEN_KEY_EVENT }, + { "report", ACTION_FIELD_REPORT }, + { "default", ACTION_FIELD_DEFAULT }, + { "affect", ACTION_FIELD_AFFECT }, + { "increment", ACTION_FIELD_INCREMENT }, + { "modifiers", ACTION_FIELD_MODIFIERS }, + { "mods", ACTION_FIELD_MODIFIERS }, + { "group", ACTION_FIELD_GROUP }, + { "x", ACTION_FIELD_X }, + { "y", ACTION_FIELD_Y }, + { "accel", ACTION_FIELD_ACCEL }, + { "accelerate", ACTION_FIELD_ACCEL }, + { "repeat", ACTION_FIELD_ACCEL }, + { "button", ACTION_FIELD_BUTTON }, + { "value", ACTION_FIELD_VALUE }, + { "controls", ACTION_FIELD_CONTROLS }, + { "ctrls", ACTION_FIELD_CONTROLS }, + { "type", ACTION_FIELD_TYPE }, + { "count", ACTION_FIELD_COUNT }, + { "screen", ACTION_FIELD_SCREEN }, + { "same", ACTION_FIELD_SAME }, + { "sameServer", ACTION_FIELD_SAME }, + { "data", ACTION_FIELD_DATA }, + { "device", ACTION_FIELD_DEVICE }, + { "dev", ACTION_FIELD_DEVICE }, + { "key", ACTION_FIELD_KEYCODE }, + { "keycode", ACTION_FIELD_KEYCODE }, + { "kc", ACTION_FIELD_KEYCODE }, + { "clearmods", ACTION_FIELD_MODS_TO_CLEAR }, + { "clearmodifiers", ACTION_FIELD_MODS_TO_CLEAR }, + { NULL, 0 } +}; + static bool -stringToAction(const char *str, unsigned *type_rtrn) +stringToAction(const char *str, enum xkb_action_type *type_rtrn) { - return stringToValue(actionStrings, str, type_rtrn); + return LookupString(actionTypeNames, str, type_rtrn); } static bool -stringToField(const char *str, unsigned *field_rtrn) +stringToField(const char *str, enum action_field *field_rtrn) { - return stringToValue(fieldStrings, str, field_rtrn); + return LookupString(fieldStrings, str, field_rtrn); } static const char * -fieldText(unsigned field) +fieldText(enum action_field field) { - return valueToString(fieldStrings, field); + return LookupValue(fieldStrings, field); } /***====================================================================***/ static inline bool -ReportMismatch(struct xkb_keymap *keymap, unsigned action, unsigned field, +ReportMismatch(struct xkb_context *ctx, xkb_message_code_t code, + enum xkb_action_type action, enum action_field field, const char *type) { - log_err(keymap->ctx, + log_err_with_code(ctx, code, "Value of %s field must be of type %s; " "Action %s definition ignored\n", fieldText(field), type, ActionTypeText(action)); @@ -187,9 +202,10 @@ ReportMismatch(struct xkb_keymap *keymap, unsigned action, unsigned field, } static inline bool -ReportIllegal(struct xkb_keymap *keymap, unsigned action, unsigned field) +ReportIllegal(struct xkb_context *ctx, enum xkb_action_type action, + enum action_field field) { - log_err(keymap->ctx, + log_err(ctx, "Field %s is not defined for an action of type %s; " "Action definition ignored\n", fieldText(field), ActionTypeText(action)); @@ -197,314 +213,264 @@ ReportIllegal(struct xkb_keymap *keymap, unsigned action, unsigned field) } static inline bool -ReportActionNotArray(struct xkb_keymap *keymap, unsigned action, - unsigned field) +ReportActionNotArray(struct xkb_context *ctx, enum xkb_action_type action, + enum action_field field) { - log_err(keymap->ctx, + log_err(ctx, "The %s field in the %s action is not an array; " "Action definition ignored\n", fieldText(field), ActionTypeText(action)); return false; } -static inline bool -ReportNotFound(struct xkb_keymap *keymap, unsigned action, unsigned field, - const char *what, const char *bad) -{ - log_err(keymap->ctx, - "%s named %s not found; " - "Ignoring the %s field of an %s action\n", - what, bad, fieldText(field), ActionTypeText(action)); - return false; -} - static bool -HandleNoAction(struct xkb_keymap *keymap, union xkb_action *action, - unsigned field, const ExprDef *array_ndx, const ExprDef *value) +HandleNoAction(struct xkb_context *ctx, const struct xkb_mod_set *mods, + union xkb_action *action, enum action_field field, + const ExprDef *array_ndx, const ExprDef *value) { - return ReportIllegal(keymap, action->type, field); + return true; } static bool -CheckLatchLockFlags(struct xkb_keymap *keymap, unsigned action, - unsigned field, const ExprDef * value, - unsigned *flags_inout) +CheckBooleanFlag(struct xkb_context *ctx, enum xkb_action_type action, + enum action_field field, enum xkb_action_flags flag, + const ExprDef *array_ndx, const ExprDef *value, + enum xkb_action_flags *flags_inout) { - unsigned tmp; - bool result; + bool set; - if (field == F_ClearLocks) - tmp = XkbSA_ClearLocks; - else if (field == F_LatchToLock) - tmp = XkbSA_LatchToLock; - else - return false; /* WSGO! */ + if (array_ndx) + return ReportActionNotArray(ctx, action, field); - if (!ExprResolveBoolean(keymap->ctx, value, &result)) - return ReportMismatch(keymap, action, field, "boolean"); + if (!ExprResolveBoolean(ctx, value, &set)) + return ReportMismatch(ctx, XKB_ERROR_WRONG_FIELD_TYPE, + action, field, "boolean"); - if (result) - *flags_inout |= tmp; + if (set) + *flags_inout |= flag; else - *flags_inout &= ~tmp; + *flags_inout &= ~flag; return true; } static bool -CheckModifierField(struct xkb_keymap *keymap, unsigned action, - const ExprDef *value, unsigned *flags_inout, +CheckModifierField(struct xkb_context *ctx, const struct xkb_mod_set *mods, + enum xkb_action_type action, const ExprDef *array_ndx, + const ExprDef *value, enum xkb_action_flags *flags_inout, xkb_mod_mask_t *mods_rtrn) { - if (value->op == EXPR_IDENT) { + if (array_ndx) + return ReportActionNotArray(ctx, action, ACTION_FIELD_MODIFIERS); + + if (value->expr.op == EXPR_IDENT) { const char *valStr; - valStr = xkb_atom_text(keymap->ctx, value->value.str); + valStr = xkb_atom_text(ctx, value->ident.ident); if (valStr && (istreq(valStr, "usemodmapmods") || istreq(valStr, "modmapmods"))) { - *mods_rtrn = 0; - *flags_inout |= XkbSA_UseModMapMods; + *flags_inout |= ACTION_MODS_LOOKUP_MODMAP; return true; } } - if (!ExprResolveVModMask(keymap, value, mods_rtrn)) - return ReportMismatch(keymap, action, F_Modifiers, "modifier mask"); + if (!ExprResolveModMask(ctx, value, MOD_BOTH, mods, mods_rtrn)) + return ReportMismatch(ctx, XKB_ERROR_WRONG_FIELD_TYPE, action, + ACTION_FIELD_MODIFIERS, "modifier mask"); - *flags_inout &= ~XkbSA_UseModMapMods; + *flags_inout &= ~ACTION_MODS_LOOKUP_MODMAP; return true; } +static const LookupEntry lockWhich[] = { + { "both", 0 }, + { "lock", ACTION_LOCK_NO_UNLOCK }, + { "neither", (ACTION_LOCK_NO_LOCK | ACTION_LOCK_NO_UNLOCK) }, + { "unlock", ACTION_LOCK_NO_LOCK }, + { NULL, 0 } +}; + static bool -HandleSetLatchMods(struct xkb_keymap *keymap, union xkb_action *action, - unsigned field, const ExprDef *array_ndx, - const ExprDef *value) +CheckAffectField(struct xkb_context *ctx, enum xkb_action_type action, + const ExprDef *array_ndx, const ExprDef *value, + enum xkb_action_flags *flags_inout) { - struct xkb_mod_action *act = &action->mods; - unsigned rtrn; - unsigned t1; - xkb_mod_mask_t t2; - - if (array_ndx != NULL) { - switch (field) { - case F_ClearLocks: - case F_LatchToLock: - case F_Modifiers: - return ReportActionNotArray(keymap, action->type, field); - } - } - switch (field) { - case F_ClearLocks: - case F_LatchToLock: - rtrn = act->flags; - if (CheckLatchLockFlags(keymap, action->type, field, value, &rtrn)) { - act->flags = rtrn; - return true; - } - return false; + enum xkb_action_flags flags; - case F_Modifiers: - t1 = act->flags; - if (CheckModifierField(keymap, action->type, value, &t1, &t2)) { - act->flags = t1; - act->mods.mods = t2; - return true; - } - return false; - } - return ReportIllegal(keymap, action->type, field); + if (array_ndx) + return ReportActionNotArray(ctx, action, ACTION_FIELD_AFFECT); + + if (!ExprResolveEnum(ctx, value, &flags, lockWhich)) + return ReportMismatch(ctx, XKB_ERROR_WRONG_FIELD_TYPE, + action, ACTION_FIELD_AFFECT, + "lock, unlock, both, neither"); + + *flags_inout &= ~(ACTION_LOCK_NO_LOCK | ACTION_LOCK_NO_UNLOCK); + *flags_inout |= flags; + return true; } static bool -HandleLockMods(struct xkb_keymap *keymap, union xkb_action *action, - unsigned field, const ExprDef *array_ndx, const ExprDef *value) +HandleSetLatchLockMods(struct xkb_context *ctx, const struct xkb_mod_set *mods, + union xkb_action *action, enum action_field field, + const ExprDef *array_ndx, const ExprDef *value) { struct xkb_mod_action *act = &action->mods; - unsigned t1; - xkb_mod_mask_t t2; - - if ((array_ndx != NULL) && (field == F_Modifiers)) - return ReportActionNotArray(keymap, action->type, field); - switch (field) { - case F_Modifiers: - t1 = act->flags; - if (CheckModifierField(keymap, action->type, value, &t1, &t2)) { - act->flags = t1; - act->mods.mods = t2; - return true; - } - return false; - } - return ReportIllegal(keymap, action->type, field); + const enum xkb_action_type type = action->type; + + if (field == ACTION_FIELD_MODIFIERS) + return CheckModifierField(ctx, mods, action->type, array_ndx, value, + &act->flags, &act->mods.mods); + if ((type == ACTION_TYPE_MOD_SET || type == ACTION_TYPE_MOD_LATCH) && + field == ACTION_FIELD_CLEAR_LOCKS) + return CheckBooleanFlag(ctx, action->type, field, + ACTION_LOCK_CLEAR, array_ndx, value, + &act->flags); + if (type == ACTION_TYPE_MOD_LATCH && + field == ACTION_FIELD_LATCH_TO_LOCK) + return CheckBooleanFlag(ctx, action->type, field, + ACTION_LATCH_TO_LOCK, array_ndx, value, + &act->flags); + if (type == ACTION_TYPE_MOD_LOCK && + field == ACTION_FIELD_AFFECT) + return CheckAffectField(ctx, action->type, array_ndx, value, + &act->flags); + + return ReportIllegal(ctx, action->type, field); } static bool -CheckGroupField(struct xkb_keymap *keymap, unsigned action, - const ExprDef *value, unsigned *flags_inout, - xkb_group_index_t *grp_rtrn) +CheckGroupField(struct xkb_context *ctx, enum xkb_action_type action, + const ExprDef *array_ndx, const ExprDef *value, + enum xkb_action_flags *flags_inout, int32_t *group_rtrn) { const ExprDef *spec; + xkb_layout_index_t idx; + enum xkb_action_flags flags = *flags_inout; + + if (array_ndx) + return ReportActionNotArray(ctx, action, ACTION_FIELD_GROUP); - if (value->op == EXPR_NEGATE || value->op == EXPR_UNARY_PLUS) { - *flags_inout &= ~XkbSA_GroupAbsolute; - spec = value->value.child; + if (value->expr.op == EXPR_NEGATE || value->expr.op == EXPR_UNARY_PLUS) { + flags &= ~ACTION_ABSOLUTE_SWITCH; + spec = value->unary.child; } else { - *flags_inout |= XkbSA_GroupAbsolute; + flags |= ACTION_ABSOLUTE_SWITCH; spec = value; } - if (!ExprResolveGroup(keymap->ctx, spec, grp_rtrn)) - return ReportMismatch(keymap, action, F_Group, - "integer (range 1..8)"); - - if (value->op == EXPR_NEGATE) - *grp_rtrn = -*grp_rtrn; - else if (value->op != EXPR_UNARY_PLUS) - (*grp_rtrn)--; - - return true; -} + if (!ExprResolveGroup(ctx, spec, &idx)) + return ReportMismatch(ctx, XKB_ERROR_UNSUPPORTED_GROUP_INDEX, action, + ACTION_FIELD_GROUP, "integer (range 1..8)"); -static bool -HandleSetLatchGroup(struct xkb_keymap *keymap, union xkb_action *action, - unsigned field, const ExprDef *array_ndx, - const ExprDef *value) -{ - struct xkb_group_action *act = &action->group; - unsigned rtrn; - unsigned t1; - xkb_group_index_t t2; - - if (array_ndx != NULL) { - switch (field) { - case F_ClearLocks: - case F_LatchToLock: - case F_Group: - return ReportActionNotArray(keymap, action->type, field); - } + /* +n, -n are relative, n is absolute. */ + if (value->expr.op == EXPR_NEGATE || value->expr.op == EXPR_UNARY_PLUS) { + *group_rtrn = (int32_t) idx; + if (value->expr.op == EXPR_NEGATE) + *group_rtrn = -*group_rtrn; } - switch (field) { - case F_ClearLocks: - case F_LatchToLock: - rtrn = act->flags; - if (CheckLatchLockFlags(keymap, action->type, field, value, &rtrn)) { - act->flags = rtrn; - return true; - } - return false; - - case F_Group: - t1 = act->flags; - if (CheckGroupField(keymap, action->type, value, &t1, &t2)) { - act->flags = t1; - act->group = t2; - return true; - } - return false; + else { + *group_rtrn = (int32_t) (idx - 1); } - return ReportIllegal(keymap, action->type, field); + *flags_inout = flags; + return true; } static bool -HandleLockGroup(struct xkb_keymap *keymap, union xkb_action *action, - unsigned field, const ExprDef *array_ndx, - const ExprDef *value) +HandleSetLatchLockGroup(struct xkb_context *ctx, const struct xkb_mod_set *mods, + union xkb_action *action, enum action_field field, + const ExprDef *array_ndx, const ExprDef *value) { struct xkb_group_action *act = &action->group; - unsigned t1; - xkb_group_index_t t2; - - if ((array_ndx != NULL) && (field == F_Group)) - return ReportActionNotArray(keymap, action->type, field); - if (field == F_Group) { - t1 = act->flags; - if (CheckGroupField(keymap, action->type, value, &t1, &t2)) { - act->flags = t1; - act->group = t2; - return true; - } - return false; - } - return ReportIllegal(keymap, action->type, field); + const enum xkb_action_type type = action->type; + + if (field == ACTION_FIELD_GROUP) + return CheckGroupField(ctx, action->type, array_ndx, value, + &act->flags, &act->group); + if ((type == ACTION_TYPE_GROUP_SET || type == ACTION_TYPE_GROUP_LATCH) && + field == ACTION_FIELD_CLEAR_LOCKS) + return CheckBooleanFlag(ctx, action->type, field, + ACTION_LOCK_CLEAR, array_ndx, value, + &act->flags); + if (type == ACTION_TYPE_GROUP_LATCH && + field == ACTION_FIELD_LATCH_TO_LOCK) + return CheckBooleanFlag(ctx, action->type, field, + ACTION_LATCH_TO_LOCK, array_ndx, value, + &act->flags); + + return ReportIllegal(ctx, action->type, field); } static bool -HandleMovePtr(struct xkb_keymap *keymap, union xkb_action *action, - unsigned field, const ExprDef *array_ndx, const ExprDef *value) +HandleMovePtr(struct xkb_context *ctx, const struct xkb_mod_set *mods, + union xkb_action *action, enum action_field field, + const ExprDef *array_ndx, const ExprDef *value) { struct xkb_pointer_action *act = &action->ptr; - bool absolute; - if ((array_ndx != NULL) && ((field == F_X) || (field == F_Y))) - return ReportActionNotArray(keymap, action->type, field); - - if (field == F_X || field == F_Y) { + if (field == ACTION_FIELD_X || field == ACTION_FIELD_Y) { int val; + const bool absolute = (value->expr.op != EXPR_NEGATE && + value->expr.op != EXPR_UNARY_PLUS); - if (value->op == EXPR_NEGATE || value->op == EXPR_UNARY_PLUS) - absolute = false; - else - absolute = true; - - if (!ExprResolveInteger(keymap->ctx, value, &val)) - return ReportMismatch(keymap, action->type, field, "integer"); + if (array_ndx) + return ReportActionNotArray(ctx, action->type, field); + + if (!ExprResolveInteger(ctx, value, &val)) + return ReportMismatch(ctx, XKB_ERROR_WRONG_FIELD_TYPE, action->type, + field, "integer"); + + if (val < INT16_MIN || val > INT16_MAX) { + log_err(ctx, + "The %s field in the %s action must be in range %d..%d; " + "Action definition ignored\n", + fieldText(field), ActionTypeText(action->type), + INT16_MIN, INT16_MAX); + return false; + } - if (field == F_X) { + if (field == ACTION_FIELD_X) { if (absolute) - act->flags |= XkbSA_MoveAbsoluteX; - act->x = val; + act->flags |= ACTION_ABSOLUTE_X; + act->x = (int16_t) val; } else { if (absolute) - act->flags |= XkbSA_MoveAbsoluteY; - act->y = val; + act->flags |= ACTION_ABSOLUTE_Y; + act->y = (int16_t) val; } return true; } - else if (field == F_Accel) { - bool set; - - if (!ExprResolveBoolean(keymap->ctx, value, &set)) - return ReportMismatch(keymap, action->type, field, "boolean"); - - if (set) - act->flags &= ~XkbSA_NoAcceleration; - else - act->flags |= XkbSA_NoAcceleration; + else if (field == ACTION_FIELD_ACCEL) { + return CheckBooleanFlag(ctx, action->type, field, + ACTION_ACCEL, array_ndx, value, &act->flags); } - return ReportIllegal(keymap, action->type, field); + return ReportIllegal(ctx, action->type, field); } -static const LookupEntry lockWhich[] = { - { "both", 0 }, - { "lock", XkbSA_LockNoUnlock }, - { "neither", (XkbSA_LockNoLock | XkbSA_LockNoUnlock) }, - { "unlock", XkbSA_LockNoLock }, - { NULL, 0 } -}; - static bool -HandlePtrBtn(struct xkb_keymap *keymap, union xkb_action *action, - unsigned field, const ExprDef *array_ndx, const ExprDef *value) +HandlePtrBtn(struct xkb_context *ctx, const struct xkb_mod_set *mods, + union xkb_action *action, enum action_field field, + const ExprDef *array_ndx, const ExprDef *value) { struct xkb_pointer_button_action *act = &action->btn; - if (field == F_Button) { + if (field == ACTION_FIELD_BUTTON) { int btn; if (array_ndx) - return ReportActionNotArray(keymap, action->type, field); + return ReportActionNotArray(ctx, action->type, field); - if (!ExprResolveButton(keymap->ctx, value, &btn)) - return ReportMismatch(keymap, action->type, field, - "integer (range 1..5)"); + if (!ExprResolveButton(ctx, value, &btn)) + return ReportMismatch(ctx, XKB_ERROR_WRONG_FIELD_TYPE, action->type, + field, "integer (range 1..5)"); if (btn < 0 || btn > 5) { - log_err(keymap->ctx, + log_err(ctx, "Button must specify default or be in the range 1..5; " "Illegal button value %d ignored\n", btn); return false; @@ -513,589 +479,270 @@ HandlePtrBtn(struct xkb_keymap *keymap, union xkb_action *action, act->button = btn; return true; } - else if ((action->type == XkbSA_LockPtrBtn) && (field == F_Affect)) { - unsigned int val; - - if (array_ndx) - return ReportActionNotArray(keymap, action->type, field); - - if (!ExprResolveEnum(keymap->ctx, value, &val, lockWhich)) - return ReportMismatch(keymap, action->type, field, - "lock or unlock"); - - act->flags &= ~(XkbSA_LockNoLock | XkbSA_LockNoUnlock); - act->flags |= val; - return true; + else if (action->type == ACTION_TYPE_PTR_LOCK && + field == ACTION_FIELD_AFFECT) { + return CheckAffectField(ctx, action->type, array_ndx, value, + &act->flags); } - else if (field == F_Count) { - int btn; + else if (field == ACTION_FIELD_COUNT) { + int val; if (array_ndx) - return ReportActionNotArray(keymap, action->type, field); + return ReportActionNotArray(ctx, action->type, field); - /* XXX: Should this actually be ResolveButton? */ - if (!ExprResolveButton(keymap->ctx, value, &btn)) - return ReportMismatch(keymap, action->type, field, "integer"); + if (!ExprResolveInteger(ctx, value, &val)) + return ReportMismatch(ctx, XKB_ERROR_WRONG_FIELD_TYPE, action->type, + field, "integer"); - if (btn < 0 || btn > 255) { - log_err(keymap->ctx, + if (val < 0 || val > 255) { + log_err(ctx, "The count field must have a value in the range 0..255; " - "Illegal count %d ignored\n", btn); + "Illegal count %d ignored\n", val); return false; } - act->count = btn; + act->count = (uint8_t) val; return true; } - return ReportIllegal(keymap, action->type, field); + + return ReportIllegal(ctx, action->type, field); } static const LookupEntry ptrDflts[] = { - { "dfltbtn", XkbSA_AffectDfltBtn }, - { "defaultbutton", XkbSA_AffectDfltBtn }, - { "button", XkbSA_AffectDfltBtn }, + { "dfltbtn", 1 }, + { "defaultbutton", 1 }, + { "button", 1 }, { NULL, 0 } }; static bool -HandleSetPtrDflt(struct xkb_keymap *keymap, union xkb_action *action, - unsigned field, const ExprDef *array_ndx, - const ExprDef *value) +HandleSetPtrDflt(struct xkb_context *ctx, const struct xkb_mod_set *mods, + union xkb_action *action, enum action_field field, + const ExprDef *array_ndx, const ExprDef *value) { struct xkb_pointer_default_action *act = &action->dflt; - if (field == F_Affect) { + if (field == ACTION_FIELD_AFFECT) { unsigned int val; if (array_ndx) - return ReportActionNotArray(keymap, action->type, field); + return ReportActionNotArray(ctx, action->type, field); - if (!ExprResolveEnum(keymap->ctx, value, &val, ptrDflts)) - return ReportMismatch(keymap, action->type, field, - "pointer component"); - act->affect = val; + if (!ExprResolveEnum(ctx, value, &val, ptrDflts)) + return ReportMismatch(ctx, XKB_ERROR_WRONG_FIELD_TYPE, action->type, + field, "pointer component"); return true; } - else if ((field == F_Button) || (field == F_Value)) { + else if (field == ACTION_FIELD_BUTTON || field == ACTION_FIELD_VALUE) { const ExprDef *button; int btn; if (array_ndx) - return ReportActionNotArray(keymap, action->type, field); + return ReportActionNotArray(ctx, action->type, field); - if (value->op == EXPR_NEGATE || value->op == EXPR_UNARY_PLUS) { - act->flags &= ~XkbSA_DfltBtnAbsolute; - button = value->value.child; + if (value->expr.op == EXPR_NEGATE || + value->expr.op == EXPR_UNARY_PLUS) { + act->flags &= ~ACTION_ABSOLUTE_SWITCH; + button = value->unary.child; } else { - act->flags |= XkbSA_DfltBtnAbsolute; + act->flags |= ACTION_ABSOLUTE_SWITCH; button = value; } - if (!ExprResolveButton(keymap->ctx, button, &btn)) - return ReportMismatch(keymap, action->type, field, - "integer (range 1..5)"); + if (!ExprResolveButton(ctx, button, &btn)) + return ReportMismatch(ctx, XKB_ERROR_WRONG_FIELD_TYPE, action->type, + field, "integer (range 1..5)"); if (btn < 0 || btn > 5) { - log_err(keymap->ctx, + log_err(ctx, "New default button value must be in the range 1..5; " "Illegal default button value %d ignored\n", btn); return false; } if (btn == 0) { - log_err(keymap->ctx, + log_err(ctx, "Cannot set default pointer button to \"default\"; " "Illegal default button setting ignored\n"); return false; } - act->value = (value->op == EXPR_NEGATE ? -btn: btn); + act->value = (value->expr.op == EXPR_NEGATE ? -btn: btn); return true; } - return ReportIllegal(keymap, action->type, field); + return ReportIllegal(ctx, action->type, field); } -static const LookupEntry isoNames[] = { - { "mods", XkbSA_ISONoAffectMods }, - { "modifiers", XkbSA_ISONoAffectMods }, - { "group", XkbSA_ISONoAffectGroup }, - { "groups", XkbSA_ISONoAffectGroup }, - { "ptr", XkbSA_ISONoAffectPtr }, - { "pointer", XkbSA_ISONoAffectPtr }, - { "ctrls", XkbSA_ISONoAffectCtrls }, - { "controls", XkbSA_ISONoAffectCtrls }, - { "all", ~((unsigned) 0) }, - { "none", 0 }, - { NULL, 0 }, -}; - static bool -HandleISOLock(struct xkb_keymap *keymap, union xkb_action *action, - unsigned field, const ExprDef *array_ndx, const ExprDef *value) -{ - struct xkb_iso_action *act = &action->iso; - - if (field == F_Modifiers) { - unsigned flags; - xkb_mod_mask_t mods; - - if (array_ndx) - return ReportActionNotArray(keymap, action->type, field); - - flags = act->flags; - if (!CheckModifierField(keymap, action->type, value, &flags, &mods)) - return false; - - act->flags = flags & (~XkbSA_ISODfltIsGroup); - act->mods.mods = mods; - return true; - } - else if (field == F_Group) { - xkb_group_index_t group; - unsigned flags; - - if (array_ndx) - return ReportActionNotArray(keymap, action->type, field); - - flags = act->flags; - if (!CheckGroupField(keymap, action->type, value, &flags, &group)) - return false; - - act->flags = flags | XkbSA_ISODfltIsGroup; - act->group = group; - return true; - } else if (F_Affect) { - xkb_mod_mask_t mask; - - if (array_ndx) - return ReportActionNotArray(keymap, action->type, field); - - if (!ExprResolveMask(keymap->ctx, value, &mask, isoNames)) - return ReportMismatch(keymap, action->type, field, - "keyboard component"); - - act->affect = (~mask) & XkbSA_ISOAffectMask; - return true; - } - - return ReportIllegal(keymap, action->type, field); -} - -static bool -HandleSwitchScreen(struct xkb_keymap *keymap, union xkb_action *action, - unsigned field, const ExprDef *array_ndx, - const ExprDef *value) +HandleSwitchScreen(struct xkb_context *ctx, const struct xkb_mod_set *mods, + union xkb_action *action, enum action_field field, + const ExprDef *array_ndx, const ExprDef *value) { struct xkb_switch_screen_action *act = &action->screen; - if (field == F_Screen) { + if (field == ACTION_FIELD_SCREEN) { const ExprDef *scrn; int val; if (array_ndx) - return ReportActionNotArray(keymap, action->type, field); + return ReportActionNotArray(ctx, action->type, field); - if (value->op == EXPR_NEGATE || value->op == EXPR_UNARY_PLUS) { - act->flags &= ~XkbSA_SwitchAbsolute; - scrn = value->value.child; + if (value->expr.op == EXPR_NEGATE || + value->expr.op == EXPR_UNARY_PLUS) { + act->flags &= ~ACTION_ABSOLUTE_SWITCH; + scrn = value->unary.child; } else { - act->flags |= XkbSA_SwitchAbsolute; + act->flags |= ACTION_ABSOLUTE_SWITCH; scrn = value; } - if (!ExprResolveInteger(keymap->ctx, scrn, &val)) - return ReportMismatch(keymap, action->type, field, - "integer (0..255)"); + if (!ExprResolveInteger(ctx, scrn, &val)) + return ReportMismatch(ctx, XKB_ERROR_WRONG_FIELD_TYPE, action->type, + field, "integer (0..255)"); if (val < 0 || val > 255) { - log_err(keymap->ctx, + log_err(ctx, "Screen index must be in the range 1..255; " "Illegal screen value %d ignored\n", val); return false; } - act->screen = (value->op == EXPR_NEGATE ? -val : val); + act->screen = (value->expr.op == EXPR_NEGATE ? -val : val); return true; } - else if (field == F_Same) { - bool set; - - if (array_ndx) - return ReportActionNotArray(keymap, action->type, field); - - if (!ExprResolveBoolean(keymap->ctx, value, &set)) - return ReportMismatch(keymap, action->type, field, "boolean"); - - if (set) - act->flags &= ~XkbSA_SwitchApplication; - else - act->flags |= XkbSA_SwitchApplication; - - return true; + else if (field == ACTION_FIELD_SAME) { + return CheckBooleanFlag(ctx, action->type, field, + ACTION_SAME_SCREEN, array_ndx, value, + &act->flags); } - return ReportIllegal(keymap, action->type, field); + return ReportIllegal(ctx, action->type, field); } -const LookupEntry ctrlNames[] = { - { "repeatkeys", XkbRepeatKeysMask }, - { "repeat", XkbRepeatKeysMask }, - { "autorepeat", XkbRepeatKeysMask }, - { "slowkeys", XkbSlowKeysMask }, - { "bouncekeys", XkbBounceKeysMask }, - { "stickykeys", XkbStickyKeysMask }, - { "mousekeys", XkbMouseKeysMask }, - { "mousekeysaccel", XkbMouseKeysAccelMask }, - { "accessxkeys", XkbAccessXKeysMask }, - { "accessxtimeout", XkbAccessXTimeoutMask }, - { "accessxfeedback", XkbAccessXFeedbackMask }, - { "audiblebell", XkbAudibleBellMask }, - { "ignoregrouplock", XkbIgnoreGroupLockMask }, - { "all", XkbAllBooleanCtrlsMask }, - { "overlay1", 0 }, - { "overlay2", 0 }, - { "none", 0 }, - { NULL, 0 } -}; - static bool -HandleSetLockControls(struct xkb_keymap *keymap, - union xkb_action *action, - unsigned field, const ExprDef *array_ndx, - const ExprDef *value) +HandleSetLockControls(struct xkb_context *ctx, const struct xkb_mod_set *mods, + union xkb_action *action, enum action_field field, + const ExprDef *array_ndx, const ExprDef *value) { struct xkb_controls_action *act = &action->ctrls; - if (field == F_Controls) { - unsigned int mask; + if (field == ACTION_FIELD_CONTROLS) { + enum xkb_action_controls mask; if (array_ndx) - return ReportActionNotArray(keymap, action->type, field); + return ReportActionNotArray(ctx, action->type, field); - if (!ExprResolveMask(keymap->ctx, value, &mask, ctrlNames)) - return ReportMismatch(keymap, action->type, field, - "controls mask"); + if (!ExprResolveMask(ctx, value, &mask, ctrlMaskNames)) + return ReportMismatch(ctx, XKB_ERROR_WRONG_FIELD_TYPE, action->type, + field, "controls mask"); act->ctrls = mask; return true; } - - return ReportIllegal(keymap, action->type, field); -} - -static const LookupEntry evNames[] = { - { "press", XkbSA_MessageOnPress }, - { "keypress", XkbSA_MessageOnPress }, - { "release", XkbSA_MessageOnRelease }, - { "keyrelease", XkbSA_MessageOnRelease }, - { "all", XkbSA_MessageOnPress | XkbSA_MessageOnRelease }, - { "none", 0 }, - { NULL, 0 } -}; - -static bool -HandleActionMessage(struct xkb_keymap *keymap, union xkb_action *action, - unsigned field, const ExprDef *array_ndx, - const ExprDef *value) -{ - struct xkb_message_action *act = &action->msg; - - if (field == F_Report) { - unsigned int mask; - - if (array_ndx) - return ReportActionNotArray(keymap, action->type, field); - - if (!ExprResolveMask(keymap->ctx, value, &mask, evNames)) - return ReportMismatch(keymap, action->type, field, - "key event mask"); - - /* FIXME: Something seems wrong here... */ - act->flags &= ~(XkbSA_MessageOnPress | XkbSA_MessageOnRelease); - act->flags = mask & (XkbSA_MessageOnPress | XkbSA_MessageOnRelease); - return true; + else if (field == ACTION_FIELD_AFFECT) { + return CheckAffectField(ctx, action->type, array_ndx, value, + &act->flags); } - else if (field == F_GenKeyEvent) { - bool set; - - if (array_ndx) - return ReportActionNotArray(keymap, action->type, field); - if (!ExprResolveBoolean(keymap->ctx, value, &set)) - return ReportMismatch(keymap, action->type, field, "boolean"); - - if (set) - act->flags |= XkbSA_MessageGenKeyEvent; - else - act->flags &= ~XkbSA_MessageGenKeyEvent; - - return true; - } - else if (field == F_Data && !array_ndx) { - const char *str; - int len; - - if (!ExprResolveString(keymap->ctx, value, &str)) - return ReportMismatch(keymap, action->type, field, "string"); - - len = strlen(str); - if (len < 1 || len > 6) { - log_warn(keymap->ctx, - "An action message can hold only 6 bytes; " - "Extra %d bytes ignored\n", len - 6); - } - - strncpy((char *) act->message, str, 6); - return true; - } - else if (field == F_Data && array_ndx) { - int ndx, datum; - - if (!ExprResolveInteger(keymap->ctx, array_ndx, &ndx)) { - log_err(keymap->ctx, - "Array subscript must be integer; " - "Illegal subscript ignored\n"); - return false; - } - - if (ndx < 0 || ndx > 5) { - log_err(keymap->ctx, - "An action message is at most 6 bytes long; " - "Attempt to use data[%d] ignored\n", ndx); - return false; - } - - if (!ExprResolveInteger(keymap->ctx, value, &datum)) - return ReportMismatch(keymap, action->type, field, "integer"); - - if (datum < 0 || datum > 255) { - log_err(keymap->ctx, - "Message data must be in the range 0..255; " - "Illegal datum %d ignored\n", datum); - return false; - } - - act->message[ndx] = (uint8_t) datum; - return true; - } - - return ReportIllegal(keymap, action->type, field); + return ReportIllegal(ctx, action->type, field); } static bool -HandleRedirectKey(struct xkb_keymap *keymap, union xkb_action *action, - unsigned field, const ExprDef *array_ndx, - const ExprDef *value) -{ - struct xkb_key *key; - struct xkb_redirect_key_action *act = &action->redirect; - unsigned t1; - xkb_mod_mask_t t2; - unsigned long tmp; - char key_name[XkbKeyNameLength]; - - if (array_ndx != NULL) - return ReportActionNotArray(keymap, action->type, field); - - switch (field) { - case F_Keycode: - if (!ExprResolveKeyName(keymap->ctx, value, key_name)) - return ReportMismatch(keymap, action->type, field, "key name"); - - tmp = KeyNameToLong(key_name); - key = FindNamedKey(keymap, tmp, true, 0); - if (!key) - return ReportNotFound(keymap, action->type, field, "Key", - KeyNameText(key_name)); - act->new_kc = XkbKeyGetKeycode(keymap, key); - return true; - - case F_ModsToClear: - case F_Modifiers: - t1 = 0; - if (CheckModifierField(keymap, action->type, value, &t1, &t2)) { - act->mods_mask |= (t2 & 0xff); - if (field == F_Modifiers) - act->mods |= (t2 & 0xff); - else - act->mods &= ~(t2 & 0xff); - - t2 = (t2 >> XkbNumModifiers) & 0xffff; - act->vmods_mask |= t2; - if (field == F_Modifiers) - act->vmods |= t2; - else - act->vmods &= ~t2; - return true; - } - return true; - } - return ReportIllegal(keymap, action->type, field); -} - -static bool -HandleDeviceBtn(struct xkb_keymap *keymap, union xkb_action *action, - unsigned field, const ExprDef *array_ndx, - const ExprDef *value) -{ - struct xkb_device_button_action *act = &action->devbtn; - - if (field == F_Button) { - int val; - - if (array_ndx) - return ReportActionNotArray(keymap, action->type, field); - - if (!ExprResolveInteger(keymap->ctx, value, &val)) - return ReportMismatch(keymap, action->type, field, - "integer (range 1..255)"); - - if (val < 0 || val > 255) { - log_err(keymap->ctx, - "Button must specify default or be in the range 1..255; " - "Illegal button value %d ignored\n", val); - return false; - } - - act->button = val; - return true; - } - else if (action->type == XkbSA_LockDeviceBtn && field == F_Affect) { - unsigned int val; - - if (array_ndx) - return ReportActionNotArray(keymap, action->type, field); - - if (!ExprResolveEnum(keymap->ctx, value, &val, lockWhich)) - return ReportMismatch(keymap, action->type, field, - "lock or unlock"); - - act->flags &= ~(XkbSA_LockNoLock | XkbSA_LockNoUnlock); - act->flags |= val; - return true; - } - else if (field == F_Count) { - int btn; - - if (array_ndx) - return ReportActionNotArray(keymap, action->type, field); - - /* XXX: Should this actually be ResolveButton? */ - if (!ExprResolveButton(keymap->ctx, value, &btn)) - return ReportMismatch(keymap, action->type, field, "integer"); - - if (btn < 0 || btn > 255) { - log_err(keymap->ctx, - "The count field must have a value in the range 0..255; " - "Illegal count %d ignored\n", btn); - return false; - } - - act->count = btn; - return true; - } - else if (field == F_Device) { - int val; - - if (array_ndx) - return ReportActionNotArray(keymap, action->type, field); - - if (!ExprResolveInteger(keymap->ctx, value, &val)) - return ReportMismatch(keymap, action->type, field, - "integer (range 1..255)"); - - if (val < 0 || val > 255) { - log_err(keymap->ctx, - "Device must specify default or be in the range 1..255; " - "Illegal device value %d ignored\n", val); - return false; - } - - act->device = val; - return true; - } - - return ReportIllegal(keymap, action->type, field); -} - -static bool -HandleDeviceValuator(struct xkb_keymap *keymap, union xkb_action *action, - unsigned field, const ExprDef *array_ndx, - const ExprDef *value) -{ - struct xkb_device_valuator_action *act = &action->devval; - (void) act; - - /* XXX - Not yet implemented */ - return false; -} - -static bool -HandlePrivate(struct xkb_keymap *keymap, union xkb_action *action, - unsigned field, const ExprDef *array_ndx, const ExprDef *value) +HandlePrivate(struct xkb_context *ctx, const struct xkb_mod_set *mods, + union xkb_action *action, enum action_field field, + const ExprDef *array_ndx, const ExprDef *value) { struct xkb_private_action *act = &action->priv; - if (field == F_Type) { + if (field == ACTION_FIELD_TYPE) { int type; - if (!ExprResolveInteger(keymap->ctx, value, &type)) - return ReportMismatch(keymap, PrivateAction, field, "integer"); + if (array_ndx) + return ReportActionNotArray(ctx, action->type, field); + + if (!ExprResolveInteger(ctx, value, &type)) + return ReportMismatch(ctx, XKB_ERROR_WRONG_FIELD_TYPE, + ACTION_TYPE_PRIVATE, field, "integer"); if (type < 0 || type > 255) { - log_err(keymap->ctx, + log_err(ctx, "Private action type must be in the range 0..255; " "Illegal type %d ignored\n", type); return false; } - act->type = (uint8_t) type; + /* + * It's possible for someone to write something like this: + * actions = [ Private(type=3,data[0]=1,data[1]=3,data[2]=3) ] + * where the type refers to some existing action type, e.g. LockMods. + * This assumes that this action's struct is laid out in memory + * exactly as described in the XKB specification and libraries. + * We, however, have changed these structs in various ways, so this + * assumption is no longer true. Since this is a lousy "feature", we + * make actions like these no-ops for now. + */ + if (type < ACTION_TYPE_PRIVATE) { + log_info(ctx, + "Private actions of type %s are not supported; Ignored\n", + ActionTypeText(type)); + act->type = ACTION_TYPE_NONE; + } + else { + act->type = (enum xkb_action_type) type; + } + return true; } - else if (field == F_Data) { + else if (field == ACTION_FIELD_DATA) { if (array_ndx == NULL) { + xkb_atom_t val; const char *str; - int len; + size_t len; - if (!ExprResolveString(keymap->ctx, value, &str)) - return ReportMismatch(keymap, action->type, field, "string"); + if (!ExprResolveString(ctx, value, &val)) + return ReportMismatch(ctx, XKB_ERROR_WRONG_FIELD_TYPE, + action->type, field, "string"); + str = xkb_atom_text(ctx, val); len = strlen(str); - if (len < 1 || len > 7) { - log_warn(keymap->ctx, - "A private action has 7 data bytes; " - "Extra %d bytes ignored\n", len - 6); + if (len < 1 || len > sizeof(act->data)) { + log_warn(ctx, + "A private action has %ld data bytes; " + "Illegal data ignored\n", sizeof(act->data)); return false; } - strncpy((char *) act->data, str, sizeof(act->data)); + /* act->data may not be null-terminated, this is intentional */ + memset(act->data, 0, sizeof(act->data)); + memcpy(act->data, str, len); return true; } else { int ndx, datum; - if (!ExprResolveInteger(keymap->ctx, array_ndx, &ndx)) { - log_err(keymap->ctx, + if (!ExprResolveInteger(ctx, array_ndx, &ndx)) { + log_err(ctx, "Array subscript must be integer; " "Illegal subscript ignored\n"); return false; } - if (ndx < 0 || ndx >= sizeof(act->data)) { - log_err(keymap->ctx, - "The data for a private action is %zu bytes long; " + if (ndx < 0 || (size_t) ndx >= sizeof(act->data)) { + log_err(ctx, + "The data for a private action is %lu bytes long; " "Attempt to use data[%d] ignored\n", - sizeof(act->data), ndx); + (unsigned long) sizeof(act->data), ndx); return false; } - if (!ExprResolveInteger(keymap->ctx, value, &datum)) - return ReportMismatch(keymap, act->type, field, "integer"); + if (!ExprResolveInteger(ctx, value, &datum)) + return ReportMismatch(ctx, XKB_ERROR_WRONG_FIELD_TYPE, act->type, + field, "integer"); if (datum < 0 || datum > 255) { - log_err(keymap->ctx, + log_err(ctx, "All data for a private action must be 0..255; " "Illegal datum %d ignored\n", datum); return false; @@ -1106,179 +753,130 @@ HandlePrivate(struct xkb_keymap *keymap, union xkb_action *action, } } - return ReportIllegal(keymap, PrivateAction, field); + return ReportIllegal(ctx, ACTION_TYPE_NONE, field); } -typedef bool (*actionHandler)(struct xkb_keymap *keymap, - union xkb_action *action, unsigned field, - const ExprDef *array_ndx, const ExprDef *value); - -static const actionHandler handleAction[XkbSA_NumActions + 1] = { - [XkbSA_NoAction] = HandleNoAction, - [XkbSA_SetMods] = HandleSetLatchMods, - [XkbSA_LatchMods] = HandleSetLatchMods, - [XkbSA_LockMods] = HandleLockMods, - [XkbSA_SetGroup] = HandleSetLatchGroup, - [XkbSA_LatchGroup] = HandleSetLatchGroup, - [XkbSA_LockGroup] = HandleLockGroup, - [XkbSA_MovePtr] = HandleMovePtr, - [XkbSA_PtrBtn] = HandlePtrBtn, - [XkbSA_LockPtrBtn] = HandlePtrBtn, - [XkbSA_SetPtrDflt] = HandleSetPtrDflt, - [XkbSA_ISOLock] = HandleISOLock, - [XkbSA_Terminate] = HandleNoAction, - [XkbSA_SwitchScreen] = HandleSwitchScreen, - [XkbSA_SetControls] = HandleSetLockControls, - [XkbSA_LockControls] = HandleSetLockControls, - [XkbSA_ActionMessage] = HandleActionMessage, - [XkbSA_RedirectKey] = HandleRedirectKey, - [XkbSA_DeviceBtn] = HandleDeviceBtn, - [XkbSA_LockDeviceBtn] = HandleDeviceBtn, - [XkbSA_DeviceValuator] = HandleDeviceValuator, - [PrivateAction] = HandlePrivate, +typedef bool (*actionHandler)(struct xkb_context *ctx, + const struct xkb_mod_set *mods, + union xkb_action *action, + enum action_field field, + const ExprDef *array_ndx, + const ExprDef *value); + +static const actionHandler handleAction[_ACTION_TYPE_NUM_ENTRIES] = { + [ACTION_TYPE_NONE] = HandleNoAction, + [ACTION_TYPE_MOD_SET] = HandleSetLatchLockMods, + [ACTION_TYPE_MOD_LATCH] = HandleSetLatchLockMods, + [ACTION_TYPE_MOD_LOCK] = HandleSetLatchLockMods, + [ACTION_TYPE_GROUP_SET] = HandleSetLatchLockGroup, + [ACTION_TYPE_GROUP_LATCH] = HandleSetLatchLockGroup, + [ACTION_TYPE_GROUP_LOCK] = HandleSetLatchLockGroup, + [ACTION_TYPE_PTR_MOVE] = HandleMovePtr, + [ACTION_TYPE_PTR_BUTTON] = HandlePtrBtn, + [ACTION_TYPE_PTR_LOCK] = HandlePtrBtn, + [ACTION_TYPE_PTR_DEFAULT] = HandleSetPtrDflt, + [ACTION_TYPE_TERMINATE] = HandleNoAction, + [ACTION_TYPE_SWITCH_VT] = HandleSwitchScreen, + [ACTION_TYPE_CTRL_SET] = HandleSetLockControls, + [ACTION_TYPE_CTRL_LOCK] = HandleSetLockControls, + [ACTION_TYPE_PRIVATE] = HandlePrivate, }; /***====================================================================***/ -static void -ApplyActionFactoryDefaults(union xkb_action * action) -{ - if (action->type == XkbSA_SetPtrDflt) { /* increment default button */ - action->dflt.affect = XkbSA_AffectDfltBtn; - action->dflt.flags = 0; - action->dflt.value = 1; - } - else if (action->type == XkbSA_ISOLock) { - action->iso.mods.mods = (1 << ModNameToIndex(XKB_MOD_NAME_CAPS)); - } -} - -int -HandleActionDef(ExprDef * def, - struct xkb_keymap *keymap, - union xkb_action *action, ActionInfo *info) +bool +HandleActionDef(struct xkb_context *ctx, ActionsInfo *info, + const struct xkb_mod_set *mods, ExprDef *def, + union xkb_action *action) { ExprDef *arg; const char *str; - unsigned tmp, hndlrType; + enum xkb_action_type handler_type; - if (def->op != EXPR_ACTION_DECL) { - log_err(keymap->ctx, "Expected an action definition, found %s\n", - exprOpText(def->op)); - return false; - } - str = xkb_atom_text(keymap->ctx, def->value.action.name); - if (!str) { - log_wsgo(keymap->ctx, "Missing name in action definition!!\n"); + if (def->expr.op != EXPR_ACTION_DECL) { + log_err(ctx, "Expected an action definition, found %s\n", + expr_op_type_to_string(def->expr.op)); return false; } - if (!stringToAction(str, &tmp)) { - log_err(keymap->ctx, "Unknown action %s\n", str); + + str = xkb_atom_text(ctx, def->action.name); + if (!stringToAction(str, &handler_type)) { + log_err(ctx, "Unknown action %s\n", str); return false; } - action->type = hndlrType = tmp; - if (action->type != XkbSA_NoAction) { - ApplyActionFactoryDefaults((union xkb_action *) action); - while (info) - { - if ((info->action == XkbSA_NoAction) - || (info->action == hndlrType)) { - if (!(*handleAction[hndlrType])(keymap, action, - info->field, - info->array_ndx, - info->value)) { - return false; - } - } - info = info->next; - } - } - for (arg = def->value.action.args; arg != NULL; + + /* + * Get the default values for this action type, as modified by + * statements such as: + * latchMods.clearLocks = True; + */ + *action = info->actions[handler_type]; + + /* + * Now change the action properties as specified for this + * particular instance, e.g. "modifiers" and "clearLocks" in: + * SetMods(modifiers=Alt,clearLocks); + */ + for (arg = def->action.args; arg != NULL; arg = (ExprDef *) arg->common.next) { const ExprDef *value; ExprDef *field, *arrayRtrn; const char *elemRtrn, *fieldRtrn; - unsigned fieldNdx; + enum action_field fieldNdx; - if (arg->op == EXPR_ASSIGN) { - field = arg->value.binary.left; - value = arg->value.binary.right; + if (arg->expr.op == EXPR_ASSIGN) { + field = arg->binary.left; + value = arg->binary.right; + } + else if (arg->expr.op == EXPR_NOT || arg->expr.op == EXPR_INVERT) { + field = arg->unary.child; + value = (const ExprDef *) &constFalse; } else { - if (arg->op == EXPR_NOT || arg->op == EXPR_INVERT) { - field = arg->value.child; - value = &constFalse; - } - else { - field = arg; - value = &constTrue; - } + field = arg; + value = (const ExprDef *) &constTrue; } - if (!ExprResolveLhs(keymap->ctx, field, &elemRtrn, &fieldRtrn, - &arrayRtrn)) - return false; /* internal error -- already reported */ - if (elemRtrn != NULL) { - log_err(keymap->ctx, + if (!ExprResolveLhs(ctx, field, &elemRtrn, &fieldRtrn, &arrayRtrn)) + return false; + + if (elemRtrn) { + log_err(ctx, "Cannot change defaults in an action definition; " "Ignoring attempt to change %s.%s\n", elemRtrn, fieldRtrn); return false; } + if (!stringToField(fieldRtrn, &fieldNdx)) { - log_err(keymap->ctx, "Unknown field name %s\n", fieldRtrn); + log_err(ctx, "Unknown field name %s\n", fieldRtrn); return false; } - if (!handleAction[hndlrType](keymap, action, fieldNdx, arrayRtrn, - value)) + + if (!handleAction[handler_type](ctx, mods, action, fieldNdx, + arrayRtrn, value)) return false; } + return true; } -/***====================================================================***/ - -int -SetActionField(struct xkb_keymap *keymap, const char *elem, const char *field, - ExprDef *array_ndx, ExprDef *value, ActionInfo **info_rtrn) +bool +SetActionField(struct xkb_context *ctx, ActionsInfo *info, + struct xkb_mod_set *mods, const char *elem, + const char *field, ExprDef *array_ndx, ExprDef *value) { - ActionInfo *new, *old; + enum xkb_action_type action; + enum action_field action_field; - new = malloc(sizeof(*new)); - if (!new) { - log_wsgo(keymap->ctx, "Couldn't allocate space for action default\n"); + if (!stringToAction(elem, &action)) return false; - } - if (istreq(elem, "action")) - new->action = XkbSA_NoAction; - else { - if (!stringToAction(elem, &new->action)) { - free(new); - return false; - } - if (new->action == XkbSA_NoAction) { - log_err(keymap->ctx, - "\"%s\" is not a valid field in a NoAction action\n", - field); - free(new); - return false; - } - } - if (!stringToField(field, &new->field)) { - log_err(keymap->ctx, "\"%s\" is not a legal field name\n", field); - free(new); + if (!stringToField(field, &action_field)) { + log_err(ctx, "\"%s\" is not a legal field name\n", field); return false; } - new->array_ndx = array_ndx; - new->value = value; - new->next = NULL; - old = *info_rtrn; - while ((old) && (old->next)) - old = old->next; - if (old == NULL) - *info_rtrn = new; - else - old->next = new; - return true; + + return handleAction[action](ctx, mods, &info->actions[action], + action_field, array_ndx, value); }