This mostly ensures that the cursor is created after the server is up and running with all of the DevPrivate keys initialized. However, it will also save a tiny amount of memory on systems where the invisible cursor is never used.
Signed-off-by: Keith Packard <[email protected]> --- xfixes/cursor.c | 78 +++++++++++++++++++++++++++++------------------------- 1 files changed, 42 insertions(+), 36 deletions(-) diff --git a/xfixes/cursor.c b/xfixes/cursor.c index b7e6c7b..c39f10d 100644 --- a/xfixes/cursor.c +++ b/xfixes/cursor.c @@ -58,7 +58,7 @@ static RESTYPE CursorClientType; static RESTYPE CursorHideCountType; static RESTYPE CursorWindowType; static CursorPtr CursorCurrent[MAXDEVICES]; -static CursorPtr pInvisibleCursor = NULL; +static CursorPtr pInvisibleCursor; static int CursorScreenPrivateKeyIndex; static DevPrivateKey CursorScreenPrivateKey = &CursorScreenPrivateKeyIndex; @@ -132,6 +132,45 @@ static Bool CursorVisible = FALSE; Bool EnableCursor = TRUE; +static CursorPtr +createInvisibleCursor (void) +{ + CursorPtr pCursor; + unsigned char *psrcbits, *pmaskbits; + CursorMetricRec cm; + + psrcbits = (unsigned char *) calloc(4, 1); + pmaskbits = (unsigned char *) calloc(4, 1); + if (psrcbits == NULL || pmaskbits == NULL) { + return NULL; + } + + cm.width = 1; + cm.height = 1; + cm.xhot = 0; + cm.yhot = 0; + + if (AllocARGBCursor(psrcbits, pmaskbits, + NULL, &cm, + 0, 0, 0, + 0, 0, 0, + &pCursor, serverClient, (XID)0) != Success) + return NullCursor; + + if (!AddResource(FakeClientID(0), RT_CURSOR, (pointer) pCursor)) + return NullCursor; + + return pCursor; +} + +static Bool +haveInvisibleCursor(void) +{ + if (!pInvisibleCursor) + pInvisibleCursor = createInvisibleCursor(); + return pInvisibleCursor != NULL; +} + static Bool CursorDisplayCursor (DeviceIntPtr pDev, ScreenPtr pScreen, @@ -150,7 +189,7 @@ CursorDisplayCursor (DeviceIntPtr pDev, if (ConnectionInfo) CursorVisible = EnableCursor; - if (cs->pCursorHideCounts != NULL || !CursorVisible) { + if ((cs->pCursorHideCounts != NULL || !CursorVisible) && haveInvisibleCursor()) { ret = ((*pScreen->RealizeCursor)(pDev, pScreen, pInvisibleCursor) && (*pScreen->DisplayCursor) (pDev, pScreen, pInvisibleCursor)); } else { @@ -1036,37 +1075,6 @@ CursorFreeWindow (pointer data, XID id) return 1; } -static CursorPtr -createInvisibleCursor (void) -{ - CursorPtr pCursor; - unsigned char *psrcbits, *pmaskbits; - CursorMetricRec cm; - - psrcbits = (unsigned char *) calloc(4, 1); - pmaskbits = (unsigned char *) calloc(4, 1); - if (psrcbits == NULL || pmaskbits == NULL) { - return NULL; - } - - cm.width = 1; - cm.height = 1; - cm.xhot = 0; - cm.yhot = 0; - - if (AllocARGBCursor(psrcbits, pmaskbits, - NULL, &cm, - 0, 0, 0, - 0, 0, 0, - &pCursor, serverClient, (XID)0) != Success) - return NullCursor; - - if (!AddResource(FakeClientID(0), RT_CURSOR, (pointer) pCursor)) - return NullCursor; - - return pCursor; -} - Bool XFixesCursorInit (void) { @@ -1095,9 +1103,7 @@ XFixesCursorInit (void) CursorWindowType = CreateNewResourceType(CursorFreeWindow, "XFixesCursorWindow"); - pInvisibleCursor = createInvisibleCursor(); - if (pInvisibleCursor == NULL) - return BadAlloc; + pInvisibleCursor = NULL; return CursorClientType && CursorHideCountType && CursorWindowType; } -- 1.7.1 _______________________________________________ [email protected]: X.Org development Archives: http://lists.x.org/archives/xorg-devel Info: http://lists.x.org/mailman/listinfo/xorg-devel
