#include "action.h"
#include "keycodes.h"
+#define PrivateAction (XkbSA_LastAction + 1)
+
static const ExprDef constTrue = {
.common = { .type = STMT_EXPR, .next = NULL },
.op = EXPR_VALUE,
.value = { .ival = 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,
+};
+
+struct _ActionInfo {
+ unsigned action;
+ enum action_field field;
+ ExprDef *array_ndx;
+ ExprDef *value;
+ struct _ActionInfo *next;
+};
+
+void
+FreeActionInfo(ActionInfo *info)
+{
+ ActionInfo *next;
+ while (info) {
+ next = info->next;
+ free(info);
+ info = next;
+ }
+}
static const LookupEntry actionStrings[] = {
{ "noaction", XkbSA_NoAction },
};
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 }
+ { "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
}
static bool
-stringToField(const char *str, unsigned *field_rtrn)
+stringToField(const char *str, enum action_field *field_rtrn)
{
return stringToValue(fieldStrings, str, field_rtrn);
}
static const char *
-fieldText(unsigned field)
+fieldText(enum action_field field)
{
return valueToString(fieldStrings, field);
}
/***====================================================================***/
static inline bool
-ReportMismatch(struct xkb_keymap *keymap, unsigned action, unsigned field,
- const char *type)
+ReportMismatch(struct xkb_keymap *keymap, unsigned action,
+ enum action_field field, const char *type)
{
log_err(keymap->ctx,
"Value of %s field must be of type %s; "
}
static inline bool
-ReportIllegal(struct xkb_keymap *keymap, unsigned action, unsigned field)
+ReportIllegal(struct xkb_keymap *keymap, unsigned action,
+ enum action_field field)
{
log_err(keymap->ctx,
"Field %s is not defined for an action of type %s; "
static inline bool
ReportActionNotArray(struct xkb_keymap *keymap, unsigned action,
- unsigned field)
+ enum action_field field)
{
log_err(keymap->ctx,
"The %s field in the %s action is not an array; "
}
static inline bool
-ReportNotFound(struct xkb_keymap *keymap, unsigned action, unsigned field,
- const char *what, const char *bad)
+ReportNotFound(struct xkb_keymap *keymap, unsigned action,
+ enum action_field field, const char *what, const char *bad)
{
log_err(keymap->ctx,
"%s named %s not found; "
static bool
HandleNoAction(struct xkb_keymap *keymap, union xkb_action *action,
- unsigned field, const ExprDef *array_ndx, const ExprDef *value)
+ enum action_field field, const ExprDef *array_ndx,
+ const ExprDef *value)
{
return ReportIllegal(keymap, action->type, field);
static bool
CheckLatchLockFlags(struct xkb_keymap *keymap, unsigned action,
- unsigned field, const ExprDef * value,
+ enum action_field field, const ExprDef * value,
unsigned *flags_inout)
{
unsigned tmp;
bool result;
- if (field == F_ClearLocks)
+ if (field == ACTION_FIELD_CLEAR_LOCKS)
tmp = XkbSA_ClearLocks;
- else if (field == F_LatchToLock)
+ else if (field == ACTION_FIELD_LATCH_TO_LOCK)
tmp = XkbSA_LatchToLock;
else
return false; /* WSGO! */
}
if (!ExprResolveVModMask(keymap, value, mods_rtrn))
- return ReportMismatch(keymap, action, F_Modifiers, "modifier mask");
+ return ReportMismatch(keymap, action,
+ ACTION_FIELD_MODIFIERS, "modifier mask");
*flags_inout &= ~XkbSA_UseModMapMods;
return true;
static bool
HandleSetLatchMods(struct xkb_keymap *keymap, union xkb_action *action,
- unsigned field, const ExprDef *array_ndx,
+ enum action_field field, const ExprDef *array_ndx,
const ExprDef *value)
{
struct xkb_mod_action *act = &action->mods;
if (array_ndx != NULL) {
switch (field) {
- case F_ClearLocks:
- case F_LatchToLock:
- case F_Modifiers:
+ case ACTION_FIELD_CLEAR_LOCKS:
+ case ACTION_FIELD_LATCH_TO_LOCK:
+ case ACTION_FIELD_MODIFIERS:
return ReportActionNotArray(keymap, action->type, field);
+ default:
+ break;
}
}
+
switch (field) {
- case F_ClearLocks:
- case F_LatchToLock:
+ case ACTION_FIELD_CLEAR_LOCKS:
+ case ACTION_FIELD_LATCH_TO_LOCK:
rtrn = act->flags;
if (CheckLatchLockFlags(keymap, action->type, field, value, &rtrn)) {
act->flags = rtrn;
}
return false;
- case F_Modifiers:
+ case ACTION_FIELD_MODIFIERS:
t1 = act->flags;
if (CheckModifierField(keymap, action->type, value, &t1, &t2)) {
act->flags = t1;
return true;
}
return false;
+
+ default:
+ break;
}
+
return ReportIllegal(keymap, action->type, field);
}
static bool
HandleLockMods(struct xkb_keymap *keymap, union xkb_action *action,
- unsigned field, const ExprDef *array_ndx, const ExprDef *value)
+ 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))
+ if (array_ndx && field == ACTION_FIELD_MODIFIERS)
return ReportActionNotArray(keymap, action->type, field);
+
switch (field) {
- case F_Modifiers:
+ case ACTION_FIELD_MODIFIERS:
t1 = act->flags;
if (CheckModifierField(keymap, action->type, value, &t1, &t2)) {
act->flags = t1;
return true;
}
return false;
+
+ default:
+ break;
}
+
return ReportIllegal(keymap, action->type, field);
}
}
if (!ExprResolveGroup(keymap->ctx, spec, grp_rtrn))
- return ReportMismatch(keymap, action, F_Group,
+ return ReportMismatch(keymap, action, ACTION_FIELD_GROUP,
"integer (range 1..8)");
if (value->op == EXPR_NEGATE)
static bool
HandleSetLatchGroup(struct xkb_keymap *keymap, union xkb_action *action,
- unsigned field, const ExprDef *array_ndx,
+ enum action_field field, const ExprDef *array_ndx,
const ExprDef *value)
{
struct xkb_group_action *act = &action->group;
if (array_ndx != NULL) {
switch (field) {
- case F_ClearLocks:
- case F_LatchToLock:
- case F_Group:
+ case ACTION_FIELD_CLEAR_LOCKS:
+ case ACTION_FIELD_LATCH_TO_LOCK:
+ case ACTION_FIELD_GROUP:
return ReportActionNotArray(keymap, action->type, field);
+
+ default:
+ break;
}
}
+
switch (field) {
- case F_ClearLocks:
- case F_LatchToLock:
+ case ACTION_FIELD_CLEAR_LOCKS:
+ case ACTION_FIELD_LATCH_TO_LOCK:
rtrn = act->flags;
if (CheckLatchLockFlags(keymap, action->type, field, value, &rtrn)) {
act->flags = rtrn;
}
return false;
- case F_Group:
+ case ACTION_FIELD_GROUP:
t1 = act->flags;
if (CheckGroupField(keymap, action->type, value, &t1, &t2)) {
act->flags = t1;
return true;
}
return false;
+
+ default:
+ break;
}
+
return ReportIllegal(keymap, action->type, field);
}
static bool
HandleLockGroup(struct xkb_keymap *keymap, union xkb_action *action,
- unsigned field, const ExprDef *array_ndx,
+ 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))
+ if ((array_ndx != NULL) && (field == ACTION_FIELD_GROUP))
return ReportActionNotArray(keymap, action->type, field);
- if (field == F_Group) {
+ if (field == ACTION_FIELD_GROUP) {
t1 = act->flags;
if (CheckGroupField(keymap, action->type, value, &t1, &t2)) {
act->flags = t1;
static bool
HandleMovePtr(struct xkb_keymap *keymap, union xkb_action *action,
- unsigned field, const ExprDef *array_ndx, const ExprDef *value)
+ 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)))
+ if (array_ndx && (field == ACTION_FIELD_X || field == ACTION_FIELD_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;
if (value->op == EXPR_NEGATE || value->op == EXPR_UNARY_PLUS)
if (!ExprResolveInteger(keymap->ctx, value, &val))
return ReportMismatch(keymap, action->type, field, "integer");
- if (field == F_X) {
+ if (field == ACTION_FIELD_X) {
if (absolute)
act->flags |= XkbSA_MoveAbsoluteX;
act->x = val;
return true;
}
- else if (field == F_Accel) {
+ else if (field == ACTION_FIELD_ACCEL) {
bool set;
if (!ExprResolveBoolean(keymap->ctx, value, &set))
static bool
HandlePtrBtn(struct xkb_keymap *keymap, union xkb_action *action,
- unsigned field, const ExprDef *array_ndx, const ExprDef *value)
+ 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)
act->button = btn;
return true;
}
- else if ((action->type == XkbSA_LockPtrBtn) && (field == F_Affect)) {
+ else if (action->type == XkbSA_LockPtrBtn &&
+ field == ACTION_FIELD_AFFECT) {
unsigned int val;
if (array_ndx)
act->flags |= val;
return true;
}
- else if (field == F_Count) {
+ else if (field == ACTION_FIELD_COUNT) {
int btn;
if (array_ndx)
static bool
HandleSetPtrDflt(struct xkb_keymap *keymap, union xkb_action *action,
- unsigned field, const ExprDef *array_ndx,
+ 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)
act->affect = val;
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;
static bool
HandleISOLock(struct xkb_keymap *keymap, union xkb_action *action,
- unsigned field, const ExprDef *array_ndx, const ExprDef *value)
+ enum action_field field, const ExprDef *array_ndx,
+ const ExprDef *value)
{
struct xkb_iso_action *act = &action->iso;
- if (field == F_Modifiers) {
+ if (field == ACTION_FIELD_MODIFIERS) {
unsigned flags;
xkb_mod_mask_t mods;
act->mods.mods = mods;
return true;
}
- else if (field == F_Group) {
+ else if (field == ACTION_FIELD_GROUP) {
xkb_group_index_t group;
unsigned flags;
act->flags = flags | XkbSA_ISODfltIsGroup;
act->group = group;
return true;
- } else if (F_Affect) {
+ } else if (ACTION_FIELD_AFFECT) {
xkb_mod_mask_t mask;
if (array_ndx)
static bool
HandleSwitchScreen(struct xkb_keymap *keymap, union xkb_action *action,
- unsigned field, const ExprDef *array_ndx,
+ 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;
act->screen = (value->op == EXPR_NEGATE ? -val : val);
return true;
}
- else if (field == F_Same) {
+ else if (field == ACTION_FIELD_SAME) {
bool set;
if (array_ndx)
};
static bool
-HandleSetLockControls(struct xkb_keymap *keymap,
- union xkb_action *action,
- unsigned field, const ExprDef *array_ndx,
+HandleSetLockControls(struct xkb_keymap *keymap, 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) {
+ if (field == ACTION_FIELD_CONTROLS) {
unsigned int mask;
if (array_ndx)
static bool
HandleActionMessage(struct xkb_keymap *keymap, union xkb_action *action,
- unsigned field, const ExprDef *array_ndx,
+ enum action_field field, const ExprDef *array_ndx,
const ExprDef *value)
{
struct xkb_message_action *act = &action->msg;
- if (field == F_Report) {
+ if (field == ACTION_FIELD_REPORT) {
unsigned int mask;
if (array_ndx)
act->flags = mask & (XkbSA_MessageOnPress | XkbSA_MessageOnRelease);
return true;
}
- else if (field == F_GenKeyEvent) {
+ else if (field == ACTION_FIELD_GEN_KEY_EVENT) {
bool set;
if (array_ndx)
return true;
}
- else if (field == F_Data && !array_ndx) {
+ else if (field == ACTION_FIELD_DATA && !array_ndx) {
const char *str;
int len;
strncpy((char *) act->message, str, 6);
return true;
}
- else if (field == F_Data && array_ndx) {
+ else if (field == ACTION_FIELD_DATA && array_ndx) {
int ndx, datum;
if (!ExprResolveInteger(keymap->ctx, array_ndx, &ndx)) {
static bool
HandleRedirectKey(struct xkb_keymap *keymap, union xkb_action *action,
- unsigned field, const ExprDef *array_ndx,
+ enum action_field field, const ExprDef *array_ndx,
const ExprDef *value)
{
struct xkb_key *key;
return ReportActionNotArray(keymap, action->type, field);
switch (field) {
- case F_Keycode:
+ case ACTION_FIELD_KEYCODE:
if (!ExprResolveKeyName(keymap->ctx, value, key_name))
return ReportMismatch(keymap, action->type, field, "key name");
act->new_kc = XkbKeyGetKeycode(keymap, key);
return true;
- case F_ModsToClear:
- case F_Modifiers:
+ case ACTION_FIELD_MODS_TO_CLEAR:
+ case ACTION_FIELD_MODIFIERS:
t1 = 0;
if (CheckModifierField(keymap, action->type, value, &t1, &t2)) {
act->mods_mask |= (t2 & 0xff);
- if (field == F_Modifiers)
+ if (field == ACTION_FIELD_MODIFIERS)
act->mods |= (t2 & 0xff);
else
act->mods &= ~(t2 & 0xff);
t2 = (t2 >> XkbNumModifiers) & 0xffff;
act->vmods_mask |= t2;
- if (field == F_Modifiers)
+ if (field == ACTION_FIELD_MODIFIERS)
act->vmods |= t2;
else
act->vmods &= ~t2;
return true;
}
return true;
+
+ default:
+ break;
}
+
return ReportIllegal(keymap, action->type, field);
}
static bool
HandleDeviceBtn(struct xkb_keymap *keymap, union xkb_action *action,
- unsigned field, const ExprDef *array_ndx,
+ enum action_field field, const ExprDef *array_ndx,
const ExprDef *value)
{
struct xkb_device_button_action *act = &action->devbtn;
- if (field == F_Button) {
+ if (field == ACTION_FIELD_BUTTON) {
int val;
if (array_ndx)
act->button = val;
return true;
}
- else if (action->type == XkbSA_LockDeviceBtn && field == F_Affect) {
+ else if (action->type == XkbSA_LockDeviceBtn &&
+ field == ACTION_FIELD_AFFECT) {
unsigned int val;
if (array_ndx)
act->flags |= val;
return true;
}
- else if (field == F_Count) {
+ else if (field == ACTION_FIELD_COUNT) {
int btn;
if (array_ndx)
act->count = btn;
return true;
}
- else if (field == F_Device) {
+ else if (field == ACTION_FIELD_DEVICE) {
int val;
if (array_ndx)
static bool
HandleDeviceValuator(struct xkb_keymap *keymap, union xkb_action *action,
- unsigned field, const ExprDef *array_ndx,
+ enum action_field field, const ExprDef *array_ndx,
const ExprDef *value)
{
struct xkb_device_valuator_action *act = &action->devval;
static bool
HandlePrivate(struct xkb_keymap *keymap, union xkb_action *action,
- unsigned field, const ExprDef *array_ndx, const ExprDef *value)
+ 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))
act->type = (uint8_t) type;
return true;
}
- else if (field == F_Data) {
+ else if (field == ACTION_FIELD_DATA) {
if (array_ndx == NULL) {
const char *str;
int len;
}
typedef bool (*actionHandler)(struct xkb_keymap *keymap,
- union xkb_action *action, unsigned field,
- const ExprDef *array_ndx, const ExprDef *value);
+ union xkb_action *action,
+ enum action_field field,
+ const ExprDef *array_ndx,
+ const ExprDef *value);
static const actionHandler handleAction[XkbSA_NumActions + 1] = {
[XkbSA_NoAction] = HandleNoAction,
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;