1
/* $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86DPMS.c,v 1.11 2003/11/11 21:02:28 dawes Exp $ */
2
/* $XdotOrg: xserver/xorg/hw/xfree86/common/xf86DPMS.c,v 1.8 2005/07/03 08:53:42 daniels Exp $ */
5
* Copyright (c) 1997-2003 by The XFree86 Project, Inc.
7
* Permission is hereby granted, free of charge, to any person obtaining a
8
* copy of this software and associated documentation files (the "Software"),
9
* to deal in the Software without restriction, including without limitation
10
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
11
* and/or sell copies of the Software, and to permit persons to whom the
12
* Software is furnished to do so, subject to the following conditions:
14
* The above copyright notice and this permission notice shall be included in
15
* all copies or substantial portions of the Software.
17
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20
* THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
21
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23
* OTHER DEALINGS IN THE SOFTWARE.
25
* Except as contained in this notice, the name of the copyright holder(s)
26
* and author(s) shall not be used in advertising or otherwise to promote
27
* the sale, use or other dealings in this Software without prior written
28
* authorization from the copyright holder(s) and author(s).
32
* This file contains the DPMS functions required by the extension.
35
#ifdef HAVE_XORG_CONFIG_H
36
#include <xorg-config.h>
46
#include <X11/extensions/dpms.h>
52
static int DPMSGeneration = 0;
53
static int DPMSIndex = -1;
54
static Bool DPMSClose(int i, ScreenPtr pScreen);
55
static int DPMSCount = 0;
60
xf86DPMSInit(ScreenPtr pScreen, DPMSSetProcPtr set, int flags)
63
ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
67
if (serverGeneration != DPMSGeneration) {
68
if ((DPMSIndex = AllocateScreenPrivateIndex()) < 0)
70
DPMSGeneration = serverGeneration;
73
if (DPMSDisabledSwitch)
75
if (!(pScreen->devPrivates[DPMSIndex].ptr = xcalloc(sizeof(DPMSRec), 1)))
78
pDPMS = (DPMSPtr)pScreen->devPrivates[DPMSIndex].ptr;
81
DPMSOpt = xf86FindOption(pScrn->options, "dpms");
84
= xf86SetBoolOption(pScrn->options, "dpms", FALSE))
85
&& !DPMSDisabledSwitch)
87
xf86MarkOptionUsed(DPMSOpt);
88
xf86DrvMsg(pScreen->myNum, X_CONFIG, "DPMS enabled\n");
89
} else if (DPMSEnabledSwitch) {
90
if (!DPMSDisabledSwitch)
92
pDPMS->Enabled = TRUE;
95
pDPMS->Enabled = defaultDPMSEnabled;
97
pDPMS->CloseScreen = pScreen->CloseScreen;
98
pScreen->CloseScreen = DPMSClose;
110
DPMSClose(int i, ScreenPtr pScreen)
114
/* This shouldn't happen */
118
pDPMS = (DPMSPtr)pScreen->devPrivates[DPMSIndex].ptr;
120
/* This shouldn't happen */
124
pScreen->CloseScreen = pDPMS->CloseScreen;
127
* Turn on DPMS when shutting down. If this function can be used
128
* depends on the order the driver wraps things. If this is called
129
* after the driver has shut down everything the driver will have
130
* to deal with this internally.
132
if (xf86Screens[i]->vtSema && xf86Screens[i]->DPMSSet) {
133
xf86Screens[i]->DPMSSet(xf86Screens[i],DPMSModeOn,0);
136
xfree((pointer)pDPMS);
137
pScreen->devPrivates[DPMSIndex].ptr = NULL;
138
if (--DPMSCount == 0)
140
return pScreen->CloseScreen(i, pScreen);
146
* Device dependent DPMS mode setting hook. This is called whenever
147
* the DPMS mode is to be changed.
156
DPMSPowerLevel = level;
161
if (level != DPMSModeOn)
162
SaveScreens(SCREEN_SAVER_FORCER, ScreenSaverActive);
164
/* For each screen, set the DPMS level */
165
for (i = 0; i < xf86NumScreens; i++) {
166
pScrn = xf86Screens[i];
167
pDPMS = (DPMSPtr)screenInfo.screens[i]->devPrivates[DPMSIndex].ptr;
168
if (pDPMS && pScrn->DPMSSet && pDPMS->Enabled && pScrn->vtSema) {
169
xf86EnableAccess(pScrn);
170
pScrn->DPMSSet(pScrn, level, 0);
178
* Return TRUE if any screen supports DPMS.
191
/* For each screen, check if DPMS is supported */
192
for (i = 0; i < xf86NumScreens; i++) {
193
pScrn = xf86Screens[i];
194
pDPMS = (DPMSPtr)screenInfo.screens[i]->devPrivates[DPMSIndex].ptr;
195
if (pDPMS && pScrn->DPMSSet)
204
* Device dependent DPMS mode getting hook. This returns the current
205
* DPMS mode, or -1 if DPMS is not supported.
207
* This should hook in to the appropriate driver-level function, which
208
* will be added to the ScrnInfoRec.
211
* 1. the calling interface should be changed to specify which
213
* 2. It isn't clear that this function is ever used or what it should
219
return DPMSPowerLevel;
222
#endif /* DPMSExtension */