From cf105bc990a2c9f0c0027b2f6c6ffe2985ca0fe0 Mon Sep 17 00:00:00 2001 From: "Enrico Weigelt, metux IT consult" Date: Wed, 1 Oct 2025 14:37:31 +0200 Subject: [PATCH] dix/Xinerama: untwist X_AllocColor request handling Instead of internally faking requests, factor out the actual logic into separate function, which is getting everything it needs as parameters, so no need to fiddle with request buffer anymore. Signed-off-by: Enrico Weigelt, metux IT consult --- Xext/panoramiXprocs.c | 35 +++++++++++++++++++++++++++++++---- dix/dispatch.c | 37 +++++++++++++++++++------------------ dix/dix_priv.h | 16 ++++++++++++++++ 3 files changed, 66 insertions(+), 22 deletions(-) diff --git a/Xext/panoramiXprocs.c b/Xext/panoramiXprocs.c index 6cadc38494..7489e9c81c 100644 --- a/Xext/panoramiXprocs.c +++ b/Xext/panoramiXprocs.c @@ -2509,13 +2509,40 @@ PanoramiXAllocColor(ClientPtr client) return result; XINERAMA_FOR_EACH_SCREEN_BACKWARD({ - stuff->cmap = cmap->info[walkScreenIdx].id; - result = (*SavedProcVector[X_AllocColor]) (client); + Colormap childCmap = cmap->info[walkScreenIdx].id; + + CARD16 red = stuff->red; + CARD16 green = stuff->green; + CARD16 blue = stuff->blue; + CARD32 pixel = 0; + + result = dixAllocColor(client, childCmap, &red, &green, &blue, &pixel); if (result != Success) - break; + return result; + + /* only send out reply for on first screen */ + if (!walkScreenIdx) { + xAllocColorReply rep; /* static init would confuse preprocessor */ + rep.red = red; + rep.green = green; + rep.blue = blue; + rep.pixel = pixel; + + if (client->swapped) { + swaps(&rep.red); + swaps(&rep.green); + swaps(&rep.blue); + swapl(&rep.pixel); + } + + /* iterating backwards, first screen comes last, so we can return here */ + return X_SEND_REPLY_SIMPLE(client, rep); + } }); - return result; + /* shouldn't ever reach here, because we already returned from within the loop + if this ever happens, PanoramiXNumScreens must be 0 */ + return BadImplementation; } int diff --git a/dix/dispatch.c b/dix/dispatch.c index b1b06f2219..a523e9f142 100644 --- a/dix/dispatch.c +++ b/dix/dispatch.c @@ -2682,21 +2682,26 @@ ProcListInstalledColormaps(ClientPtr client) return X_SEND_REPLY_WITH_RPCBUF(client, rep, rpcbuf); } +int dixAllocColor(ClientPtr client, Colormap cmap, CARD16 *red, + CARD16 *green, CARD16 *blue, CARD32 *pixel) +{ + ColormapPtr pmap; + int rc = dixLookupResourceByType((void **) &pmap, + cmap, + X11_RESTYPE_COLORMAP, + client, + DixAddAccess); + if (rc != Success) + return rc; + + return AllocColor(pmap, red, green, blue, pixel, client->index); +} + int ProcAllocColor(ClientPtr client) { - ColormapPtr pmap; - int rc; - REQUEST(xAllocColorReq); - REQUEST_SIZE_MATCH(xAllocColorReq); - rc = dixLookupResourceByType((void **) &pmap, stuff->cmap, X11_RESTYPE_COLORMAP, - client, DixAddAccess); - if (rc != Success) { - client->errorValue = stuff->cmap; - return rc; - } xAllocColorReply rep = { .red = stuff->red, @@ -2704,9 +2709,11 @@ ProcAllocColor(ClientPtr client) .blue = stuff->blue, }; - if ((rc = AllocColor(pmap, &rep.red, &rep.green, &rep.blue, - &rep.pixel, client->index))) + int rc = dixAllocColor(client, stuff->cmap, &rep.red, &rep.green, &rep.blue, &rep.pixel); + if (rc != Success) { + client->errorValue = stuff->cmap; return rc; + } if (client->swapped) { swaps(&rep.red); @@ -2715,13 +2722,7 @@ ProcAllocColor(ClientPtr client) swapl(&rep.pixel); } -#ifdef XINERAMA - if (noPanoramiXExtension || !pmap->pScreen->myNum) - return X_SEND_REPLY_SIMPLE(client, rep); - return Success; -#else return X_SEND_REPLY_SIMPLE(client, rep); -#endif /* XINERAMA */ } int diff --git a/dix/dix_priv.h b/dix/dix_priv.h index aa2b993b1a..a1e1f37af3 100644 --- a/dix/dix_priv.h +++ b/dix/dix_priv.h @@ -745,4 +745,20 @@ static inline int xmitClientEvent(ClientPtr pClient, xEvent ev) return WriteToClient(pClient, sizeof(xEvent), &ev); } +/* + * allocate color for given client + * the colors channel values need to be filled into the fields pointed + * to by the parameters, and the actually allocated ones are returned there + * + * @param client pointer to client + * @param cmap XID of the cmap to use + * @param red pointer to red channel value + * @param green pointer to green channel value + * @param blue pointer to blue channel value + * @param pixel pointer to return buffer for pixel value + * @return X11 error code + */ +int dixAllocColor(ClientPtr client, Colormap cmap, CARD16 *red, + CARD16 *green, CARD16 *blue, CARD32 *pixel); + #endif /* _XSERVER_DIX_PRIV_H */