Beispiel #1
0
static int
eventToBarrierEvent(BarrierEvent *ev, xEvent **xi)
{
    xXIBarrierEvent *barrier;
    int len = sizeof(xXIBarrierEvent);

    *xi = calloc(1, len);
    barrier = (xXIBarrierEvent*) *xi;
    barrier->type = GenericEvent;
    barrier->extension = IReqCode;
    barrier->evtype = GetXI2Type(ev->type);
    barrier->length = bytes_to_int32(len - sizeof(xEvent));
    barrier->deviceid = ev->deviceid;
    barrier->sourceid = ev->sourceid;
    barrier->time = ev->time;
    barrier->event = ev->window;
    barrier->root = ev->root;
    barrier->dx = double_to_fp3232(ev->dx);
    barrier->dy = double_to_fp3232(ev->dy);
    barrier->dtime = ev->dt;
    barrier->flags = ev->flags;
    barrier->eventid = ev->event_id;
    barrier->barrier = ev->barrierid;
    barrier->root_x = double_to_fp1616(ev->root_x);
    barrier->root_y = double_to_fp1616(ev->root_y);

    return Success;
}
Beispiel #2
0
static int
appendScrollInfo(DeviceChangedEvent *dce, xXIScrollInfo *info, int axisnumber)
{
    if (dce->valuators[axisnumber].scroll.type == SCROLL_TYPE_NONE)
        return 0;

    info->type = XIScrollClass;
    info->length = sizeof(xXIScrollInfo)/4;
    info->number = axisnumber;
    switch(dce->valuators[axisnumber].scroll.type)
    {
        case SCROLL_TYPE_VERTICAL:
            info->scroll_type = XIScrollTypeVertical;
            break;
        case SCROLL_TYPE_HORIZONTAL:
            info->scroll_type = XIScrollTypeHorizontal;
            break;
        default:
            ErrorF("[Xi] Unknown scroll type %d. This is a bug.\n", dce->valuators[axisnumber].scroll.type);
            break;
    }
    info->increment = double_to_fp3232(dce->valuators[axisnumber].scroll.increment);
    info->sourceid = dce->sourceid;

    info->flags = 0;

    if (dce->valuators[axisnumber].scroll.flags & SCROLL_FLAG_DONT_EMULATE)
        info->flags |= XIScrollFlagNoEmulation;
    if (dce->valuators[axisnumber].scroll.flags & SCROLL_FLAG_PREFERRED)
        info->flags |= XIScrollFlagPreferred;

    return info->length * 4;
}
Beispiel #3
0
static int
eventToRawEvent(RawDeviceEvent *ev, xEvent **xi)
{
    xXIRawEvent* raw;
    int vallen, nvals;
    int i, len = sizeof(xXIRawEvent);
    char *ptr;
    FP3232 *axisval, *axisval_raw;

    nvals = count_bits(ev->valuators.mask, sizeof(ev->valuators.mask));
    len += nvals * sizeof(FP3232) * 2; /* 8 byte per valuator, once
                                    raw, once processed */
    vallen = bytes_to_int32(bits_to_bytes(MAX_VALUATORS));
    len += vallen * 4; /* valuators mask */

    *xi = calloc(1, len);
    raw = (xXIRawEvent*)*xi;
    raw->type           = GenericEvent;
    raw->extension      = IReqCode;
    raw->evtype         = GetXI2Type(ev->type);
    raw->time           = ev->time;
    raw->length         = bytes_to_int32(len - sizeof(xEvent));
    raw->detail         = ev->detail.button;
    raw->deviceid       = ev->deviceid;
    raw->sourceid       = ev->sourceid;
    raw->valuators_len  = vallen;
    raw->flags          = ev->flags;

    ptr = (char*)&raw[1];
    axisval = (FP3232*)(ptr + raw->valuators_len * 4);
    axisval_raw = axisval + nvals;
    for (i = 0; i < sizeof(ev->valuators.mask) * 8; i++)
    {
        if (BitIsOn(ev->valuators.mask, i))
        {
            SetBit(ptr, i);
            *axisval =  double_to_fp3232(ev->valuators.data[i]);
            *axisval_raw = double_to_fp3232(ev->valuators.data_raw[i]);
            axisval++;
            axisval_raw++;
        }
    }

    return Success;
}
int
ListScrollInfo(DeviceIntPtr dev, xXIScrollInfo * info, int axisnumber)
{
    ValuatorClassPtr v = dev->valuator;
    AxisInfoPtr axis = &v->axes[axisnumber];

    if (axis->scroll.type == SCROLL_TYPE_NONE)
        return 0;

    info->type = XIScrollClass;
    info->length = sizeof(xXIScrollInfo) / 4;
    info->number = axisnumber;
    switch (axis->scroll.type) {
    case SCROLL_TYPE_VERTICAL:
        info->scroll_type = XIScrollTypeVertical;
        break;
    case SCROLL_TYPE_HORIZONTAL:
        info->scroll_type = XIScrollTypeHorizontal;
        break;
    default:
        ErrorF("[Xi] Unknown scroll type %d. This is a bug.\n",
               axis->scroll.type);
        break;
    }
    info->increment = double_to_fp3232(axis->scroll.increment);
    info->sourceid = v->sourceid;

    info->flags = 0;

    if (axis->scroll.flags & SCROLL_FLAG_DONT_EMULATE)
        info->flags |= XIScrollFlagNoEmulation;
    if (axis->scroll.flags & SCROLL_FLAG_PREFERRED)
        info->flags |= XIScrollFlagPreferred;

    return info->length * 4;
}
/**
 * List axis information for the given axis.
 *
 * @return The number of bytes written into info.
 */
int
ListValuatorInfo(DeviceIntPtr dev, xXIValuatorInfo * info, int axisnumber,
                 Bool reportState)
{
    ValuatorClassPtr v = dev->valuator;

    info->type = ValuatorClass;
    info->length = sizeof(xXIValuatorInfo) / 4;
    info->label = v->axes[axisnumber].label;
    info->min.integral = v->axes[axisnumber].min_value;
    info->min.frac = 0;
    info->max.integral = v->axes[axisnumber].max_value;
    info->max.frac = 0;
    info->value = double_to_fp3232(v->axisVal[axisnumber]);
    info->resolution = v->axes[axisnumber].resolution;
    info->number = axisnumber;
    info->mode = valuator_get_mode(dev, axisnumber);
    info->sourceid = v->sourceid;

    if (!reportState)
        info->value = info->min;

    return info->length * 4;
}
static void test_values_XIRawEvent(RawDeviceEvent *in, xXIRawEvent *out,
                                   BOOL swap)
{
    int i;
    unsigned char *ptr;
    FP3232 *value, *raw_value;
    int nvals = 0;
    int bits_set;
    int len;
    uint32_t flagmask = 0;

    if (swap)
    {
        swaps(&out->sequenceNumber);
        swapl(&out->length);
        swaps(&out->evtype);
        swaps(&out->deviceid);
        swapl(&out->time);
        swapl(&out->detail);
        swaps(&out->valuators_len);
        swapl(&out->flags);
    }


    assert(out->type == GenericEvent);
    assert(out->extension == 0); /* IReqCode defaults to 0 */
    assert(out->evtype == GetXI2Type((InternalEvent*)in));
    assert(out->time == in->time);
    assert(out->detail == in->detail.button);
    assert(out->deviceid == in->deviceid);
    assert(out->valuators_len >= bytes_to_int32(bits_to_bytes(sizeof(in->valuators.mask))));

    switch (in->type) {
    case ET_RawMotion:
    case ET_RawButtonPress:
    case ET_RawButtonRelease:
        flagmask = XIPointerEmulated;
        break;
    default:
        flagmask = 0;
    }
    assert((out->flags & ~flagmask) == 0);

    ptr = (unsigned char*)&out[1];
    bits_set = 0;

    for (i = 0; out->valuators_len && i < sizeof(in->valuators.mask) * 8; i++)
    {
        if (i >= MAX_VALUATORS)
            assert (!XIMaskIsSet(in->valuators.mask, i));
        assert (XIMaskIsSet(in->valuators.mask, i) == XIMaskIsSet(ptr, i));
        if (XIMaskIsSet(in->valuators.mask, i))
            bits_set++;
    }

    /* length is len of valuator mask (in 4-byte units) + the number of bits
     * set. Each bit set represents 2 8-byte values, hence the
     * 'bits_set * 4' */
    len = out->valuators_len + bits_set * 4;
    assert(out->length == len);

    nvals = 0;

    for (i = 0; out->valuators_len && i < MAX_VALUATORS; i++)
    {
        assert (XIMaskIsSet(in->valuators.mask, i) == XIMaskIsSet(ptr, i));
        if (XIMaskIsSet(in->valuators.mask, i))
        {
            FP3232 vi, vo;
            value = (FP3232*)(((unsigned char*)&out[1]) + out->valuators_len * 4);
            value += nvals;

            vi = double_to_fp3232(in->valuators.data[i]);

            vo.integral = value->integral;
            vo.frac = value->frac;
            if (swap)
            {
                swapl(&vo.integral);
                swapl(&vo.frac);
            }

            assert(vi.integral == vo.integral);
            assert(vi.frac == vo.frac);

            raw_value = value + bits_set;

            vi = double_to_fp3232(in->valuators.data_raw[i]);

            vo.integral = raw_value->integral;
            vo.frac = raw_value->frac;
            if (swap)
            {
                swapl(&vo.integral);
                swapl(&vo.frac);
            }

            assert(vi.integral == vo.integral);
            assert(vi.frac == vo.frac);

            nvals++;
        }
    }
}
static void test_values_XIDeviceEvent(DeviceEvent *in, xXIDeviceEvent *out,
                                      BOOL swap)
{
    int buttons, valuators;
    int i;
    unsigned char *ptr;
    uint32_t flagmask = 0;
    FP3232 *values;

    if (swap) {
        swaps(&out->sequenceNumber);
        swapl(&out->length);
        swaps(&out->evtype);
        swaps(&out->deviceid);
        swaps(&out->sourceid);
        swapl(&out->time);
        swapl(&out->detail);
        swapl(&out->root);
        swapl(&out->event);
        swapl(&out->child);
        swapl(&out->root_x);
        swapl(&out->root_y);
        swapl(&out->event_x);
        swapl(&out->event_y);
        swaps(&out->buttons_len);
        swaps(&out->valuators_len);
        swapl(&out->mods.base_mods);
        swapl(&out->mods.latched_mods);
        swapl(&out->mods.locked_mods);
        swapl(&out->mods.effective_mods);
        swapl(&out->flags);
    }

    assert(out->extension == 0); /* IReqCode defaults to 0 */
    assert(out->evtype == GetXI2Type((InternalEvent*)in));
    assert(out->time == in->time);
    assert(out->detail == in->detail.button);
    assert(out->length >= 12);

    assert(out->deviceid == in->deviceid);
    assert(out->sourceid == in->sourceid);

    switch (in->type) {
        case ET_ButtonPress:
        case ET_Motion:
        case ET_ButtonRelease:
            flagmask = XIPointerEmulated;
            break;
        case ET_KeyPress:
            flagmask = XIKeyRepeat;
            break;
        default:
            flagmask = 0;
            break;
    }
    assert((out->flags & ~flagmask) == 0);

    assert(out->root == in->root);
    assert(out->event == None); /* set in FixUpEventFromWindow */
    assert(out->child == None); /* set in FixUpEventFromWindow */

    assert(out->mods.base_mods == in->mods.base);
    assert(out->mods.latched_mods == in->mods.latched);
    assert(out->mods.locked_mods == in->mods.locked);
    assert(out->mods.effective_mods == in->mods.effective);

    assert(out->group.base_group == in->group.base);
    assert(out->group.latched_group == in->group.latched);
    assert(out->group.locked_group == in->group.locked);
    assert(out->group.effective_group == in->group.effective);

    assert(out->event_x == 0); /* set in FixUpEventFromWindow */
    assert(out->event_y == 0); /* set in FixUpEventFromWindow */

    assert(out->root_x == FP1616(in->root_x, in->root_x_frac));
    assert(out->root_y == FP1616(in->root_y, in->root_y_frac));

    buttons = 0;
    for (i = 0; i < bits_to_bytes(sizeof(in->buttons)); i++)
    {
        if (XIMaskIsSet(in->buttons, i))
        {
            assert(out->buttons_len >= bytes_to_int32(bits_to_bytes(i)));
            buttons++;
        }
    }

    ptr = (unsigned char*)&out[1];
    for (i = 0; i < sizeof(in->buttons) * 8; i++)
        assert(XIMaskIsSet(in->buttons, i) == XIMaskIsSet(ptr, i));


    valuators = 0;
    for (i = 0; i < MAX_VALUATORS; i++)
        if (XIMaskIsSet(in->valuators.mask, i))
            valuators++;

    assert(out->valuators_len >= bytes_to_int32(bits_to_bytes(valuators)));

    ptr += out->buttons_len * 4;
    values = (FP3232*)(ptr + out->valuators_len * 4);
    for (i = 0; i < sizeof(in->valuators.mask) * 8 ||
                i < (out->valuators_len * 4) * 8; i++)
    {
        if (i >= MAX_VALUATORS)
            assert(!XIMaskIsSet(in->valuators.mask, i) && !XIMaskIsSet(ptr, i));
        else if (i > sizeof(in->valuators.mask) * 8)
            assert(!XIMaskIsSet(ptr, i));
        else if (i > out->valuators_len * 4 * 8)
            assert(!XIMaskIsSet(in->valuators.mask, i));
        else {
            assert(XIMaskIsSet(in->valuators.mask, i) ==
                     XIMaskIsSet(ptr, i));

            if (XIMaskIsSet(ptr, i))
            {
                FP3232 vi, vo;

                vi = double_to_fp3232(in->valuators.data[i]);
                vo = *values;

                if (swap)
                {
                    swapl(&vo.integral);
                    swapl(&vo.frac);
                }


                assert(vi.integral == vo.integral);
                assert(vi.frac == vo.frac);
                values++;
            }
        }
    }
}
Beispiel #8
0
static int
eventToDeviceEvent(DeviceEvent *ev, xEvent **xi)
{
    int len = sizeof(xXIDeviceEvent);
    xXIDeviceEvent *xde;
    int i, btlen, vallen;
    char *ptr;
    FP3232 *axisval;

    /* FIXME: this should just send the buttons we have, not MAX_BUTTONs. Same
     * with MAX_VALUATORS below */
    /* btlen is in 4 byte units */
    btlen = bytes_to_int32(bits_to_bytes(MAX_BUTTONS));
    len += btlen * 4; /* buttonmask len */


    vallen = count_bits(ev->valuators.mask, sizeof(ev->valuators.mask)/sizeof(ev->valuators.mask[0]));
    len += vallen * 2 * sizeof(uint32_t); /* axisvalues */
    vallen = bytes_to_int32(bits_to_bytes(MAX_VALUATORS));
    len += vallen * 4; /* valuators mask */

    *xi = calloc(1, len);
    xde = (xXIDeviceEvent*)*xi;
    xde->type           = GenericEvent;
    xde->extension      = IReqCode;
    xde->evtype         = GetXI2Type(ev->type);
    xde->time           = ev->time;
    xde->length         = bytes_to_int32(len - sizeof(xEvent));
    if (IsTouchEvent((InternalEvent*)ev))
        xde->detail     = ev->touchid;
    else
        xde->detail     = ev->detail.button;

    xde->root           = ev->root;
    xde->buttons_len    = btlen;
    xde->valuators_len  = vallen;
    xde->deviceid       = ev->deviceid;
    xde->sourceid       = ev->sourceid;
    xde->root_x         = FP1616(ev->root_x, ev->root_x_frac);
    xde->root_y         = FP1616(ev->root_y, ev->root_y_frac);

    if (ev->type == ET_TouchUpdate)
        xde->flags |= (ev->flags & TOUCH_PENDING_END) ? XITouchPendingEnd : 0;
    else
        xde->flags = ev->flags;

    if (IsTouchEvent((InternalEvent*)ev) &&
        ev->flags & TOUCH_POINTER_EMULATED)
        xde->flags |= XITouchEmulatingPointer;

    if (ev->key_repeat)
        xde->flags      |= XIKeyRepeat;

    xde->mods.base_mods         = ev->mods.base;
    xde->mods.latched_mods      = ev->mods.latched;
    xde->mods.locked_mods       = ev->mods.locked;
    xde->mods.effective_mods    = ev->mods.effective;

    xde->group.base_group       = ev->group.base;
    xde->group.latched_group    = ev->group.latched;
    xde->group.locked_group     = ev->group.locked;
    xde->group.effective_group  = ev->group.effective;

    ptr = (char*)&xde[1];
    for (i = 0; i < sizeof(ev->buttons) * 8; i++)
    {
        if (BitIsOn(ev->buttons, i))
            SetBit(ptr, i);
    }

    ptr += xde->buttons_len * 4;
    axisval = (FP3232*)(ptr + xde->valuators_len * 4);
    for (i = 0; i < sizeof(ev->valuators.mask) * 8; i++)
    {
        if (BitIsOn(ev->valuators.mask, i))
        {
            SetBit(ptr, i);
            *axisval = double_to_fp3232(ev->valuators.data[i]);
            axisval++;
        }
    }

    return Success;
}