action: add a common CheckBooleanFlag function
Signed-off-by: Ran Benita <ran234@gmail.com>master
parent
18191702ae
commit
af75353a88
|
@ -230,30 +230,23 @@ HandleNoAction(struct xkb_keymap *keymap, union xkb_action *action,
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
CheckLatchLockFlags(struct xkb_context *ctx, enum xkb_action_type action,
|
CheckBooleanFlag(struct xkb_context *ctx, enum xkb_action_type action,
|
||||||
enum action_field field, const ExprDef *array_ndx,
|
enum action_field field, enum xkb_action_flags flag,
|
||||||
const ExprDef *value, enum xkb_action_flags *flags_inout)
|
const ExprDef *array_ndx, const ExprDef *value,
|
||||||
|
enum xkb_action_flags *flags_inout)
|
||||||
{
|
{
|
||||||
enum xkb_action_flags tmp;
|
bool set;
|
||||||
bool result;
|
|
||||||
|
|
||||||
if (array_ndx)
|
if (array_ndx)
|
||||||
return ReportActionNotArray(ctx, action, field);
|
return ReportActionNotArray(ctx, action, field);
|
||||||
|
|
||||||
if (field == ACTION_FIELD_CLEAR_LOCKS)
|
if (!ExprResolveBoolean(ctx, value, &set))
|
||||||
tmp = ACTION_LOCK_CLEAR;
|
|
||||||
else if (field == ACTION_FIELD_LATCH_TO_LOCK)
|
|
||||||
tmp = ACTION_LATCH_TO_LOCK;
|
|
||||||
else
|
|
||||||
return false; /* WSGO! */
|
|
||||||
|
|
||||||
if (!ExprResolveBoolean(ctx, value, &result))
|
|
||||||
return ReportMismatch(ctx, action, field, "boolean");
|
return ReportMismatch(ctx, action, field, "boolean");
|
||||||
|
|
||||||
if (result)
|
if (set)
|
||||||
*flags_inout |= tmp;
|
*flags_inout |= flag;
|
||||||
else
|
else
|
||||||
*flags_inout &= ~tmp;
|
*flags_inout &= ~flag;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -292,11 +285,15 @@ HandleSetLatchMods(struct xkb_keymap *keymap, union xkb_action *action,
|
||||||
{
|
{
|
||||||
struct xkb_mod_action *act = &action->mods;
|
struct xkb_mod_action *act = &action->mods;
|
||||||
|
|
||||||
if (field == ACTION_FIELD_CLEAR_LOCKS ||
|
if (field == ACTION_FIELD_CLEAR_LOCKS)
|
||||||
field == ACTION_FIELD_LATCH_TO_LOCK)
|
return CheckBooleanFlag(keymap->ctx, action->type, field,
|
||||||
return CheckLatchLockFlags(keymap->ctx, action->type, field, array_ndx,
|
ACTION_LOCK_CLEAR, array_ndx, value,
|
||||||
value, &act->flags);
|
&act->flags);
|
||||||
else if (field == ACTION_FIELD_MODIFIERS)
|
if (field == ACTION_FIELD_LATCH_TO_LOCK)
|
||||||
|
return CheckBooleanFlag(keymap->ctx, action->type, field,
|
||||||
|
ACTION_LATCH_TO_LOCK, array_ndx, value,
|
||||||
|
&act->flags);
|
||||||
|
if (field == ACTION_FIELD_MODIFIERS)
|
||||||
return CheckModifierField(keymap, action->type, array_ndx, value,
|
return CheckModifierField(keymap, action->type, array_ndx, value,
|
||||||
&act->flags, &act->mods.mods);
|
&act->flags, &act->mods.mods);
|
||||||
|
|
||||||
|
@ -392,11 +389,15 @@ HandleSetLatchGroup(struct xkb_keymap *keymap, union xkb_action *action,
|
||||||
{
|
{
|
||||||
struct xkb_group_action *act = &action->group;
|
struct xkb_group_action *act = &action->group;
|
||||||
|
|
||||||
if (field == ACTION_FIELD_CLEAR_LOCKS ||
|
if (field == ACTION_FIELD_CLEAR_LOCKS)
|
||||||
field == ACTION_FIELD_LATCH_TO_LOCK)
|
return CheckBooleanFlag(keymap->ctx, action->type, field,
|
||||||
return CheckLatchLockFlags(keymap->ctx, action->type, field, array_ndx,
|
ACTION_LOCK_CLEAR, array_ndx, value,
|
||||||
value, &act->flags);
|
&act->flags);
|
||||||
else if (field == ACTION_FIELD_GROUP)
|
if (field == ACTION_FIELD_LATCH_TO_LOCK)
|
||||||
|
return CheckBooleanFlag(keymap->ctx, action->type, field,
|
||||||
|
ACTION_LATCH_TO_LOCK, array_ndx, value,
|
||||||
|
&act->flags);
|
||||||
|
if (field == ACTION_FIELD_GROUP)
|
||||||
return CheckGroupField(keymap->ctx, action->type, array_ndx, value,
|
return CheckGroupField(keymap->ctx, action->type, array_ndx, value,
|
||||||
&act->flags, &act->group);
|
&act->flags, &act->group);
|
||||||
|
|
||||||
|
@ -458,18 +459,8 @@ HandleMovePtr(struct xkb_keymap *keymap, union xkb_action *action,
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else if (field == ACTION_FIELD_ACCEL) {
|
else if (field == ACTION_FIELD_ACCEL) {
|
||||||
bool set;
|
return CheckBooleanFlag(keymap->ctx, action->type, field,
|
||||||
|
ACTION_ACCEL, array_ndx, value, &act->flags);
|
||||||
if (array_ndx)
|
|
||||||
return ReportActionNotArray(keymap->ctx, action->type, field);
|
|
||||||
|
|
||||||
if (!ExprResolveBoolean(keymap->ctx, value, &set))
|
|
||||||
return ReportMismatch(keymap->ctx, action->type, field, "boolean");
|
|
||||||
|
|
||||||
if (set)
|
|
||||||
act->flags |= ACTION_ACCEL;
|
|
||||||
else
|
|
||||||
act->flags &= ~ACTION_ACCEL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ReportIllegal(keymap->ctx, action->type, field);
|
return ReportIllegal(keymap->ctx, action->type, field);
|
||||||
|
@ -635,20 +626,9 @@ HandleSwitchScreen(struct xkb_keymap *keymap, union xkb_action *action,
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else if (field == ACTION_FIELD_SAME) {
|
else if (field == ACTION_FIELD_SAME) {
|
||||||
bool set;
|
return CheckBooleanFlag(keymap->ctx, action->type, field,
|
||||||
|
ACTION_SAME_SCREEN, array_ndx, value,
|
||||||
if (array_ndx)
|
&act->flags);
|
||||||
return ReportActionNotArray(keymap->ctx, action->type, field);
|
|
||||||
|
|
||||||
if (!ExprResolveBoolean(keymap->ctx, value, &set))
|
|
||||||
return ReportMismatch(keymap->ctx, action->type, field, "boolean");
|
|
||||||
|
|
||||||
if (set)
|
|
||||||
act->flags |= ACTION_SAME_SCREEN;
|
|
||||||
else
|
|
||||||
act->flags &= ~ACTION_SAME_SCREEN;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ReportIllegal(keymap->ctx, action->type, field);
|
return ReportIllegal(keymap->ctx, action->type, field);
|
||||||
|
|
Loading…
Reference in New Issue