Xi: split hierarchy manipulation into static functions.
No functional changes, just code cleanup to improve readability. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Reviewed-by: Julien Cristau <jcristau@debian.org>
This commit is contained in:
parent
4132b1c591
commit
9b89b91c68
|
@ -136,67 +136,28 @@ int SProcXIChangeHierarchy(ClientPtr client)
|
||||||
return (ProcXIChangeHierarchy(client));
|
return (ProcXIChangeHierarchy(client));
|
||||||
}
|
}
|
||||||
|
|
||||||
#define SWAPIF(cmd) if (client->swapped) { cmd; }
|
static int
|
||||||
|
add_master(ClientPtr client, xXIAddMasterInfo *c, int flags[MAXDEVICES])
|
||||||
int
|
|
||||||
ProcXIChangeHierarchy(ClientPtr client)
|
|
||||||
{
|
{
|
||||||
DeviceIntPtr ptr, keybd, XTestptr, XTestkeybd;
|
DeviceIntPtr ptr, keybd, XTestptr, XTestkeybd;
|
||||||
xXIAnyHierarchyChangeInfo *any;
|
|
||||||
int required_len = sizeof(xXIChangeHierarchyReq);
|
|
||||||
char n;
|
|
||||||
int rc = Success;
|
|
||||||
int flags[MAXDEVICES] = {0};
|
|
||||||
|
|
||||||
REQUEST(xXIChangeHierarchyReq);
|
|
||||||
REQUEST_AT_LEAST_SIZE(xXIChangeHierarchyReq);
|
|
||||||
|
|
||||||
if (!stuff->num_changes)
|
|
||||||
return rc;
|
|
||||||
|
|
||||||
any = (xXIAnyHierarchyChangeInfo*)&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 XIAddMaster:
|
|
||||||
{
|
|
||||||
xXIAddMasterInfo* c = (xXIAddMasterInfo*)any;
|
|
||||||
char* name;
|
char* name;
|
||||||
|
int rc;
|
||||||
|
|
||||||
SWAPIF(swaps(&c->name_len, n));
|
|
||||||
name = calloc(c->name_len + 1, sizeof(char));
|
name = calloc(c->name_len + 1, sizeof(char));
|
||||||
strncpy(name, (char*)&c[1], c->name_len);
|
strncpy(name, (char*)&c[1], c->name_len);
|
||||||
|
|
||||||
|
|
||||||
rc = AllocDevicePair(client, name, &ptr, &keybd,
|
rc = AllocDevicePair(client, name, &ptr, &keybd,
|
||||||
CorePointerProc, CoreKeyboardProc,
|
CorePointerProc, CoreKeyboardProc, TRUE);
|
||||||
TRUE);
|
|
||||||
if (rc != Success)
|
if (rc != Success)
|
||||||
{
|
|
||||||
free(name);
|
|
||||||
goto unwind;
|
goto unwind;
|
||||||
}
|
|
||||||
|
|
||||||
if (!c->send_core)
|
if (!c->send_core)
|
||||||
ptr->coreEvents = keybd->coreEvents = FALSE;
|
ptr->coreEvents = keybd->coreEvents = FALSE;
|
||||||
|
|
||||||
/* Allocate virtual slave devices for xtest events */
|
/* Allocate virtual slave devices for xtest events */
|
||||||
rc = AllocXTestDevice(client, name, &XTestptr, &XTestkeybd,
|
rc = AllocXTestDevice(client, name, &XTestptr, &XTestkeybd, ptr, keybd);
|
||||||
ptr, keybd);
|
|
||||||
if (rc != Success)
|
if (rc != Success)
|
||||||
{
|
|
||||||
|
|
||||||
free(name);
|
|
||||||
goto unwind;
|
goto unwind;
|
||||||
}
|
|
||||||
|
|
||||||
ActivateDevice(ptr, FALSE);
|
ActivateDevice(ptr, FALSE);
|
||||||
ActivateDevice(keybd, FALSE);
|
ActivateDevice(keybd, FALSE);
|
||||||
|
@ -228,19 +189,23 @@ ProcXIChangeHierarchy(ClientPtr client)
|
||||||
flags[XTestptr->id] |= XISlaveAttached;
|
flags[XTestptr->id] |= XISlaveAttached;
|
||||||
flags[XTestkeybd->id] |= XISlaveAttached;
|
flags[XTestkeybd->id] |= XISlaveAttached;
|
||||||
|
|
||||||
|
unwind:
|
||||||
free(name);
|
free(name);
|
||||||
|
return rc;
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
case XIRemoveMaster:
|
static int
|
||||||
|
remove_master(ClientPtr client, xXIRemoveMasterInfo *r,
|
||||||
|
int flags[MAXDEVICES])
|
||||||
{
|
{
|
||||||
xXIRemoveMasterInfo* r = (xXIRemoveMasterInfo*)any;
|
DeviceIntPtr ptr, keybd, XTestptr, XTestkeybd;
|
||||||
|
int rc = Success;
|
||||||
|
|
||||||
if (r->return_mode != XIAttachToMaster &&
|
if (r->return_mode != XIAttachToMaster &&
|
||||||
r->return_mode != XIFloating)
|
r->return_mode != XIFloating)
|
||||||
return BadValue;
|
return BadValue;
|
||||||
|
|
||||||
rc = dixLookupDevice(&ptr, r->deviceid, client,
|
rc = dixLookupDevice(&ptr, r->deviceid, client, DixDestroyAccess);
|
||||||
DixDestroyAccess);
|
|
||||||
if (rc != Success)
|
if (rc != Success)
|
||||||
goto unwind;
|
goto unwind;
|
||||||
|
|
||||||
|
@ -252,8 +217,7 @@ ProcXIChangeHierarchy(ClientPtr client)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* XXX: For now, don't allow removal of VCP, VCK */
|
/* XXX: For now, don't allow removal of VCP, VCK */
|
||||||
if (ptr == inputInfo.pointer ||
|
if (ptr == inputInfo.pointer || ptr == inputInfo.keyboard)
|
||||||
ptr == inputInfo.keyboard)
|
|
||||||
{
|
{
|
||||||
rc = BadDevice;
|
rc = BadDevice;
|
||||||
goto unwind;
|
goto unwind;
|
||||||
|
@ -261,23 +225,16 @@ ProcXIChangeHierarchy(ClientPtr client)
|
||||||
|
|
||||||
|
|
||||||
ptr = GetMaster(ptr, MASTER_POINTER);
|
ptr = GetMaster(ptr, MASTER_POINTER);
|
||||||
rc = dixLookupDevice(&ptr,
|
rc = dixLookupDevice(&ptr, ptr->id, client, DixDestroyAccess);
|
||||||
ptr->id,
|
|
||||||
client,
|
|
||||||
DixDestroyAccess);
|
|
||||||
if (rc != Success)
|
if (rc != Success)
|
||||||
goto unwind;
|
goto unwind;
|
||||||
keybd = GetMaster(ptr, MASTER_KEYBOARD);
|
keybd = GetMaster(ptr, MASTER_KEYBOARD);
|
||||||
rc = dixLookupDevice(&keybd,
|
rc = dixLookupDevice(&keybd, keybd->id, client, DixDestroyAccess);
|
||||||
keybd->id,
|
|
||||||
client,
|
|
||||||
DixDestroyAccess);
|
|
||||||
if (rc != Success)
|
if (rc != Success)
|
||||||
goto unwind;
|
goto unwind;
|
||||||
|
|
||||||
XTestptr = GetXTestDevice(ptr);
|
XTestptr = GetXTestDevice(ptr);
|
||||||
rc = dixLookupDevice(&XTestptr, XTestptr->id, client,
|
rc = dixLookupDevice(&XTestptr, XTestptr->id, client, DixDestroyAccess);
|
||||||
DixDestroyAccess);
|
|
||||||
if (rc != Success)
|
if (rc != Success)
|
||||||
goto unwind;
|
goto unwind;
|
||||||
|
|
||||||
|
@ -295,8 +252,7 @@ ProcXIChangeHierarchy(ClientPtr client)
|
||||||
newptr,
|
newptr,
|
||||||
newkeybd;
|
newkeybd;
|
||||||
|
|
||||||
rc = dixLookupDevice(&newptr, r->return_pointer,
|
rc = dixLookupDevice(&newptr, r->return_pointer, client, DixAddAccess);
|
||||||
client, DixAddAccess);
|
|
||||||
if (rc != Success)
|
if (rc != Success)
|
||||||
goto unwind;
|
goto unwind;
|
||||||
|
|
||||||
|
@ -319,9 +275,7 @@ ProcXIChangeHierarchy(ClientPtr client)
|
||||||
goto unwind;
|
goto unwind;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (attached = inputInfo.devices;
|
for (attached = inputInfo.devices; attached; attached = attached->next)
|
||||||
attached;
|
|
||||||
attached = attached->next)
|
|
||||||
{
|
{
|
||||||
if (!IsMaster(attached)) {
|
if (!IsMaster(attached)) {
|
||||||
if (attached->u.master == ptr)
|
if (attached->u.master == ptr)
|
||||||
|
@ -363,14 +317,18 @@ ProcXIChangeHierarchy(ClientPtr client)
|
||||||
flags[XTestkeybd->id] |= XISlaveRemoved;
|
flags[XTestkeybd->id] |= XISlaveRemoved;
|
||||||
flags[keybd->id] |= XIMasterRemoved;
|
flags[keybd->id] |= XIMasterRemoved;
|
||||||
flags[ptr->id] |= XIMasterRemoved;
|
flags[ptr->id] |= XIMasterRemoved;
|
||||||
}
|
|
||||||
break;
|
|
||||||
case XIDetachSlave:
|
|
||||||
{
|
|
||||||
xXIDetachSlaveInfo* c = (xXIDetachSlaveInfo*)any;
|
|
||||||
|
|
||||||
rc = dixLookupDevice(&ptr, c->deviceid, client,
|
unwind:
|
||||||
DixManageAccess);
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
detach_slave(ClientPtr client, xXIDetachSlaveInfo *c, int flags[MAXDEVICES])
|
||||||
|
{
|
||||||
|
DeviceIntPtr ptr;
|
||||||
|
int rc;
|
||||||
|
|
||||||
|
rc = dixLookupDevice(&ptr, c->deviceid, client, DixManageAccess);
|
||||||
if (rc != Success)
|
if (rc != Success)
|
||||||
goto unwind;
|
goto unwind;
|
||||||
|
|
||||||
|
@ -391,15 +349,20 @@ ProcXIChangeHierarchy(ClientPtr client)
|
||||||
|
|
||||||
AttachDevice(client, ptr, NULL);
|
AttachDevice(client, ptr, NULL);
|
||||||
flags[ptr->id] |= XISlaveDetached;
|
flags[ptr->id] |= XISlaveDetached;
|
||||||
}
|
|
||||||
break;
|
|
||||||
case XIAttachSlave:
|
|
||||||
{
|
|
||||||
xXIAttachSlaveInfo* c = (xXIAttachSlaveInfo*)any;
|
|
||||||
DeviceIntPtr newmaster;
|
|
||||||
|
|
||||||
rc = dixLookupDevice(&ptr, c->deviceid, client,
|
unwind:
|
||||||
DixManageAccess);
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
attach_slave(ClientPtr client, xXIAttachSlaveInfo *c,
|
||||||
|
int flags[MAXDEVICES])
|
||||||
|
{
|
||||||
|
DeviceIntPtr ptr;
|
||||||
|
DeviceIntPtr newmaster;
|
||||||
|
int rc;
|
||||||
|
|
||||||
|
rc = dixLookupDevice(&ptr, c->deviceid, client, DixManageAccess);
|
||||||
if (rc != Success)
|
if (rc != Success)
|
||||||
goto unwind;
|
goto unwind;
|
||||||
|
|
||||||
|
@ -418,8 +381,7 @@ ProcXIChangeHierarchy(ClientPtr client)
|
||||||
goto unwind;
|
goto unwind;
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = dixLookupDevice(&newmaster, c->new_master,
|
rc = dixLookupDevice(&newmaster, c->new_master, client, DixAddAccess);
|
||||||
client, DixAddAccess);
|
|
||||||
if (rc != Success)
|
if (rc != Success)
|
||||||
goto unwind;
|
goto unwind;
|
||||||
if (!IsMaster(newmaster))
|
if (!IsMaster(newmaster))
|
||||||
|
@ -429,16 +391,86 @@ ProcXIChangeHierarchy(ClientPtr client)
|
||||||
goto unwind;
|
goto unwind;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!((IsPointerDevice(newmaster) &&
|
if (!((IsPointerDevice(newmaster) && IsPointerDevice(ptr)) ||
|
||||||
IsPointerDevice(ptr)) ||
|
(IsKeyboardDevice(newmaster) && IsKeyboardDevice(ptr))))
|
||||||
(IsKeyboardDevice(newmaster) &&
|
|
||||||
IsKeyboardDevice(ptr))))
|
|
||||||
{
|
{
|
||||||
rc = BadDevice;
|
rc = BadDevice;
|
||||||
goto unwind;
|
goto unwind;
|
||||||
}
|
}
|
||||||
|
|
||||||
AttachDevice(client, ptr, newmaster);
|
AttachDevice(client, ptr, newmaster);
|
||||||
flags[ptr->id] |= XISlaveAttached;
|
flags[ptr->id] |= XISlaveAttached;
|
||||||
|
|
||||||
|
unwind:
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#define SWAPIF(cmd) if (client->swapped) { cmd; }
|
||||||
|
|
||||||
|
int
|
||||||
|
ProcXIChangeHierarchy(ClientPtr client)
|
||||||
|
{
|
||||||
|
xXIAnyHierarchyChangeInfo *any;
|
||||||
|
int required_len = sizeof(xXIChangeHierarchyReq);
|
||||||
|
char n;
|
||||||
|
int rc = Success;
|
||||||
|
int flags[MAXDEVICES] = {0};
|
||||||
|
|
||||||
|
REQUEST(xXIChangeHierarchyReq);
|
||||||
|
REQUEST_AT_LEAST_SIZE(xXIChangeHierarchyReq);
|
||||||
|
|
||||||
|
if (!stuff->num_changes)
|
||||||
|
return rc;
|
||||||
|
|
||||||
|
any = (xXIAnyHierarchyChangeInfo*)&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 XIAddMaster:
|
||||||
|
{
|
||||||
|
xXIAddMasterInfo* c = (xXIAddMasterInfo*)any;
|
||||||
|
SWAPIF(swaps(&c->name_len, n));
|
||||||
|
|
||||||
|
rc = add_master(client, c, flags);
|
||||||
|
if (rc != Success)
|
||||||
|
goto unwind;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case XIRemoveMaster:
|
||||||
|
{
|
||||||
|
xXIRemoveMasterInfo* r = (xXIRemoveMasterInfo*)any;
|
||||||
|
|
||||||
|
rc = remove_master(client, r, flags);
|
||||||
|
if (rc != Success)
|
||||||
|
goto unwind;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case XIDetachSlave:
|
||||||
|
{
|
||||||
|
xXIDetachSlaveInfo* c = (xXIDetachSlaveInfo*)any;
|
||||||
|
|
||||||
|
rc = detach_slave(client, c, flags);
|
||||||
|
if (rc != Success)
|
||||||
|
goto unwind;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case XIAttachSlave:
|
||||||
|
{
|
||||||
|
xXIAttachSlaveInfo* c = (xXIAttachSlaveInfo*)any;
|
||||||
|
|
||||||
|
rc = attach_slave(client, c, flags);
|
||||||
|
if (rc != Success)
|
||||||
|
goto unwind;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue