Esempio n. 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;
}
Esempio n. 2
0
int
ProcXIQueryPointer(ClientPtr client)
{
    int rc;
    xXIQueryPointerReply rep;
    DeviceIntPtr pDev, kbd;
    WindowPtr pWin, t;
    SpritePtr pSprite;
    XkbStatePtr state;
    char *buttons = NULL;
    int buttons_size = 0;       /* size of buttons array */
    XIClientPtr xi_client;
    Bool have_xi22 = FALSE;

    REQUEST(xXIQueryPointerReq);
    REQUEST_SIZE_MATCH(xXIQueryPointerReq);

    /* Check if client is compliant with XInput 2.2 or later. Earlier clients
     * do not know about touches, so we must report emulated button presses. 2.2
     * and later clients are aware of touches, so we don't include emulated
     * button presses in the reply. */
    xi_client = dixLookupPrivate(&client->devPrivates, XIClientPrivateKey);
    if (version_compare(xi_client->major_version,
                        xi_client->minor_version, 2, 2) >= 0)
        have_xi22 = TRUE;

    rc = dixLookupDevice(&pDev, stuff->deviceid, client, DixReadAccess);
    if (rc != Success) {
        client->errorValue = stuff->deviceid;
        return rc;
    }

    if (pDev->valuator == NULL || IsKeyboardDevice(pDev) || (!IsMaster(pDev) && !IsFloating(pDev))) {   /* no attached devices */
        client->errorValue = stuff->deviceid;
        return BadDevice;
    }

    rc = dixLookupWindow(&pWin, stuff->win, client, DixGetAttrAccess);
    if (rc != Success) {
        client->errorValue = stuff->win;
        return rc;
    }

    if (pDev->valuator->motionHintWindow)
        MaybeStopHint(pDev, client);

    if (IsMaster(pDev))
        kbd = GetMaster(pDev, MASTER_KEYBOARD);
    else
        kbd = (pDev->key) ? pDev : NULL;

    pSprite = pDev->spriteInfo->sprite;

    rep = (xXIQueryPointerReply) {
        .repType = X_Reply,
        .RepType = X_XIQueryPointer,
        .sequenceNumber = client->sequence,
        .length = 6,
        .root = (GetCurrentRootWindow(pDev))->drawable.id,
        .root_x = double_to_fp1616(pSprite->hot.x),
        .root_y = double_to_fp1616(pSprite->hot.y),
        .child = None
    };

    if (kbd) {
        state = &kbd->key->xkbInfo->state;
        rep.mods.base_mods = state->base_mods;
        rep.mods.latched_mods = state->latched_mods;
        rep.mods.locked_mods = state->locked_mods;

        rep.group.base_group = state->base_group;
        rep.group.latched_group = state->latched_group;
        rep.group.locked_group = state->locked_group;
    }

    if (pDev->button) {
        int i;

        rep.buttons_len =
            bytes_to_int32(bits_to_bytes(pDev->button->numButtons));
        rep.length += rep.buttons_len;
        buttons = calloc(rep.buttons_len, 4);
        if (!buttons)
            return BadAlloc;
        buttons_size = rep.buttons_len * 4;

        for (i = 1; i < pDev->button->numButtons; i++)
            if (BitIsOn(pDev->button->down, i))
                SetBit(buttons, pDev->button->map[i]);

        if (!have_xi22 && pDev->touch && pDev->touch->buttonsDown > 0)
            SetBit(buttons, pDev->button->map[1]);
    }
    else
        rep.buttons_len = 0;

    if (pSprite->hot.pScreen == pWin->drawable.pScreen) {
        rep.same_screen = xTrue;
        rep.win_x = double_to_fp1616(pSprite->hot.x - pWin->drawable.x);
        rep.win_y = double_to_fp1616(pSprite->hot.y - pWin->drawable.y);
        for (t = pSprite->win; t; t = t->parent)
            if (t->parent == pWin) {
                rep.child = t->drawable.id;
                break;
            }
    }
    else {
        rep.same_screen = xFalse;
        rep.win_x = 0;
        rep.win_y = 0;
    }

#ifdef PANORAMIX
    if (!noPanoramiXExtension) {
        rep.root_x += double_to_fp1616(screenInfo.screens[0]->x);
        rep.root_y += double_to_fp1616(screenInfo.screens[0]->y);
        if (stuff->win == rep.root) {
            rep.win_x += double_to_fp1616(screenInfo.screens[0]->x);
            rep.win_y += double_to_fp1616(screenInfo.screens[0]->y);
        }
    }
#endif

    WriteReplyToClient(client, sizeof(xXIQueryPointerReply), &rep);
    if (buttons)
        WriteToClient(client, buttons_size, buttons);

    free(buttons);

    return Success;
}

/***********************************************************************
 *
 * This procedure writes the reply for the XIQueryPointer function,
 * if the client and server have a different byte ordering.
 *
 */

void
SRepXIQueryPointer(ClientPtr client, int size, xXIQueryPointerReply * rep)
{
    swaps(&rep->sequenceNumber);
    swapl(&rep->length);
    swapl(&rep->root);
    swapl(&rep->child);
    swapl(&rep->root_x);
    swapl(&rep->root_y);
    swapl(&rep->win_x);
    swapl(&rep->win_y);
    swaps(&rep->buttons_len);

    WriteToClient(client, size, rep);
}
Esempio n. 3
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 = double_to_fp1616(ev->root_x + ev->root_x_frac);
    xde->root_y = double_to_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;
}