Allow for multiple animated cursors.

This commit is contained in:
Peter Hutterer 2007-04-04 17:38:10 +09:30
parent 676188531b
commit 7f36ba5706

View File

@ -80,7 +80,8 @@ typedef struct _AnimCurState {
CARD32 time; CARD32 time;
} AnimCurStateRec, *AnimCurStatePtr; } AnimCurStateRec, *AnimCurStatePtr;
static AnimCurStateRec animCurState; /* What a waste. But we need an API change to alloc it per device only. */
static AnimCurStateRec animCurState[MAX_DEVICES];
static unsigned char empty[4]; static unsigned char empty[4];
@ -175,35 +176,47 @@ AnimCurScreenBlockHandler (int screenNum,
{ {
ScreenPtr pScreen = screenInfo.screens[screenNum]; ScreenPtr pScreen = screenInfo.screens[screenNum];
AnimCurScreenPtr as = GetAnimCurScreen(pScreen); AnimCurScreenPtr as = GetAnimCurScreen(pScreen);
DeviceIntPtr dev;
CARD32 now = 0,
soonest = ~0; /* earliest time to wakeup again */
if (pScreen == animCurState.pScreen) for (dev = inputInfo.devices; dev; dev = dev->next)
{ {
CARD32 now = GetTimeInMillis (); if (IsPointerDevice(dev) && pScreen == animCurState[dev->id].pScreen)
if ((INT32) (now - animCurState.time) >= 0)
{ {
AnimCurPtr ac = GetAnimCur(animCurState.pCursor); if (!now) now = GetTimeInMillis ();
int elt = (animCurState.elt + 1) % ac->nelt;
DisplayCursorProcPtr DisplayCursor;
/* if ((INT32) (now - animCurState[dev->id].time) >= 0)
* Not a simple Unwrap/Wrap as this {
* isn't called along the DisplayCursor AnimCurPtr ac = GetAnimCur(animCurState[dev->id].pCursor);
* wrapper chain. int elt = (animCurState[dev->id].elt + 1) % ac->nelt;
*/ DisplayCursorProcPtr DisplayCursor;
DisplayCursor = pScreen->DisplayCursor;
pScreen->DisplayCursor = as->DisplayCursor;
(void) (*pScreen->DisplayCursor) (inputInfo.pointer,
pScreen,
ac->elts[elt].pCursor);
as->DisplayCursor = pScreen->DisplayCursor;
pScreen->DisplayCursor = DisplayCursor;
animCurState.elt = elt; /*
animCurState.time = now + ac->elts[elt].delay; * Not a simple Unwrap/Wrap as this
* isn't called along the DisplayCursor
* wrapper chain.
*/
DisplayCursor = pScreen->DisplayCursor;
pScreen->DisplayCursor = as->DisplayCursor;
(void) (*pScreen->DisplayCursor) (dev,
pScreen,
ac->elts[elt].pCursor);
as->DisplayCursor = pScreen->DisplayCursor;
pScreen->DisplayCursor = DisplayCursor;
animCurState[dev->id].elt = elt;
animCurState[dev->id].time = now + ac->elts[elt].delay;
}
if (soonest > animCurState[dev->id].time)
soonest = animCurState[dev->id].time;
} }
AdjustWaitForDelay (pTimeout, animCurState.time - now);
} }
if (now)
AdjustWaitForDelay (pTimeout, soonest - now);
Unwrap (as, pScreen, BlockHandler); Unwrap (as, pScreen, BlockHandler);
(*pScreen->BlockHandler) (screenNum, blockData, pTimeout, pReadmask); (*pScreen->BlockHandler) (screenNum, blockData, pTimeout, pReadmask);
Wrap (as, pScreen, BlockHandler, AnimCurScreenBlockHandler); Wrap (as, pScreen, BlockHandler, AnimCurScreenBlockHandler);
@ -220,7 +233,7 @@ AnimCurDisplayCursor (DeviceIntPtr pDev,
Unwrap (as, pScreen, DisplayCursor); Unwrap (as, pScreen, DisplayCursor);
if (IsAnimCur(pCursor)) if (IsAnimCur(pCursor))
{ {
if (pCursor != animCurState.pCursor) if (pCursor != animCurState[pDev->id].pCursor)
{ {
AnimCurPtr ac = GetAnimCur(pCursor); AnimCurPtr ac = GetAnimCur(pCursor);
@ -228,10 +241,10 @@ AnimCurDisplayCursor (DeviceIntPtr pDev,
(pDev, pScreen, ac->elts[0].pCursor); (pDev, pScreen, ac->elts[0].pCursor);
if (ret) if (ret)
{ {
animCurState.elt = 0; animCurState[pDev->id].elt = 0;
animCurState.time = GetTimeInMillis () + ac->elts[0].delay; animCurState[pDev->id].time = GetTimeInMillis () + ac->elts[0].delay;
animCurState.pCursor = pCursor; animCurState[pDev->id].pCursor = pCursor;
animCurState.pScreen = pScreen; animCurState[pDev->id].pScreen = pScreen;
} }
} }
else else
@ -239,8 +252,8 @@ AnimCurDisplayCursor (DeviceIntPtr pDev,
} }
else else
{ {
animCurState.pCursor = 0; animCurState[pDev->id].pCursor = 0;
animCurState.pScreen = 0; animCurState[pDev->id].pScreen = 0;
ret = (*pScreen->DisplayCursor) (pDev, pScreen, pCursor); ret = (*pScreen->DisplayCursor) (pDev, pScreen, pCursor);
} }
Wrap (as, pScreen, DisplayCursor, AnimCurDisplayCursor); Wrap (as, pScreen, DisplayCursor, AnimCurDisplayCursor);
@ -258,8 +271,8 @@ AnimCurSetCursorPosition (DeviceIntPtr pDev,
Bool ret; Bool ret;
Unwrap (as, pScreen, SetCursorPosition); Unwrap (as, pScreen, SetCursorPosition);
if (animCurState.pCursor) if (animCurState[pDev->id].pCursor)
animCurState.pScreen = pScreen; animCurState[pDev->id].pScreen = pScreen;
ret = (*pScreen->SetCursorPosition) (pDev, pScreen, x, y, generateEvent); ret = (*pScreen->SetCursorPosition) (pDev, pScreen, x, y, generateEvent);
Wrap (as, pScreen, SetCursorPosition, AnimCurSetCursorPosition); Wrap (as, pScreen, SetCursorPosition, AnimCurSetCursorPosition);
return ret; return ret;
@ -324,7 +337,7 @@ AnimCurRecolorCursor (DeviceIntPtr pDev,
for (i = 0; i < ac->nelt; i++) for (i = 0; i < ac->nelt; i++)
(*pScreen->RecolorCursor) (pDev, pScreen, ac->elts[i].pCursor, (*pScreen->RecolorCursor) (pDev, pScreen, ac->elts[i].pCursor,
displayed && displayed &&
animCurState.elt == i); animCurState[pDev->id].elt == i);
} }
else else
(*pScreen->RecolorCursor) (pDev, pScreen, pCursor, displayed); (*pScreen->RecolorCursor) (pDev, pScreen, pCursor, displayed);
@ -338,14 +351,17 @@ AnimCurInit (ScreenPtr pScreen)
if (AnimCurGeneration != serverGeneration) if (AnimCurGeneration != serverGeneration)
{ {
int i;
AnimCurScreenPrivateIndex = AllocateScreenPrivateIndex (); AnimCurScreenPrivateIndex = AllocateScreenPrivateIndex ();
if (AnimCurScreenPrivateIndex < 0) if (AnimCurScreenPrivateIndex < 0)
return FALSE; return FALSE;
AnimCurGeneration = serverGeneration; AnimCurGeneration = serverGeneration;
animCurState.pCursor = 0; for (i = 0; i < MAX_DEVICES; i++) {
animCurState.pScreen = 0; animCurState[i].pCursor = 0;
animCurState.elt = 0; animCurState[i].pScreen = 0;
animCurState.time = 0; animCurState[i].elt = 0;
animCurState[i].time = 0;
}
} }
as = (AnimCurScreenPtr) xalloc (sizeof (AnimCurScreenRec)); as = (AnimCurScreenPtr) xalloc (sizeof (AnimCurScreenRec));
if (!as) if (!as)