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:
parent
033a2b12fc
commit
273890924b
|
@ -196,25 +196,25 @@ ProcXIChangeDeviceHierarchy(ClientPtr client)
|
|||
goto unwind;
|
||||
}
|
||||
|
||||
ActivateDevice(ptr);
|
||||
ActivateDevice(keybd);
|
||||
ActivateDevice(ptr, FALSE);
|
||||
ActivateDevice(keybd, FALSE);
|
||||
flags[ptr->id] |= XIMasterAdded;
|
||||
flags[keybd->id] |= XIMasterAdded;
|
||||
|
||||
ActivateDevice(xtstptr);
|
||||
ActivateDevice(xtstkeybd);
|
||||
ActivateDevice(xtstptr, FALSE);
|
||||
ActivateDevice(xtstkeybd, FALSE);
|
||||
flags[xtstptr->id] |= XISlaveAdded;
|
||||
flags[xtstkeybd->id] |= XISlaveAdded;
|
||||
|
||||
if (c->enable)
|
||||
{
|
||||
EnableDevice(ptr);
|
||||
EnableDevice(keybd);
|
||||
EnableDevice(ptr, FALSE);
|
||||
EnableDevice(keybd, FALSE);
|
||||
flags[ptr->id] |= XIDeviceEnabled;
|
||||
flags[keybd->id] |= XIDeviceEnabled;
|
||||
|
||||
EnableDevice(xtstptr);
|
||||
EnableDevice(xtstkeybd);
|
||||
EnableDevice(xtstptr, FALSE);
|
||||
EnableDevice(xtstkeybd, FALSE);
|
||||
flags[xtstptr->id] |= XIDeviceEnabled;
|
||||
flags[xtstkeybd->id] |= XIDeviceEnabled;
|
||||
}
|
||||
|
@ -389,19 +389,19 @@ ProcXIChangeDeviceHierarchy(ClientPtr client)
|
|||
|
||||
/* disable the remove the devices, xtst devices must be done first
|
||||
else the sprites they rely on will be destroyed */
|
||||
DisableDevice(xtstptr);
|
||||
DisableDevice(xtstkeybd);
|
||||
DisableDevice(keybd);
|
||||
DisableDevice(ptr);
|
||||
DisableDevice(xtstptr, FALSE);
|
||||
DisableDevice(xtstkeybd, FALSE);
|
||||
DisableDevice(keybd, FALSE);
|
||||
DisableDevice(ptr, FALSE);
|
||||
flags[xtstptr->id] |= XIDeviceDisabled | XISlaveDetached;
|
||||
flags[xtstkeybd->id] |= XIDeviceDisabled | XISlaveDetached;
|
||||
flags[keybd->id] |= XIDeviceDisabled;
|
||||
flags[ptr->id] |= XIDeviceDisabled;
|
||||
|
||||
RemoveDevice(xtstptr);
|
||||
RemoveDevice(xtstkeybd);
|
||||
RemoveDevice(keybd);
|
||||
RemoveDevice(ptr);
|
||||
RemoveDevice(xtstptr, FALSE);
|
||||
RemoveDevice(xtstkeybd, FALSE);
|
||||
RemoveDevice(keybd, FALSE);
|
||||
RemoveDevice(ptr, FALSE);
|
||||
flags[xtstptr->id] |= XISlaveRemoved;
|
||||
flags[xtstkeybd->id] |= XISlaveRemoved;
|
||||
flags[keybd->id] |= XIMasterRemoved;
|
||||
|
|
|
@ -253,9 +253,9 @@ ProcXChangeDeviceControl(ClientPtr client)
|
|||
|
||||
if (status == Success) {
|
||||
if (e->enable)
|
||||
EnableDevice(dev);
|
||||
EnableDevice(dev, TRUE);
|
||||
else
|
||||
DisableDevice(dev);
|
||||
DisableDevice(dev, TRUE);
|
||||
ret = Success;
|
||||
} else if (status == DeviceBusy) {
|
||||
rep.status = DeviceBusy;
|
||||
|
|
|
@ -130,9 +130,9 @@ DeviceSetProperty(DeviceIntPtr dev, Atom property, XIPropertyValuePtr prop,
|
|||
if (!checkonly)
|
||||
{
|
||||
if ((*((CARD8*)prop->data)) && !dev->enabled)
|
||||
EnableDevice(dev);
|
||||
EnableDevice(dev, TRUE);
|
||||
else if (!(*((CARD8*)prop->data)) && dev->enabled)
|
||||
DisableDevice(dev);
|
||||
DisableDevice(dev, TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -284,10 +284,11 @@ SendDevicePresenceEvent(int deviceid, int type)
|
|||
* device.
|
||||
*
|
||||
* @param The device to be enabled.
|
||||
* @param sendevent True if an XI2 event should be sent.
|
||||
* @return TRUE on success or FALSE otherwise.
|
||||
*/
|
||||
Bool
|
||||
EnableDevice(DeviceIntPtr dev)
|
||||
EnableDevice(DeviceIntPtr dev, BOOL sendevent)
|
||||
{
|
||||
DeviceIntPtr *prev;
|
||||
int ret;
|
||||
|
@ -362,8 +363,11 @@ EnableDevice(DeviceIntPtr dev)
|
|||
TRUE);
|
||||
|
||||
SendDevicePresenceEvent(dev->id, DeviceEnabled);
|
||||
flags[dev->id] |= XIDeviceEnabled;
|
||||
XISendDeviceHierarchyEvent(flags);
|
||||
if (sendevent)
|
||||
{
|
||||
flags[dev->id] |= XIDeviceEnabled;
|
||||
XISendDeviceHierarchyEvent(flags);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
@ -376,10 +380,11 @@ EnableDevice(DeviceIntPtr dev)
|
|||
* Master keyboard devices have to be disabled before master pointer devices
|
||||
* otherwise things turn bad.
|
||||
*
|
||||
* @param sendevent True if an XI2 event should be sent.
|
||||
* @return TRUE on success or FALSE otherwise.
|
||||
*/
|
||||
Bool
|
||||
DisableDevice(DeviceIntPtr dev)
|
||||
DisableDevice(DeviceIntPtr dev, BOOL sendevent)
|
||||
{
|
||||
DeviceIntPtr *prev, other;
|
||||
BOOL enabled;
|
||||
|
@ -438,8 +443,11 @@ DisableDevice(DeviceIntPtr dev)
|
|||
TRUE);
|
||||
|
||||
SendDevicePresenceEvent(dev->id, DeviceDisabled);
|
||||
flags[dev->id] = XIDeviceDisabled;
|
||||
XISendDeviceHierarchyEvent(flags);
|
||||
if (sendevent)
|
||||
{
|
||||
flags[dev->id] = XIDeviceDisabled;
|
||||
XISendDeviceHierarchyEvent(flags);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
@ -450,14 +458,14 @@ DisableDevice(DeviceIntPtr dev)
|
|||
* Must be called before EnableDevice.
|
||||
* 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.
|
||||
*/
|
||||
int
|
||||
ActivateDevice(DeviceIntPtr dev)
|
||||
ActivateDevice(DeviceIntPtr dev, BOOL sendevent)
|
||||
{
|
||||
int ret = Success;
|
||||
ScreenPtr pScreen = screenInfo.screens[0];
|
||||
int flags[MAXDEVICES];
|
||||
|
||||
if (!dev || !dev->deviceProc)
|
||||
return BadImplementation;
|
||||
|
@ -472,8 +480,12 @@ ActivateDevice(DeviceIntPtr dev)
|
|||
pScreen->DeviceCursorInitialize(dev, pScreen);
|
||||
|
||||
SendDevicePresenceEvent(dev->id, DeviceAdded);
|
||||
flags[dev->id] = XISlaveAdded;
|
||||
XISendDeviceHierarchyEvent(flags);
|
||||
if (sendevent)
|
||||
{
|
||||
int flags[MAXDEVICES] = {0};
|
||||
flags[dev->id] = XISlaveAdded;
|
||||
XISendDeviceHierarchyEvent(flags);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -580,11 +592,11 @@ InitCoreDevices(void)
|
|||
TRUE) != Success)
|
||||
FatalError("Failed to allocate core devices");
|
||||
|
||||
if (ActivateDevice(inputInfo.pointer) != Success ||
|
||||
ActivateDevice(inputInfo.keyboard) != Success)
|
||||
if (ActivateDevice(inputInfo.pointer, TRUE) != Success ||
|
||||
ActivateDevice(inputInfo.keyboard, TRUE) != Success)
|
||||
FatalError("Failed to activate core devices.");
|
||||
if (!EnableDevice(inputInfo.pointer) ||
|
||||
!EnableDevice(inputInfo.keyboard))
|
||||
if (!EnableDevice(inputInfo.pointer, TRUE) ||
|
||||
!EnableDevice(inputInfo.keyboard, TRUE))
|
||||
FatalError("Failed to enable core devices.");
|
||||
|
||||
/*
|
||||
|
@ -596,11 +608,11 @@ InitCoreDevices(void)
|
|||
&vxtstkeyboard) != Success)
|
||||
FatalError("Failed to allocate XTst devices");
|
||||
|
||||
if (ActivateDevice(vxtstpointer) != Success ||
|
||||
ActivateDevice(vxtstkeyboard) != Success)
|
||||
if (ActivateDevice(vxtstpointer, TRUE) != Success ||
|
||||
ActivateDevice(vxtstkeyboard, TRUE) != Success)
|
||||
FatalError("Failed to activate xtst core devices.");
|
||||
if (!EnableDevice(vxtstpointer) ||
|
||||
!EnableDevice(vxtstkeyboard))
|
||||
if (!EnableDevice(vxtstpointer, TRUE) ||
|
||||
!EnableDevice(vxtstkeyboard, TRUE))
|
||||
FatalError("Failed to enable xtst core devices.");
|
||||
|
||||
AttachDevice(NULL, vxtstpointer, inputInfo.pointer);
|
||||
|
@ -627,7 +639,7 @@ InitAndStartDevices(void)
|
|||
for (dev = inputInfo.off_devices; dev; dev = dev->next) {
|
||||
DebugF("(dix) initialising device %d\n", dev->id);
|
||||
if (!dev->inited)
|
||||
ActivateDevice(dev);
|
||||
ActivateDevice(dev, TRUE);
|
||||
}
|
||||
|
||||
/* enable real devices */
|
||||
|
@ -636,7 +648,7 @@ InitAndStartDevices(void)
|
|||
DebugF("(dix) enabling device %d\n", dev->id);
|
||||
next = dev->next;
|
||||
if (dev->inited && dev->startup)
|
||||
(void)EnableDevice(dev);
|
||||
EnableDevice(dev, TRUE);
|
||||
}
|
||||
|
||||
return Success;
|
||||
|
@ -929,9 +941,11 @@ UndisplayDevices(void)
|
|||
* 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,
|
||||
* so let's not send a DeviceRemoved event either.
|
||||
*
|
||||
* @param sendevent True if an XI2 event should be sent.
|
||||
*/
|
||||
int
|
||||
RemoveDevice(DeviceIntPtr dev)
|
||||
RemoveDevice(DeviceIntPtr dev, BOOL sendevent)
|
||||
{
|
||||
DeviceIntPtr prev,tmp,next;
|
||||
int ret = BadMatch;
|
||||
|
@ -953,7 +967,7 @@ RemoveDevice(DeviceIntPtr dev)
|
|||
if (DevHasCursor(dev))
|
||||
screen->DisplayCursor(dev, screen, NullCursor);
|
||||
|
||||
DisableDevice(dev);
|
||||
DisableDevice(dev, sendevent);
|
||||
flags[dev->id] = XIDeviceDisabled;
|
||||
}
|
||||
|
||||
|
@ -992,7 +1006,8 @@ RemoveDevice(DeviceIntPtr dev)
|
|||
if (ret == Success && initialized) {
|
||||
inputInfo.numDevices--;
|
||||
SendDevicePresenceEvent(deviceid, DeviceRemoved);
|
||||
XISendDeviceHierarchyEvent(flags);
|
||||
if (sendevent)
|
||||
XISendDeviceHierarchyEvent(flags);
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
@ -2360,7 +2375,7 @@ AllocDevicePair (ClientPtr client, char* name,
|
|||
keyboard = AddInputDevice(client, CoreKeyboardProc, TRUE);
|
||||
if (!keyboard)
|
||||
{
|
||||
RemoveDevice(pointer);
|
||||
RemoveDevice(pointer, FALSE);
|
||||
return BadAlloc;
|
||||
}
|
||||
|
||||
|
|
|
@ -462,7 +462,7 @@ xf86VTSwitch(void)
|
|||
if (pInfo->dev) {
|
||||
xf86ReleaseKeys(pInfo->dev);
|
||||
ProcessInputEvents();
|
||||
DisableDevice(pInfo->dev);
|
||||
DisableDevice(pInfo->dev, TRUE);
|
||||
}
|
||||
}
|
||||
xf86EnterServerState(SETUP);
|
||||
|
@ -497,7 +497,7 @@ xf86VTSwitch(void)
|
|||
pInfo = xf86InputDevs;
|
||||
while (pInfo) {
|
||||
if (pInfo->dev)
|
||||
EnableDevice(pInfo->dev);
|
||||
EnableDevice(pInfo->dev, TRUE);
|
||||
pInfo = pInfo->next;
|
||||
}
|
||||
for (ih = InputHandlers; ih; ih = ih->next)
|
||||
|
@ -555,7 +555,7 @@ xf86VTSwitch(void)
|
|||
pInfo = xf86InputDevs;
|
||||
while (pInfo) {
|
||||
if (pInfo->dev)
|
||||
EnableDevice(pInfo->dev);
|
||||
EnableDevice(pInfo->dev, TRUE);
|
||||
pInfo = pInfo->next;
|
||||
}
|
||||
|
||||
|
|
|
@ -76,7 +76,7 @@ suspend (pmEvent event, Bool undo)
|
|||
}
|
||||
pInfo = xf86InputDevs;
|
||||
while (pInfo) {
|
||||
DisableDevice(pInfo->dev);
|
||||
DisableDevice(pInfo->dev, TRUE);
|
||||
pInfo = pInfo->next;
|
||||
}
|
||||
xf86EnterServerState(SETUP);
|
||||
|
@ -119,7 +119,7 @@ resume(pmEvent event, Bool undo)
|
|||
dixSaveScreens(serverClient, SCREEN_SAVER_FORCER, ScreenSaverReset);
|
||||
pInfo = xf86InputDevs;
|
||||
while (pInfo) {
|
||||
EnableDevice(pInfo->dev);
|
||||
EnableDevice(pInfo->dev, TRUE);
|
||||
pInfo = pInfo->next;
|
||||
}
|
||||
xf86inSuspend = FALSE;
|
||||
|
|
|
@ -377,7 +377,7 @@ OpenInputDevice(DeviceIntPtr dev,
|
|||
int *status)
|
||||
{
|
||||
if (!dev->inited)
|
||||
ActivateDevice(dev);
|
||||
ActivateDevice(dev, TRUE);
|
||||
|
||||
*status = Success;
|
||||
}
|
||||
|
@ -544,18 +544,18 @@ xf86NewInputDevice(IDevPtr idev, DeviceIntPtr *pdev, BOOL enable)
|
|||
}
|
||||
|
||||
dev = pInfo->dev;
|
||||
rval = ActivateDevice(dev);
|
||||
rval = ActivateDevice(dev, TRUE);
|
||||
if (rval != Success)
|
||||
{
|
||||
xf86Msg(X_ERROR, "Couldn't init device \"%s\"\n", idev->identifier);
|
||||
RemoveDevice(dev);
|
||||
RemoveDevice(dev, TRUE);
|
||||
goto unwind;
|
||||
}
|
||||
|
||||
/* Enable it if it's properly initialised and we're currently in the VT */
|
||||
if (enable && dev->inited && dev->startup && xf86Screens[0]->vtSema)
|
||||
{
|
||||
EnableDevice(dev);
|
||||
EnableDevice(dev, TRUE);
|
||||
if (!dev->enabled)
|
||||
{
|
||||
xf86Msg(X_ERROR, "Couldn't init device \"%s\"\n", idev->identifier);
|
||||
|
@ -680,7 +680,7 @@ DeleteInputDeviceRequest(DeviceIntPtr pDev)
|
|||
}
|
||||
|
||||
OsBlockSignals();
|
||||
RemoveDevice(pDev);
|
||||
RemoveDevice(pDev, TRUE);
|
||||
|
||||
if (!isMaster && pInfo != NULL)
|
||||
{
|
||||
|
@ -1065,7 +1065,7 @@ xf86DisableDevice(DeviceIntPtr dev, Bool panic)
|
|||
|
||||
if(!panic)
|
||||
{
|
||||
DisableDevice(dev);
|
||||
DisableDevice(dev, TRUE);
|
||||
} else
|
||||
{
|
||||
ev.type = DevicePresenceNotify;
|
||||
|
@ -1088,7 +1088,7 @@ xf86DisableDevice(DeviceIntPtr dev, Bool panic)
|
|||
void
|
||||
xf86EnableDevice(DeviceIntPtr dev)
|
||||
{
|
||||
EnableDevice(dev);
|
||||
EnableDevice(dev, TRUE);
|
||||
}
|
||||
|
||||
/* end of xf86Xinput.c */
|
||||
|
|
|
@ -228,13 +228,16 @@ extern _X_EXPORT DeviceIntPtr AddInputDevice(
|
|||
Bool /*autoStart*/);
|
||||
|
||||
extern _X_EXPORT Bool EnableDevice(
|
||||
DeviceIntPtr /*device*/);
|
||||
DeviceIntPtr /*device*/,
|
||||
BOOL /* sendevent */);
|
||||
|
||||
extern _X_EXPORT Bool ActivateDevice(
|
||||
DeviceIntPtr /*device*/);
|
||||
DeviceIntPtr /*device*/,
|
||||
BOOL /* sendevent */);
|
||||
|
||||
extern _X_EXPORT Bool DisableDevice(
|
||||
DeviceIntPtr /*device*/);
|
||||
DeviceIntPtr /*device*/,
|
||||
BOOL /* sendevent */);
|
||||
|
||||
extern int InitAndStartDevices(void);
|
||||
|
||||
|
@ -243,7 +246,8 @@ extern void CloseDownDevices(void);
|
|||
extern void UndisplayDevices(void);
|
||||
|
||||
extern _X_EXPORT int RemoveDevice(
|
||||
DeviceIntPtr /*dev*/);
|
||||
DeviceIntPtr /*dev*/,
|
||||
BOOL /* sendevent */);
|
||||
|
||||
extern _X_EXPORT int NumMotionEvents(void);
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user