2007-10-19 07:06:37 +02:00
|
|
|
/*
|
2008-04-25 07:20:24 +02:00
|
|
|
* Copyright 2007-2008 Peter Hutterer
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
2008-05-21 14:21:27 +02:00
|
|
|
* Author: Peter Hutterer, University of South Australia, NICTA
|
2008-04-25 07:20:24 +02:00
|
|
|
*/
|
2007-10-19 07:06:37 +02:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
*
|
|
|
|
* Request change in the device hierarchy.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_DIX_CONFIG_H
|
|
|
|
#include <dix-config.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#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 */
|
|
|
|
#include <X11/extensions/XI.h>
|
|
|
|
#include <X11/extensions/XIproto.h>
|
|
|
|
#include <X11/extensions/geproto.h>
|
|
|
|
#include "extnsionst.h"
|
|
|
|
#include "exevents.h"
|
|
|
|
#include "exglobals.h"
|
|
|
|
#include "geext.h"
|
2008-01-21 14:13:53 +01:00
|
|
|
#include "xace.h"
|
2007-10-19 07:06:37 +02:00
|
|
|
|
2009-01-11 08:17:41 +01:00
|
|
|
#include "xkbsrv.h"
|
|
|
|
|
2007-10-19 07:06:37 +02:00
|
|
|
#include "chdevhier.h"
|
|
|
|
|
2009-03-27 07:14:15 +01:00
|
|
|
extern DevPrivateKey XTstDevicePrivateKey;
|
|
|
|
|
2007-10-19 07:06:37 +02:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
*
|
|
|
|
* This procedure allows a client to change the device hierarchy through
|
|
|
|
* adding new master devices, removing them, etc.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
int SProcXChangeDeviceHierarchy(ClientPtr client)
|
|
|
|
{
|
|
|
|
char n;
|
|
|
|
|
|
|
|
REQUEST(xChangeDeviceHierarchyReq);
|
|
|
|
swaps(&stuff->length, n);
|
|
|
|
return (ProcXChangeDeviceHierarchy(client));
|
|
|
|
}
|
|
|
|
|
|
|
|
#define SWAPIF(cmd) if (client->swapped) { cmd; }
|
|
|
|
|
|
|
|
int
|
|
|
|
ProcXChangeDeviceHierarchy(ClientPtr client)
|
|
|
|
{
|
2009-03-27 07:14:15 +01:00
|
|
|
DeviceIntPtr ptr, keybd, xtstptr, xtstkeybd;
|
2007-11-08 08:24:17 +01:00
|
|
|
DeviceIntRec dummyDev;
|
2007-10-19 07:06:37 +02:00
|
|
|
xAnyHierarchyChangeInfo *any;
|
|
|
|
int required_len = sizeof(xChangeDeviceHierarchyReq);
|
|
|
|
char n;
|
2008-06-14 04:41:58 +02:00
|
|
|
int rc = Success;
|
2008-02-18 07:16:07 +01:00
|
|
|
int nchanges = 0;
|
2007-11-08 08:24:17 +01:00
|
|
|
deviceHierarchyChangedEvent ev;
|
2007-10-19 07:06:37 +02:00
|
|
|
|
|
|
|
REQUEST(xChangeDeviceHierarchyReq);
|
|
|
|
REQUEST_AT_LEAST_SIZE(xChangeDeviceHierarchyReq);
|
|
|
|
|
|
|
|
any = (xAnyHierarchyChangeInfo*)&stuff[1];
|
|
|
|
while(stuff->num_changes--)
|
|
|
|
{
|
|
|
|
SWAPIF(swapl(&any->type, n));
|
|
|
|
SWAPIF(swaps(&any->length, n));
|
|
|
|
|
|
|
|
required_len += any->length;
|
|
|
|
if ((stuff->length * 4) < required_len)
|
|
|
|
return BadLength;
|
|
|
|
|
|
|
|
switch(any->type)
|
|
|
|
{
|
|
|
|
case CH_CreateMasterDevice:
|
|
|
|
{
|
|
|
|
xCreateMasterInfo* c = (xCreateMasterInfo*)any;
|
|
|
|
char* name;
|
2008-01-18 08:22:38 +01:00
|
|
|
|
2007-10-19 07:06:37 +02:00
|
|
|
SWAPIF(swaps(&c->namelen, n));
|
|
|
|
name = xcalloc(c->namelen + 1, sizeof(char));
|
|
|
|
strncpy(name, (char*)&c[1], c->namelen);
|
|
|
|
|
2008-01-18 08:22:38 +01:00
|
|
|
|
2009-04-16 07:33:30 +02:00
|
|
|
rc = AllocDevicePair(client, name, &ptr, &keybd, TRUE);
|
2008-01-21 14:13:53 +01:00
|
|
|
if (rc != Success)
|
2007-10-19 07:06:37 +02:00
|
|
|
{
|
|
|
|
xfree(name);
|
2008-02-18 07:16:07 +01:00
|
|
|
goto unwind;
|
2007-10-19 07:06:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!c->sendCore)
|
|
|
|
ptr->coreEvents = keybd->coreEvents = FALSE;
|
2009-01-29 12:42:57 +01:00
|
|
|
|
2009-03-27 07:14:15 +01:00
|
|
|
/* Allocate virtual slave devices for xtest events */
|
|
|
|
rc = AllocXtstDevice(client, name, &xtstptr, &xtstkeybd);
|
|
|
|
if (rc != Success)
|
|
|
|
{
|
|
|
|
|
|
|
|
xfree(name);
|
|
|
|
goto unwind;
|
|
|
|
}
|
|
|
|
|
2007-10-19 07:06:37 +02:00
|
|
|
ActivateDevice(ptr);
|
|
|
|
ActivateDevice(keybd);
|
2009-03-27 07:14:15 +01:00
|
|
|
ActivateDevice(xtstptr);
|
|
|
|
ActivateDevice(xtstkeybd);
|
2007-10-19 07:06:37 +02:00
|
|
|
|
|
|
|
if (c->enable)
|
|
|
|
{
|
|
|
|
EnableDevice(ptr);
|
|
|
|
EnableDevice(keybd);
|
2009-03-27 07:14:15 +01:00
|
|
|
EnableDevice(xtstptr);
|
|
|
|
EnableDevice(xtstkeybd);
|
2007-10-19 07:06:37 +02:00
|
|
|
}
|
2009-03-27 07:14:15 +01:00
|
|
|
|
|
|
|
/* Attach the XTest virtual devices to the newly
|
|
|
|
created master device */
|
|
|
|
AttachDevice(NULL, xtstptr, ptr);
|
|
|
|
AttachDevice(NULL, xtstkeybd, keybd);
|
|
|
|
|
2007-10-19 07:06:37 +02:00
|
|
|
xfree(name);
|
2008-02-18 07:16:07 +01:00
|
|
|
nchanges++;
|
2007-10-19 07:06:37 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case CH_RemoveMasterDevice:
|
|
|
|
{
|
|
|
|
xRemoveMasterInfo* r = (xRemoveMasterInfo*)any;
|
2009-03-27 07:14:15 +01:00
|
|
|
DeviceIntPtr xtstdevice;
|
2007-10-19 07:06:37 +02:00
|
|
|
|
2007-11-13 07:44:35 +01:00
|
|
|
if (r->returnMode != AttachToMaster &&
|
2007-10-19 07:06:37 +02:00
|
|
|
r->returnMode != Floating)
|
|
|
|
return BadValue;
|
|
|
|
|
2008-01-03 07:34:54 +01:00
|
|
|
rc = dixLookupDevice(&ptr, r->deviceid, client,
|
2008-01-18 08:22:38 +01:00
|
|
|
DixDestroyAccess);
|
2008-01-03 07:34:54 +01:00
|
|
|
if (rc != Success)
|
2008-02-18 07:16:07 +01:00
|
|
|
goto unwind;
|
2008-01-03 07:34:54 +01:00
|
|
|
|
|
|
|
if (!ptr->isMaster)
|
|
|
|
{
|
|
|
|
client->errorValue = r->deviceid;
|
2008-02-18 07:16:07 +01:00
|
|
|
rc = BadDevice;
|
|
|
|
goto unwind;
|
2008-01-03 07:34:54 +01:00
|
|
|
}
|
2007-10-19 07:06:37 +02:00
|
|
|
|
|
|
|
/* XXX: For now, don't allow removal of VCP, VCK */
|
|
|
|
if (ptr == inputInfo.pointer ||
|
|
|
|
ptr == inputInfo.keyboard)
|
2008-02-18 07:16:07 +01:00
|
|
|
{
|
|
|
|
rc = BadDevice;
|
|
|
|
goto unwind;
|
|
|
|
}
|
2007-10-19 07:06:37 +02:00
|
|
|
|
2009-03-27 07:14:15 +01:00
|
|
|
for(xtstdevice = inputInfo.devices; xtstdevice ; xtstdevice = xtstdevice->next )
|
|
|
|
if( !xtstdevice->isMaster && xtstdevice->u.master == ptr &&
|
|
|
|
dixLookupPrivate(&xtstdevice->devPrivates, XTstDevicePrivateKey ))
|
|
|
|
break;
|
|
|
|
|
|
|
|
rc = dixLookupDevice(&xtstptr, xtstdevice->id, client,
|
|
|
|
DixDestroyAccess);
|
|
|
|
if (rc != Success)
|
|
|
|
goto unwind;
|
|
|
|
|
|
|
|
/* find keyboards to destroy */
|
2007-10-19 07:06:37 +02:00
|
|
|
if (IsPointerDevice(ptr))
|
2008-01-18 08:22:38 +01:00
|
|
|
{
|
|
|
|
rc = dixLookupDevice(&keybd,
|
|
|
|
ptr->spriteInfo->paired->id,
|
|
|
|
client,
|
|
|
|
DixDestroyAccess);
|
|
|
|
if (rc != Success)
|
2008-02-18 07:16:07 +01:00
|
|
|
goto unwind;
|
2009-03-27 07:14:15 +01:00
|
|
|
|
2008-01-18 08:22:38 +01:00
|
|
|
}
|
2007-10-19 07:06:37 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
keybd = ptr;
|
2008-01-18 08:22:38 +01:00
|
|
|
rc = dixLookupDevice(&ptr,
|
|
|
|
keybd->spriteInfo->paired->id,
|
|
|
|
client,
|
|
|
|
DixDestroyAccess);
|
|
|
|
if (rc != Success)
|
2008-02-18 07:16:07 +01:00
|
|
|
goto unwind;
|
2009-03-27 07:14:15 +01:00
|
|
|
|
2007-10-19 07:06:37 +02:00
|
|
|
}
|
|
|
|
|
2009-03-27 07:14:15 +01:00
|
|
|
/* handle xtst pointer / keyboard slave devices */
|
|
|
|
if ( IsPointerDevice(xtstptr))
|
|
|
|
{
|
|
|
|
/* Search the matching keyboard */
|
|
|
|
for(xtstdevice = inputInfo.devices; xtstdevice ; xtstdevice = xtstdevice->next )
|
|
|
|
if( !xtstdevice->isMaster &&
|
|
|
|
xtstdevice->u.master == keybd &&
|
|
|
|
IsKeyboardDevice(xtstdevice) &&
|
|
|
|
dixLookupPrivate(&xtstdevice->devPrivates, XTstDevicePrivateKey ))
|
|
|
|
break;
|
|
|
|
|
|
|
|
rc = dixLookupDevice(&xtstkeybd,
|
|
|
|
xtstdevice->id,
|
|
|
|
client,
|
|
|
|
DixDestroyAccess);
|
|
|
|
|
|
|
|
if (rc != Success)
|
|
|
|
goto unwind;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
xtstkeybd = xtstptr;
|
|
|
|
/* Search the matching pointer */
|
|
|
|
for(xtstdevice = inputInfo.devices; xtstdevice ; xtstdevice = xtstdevice->next )
|
|
|
|
if( !xtstdevice->isMaster &&
|
|
|
|
xtstdevice->u.master == ptr &&
|
|
|
|
IsPointerDevice(xtstdevice) &&
|
|
|
|
dixLookupPrivate(&xtstdevice->devPrivates, XTstDevicePrivateKey )
|
|
|
|
)
|
|
|
|
break;
|
|
|
|
rc = dixLookupDevice(&xtstptr,
|
|
|
|
xtstdevice->id,
|
|
|
|
client,
|
|
|
|
DixDestroyAccess);
|
|
|
|
|
|
|
|
if (rc != Success)
|
|
|
|
goto unwind;
|
|
|
|
}
|
2008-01-18 08:22:38 +01:00
|
|
|
|
2007-10-19 07:06:37 +02:00
|
|
|
/* Disabling sends the devices floating, reattach them if
|
|
|
|
* desired. */
|
|
|
|
if (r->returnMode == AttachToMaster)
|
|
|
|
{
|
2007-11-13 07:44:35 +01:00
|
|
|
DeviceIntPtr attached,
|
|
|
|
newptr,
|
2007-10-19 07:06:37 +02:00
|
|
|
newkeybd;
|
|
|
|
|
2008-01-03 07:34:54 +01:00
|
|
|
rc = dixLookupDevice(&newptr, r->returnPointer,
|
|
|
|
client, DixWriteAccess);
|
|
|
|
if (rc != Success)
|
2008-02-18 07:16:07 +01:00
|
|
|
goto unwind;
|
2008-01-03 07:34:54 +01:00
|
|
|
|
|
|
|
if (!newptr->isMaster)
|
|
|
|
{
|
|
|
|
client->errorValue = r->returnPointer;
|
2008-02-18 07:16:07 +01:00
|
|
|
rc = BadDevice;
|
|
|
|
goto unwind;
|
2008-01-03 07:34:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
rc = dixLookupDevice(&newkeybd, r->returnKeyboard,
|
|
|
|
client, DixWriteAccess);
|
|
|
|
if (rc != Success)
|
2008-02-18 07:16:07 +01:00
|
|
|
goto unwind;
|
2008-01-03 07:34:54 +01:00
|
|
|
|
|
|
|
if (!newkeybd->isMaster)
|
|
|
|
{
|
|
|
|
client->errorValue = r->returnKeyboard;
|
2008-02-18 07:16:07 +01:00
|
|
|
rc = BadDevice;
|
|
|
|
goto unwind;
|
2008-01-03 07:34:54 +01:00
|
|
|
}
|
2007-10-19 07:06:37 +02:00
|
|
|
|
2007-11-13 07:44:35 +01:00
|
|
|
for (attached = inputInfo.devices;
|
|
|
|
attached;
|
2007-10-19 07:06:37 +02:00
|
|
|
attached = attached->next)
|
|
|
|
{
|
|
|
|
if (!attached->isMaster) {
|
|
|
|
if (attached->u.master == ptr)
|
|
|
|
AttachDevice(client, attached, newptr);
|
|
|
|
if (attached->u.master == keybd)
|
|
|
|
AttachDevice(client, attached, newkeybd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* can't disable until we removed pairing */
|
|
|
|
keybd->spriteInfo->paired = NULL;
|
|
|
|
ptr->spriteInfo->paired = NULL;
|
2009-03-27 07:14:15 +01:00
|
|
|
xtstptr->spriteInfo->paired = NULL;
|
|
|
|
xtstkeybd->spriteInfo->paired = NULL;
|
|
|
|
|
|
|
|
/* disable the remove the devices, xtst devices must be done first
|
|
|
|
else the sprites they rely on will be destroyed */
|
|
|
|
DisableDevice(xtstptr);
|
|
|
|
DisableDevice(xtstkeybd);
|
2007-10-19 07:06:37 +02:00
|
|
|
DisableDevice(keybd);
|
|
|
|
DisableDevice(ptr);
|
|
|
|
|
2009-03-27 07:14:15 +01:00
|
|
|
RemoveDevice(xtstptr);
|
|
|
|
RemoveDevice(xtstkeybd);
|
2007-10-19 07:06:37 +02:00
|
|
|
RemoveDevice(keybd);
|
|
|
|
RemoveDevice(ptr);
|
2008-02-18 07:16:07 +01:00
|
|
|
nchanges++;
|
2007-10-19 07:06:37 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case CH_ChangeAttachment:
|
|
|
|
{
|
2009-03-27 07:14:15 +01:00
|
|
|
DeviceIntPtr *xtstdevice;
|
|
|
|
|
2007-10-19 07:06:37 +02:00
|
|
|
xChangeAttachmentInfo* c = (xChangeAttachmentInfo*)any;
|
|
|
|
|
2008-01-03 07:34:54 +01:00
|
|
|
rc = dixLookupDevice(&ptr, c->deviceid, client,
|
|
|
|
DixWriteAccess);
|
|
|
|
if (rc != Success)
|
2008-02-18 07:16:07 +01:00
|
|
|
goto unwind;
|
2008-01-03 07:34:54 +01:00
|
|
|
|
|
|
|
if (ptr->isMaster)
|
|
|
|
{
|
|
|
|
client->errorValue = c->deviceid;
|
2008-02-18 07:16:07 +01:00
|
|
|
rc = BadDevice;
|
|
|
|
goto unwind;
|
2008-01-03 07:34:54 +01:00
|
|
|
}
|
2007-10-19 07:06:37 +02:00
|
|
|
|
2009-03-27 07:14:15 +01:00
|
|
|
xtstdevice = dixLookupPrivate( &ptr->devPrivates,
|
|
|
|
XTstDevicePrivateKey );
|
|
|
|
|
|
|
|
/* Don't allow changes to Xtst Devices, these are fixed */
|
|
|
|
if( xtstdevice )
|
|
|
|
{
|
|
|
|
client->errorValue = c->deviceid;
|
|
|
|
rc = BadDevice;
|
|
|
|
goto unwind;
|
|
|
|
}
|
|
|
|
|
2007-10-19 07:06:37 +02:00
|
|
|
if (c->changeMode == Floating)
|
|
|
|
AttachDevice(client, ptr, NULL);
|
|
|
|
else
|
|
|
|
{
|
2008-01-03 07:34:54 +01:00
|
|
|
DeviceIntPtr newmaster;
|
|
|
|
rc = dixLookupDevice(&newmaster, c->newMaster,
|
|
|
|
client, DixWriteAccess);
|
|
|
|
if (rc != Success)
|
2008-02-18 07:16:07 +01:00
|
|
|
goto unwind;
|
2008-01-03 07:34:54 +01:00
|
|
|
if (!newmaster->isMaster)
|
|
|
|
{
|
|
|
|
client->errorValue = c->newMaster;
|
2008-02-18 07:16:07 +01:00
|
|
|
rc = BadDevice;
|
|
|
|
goto unwind;
|
2008-01-03 07:34:54 +01:00
|
|
|
}
|
2007-10-19 07:06:37 +02:00
|
|
|
|
2008-04-10 00:38:54 +02:00
|
|
|
if (!((IsPointerDevice(newmaster) &&
|
|
|
|
IsPointerDevice(ptr)) ||
|
2007-10-19 07:06:37 +02:00
|
|
|
(IsKeyboardDevice(newmaster) &&
|
2008-04-10 00:38:54 +02:00
|
|
|
IsKeyboardDevice(ptr))))
|
2008-02-18 07:16:07 +01:00
|
|
|
{
|
|
|
|
rc = BadDevice;
|
|
|
|
goto unwind;
|
|
|
|
}
|
2007-10-19 07:06:37 +02:00
|
|
|
AttachDevice(client, ptr, newmaster);
|
|
|
|
}
|
2008-02-18 07:16:07 +01:00
|
|
|
nchanges++;
|
2007-10-19 07:06:37 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
any = (xAnyHierarchyChangeInfo*)((char*)any + any->length);
|
|
|
|
}
|
|
|
|
|
2008-02-18 07:16:07 +01:00
|
|
|
unwind:
|
2007-11-08 08:24:17 +01:00
|
|
|
|
2008-02-18 07:16:07 +01:00
|
|
|
if (nchanges > 0) /* even if an error occured, we need to send an event if
|
|
|
|
we changed anything in the hierarchy. */
|
|
|
|
{
|
|
|
|
ev.type = GenericEvent;
|
|
|
|
ev.extension = IReqCode;
|
|
|
|
ev.length = 0;
|
|
|
|
ev.evtype = XI_DeviceHierarchyChangedNotify;
|
|
|
|
ev.time = GetTimeInMillis();
|
|
|
|
|
|
|
|
SendEventToAllWindows(&dummyDev, XI_DeviceHierarchyChangedMask,
|
|
|
|
(xEvent*)&ev, 1);
|
|
|
|
}
|
|
|
|
return rc;
|
2007-10-19 07:06:37 +02:00
|
|
|
}
|
|
|
|
|