Exemple #1
0
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);
}
Exemple #2
0
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;
}
Exemple #3
0
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);
}