Ejemplo n.º 1
0
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);
}
Ejemplo n.º 2
0
static bool
HandleLockMods(struct xkb_keymap *keymap, union xkb_action *action,
               enum action_field field, const ExprDef *array_ndx,
               const ExprDef *value)
{
    struct xkb_mod_action *act = &action->mods;
    enum xkb_action_flags t1;
    xkb_mod_mask_t t2;

    if (array_ndx && field == ACTION_FIELD_MODIFIERS)
        return ReportActionNotArray(keymap, action->type, field);

    switch (field) {
    case ACTION_FIELD_MODIFIERS:
        t1 = act->flags;
        if (CheckModifierField(keymap, action->type, value, &t1, &t2)) {
            act->flags = t1;
            act->mods.mods = t2;
            return true;
        }
        return false;

    default:
        break;
    }

    return ReportIllegal(keymap, action->type, field);
}
Ejemplo n.º 3
0
static bool
HandleSetLatchLockMods(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_mod_action *act = &action->mods;
    const enum xkb_action_type type = action->type;

    if (field == ACTION_FIELD_MODIFIERS)
        return CheckModifierField(ctx, mods, action->type, array_ndx, value,
                                  &act->flags, &act->mods.mods);
    if ((type == ACTION_TYPE_MOD_SET || type == ACTION_TYPE_MOD_LATCH) &&
        field == ACTION_FIELD_CLEAR_LOCKS)
        return CheckBooleanFlag(ctx, action->type, field,
                                ACTION_LOCK_CLEAR, array_ndx, value,
                                &act->flags);
    if (type == ACTION_TYPE_MOD_LATCH &&
        field == ACTION_FIELD_LATCH_TO_LOCK)
        return CheckBooleanFlag(ctx, action->type, field,
                                ACTION_LATCH_TO_LOCK, array_ndx, value,
                                &act->flags);
    if (type == ACTION_TYPE_MOD_LOCK &&
        field == ACTION_FIELD_AFFECT)
        return CheckAffectField(ctx, action->type, array_ndx, value,
                                &act->flags);

    return ReportIllegal(ctx, action->type, field);
}
Ejemplo n.º 4
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);
}
Ejemplo n.º 5
0
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);
}
Ejemplo n.º 6
0
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);
}
Ejemplo n.º 7
0
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);
}
Ejemplo n.º 8
0
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);
}
Ejemplo n.º 9
0
static bool
HandleSetLatchGroup(struct xkb_keymap *keymap, union xkb_action *action,
                    enum action_field field, const ExprDef *array_ndx,
                    const ExprDef *value)
{
    struct xkb_group_action *act = &action->group;
    enum xkb_action_flags rtrn, t1;
    xkb_layout_index_t t2;

    if (array_ndx != NULL) {
        switch (field) {
        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 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 true;
        }
        return false;

    case ACTION_FIELD_GROUP:
        t1 = act->flags;
        if (CheckGroupField(keymap, action->type, value, &t1, &t2)) {
            act->flags = t1;
            act->group = t2;
            return true;
        }
        return false;

    default:
        break;
    }

    return ReportIllegal(keymap, action->type, field);
}
Ejemplo n.º 10
0
static bool
HandleSetLatchMods(struct xkb_keymap *keymap, union xkb_action *action,
                   enum action_field field, const ExprDef *array_ndx,
                   const ExprDef *value)
{
    struct xkb_mod_action *act = &action->mods;
    enum xkb_action_flags rtrn, t1;
    xkb_mod_mask_t t2;

    if (array_ndx != NULL) {
        switch (field) {
        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 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 true;
        }
        return false;

    case ACTION_FIELD_MODIFIERS:
        t1 = act->flags;
        if (CheckModifierField(keymap, action->type, value, &t1, &t2)) {
            act->flags = t1;
            act->mods.mods = t2;
            return true;
        }
        return false;

    default:
        break;
    }

    return ReportIllegal(keymap, action->type, field);
}
Ejemplo n.º 11
0
static bool
HandleLockGroup(struct xkb_keymap *keymap, union xkb_action *action,
                enum action_field field, const ExprDef *array_ndx,
                const ExprDef *value)
{
    struct xkb_group_action *act = &action->group;
    enum xkb_action_flags t1;
    xkb_layout_index_t t2;

    if ((array_ndx != NULL) && (field == ACTION_FIELD_GROUP))
        return ReportActionNotArray(keymap, action->type, field);
    if (field == ACTION_FIELD_GROUP) {
        t1 = act->flags;
        if (CheckGroupField(keymap, action->type, value, &t1, &t2)) {
            act->flags = t1;
            act->group = t2;
            return true;
        }
        return false;
    }
    return ReportIllegal(keymap, action->type, field);
}
Ejemplo n.º 12
0
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);
}
Ejemplo n.º 13
0
static bool
HandleSetLatchLockGroup(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_group_action *act = &action->group;
    const enum xkb_action_type type = action->type;

    if (field == ACTION_FIELD_GROUP)
        return CheckGroupField(ctx, action->type, array_ndx, value,
                               &act->flags, &act->group);
    if ((type == ACTION_TYPE_GROUP_SET || type == ACTION_TYPE_GROUP_LATCH) &&
        field == ACTION_FIELD_CLEAR_LOCKS)
        return CheckBooleanFlag(ctx, action->type, field,
                                ACTION_LOCK_CLEAR, array_ndx, value,
                                &act->flags);
    if (type == ACTION_TYPE_GROUP_LATCH &&
        field == ACTION_FIELD_LATCH_TO_LOCK)
        return CheckBooleanFlag(ctx, action->type, field,
                                ACTION_LATCH_TO_LOCK, array_ndx, value,
                                &act->flags);

    return ReportIllegal(ctx, action->type, field);
}
Ejemplo n.º 14
0
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);
}
Ejemplo n.º 15
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);
}