xi: add DEVICE_ENABLE control

Add DEVICE_ENABLE control, which allows runtime enabling and disabling
of specific devices.
This commit is contained in:
Daniel Stone 2006-10-20 00:28:40 +03:00 committed by Daniel Stone
parent b0780312d8
commit a8d3dad9d9
5 changed files with 57 additions and 0 deletions

View File

@ -106,6 +106,7 @@ ProcXChangeDeviceControl(ClientPtr client)
CARD32 *resolution;
xDeviceTSCtl *ts;
xDeviceCoreCtl *c;
xDeviceEnableCtl *e;
REQUEST(xChangeDeviceControlReq);
REQUEST_AT_LEAST_SIZE(xChangeDeviceControlReq);
@ -217,6 +218,28 @@ ProcXChangeDeviceControl(ClientPtr client)
return Success;
}
break;
case DEVICE_ENABLE:
e = (xDeviceEnableCtl *)&stuff[1];
status = ChangeDeviceControl(client, dev, (xDeviceCtl *) e);
if (status == Success) {
if (e->enable)
EnableDevice(dev);
else
DisableDevice(dev);
} else if (status == DeviceBusy) {
rep.status = DeviceBusy;
WriteReplyToClient(client, sizeof(xChangeDeviceControlReply),
&rep);
return Success;
} else {
SendErrorToClient(client, IReqCode, X_ChangeDeviceControl, 0,
BadMatch);
return Success;
}
break;
default:
SendErrorToClient(client, IReqCode, X_ChangeDeviceControl, 0, BadValue);

View File

@ -136,6 +136,9 @@ ProcXGetDeviceControl(ClientPtr client)
case DEVICE_CORE:
total_length = sizeof(xDeviceCoreCtl);
break;
case DEVICE_ENABLE:
total_length = sizeof(xDeviceEnableCtl);
break;
default:
SendErrorToClient(client, IReqCode, X_GetDeviceControl, 0, BadValue);
return Success;
@ -157,6 +160,10 @@ ProcXGetDeviceControl(ClientPtr client)
break;
case DEVICE_CORE:
CopySwapDeviceCore(client, dev, buf);
break;
case DEVICE_ENABLE:
CopySwapDeviceEnable(client, dev, buf);
break;
default:
break;
}
@ -239,6 +246,7 @@ void CopySwapDeviceCore (ClientPtr client, DeviceIntPtr dev, char *buf)
c->control = DEVICE_CORE;
c->length = sizeof(c);
c->status = dev->coreEvents;
c->iscore = (dev == inputInfo.keyboard || dev == inputInfo.pointer);
if (client->swapped) {
swaps(&c->control, n);
@ -247,6 +255,22 @@ void CopySwapDeviceCore (ClientPtr client, DeviceIntPtr dev, char *buf)
}
}
void CopySwapDeviceEnable (ClientPtr client, DeviceIntPtr dev, char *buf)
{
register char n;
xDeviceEnableState *e = (xDeviceEnableState *) buf;
e->control = DEVICE_ENABLE;
e->length = sizeof(e);
e->enable = dev->enabled;
if (client->swapped) {
swaps(&e->control, n);
swaps(&e->length, n);
swaps(&e->enable, n);
}
}
/***********************************************************************
*

View File

@ -52,6 +52,11 @@ void CopySwapDeviceCore(ClientPtr /* client */ ,
char * /* buf */
);
void CopySwapDeviceEnable(ClientPtr /* client */ ,
DeviceIntPtr /* dev */ ,
char * /* buf */
);
void SRepXGetDeviceControl(ClientPtr /* client */ ,
int /* size */ ,
xGetDeviceControlReply * /* rep */

View File

@ -130,6 +130,8 @@ AddInputDevice(DeviceProc deviceProc, Bool autoStart)
dev->devPrivates = NULL;
dev->unwrapProc = NULL;
dev->coreEvents = TRUE;
dev->inited = FALSE;
dev->enabled = FALSE;
for (prev = &inputInfo.off_devices; *prev; prev = &(*prev)->next)
;
@ -154,6 +156,7 @@ EnableDevice(register DeviceIntPtr dev)
ErrorF("couldn't enable device %d\n", dev->id);
return FALSE;
}
dev->enabled = TRUE;
*prev = dev->next;
for (prev = &inputInfo.devices; *prev; prev = &(*prev)->next)
@ -176,6 +179,7 @@ DisableDevice(register DeviceIntPtr dev)
if (*prev != dev)
return FALSE;
(void)(*dev->deviceProc)(dev, DEVICE_OFF);
dev->enabled = FALSE;
*prev = dev->next;
dev->next = inputInfo.off_devices;
inputInfo.off_devices = dev;

View File

@ -265,6 +265,7 @@ typedef struct _DeviceIntRec {
used to initialize, turn on, or
turn off the device */
Bool inited; /* TRUE if INIT returns Success */
Bool enabled; /* TRUE if ON returns Success */
Bool coreEvents; /* TRUE if device also sends core */
GrabPtr grab; /* the grabber - used by DIX */
struct {