action: convert action field type to enum

We can also hide the ActionInfo definition inside action.c.

Signed-off-by: Ran Benita <ran234@gmail.com>
master
Ran Benita 2012-08-11 11:54:05 +03:00
parent 8f1ee62904
commit 79a2cc09cc
3 changed files with 200 additions and 155 deletions

View File

@ -30,6 +30,8 @@
#include "action.h" #include "action.h"
#include "keycodes.h" #include "keycodes.h"
#define PrivateAction (XkbSA_LastAction + 1)
static const ExprDef constTrue = { static const ExprDef constTrue = {
.common = { .type = STMT_EXPR, .next = NULL }, .common = { .type = STMT_EXPR, .next = NULL },
.op = EXPR_VALUE, .op = EXPR_VALUE,
@ -44,7 +46,50 @@ static const ExprDef constFalse = {
.value = { .ival = 0 }, .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[] = { static const LookupEntry actionStrings[] = {
{ "noaction", XkbSA_NoAction }, { "noaction", XkbSA_NoAction },
@ -92,39 +137,39 @@ static const LookupEntry actionStrings[] = {
}; };
static const LookupEntry fieldStrings[] = { static const LookupEntry fieldStrings[] = {
{ "clearLocks", F_ClearLocks }, { "clearLocks", ACTION_FIELD_CLEAR_LOCKS },
{ "latchToLock", F_LatchToLock }, { "latchToLock", ACTION_FIELD_LATCH_TO_LOCK },
{ "genKeyEvent", F_GenKeyEvent }, { "genKeyEvent", ACTION_FIELD_GEN_KEY_EVENT },
{ "generateKeyEvent", F_GenKeyEvent }, { "generateKeyEvent", ACTION_FIELD_GEN_KEY_EVENT },
{ "report", F_Report }, { "report", ACTION_FIELD_REPORT },
{ "default", F_Default }, { "default", ACTION_FIELD_DEFAULT },
{ "affect", F_Affect }, { "affect", ACTION_FIELD_AFFECT },
{ "increment", F_Increment }, { "increment", ACTION_FIELD_INCREMENT },
{ "modifiers", F_Modifiers }, { "modifiers", ACTION_FIELD_MODIFIERS },
{ "mods", F_Modifiers }, { "mods", ACTION_FIELD_MODIFIERS },
{ "group", F_Group }, { "group", ACTION_FIELD_GROUP },
{ "x", F_X }, { "x", ACTION_FIELD_X },
{ "y", F_Y }, { "y", ACTION_FIELD_Y },
{ "accel", F_Accel }, { "accel", ACTION_FIELD_ACCEL },
{ "accelerate", F_Accel }, { "accelerate", ACTION_FIELD_ACCEL },
{ "repeat", F_Accel }, { "repeat", ACTION_FIELD_ACCEL },
{ "button", F_Button }, { "button", ACTION_FIELD_BUTTON },
{ "value", F_Value }, { "value", ACTION_FIELD_VALUE },
{ "controls", F_Controls }, { "controls", ACTION_FIELD_CONTROLS },
{ "ctrls", F_Controls }, { "ctrls", ACTION_FIELD_CONTROLS },
{ "type", F_Type }, { "type", ACTION_FIELD_TYPE },
{ "count", F_Count }, { "count", ACTION_FIELD_COUNT },
{ "screen", F_Screen }, { "screen", ACTION_FIELD_SCREEN },
{ "same", F_Same }, { "same", ACTION_FIELD_SAME },
{ "sameServer", F_Same }, { "sameServer", ACTION_FIELD_SAME },
{ "data", F_Data }, { "data", ACTION_FIELD_DATA },
{ "device", F_Device }, { "device", ACTION_FIELD_DEVICE },
{ "dev", F_Device }, { "dev", ACTION_FIELD_DEVICE },
{ "key", F_Keycode }, { "key", ACTION_FIELD_KEYCODE },
{ "keycode", F_Keycode }, { "keycode", ACTION_FIELD_KEYCODE },
{ "kc", F_Keycode }, { "kc", ACTION_FIELD_KEYCODE },
{ "clearmods", F_ModsToClear }, { "clearmods", ACTION_FIELD_MODS_TO_CLEAR },
{ "clearmodifiers", F_ModsToClear }, { "clearmodifiers", ACTION_FIELD_MODS_TO_CLEAR },
{ NULL, 0 } { NULL, 0 }
}; };
@ -166,13 +211,13 @@ stringToAction(const char *str, unsigned *type_rtrn)
} }
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); return stringToValue(fieldStrings, str, field_rtrn);
} }
static const char * static const char *
fieldText(unsigned field) fieldText(enum action_field field)
{ {
return valueToString(fieldStrings, field); return valueToString(fieldStrings, field);
} }
@ -180,8 +225,8 @@ fieldText(unsigned field)
/***====================================================================***/ /***====================================================================***/
static inline bool static inline bool
ReportMismatch(struct xkb_keymap *keymap, unsigned action, unsigned field, ReportMismatch(struct xkb_keymap *keymap, unsigned action,
const char *type) enum action_field field, const char *type)
{ {
log_err(keymap->ctx, log_err(keymap->ctx,
"Value of %s field must be of type %s; " "Value of %s field must be of type %s; "
@ -191,7 +236,8 @@ ReportMismatch(struct xkb_keymap *keymap, unsigned action, unsigned field,
} }
static inline bool 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, log_err(keymap->ctx,
"Field %s is not defined for an action of type %s; " "Field %s is not defined for an action of type %s; "
@ -202,7 +248,7 @@ ReportIllegal(struct xkb_keymap *keymap, unsigned action, unsigned field)
static inline bool static inline bool
ReportActionNotArray(struct xkb_keymap *keymap, unsigned action, ReportActionNotArray(struct xkb_keymap *keymap, unsigned action,
unsigned field) enum action_field field)
{ {
log_err(keymap->ctx, log_err(keymap->ctx,
"The %s field in the %s action is not an array; " "The %s field in the %s action is not an array; "
@ -212,8 +258,8 @@ ReportActionNotArray(struct xkb_keymap *keymap, unsigned action,
} }
static inline bool static inline bool
ReportNotFound(struct xkb_keymap *keymap, unsigned action, unsigned field, ReportNotFound(struct xkb_keymap *keymap, unsigned action,
const char *what, const char *bad) enum action_field field, const char *what, const char *bad)
{ {
log_err(keymap->ctx, log_err(keymap->ctx,
"%s named %s not found; " "%s named %s not found; "
@ -224,7 +270,8 @@ ReportNotFound(struct xkb_keymap *keymap, unsigned action, unsigned field,
static bool static bool
HandleNoAction(struct xkb_keymap *keymap, union xkb_action *action, 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); return ReportIllegal(keymap, action->type, field);
@ -232,15 +279,15 @@ HandleNoAction(struct xkb_keymap *keymap, union xkb_action *action,
static bool static bool
CheckLatchLockFlags(struct xkb_keymap *keymap, unsigned action, CheckLatchLockFlags(struct xkb_keymap *keymap, unsigned action,
unsigned field, const ExprDef * value, enum action_field field, const ExprDef * value,
unsigned *flags_inout) unsigned *flags_inout)
{ {
unsigned tmp; unsigned tmp;
bool result; bool result;
if (field == F_ClearLocks) if (field == ACTION_FIELD_CLEAR_LOCKS)
tmp = XkbSA_ClearLocks; tmp = XkbSA_ClearLocks;
else if (field == F_LatchToLock) else if (field == ACTION_FIELD_LATCH_TO_LOCK)
tmp = XkbSA_LatchToLock; tmp = XkbSA_LatchToLock;
else else
return false; /* WSGO! */ return false; /* WSGO! */
@ -274,7 +321,8 @@ CheckModifierField(struct xkb_keymap *keymap, unsigned action,
} }
if (!ExprResolveVModMask(keymap, value, mods_rtrn)) 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; *flags_inout &= ~XkbSA_UseModMapMods;
return true; return true;
@ -282,7 +330,7 @@ CheckModifierField(struct xkb_keymap *keymap, unsigned action,
static bool static bool
HandleSetLatchMods(struct xkb_keymap *keymap, union xkb_action *action, 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) const ExprDef *value)
{ {
struct xkb_mod_action *act = &action->mods; struct xkb_mod_action *act = &action->mods;
@ -292,15 +340,18 @@ HandleSetLatchMods(struct xkb_keymap *keymap, union xkb_action *action,
if (array_ndx != NULL) { if (array_ndx != NULL) {
switch (field) { switch (field) {
case F_ClearLocks: case ACTION_FIELD_CLEAR_LOCKS:
case F_LatchToLock: case ACTION_FIELD_LATCH_TO_LOCK:
case F_Modifiers: case ACTION_FIELD_MODIFIERS:
return ReportActionNotArray(keymap, action->type, field); return ReportActionNotArray(keymap, action->type, field);
default:
break;
} }
} }
switch (field) { switch (field) {
case F_ClearLocks: case ACTION_FIELD_CLEAR_LOCKS:
case F_LatchToLock: case ACTION_FIELD_LATCH_TO_LOCK:
rtrn = act->flags; rtrn = act->flags;
if (CheckLatchLockFlags(keymap, action->type, field, value, &rtrn)) { if (CheckLatchLockFlags(keymap, action->type, field, value, &rtrn)) {
act->flags = rtrn; act->flags = rtrn;
@ -308,7 +359,7 @@ HandleSetLatchMods(struct xkb_keymap *keymap, union xkb_action *action,
} }
return false; return false;
case F_Modifiers: case ACTION_FIELD_MODIFIERS:
t1 = act->flags; t1 = act->flags;
if (CheckModifierField(keymap, action->type, value, &t1, &t2)) { if (CheckModifierField(keymap, action->type, value, &t1, &t2)) {
act->flags = t1; act->flags = t1;
@ -316,22 +367,28 @@ HandleSetLatchMods(struct xkb_keymap *keymap, union xkb_action *action,
return true; return true;
} }
return false; return false;
default:
break;
} }
return ReportIllegal(keymap, action->type, field); return ReportIllegal(keymap, action->type, field);
} }
static bool static bool
HandleLockMods(struct xkb_keymap *keymap, union xkb_action *action, 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; struct xkb_mod_action *act = &action->mods;
unsigned t1; unsigned t1;
xkb_mod_mask_t t2; 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); return ReportActionNotArray(keymap, action->type, field);
switch (field) { switch (field) {
case F_Modifiers: case ACTION_FIELD_MODIFIERS:
t1 = act->flags; t1 = act->flags;
if (CheckModifierField(keymap, action->type, value, &t1, &t2)) { if (CheckModifierField(keymap, action->type, value, &t1, &t2)) {
act->flags = t1; act->flags = t1;
@ -339,7 +396,11 @@ HandleLockMods(struct xkb_keymap *keymap, union xkb_action *action,
return true; return true;
} }
return false; return false;
default:
break;
} }
return ReportIllegal(keymap, action->type, field); return ReportIllegal(keymap, action->type, field);
} }
@ -360,7 +421,7 @@ CheckGroupField(struct xkb_keymap *keymap, unsigned action,
} }
if (!ExprResolveGroup(keymap->ctx, spec, grp_rtrn)) if (!ExprResolveGroup(keymap->ctx, spec, grp_rtrn))
return ReportMismatch(keymap, action, F_Group, return ReportMismatch(keymap, action, ACTION_FIELD_GROUP,
"integer (range 1..8)"); "integer (range 1..8)");
if (value->op == EXPR_NEGATE) if (value->op == EXPR_NEGATE)
@ -373,7 +434,7 @@ CheckGroupField(struct xkb_keymap *keymap, unsigned action,
static bool static bool
HandleSetLatchGroup(struct xkb_keymap *keymap, union xkb_action *action, 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) const ExprDef *value)
{ {
struct xkb_group_action *act = &action->group; struct xkb_group_action *act = &action->group;
@ -383,15 +444,19 @@ HandleSetLatchGroup(struct xkb_keymap *keymap, union xkb_action *action,
if (array_ndx != NULL) { if (array_ndx != NULL) {
switch (field) { switch (field) {
case F_ClearLocks: case ACTION_FIELD_CLEAR_LOCKS:
case F_LatchToLock: case ACTION_FIELD_LATCH_TO_LOCK:
case F_Group: case ACTION_FIELD_GROUP:
return ReportActionNotArray(keymap, action->type, field); return ReportActionNotArray(keymap, action->type, field);
default:
break;
} }
} }
switch (field) { switch (field) {
case F_ClearLocks: case ACTION_FIELD_CLEAR_LOCKS:
case F_LatchToLock: case ACTION_FIELD_LATCH_TO_LOCK:
rtrn = act->flags; rtrn = act->flags;
if (CheckLatchLockFlags(keymap, action->type, field, value, &rtrn)) { if (CheckLatchLockFlags(keymap, action->type, field, value, &rtrn)) {
act->flags = rtrn; act->flags = rtrn;
@ -399,7 +464,7 @@ HandleSetLatchGroup(struct xkb_keymap *keymap, union xkb_action *action,
} }
return false; return false;
case F_Group: case ACTION_FIELD_GROUP:
t1 = act->flags; t1 = act->flags;
if (CheckGroupField(keymap, action->type, value, &t1, &t2)) { if (CheckGroupField(keymap, action->type, value, &t1, &t2)) {
act->flags = t1; act->flags = t1;
@ -407,22 +472,26 @@ HandleSetLatchGroup(struct xkb_keymap *keymap, union xkb_action *action,
return true; return true;
} }
return false; return false;
default:
break;
} }
return ReportIllegal(keymap, action->type, field); return ReportIllegal(keymap, action->type, field);
} }
static bool static bool
HandleLockGroup(struct xkb_keymap *keymap, union xkb_action *action, 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) const ExprDef *value)
{ {
struct xkb_group_action *act = &action->group; struct xkb_group_action *act = &action->group;
unsigned t1; unsigned t1;
xkb_group_index_t t2; 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); return ReportActionNotArray(keymap, action->type, field);
if (field == F_Group) { if (field == ACTION_FIELD_GROUP) {
t1 = act->flags; t1 = act->flags;
if (CheckGroupField(keymap, action->type, value, &t1, &t2)) { if (CheckGroupField(keymap, action->type, value, &t1, &t2)) {
act->flags = t1; act->flags = t1;
@ -436,15 +505,16 @@ HandleLockGroup(struct xkb_keymap *keymap, union xkb_action *action,
static bool static bool
HandleMovePtr(struct xkb_keymap *keymap, union xkb_action *action, 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; struct xkb_pointer_action *act = &action->ptr;
bool absolute; 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); return ReportActionNotArray(keymap, action->type, field);
if (field == F_X || field == F_Y) { if (field == ACTION_FIELD_X || field == ACTION_FIELD_Y) {
int val; int val;
if (value->op == EXPR_NEGATE || value->op == EXPR_UNARY_PLUS) if (value->op == EXPR_NEGATE || value->op == EXPR_UNARY_PLUS)
@ -455,7 +525,7 @@ HandleMovePtr(struct xkb_keymap *keymap, union xkb_action *action,
if (!ExprResolveInteger(keymap->ctx, value, &val)) if (!ExprResolveInteger(keymap->ctx, value, &val))
return ReportMismatch(keymap, action->type, field, "integer"); return ReportMismatch(keymap, action->type, field, "integer");
if (field == F_X) { if (field == ACTION_FIELD_X) {
if (absolute) if (absolute)
act->flags |= XkbSA_MoveAbsoluteX; act->flags |= XkbSA_MoveAbsoluteX;
act->x = val; act->x = val;
@ -468,7 +538,7 @@ HandleMovePtr(struct xkb_keymap *keymap, union xkb_action *action,
return true; return true;
} }
else if (field == F_Accel) { else if (field == ACTION_FIELD_ACCEL) {
bool set; bool set;
if (!ExprResolveBoolean(keymap->ctx, value, &set)) if (!ExprResolveBoolean(keymap->ctx, value, &set))
@ -493,11 +563,12 @@ static const LookupEntry lockWhich[] = {
static bool static bool
HandlePtrBtn(struct xkb_keymap *keymap, union xkb_action *action, 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; struct xkb_pointer_button_action *act = &action->btn;
if (field == F_Button) { if (field == ACTION_FIELD_BUTTON) {
int btn; int btn;
if (array_ndx) if (array_ndx)
@ -517,7 +588,8 @@ HandlePtrBtn(struct xkb_keymap *keymap, union xkb_action *action,
act->button = btn; act->button = btn;
return true; return true;
} }
else if ((action->type == XkbSA_LockPtrBtn) && (field == F_Affect)) { else if (action->type == XkbSA_LockPtrBtn &&
field == ACTION_FIELD_AFFECT) {
unsigned int val; unsigned int val;
if (array_ndx) if (array_ndx)
@ -531,7 +603,7 @@ HandlePtrBtn(struct xkb_keymap *keymap, union xkb_action *action,
act->flags |= val; act->flags |= val;
return true; return true;
} }
else if (field == F_Count) { else if (field == ACTION_FIELD_COUNT) {
int btn; int btn;
if (array_ndx) if (array_ndx)
@ -563,12 +635,12 @@ static const LookupEntry ptrDflts[] = {
static bool static bool
HandleSetPtrDflt(struct xkb_keymap *keymap, union xkb_action *action, 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) const ExprDef *value)
{ {
struct xkb_pointer_default_action *act = &action->dflt; struct xkb_pointer_default_action *act = &action->dflt;
if (field == F_Affect) { if (field == ACTION_FIELD_AFFECT) {
unsigned int val; unsigned int val;
if (array_ndx) if (array_ndx)
@ -580,7 +652,7 @@ HandleSetPtrDflt(struct xkb_keymap *keymap, union xkb_action *action,
act->affect = val; act->affect = val;
return true; return true;
} }
else if ((field == F_Button) || (field == F_Value)) { else if (field == ACTION_FIELD_BUTTON || field == ACTION_FIELD_VALUE) {
const ExprDef *button; const ExprDef *button;
int btn; int btn;
@ -636,11 +708,12 @@ static const LookupEntry isoNames[] = {
static bool static bool
HandleISOLock(struct xkb_keymap *keymap, union xkb_action *action, 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; struct xkb_iso_action *act = &action->iso;
if (field == F_Modifiers) { if (field == ACTION_FIELD_MODIFIERS) {
unsigned flags; unsigned flags;
xkb_mod_mask_t mods; xkb_mod_mask_t mods;
@ -655,7 +728,7 @@ HandleISOLock(struct xkb_keymap *keymap, union xkb_action *action,
act->mods.mods = mods; act->mods.mods = mods;
return true; return true;
} }
else if (field == F_Group) { else if (field == ACTION_FIELD_GROUP) {
xkb_group_index_t group; xkb_group_index_t group;
unsigned flags; unsigned flags;
@ -669,7 +742,7 @@ HandleISOLock(struct xkb_keymap *keymap, union xkb_action *action,
act->flags = flags | XkbSA_ISODfltIsGroup; act->flags = flags | XkbSA_ISODfltIsGroup;
act->group = group; act->group = group;
return true; return true;
} else if (F_Affect) { } else if (ACTION_FIELD_AFFECT) {
xkb_mod_mask_t mask; xkb_mod_mask_t mask;
if (array_ndx) if (array_ndx)
@ -688,12 +761,12 @@ HandleISOLock(struct xkb_keymap *keymap, union xkb_action *action,
static bool static bool
HandleSwitchScreen(struct xkb_keymap *keymap, union xkb_action *action, 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) const ExprDef *value)
{ {
struct xkb_switch_screen_action *act = &action->screen; struct xkb_switch_screen_action *act = &action->screen;
if (field == F_Screen) { if (field == ACTION_FIELD_SCREEN) {
const ExprDef *scrn; const ExprDef *scrn;
int val; int val;
@ -723,7 +796,7 @@ HandleSwitchScreen(struct xkb_keymap *keymap, union xkb_action *action,
act->screen = (value->op == EXPR_NEGATE ? -val : val); act->screen = (value->op == EXPR_NEGATE ? -val : val);
return true; return true;
} }
else if (field == F_Same) { else if (field == ACTION_FIELD_SAME) {
bool set; bool set;
if (array_ndx) if (array_ndx)
@ -765,14 +838,13 @@ const LookupEntry ctrlNames[] = {
}; };
static bool static bool
HandleSetLockControls(struct xkb_keymap *keymap, HandleSetLockControls(struct xkb_keymap *keymap, union xkb_action *action,
union xkb_action *action, enum action_field field, const ExprDef *array_ndx,
unsigned field, const ExprDef *array_ndx,
const ExprDef *value) const ExprDef *value)
{ {
struct xkb_controls_action *act = &action->ctrls; struct xkb_controls_action *act = &action->ctrls;
if (field == F_Controls) { if (field == ACTION_FIELD_CONTROLS) {
unsigned int mask; unsigned int mask;
if (array_ndx) if (array_ndx)
@ -801,12 +873,12 @@ static const LookupEntry evNames[] = {
static bool static bool
HandleActionMessage(struct xkb_keymap *keymap, union xkb_action *action, 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) const ExprDef *value)
{ {
struct xkb_message_action *act = &action->msg; struct xkb_message_action *act = &action->msg;
if (field == F_Report) { if (field == ACTION_FIELD_REPORT) {
unsigned int mask; unsigned int mask;
if (array_ndx) if (array_ndx)
@ -821,7 +893,7 @@ HandleActionMessage(struct xkb_keymap *keymap, union xkb_action *action,
act->flags = mask & (XkbSA_MessageOnPress | XkbSA_MessageOnRelease); act->flags = mask & (XkbSA_MessageOnPress | XkbSA_MessageOnRelease);
return true; return true;
} }
else if (field == F_GenKeyEvent) { else if (field == ACTION_FIELD_GEN_KEY_EVENT) {
bool set; bool set;
if (array_ndx) if (array_ndx)
@ -837,7 +909,7 @@ HandleActionMessage(struct xkb_keymap *keymap, union xkb_action *action,
return true; return true;
} }
else if (field == F_Data && !array_ndx) { else if (field == ACTION_FIELD_DATA && !array_ndx) {
const char *str; const char *str;
int len; int len;
@ -854,7 +926,7 @@ HandleActionMessage(struct xkb_keymap *keymap, union xkb_action *action,
strncpy((char *) act->message, str, 6); strncpy((char *) act->message, str, 6);
return true; return true;
} }
else if (field == F_Data && array_ndx) { else if (field == ACTION_FIELD_DATA && array_ndx) {
int ndx, datum; int ndx, datum;
if (!ExprResolveInteger(keymap->ctx, array_ndx, &ndx)) { if (!ExprResolveInteger(keymap->ctx, array_ndx, &ndx)) {
@ -890,7 +962,7 @@ HandleActionMessage(struct xkb_keymap *keymap, union xkb_action *action,
static bool static bool
HandleRedirectKey(struct xkb_keymap *keymap, union xkb_action *action, 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) const ExprDef *value)
{ {
struct xkb_key *key; struct xkb_key *key;
@ -904,7 +976,7 @@ HandleRedirectKey(struct xkb_keymap *keymap, union xkb_action *action,
return ReportActionNotArray(keymap, action->type, field); return ReportActionNotArray(keymap, action->type, field);
switch (field) { switch (field) {
case F_Keycode: case ACTION_FIELD_KEYCODE:
if (!ExprResolveKeyName(keymap->ctx, value, key_name)) if (!ExprResolveKeyName(keymap->ctx, value, key_name))
return ReportMismatch(keymap, action->type, field, "key name"); return ReportMismatch(keymap, action->type, field, "key name");
@ -916,37 +988,41 @@ HandleRedirectKey(struct xkb_keymap *keymap, union xkb_action *action,
act->new_kc = XkbKeyGetKeycode(keymap, key); act->new_kc = XkbKeyGetKeycode(keymap, key);
return true; return true;
case F_ModsToClear: case ACTION_FIELD_MODS_TO_CLEAR:
case F_Modifiers: case ACTION_FIELD_MODIFIERS:
t1 = 0; t1 = 0;
if (CheckModifierField(keymap, action->type, value, &t1, &t2)) { if (CheckModifierField(keymap, action->type, value, &t1, &t2)) {
act->mods_mask |= (t2 & 0xff); act->mods_mask |= (t2 & 0xff);
if (field == F_Modifiers) if (field == ACTION_FIELD_MODIFIERS)
act->mods |= (t2 & 0xff); act->mods |= (t2 & 0xff);
else else
act->mods &= ~(t2 & 0xff); act->mods &= ~(t2 & 0xff);
t2 = (t2 >> XkbNumModifiers) & 0xffff; t2 = (t2 >> XkbNumModifiers) & 0xffff;
act->vmods_mask |= t2; act->vmods_mask |= t2;
if (field == F_Modifiers) if (field == ACTION_FIELD_MODIFIERS)
act->vmods |= t2; act->vmods |= t2;
else else
act->vmods &= ~t2; act->vmods &= ~t2;
return true; return true;
} }
return true; return true;
default:
break;
} }
return ReportIllegal(keymap, action->type, field); return ReportIllegal(keymap, action->type, field);
} }
static bool static bool
HandleDeviceBtn(struct xkb_keymap *keymap, union xkb_action *action, 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) const ExprDef *value)
{ {
struct xkb_device_button_action *act = &action->devbtn; struct xkb_device_button_action *act = &action->devbtn;
if (field == F_Button) { if (field == ACTION_FIELD_BUTTON) {
int val; int val;
if (array_ndx) if (array_ndx)
@ -966,7 +1042,8 @@ HandleDeviceBtn(struct xkb_keymap *keymap, union xkb_action *action,
act->button = val; act->button = val;
return true; return true;
} }
else if (action->type == XkbSA_LockDeviceBtn && field == F_Affect) { else if (action->type == XkbSA_LockDeviceBtn &&
field == ACTION_FIELD_AFFECT) {
unsigned int val; unsigned int val;
if (array_ndx) if (array_ndx)
@ -980,7 +1057,7 @@ HandleDeviceBtn(struct xkb_keymap *keymap, union xkb_action *action,
act->flags |= val; act->flags |= val;
return true; return true;
} }
else if (field == F_Count) { else if (field == ACTION_FIELD_COUNT) {
int btn; int btn;
if (array_ndx) if (array_ndx)
@ -1000,7 +1077,7 @@ HandleDeviceBtn(struct xkb_keymap *keymap, union xkb_action *action,
act->count = btn; act->count = btn;
return true; return true;
} }
else if (field == F_Device) { else if (field == ACTION_FIELD_DEVICE) {
int val; int val;
if (array_ndx) if (array_ndx)
@ -1026,7 +1103,7 @@ HandleDeviceBtn(struct xkb_keymap *keymap, union xkb_action *action,
static bool static bool
HandleDeviceValuator(struct xkb_keymap *keymap, union xkb_action *action, 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) const ExprDef *value)
{ {
struct xkb_device_valuator_action *act = &action->devval; struct xkb_device_valuator_action *act = &action->devval;
@ -1038,11 +1115,12 @@ HandleDeviceValuator(struct xkb_keymap *keymap, union xkb_action *action,
static bool static bool
HandlePrivate(struct xkb_keymap *keymap, union xkb_action *action, 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; struct xkb_private_action *act = &action->priv;
if (field == F_Type) { if (field == ACTION_FIELD_TYPE) {
int type; int type;
if (!ExprResolveInteger(keymap->ctx, value, &type)) if (!ExprResolveInteger(keymap->ctx, value, &type))
@ -1058,7 +1136,7 @@ HandlePrivate(struct xkb_keymap *keymap, union xkb_action *action,
act->type = (uint8_t) type; act->type = (uint8_t) type;
return true; return true;
} }
else if (field == F_Data) { else if (field == ACTION_FIELD_DATA) {
if (array_ndx == NULL) { if (array_ndx == NULL) {
const char *str; const char *str;
int len; int len;
@ -1114,8 +1192,10 @@ HandlePrivate(struct xkb_keymap *keymap, union xkb_action *action,
} }
typedef bool (*actionHandler)(struct xkb_keymap *keymap, typedef bool (*actionHandler)(struct xkb_keymap *keymap,
union xkb_action *action, unsigned field, union xkb_action *action,
const ExprDef *array_ndx, const ExprDef *value); enum action_field field,
const ExprDef *array_ndx,
const ExprDef *value);
static const actionHandler handleAction[XkbSA_NumActions + 1] = { static const actionHandler handleAction[XkbSA_NumActions + 1] = {
[XkbSA_NoAction] = HandleNoAction, [XkbSA_NoAction] = HandleNoAction,
@ -1202,7 +1282,7 @@ HandleActionDef(ExprDef * def,
const ExprDef *value; const ExprDef *value;
ExprDef *field, *arrayRtrn; ExprDef *field, *arrayRtrn;
const char *elemRtrn, *fieldRtrn; const char *elemRtrn, *fieldRtrn;
unsigned fieldNdx; enum action_field fieldNdx;
if (arg->op == EXPR_ASSIGN) { if (arg->op == EXPR_ASSIGN) {
field = arg->value.binary.left; field = arg->value.binary.left;

View File

@ -27,41 +27,10 @@
#ifndef XKBCOMP_ACTION_H #ifndef XKBCOMP_ACTION_H
#define XKBCOMP_ACTION_H #define XKBCOMP_ACTION_H
#define F_ClearLocks 0 typedef struct _ActionInfo ActionInfo;
#define F_LatchToLock 1
#define F_GenKeyEvent 2
#define F_Report 3
#define F_Default 4
#define F_Affect 5
#define F_Increment 6
#define F_Modifiers 7
#define F_Group 8
#define F_X 9
#define F_Y 10
#define F_Accel 11
#define F_Button 12
#define F_Value 13
#define F_Controls 14
#define F_Type 15
#define F_Count 16
#define F_Screen 17
#define F_Same 18
#define F_Data 19
#define F_Device 20
#define F_Keycode 21
#define F_ModsToClear 22
#define F_LastField F_ModsToClear
#define F_NumFields (F_LastField + 1)
#define PrivateAction (XkbSA_LastAction + 1) void
FreeActionInfo(ActionInfo *info);
typedef struct _ActionInfo {
unsigned action;
unsigned field;
ExprDef *array_ndx;
ExprDef *value;
struct _ActionInfo *next;
} ActionInfo;
int int
HandleActionDef(ExprDef *def, struct xkb_keymap *keymap, HandleActionDef(ExprDef *def, struct xkb_keymap *keymap,

View File

@ -187,7 +187,6 @@ InitCompatInfo(CompatInfo *info, struct xkb_keymap *keymap, unsigned file_id)
static void static void
ClearCompatInfo(CompatInfo *info) ClearCompatInfo(CompatInfo *info)
{ {
ActionInfo *next_act;
SymInterpInfo *si, *next_si; SymInterpInfo *si, *next_si;
LEDInfo *led, *next_led; LEDInfo *led, *next_led;
struct xkb_keymap *keymap = info->keymap; struct xkb_keymap *keymap = info->keymap;
@ -208,11 +207,8 @@ ClearCompatInfo(CompatInfo *info)
XkbNumKbdGroups * sizeof(GroupCompatInfo)); XkbNumKbdGroups * sizeof(GroupCompatInfo));
list_foreach_safe(led, next_led, &info->leds, entry) list_foreach_safe(led, next_led, &info->leds, entry)
free(led); free(led);
while (info->act) { FreeActionInfo(info->act);
next_act = info->act->next; info->act = NULL;
free(info->act);
info->act = next_act;
}
info->keymap = NULL; info->keymap = NULL;
ClearVModInfo(&info->vmods, keymap); ClearVModInfo(&info->vmods, keymap);
} }