Xext: shape: use REQUEST_HEAD_STRUCT and REQUEST_FIELD_* macros

Use the new macros to make request struct parsing / field swapping
much easier.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
This commit is contained in:
Enrico Weigelt, metux IT consult
2024-07-03 02:45:34 +02:00
parent 109da9a188
commit a1f10d8f63

View File

@@ -35,6 +35,7 @@ in this Software without prior written authorization from The Open Group.
#include "dix/dix_priv.h"
#include "dix/gc_priv.h"
#include "dix/request_priv.h"
#include "misc.h"
#include "os.h"
@@ -207,24 +208,16 @@ CreateClipShape(WindowPtr pWin)
static int
ProcShapeQueryVersion(ClientPtr client)
{
REQUEST_HEAD_STRUCT(xShapeQueryVersionReq);
xShapeQueryVersionReply rep = {
.type = X_Reply,
.sequenceNumber = client->sequence,
.length = 0,
.majorVersion = SERVER_SHAPE_MAJOR_VERSION,
.minorVersion = SERVER_SHAPE_MINOR_VERSION
};
REQUEST_SIZE_MATCH(xShapeQueryVersionReq);
if (client->swapped) {
swaps(&rep.sequenceNumber);
swapl(&rep.length);
swaps(&rep.majorVersion);
swaps(&rep.minorVersion);
}
WriteToClient(client, sizeof(xShapeQueryVersionReply), &rep);
return Success;
REPLY_FIELD_CARD16(majorVersion);
REPLY_FIELD_CARD16(minorVersion);
REPLY_SEND_RET_SUCCESS();
}
static int
@@ -294,8 +287,11 @@ ShapeRectangles(ClientPtr client, xShapeRectanglesReq *stuff)
static int
ProcShapeRectangles(ClientPtr client)
{
REQUEST(xShapeRectanglesReq);
REQUEST_AT_LEAST_SIZE(xShapeRectanglesReq);
REQUEST_HEAD_AT_LEAST(xShapeRectanglesReq);
REQUEST_FIELD_CARD32(dest);
REQUEST_FIELD_CARD16(xOff);
REQUEST_FIELD_CARD16(yOff);
REQUEST_REST_CARD16();
#ifdef PANORAMIX
if (noPanoramiXExtension)
@@ -390,8 +386,11 @@ ShapeMask(ClientPtr client, xShapeMaskReq *stuff)
static int
ProcShapeMask(ClientPtr client)
{
REQUEST(xShapeMaskReq);
REQUEST_SIZE_MATCH(xShapeMaskReq);
REQUEST_HEAD_STRUCT(xShapeMaskReq);
REQUEST_FIELD_CARD32(dest);
REQUEST_FIELD_CARD16(xOff);
REQUEST_FIELD_CARD16(yOff);
REQUEST_FIELD_CARD32(src);
#ifdef PANORAMIX
if (noPanoramiXExtension)
@@ -516,8 +515,11 @@ ShapeCombine(ClientPtr client, xShapeCombineReq *stuff)
static int
ProcShapeCombine(ClientPtr client)
{
REQUEST(xShapeCombineReq);
REQUEST_AT_LEAST_SIZE(xShapeCombineReq);
REQUEST_HEAD_STRUCT(xShapeCombineReq);
REQUEST_FIELD_CARD32(dest);
REQUEST_FIELD_CARD16(xOff);
REQUEST_FIELD_CARD16(yOff);
REQUEST_FIELD_CARD32(src);
#ifdef PANORAMIX
if (noPanoramiXExtension)
@@ -585,8 +587,10 @@ ShapeOffset(ClientPtr client, xShapeOffsetReq *stuff)
static int
ProcShapeOffset(ClientPtr client)
{
REQUEST(xShapeOffsetReq);
REQUEST_AT_LEAST_SIZE(xShapeOffsetReq);
REQUEST_HEAD_AT_LEAST(xShapeOffsetReq);
REQUEST_FIELD_CARD32(dest);
REQUEST_FIELD_CARD16(yOff);
REQUEST_FIELD_CARD16(yOff);
#ifdef PANORAMIX
PanoramiXRes *win;
@@ -615,14 +619,15 @@ ProcShapeOffset(ClientPtr client)
static int
ProcShapeQueryExtents(ClientPtr client)
{
REQUEST(xShapeQueryExtentsReq);
REQUEST_HEAD_STRUCT(xShapeQueryExtentsReq);
REQUEST_FIELD_CARD32(window);
WindowPtr pWin;
xShapeQueryExtentsReply rep;
BoxRec extents, *pExtents;
int rc;
RegionPtr region;
REQUEST_SIZE_MATCH(xShapeQueryExtentsReq);
rc = dixLookupWindow(&pWin, stuff->window, client, DixGetAttrAccess);
if (rc != Success)
return rc;
@@ -724,13 +729,14 @@ ShapeFreeEvents(void *data, XID id)
static int
ProcShapeSelectInput(ClientPtr client)
{
REQUEST(xShapeSelectInputReq);
REQUEST_HEAD_STRUCT(xShapeSelectInputReq);
REQUEST_FIELD_CARD32(window);
WindowPtr pWin;
ShapeEventPtr pShapeEvent, pNewShapeEvent, *pHead;
XID clientResource;
int rc;
REQUEST_SIZE_MATCH(xShapeSelectInputReq);
rc = dixLookupWindow(&pWin, stuff->window, client, DixReceiveAccess);
if (rc != Success)
return rc;
@@ -895,13 +901,14 @@ SendShapeNotify(WindowPtr pWin, int which)
static int
ProcShapeInputSelected(ClientPtr client)
{
REQUEST(xShapeInputSelectedReq);
REQUEST_HEAD_STRUCT(xShapeInputSelectedReq);
REQUEST_FIELD_CARD32(window);
WindowPtr pWin;
ShapeEventPtr pShapeEvent, *pHead;
int enabled, rc;
xShapeInputSelectedReply rep;
REQUEST_SIZE_MATCH(xShapeInputSelectedReq);
rc = dixLookupWindow(&pWin, stuff->window, client, DixGetAttrAccess);
if (rc != Success)
return rc;
@@ -935,14 +942,15 @@ ProcShapeInputSelected(ClientPtr client)
static int
ProcShapeGetRectangles(ClientPtr client)
{
REQUEST(xShapeGetRectanglesReq);
REQUEST_HEAD_STRUCT(xShapeGetRectanglesReq);
REQUEST_FIELD_CARD32(window);
WindowPtr pWin;
xShapeGetRectanglesReply rep;
xRectangle *rects;
int nrects, i, rc;
RegionPtr region;
REQUEST_SIZE_MATCH(xShapeGetRectanglesReq);
rc = dixLookupWindow(&pWin, stuff->window, client, DixGetAttrAccess);
if (rc != Success)
return rc;
@@ -1063,141 +1071,6 @@ SShapeNotifyEvent(xShapeNotifyEvent * from, xShapeNotifyEvent * to)
to->shaped = from->shaped;
}
static int _X_COLD
SProcShapeQueryVersion(ClientPtr client)
{
REQUEST(xShapeQueryVersionReq);
swaps(&stuff->length);
return ProcShapeQueryVersion(client);
}
static int _X_COLD
SProcShapeRectangles(ClientPtr client)
{
REQUEST(xShapeRectanglesReq);
swaps(&stuff->length);
REQUEST_AT_LEAST_SIZE(xShapeRectanglesReq);
swapl(&stuff->dest);
swaps(&stuff->xOff);
swaps(&stuff->yOff);
SwapRestS(stuff);
return ProcShapeRectangles(client);
}
static int _X_COLD
SProcShapeMask(ClientPtr client)
{
REQUEST(xShapeMaskReq);
swaps(&stuff->length);
REQUEST_SIZE_MATCH(xShapeMaskReq);
swapl(&stuff->dest);
swaps(&stuff->xOff);
swaps(&stuff->yOff);
swapl(&stuff->src);
return ProcShapeMask(client);
}
static int _X_COLD
SProcShapeCombine(ClientPtr client)
{
REQUEST(xShapeCombineReq);
swaps(&stuff->length);
REQUEST_SIZE_MATCH(xShapeCombineReq);
swapl(&stuff->dest);
swaps(&stuff->xOff);
swaps(&stuff->yOff);
swapl(&stuff->src);
return ProcShapeCombine(client);
}
static int _X_COLD
SProcShapeOffset(ClientPtr client)
{
REQUEST(xShapeOffsetReq);
swaps(&stuff->length);
REQUEST_SIZE_MATCH(xShapeOffsetReq);
swapl(&stuff->dest);
swaps(&stuff->xOff);
swaps(&stuff->yOff);
return ProcShapeOffset(client);
}
static int _X_COLD
SProcShapeQueryExtents(ClientPtr client)
{
REQUEST(xShapeQueryExtentsReq);
swaps(&stuff->length);
REQUEST_SIZE_MATCH(xShapeQueryExtentsReq);
swapl(&stuff->window);
return ProcShapeQueryExtents(client);
}
static int _X_COLD
SProcShapeSelectInput(ClientPtr client)
{
REQUEST(xShapeSelectInputReq);
swaps(&stuff->length);
REQUEST_SIZE_MATCH(xShapeSelectInputReq);
swapl(&stuff->window);
return ProcShapeSelectInput(client);
}
static int _X_COLD
SProcShapeInputSelected(ClientPtr client)
{
REQUEST(xShapeInputSelectedReq);
swaps(&stuff->length);
REQUEST_SIZE_MATCH(xShapeInputSelectedReq);
swapl(&stuff->window);
return ProcShapeInputSelected(client);
}
static int _X_COLD
SProcShapeGetRectangles(ClientPtr client)
{
REQUEST(xShapeGetRectanglesReq);
swaps(&stuff->length);
REQUEST_SIZE_MATCH(xShapeGetRectanglesReq);
swapl(&stuff->window);
return ProcShapeGetRectangles(client);
}
static int _X_COLD
SProcShapeDispatch(ClientPtr client)
{
REQUEST(xReq);
switch (stuff->data) {
case X_ShapeQueryVersion:
return SProcShapeQueryVersion(client);
case X_ShapeRectangles:
return SProcShapeRectangles(client);
case X_ShapeMask:
return SProcShapeMask(client);
case X_ShapeCombine:
return SProcShapeCombine(client);
case X_ShapeOffset:
return SProcShapeOffset(client);
case X_ShapeQueryExtents:
return SProcShapeQueryExtents(client);
case X_ShapeSelectInput:
return SProcShapeSelectInput(client);
case X_ShapeInputSelected:
return SProcShapeInputSelected(client);
case X_ShapeGetRectangles:
return SProcShapeGetRectangles(client);
default:
return BadRequest;
}
}
void
ShapeExtensionInit(void)
{
@@ -1207,7 +1080,7 @@ ShapeExtensionInit(void)
ShapeEventType = CreateNewResourceType(ShapeFreeEvents, "ShapeEvent");
if (ClientType && ShapeEventType &&
(extEntry = AddExtension(SHAPENAME, ShapeNumberEvents, 0,
ProcShapeDispatch, SProcShapeDispatch,
ProcShapeDispatch, ProcShapeDispatch,
NULL, StandardMinorOpcode))) {
ShapeEventBase = extEntry->eventBase;
EventSwapVector[ShapeEventBase] = (EventSwapPtr) SShapeNotifyEvent;