Xext: dpms: 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-02 13:09:49 +02:00
parent 893f56f6b0
commit 9614b41afb

View File

@ -30,7 +30,9 @@ Equipment Corporation.
#include <X11/X.h>
#include <X11/Xproto.h>
#include <X11/extensions/dpmsproto.h>
#include "dix/request_priv.h"
#include "os/screensaver.h"
#include "Xext/geext_priv.h"
@ -39,7 +41,6 @@ Equipment Corporation.
#include "dixstruct.h"
#include "extnsionst.h"
#include "opaque.h"
#include <X11/extensions/dpmsproto.h>
#include "dpmsproc.h"
#include "extinit_priv.h"
#include "scrnintstr.h"
@ -124,12 +125,13 @@ SDPMSInfoNotifyEvent(xGenericEvent * from,
static int
ProcDPMSSelectInput(register ClientPtr client)
{
REQUEST(xDPMSSelectInputReq);
REQUEST_HEAD_STRUCT(xDPMSSelectInputReq);
REQUEST_FIELD_CARD32(eventMask);
DPMSEventPtr pEvent, pNewEvent, *pHead;
XID clientResource;
int i;
REQUEST_SIZE_MATCH(xDPMSSelectInputReq);
i = dixLookupResourceByType((void **)&pHead, eventResource, DPMSEventType,
client,
DixWriteAccess);
@ -295,7 +297,10 @@ DPMSSet(ClientPtr client, int level)
static int
ProcDPMSGetVersion(ClientPtr client)
{
/* REQUEST(xDPMSGetVersionReq); */
REQUEST_HEAD_STRUCT(xDPMSGetVersionReq);
REQUEST_FIELD_CARD16(majorVersion);
REQUEST_FIELD_CARD16(minorVersion);
xDPMSGetVersionReply rep = {
.type = X_Reply,
.sequenceNumber = client->sequence,
@ -304,8 +309,6 @@ ProcDPMSGetVersion(ClientPtr client)
.minorVersion = SERVER_DPMS_MINOR_VERSION
};
REQUEST_SIZE_MATCH(xDPMSGetVersionReq);
if (client->swapped) {
swaps(&rep.sequenceNumber);
swaps(&rep.majorVersion);
@ -318,7 +321,8 @@ ProcDPMSGetVersion(ClientPtr client)
static int
ProcDPMSCapable(ClientPtr client)
{
/* REQUEST(xDPMSCapableReq); */
REQUEST_HEAD_STRUCT(xDPMSCapableReq);
xDPMSCapableReply rep = {
.type = X_Reply,
.sequenceNumber = client->sequence,
@ -326,8 +330,6 @@ ProcDPMSCapable(ClientPtr client)
.capable = TRUE
};
REQUEST_SIZE_MATCH(xDPMSCapableReq);
if (client->swapped) {
swaps(&rep.sequenceNumber);
}
@ -338,7 +340,8 @@ ProcDPMSCapable(ClientPtr client)
static int
ProcDPMSGetTimeouts(ClientPtr client)
{
/* REQUEST(xDPMSGetTimeoutsReq); */
REQUEST_HEAD_STRUCT(xDPMSGetTimeoutsReq);
xDPMSGetTimeoutsReply rep = {
.type = X_Reply,
.sequenceNumber = client->sequence,
@ -348,8 +351,6 @@ ProcDPMSGetTimeouts(ClientPtr client)
.off = DPMSOffTime / MILLI_PER_SECOND
};
REQUEST_SIZE_MATCH(xDPMSGetTimeoutsReq);
if (client->swapped) {
swaps(&rep.sequenceNumber);
swaps(&rep.standby);
@ -363,9 +364,10 @@ ProcDPMSGetTimeouts(ClientPtr client)
static int
ProcDPMSSetTimeouts(ClientPtr client)
{
REQUEST(xDPMSSetTimeoutsReq);
REQUEST_SIZE_MATCH(xDPMSSetTimeoutsReq);
REQUEST_HEAD_STRUCT(xDPMSSetTimeoutsReq);
REQUEST_FIELD_CARD16(standby);
REQUEST_FIELD_CARD16(suspend);
REQUEST_FIELD_CARD16(off);
if ((stuff->off != 0) && (stuff->off < stuff->suspend)) {
client->errorValue = stuff->off;
@ -387,9 +389,9 @@ ProcDPMSSetTimeouts(ClientPtr client)
static int
ProcDPMSEnable(ClientPtr client)
{
Bool was_enabled = DPMSEnabled;
REQUEST_HEAD_STRUCT(xDPMSEnableReq);
REQUEST_SIZE_MATCH(xDPMSEnableReq);
Bool was_enabled = DPMSEnabled;
DPMSEnabled = TRUE;
if (!was_enabled) {
@ -403,12 +405,10 @@ ProcDPMSEnable(ClientPtr client)
static int
ProcDPMSDisable(ClientPtr client)
{
REQUEST_HEAD_STRUCT(xDPMSDisableReq);
Bool was_enabled = DPMSEnabled;
/* REQUEST(xDPMSDisableReq); */
REQUEST_SIZE_MATCH(xDPMSDisableReq);
DPMSSet(client, DPMSModeOn);
DPMSEnabled = FALSE;
@ -421,9 +421,8 @@ ProcDPMSDisable(ClientPtr client)
static int
ProcDPMSForceLevel(ClientPtr client)
{
REQUEST(xDPMSForceLevelReq);
REQUEST_SIZE_MATCH(xDPMSForceLevelReq);
REQUEST_HEAD_STRUCT(xDPMSForceLevelReq);
REQUEST_FIELD_CARD16(level);
if (!DPMSEnabled)
return BadMatch;
@ -443,7 +442,8 @@ ProcDPMSForceLevel(ClientPtr client)
static int
ProcDPMSInfo(ClientPtr client)
{
/* REQUEST(xDPMSInfoReq); */
REQUEST_HEAD_STRUCT(xDPMSInfoReq);
xDPMSInfoReply rep = {
.type = X_Reply,
.sequenceNumber = client->sequence,
@ -452,8 +452,6 @@ ProcDPMSInfo(ClientPtr client)
.state = DPMSEnabled
};
REQUEST_SIZE_MATCH(xDPMSInfoReq);
if (client->swapped) {
swaps(&rep.sequenceNumber);
swaps(&rep.power_level);
@ -491,78 +489,6 @@ ProcDPMSDispatch(ClientPtr client)
}
}
static int _X_COLD
SProcDPMSGetVersion(ClientPtr client)
{
REQUEST(xDPMSGetVersionReq);
REQUEST_SIZE_MATCH(xDPMSGetVersionReq);
swaps(&stuff->majorVersion);
swaps(&stuff->minorVersion);
return ProcDPMSGetVersion(client);
}
static int _X_COLD
SProcDPMSSetTimeouts(ClientPtr client)
{
REQUEST(xDPMSSetTimeoutsReq);
REQUEST_SIZE_MATCH(xDPMSSetTimeoutsReq);
swaps(&stuff->standby);
swaps(&stuff->suspend);
swaps(&stuff->off);
return ProcDPMSSetTimeouts(client);
}
static int _X_COLD
SProcDPMSForceLevel(ClientPtr client)
{
REQUEST(xDPMSForceLevelReq);
REQUEST_SIZE_MATCH(xDPMSForceLevelReq);
swaps(&stuff->level);
return ProcDPMSForceLevel(client);
}
static int _X_COLD
SProcDPMSSelectInput(ClientPtr client)
{
REQUEST(xDPMSSelectInputReq);
REQUEST_SIZE_MATCH(xDPMSSelectInputReq);
swapl(&stuff->eventMask);
return ProcDPMSSelectInput(client);
}
static int _X_COLD
SProcDPMSDispatch(ClientPtr client)
{
REQUEST(xReq);
switch (stuff->data) {
case X_DPMSGetVersion:
return SProcDPMSGetVersion(client);
case X_DPMSCapable:
return ProcDPMSCapable(client);
case X_DPMSGetTimeouts:
return ProcDPMSGetTimeouts(client);
case X_DPMSSetTimeouts:
return SProcDPMSSetTimeouts(client);
case X_DPMSEnable:
return ProcDPMSEnable(client);
case X_DPMSDisable:
return ProcDPMSDisable(client);
case X_DPMSForceLevel:
return SProcDPMSForceLevel(client);
case X_DPMSInfo:
return ProcDPMSInfo(client);
case X_DPMSSelectInput:
return SProcDPMSSelectInput(client);
default:
return BadRequest;
}
}
static void
DPMSCloseDownExtension(ExtensionEntry *e)
{
@ -592,7 +518,7 @@ DPMSExtensionInit(void)
if (DPMSEnabled && ClientType && DPMSEventType &&
(extEntry = AddExtension(DPMSExtensionName, 0, 0,
ProcDPMSDispatch, SProcDPMSDispatch,
ProcDPMSDispatch, ProcDPMSDispatch,
DPMSCloseDownExtension, StandardMinorOpcode))) {
DPMSReqCode = extEntry->base;
GERegisterExtension(DPMSReqCode, SDPMSInfoNotifyEvent);