summaryrefslogtreecommitdiff
path: root/xserver/hw/xfree86/common/xf86DPMS.c
diff options
context:
space:
mode:
authorMatthieu Herrb <matthieu@cvs.openbsd.org>2008-11-02 15:26:35 +0000
committerMatthieu Herrb <matthieu@cvs.openbsd.org>2008-11-02 15:26:35 +0000
commitdbca69c8a4f3e2d1ccb4f89152213b2861b33af6 (patch)
treef8963ef73903a7b4374adc2354dffbaa905112ac /xserver/hw/xfree86/common/xf86DPMS.c
parent33b2029f322f3c238b7ba528083195ad8dde33e1 (diff)
xserver 1.5.2. tested by ckuethe@, oga@, and others.
Diffstat (limited to 'xserver/hw/xfree86/common/xf86DPMS.c')
-rw-r--r--xserver/hw/xfree86/common/xf86DPMS.c53
1 files changed, 29 insertions, 24 deletions
diff --git a/xserver/hw/xfree86/common/xf86DPMS.c b/xserver/hw/xfree86/common/xf86DPMS.c
index 3aa83e882..4fb901aae 100644
--- a/xserver/hw/xfree86/common/xf86DPMS.c
+++ b/xserver/hw/xfree86/common/xf86DPMS.c
@@ -47,8 +47,7 @@
#ifdef DPMSExtension
-static int DPMSGeneration = 0;
-static int DPMSIndex = -1;
+static DevPrivateKey DPMSKey = NULL;
static Bool DPMSClose(int i, ScreenPtr pScreen);
static int DPMSCount = 0;
#endif
@@ -61,19 +60,17 @@ xf86DPMSInit(ScreenPtr pScreen, DPMSSetProcPtr set, int flags)
ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
DPMSPtr pDPMS;
pointer DPMSOpt;
+ MessageType enabled_from = X_INFO;
- if (serverGeneration != DPMSGeneration) {
- if ((DPMSIndex = AllocateScreenPrivateIndex()) < 0)
- return FALSE;
- DPMSGeneration = serverGeneration;
- }
+ DPMSKey = &DPMSKey;
if (DPMSDisabledSwitch)
DPMSEnabled = FALSE;
- if (!(pScreen->devPrivates[DPMSIndex].ptr = xcalloc(sizeof(DPMSRec), 1)))
+ if (!dixSetPrivate(&pScreen->devPrivates, DPMSKey,
+ xcalloc(sizeof(DPMSRec), 1)))
return FALSE;
- pDPMS = (DPMSPtr)pScreen->devPrivates[DPMSIndex].ptr;
+ pDPMS = (DPMSPtr)dixLookupPrivate(&pScreen->devPrivates, DPMSKey);
pScrn->DPMSSet = set;
pDPMS->Flags = flags;
DPMSOpt = xf86FindOption(pScrn->options, "dpms");
@@ -82,8 +79,8 @@ xf86DPMSInit(ScreenPtr pScreen, DPMSSetProcPtr set, int flags)
= xf86SetBoolOption(pScrn->options, "dpms", FALSE))
&& !DPMSDisabledSwitch)
DPMSEnabled = TRUE;
+ enabled_from = X_CONFIG;
xf86MarkOptionUsed(DPMSOpt);
- xf86DrvMsg(pScreen->myNum, X_CONFIG, "DPMS enabled\n");
} else if (DPMSEnabledSwitch) {
if (!DPMSDisabledSwitch)
DPMSEnabled = TRUE;
@@ -92,6 +89,8 @@ xf86DPMSInit(ScreenPtr pScreen, DPMSSetProcPtr set, int flags)
else {
pDPMS->Enabled = defaultDPMSEnabled;
}
+ if (pDPMS->Enabled)
+ xf86DrvMsg(pScreen->myNum, enabled_from, "DPMS enabled\n");
pDPMS->CloseScreen = pScreen->CloseScreen;
pScreen->CloseScreen = DPMSClose;
DPMSCount++;
@@ -110,10 +109,10 @@ DPMSClose(int i, ScreenPtr pScreen)
DPMSPtr pDPMS;
/* This shouldn't happen */
- if (DPMSIndex < 0)
+ if (DPMSKey == NULL)
return FALSE;
- pDPMS = (DPMSPtr)pScreen->devPrivates[DPMSIndex].ptr;
+ pDPMS = (DPMSPtr)dixLookupPrivate(&pScreen->devPrivates, DPMSKey);
/* This shouldn't happen */
if (!pDPMS)
@@ -132,9 +131,9 @@ DPMSClose(int i, ScreenPtr pScreen)
}
xfree((pointer)pDPMS);
- pScreen->devPrivates[DPMSIndex].ptr = NULL;
+ dixSetPrivate(&pScreen->devPrivates, DPMSKey, NULL);
if (--DPMSCount == 0)
- DPMSIndex = -1;
+ DPMSKey = NULL;
return pScreen->CloseScreen(i, pScreen);
}
@@ -144,30 +143,35 @@ DPMSClose(int i, ScreenPtr pScreen)
* Device dependent DPMS mode setting hook. This is called whenever
* the DPMS mode is to be changed.
*/
-_X_EXPORT void
-DPMSSet(int level)
+_X_EXPORT int
+DPMSSet(ClientPtr client, int level)
{
- int i;
+ int rc, i;
DPMSPtr pDPMS;
ScrnInfoPtr pScrn;
DPMSPowerLevel = level;
- if (DPMSIndex < 0)
- return;
+ if (DPMSKey == NULL)
+ return Success;
- if (level != DPMSModeOn)
- SaveScreens(SCREEN_SAVER_FORCER, ScreenSaverActive);
+ if (level != DPMSModeOn) {
+ rc = dixSaveScreens(client, SCREEN_SAVER_FORCER, ScreenSaverActive);
+ if (rc != Success)
+ return rc;
+ }
/* For each screen, set the DPMS level */
for (i = 0; i < xf86NumScreens; i++) {
pScrn = xf86Screens[i];
- pDPMS = (DPMSPtr)screenInfo.screens[i]->devPrivates[DPMSIndex].ptr;
+ pDPMS = (DPMSPtr)dixLookupPrivate(&screenInfo.screens[i]->devPrivates,
+ DPMSKey);
if (pDPMS && pScrn->DPMSSet && pDPMS->Enabled && pScrn->vtSema) {
xf86EnableAccess(pScrn);
pScrn->DPMSSet(pScrn, level, 0);
}
}
+ return Success;
}
@@ -182,14 +186,15 @@ DPMSSupported(void)
DPMSPtr pDPMS;
ScrnInfoPtr pScrn;
- if (DPMSIndex < 0) {
+ if (DPMSKey == NULL) {
return FALSE;
}
/* For each screen, check if DPMS is supported */
for (i = 0; i < xf86NumScreens; i++) {
pScrn = xf86Screens[i];
- pDPMS = (DPMSPtr)screenInfo.screens[i]->devPrivates[DPMSIndex].ptr;
+ pDPMS = (DPMSPtr)dixLookupPrivate(&screenInfo.screens[i]->devPrivates,
+ DPMSKey);
if (pDPMS && pScrn->DPMSSet)
return TRUE;
}