input: store the master device's ID in the devPrivate for XTest devices.

Rather than storing a simple boolean in the devPrivate for XTest devices,
store the actual master device's id (since it is constant for the life of
the device anyway).

Callers should use GetXtstDevice now instead of digging around in the
devPrivates themselves.

This patch allows for a cleanup in the creation of new master devices since
GetMaster and GetXtstDevice spare the need for loops, IsPointer checks and
similar.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Acked-by: Benjamin Close <Benjamin.Close@clearchain.com>
This commit is contained in:
Peter Hutterer 2009-06-23 10:50:52 +10:00
parent 1bcc0d3c24
commit 0814f511d5
4 changed files with 64 additions and 77 deletions

View File

@ -56,7 +56,6 @@
extern int DeviceValuator;
extern int DeviceMotionNotify;
extern DevPrivateKey XTstDevicePrivateKey;
#ifdef PANORAMIX
#include "panoramiX.h"
@ -299,14 +298,7 @@ ProcXTestFakeInput(ClientPtr client)
return BadValue;
}
/* When faking core events through XTest, we always fake through the
* virtual test device.
*/
for(it = inputInfo.devices; it ; it = it->next )
if( !IsMaster(it) && it->u.master == dev &&
dixLookupPrivate(&it->devPrivates, XTstDevicePrivateKey ))
break;
dev= it;
dev = GetXtstDevice(dev);
}
/* If the event has a time set, wait for it to pass */

View File

@ -186,8 +186,9 @@ ProcXIChangeHierarchy(ClientPtr client)
if (!c->send_core)
ptr->coreEvents = keybd->coreEvents = FALSE;
/* Allocate virtual slave devices for xtest events */
rc = AllocXtstDevice(client, name, &xtstptr, &xtstkeybd);
/* Allocate virtual slave devices for xtest events */
rc = AllocXtstDevice(client, name, &xtstptr, &xtstkeybd,
ptr, keybd);
if (rc != Success)
{
@ -231,7 +232,6 @@ ProcXIChangeHierarchy(ClientPtr client)
case XIRemoveMaster:
{
xXIRemoveMasterInfo* r = (xXIRemoveMasterInfo*)any;
DeviceIntPtr xtstdevice;
if (r->return_mode != XIAttachToMaster &&
r->return_mode != XIFloating)
@ -257,69 +257,33 @@ ProcXIChangeHierarchy(ClientPtr client)
goto unwind;
}
for(xtstdevice = inputInfo.devices; xtstdevice ; xtstdevice = xtstdevice->next )
if (IsXtstDevice(xtstdevice, ptr))
break;
rc = dixLookupDevice(&xtstptr, xtstdevice->id, client,
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;
/* find keyboards to destroy */
if (IsPointerDevice(ptr))
{
rc = dixLookupDevice(&keybd,
ptr->spriteInfo->paired->id,
client,
DixDestroyAccess);
if (rc != Success)
goto unwind;
xtstptr = GetXtstDevice(ptr);
rc = dixLookupDevice(&xtstptr, xtstptr->id, client,
DixDestroyAccess);
if (rc != Success)
goto unwind;
}
else
{
keybd = ptr;
rc = dixLookupDevice(&ptr,
keybd->spriteInfo->paired->id,
client,
DixDestroyAccess);
if (rc != Success)
goto unwind;
}
/* handle xtst pointer / keyboard slave devices */
if ( IsPointerDevice(xtstptr))
{
/* Search the matching keyboard */
for(xtstdevice = inputInfo.devices; xtstdevice ; xtstdevice = xtstdevice->next )
if(IsKeyboardDevice(xtstdevice) && IsXtstDevice(xtstdevice, keybd))
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(IsPointerDevice(xtstdevice) && IsXtstDevice(xtstdevice, ptr))
break;
rc = dixLookupDevice(&xtstptr,
xtstdevice->id,
client,
DixDestroyAccess);
if (rc != Success)
goto unwind;
}
xtstkeybd = GetXtstDevice(keybd);
rc = dixLookupDevice(&xtstkeybd, xtstkeybd->id, client,
DixDestroyAccess);
if (rc != Success)
goto unwind;
/* Disabling sends the devices floating, reattach them if
* desired. */

View File

@ -639,8 +639,8 @@ InitCoreDevices(void)
is a slave device to inputInfo master devices
*/
if(AllocXtstDevice(serverClient, "Virtual core",
&vxtstpointer,
&vxtstkeyboard) != Success)
&vxtstpointer, &vxtstkeyboard,
inputInfo.pointer, inputInfo.keyboard) != Success)
FatalError("Failed to allocate XTst devices");
if (ActivateDevice(vxtstpointer, TRUE) != Success ||
@ -2570,7 +2570,8 @@ AllocDevicePair (ClientPtr client, char* name,
* still need to be called.
*/
int AllocXtstDevice (ClientPtr client, char* name,
DeviceIntPtr* ptr, DeviceIntPtr* keybd)
DeviceIntPtr* ptr, DeviceIntPtr* keybd,
DeviceIntPtr master_ptr, DeviceIntPtr master_keybd)
{
int retval;
int len = strlen(name);
@ -2581,8 +2582,8 @@ int AllocXtstDevice (ClientPtr client, char* name,
retval = AllocDevicePair( client, xtstname, ptr, keybd, FALSE);
if ( retval == Success ){
dixSetPrivate(&((*ptr)->devPrivates), XTstDevicePrivateKey, (void *)True );
dixSetPrivate(&((*keybd)->devPrivates), XTstDevicePrivateKey,(void *)True);
dixSetPrivate(&((*ptr)->devPrivates), XTstDevicePrivateKey, (void *)master_ptr->id);
dixSetPrivate(&((*keybd)->devPrivates), XTstDevicePrivateKey, (void *)master_keybd->id);
}
xfree( xtstname );
@ -2599,6 +2600,33 @@ int AllocXtstDevice (ClientPtr client, char* name,
BOOL
IsXtstDevice(DeviceIntPtr dev, DeviceIntPtr master)
{
return (!IsMaster(dev) && (!master || dev->u.master == master) &&
( dixLookupPrivate(&dev->devPrivates, XTstDevicePrivateKey) != NULL));
int mid;
void *tmp; /* shut up, gcc! */
if (IsMaster(dev))
return FALSE;
tmp = dixLookupPrivate(&dev->devPrivates, XTstDevicePrivateKey);
mid = (int)tmp;
return (!master || mid == master->id);
}
/**
* @return The X Test virtual device for the given master.
*/
DeviceIntPtr
GetXtstDevice(DeviceIntPtr master)
{
DeviceIntPtr it;
for (it = inputInfo.devices; it; it = it->next)
{
if (IsXtstDevice(it, master))
return it;
}
/* This only happens if master is a slave device. don't do that */
return NULL;
}

View File

@ -496,8 +496,11 @@ extern int change_modmap(ClientPtr client, DeviceIntPtr dev, KeyCode *map,
extern int AllocXtstDevice(ClientPtr client,
char* name,
DeviceIntPtr* ptr,
DeviceIntPtr* keybd);
DeviceIntPtr* keybd,
DeviceIntPtr master_ptr,
DeviceIntPtr master_keybd);
extern BOOL IsXtstDevice(DeviceIntPtr dev, DeviceIntPtr master);
extern DeviceIntPtr GetXtstDevice(DeviceIntPtr master);
/* misc event helpers */
extern Mask GetEventFilter(DeviceIntPtr dev, xEvent *event);