2010-07-27 13:02:24 -06:00
|
|
|
/*
|
|
|
|
* Copyright 2007-2008 Peter Hutterer
|
|
|
|
* Copyright 2009 Red Hat, Inc.
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice (including the next
|
|
|
|
* paragraph) shall be included in all copies or substantial portions of the
|
|
|
|
* Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
* DEALINGS IN THE SOFTWARE.
|
|
|
|
*
|
|
|
|
* Author: Peter Hutterer, University of South Australia, NICTA
|
|
|
|
*/
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
*
|
|
|
|
* Request change in the device hierarchy.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_DIX_CONFIG_H
|
|
|
|
#include <dix-config.h>
|
|
|
|
#endif
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
#include <X11/X.h> /* for inputstr.h */
|
|
|
|
#include <X11/Xproto.h> /* Request macro */
|
|
|
|
#include "inputstr.h" /* DeviceIntPtr */
|
|
|
|
#include "windowstr.h" /* window structure */
|
|
|
|
#include "scrnintstr.h" /* screen structure */
|
2010-07-27 13:02:24 -06:00
|
|
|
#include <X11/extensions/XI.h>
|
|
|
|
#include <X11/extensions/XI2proto.h>
|
|
|
|
#include <X11/extensions/geproto.h>
|
|
|
|
#include "extnsionst.h"
|
|
|
|
#include "exevents.h"
|
|
|
|
#include "exglobals.h"
|
|
|
|
#include "geext.h"
|
|
|
|
#include "xace.h"
|
2012-06-10 07:21:05 -06:00
|
|
|
#include "xiquerydevice.h" /* for GetDeviceUse */
|
2010-07-27 13:02:24 -06:00
|
|
|
|
|
|
|
#include "xkbsrv.h"
|
|
|
|
|
|
|
|
#include "xichangehierarchy.h"
|
2013-06-07 11:28:45 -06:00
|
|
|
#include "xibarriers.h"
|
2010-07-27 13:02:24 -06:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Send the current state of the device hierarchy to all clients.
|
|
|
|
*/
|
2012-06-10 07:21:05 -06:00
|
|
|
void
|
|
|
|
XISendDeviceHierarchyEvent(int flags[MAXDEVICES])
|
2010-07-27 13:02:24 -06:00
|
|
|
{
|
|
|
|
xXIHierarchyEvent *ev;
|
|
|
|
xXIHierarchyInfo *info;
|
|
|
|
DeviceIntRec dummyDev;
|
|
|
|
DeviceIntPtr dev;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (!flags)
|
|
|
|
return;
|
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
ev = calloc(1, sizeof(xXIHierarchyEvent) +
|
2012-06-10 07:21:05 -06:00
|
|
|
MAXDEVICES * sizeof(xXIHierarchyInfo));
|
2011-11-05 07:32:40 -06:00
|
|
|
if (!ev)
|
|
|
|
return;
|
2010-07-27 13:02:24 -06:00
|
|
|
ev->type = GenericEvent;
|
|
|
|
ev->extension = IReqCode;
|
|
|
|
ev->evtype = XI_HierarchyChanged;
|
|
|
|
ev->time = GetTimeInMillis();
|
|
|
|
ev->flags = 0;
|
|
|
|
ev->num_info = inputInfo.numDevices;
|
|
|
|
|
2013-06-07 11:28:45 -06:00
|
|
|
info = (xXIHierarchyInfo *) &ev[1];
|
2012-06-10 07:21:05 -06:00
|
|
|
for (dev = inputInfo.devices; dev; dev = dev->next) {
|
2010-07-27 13:02:24 -06:00
|
|
|
info->deviceid = dev->id;
|
|
|
|
info->enabled = dev->enabled;
|
|
|
|
info->use = GetDeviceUse(dev, &info->attachment);
|
|
|
|
info->flags = flags[dev->id];
|
|
|
|
ev->flags |= info->flags;
|
|
|
|
info++;
|
|
|
|
}
|
2012-06-10 07:21:05 -06:00
|
|
|
for (dev = inputInfo.off_devices; dev; dev = dev->next) {
|
2010-07-27 13:02:24 -06:00
|
|
|
info->deviceid = dev->id;
|
|
|
|
info->enabled = dev->enabled;
|
|
|
|
info->use = GetDeviceUse(dev, &info->attachment);
|
|
|
|
info->flags = flags[dev->id];
|
|
|
|
ev->flags |= info->flags;
|
|
|
|
info++;
|
|
|
|
}
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
for (i = 0; i < MAXDEVICES; i++) {
|
|
|
|
if (flags[i] & (XIMasterRemoved | XISlaveRemoved)) {
|
2010-07-27 13:02:24 -06:00
|
|
|
info->deviceid = i;
|
|
|
|
info->enabled = FALSE;
|
|
|
|
info->flags = flags[i];
|
|
|
|
info->use = 0;
|
|
|
|
ev->flags |= info->flags;
|
|
|
|
ev->num_info++;
|
|
|
|
info++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ev->length = bytes_to_int32(ev->num_info * sizeof(xXIHierarchyInfo));
|
|
|
|
|
2011-11-05 07:32:40 -06:00
|
|
|
memset(&dummyDev, 0, sizeof(dummyDev));
|
2010-07-27 13:02:24 -06:00
|
|
|
dummyDev.id = XIAllDevices;
|
2011-11-05 07:32:40 -06:00
|
|
|
dummyDev.type = SLAVE;
|
2012-06-10 07:21:05 -06:00
|
|
|
SendEventToAllWindows(&dummyDev, (XI_HierarchyChangedMask >> 8),
|
|
|
|
(xEvent *) ev, 1);
|
2010-12-05 08:36:02 -07:00
|
|
|
free(ev);
|
2010-07-27 13:02:24 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
*
|
|
|
|
* This procedure allows a client to change the device hierarchy through
|
|
|
|
* adding new master devices, removing them, etc.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2019-07-27 01:57:06 -06:00
|
|
|
int _X_COLD
|
2012-06-10 07:21:05 -06:00
|
|
|
SProcXIChangeHierarchy(ClientPtr client)
|
2010-07-27 13:02:24 -06:00
|
|
|
{
|
|
|
|
REQUEST(xXIChangeHierarchyReq);
|
2012-06-10 07:21:05 -06:00
|
|
|
swaps(&stuff->length);
|
2010-07-27 13:02:24 -06:00
|
|
|
return (ProcXIChangeHierarchy(client));
|
|
|
|
}
|
|
|
|
|
2011-11-05 07:32:40 -06:00
|
|
|
static int
|
2012-06-10 07:21:05 -06:00
|
|
|
add_master(ClientPtr client, xXIAddMasterInfo * c, int flags[MAXDEVICES])
|
2011-11-05 07:32:40 -06:00
|
|
|
{
|
|
|
|
DeviceIntPtr ptr, keybd, XTestptr, XTestkeybd;
|
2012-06-10 07:21:05 -06:00
|
|
|
char *name;
|
2011-11-05 07:32:40 -06:00
|
|
|
int rc;
|
|
|
|
|
|
|
|
name = calloc(c->name_len + 1, sizeof(char));
|
2014-05-02 13:27:46 -06:00
|
|
|
if (name == NULL) {
|
|
|
|
rc = BadAlloc;
|
|
|
|
goto unwind;
|
|
|
|
}
|
2012-06-10 07:21:05 -06:00
|
|
|
strncpy(name, (char *) &c[1], c->name_len);
|
2011-11-05 07:32:40 -06:00
|
|
|
|
|
|
|
rc = AllocDevicePair(client, name, &ptr, &keybd,
|
|
|
|
CorePointerProc, CoreKeyboardProc, TRUE);
|
|
|
|
if (rc != Success)
|
|
|
|
goto unwind;
|
|
|
|
|
|
|
|
if (!c->send_core)
|
2012-06-10 07:21:05 -06:00
|
|
|
ptr->coreEvents = keybd->coreEvents = FALSE;
|
2011-11-05 07:32:40 -06:00
|
|
|
|
|
|
|
/* Allocate virtual slave devices for xtest events */
|
|
|
|
rc = AllocXTestDevice(client, name, &XTestptr, &XTestkeybd, ptr, keybd);
|
2012-06-10 07:21:05 -06:00
|
|
|
if (rc != Success) {
|
2011-11-05 07:32:40 -06:00
|
|
|
DeleteInputDeviceRequest(ptr);
|
|
|
|
DeleteInputDeviceRequest(keybd);
|
|
|
|
goto unwind;
|
|
|
|
}
|
|
|
|
|
|
|
|
ActivateDevice(ptr, FALSE);
|
|
|
|
ActivateDevice(keybd, FALSE);
|
|
|
|
flags[ptr->id] |= XIMasterAdded;
|
|
|
|
flags[keybd->id] |= XIMasterAdded;
|
|
|
|
|
|
|
|
ActivateDevice(XTestptr, FALSE);
|
|
|
|
ActivateDevice(XTestkeybd, FALSE);
|
|
|
|
flags[XTestptr->id] |= XISlaveAdded;
|
|
|
|
flags[XTestkeybd->id] |= XISlaveAdded;
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (c->enable) {
|
2011-11-05 07:32:40 -06:00
|
|
|
EnableDevice(ptr, FALSE);
|
|
|
|
EnableDevice(keybd, FALSE);
|
|
|
|
flags[ptr->id] |= XIDeviceEnabled;
|
|
|
|
flags[keybd->id] |= XIDeviceEnabled;
|
|
|
|
|
|
|
|
EnableDevice(XTestptr, FALSE);
|
|
|
|
EnableDevice(XTestkeybd, FALSE);
|
|
|
|
flags[XTestptr->id] |= XIDeviceEnabled;
|
|
|
|
flags[XTestkeybd->id] |= XIDeviceEnabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Attach the XTest virtual devices to the newly
|
|
|
|
created master device */
|
|
|
|
AttachDevice(NULL, XTestptr, ptr);
|
|
|
|
AttachDevice(NULL, XTestkeybd, keybd);
|
|
|
|
flags[XTestptr->id] |= XISlaveAttached;
|
|
|
|
flags[XTestkeybd->id] |= XISlaveAttached;
|
|
|
|
|
2017-12-08 08:01:59 -07:00
|
|
|
for (int i = 0; i < currentMaxClients; i++)
|
|
|
|
XIBarrierNewMasterDevice(clients[i], ptr->id);
|
2013-06-07 11:28:45 -06:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
unwind:
|
2011-11-05 07:32:40 -06:00
|
|
|
free(name);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2012-01-31 00:52:35 -07:00
|
|
|
static void
|
|
|
|
disable_clientpointer(DeviceIntPtr dev)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
for (i = 0; i < currentMaxClients; i++) {
|
2012-01-31 00:52:35 -07:00
|
|
|
ClientPtr client = clients[i];
|
2012-06-10 07:21:05 -06:00
|
|
|
|
2012-01-31 00:52:35 -07:00
|
|
|
if (client && client->clientPtr == dev)
|
|
|
|
client->clientPtr = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-05 07:32:40 -06:00
|
|
|
static int
|
2012-06-10 07:21:05 -06:00
|
|
|
remove_master(ClientPtr client, xXIRemoveMasterInfo * r, int flags[MAXDEVICES])
|
2011-11-05 07:32:40 -06:00
|
|
|
{
|
|
|
|
DeviceIntPtr ptr, keybd, XTestptr, XTestkeybd;
|
|
|
|
int rc = Success;
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (r->return_mode != XIAttachToMaster && r->return_mode != XIFloating)
|
2011-11-05 07:32:40 -06:00
|
|
|
return BadValue;
|
|
|
|
|
|
|
|
rc = dixLookupDevice(&ptr, r->deviceid, client, DixDestroyAccess);
|
|
|
|
if (rc != Success)
|
|
|
|
goto unwind;
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (!IsMaster(ptr)) {
|
2011-11-05 07:32:40 -06:00
|
|
|
client->errorValue = r->deviceid;
|
|
|
|
rc = BadDevice;
|
|
|
|
goto unwind;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* XXX: For now, don't allow removal of VCP, VCK */
|
2012-06-10 07:21:05 -06:00
|
|
|
if (ptr == inputInfo.pointer ||ptr == inputInfo.keyboard) {
|
2011-11-05 07:32:40 -06:00
|
|
|
rc = BadDevice;
|
|
|
|
goto unwind;
|
|
|
|
}
|
|
|
|
|
|
|
|
ptr = GetMaster(ptr, MASTER_POINTER);
|
|
|
|
rc = dixLookupDevice(&ptr, ptr->id, client, DixDestroyAccess);
|
|
|
|
if (rc != Success)
|
|
|
|
goto unwind;
|
|
|
|
keybd = GetMaster(ptr, MASTER_KEYBOARD);
|
|
|
|
rc = dixLookupDevice(&keybd, keybd->id, client, DixDestroyAccess);
|
|
|
|
if (rc != Success)
|
|
|
|
goto unwind;
|
|
|
|
|
|
|
|
XTestptr = GetXTestDevice(ptr);
|
|
|
|
rc = dixLookupDevice(&XTestptr, XTestptr->id, client, DixDestroyAccess);
|
|
|
|
if (rc != Success)
|
|
|
|
goto unwind;
|
|
|
|
|
|
|
|
XTestkeybd = GetXTestDevice(keybd);
|
2012-06-10 07:21:05 -06:00
|
|
|
rc = dixLookupDevice(&XTestkeybd, XTestkeybd->id, client, DixDestroyAccess);
|
2011-11-05 07:32:40 -06:00
|
|
|
if (rc != Success)
|
|
|
|
goto unwind;
|
|
|
|
|
2012-01-31 00:52:35 -07:00
|
|
|
disable_clientpointer(ptr);
|
|
|
|
|
2011-11-05 07:32:40 -06:00
|
|
|
/* Disabling sends the devices floating, reattach them if
|
|
|
|
* desired. */
|
2012-06-10 07:21:05 -06:00
|
|
|
if (r->return_mode == XIAttachToMaster) {
|
|
|
|
DeviceIntPtr attached, newptr, newkeybd;
|
2011-11-05 07:32:40 -06:00
|
|
|
|
|
|
|
rc = dixLookupDevice(&newptr, r->return_pointer, client, DixAddAccess);
|
|
|
|
if (rc != Success)
|
|
|
|
goto unwind;
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (!IsMaster(newptr)) {
|
2011-11-05 07:32:40 -06:00
|
|
|
client->errorValue = r->return_pointer;
|
|
|
|
rc = BadDevice;
|
|
|
|
goto unwind;
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = dixLookupDevice(&newkeybd, r->return_keyboard,
|
|
|
|
client, DixAddAccess);
|
|
|
|
if (rc != Success)
|
|
|
|
goto unwind;
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (!IsMaster(newkeybd)) {
|
2011-11-05 07:32:40 -06:00
|
|
|
client->errorValue = r->return_keyboard;
|
|
|
|
rc = BadDevice;
|
|
|
|
goto unwind;
|
|
|
|
}
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
for (attached = inputInfo.devices; attached; attached = attached->next) {
|
2011-11-05 07:32:40 -06:00
|
|
|
if (!IsMaster(attached)) {
|
2012-06-10 07:21:05 -06:00
|
|
|
if (GetMaster(attached, MASTER_ATTACHED) == ptr) {
|
2011-11-05 07:32:40 -06:00
|
|
|
AttachDevice(client, attached, newptr);
|
|
|
|
flags[attached->id] |= XISlaveAttached;
|
|
|
|
}
|
2012-06-10 07:21:05 -06:00
|
|
|
if (GetMaster(attached, MASTER_ATTACHED) == keybd) {
|
2011-11-05 07:32:40 -06:00
|
|
|
AttachDevice(client, attached, newkeybd);
|
|
|
|
flags[attached->id] |= XISlaveAttached;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-08 08:01:59 -07:00
|
|
|
for (int i = 0; i < currentMaxClients; i++)
|
|
|
|
XIBarrierRemoveMasterDevice(clients[i], ptr->id);
|
2011-11-05 07:32:40 -06:00
|
|
|
|
|
|
|
/* disable the remove the devices, XTest devices must be done first
|
|
|
|
else the sprites they rely on will be destroyed */
|
|
|
|
DisableDevice(XTestptr, FALSE);
|
|
|
|
DisableDevice(XTestkeybd, FALSE);
|
|
|
|
DisableDevice(keybd, FALSE);
|
|
|
|
DisableDevice(ptr, FALSE);
|
|
|
|
flags[XTestptr->id] |= XIDeviceDisabled | XISlaveDetached;
|
|
|
|
flags[XTestkeybd->id] |= XIDeviceDisabled | XISlaveDetached;
|
|
|
|
flags[keybd->id] |= XIDeviceDisabled;
|
|
|
|
flags[ptr->id] |= XIDeviceDisabled;
|
|
|
|
|
|
|
|
flags[XTestptr->id] |= XISlaveRemoved;
|
|
|
|
flags[XTestkeybd->id] |= XISlaveRemoved;
|
|
|
|
flags[keybd->id] |= XIMasterRemoved;
|
|
|
|
flags[ptr->id] |= XIMasterRemoved;
|
|
|
|
|
2013-06-07 11:28:45 -06:00
|
|
|
RemoveDevice(XTestptr, FALSE);
|
|
|
|
RemoveDevice(XTestkeybd, FALSE);
|
|
|
|
RemoveDevice(keybd, FALSE);
|
|
|
|
RemoveDevice(ptr, FALSE);
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
unwind:
|
2011-11-05 07:32:40 -06:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2012-06-10 07:21:05 -06:00
|
|
|
detach_slave(ClientPtr client, xXIDetachSlaveInfo * c, int flags[MAXDEVICES])
|
2011-11-05 07:32:40 -06:00
|
|
|
{
|
|
|
|
DeviceIntPtr dev;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
rc = dixLookupDevice(&dev, c->deviceid, client, DixManageAccess);
|
|
|
|
if (rc != Success)
|
|
|
|
goto unwind;
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (IsMaster(dev)) {
|
2011-11-05 07:32:40 -06:00
|
|
|
client->errorValue = c->deviceid;
|
|
|
|
rc = BadDevice;
|
|
|
|
goto unwind;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Don't allow changes to XTest Devices, these are fixed */
|
2012-06-10 07:21:05 -06:00
|
|
|
if (IsXTestDevice(dev, NULL)) {
|
2011-11-05 07:32:40 -06:00
|
|
|
client->errorValue = c->deviceid;
|
|
|
|
rc = BadDevice;
|
|
|
|
goto unwind;
|
|
|
|
}
|
|
|
|
|
|
|
|
ReleaseButtonsAndKeys(dev);
|
|
|
|
AttachDevice(client, dev, NULL);
|
|
|
|
flags[dev->id] |= XISlaveDetached;
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
unwind:
|
2011-11-05 07:32:40 -06:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2012-06-10 07:21:05 -06:00
|
|
|
attach_slave(ClientPtr client, xXIAttachSlaveInfo * c, int flags[MAXDEVICES])
|
2011-11-05 07:32:40 -06:00
|
|
|
{
|
|
|
|
DeviceIntPtr dev;
|
|
|
|
DeviceIntPtr newmaster;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
rc = dixLookupDevice(&dev, c->deviceid, client, DixManageAccess);
|
|
|
|
if (rc != Success)
|
|
|
|
goto unwind;
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (IsMaster(dev)) {
|
2011-11-05 07:32:40 -06:00
|
|
|
client->errorValue = c->deviceid;
|
|
|
|
rc = BadDevice;
|
|
|
|
goto unwind;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Don't allow changes to XTest Devices, these are fixed */
|
2012-06-10 07:21:05 -06:00
|
|
|
if (IsXTestDevice(dev, NULL)) {
|
2011-11-05 07:32:40 -06:00
|
|
|
client->errorValue = c->deviceid;
|
|
|
|
rc = BadDevice;
|
|
|
|
goto unwind;
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = dixLookupDevice(&newmaster, c->new_master, client, DixAddAccess);
|
|
|
|
if (rc != Success)
|
|
|
|
goto unwind;
|
2012-06-10 07:21:05 -06:00
|
|
|
if (!IsMaster(newmaster)) {
|
2011-11-05 07:32:40 -06:00
|
|
|
client->errorValue = c->new_master;
|
|
|
|
rc = BadDevice;
|
|
|
|
goto unwind;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!((IsPointerDevice(newmaster) && IsPointerDevice(dev)) ||
|
2012-06-10 07:21:05 -06:00
|
|
|
(IsKeyboardDevice(newmaster) && IsKeyboardDevice(dev)))) {
|
2011-11-05 07:32:40 -06:00
|
|
|
rc = BadDevice;
|
|
|
|
goto unwind;
|
|
|
|
}
|
|
|
|
|
|
|
|
ReleaseButtonsAndKeys(dev);
|
|
|
|
AttachDevice(client, dev, newmaster);
|
|
|
|
flags[dev->id] |= XISlaveAttached;
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
unwind:
|
2011-11-05 07:32:40 -06:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
#define SWAPIF(cmd) if (client->swapped) { cmd; }
|
|
|
|
|
|
|
|
int
|
|
|
|
ProcXIChangeHierarchy(ClientPtr client)
|
|
|
|
{
|
|
|
|
xXIAnyHierarchyChangeInfo *any;
|
2014-12-09 10:58:52 -07:00
|
|
|
size_t len; /* length of data remaining in request */
|
2010-07-27 13:02:24 -06:00
|
|
|
int rc = Success;
|
2012-06-10 07:21:05 -06:00
|
|
|
int flags[MAXDEVICES] = { 0 };
|
2010-07-27 13:02:24 -06:00
|
|
|
|
|
|
|
REQUEST(xXIChangeHierarchyReq);
|
|
|
|
REQUEST_AT_LEAST_SIZE(xXIChangeHierarchyReq);
|
|
|
|
|
|
|
|
if (!stuff->num_changes)
|
|
|
|
return rc;
|
|
|
|
|
2017-10-14 03:32:30 -06:00
|
|
|
len = ((size_t)stuff->length << 2) - sizeof(xXIChangeHierarchyReq);
|
2014-12-09 10:58:52 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
any = (xXIAnyHierarchyChangeInfo *) &stuff[1];
|
|
|
|
while (stuff->num_changes--) {
|
2014-12-09 10:58:52 -07:00
|
|
|
if (len < sizeof(xXIAnyHierarchyChangeInfo)) {
|
|
|
|
rc = BadLength;
|
|
|
|
goto unwind;
|
|
|
|
}
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
SWAPIF(swaps(&any->type));
|
|
|
|
SWAPIF(swaps(&any->length));
|
2010-07-27 13:02:24 -06:00
|
|
|
|
2016-05-29 06:02:34 -06:00
|
|
|
if (len < ((size_t)any->length << 2))
|
2010-07-27 13:02:24 -06:00
|
|
|
return BadLength;
|
|
|
|
|
2014-12-09 10:58:52 -07:00
|
|
|
#define CHANGE_SIZE_MATCH(type) \
|
|
|
|
do { \
|
|
|
|
if ((len < sizeof(type)) || (any->length != (sizeof(type) >> 2))) { \
|
|
|
|
rc = BadLength; \
|
|
|
|
goto unwind; \
|
|
|
|
} \
|
|
|
|
} while(0)
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
switch (any->type) {
|
|
|
|
case XIAddMaster:
|
2010-07-27 13:02:24 -06:00
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
xXIAddMasterInfo *c = (xXIAddMasterInfo *) any;
|
|
|
|
|
2014-12-09 10:58:52 -07:00
|
|
|
/* Variable length, due to appended name string */
|
|
|
|
if (len < sizeof(xXIAddMasterInfo)) {
|
|
|
|
rc = BadLength;
|
|
|
|
goto unwind;
|
|
|
|
}
|
2012-06-10 07:21:05 -06:00
|
|
|
SWAPIF(swaps(&c->name_len));
|
2014-12-09 10:58:52 -07:00
|
|
|
if (c->name_len > (len - sizeof(xXIAddMasterInfo))) {
|
|
|
|
rc = BadLength;
|
|
|
|
goto unwind;
|
|
|
|
}
|
2012-06-10 07:21:05 -06:00
|
|
|
|
|
|
|
rc = add_master(client, c, flags);
|
|
|
|
if (rc != Success)
|
|
|
|
goto unwind;
|
2010-07-27 13:02:24 -06:00
|
|
|
}
|
2012-06-10 07:21:05 -06:00
|
|
|
break;
|
|
|
|
case XIRemoveMaster:
|
|
|
|
{
|
|
|
|
xXIRemoveMasterInfo *r = (xXIRemoveMasterInfo *) any;
|
|
|
|
|
2014-12-09 10:58:52 -07:00
|
|
|
CHANGE_SIZE_MATCH(xXIRemoveMasterInfo);
|
2012-06-10 07:21:05 -06:00
|
|
|
rc = remove_master(client, r, flags);
|
|
|
|
if (rc != Success)
|
|
|
|
goto unwind;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case XIDetachSlave:
|
|
|
|
{
|
|
|
|
xXIDetachSlaveInfo *c = (xXIDetachSlaveInfo *) any;
|
2010-07-27 13:02:24 -06:00
|
|
|
|
2014-12-09 10:58:52 -07:00
|
|
|
CHANGE_SIZE_MATCH(xXIDetachSlaveInfo);
|
2012-06-10 07:21:05 -06:00
|
|
|
rc = detach_slave(client, c, flags);
|
|
|
|
if (rc != Success)
|
|
|
|
goto unwind;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case XIAttachSlave:
|
|
|
|
{
|
|
|
|
xXIAttachSlaveInfo *c = (xXIAttachSlaveInfo *) any;
|
|
|
|
|
2014-12-09 10:58:52 -07:00
|
|
|
CHANGE_SIZE_MATCH(xXIAttachSlaveInfo);
|
2012-06-10 07:21:05 -06:00
|
|
|
rc = attach_slave(client, c, flags);
|
|
|
|
if (rc != Success)
|
|
|
|
goto unwind;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-12-09 10:58:52 -07:00
|
|
|
len -= any->length * 4;
|
2012-06-10 07:21:05 -06:00
|
|
|
any = (xXIAnyHierarchyChangeInfo *) ((char *) any + any->length * 4);
|
2010-07-27 13:02:24 -06:00
|
|
|
}
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
unwind:
|
2010-07-27 13:02:24 -06:00
|
|
|
|
|
|
|
XISendDeviceHierarchyEvent(flags);
|
|
|
|
return rc;
|
|
|
|
}
|