xenocara/xserver/Xext/dpms.c

364 lines
8.5 KiB
C
Raw Normal View History

2006-11-26 11:13:41 -07:00
/*****************************************************************
Copyright (c) 1996 Digital Equipment Corporation, Maynard, Massachusetts.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software.
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
DIGITAL EQUIPMENT CORPORATION BE LIABLE FOR ANY CLAIM, DAMAGES, INCLUDING,
BUT NOT LIMITED TO CONSEQUENTIAL OR INCIDENTAL DAMAGES, OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
2006-11-26 11:13:41 -07:00
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Except as contained in this notice, the name of Digital Equipment Corporation
2006-11-26 11:13:41 -07:00
shall not be used in advertising or otherwise to promote the sale, use or other
dealings in this Software without prior written authorization from Digital
2006-11-26 11:13:41 -07:00
Equipment Corporation.
******************************************************************/
#ifdef HAVE_DIX_CONFIG_H
#include <dix-config.h>
#endif
#include <X11/X.h>
#include <X11/Xproto.h>
#include "misc.h"
#include "os.h"
#include "dixstruct.h"
#include "extnsionst.h"
#include "opaque.h"
#include <X11/extensions/dpmsproto.h>
2006-11-26 11:13:41 -07:00
#include "dpmsproc.h"
#include "extinit.h"
2006-11-26 11:13:41 -07:00
static int
ProcDPMSGetVersion(ClientPtr client)
2006-11-26 11:13:41 -07:00
{
/* REQUEST(xDPMSGetVersionReq); */
xDPMSGetVersionReply rep = {
.type = X_Reply,
.sequenceNumber = client->sequence,
.length = 0,
.majorVersion = DPMSMajorVersion,
.minorVersion = DPMSMinorVersion
};
2006-11-26 11:13:41 -07:00
REQUEST_SIZE_MATCH(xDPMSGetVersionReq);
if (client->swapped) {
swaps(&rep.sequenceNumber);
swaps(&rep.majorVersion);
swaps(&rep.minorVersion);
2006-11-26 11:13:41 -07:00
}
WriteToClient(client, sizeof(xDPMSGetVersionReply), &rep);
return Success;
2006-11-26 11:13:41 -07:00
}
static int
ProcDPMSCapable(ClientPtr client)
2006-11-26 11:13:41 -07:00
{
/* REQUEST(xDPMSCapableReq); */
xDPMSCapableReply rep = {
.type = X_Reply,
.sequenceNumber = client->sequence,
.length = 0,
.capable = DPMSCapableFlag
};
2006-11-26 11:13:41 -07:00
REQUEST_SIZE_MATCH(xDPMSCapableReq);
if (client->swapped) {
swaps(&rep.sequenceNumber);
2006-11-26 11:13:41 -07:00
}
WriteToClient(client, sizeof(xDPMSCapableReply), &rep);
return Success;
2006-11-26 11:13:41 -07:00
}
static int
ProcDPMSGetTimeouts(ClientPtr client)
2006-11-26 11:13:41 -07:00
{
/* REQUEST(xDPMSGetTimeoutsReq); */
xDPMSGetTimeoutsReply rep = {
.type = X_Reply,
.sequenceNumber = client->sequence,
.length = 0,
.standby = DPMSStandbyTime / MILLI_PER_SECOND,
.suspend = DPMSSuspendTime / MILLI_PER_SECOND,
.off = DPMSOffTime / MILLI_PER_SECOND
};
2006-11-26 11:13:41 -07:00
REQUEST_SIZE_MATCH(xDPMSGetTimeoutsReq);
if (client->swapped) {
swaps(&rep.sequenceNumber);
swaps(&rep.standby);
swaps(&rep.suspend);
swaps(&rep.off);
2006-11-26 11:13:41 -07:00
}
WriteToClient(client, sizeof(xDPMSGetTimeoutsReply), &rep);
return Success;
2006-11-26 11:13:41 -07:00
}
static int
ProcDPMSSetTimeouts(ClientPtr client)
2006-11-26 11:13:41 -07:00
{
REQUEST(xDPMSSetTimeoutsReq);
REQUEST_SIZE_MATCH(xDPMSSetTimeoutsReq);
if ((stuff->off != 0) && (stuff->off < stuff->suspend)) {
client->errorValue = stuff->off;
return BadValue;
}
if ((stuff->suspend != 0) && (stuff->suspend < stuff->standby)) {
client->errorValue = stuff->suspend;
return BadValue;
2006-11-26 11:13:41 -07:00
}
DPMSStandbyTime = stuff->standby * MILLI_PER_SECOND;
DPMSSuspendTime = stuff->suspend * MILLI_PER_SECOND;
DPMSOffTime = stuff->off * MILLI_PER_SECOND;
SetScreenSaverTimer();
return Success;
2006-11-26 11:13:41 -07:00
}
static int
ProcDPMSEnable(ClientPtr client)
2006-11-26 11:13:41 -07:00
{
Bool was_enabled = DPMSEnabled;
2006-11-26 11:13:41 -07:00
REQUEST_SIZE_MATCH(xDPMSEnableReq);
if (DPMSCapableFlag) {
DPMSEnabled = TRUE;
if (!was_enabled)
SetScreenSaverTimer();
}
2006-11-26 11:13:41 -07:00
return Success;
2006-11-26 11:13:41 -07:00
}
static int
ProcDPMSDisable(ClientPtr client)
2006-11-26 11:13:41 -07:00
{
/* REQUEST(xDPMSDisableReq); */
REQUEST_SIZE_MATCH(xDPMSDisableReq);
DPMSSet(client, DPMSModeOn);
2006-11-26 11:13:41 -07:00
DPMSEnabled = FALSE;
return Success;
2006-11-26 11:13:41 -07:00
}
static int
ProcDPMSForceLevel(ClientPtr client)
2006-11-26 11:13:41 -07:00
{
REQUEST(xDPMSForceLevelReq);
REQUEST_SIZE_MATCH(xDPMSForceLevelReq);
if (!DPMSEnabled)
return BadMatch;
2006-11-26 11:13:41 -07:00
2009-10-31 08:09:43 -06:00
if (stuff->level != DPMSModeOn &&
stuff->level != DPMSModeStandby &&
stuff->level != DPMSModeSuspend && stuff->level != DPMSModeOff) {
client->errorValue = stuff->level;
return BadValue;
2006-11-26 11:13:41 -07:00
}
DPMSSet(client, stuff->level);
2006-11-26 11:13:41 -07:00
return Success;
2006-11-26 11:13:41 -07:00
}
static int
ProcDPMSInfo(ClientPtr client)
2006-11-26 11:13:41 -07:00
{
/* REQUEST(xDPMSInfoReq); */
xDPMSInfoReply rep = {
.type = X_Reply,
.sequenceNumber = client->sequence,
.length = 0,
.power_level = DPMSPowerLevel,
.state = DPMSEnabled
};
2006-11-26 11:13:41 -07:00
REQUEST_SIZE_MATCH(xDPMSInfoReq);
if (client->swapped) {
swaps(&rep.sequenceNumber);
swaps(&rep.power_level);
2006-11-26 11:13:41 -07:00
}
WriteToClient(client, sizeof(xDPMSInfoReply), &rep);
return Success;
2006-11-26 11:13:41 -07:00
}
static int
ProcDPMSDispatch(ClientPtr client)
2006-11-26 11:13:41 -07:00
{
REQUEST(xReq);
switch (stuff->data) {
2006-11-26 11:13:41 -07:00
case X_DPMSGetVersion:
return ProcDPMSGetVersion(client);
2006-11-26 11:13:41 -07:00
case X_DPMSCapable:
return ProcDPMSCapable(client);
2006-11-26 11:13:41 -07:00
case X_DPMSGetTimeouts:
return ProcDPMSGetTimeouts(client);
2006-11-26 11:13:41 -07:00
case X_DPMSSetTimeouts:
return ProcDPMSSetTimeouts(client);
2006-11-26 11:13:41 -07:00
case X_DPMSEnable:
return ProcDPMSEnable(client);
2006-11-26 11:13:41 -07:00
case X_DPMSDisable:
return ProcDPMSDisable(client);
2006-11-26 11:13:41 -07:00
case X_DPMSForceLevel:
return ProcDPMSForceLevel(client);
2006-11-26 11:13:41 -07:00
case X_DPMSInfo:
return ProcDPMSInfo(client);
2006-11-26 11:13:41 -07:00
default:
return BadRequest;
2006-11-26 11:13:41 -07:00
}
}
static int
SProcDPMSGetVersion(ClientPtr client)
2006-11-26 11:13:41 -07:00
{
REQUEST(xDPMSGetVersionReq);
swaps(&stuff->length);
2006-11-26 11:13:41 -07:00
REQUEST_SIZE_MATCH(xDPMSGetVersionReq);
swaps(&stuff->majorVersion);
swaps(&stuff->minorVersion);
2006-11-26 11:13:41 -07:00
return ProcDPMSGetVersion(client);
}
static int
SProcDPMSCapable(ClientPtr client)
2006-11-26 11:13:41 -07:00
{
REQUEST(xDPMSCapableReq);
swaps(&stuff->length);
2006-11-26 11:13:41 -07:00
REQUEST_SIZE_MATCH(xDPMSCapableReq);
return ProcDPMSCapable(client);
}
static int
SProcDPMSGetTimeouts(ClientPtr client)
2006-11-26 11:13:41 -07:00
{
REQUEST(xDPMSGetTimeoutsReq);
swaps(&stuff->length);
2006-11-26 11:13:41 -07:00
REQUEST_SIZE_MATCH(xDPMSGetTimeoutsReq);
return ProcDPMSGetTimeouts(client);
}
static int
SProcDPMSSetTimeouts(ClientPtr client)
2006-11-26 11:13:41 -07:00
{
REQUEST(xDPMSSetTimeoutsReq);
swaps(&stuff->length);
2006-11-26 11:13:41 -07:00
REQUEST_SIZE_MATCH(xDPMSSetTimeoutsReq);
swaps(&stuff->standby);
swaps(&stuff->suspend);
swaps(&stuff->off);
2006-11-26 11:13:41 -07:00
return ProcDPMSSetTimeouts(client);
}
static int
SProcDPMSEnable(ClientPtr client)
2006-11-26 11:13:41 -07:00
{
REQUEST(xDPMSEnableReq);
swaps(&stuff->length);
2006-11-26 11:13:41 -07:00
REQUEST_SIZE_MATCH(xDPMSEnableReq);
return ProcDPMSEnable(client);
}
static int
SProcDPMSDisable(ClientPtr client)
2006-11-26 11:13:41 -07:00
{
REQUEST(xDPMSDisableReq);
swaps(&stuff->length);
2006-11-26 11:13:41 -07:00
REQUEST_SIZE_MATCH(xDPMSDisableReq);
return ProcDPMSDisable(client);
}
static int
SProcDPMSForceLevel(ClientPtr client)
2006-11-26 11:13:41 -07:00
{
REQUEST(xDPMSForceLevelReq);
swaps(&stuff->length);
2006-11-26 11:13:41 -07:00
REQUEST_SIZE_MATCH(xDPMSForceLevelReq);
swaps(&stuff->level);
2006-11-26 11:13:41 -07:00
return ProcDPMSForceLevel(client);
}
static int
SProcDPMSInfo(ClientPtr client)
2006-11-26 11:13:41 -07:00
{
REQUEST(xDPMSInfoReq);
swaps(&stuff->length);
2006-11-26 11:13:41 -07:00
REQUEST_SIZE_MATCH(xDPMSInfoReq);
return ProcDPMSInfo(client);
}
static int
SProcDPMSDispatch(ClientPtr client)
2006-11-26 11:13:41 -07:00
{
REQUEST(xReq);
switch (stuff->data) {
2006-11-26 11:13:41 -07:00
case X_DPMSGetVersion:
return SProcDPMSGetVersion(client);
2006-11-26 11:13:41 -07:00
case X_DPMSCapable:
return SProcDPMSCapable(client);
2006-11-26 11:13:41 -07:00
case X_DPMSGetTimeouts:
return SProcDPMSGetTimeouts(client);
2006-11-26 11:13:41 -07:00
case X_DPMSSetTimeouts:
return SProcDPMSSetTimeouts(client);
2006-11-26 11:13:41 -07:00
case X_DPMSEnable:
return SProcDPMSEnable(client);
2006-11-26 11:13:41 -07:00
case X_DPMSDisable:
return SProcDPMSDisable(client);
2006-11-26 11:13:41 -07:00
case X_DPMSForceLevel:
return SProcDPMSForceLevel(client);
2006-11-26 11:13:41 -07:00
case X_DPMSInfo:
return SProcDPMSInfo(client);
2006-11-26 11:13:41 -07:00
default:
return BadRequest;
2006-11-26 11:13:41 -07:00
}
}
void
DPMSExtensionInit(void)
{
AddExtension(DPMSExtensionName, 0, 0,
ProcDPMSDispatch, SProcDPMSDispatch,
NULL, StandardMinorOpcode);
}