Start devices after windows are initialized.

This fixes the hotplug segfault introduced with the multihead changes and
cleans up the code a bit as well.
This commit is contained in:
Peter Hutterer 2007-05-01 15:49:41 +09:30
parent 11d0e2109b
commit 0214d0b96a
4 changed files with 45 additions and 57 deletions

View File

@ -202,10 +202,11 @@ EnableDevice(DeviceIntPtr dev)
prev = &(*prev)->next)
;
/* Sprites will be initialized with their 'windows' just when inside the
* DefineInitialRootWindow function! */
/* Sprites pop up on the first root window, so we can supply it directly
* here.
*/
if (IsPointerDevice(dev) && dev->spriteInfo->spriteOwner)
InitializeSprite(dev, NullWindow);
InitializeSprite(dev, WindowTable[0]);
else
PairDevices(NULL, inputInfo.pointer, dev);
@ -301,11 +302,6 @@ ActivateDevice(DeviceIntPtr dev)
return ret;
}
int
DeactivateDevice(DeviceIntPtr dev)
{
}
static void
CoreKeyboardBell(int volume, DeviceIntPtr pDev, pointer arg, int something)
{
@ -451,14 +447,7 @@ InitCoreDevices(void)
dev->devPrivates[CoreDevicePrivatesIndex].ptr = NULL;
(void)ActivateDevice(dev);
/* Enable device, and then remove it from the device list. Virtual
* devices are kept separate, not in the standard device list.
*/
if (dev->inited && dev->startup)
EnableDevice(dev);
inputInfo.off_devices = inputInfo.devices = NULL;
inputInfo.keyboard = dev;
inputInfo.keyboard->next = NULL;
}
if (!inputInfo.pointer) {
@ -478,35 +467,25 @@ InitCoreDevices(void)
dev->coreGrab.ActivateGrab = ActivatePointerGrab;
dev->coreGrab.DeactivateGrab = DeactivatePointerGrab;
dev->coreEvents = FALSE;
dev->spriteInfo->spriteOwner = TRUE;
if (!AllocateDevicePrivate(dev, CoreDevicePrivatesIndex))
FatalError("Couldn't allocate pointer devPrivates\n");
dev->devPrivates[CoreDevicePrivatesIndex].ptr = NULL;
(void)ActivateDevice(dev);
/* Enable device, and then remove it from the device list. Virtual
* devices are kept separate, not in the standard device list.
*/
if (dev->inited && dev->startup)
EnableDevice(dev);
inputInfo.off_devices = inputInfo.devices = NULL;
inputInfo.pointer = dev;
inputInfo.pointer->next = NULL;
/* the core keyboard is initialised by now. set the keyboard's sprite
* to the core pointer's sprite. */
PairDevices(pairingClient, inputInfo.pointer, inputInfo.keyboard);
}
}
/**
* Activate and enable all devices.
*
* After InitAndStartDevices() all devices are finished with their setup
* routines and start emitting events.
* Each physical keyboard is paired with the first available unpaired pointer.
* InitAndStartDevices needs to be called AFTER the windows are initialized.
* Devices will start sending events after InitAndStartDevices() has
* completed.
*/
int
InitAndStartDevices(void)
InitAndStartDevices(WindowPtr root)
{
DeviceIntPtr dev, next;
@ -514,13 +493,6 @@ InitAndStartDevices(void)
DebugF("(dix) initialising device %d\n", dev->id);
ActivateDevice(dev);
}
for (dev = inputInfo.off_devices; dev; dev = next)
{
DebugF("(dix) enabling device %d\n", dev->id);
next = dev->next;
if (dev->inited && dev->startup)
(void)EnableDevice(dev);
}
if (!inputInfo.keyboard) {
ErrorF("No core keyboard\n");
@ -531,12 +503,37 @@ InitAndStartDevices(void)
return BadImplementation;
}
/* All of the devices are started up now. Try to pair each keyboard with a
* real pointer, if possible. */
/* Now enable all devices */
if (inputInfo.keyboard->inited && inputInfo.keyboard->startup)
EnableDevice(inputInfo.keyboard);
if (inputInfo.pointer->inited && inputInfo.pointer->startup)
EnableDevice(inputInfo.pointer);
/* Remove VCP and VCK from device list */
inputInfo.devices = NULL;
inputInfo.keyboard->next = inputInfo.pointer->next = NULL;
/* enable real devices */
for (dev = inputInfo.off_devices; dev; dev = next)
{
DebugF("(dix) enabling device %d\n", dev->id);
next = dev->next;
if (dev->inited && dev->startup)
(void)EnableDevice(dev);
}
/* All of the devices are started up now. Pair VCK with VCP, then
* pair each real keyboard with a real pointer.
*/
PairDevices(NULL, inputInfo.pointer, inputInfo.keyboard);
for (dev = inputInfo.devices; dev; dev = dev->next)
{
if (!DevHasCursor(dev))
PairDevices(NULL, GuessFreePointerDevice(), dev);
else
/* enter/leave counter on root window */
((FocusSemaphoresPtr)root->devPrivates[FocusPrivatesIndex].ptr)->enterleave++;
}
return Success;

View File

@ -2501,23 +2501,10 @@ void ReinitializeRootWindow(WindowPtr win, int xoff, int yoff)
void
DefineInitialRootWindow(WindowPtr win)
{
DeviceIntPtr pDev = inputInfo.devices;
#ifdef XEVIE
xeviewin = win;
#endif
InitializeSprite(inputInfo.pointer, win);
while (pDev)
{
if (DevHasCursor(pDev))
{
InitializeSprite(pDev, win);
((FocusSemaphoresPtr)win->devPrivates[FocusPrivatesIndex].ptr)->enterleave++;
}
pDev = pDev->next;
}
}
void

View File

@ -396,10 +396,6 @@ main(int argc, char *argv[], char *envp[])
if (!CreateRootWindow(pScreen))
FatalError("failed to create root window");
}
InitCoreDevices();
InitInput(argc, argv);
if (InitAndStartDevices() != Success)
FatalError("failed to initialize core devices");
InitFonts();
#ifdef BUILTIN_FONTS
@ -451,6 +447,12 @@ main(int argc, char *argv[], char *envp[])
for (i = 0; i < screenInfo.numScreens; i++)
InitRootWindow(WindowTable[i]);
DefineInitialRootWindow(WindowTable[0]);
InitCoreDevices();
InitInput(argc, argv);
if (InitAndStartDevices(WindowTable[0]) != Success)
FatalError("failed to initialize core devices");
SaveScreens(SCREEN_SAVER_FORCER, ScreenSaverReset);
#ifdef PANORAMIX

View File

@ -186,7 +186,9 @@ extern Bool ActivateDevice(
extern Bool DisableDevice(
DeviceIntPtr /*device*/);
extern int InitAndStartDevices(void);
extern int InitAndStartDevices(
WindowPtr /*root*/);
extern void CloseDownDevices(void);