static bool HandleSetPtrDflt(struct xkb_keymap *keymap, 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 == ACTION_FIELD_AFFECT) { unsigned int val; if (array_ndx) return ReportActionNotArray(keymap, action->type, field); if (!ExprResolveEnum(keymap->ctx, value, &val, ptrDflts)) return ReportMismatch(keymap, action->type, field, "pointer component"); return true; } else if (field == ACTION_FIELD_BUTTON || field == ACTION_FIELD_VALUE) { const ExprDef *button; int btn; if (array_ndx) return ReportActionNotArray(keymap, action->type, field); if (value->expr.op == EXPR_NEGATE || value->expr.op == EXPR_UNARY_PLUS) { act->flags &= ~ACTION_ABSOLUTE_SWITCH; button = value->unary.child; } else { act->flags |= ACTION_ABSOLUTE_SWITCH; button = value; } if (!ExprResolveButton(keymap->ctx, button, &btn)) return ReportMismatch(keymap, action->type, field, "integer (range 1..5)"); if (btn < 0 || btn > 5) { log_err(keymap->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, "Cannot set default pointer button to \"default\"; " "Illegal default button setting ignored\n"); return false; } act->value = (value->expr.op == EXPR_NEGATE ? -btn: btn); return true; } return ReportIllegal(keymap, action->type, field); }
static bool HandleSwitchScreen(struct xkb_keymap *keymap, 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 == ACTION_FIELD_SCREEN) { const ExprDef *scrn; int val; if (array_ndx) return ReportActionNotArray(keymap, action->type, field); if (value->expr.op == EXPR_NEGATE || value->expr.op == EXPR_UNARY_PLUS) { act->flags &= ~ACTION_ABSOLUTE_SWITCH; scrn = value->unary.child; } else { act->flags |= ACTION_ABSOLUTE_SWITCH; scrn = value; } if (!ExprResolveInteger(keymap->ctx, scrn, &val)) return ReportMismatch(keymap, action->type, field, "integer (0..255)"); if (val < 0 || val > 255) { log_err(keymap->ctx, "Screen index must be in the range 1..255; " "Illegal screen value %d ignored\n", val); return false; } act->screen = (value->expr.op == EXPR_NEGATE ? -val : val); return true; } else if (field == ACTION_FIELD_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 &= ~ACTION_SAME_SCREEN; else act->flags |= ACTION_SAME_SCREEN; return true; } return ReportIllegal(keymap, action->type, field); }
static bool 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 == ACTION_FIELD_BUTTON) { int btn; if (array_ndx) return ReportActionNotArray(ctx, action->type, field); if (!ExprResolveButton(ctx, value, &btn)) return ReportMismatch(ctx, action->type, field, "integer (range 1..5)"); if (btn < 0 || btn > 5) { log_err(ctx, "Button must specify default or be in the range 1..5; " "Illegal button value %d ignored\n", btn); return false; } act->button = btn; 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 == ACTION_FIELD_COUNT) { int val; if (array_ndx) return ReportActionNotArray(ctx, action->type, field); if (!ExprResolveInteger(ctx, value, &val)) return ReportMismatch(ctx, action->type, field, "integer"); 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", val); return false; } act->count = (uint8_t) val; return true; } return ReportIllegal(ctx, action->type, field); }
static bool HandleMovePtr(struct xkb_keymap *keymap, 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 && (field == ACTION_FIELD_X || field == ACTION_FIELD_Y)) return ReportActionNotArray(keymap, action->type, field); if (field == ACTION_FIELD_X || field == ACTION_FIELD_Y) { int val; if (value->expr.op == EXPR_NEGATE || value->expr.op == EXPR_UNARY_PLUS) absolute = false; else absolute = true; if (!ExprResolveInteger(keymap->ctx, value, &val)) return ReportMismatch(keymap, action->type, field, "integer"); if (field == ACTION_FIELD_X) { if (absolute) act->flags |= ACTION_ABSOLUTE_X; act->x = val; } else { if (absolute) act->flags |= ACTION_ABSOLUTE_Y; act->y = val; } return true; } else if (field == ACTION_FIELD_ACCEL) { bool set; if (!ExprResolveBoolean(keymap->ctx, value, &set)) return ReportMismatch(keymap, action->type, field, "boolean"); if (set) act->flags &= ~ACTION_NO_ACCEL; else act->flags |= ACTION_NO_ACCEL; } return ReportIllegal(keymap, action->type, field); }
static bool CheckGroupField(struct xkb_keymap *keymap, unsigned action, const ExprDef *value, enum xkb_action_flags *flags_inout, xkb_layout_index_t *grp_rtrn) { const ExprDef *spec; if (value->expr.op == EXPR_NEGATE || value->expr.op == EXPR_UNARY_PLUS) { *flags_inout &= ~ACTION_ABSOLUTE_SWITCH; spec = value->unary.child; } else { *flags_inout |= ACTION_ABSOLUTE_SWITCH; spec = value; } if (!ExprResolveGroup(keymap->ctx, spec, grp_rtrn)) return ReportMismatch(keymap, action, ACTION_FIELD_GROUP, "integer (range 1..8)"); if (value->expr.op == EXPR_NEGATE) *grp_rtrn = -*grp_rtrn; else if (value->expr.op != EXPR_UNARY_PLUS) (*grp_rtrn)--; return true; }
static bool CheckLatchLockFlags(struct xkb_keymap *keymap, enum xkb_action_type action, enum action_field field, const ExprDef *value, enum xkb_action_flags *flags_inout) { enum xkb_action_flags tmp; bool result; if (field == ACTION_FIELD_CLEAR_LOCKS) tmp = ACTION_LOCK_CLEAR; else if (field == ACTION_FIELD_LATCH_TO_LOCK) tmp = ACTION_LATCH_TO_LOCK; else return false; /* WSGO! */ if (!ExprResolveBoolean(keymap->ctx, value, &result)) return ReportMismatch(keymap, action, field, "boolean"); if (result) *flags_inout |= tmp; else *flags_inout &= ~tmp; return true; }
static bool 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 == ACTION_FIELD_CONTROLS) { enum xkb_action_controls mask; if (array_ndx) return ReportActionNotArray(ctx, action->type, field); if (!ExprResolveMask(ctx, value, &mask, ctrlMaskNames)) return ReportMismatch(ctx, action->type, field, "controls mask"); act->ctrls = mask; return true; } else if (field == ACTION_FIELD_AFFECT) { return CheckAffectField(ctx, action->type, array_ndx, value, &act->flags); } return ReportIllegal(ctx, action->type, field); }
static bool 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 (array_ndx) return ReportActionNotArray(ctx, action, ACTION_FIELD_MODIFIERS); if (value->expr.op == EXPR_IDENT) { const char *valStr; valStr = xkb_atom_text(ctx, value->ident.ident); if (valStr && (istreq(valStr, "usemodmapmods") || istreq(valStr, "modmapmods"))) { *mods_rtrn = 0; *flags_inout |= ACTION_MODS_LOOKUP_MODMAP; return true; } } if (!ExprResolveModMask(ctx, value, MOD_BOTH, mods, mods_rtrn)) return ReportMismatch(ctx, action, ACTION_FIELD_MODIFIERS, "modifier mask"); *flags_inout &= ~ACTION_MODS_LOOKUP_MODMAP; return true; }
static bool 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; 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 (array_ndx) return ReportActionNotArray(ctx, action->type, field); if (!ExprResolveInteger(ctx, value, &val)) return ReportMismatch(ctx, 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 == ACTION_FIELD_X) { if (absolute) act->flags |= ACTION_ABSOLUTE_X; act->x = (int16_t) val; } else { if (absolute) act->flags |= ACTION_ABSOLUTE_Y; act->y = (int16_t) val; } return true; } else if (field == ACTION_FIELD_ACCEL) { return CheckBooleanFlag(ctx, action->type, field, ACTION_ACCEL, array_ndx, value, &act->flags); } return ReportIllegal(ctx, action->type, field); }
static bool CheckAffectField(struct xkb_context *ctx, enum xkb_action_type action, const ExprDef *array_ndx, const ExprDef *value, enum xkb_action_flags *flags_inout) { enum xkb_action_flags flags; if (array_ndx) return ReportActionNotArray(ctx, action, ACTION_FIELD_AFFECT); if (!ExprResolveEnum(ctx, value, &flags, lockWhich)) return ReportMismatch(ctx, 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 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) { bool set; if (array_ndx) return ReportActionNotArray(ctx, action, field); if (!ExprResolveBoolean(ctx, value, &set)) return ReportMismatch(ctx, action, field, "boolean"); if (set) *flags_inout |= flag; else *flags_inout &= ~flag; return true; }
static bool 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 == ACTION_FIELD_CONTROLS) { unsigned int mask; if (array_ndx) return ReportActionNotArray(keymap, action->type, field); if (!ExprResolveMask(keymap->ctx, value, &mask, ctrlMaskNames)) return ReportMismatch(keymap, action->type, field, "controls mask"); act->ctrls = mask; return true; } return ReportIllegal(keymap, action->type, field); }
static bool 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->expr.op == EXPR_NEGATE || value->expr.op == EXPR_UNARY_PLUS) { flags &= ~ACTION_ABSOLUTE_SWITCH; spec = value->unary.child; } else { flags |= ACTION_ABSOLUTE_SWITCH; spec = value; } if (!ExprResolveGroup(ctx, spec, &idx)) return ReportMismatch(ctx, action, ACTION_FIELD_GROUP, "integer (range 1..8)"); /* +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; } else { *group_rtrn = (int32_t) (idx - 1); } *flags_inout = flags; return true; }
static bool HandlePrivate(struct xkb_keymap *keymap, union xkb_action *action, enum action_field field, const ExprDef *array_ndx, const ExprDef *value) { struct xkb_private_action *act = &action->priv; if (field == ACTION_FIELD_TYPE) { int type; if (!ExprResolveInteger(keymap->ctx, value, &type)) return ReportMismatch(keymap, ACTION_TYPE_PRIVATE, field, "integer"); if (type < 0 || type > 255) { log_err(keymap->ctx, "Private action type must be in the range 0..255; " "Illegal type %d ignored\n", type); return false; } /* * 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(keymap->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 == ACTION_FIELD_DATA) { if (array_ndx == NULL) { xkb_atom_t val; const char *str; int len; if (!ExprResolveString(keymap->ctx, value, &val)) return ReportMismatch(keymap, action->type, field, "string"); str = xkb_atom_text(keymap->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); return false; } strncpy((char *) act->data, str, sizeof(act->data)); return true; } else { 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 >= sizeof(act->data)) { log_err(keymap->ctx, "The data for a private action is %lu bytes long; " "Attempt to use data[%d] ignored\n", (unsigned long) sizeof(act->data), ndx); return false; } if (!ExprResolveInteger(keymap->ctx, value, &datum)) return ReportMismatch(keymap, act->type, field, "integer"); if (datum < 0 || datum > 255) { log_err(keymap->ctx, "All data for a private action must be 0..255; " "Illegal datum %d ignored\n", datum); return false; } act->data[ndx] = (uint8_t) datum; return true; } } return ReportIllegal(keymap, ACTION_TYPE_NONE, field); }
static bool HandlePtrBtn(struct xkb_keymap *keymap, 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 == ACTION_FIELD_BUTTON) { int btn; if (array_ndx) return ReportActionNotArray(keymap, action->type, field); if (!ExprResolveButton(keymap->ctx, value, &btn)) return ReportMismatch(keymap, action->type, field, "integer (range 1..5)"); if (btn < 0 || btn > 5) { log_err(keymap->ctx, "Button must specify default or be in the range 1..5; " "Illegal button value %d ignored\n", btn); return false; } act->button = btn; return true; } else if (action->type == ACTION_TYPE_PTR_LOCK && field == ACTION_FIELD_AFFECT) { enum xkb_action_flags 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 &= ~(ACTION_LOCK_NO_LOCK | ACTION_LOCK_NO_UNLOCK); act->flags |= val; return true; } else if (field == ACTION_FIELD_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; } return ReportIllegal(keymap, action->type, field); }