diff --git a/XTrap/xtrapdi.c b/XTrap/xtrapdi.c
index bc15bbd..f5106aa 100644
--- a/XTrap/xtrapdi.c
+++ b/XTrap/xtrapdi.c
@@ -102,7 +102,7 @@ globalref int_function XETrapProcVector[
 #ifndef VECTORED_EVENTS
 globalref int_function EventProcVector[XETrapCoreEvents];
 #else
-extern WindowPtr GetCurrentRootWindow();
+extern WindowPtr GetCurrentRootWindow(DeviceIntPtr);
 globalref int_function EventProcVector[128L];
 #endif
 static int_function keybd_process_inp = NULL;  /* Used for VECTORED_EVENTS */
@@ -1620,7 +1620,10 @@ int XETrapEventVector(ClientPtr client, 
                 (x_event->u.u.type <= MotionNotify) && 
                 (!x_event->u.keyButtonPointer.sameScreen)))
             {   /* we've moved/warped to another screen */
-                WindowPtr root_win = GetCurrentRootWindow();
+		/* XXX: We're getting inputInfo.pointer here, but I guess
+		 * it might be really wrong. Which mouse's current window
+		 * do we want here? */
+                WindowPtr root_win = GetCurrentRootWindow(inputInfo.pointer);
                 current_screen = root_win->drawable.pScreen->myNum;
             }
             data.hdr.screen = current_screen;
diff --git a/Xext/xevie.c b/Xext/xevie.c
index 7922913..0feb4d7 100644
--- a/Xext/xevie.c
+++ b/Xext/xevie.c
@@ -463,7 +463,7 @@ XevieKbdProcessInputProc(xEvent *xE, Dev
             xevieModifiersOn = TRUE;
 
         xE->u.keyButtonPointer.event = xeviewin->drawable.id;
-        xE->u.keyButtonPointer.root = GetCurrentRootWindow()->drawable.id;
+        xE->u.keyButtonPointer.root = GetCurrentRootWindow(dev)->drawable.id;
         xE->u.keyButtonPointer.child = (xeviewin->firstChild)
             ? xeviewin->firstChild->drawable.id:0;
         xE->u.keyButtonPointer.rootX = xeviehot.x;
diff --git a/Xext/xtest.c b/Xext/xtest.c
index 93e88c4..963029c 100644
--- a/Xext/xtest.c
+++ b/Xext/xtest.c
@@ -363,7 +363,7 @@ #endif /* XINPUT */
         if (!dev)
             dev = PickPointer(client);
 	if (ev->u.keyButtonPointer.root == None)
-	    root = GetCurrentRootWindow();
+	    root = GetCurrentRootWindow(dev);
 	else
 	{
 	    rc = dixLookupWindow(&root, ev->u.keyButtonPointer.root, client,
@@ -428,10 +428,10 @@ #ifdef PANORAMIX
 	if ((!noPanoramiXExtension
 	     && root->drawable.pScreen->myNum 
                 != XineramaGetCursorScreen(dev))
-	    || (noPanoramiXExtension && root != GetCurrentRootWindow()))
+	    || (noPanoramiXExtension && root != GetCurrentRootWindow(dev)))
 
 #else
-	if (root != GetCurrentRootWindow())
+	if (root != GetCurrentRootWindow(dev))
 #endif
 	{
 	    NewCurrentScreen(dev, root->drawable.pScreen,
diff --git a/Xi/exevents.c b/Xi/exevents.c
index 26f3640..d00dc29 100644
--- a/Xi/exevents.c
+++ b/Xi/exevents.c
@@ -835,7 +835,7 @@ SendEvent(ClientPtr client, DeviceIntPtr
 	/* If the input focus is PointerRootWin, send the event to where
 	 * the pointer is if possible, then perhaps propogate up to root. */
 	if (inputFocus == PointerRootWin)
-	    inputFocus = GetCurrentRootWindow();
+	    inputFocus = GetCurrentRootWindow(d);
 
 	if (IsParent(inputFocus, spriteWin)) {
 	    effectiveFocus = inputFocus;
diff --git a/Xi/querydp.c b/Xi/querydp.c
index d2ed0b8..6224f13 100644
--- a/Xi/querydp.c
+++ b/Xi/querydp.c
@@ -107,7 +107,7 @@ ProcXQueryDevicePointer(ClientPtr client
     rep.length = 0;
     rep.sequenceNumber = client->sequence;
     rep.mask = pDev->button->state | inputInfo.keyboard->key->state;
-    rep.root = (GetCurrentRootWindow())->drawable.id;
+    rep.root = (GetCurrentRootWindow(pDev))->drawable.id;
     rep.rootX = pSprite->hot.x;
     rep.rootY = pSprite->hot.y;
     rep.child = None;
diff --git a/dix/devices.c b/dix/devices.c
index 6edf138..fe50774 100644
--- a/dix/devices.c
+++ b/dix/devices.c
@@ -194,6 +194,14 @@ EnableDevice(DeviceIntPtr dev)
 	 *prev && (*prev != dev);
 	 prev = &(*prev)->next)
 	;
+
+    /* Sprites will be initialized with their 'windows' just when inside the
+     * DefineInitialRootWindow function! */
+    if (IsPointerDevice(dev) && dev->spriteInfo->spriteOwner)
+        InitializeSprite(dev, NullWindow);
+    else
+        PairDevices(NULL, inputInfo.pointer, dev);
+
     if ((*prev != dev) || !dev->inited ||
 	((ret = (*dev->deviceProc)(dev, DEVICE_ON)) != Success)) {
         ErrorF("couldn't enable device %d\n", dev->id);
@@ -202,11 +210,6 @@ EnableDevice(DeviceIntPtr dev)
     dev->enabled = TRUE;
     *prev = dev->next;
 
-    if (IsPointerDevice(dev) && dev->spriteInfo->spriteOwner)
-        InitializeSprite(dev, GetCurrentRootWindow());
-    else
-        PairDevices(NULL, inputInfo.pointer, dev);
-
     for (prev = &inputInfo.devices; *prev; prev = &(*prev)->next)
         ;
     *prev = dev;
@@ -611,8 +614,10 @@ #ifdef XKB
 	XkbRemoveResourceClient((DevicePtr)dev,dev->xkb_interest->resource);
 #endif
     
-    if (DevHasCursor(dev))
+    if (DevHasCursor(dev)) {
+	xfree(dev->spriteInfo->sprite->spriteTrace);
         xfree((pointer)dev->spriteInfo->sprite);
+    }
 
     /* a client may have the device set as client pointer */
     for (j = 0; j < currentMaxClients; j++)
diff --git a/dix/events.c b/dix/events.c
index 1733e2d..0ad5603 100644
--- a/dix/events.c
+++ b/dix/events.c
@@ -230,15 +230,7 @@ static struct {
     TimeStamp		time;
 } syncEvents;
 
-/*
- * The window trace information is used to avoid having to compute all the
- * windows between the root and the current pointer window each time a button
- * or key goes down. The grabs on each of those windows must be checked.
- */
-static WindowPtr *spriteTrace = (WindowPtr *)NULL;
-#define ROOT spriteTrace[0]
-static int spriteTraceSize = 0;
-static int spriteTraceGood;
+#define rootWindow spriteTrace[0]
 
 /** 
  * True if device owns a cursor, false if device shares a cursor sprite with
@@ -284,6 +276,7 @@ static void DoEnterLeaveEvents(
 ); 
 
 static WindowPtr XYToWindow(
+    DeviceIntPtr pDev,
     int x,
     int y
 );
@@ -607,7 +600,7 @@ #ifdef XEVIE
     xeviehot.y = pSprite->hot.y;
     xeviewin =
 #endif
-    pSprite->win = XYToWindow(pSprite->hot.x, pSprite->hot.y);
+    pSprite->win = XYToWindow(pDev, pSprite->hot.x, pSprite->hot.y);
 
     if (pSprite->win != prevSpriteWin)
     {
@@ -858,7 +851,7 @@ #ifdef XEVIE
     xeviehot.x = pSprite->hot.x;
     xeviehot.y = pSprite->hot.y;
 #endif
-    ROOT = WindowTable[pSprite->hot.pScreen->myNum];
+    pSprite->rootWindow = WindowTable[pSprite->hot.pScreen->myNum];
 }
 
 static void
@@ -974,9 +967,11 @@ PostNewCursor(DeviceIntPtr pDev)
 }
 
 _X_EXPORT WindowPtr
-GetCurrentRootWindow(void)
+GetCurrentRootWindow(DeviceIntPtr dev)
 {
-    return ROOT;
+    /* Since there is more than one mouse, there is one current root window for
+     * each mouse */
+    return dev->spriteInfo->sprite->rootWindow;
 }
 
 _X_EXPORT WindowPtr
@@ -1201,10 +1196,11 @@ ComputeFreezes(void)
 	count = replayDev->coreGrab.sync.evcount;
 	syncEvents.replayDev = (DeviceIntPtr)NULL;
 
-        w = XYToWindow( XE_KBPTR.rootX, XE_KBPTR.rootY);
-	for (i = 0; i < spriteTraceGood; i++)
+        w = XYToWindow(replayDev, XE_KBPTR.rootX, XE_KBPTR.rootY);
+	for (i = 0; i < replayDev->spriteInfo->sprite->spriteTraceGood; i++)
 	{
-	    if (syncEvents.replayWin == spriteTrace[i])
+	    if (syncEvents.replayWin ==
+		replayDev->spriteInfo->sprite->spriteTrace[i])
 	    {
 		if (!CheckDeviceGrabs(replayDev, xE, i+1, count)) {
 		    if (replayDev->focus)
@@ -1365,7 +1361,8 @@ DeactivatePointerGrab(DeviceIntPtr mouse
     DoEnterLeaveEvents(mouse, grab->window, 
                        mouse->spriteInfo->sprite->win, NotifyUngrab);
     if (grab->confineTo)
-	ConfineCursorToWindow(mouse, ROOT, FALSE, FALSE);
+	ConfineCursorToWindow(mouse, mouse->spriteInfo->sprite->rootWindow,
+			      FALSE, FALSE);
     PostNewCursor(mouse);
     if (grab->cursor)
 	FreeCursor(grab->cursor, (Cursor)0);
@@ -1888,7 +1885,7 @@ FixUpEventFromWindow(
 
     if (calcChild)
     {
-        WindowPtr w=spriteTrace[spriteTraceGood-1];
+        WindowPtr w= pSprite->spriteTrace[pSprite->spriteTraceGood-1];
 	/* If the search ends up past the root should the child field be 
 	 	set to none or should the value in the argument be passed 
 		through. It probably doesn't matter since everyone calls 
@@ -1913,7 +1910,7 @@ FixUpEventFromWindow(
  	    w = w->parent;
         } 	    
     }
-    XE_KBPTR.root = ROOT->drawable.id;
+    XE_KBPTR.root = pSprite->rootWindow->drawable.id;
     XE_KBPTR.event = pWin->drawable.id;
     if (pSprite->hot.pScreen == pWin->drawable.pScreen)
     {
@@ -2064,13 +2061,15 @@ #endif
 }
 
 static WindowPtr 
-XYToWindow(int x, int y)
+XYToWindow(DeviceIntPtr pDev, int x, int y)
 {
     WindowPtr  pWin;
     BoxRec		box;
+    SpritePtr pSprite;
 
-    spriteTraceGood = 1;	/* root window still there */
-    pWin = ROOT->firstChild;
+    pSprite = pDev->spriteInfo->sprite;
+    pSprite->spriteTraceGood = 1;	/* root window still there */
+    pWin = pSprite->rootWindow->firstChild;
     while (pWin)
     {
 	if ((pWin->mapped) &&
@@ -2094,21 +2093,22 @@ #ifdef SHAPE
 #endif
 	    )
 	{
-	    if (spriteTraceGood >= spriteTraceSize)
+	    if (pSprite->spriteTraceGood >= pSprite->spriteTraceSize)
 	    {
-		spriteTraceSize += 10;
+		pSprite->spriteTraceSize += 10;
 		Must_have_memory = TRUE; /* XXX */
-		spriteTrace = (WindowPtr *)xrealloc(
-		    spriteTrace, spriteTraceSize*sizeof(WindowPtr));
+		pSprite->spriteTrace = (WindowPtr *)xrealloc(
+		                    pSprite->spriteTrace,
+		                    pSprite->spriteTraceSize*sizeof(WindowPtr));
 		Must_have_memory = FALSE; /* XXX */
 	    }
-	    spriteTrace[spriteTraceGood++] = pWin;
+	    pSprite->spriteTrace[pSprite->spriteTraceGood++] = pWin;
 	    pWin = pWin->firstChild;
 	}
 	else
 	    pWin = pWin->nextSib;
     }
-    return spriteTrace[spriteTraceGood-1];
+    return pSprite->spriteTrace[pSprite->spriteTraceGood-1];
 }
 
 Bool
@@ -2129,7 +2129,7 @@ #endif
 	if (pSprite->hot.pScreen != pSprite->hotPhys.pScreen)
 	{
 	    pSprite->hot.pScreen = pSprite->hotPhys.pScreen;
-	    ROOT = WindowTable[pSprite->hot.pScreen->myNum];
+	    pSprite->rootWindow = WindowTable[pSprite->hot.pScreen->myNum];
 	}
 	pSprite->hot.x = XE_KBPTR.rootX;
 	pSprite->hot.y = XE_KBPTR.rootY;
@@ -2166,7 +2166,7 @@ #endif
 #ifdef XEVIE
     xeviewin =
 #endif
-    pSprite->win = XYToWindow(pSprite->hot.x, pSprite->hot.y);
+    pSprite->win = XYToWindow(pDev, pSprite->hot.x, pSprite->hot.y);
 #ifdef notyet
     if (!(pSprite->win->deliverableEvents &
 	  Motion_Filter(pDev->button))
@@ -2263,7 +2263,6 @@ DefineInitialRootWindow(WindowPtr win)
 #ifdef XEVIE
     xeviewin = win;
 #endif
-    ROOT = win;
 
     InitializeSprite(inputInfo.pointer, win);
 
@@ -2312,8 +2311,35 @@ InitializeSprite(DeviceIntPtr pDev, Wind
     {
         pSprite->current = wCursor(pWin);
         pSprite->current->refcnt++;
-    } else
+ 	pSprite->spriteTrace = (WindowPtr *)xalloc(32*sizeof(WindowPtr));
+	/* FIXME; spriteTrace[0] needs to be NULL, otherwise
+	* GetCurrentRootWindow() in EnableDevice() may return a
+	* invalid value. (whot) */
+	/* If I interpreted correctly what you wrote, I guess it's
+	 * fixed (PauloZanoni). */
+	memset(pSprite->spriteTrace, 0, 32 * sizeof(WindowPtr));
+	if (!pSprite->spriteTrace)
+	    FatalError("Failed to allocate spriteTrace");
+	pSprite->spriteTraceSize = 32;
+	memset(pSprite->spriteTrace, 0, 32 * sizeof(WindowPtr));
+
+	pSprite->rootWindow = pWin;
+	pSprite->spriteTraceGood = 1;
+
+	/* Maybe the right option here should be 'pScreen', but since the
+	 * enqueue/dequeue screens were alwyas initialized with
+	 * screenInfo.screens[0], I'll keep with it. */
+	pSprite->pEnqueueScreen = screenInfo.screens[0];
+	pSprite->pDequeueScreen = pSprite->pEnqueueScreen;
+
+    } else {
         pSprite->current = NullCursor;
+	pSprite->spriteTrace = NULL;
+	pSprite->spriteTraceSize = 0;
+	pSprite->spriteTraceGood = 0;
+	pSprite->pEnqueueScreen = screenInfo.screens[0];
+	pSprite->pDequeueScreen = pSprite->pEnqueueScreen;
+    }
 
     if (pScreen)
     {
@@ -2768,14 +2794,15 @@ #endif
 	}
   
 	if ((focus->win == NoneWin) ||
-	    (i >= spriteTraceGood) ||
-	    ((i > checkFirst) && (pWin != spriteTrace[i-1])))
+	    (i >= device->spriteInfo->sprite->spriteTraceGood) ||
+	    ((i > checkFirst) &&
+             (pWin != device->spriteInfo->sprite->spriteTrace[i-1])))
 	    return FALSE;
     }
 
-    for (; i < spriteTraceGood; i++)
+    for (; i < device->spriteInfo->sprite->spriteTraceGood; i++)
     {
-	pWin = spriteTrace[i];
+	pWin = device->spriteInfo->sprite->spriteTrace[i];
 	if (pWin->optional &&
 	    CheckPassiveGrabsOnWindow(pWin, device, xE, count))
 	    return TRUE;
@@ -2946,7 +2973,9 @@ #endif
         {
           xeviekb = keybd;
           if(!rootWin) {
-	      rootWin = GetCurrentRootWindow()->drawable.id;
+	      /* XXX I guess this really doesn't make sense, but I'm not sure
+               * about what to do exactly! */
+	      rootWin = GetCurrentRootWindow(keybd)->drawable.id;
           }
           xE->u.keyButtonPointer.event = xeviewin->drawable.id;
           xE->u.keyButtonPointer.root = rootWin;
@@ -3806,7 +3835,7 @@ DoFocusEvents(DeviceIntPtr dev, WindowPt
 	if ((fromWin == NullWindow) || (fromWin == PointerRootWin))
    	{
 	    if (fromWin == PointerRootWin)
-                FocusOutEvents(dev, pSprite->win, ROOT, mode,
+                FocusOutEvents(dev, pSprite->win, pSprite->rootWindow, mode,
                         NotifyPointer, TRUE);
 	    /* Notify all the roots */
 #ifdef PANORAMIX
@@ -3836,16 +3865,16 @@ #endif
 	    for (i=0; i<screenInfo.numScreens; i++)
 	        FocusEvent(dev, FocusIn, mode, in, WindowTable[i]);
 	if (toWin == PointerRootWin)
-	    (void)FocusInEvents(dev, ROOT, pSprite->win, NullWindow, mode,
-				NotifyPointer, TRUE);
+	    (void)FocusInEvents(dev, pSprite->rootWindow, pSprite->win,
+				NullWindow, mode, NotifyPointer, TRUE);
     }
     else
     {
 	if ((fromWin == NullWindow) || (fromWin == PointerRootWin))
 	{
 	    if (fromWin == PointerRootWin)
-		FocusOutEvents(dev, pSprite->win, ROOT, mode, NotifyPointer,
-			       TRUE);
+		FocusOutEvents(dev, pSprite->win, pSprite->rootWindow, mode,
+			       NotifyPointer, TRUE);
 #ifdef PANORAMIX
  	    if ( !noPanoramiXExtension )
 	        FocusEvent(dev, FocusOut, mode, out, WindowTable[0]);
@@ -3854,7 +3883,7 @@ #endif
 	        for (i=0; i<screenInfo.numScreens; i++)
 	            FocusEvent(dev, FocusOut, mode, out, WindowTable[i]);
 	    if (toWin->parent != NullWindow)
-	      (void)FocusInEvents(dev, ROOT, toWin, toWin, mode,
+	      (void)FocusInEvents(dev, pSprite->rootWindow, toWin, toWin, mode,
 				  NotifyNonlinearVirtual, TRUE);
 	    FocusEvent(dev, FocusIn, mode, NotifyNonlinear, toWin);
 	    if (IsParent(toWin, pSprite->win))
@@ -4130,7 +4159,9 @@ ProcGrabPointer(ClientPtr client)
 	if (grab)
  	{
 	    if (grab->confineTo && !confineTo)
-		ConfineCursorToWindow(device, ROOT, FALSE, FALSE);
+		ConfineCursorToWindow(device,
+				      device->spriteInfo->sprite->rootWindow,
+				      FALSE, FALSE);
 	    oldCursor = grab->cursor;
 	}
 	tempGrab.cursor = cursor;
@@ -4351,7 +4382,7 @@ ProcQueryPointer(ClientPtr client)
     rep.sequenceNumber = client->sequence;
     rep.mask = mouse->button->state | inputInfo.keyboard->key->state;
     rep.length = 0;
-    rep.root = (ROOT)->drawable.id;
+    rep.root = (pSprite->rootWindow)->drawable.id;
     rep.rootX = pSprite->hot.x;
     rep.rootY = pSprite->hot.y;
     rep.child = None;
@@ -4400,19 +4431,6 @@ InitEvents(void)
     inputInfo.off_devices = (DeviceIntPtr)NULL;
     inputInfo.keyboard = (DeviceIntPtr)NULL;
     inputInfo.pointer = (DeviceIntPtr)NULL;
-    if (spriteTraceSize == 0)
-    {
-	spriteTraceSize = 32;
-	spriteTrace = (WindowPtr *)xalloc(32*sizeof(WindowPtr));
-        /* FIXME: spriteTrace[0] needs to be NULL, otherwise
-         * GetCurrentRootWindow() in EnableDevice() may return a invalid
-         * value. (whot)
-         */
-        memset(spriteTrace, 0, 32 * sizeof(WindowPtr));
-	if (!spriteTrace)
-	    FatalError("failed to allocate spriteTrace");
-    }
-    spriteTraceGood = 0;
     lastEventMask = OwnerGrabButtonMask;
     filters[MotionNotify] = PointerMotionMask;
 #ifdef XEVIE
@@ -4445,9 +4463,9 @@ #endif
 void
 CloseDownEvents(void)
 {
-  xfree(spriteTrace);
-  spriteTrace = NULL;
-  spriteTraceSize = 0;
+    /* This function was used to free spriteTraces, but now they are
+     * freed when SpriteRec is freed.
+     * Should this function be removed? */
 }
 
 int
@@ -4497,7 +4515,7 @@ ProcSendEvent(ClientPtr client)
 	/* If the input focus is PointerRootWin, send the event to where
 	the pointer is if possible, then perhaps propogate up to root. */
    	if (inputFocus == PointerRootWin)
-	    inputFocus = ROOT;
+	    inputFocus = pSprite->rootWindow;
 
 	if (IsParent(inputFocus, pSprite->win))
 	{
diff --git a/dix/main.c b/dix/main.c
index f5b89ba..d2bf57b 100644
--- a/dix/main.c
+++ b/dix/main.c
@@ -498,7 +498,7 @@ #endif
 	    FreeScreen(screenInfo.screens[i]);
 	    screenInfo.numScreens = i;
 	}
-  	CloseDownEvents();
+	CloseDownEvents();
 	xfree(WindowTable);
 	WindowTable = NULL;
 	FreeFonts();
diff --git a/hw/xwin/winwin32rootlesswndproc.c b/hw/xwin/winwin32rootlesswndproc.c
index ffa8493..54df889 100755
--- a/hw/xwin/winwin32rootlesswndproc.c
+++ b/hw/xwin/winwin32rootlesswndproc.c
@@ -299,7 +299,9 @@ IsRaiseOnClick (WindowPtr pWin)
 
   struct _Window	*pwin;
   struct _Property	*prop;  
-  WindowPtr		pRoot = GetCurrentRootWindow ();
+  /* XXX We're getting inputInfo.poniter here, but this might be really wrong.
+   * Which pointer's current window do we want? */
+  WindowPtr		pRoot = GetCurrentRootWindow (inputInfo.pointer);
 
   if (!pWin)
     {
@@ -352,7 +354,9 @@ IsMouseActive (WindowPtr pWin)
 
   struct _Window	*pwin;
   struct _Property	*prop;
-  WindowPtr		pRoot = GetCurrentRootWindow ();
+  /* XXX We're getting inputInfo.poniter here, but this might be really wrong.
+   * Which pointer's current window do we want? */
+  WindowPtr		pRoot = GetCurrentRootWindow (inputInfo.pointer);
 
   if (!pWin)
     {
diff --git a/include/dix.h b/include/dix.h
index 385f56c..9da265d 100644
--- a/include/dix.h
+++ b/include/dix.h
@@ -357,7 +357,7 @@ extern Bool IsParent(
     WindowPtr /* maybeparent */,
     WindowPtr /* child */);
 
-extern WindowPtr GetCurrentRootWindow(void);
+extern WindowPtr GetCurrentRootWindow(DeviceIntPtr pDev);
 
 extern WindowPtr GetSpriteWindow(DeviceIntPtr pDev);
 
diff --git a/include/inputstr.h b/include/inputstr.h
index bdb7518..4ed6903 100644
--- a/include/inputstr.h
+++ b/include/inputstr.h
@@ -287,6 +287,18 @@ #ifdef PANORAMIX
     WindowPtr   windows[MAXSCREENS];
     WindowPtr	confineWin;	/* confine window */ 
 #endif
+    /* The window trace information is used at dix/events.c to avoid having
+     *  to compute all the windows between the root and the current pointer
+     *  window each time a button or key goes down. The grabs on each of those
+     *  windows must be checked.
+     *  spriteTraces should only be used at dix/events.c! */
+    WindowPtr *spriteTrace;
+    int spriteTraceSize;
+    int spriteTraceGood;
+    /* pEnqueueScreen and pDequeueScreen were moved from mieq to here! */
+    ScreenPtr pEnqueueScreen; /* screen events are being delivered to */
+    ScreenPtr pDequeueScreen; /* screen events are being dispatched to */
+
 } SpriteRec, *SpritePtr;
 
 /* states for devices */
diff --git a/mi/mi.h b/mi/mi.h
index fad2d19..f83c42b 100644
--- a/mi/mi.h
+++ b/mi/mi.h
@@ -158,6 +158,7 @@ extern void mieqEnqueue(
 );
 
 extern void mieqSwitchScreen(
+    DeviceIntPtr /* pDev */,
     ScreenPtr /*pScreen*/,
     Bool /*fromDIX*/
 );
diff --git a/mi/mieq.c b/mi/mieq.c
index 143a94f..6edc7ee 100644
--- a/mi/mieq.c
+++ b/mi/mieq.c
@@ -79,8 +79,6 @@ typedef struct _EventQueue {
     CARD32           lastEventTime;      /* to avoid time running backwards */
     int              lastMotion;         /* device ID if last event motion? */
     EventRec         events[QUEUE_SIZE]; /* static allocation for signals */
-    ScreenPtr        pEnqueueScreen;     /* screen events are being delivered to */
-    ScreenPtr        pDequeueScreen;     /* screen events are being dispatched to */
     mieqHandler      handlers[128];      /* custom event handler */
 } EventQueueRec, *EventQueuePtr;
 
@@ -94,8 +92,6 @@ mieqInit(void)
     miEventQueue.head = miEventQueue.tail = 0;
     miEventQueue.lastEventTime = GetTimeInMillis ();
     miEventQueue.lastMotion = FALSE;
-    miEventQueue.pEnqueueScreen = screenInfo.screens[0];
-    miEventQueue.pDequeueScreen = miEventQueue.pEnqueueScreen;
     for (i = 0; i < 128; i++)
         miEventQueue.handlers[i] = NULL;
     SetInputCheck(&miEventQueue.head, &miEventQueue.tail);
@@ -179,18 +175,19 @@ mieqEnqueue(DeviceIntPtr pDev, xEvent *e
 
     miEventQueue.lastEventTime =
 	miEventQueue.events[oldtail].event[0].u.keyButtonPointer.time;
-    miEventQueue.events[oldtail].pScreen = miEventQueue.pEnqueueScreen;
+    miEventQueue.events[oldtail].pScreen =
+				       pDev->spriteInfo->sprite->pEnqueueScreen;
     miEventQueue.events[oldtail].pDev = pDev;
 
     miEventQueue.lastMotion = isMotion;
 }
 
 void
-mieqSwitchScreen(ScreenPtr pScreen, Bool fromDIX)
+mieqSwitchScreen(DeviceIntPtr pDev, ScreenPtr pScreen, Bool fromDIX)
 {
-    miEventQueue.pEnqueueScreen = pScreen;
+    pDev->spriteInfo->sprite->pEnqueueScreen = pScreen;
     if (fromDIX)
-	miEventQueue.pDequeueScreen = pScreen;
+	pDev->spriteInfo->sprite->pDequeueScreen = pScreen;
 }
 
 void
@@ -224,15 +221,16 @@ #endif
 
         e = &miEventQueue.events[miEventQueue.head];
         /* Assumption - screen switching can only occur on motion events. */
-        if (e->pScreen != miEventQueue.pDequeueScreen) {
-            miEventQueue.pDequeueScreen = e->pScreen;
+        if (e->pScreen != e->pDev->spriteInfo->sprite->pDequeueScreen) {
+            e->pDev->spriteInfo->sprite->pDequeueScreen = e->pScreen;
             x = e->event[0].u.keyButtonPointer.rootX;
             y = e->event[0].u.keyButtonPointer.rootY;
             if (miEventQueue.head == QUEUE_SIZE - 1)
                 miEventQueue.head = 0;
             else
                 ++miEventQueue.head;
-            NewCurrentScreen (e->pDev, miEventQueue.pDequeueScreen, x, y);
+            NewCurrentScreen (e->pDev,
+			     e->pDev->spriteInfo->sprite->pDequeueScreen, x, y);
         }
         else {
             if (miEventQueue.head == QUEUE_SIZE - 1)
@@ -243,7 +241,7 @@ #endif
             /* If someone's registered a custom event handler, let them
              * steal it. */
             if (miEventQueue.handlers[e->event->u.u.type]) {
-                miEventQueue.handlers[e->event->u.u.type](miEventQueue.pDequeueScreen->myNum,
+                miEventQueue.handlers[e->event->u.u.type](e->pDev->spriteInfo->sprite->pDequeueScreen->myNum,
                                                           e->event, dev,
                                                           e->nevents);
                 return;
diff --git a/mi/mipointer.c b/mi/mipointer.c
index b06a0be..b14c2c7 100644
--- a/mi/mipointer.c
+++ b/mi/mipointer.c
@@ -351,7 +351,7 @@ miPointerWarpCursor (pDev, pScreen, x, y
     SetupScreen (pScreen);
 
     if (pPointer->pScreen != pScreen)
-	(*pScreenPriv->screenFuncs->NewEventScreen) (pScreen, TRUE);
+	(*pScreenPriv->screenFuncs->NewEventScreen) (pDev, pScreen, TRUE);
 
     if (GenerateEvent)
     {
@@ -492,7 +492,7 @@ miPointerSetScreen(DeviceIntPtr pDev, in
 
 	pScreen = screenInfo.screens[screen_no];
 	pScreenPriv = GetScreenPrivate (pScreen);
-	(*pScreenPriv->screenFuncs->NewEventScreen) (pScreen, FALSE);
+	(*pScreenPriv->screenFuncs->NewEventScreen) (pDev, pScreen, FALSE);
 	NewCurrentScreen (pDev, pScreen, x, y);
 
         pPointer->limits.x2 = pScreen->width;
@@ -570,7 +570,8 @@ miPointerSetPosition(DeviceIntPtr pDev, 
 	    if (newScreen != pScreen)
 	    {
 		pScreen = newScreen;
-		(*pScreenPriv->screenFuncs->NewEventScreen) (pScreen, FALSE);
+		(*pScreenPriv->screenFuncs->NewEventScreen) (pDev, pScreen,
+							     FALSE);
 		pScreenPriv = GetScreenPrivate (pScreen);
 	    	/* Smash the confine to the new screen */
                 pPointer->limits.x2 = pScreen->width;
diff --git a/mi/mipointer.h b/mi/mipointer.h
index 666a6eb..cc9c037 100644
--- a/mi/mipointer.h
+++ b/mi/mipointer.h
@@ -88,6 +88,7 @@ typedef struct _miPointerScreenFuncRec {
                     xEventPtr /* event */
                     );
     void	(*NewEventScreen)(
+		    DeviceIntPtr /* pDev */,
                     ScreenPtr /* pScr */,
 		    Bool /* fromDIX */
                     );
diff --git a/randr/rrpointer.c b/randr/rrpointer.c
index fec5d45..8bb805e 100644
--- a/randr/rrpointer.c
+++ b/randr/rrpointer.c
@@ -135,10 +135,17 @@ RRPointerMoved (ScreenPtr pScreen, int x
 void
 RRPointerScreenConfigured (ScreenPtr pScreen)
 {
-    WindowPtr	pRoot = GetCurrentRootWindow ();
+    WindowPtr	pRoot = GetCurrentRootWindow (inputInfo.pointer);
     ScreenPtr	pCurrentScreen = pRoot ? pRoot->drawable.pScreen : NULL;
     int		x, y;
 
+    /* XXX: GetCurrentRootWindow now revices an argument, I've put
+      * inputInfo.pointer, but I really think this is wrong...
+     * What do we do here? I've made this so that it can compile,
+     * but I don't think randr should assume there is just one pointer.
+     * There might be more than one pointer on the screen! So, what to do?
+     * What happens? */
+
     if (pScreen != pCurrentScreen)
 	return;
     GetSpritePosition(inputInfo.pointer, &x, &y);
