xenocara/xserver/Xext/dpms.c

452 lines
11 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"
#include "scrnintstr.h"
#include "windowstr.h"
CARD16 DPMSPowerLevel = 0;
Bool DPMSDisabledSwitch = FALSE;
CARD32 DPMSStandbyTime = -1;
CARD32 DPMSSuspendTime = -1;
CARD32 DPMSOffTime = -1;
Bool DPMSEnabled;
Bool
DPMSSupported(void)
{
int i;
/* For each screen, check if DPMS is supported */
for (i = 0; i < screenInfo.numScreens; i++)
if (screenInfo.screens[i]->DPMS != NULL)
return TRUE;
for (i = 0; i < screenInfo.numGPUScreens; i++)
if (screenInfo.gpuscreens[i]->DPMS != NULL)
return TRUE;
return FALSE;
}
static Bool
isUnblank(int mode)
{
switch (mode) {
case SCREEN_SAVER_OFF:
case SCREEN_SAVER_FORCER:
return TRUE;
case SCREEN_SAVER_ON:
case SCREEN_SAVER_CYCLE:
return FALSE;
default:
return TRUE;
}
}
int
DPMSSet(ClientPtr client, int level)
{
int rc, i;
DPMSPowerLevel = level;
if (level != DPMSModeOn) {
if (isUnblank(screenIsSaved)) {
rc = dixSaveScreens(client, SCREEN_SAVER_FORCER, ScreenSaverActive);
if (rc != Success)
return rc;
}
} else if (!isUnblank(screenIsSaved)) {
rc = dixSaveScreens(client, SCREEN_SAVER_OFF, ScreenSaverReset);
if (rc != Success)
return rc;
}
for (i = 0; i < screenInfo.numScreens; i++)
if (screenInfo.screens[i]->DPMS != NULL)
screenInfo.screens[i]->DPMS(screenInfo.screens[i], level);
for (i = 0; i < screenInfo.numGPUScreens; i++)
if (screenInfo.gpuscreens[i]->DPMS != NULL)
screenInfo.gpuscreens[i]->DPMS(screenInfo.gpuscreens[i], level);
return Success;
}
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 = TRUE
};
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);
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 _X_COLD
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 _X_COLD
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 _X_COLD
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 _X_COLD
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 _X_COLD
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 _X_COLD
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 _X_COLD
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 _X_COLD
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 _X_COLD
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
}
}
static void
DPMSCloseDownExtension(ExtensionEntry *e)
{
DPMSSet(serverClient, DPMSModeOn);
}
void
DPMSExtensionInit(void)
{
#define CONDITIONALLY_SET_DPMS_TIMEOUT(_timeout_value_) \
if (_timeout_value_ == -1) { /* not yet set from config */ \
_timeout_value_ = ScreenSaverTime; \
}
CONDITIONALLY_SET_DPMS_TIMEOUT(DPMSStandbyTime)
CONDITIONALLY_SET_DPMS_TIMEOUT(DPMSSuspendTime)
CONDITIONALLY_SET_DPMS_TIMEOUT(DPMSOffTime)
DPMSPowerLevel = DPMSModeOn;
DPMSEnabled = DPMSSupported();
if (DPMSEnabled)
AddExtension(DPMSExtensionName, 0, 0,
ProcDPMSDispatch, SProcDPMSDispatch,
DPMSCloseDownExtension, StandardMinorOpcode);
}