Example #1
0
int
ProcXCloseDevice(register ClientPtr client)
{
    int i;
    WindowPtr pWin, p1;
    DeviceIntPtr d;

    REQUEST(xCloseDeviceReq);
    REQUEST_SIZE_MATCH(xCloseDeviceReq);

    d = LookupDeviceIntRec(stuff->deviceid);
    if (d == NULL) {
	SendErrorToClient(client, IReqCode, X_CloseDevice, 0, BadDevice);
	return Success;
    }

    if (d->grab && SameClient(d->grab, client))
	(*d->DeactivateGrab) (d);	/* release active grab */

    /* Remove event selections from all windows for events from this device 
     * and selected by this client.
     * Delete passive grabs from all windows for this device.      */

    for (i = 0; i < screenInfo.numScreens; i++) {
	pWin = WindowTable[i];
	DeleteDeviceEvents(d, pWin, client);
	p1 = pWin->firstChild;
	DeleteEventsFromChildren(d, p1, client);
    }

    CloseInputDevice(d, client);
    return Success;
}
Example #2
0
int
ProcXGetDeviceButtonMapping(register ClientPtr client)
{
    DeviceIntPtr dev;
    xGetDeviceButtonMappingReply rep;
    ButtonClassPtr b;

    REQUEST(xGetDeviceButtonMappingReq);
    REQUEST_SIZE_MATCH(xGetDeviceButtonMappingReq);

    rep.repType = X_Reply;
    rep.RepType = X_GetDeviceButtonMapping;
    rep.nElts = 0;
    rep.length = 0;
    rep.sequenceNumber = client->sequence;

    dev = LookupDeviceIntRec(stuff->deviceid);
    if (dev == NULL) {
	SendErrorToClient(client, IReqCode, X_GetDeviceButtonMapping, 0,
			  BadDevice);
	return Success;
    }

    b = dev->button;
    if (b == NULL) {
	SendErrorToClient(client, IReqCode, X_GetDeviceButtonMapping, 0,
			  BadMatch);
	return Success;
    }
    rep.nElts = b->numButtons;
    rep.length = (rep.nElts + (4 - 1)) / 4;
    WriteReplyToClient(client, sizeof(xGetDeviceButtonMappingReply), &rep);
    (void)WriteToClient(client, rep.nElts, (char *)&b->map[1]);
    return Success;
}
Example #3
0
static int
remove_device(DBusMessage *message, DBusMessage *reply, DBusError *error)
{
    int deviceid, ret, err;
    DeviceIntPtr dev;
    DBusMessageIter iter, reply_iter;

    dbus_message_iter_init_append(reply, &reply_iter);

    if (!dbus_message_iter_init(message, &iter)) {
        ErrorF("[config/dbus] failed to init iterator\n");
        MALFORMED_MESSAGE();
    }

    if (!dbus_message_get_args(message, error, DBUS_TYPE_UINT32,
                               &deviceid, DBUS_TYPE_INVALID)) {
        MALFORMED_MESSAGE_ERROR();
    }

    dev = LookupDeviceIntRec(deviceid);
    if (!dev) {
        DebugF("[config/dbus] bogus device id %d given\n", deviceid);
        ret = BadMatch;
        goto unwind;
    }

    DebugF("[config/dbus] removing device %s (id %d)\n", dev->name, deviceid);

    /* Call PIE here so we don't try to dereference a device that's
     * already been removed. */
    OsBlockSignals();
    ProcessInputEvents();
    DeleteInputDeviceRequest(dev);
    OsReleaseSignals();

    ret = Success;

unwind:
    err = (ret == Success) ? ret : -ret;
    dbus_message_iter_append_basic(&reply_iter, DBUS_TYPE_INT32, &err);

    return ret;
}
Example #4
0
int
ProcXSetDeviceModifierMapping(ClientPtr client)
{
    int ret;
    xSetDeviceModifierMappingReply rep;
    DeviceIntPtr dev;
    KeyClassPtr kp;

    REQUEST(xSetDeviceModifierMappingReq);
    REQUEST_AT_LEAST_SIZE(xSetDeviceModifierMappingReq);

    dev = LookupDeviceIntRec(stuff->deviceid);
    if (dev == NULL) {
	SendErrorToClient(client, IReqCode, X_SetDeviceModifierMapping, 0,
			  BadDevice);
	return Success;
    }

    rep.repType = X_Reply;
    rep.RepType = X_SetDeviceModifierMapping;
    rep.length = 0;
    rep.sequenceNumber = client->sequence;

    ret = SetModifierMapping(client, dev, stuff->length,
			     (sizeof(xSetDeviceModifierMappingReq) >> 2),
			     stuff->numKeyPerModifier, (BYTE *) & stuff[1],
			     &kp);

    if (ret == MappingSuccess || ret == MappingBusy || ret == MappingFailed) {
	rep.success = ret;
	if (ret == MappingSuccess)
	    SendDeviceMappingNotify(client, MappingModifier, 0, 0, dev);
	WriteReplyToClient(client, sizeof(xSetDeviceModifierMappingReply),
			   &rep);
    } else {
	if (ret == -1)
	    ret = BadValue;
	SendErrorToClient(client, IReqCode, X_SetDeviceModifierMapping, 0, ret);
    }

    return Success;
}
Example #5
0
int
ProcXOpenDevice(ClientPtr client)
{
    xInputClassInfo evbase[numInputClasses];
    int j = 0;
    int status = Success;
    xOpenDeviceReply rep;
    DeviceIntPtr dev;

    REQUEST(xOpenDeviceReq);
    REQUEST_SIZE_MATCH(xOpenDeviceReq);

    if (stuff->deviceid == inputInfo.pointer->id ||
	stuff->deviceid == inputInfo.keyboard->id) {
	SendErrorToClient(client, IReqCode, X_OpenDevice, 0, BadDevice);
	return Success;
    }

    if ((dev = LookupDeviceIntRec(stuff->deviceid)) == NULL) {	/* not open */
	for (dev = inputInfo.off_devices; dev; dev = dev->next)
	    if (dev->id == stuff->deviceid)
		break;
	if (dev == NULL) {
	    SendErrorToClient(client, IReqCode, X_OpenDevice, 0, BadDevice);
	    return Success;
	}
    }

    OpenInputDevice(dev, client, &status);
    if (status != Success) {
	SendErrorToClient(client, IReqCode, X_OpenDevice, 0, status);
	return Success;
    }

    rep.repType = X_Reply;
    rep.RepType = X_OpenDevice;
    rep.sequenceNumber = client->sequence;
    if (dev->key != NULL) {
	evbase[j].class = KeyClass;
	evbase[j++].event_type_base = event_base[KeyClass];
    }
Example #6
0
int
ProcXDeviceBell(register ClientPtr client)
{
    DeviceIntPtr dev;
    KbdFeedbackPtr k;
    BellFeedbackPtr b;
    int base;
    int newpercent;
    CARD8 class;
    pointer ctrl;
    BellProcPtr proc;

    REQUEST(xDeviceBellReq);
    REQUEST_SIZE_MATCH(xDeviceBellReq);

    dev = LookupDeviceIntRec(stuff->deviceid);
    if (dev == NULL) {
	client->errorValue = stuff->deviceid;
	SendErrorToClient(client, IReqCode, X_DeviceBell, 0, BadDevice);
	return Success;
    }

    if (stuff->percent < -100 || stuff->percent > 100) {
	client->errorValue = stuff->percent;
	SendErrorToClient(client, IReqCode, X_DeviceBell, 0, BadValue);
	return Success;
    }
    if (stuff->feedbackclass == KbdFeedbackClass) {
	for (k = dev->kbdfeed; k; k = k->next)
	    if (k->ctrl.id == stuff->feedbackid)
		break;
	if (!k) {
	    client->errorValue = stuff->feedbackid;
	    SendErrorToClient(client, IReqCode, X_DeviceBell, 0, BadValue);
	    return Success;
	}
	base = k->ctrl.bell;
	proc = k->BellProc;
	ctrl = (pointer) & (k->ctrl);
	class = KbdFeedbackClass;
    } else if (stuff->feedbackclass == BellFeedbackClass) {
Example #7
0
int
ProcXSetDeviceFocus(ClientPtr client)
{
    int ret;
    DeviceIntPtr dev;

    REQUEST(xSetDeviceFocusReq);
    REQUEST_SIZE_MATCH(xSetDeviceFocusReq);

    dev = LookupDeviceIntRec(stuff->device);
    if (dev == NULL || !dev->focus) {
	SendErrorToClient(client, IReqCode, X_SetDeviceFocus, 0, BadDevice);
	return Success;
    }

    ret = SetInputFocus(client, dev, stuff->focus, stuff->revertTo,
			stuff->time, TRUE);
    if (ret != Success)
	SendErrorToClient(client, IReqCode, X_SetDeviceFocus, 0, ret);

    return Success;
}
Example #8
0
int
ProcXUngrabDevice(ClientPtr client)
{
    DeviceIntPtr dev;
    GrabPtr grab;
    TimeStamp time;

    REQUEST(xUngrabDeviceReq);
    REQUEST_SIZE_MATCH(xUngrabDeviceReq);

    dev = LookupDeviceIntRec(stuff->deviceid);
    if (dev == NULL) {
	SendErrorToClient(client, IReqCode, X_UngrabDevice, 0, BadDevice);
	return Success;
    }
    grab = dev->grab;

    time = ClientTimeToServerTime(stuff->time);
    if ((CompareTimeStamps(time, currentTime) != LATER) &&
	(CompareTimeStamps(time, dev->grabTime) != EARLIER) &&
	(grab) && SameClient(grab, client))
	(*dev->DeactivateGrab) (dev);
    return Success;
}
Example #9
0
int
ProcXUngrabDeviceKey(ClientPtr client)
{
    DeviceIntPtr dev;
    DeviceIntPtr mdev;
    WindowPtr pWin;
    GrabRec temporaryGrab;

    REQUEST(xUngrabDeviceKeyReq);
    REQUEST_SIZE_MATCH(xUngrabDeviceKeyReq);

    dev = LookupDeviceIntRec(stuff->grabbed_device);
    if (dev == NULL) {
        SendErrorToClient(client, IReqCode, X_UngrabDeviceKey, 0, BadDevice);
        return Success;
    }
    if (dev->key == NULL) {
        SendErrorToClient(client, IReqCode, X_UngrabDeviceKey, 0, BadMatch);
        return Success;
    }

    if (stuff->modifier_device != UseXKeyboard) {
        mdev = LookupDeviceIntRec(stuff->modifier_device);
        if (mdev == NULL) {
            SendErrorToClient(client, IReqCode, X_UngrabDeviceKey, 0,
                              BadDevice);
            return Success;
        }
        if (mdev->key == NULL) {
            SendErrorToClient(client, IReqCode, X_UngrabDeviceKey, 0, BadMatch);
            return Success;
        }
    } else
        mdev = (DeviceIntPtr) LookupKeyboardDevice();

    pWin = LookupWindow(stuff->grabWindow, client);
    if (!pWin) {
        SendErrorToClient(client, IReqCode, X_UngrabDeviceKey, 0, BadWindow);
        return Success;
    }
    if (((stuff->key > dev->key->curKeySyms.maxKeyCode) ||
            (stuff->key < dev->key->curKeySyms.minKeyCode))
            && (stuff->key != AnyKey)) {
        SendErrorToClient(client, IReqCode, X_UngrabDeviceKey, 0, BadValue);
        return Success;
    }
    if ((stuff->modifiers != AnyModifier) &&
            (stuff->modifiers & ~AllModifiersMask)) {
        SendErrorToClient(client, IReqCode, X_UngrabDeviceKey, 0, BadValue);
        return Success;
    }

    temporaryGrab.resource = client->clientAsMask;
    temporaryGrab.device = dev;
    temporaryGrab.window = pWin;
    temporaryGrab.type = DeviceKeyPress;
    temporaryGrab.modifierDevice = mdev;
    temporaryGrab.modifiersDetail.exact = stuff->modifiers;
    temporaryGrab.modifiersDetail.pMask = NULL;
    temporaryGrab.detail.exact = stuff->key;
    temporaryGrab.detail.pMask = NULL;

    DeletePassiveGrabFromList(&temporaryGrab);
    return Success;
}
Example #10
0
int
ProcXUngrabDeviceButton(ClientPtr client)
{
    DeviceIntPtr dev;
    DeviceIntPtr mdev;
    WindowPtr pWin;
    GrabRec temporaryGrab;
    int rc;

    REQUEST(xUngrabDeviceButtonReq);
    REQUEST_SIZE_MATCH(xUngrabDeviceButtonReq);

    dev = LookupDeviceIntRec(stuff->grabbed_device);
    if (dev == NULL) {
	SendErrorToClient(client, IReqCode, X_UngrabDeviceButton, 0, BadDevice);
	return Success;
    }
    if (dev->button == NULL) {
	SendErrorToClient(client, IReqCode, X_UngrabDeviceButton, 0, BadMatch);
	return Success;
    }

    if (stuff->modifier_device != UseXKeyboard) {
	mdev = LookupDeviceIntRec(stuff->modifier_device);
	if (mdev == NULL) {
	    SendErrorToClient(client, IReqCode, X_UngrabDeviceButton, 0,
			      BadDevice);
	    return Success;
	}
	if (mdev->key == NULL) {
	    SendErrorToClient(client, IReqCode, X_UngrabDeviceButton, 0,
			      BadMatch);
	    return Success;
	}
    } else
	mdev = (DeviceIntPtr) LookupKeyboardDevice();

    rc = dixLookupWindow(&pWin, stuff->grabWindow, client, DixUnknownAccess);
    if (rc != Success) {
	SendErrorToClient(client, IReqCode, X_UngrabDeviceButton, 0, rc);
	return Success;
    }

    if ((stuff->modifiers != AnyModifier) &&
	(stuff->modifiers & ~AllModifiersMask)) {
	SendErrorToClient(client, IReqCode, X_UngrabDeviceButton, 0, BadValue);
	return Success;
    }

    temporaryGrab.resource = client->clientAsMask;
    temporaryGrab.device = dev;
    temporaryGrab.window = pWin;
    temporaryGrab.type = DeviceButtonPress;
    temporaryGrab.modifierDevice = mdev;
    temporaryGrab.modifiersDetail.exact = stuff->modifiers;
    temporaryGrab.modifiersDetail.pMask = NULL;
    temporaryGrab.detail.exact = stuff->button;
    temporaryGrab.detail.pMask = NULL;

    DeletePassiveGrabFromList(&temporaryGrab);
    return Success;
}