input: reduce the number of superfluous hierarchy events

There's only two reasons for hierarchy events:
- device is added, removed, etc. In this case we want to send the event as
  it happens.
- devices are added in a XIChangeDeviceHierarchy request. In this case we
  only want one event cumulating all changes.
This commit is contained in:
Peter Hutterer 2009-05-12 16:09:35 +10:00
parent 033a2b12fc
commit 273890924b
7 changed files with 79 additions and 60 deletions

View File

@ -196,25 +196,25 @@ ProcXIChangeDeviceHierarchy(ClientPtr client)
goto unwind; goto unwind;
} }
ActivateDevice(ptr); ActivateDevice(ptr, FALSE);
ActivateDevice(keybd); ActivateDevice(keybd, FALSE);
flags[ptr->id] |= XIMasterAdded; flags[ptr->id] |= XIMasterAdded;
flags[keybd->id] |= XIMasterAdded; flags[keybd->id] |= XIMasterAdded;
ActivateDevice(xtstptr); ActivateDevice(xtstptr, FALSE);
ActivateDevice(xtstkeybd); ActivateDevice(xtstkeybd, FALSE);
flags[xtstptr->id] |= XISlaveAdded; flags[xtstptr->id] |= XISlaveAdded;
flags[xtstkeybd->id] |= XISlaveAdded; flags[xtstkeybd->id] |= XISlaveAdded;
if (c->enable) if (c->enable)
{ {
EnableDevice(ptr); EnableDevice(ptr, FALSE);
EnableDevice(keybd); EnableDevice(keybd, FALSE);
flags[ptr->id] |= XIDeviceEnabled; flags[ptr->id] |= XIDeviceEnabled;
flags[keybd->id] |= XIDeviceEnabled; flags[keybd->id] |= XIDeviceEnabled;
EnableDevice(xtstptr); EnableDevice(xtstptr, FALSE);
EnableDevice(xtstkeybd); EnableDevice(xtstkeybd, FALSE);
flags[xtstptr->id] |= XIDeviceEnabled; flags[xtstptr->id] |= XIDeviceEnabled;
flags[xtstkeybd->id] |= XIDeviceEnabled; flags[xtstkeybd->id] |= XIDeviceEnabled;
} }
@ -389,19 +389,19 @@ ProcXIChangeDeviceHierarchy(ClientPtr client)
/* disable the remove the devices, xtst devices must be done first /* disable the remove the devices, xtst devices must be done first
else the sprites they rely on will be destroyed */ else the sprites they rely on will be destroyed */
DisableDevice(xtstptr); DisableDevice(xtstptr, FALSE);
DisableDevice(xtstkeybd); DisableDevice(xtstkeybd, FALSE);
DisableDevice(keybd); DisableDevice(keybd, FALSE);
DisableDevice(ptr); DisableDevice(ptr, FALSE);
flags[xtstptr->id] |= XIDeviceDisabled | XISlaveDetached; flags[xtstptr->id] |= XIDeviceDisabled | XISlaveDetached;
flags[xtstkeybd->id] |= XIDeviceDisabled | XISlaveDetached; flags[xtstkeybd->id] |= XIDeviceDisabled | XISlaveDetached;
flags[keybd->id] |= XIDeviceDisabled; flags[keybd->id] |= XIDeviceDisabled;
flags[ptr->id] |= XIDeviceDisabled; flags[ptr->id] |= XIDeviceDisabled;
RemoveDevice(xtstptr); RemoveDevice(xtstptr, FALSE);
RemoveDevice(xtstkeybd); RemoveDevice(xtstkeybd, FALSE);
RemoveDevice(keybd); RemoveDevice(keybd, FALSE);
RemoveDevice(ptr); RemoveDevice(ptr, FALSE);
flags[xtstptr->id] |= XISlaveRemoved; flags[xtstptr->id] |= XISlaveRemoved;
flags[xtstkeybd->id] |= XISlaveRemoved; flags[xtstkeybd->id] |= XISlaveRemoved;
flags[keybd->id] |= XIMasterRemoved; flags[keybd->id] |= XIMasterRemoved;

View File

@ -253,9 +253,9 @@ ProcXChangeDeviceControl(ClientPtr client)
if (status == Success) { if (status == Success) {
if (e->enable) if (e->enable)
EnableDevice(dev); EnableDevice(dev, TRUE);
else else
DisableDevice(dev); DisableDevice(dev, TRUE);
ret = Success; ret = Success;
} else if (status == DeviceBusy) { } else if (status == DeviceBusy) {
rep.status = DeviceBusy; rep.status = DeviceBusy;

View File

@ -130,9 +130,9 @@ DeviceSetProperty(DeviceIntPtr dev, Atom property, XIPropertyValuePtr prop,
if (!checkonly) if (!checkonly)
{ {
if ((*((CARD8*)prop->data)) && !dev->enabled) if ((*((CARD8*)prop->data)) && !dev->enabled)
EnableDevice(dev); EnableDevice(dev, TRUE);
else if (!(*((CARD8*)prop->data)) && dev->enabled) else if (!(*((CARD8*)prop->data)) && dev->enabled)
DisableDevice(dev); DisableDevice(dev, TRUE);
} }
} }
@ -284,10 +284,11 @@ SendDevicePresenceEvent(int deviceid, int type)
* device. * device.
* *
* @param The device to be enabled. * @param The device to be enabled.
* @param sendevent True if an XI2 event should be sent.
* @return TRUE on success or FALSE otherwise. * @return TRUE on success or FALSE otherwise.
*/ */
Bool Bool
EnableDevice(DeviceIntPtr dev) EnableDevice(DeviceIntPtr dev, BOOL sendevent)
{ {
DeviceIntPtr *prev; DeviceIntPtr *prev;
int ret; int ret;
@ -362,8 +363,11 @@ EnableDevice(DeviceIntPtr dev)
TRUE); TRUE);
SendDevicePresenceEvent(dev->id, DeviceEnabled); SendDevicePresenceEvent(dev->id, DeviceEnabled);
flags[dev->id] |= XIDeviceEnabled; if (sendevent)
XISendDeviceHierarchyEvent(flags); {
flags[dev->id] |= XIDeviceEnabled;
XISendDeviceHierarchyEvent(flags);
}
return TRUE; return TRUE;
} }
@ -376,10 +380,11 @@ EnableDevice(DeviceIntPtr dev)
* Master keyboard devices have to be disabled before master pointer devices * Master keyboard devices have to be disabled before master pointer devices
* otherwise things turn bad. * otherwise things turn bad.
* *
* @param sendevent True if an XI2 event should be sent.
* @return TRUE on success or FALSE otherwise. * @return TRUE on success or FALSE otherwise.
*/ */
Bool Bool
DisableDevice(DeviceIntPtr dev) DisableDevice(DeviceIntPtr dev, BOOL sendevent)
{ {
DeviceIntPtr *prev, other; DeviceIntPtr *prev, other;
BOOL enabled; BOOL enabled;
@ -438,8 +443,11 @@ DisableDevice(DeviceIntPtr dev)
TRUE); TRUE);
SendDevicePresenceEvent(dev->id, DeviceDisabled); SendDevicePresenceEvent(dev->id, DeviceDisabled);
flags[dev->id] = XIDeviceDisabled; if (sendevent)
XISendDeviceHierarchyEvent(flags); {
flags[dev->id] = XIDeviceDisabled;
XISendDeviceHierarchyEvent(flags);
}
return TRUE; return TRUE;
} }
@ -450,14 +458,14 @@ DisableDevice(DeviceIntPtr dev)
* Must be called before EnableDevice. * Must be called before EnableDevice.
* The device will NOT send events until it is enabled! * The device will NOT send events until it is enabled!
* *
* @param sendevent True if an XI2 event should be sent.
* @return Success or an error code on failure. * @return Success or an error code on failure.
*/ */
int int
ActivateDevice(DeviceIntPtr dev) ActivateDevice(DeviceIntPtr dev, BOOL sendevent)
{ {
int ret = Success; int ret = Success;
ScreenPtr pScreen = screenInfo.screens[0]; ScreenPtr pScreen = screenInfo.screens[0];
int flags[MAXDEVICES];
if (!dev || !dev->deviceProc) if (!dev || !dev->deviceProc)
return BadImplementation; return BadImplementation;
@ -472,8 +480,12 @@ ActivateDevice(DeviceIntPtr dev)
pScreen->DeviceCursorInitialize(dev, pScreen); pScreen->DeviceCursorInitialize(dev, pScreen);
SendDevicePresenceEvent(dev->id, DeviceAdded); SendDevicePresenceEvent(dev->id, DeviceAdded);
flags[dev->id] = XISlaveAdded; if (sendevent)
XISendDeviceHierarchyEvent(flags); {
int flags[MAXDEVICES] = {0};
flags[dev->id] = XISlaveAdded;
XISendDeviceHierarchyEvent(flags);
}
return ret; return ret;
} }
@ -580,11 +592,11 @@ InitCoreDevices(void)
TRUE) != Success) TRUE) != Success)
FatalError("Failed to allocate core devices"); FatalError("Failed to allocate core devices");
if (ActivateDevice(inputInfo.pointer) != Success || if (ActivateDevice(inputInfo.pointer, TRUE) != Success ||
ActivateDevice(inputInfo.keyboard) != Success) ActivateDevice(inputInfo.keyboard, TRUE) != Success)
FatalError("Failed to activate core devices."); FatalError("Failed to activate core devices.");
if (!EnableDevice(inputInfo.pointer) || if (!EnableDevice(inputInfo.pointer, TRUE) ||
!EnableDevice(inputInfo.keyboard)) !EnableDevice(inputInfo.keyboard, TRUE))
FatalError("Failed to enable core devices."); FatalError("Failed to enable core devices.");
/* /*
@ -596,11 +608,11 @@ InitCoreDevices(void)
&vxtstkeyboard) != Success) &vxtstkeyboard) != Success)
FatalError("Failed to allocate XTst devices"); FatalError("Failed to allocate XTst devices");
if (ActivateDevice(vxtstpointer) != Success || if (ActivateDevice(vxtstpointer, TRUE) != Success ||
ActivateDevice(vxtstkeyboard) != Success) ActivateDevice(vxtstkeyboard, TRUE) != Success)
FatalError("Failed to activate xtst core devices."); FatalError("Failed to activate xtst core devices.");
if (!EnableDevice(vxtstpointer) || if (!EnableDevice(vxtstpointer, TRUE) ||
!EnableDevice(vxtstkeyboard)) !EnableDevice(vxtstkeyboard, TRUE))
FatalError("Failed to enable xtst core devices."); FatalError("Failed to enable xtst core devices.");
AttachDevice(NULL, vxtstpointer, inputInfo.pointer); AttachDevice(NULL, vxtstpointer, inputInfo.pointer);
@ -627,7 +639,7 @@ InitAndStartDevices(void)
for (dev = inputInfo.off_devices; dev; dev = dev->next) { for (dev = inputInfo.off_devices; dev; dev = dev->next) {
DebugF("(dix) initialising device %d\n", dev->id); DebugF("(dix) initialising device %d\n", dev->id);
if (!dev->inited) if (!dev->inited)
ActivateDevice(dev); ActivateDevice(dev, TRUE);
} }
/* enable real devices */ /* enable real devices */
@ -636,7 +648,7 @@ InitAndStartDevices(void)
DebugF("(dix) enabling device %d\n", dev->id); DebugF("(dix) enabling device %d\n", dev->id);
next = dev->next; next = dev->next;
if (dev->inited && dev->startup) if (dev->inited && dev->startup)
(void)EnableDevice(dev); EnableDevice(dev, TRUE);
} }
return Success; return Success;
@ -929,9 +941,11 @@ UndisplayDevices(void)
* happen if a malloc fails during the addition of master devices. If * happen if a malloc fails during the addition of master devices. If
* dev->init is FALSE it means the client never received a DeviceAdded event, * dev->init is FALSE it means the client never received a DeviceAdded event,
* so let's not send a DeviceRemoved event either. * so let's not send a DeviceRemoved event either.
*
* @param sendevent True if an XI2 event should be sent.
*/ */
int int
RemoveDevice(DeviceIntPtr dev) RemoveDevice(DeviceIntPtr dev, BOOL sendevent)
{ {
DeviceIntPtr prev,tmp,next; DeviceIntPtr prev,tmp,next;
int ret = BadMatch; int ret = BadMatch;
@ -953,7 +967,7 @@ RemoveDevice(DeviceIntPtr dev)
if (DevHasCursor(dev)) if (DevHasCursor(dev))
screen->DisplayCursor(dev, screen, NullCursor); screen->DisplayCursor(dev, screen, NullCursor);
DisableDevice(dev); DisableDevice(dev, sendevent);
flags[dev->id] = XIDeviceDisabled; flags[dev->id] = XIDeviceDisabled;
} }
@ -992,7 +1006,8 @@ RemoveDevice(DeviceIntPtr dev)
if (ret == Success && initialized) { if (ret == Success && initialized) {
inputInfo.numDevices--; inputInfo.numDevices--;
SendDevicePresenceEvent(deviceid, DeviceRemoved); SendDevicePresenceEvent(deviceid, DeviceRemoved);
XISendDeviceHierarchyEvent(flags); if (sendevent)
XISendDeviceHierarchyEvent(flags);
} }
return ret; return ret;
@ -2360,7 +2375,7 @@ AllocDevicePair (ClientPtr client, char* name,
keyboard = AddInputDevice(client, CoreKeyboardProc, TRUE); keyboard = AddInputDevice(client, CoreKeyboardProc, TRUE);
if (!keyboard) if (!keyboard)
{ {
RemoveDevice(pointer); RemoveDevice(pointer, FALSE);
return BadAlloc; return BadAlloc;
} }

View File

@ -462,7 +462,7 @@ xf86VTSwitch(void)
if (pInfo->dev) { if (pInfo->dev) {
xf86ReleaseKeys(pInfo->dev); xf86ReleaseKeys(pInfo->dev);
ProcessInputEvents(); ProcessInputEvents();
DisableDevice(pInfo->dev); DisableDevice(pInfo->dev, TRUE);
} }
} }
xf86EnterServerState(SETUP); xf86EnterServerState(SETUP);
@ -497,7 +497,7 @@ xf86VTSwitch(void)
pInfo = xf86InputDevs; pInfo = xf86InputDevs;
while (pInfo) { while (pInfo) {
if (pInfo->dev) if (pInfo->dev)
EnableDevice(pInfo->dev); EnableDevice(pInfo->dev, TRUE);
pInfo = pInfo->next; pInfo = pInfo->next;
} }
for (ih = InputHandlers; ih; ih = ih->next) for (ih = InputHandlers; ih; ih = ih->next)
@ -555,7 +555,7 @@ xf86VTSwitch(void)
pInfo = xf86InputDevs; pInfo = xf86InputDevs;
while (pInfo) { while (pInfo) {
if (pInfo->dev) if (pInfo->dev)
EnableDevice(pInfo->dev); EnableDevice(pInfo->dev, TRUE);
pInfo = pInfo->next; pInfo = pInfo->next;
} }

View File

@ -76,7 +76,7 @@ suspend (pmEvent event, Bool undo)
} }
pInfo = xf86InputDevs; pInfo = xf86InputDevs;
while (pInfo) { while (pInfo) {
DisableDevice(pInfo->dev); DisableDevice(pInfo->dev, TRUE);
pInfo = pInfo->next; pInfo = pInfo->next;
} }
xf86EnterServerState(SETUP); xf86EnterServerState(SETUP);
@ -119,7 +119,7 @@ resume(pmEvent event, Bool undo)
dixSaveScreens(serverClient, SCREEN_SAVER_FORCER, ScreenSaverReset); dixSaveScreens(serverClient, SCREEN_SAVER_FORCER, ScreenSaverReset);
pInfo = xf86InputDevs; pInfo = xf86InputDevs;
while (pInfo) { while (pInfo) {
EnableDevice(pInfo->dev); EnableDevice(pInfo->dev, TRUE);
pInfo = pInfo->next; pInfo = pInfo->next;
} }
xf86inSuspend = FALSE; xf86inSuspend = FALSE;

View File

@ -377,7 +377,7 @@ OpenInputDevice(DeviceIntPtr dev,
int *status) int *status)
{ {
if (!dev->inited) if (!dev->inited)
ActivateDevice(dev); ActivateDevice(dev, TRUE);
*status = Success; *status = Success;
} }
@ -544,18 +544,18 @@ xf86NewInputDevice(IDevPtr idev, DeviceIntPtr *pdev, BOOL enable)
} }
dev = pInfo->dev; dev = pInfo->dev;
rval = ActivateDevice(dev); rval = ActivateDevice(dev, TRUE);
if (rval != Success) if (rval != Success)
{ {
xf86Msg(X_ERROR, "Couldn't init device \"%s\"\n", idev->identifier); xf86Msg(X_ERROR, "Couldn't init device \"%s\"\n", idev->identifier);
RemoveDevice(dev); RemoveDevice(dev, TRUE);
goto unwind; goto unwind;
} }
/* Enable it if it's properly initialised and we're currently in the VT */ /* Enable it if it's properly initialised and we're currently in the VT */
if (enable && dev->inited && dev->startup && xf86Screens[0]->vtSema) if (enable && dev->inited && dev->startup && xf86Screens[0]->vtSema)
{ {
EnableDevice(dev); EnableDevice(dev, TRUE);
if (!dev->enabled) if (!dev->enabled)
{ {
xf86Msg(X_ERROR, "Couldn't init device \"%s\"\n", idev->identifier); xf86Msg(X_ERROR, "Couldn't init device \"%s\"\n", idev->identifier);
@ -680,7 +680,7 @@ DeleteInputDeviceRequest(DeviceIntPtr pDev)
} }
OsBlockSignals(); OsBlockSignals();
RemoveDevice(pDev); RemoveDevice(pDev, TRUE);
if (!isMaster && pInfo != NULL) if (!isMaster && pInfo != NULL)
{ {
@ -1065,7 +1065,7 @@ xf86DisableDevice(DeviceIntPtr dev, Bool panic)
if(!panic) if(!panic)
{ {
DisableDevice(dev); DisableDevice(dev, TRUE);
} else } else
{ {
ev.type = DevicePresenceNotify; ev.type = DevicePresenceNotify;
@ -1088,7 +1088,7 @@ xf86DisableDevice(DeviceIntPtr dev, Bool panic)
void void
xf86EnableDevice(DeviceIntPtr dev) xf86EnableDevice(DeviceIntPtr dev)
{ {
EnableDevice(dev); EnableDevice(dev, TRUE);
} }
/* end of xf86Xinput.c */ /* end of xf86Xinput.c */

View File

@ -228,13 +228,16 @@ extern _X_EXPORT DeviceIntPtr AddInputDevice(
Bool /*autoStart*/); Bool /*autoStart*/);
extern _X_EXPORT Bool EnableDevice( extern _X_EXPORT Bool EnableDevice(
DeviceIntPtr /*device*/); DeviceIntPtr /*device*/,
BOOL /* sendevent */);
extern _X_EXPORT Bool ActivateDevice( extern _X_EXPORT Bool ActivateDevice(
DeviceIntPtr /*device*/); DeviceIntPtr /*device*/,
BOOL /* sendevent */);
extern _X_EXPORT Bool DisableDevice( extern _X_EXPORT Bool DisableDevice(
DeviceIntPtr /*device*/); DeviceIntPtr /*device*/,
BOOL /* sendevent */);
extern int InitAndStartDevices(void); extern int InitAndStartDevices(void);
@ -243,7 +246,8 @@ extern void CloseDownDevices(void);
extern void UndisplayDevices(void); extern void UndisplayDevices(void);
extern _X_EXPORT int RemoveDevice( extern _X_EXPORT int RemoveDevice(
DeviceIntPtr /*dev*/); DeviceIntPtr /*dev*/,
BOOL /* sendevent */);
extern _X_EXPORT int NumMotionEvents(void); extern _X_EXPORT int NumMotionEvents(void);