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

View File

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

View File

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

View File

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