3 * Copyright (c) 1997-2003 by The XFree86 Project, Inc.
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
19 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
20 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
21 * OTHER DEALINGS IN THE SOFTWARE.
23 * Except as contained in this notice, the name of the copyright holder(s)
24 * and author(s) shall not be used in advertising or otherwise to promote
25 * the sale, use or other dealings in this Software without prior written
26 * authorization from the copyright holder(s) and author(s).
30 * This file contains the DPMS functions required by the extension.
33 #ifdef HAVE_XORG_CONFIG_H
34 #include <xorg-config.h>
44 #include <X11/extensions/dpms.h>
50 static int DPMSGeneration
= 0;
51 static int DPMSIndex
= -1;
52 static Bool
DPMSClose(int i
, ScreenPtr pScreen
);
53 static int DPMSCount
= 0;
58 xf86DPMSInit(ScreenPtr pScreen
, DPMSSetProcPtr set
, int flags
)
61 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
65 if (serverGeneration
!= DPMSGeneration
) {
66 if ((DPMSIndex
= AllocateScreenPrivateIndex()) < 0)
68 DPMSGeneration
= serverGeneration
;
71 if (DPMSDisabledSwitch
)
73 if (!(pScreen
->devPrivates
[DPMSIndex
].ptr
= xcalloc(sizeof(DPMSRec
), 1)))
76 pDPMS
= (DPMSPtr
)pScreen
->devPrivates
[DPMSIndex
].ptr
;
79 DPMSOpt
= xf86FindOption(pScrn
->options
, "dpms");
82 = xf86SetBoolOption(pScrn
->options
, "dpms", FALSE
))
83 && !DPMSDisabledSwitch
)
85 xf86MarkOptionUsed(DPMSOpt
);
86 xf86DrvMsg(pScreen
->myNum
, X_CONFIG
, "DPMS enabled\n");
87 } else if (DPMSEnabledSwitch
) {
88 if (!DPMSDisabledSwitch
)
90 pDPMS
->Enabled
= TRUE
;
93 pDPMS
->Enabled
= defaultDPMSEnabled
;
95 pDPMS
->CloseScreen
= pScreen
->CloseScreen
;
96 pScreen
->CloseScreen
= DPMSClose
;
108 DPMSClose(int i
, ScreenPtr pScreen
)
112 /* This shouldn't happen */
116 pDPMS
= (DPMSPtr
)pScreen
->devPrivates
[DPMSIndex
].ptr
;
118 /* This shouldn't happen */
122 pScreen
->CloseScreen
= pDPMS
->CloseScreen
;
125 * Turn on DPMS when shutting down. If this function can be used
126 * depends on the order the driver wraps things. If this is called
127 * after the driver has shut down everything the driver will have
128 * to deal with this internally.
130 if (xf86Screens
[i
]->vtSema
&& xf86Screens
[i
]->DPMSSet
) {
131 xf86Screens
[i
]->DPMSSet(xf86Screens
[i
],DPMSModeOn
,0);
134 xfree((pointer
)pDPMS
);
135 pScreen
->devPrivates
[DPMSIndex
].ptr
= NULL
;
136 if (--DPMSCount
== 0)
138 return pScreen
->CloseScreen(i
, pScreen
);
144 * Device dependent DPMS mode setting hook. This is called whenever
145 * the DPMS mode is to be changed.
154 DPMSPowerLevel
= level
;
159 if (level
!= DPMSModeOn
)
160 SaveScreens(SCREEN_SAVER_FORCER
, ScreenSaverActive
);
162 /* For each screen, set the DPMS level */
163 for (i
= 0; i
< xf86NumScreens
; i
++) {
164 pScrn
= xf86Screens
[i
];
165 pDPMS
= (DPMSPtr
)screenInfo
.screens
[i
]->devPrivates
[DPMSIndex
].ptr
;
166 if (pDPMS
&& pScrn
->DPMSSet
&& pDPMS
->Enabled
&& pScrn
->vtSema
) {
167 xf86EnableAccess(pScrn
);
168 pScrn
->DPMSSet(pScrn
, level
, 0);
176 * Return TRUE if any screen supports DPMS.
189 /* For each screen, check if DPMS is supported */
190 for (i
= 0; i
< xf86NumScreens
; i
++) {
191 pScrn
= xf86Screens
[i
];
192 pDPMS
= (DPMSPtr
)screenInfo
.screens
[i
]->devPrivates
[DPMSIndex
].ptr
;
193 if (pDPMS
&& pScrn
->DPMSSet
)
202 * Device dependent DPMS mode getting hook. This returns the current
203 * DPMS mode, or -1 if DPMS is not supported.
205 * This should hook in to the appropriate driver-level function, which
206 * will be added to the ScrnInfoRec.
209 * 1. the calling interface should be changed to specify which
211 * 2. It isn't clear that this function is ever used or what it should
217 return DPMSPowerLevel
;
220 #endif /* DPMSExtension */