aboutsummaryrefslogtreecommitdiff
path: root/nx-X11/programs/Xserver
diff options
context:
space:
mode:
authorMihai Moldovan <ionic@ionic.de>2018-02-07 23:19:33 +0100
committerMihai Moldovan <ionic@ionic.de>2018-02-07 23:19:33 +0100
commitaecdb52661898d0ba400a61550fa6ce9c0a4d829 (patch)
treef3c82763aa3f6c19da425e75c5c37dae228f38b4 /nx-X11/programs/Xserver
parentcbdae3b71bfc654cfc0c81b1ddf51975bcb93146 (diff)
parent5ec2366c40a540245be4a643fcf740fb16bcec50 (diff)
downloadnx-libs-aecdb52661898d0ba400a61550fa6ce9c0a4d829.tar.gz
nx-libs-aecdb52661898d0ba400a61550fa6ce9c0a4d829.tar.bz2
nx-libs-aecdb52661898d0ba400a61550fa6ce9c0a4d829.zip
Merge branch 'uli42-pr/update_xext' into 3.6.x
Attributes GH PR #643: https://github.com/ArcticaProject/nx-libs/pull/643
Diffstat (limited to 'nx-X11/programs/Xserver')
-rw-r--r--nx-X11/programs/Xserver/Xext/dpms.c6
-rw-r--r--nx-X11/programs/Xserver/Xext/panoramiX.c31
-rw-r--r--nx-X11/programs/Xserver/Xext/saver.c149
-rw-r--r--nx-X11/programs/Xserver/Xext/sleepuntil.c2
-rw-r--r--nx-X11/programs/Xserver/Xext/sync.c12
-rw-r--r--nx-X11/programs/Xserver/Xext/xres.c4
-rw-r--r--nx-X11/programs/Xserver/Xext/xvmain.c6
-rw-r--r--nx-X11/programs/Xserver/dix/Imakefile2
-rw-r--r--nx-X11/programs/Xserver/dix/globals.c4
-rw-r--r--nx-X11/programs/Xserver/dix/main.c6
-rw-r--r--nx-X11/programs/Xserver/include/globals.h4
-rw-r--r--nx-X11/programs/Xserver/os/WaitFor.c193
12 files changed, 298 insertions, 121 deletions
diff --git a/nx-X11/programs/Xserver/Xext/dpms.c b/nx-X11/programs/Xserver/Xext/dpms.c
index e05a70621..74969bb52 100644
--- a/nx-X11/programs/Xserver/Xext/dpms.c
+++ b/nx-X11/programs/Xserver/Xext/dpms.c
@@ -183,12 +183,12 @@ ProcDPMSSetTimeouts(client)
client->errorValue = stuff->suspend;
return BadValue;
}
-
+
DPMSStandbyTime = stuff->standby * MILLI_PER_SECOND;
DPMSSuspendTime = stuff->suspend * MILLI_PER_SECOND;
DPMSOffTime = stuff->off * MILLI_PER_SECOND;
- SetDPMSTimers();
-
+ SetScreenSaverTimer();
+
return(client->noClientException);
}
diff --git a/nx-X11/programs/Xserver/Xext/panoramiX.c b/nx-X11/programs/Xserver/Xext/panoramiX.c
index e720965d4..e36d04d9e 100644
--- a/nx-X11/programs/Xserver/Xext/panoramiX.c
+++ b/nx-X11/programs/Xserver/Xext/panoramiX.c
@@ -72,10 +72,10 @@ static unsigned char PanoramiXReqCode = 0;
int PanoramiXPixWidth = 0;
int PanoramiXPixHeight = 0;
-int PanoramiXNumScreens = 0;
+_X_EXPORT int PanoramiXNumScreens = 0;
-PanoramiXData *panoramiXdataPtr = NULL;
-RegionRec PanoramiXScreenRegion = {{0, 0, 0, 0}, NULL};
+_X_EXPORT PanoramiXData *panoramiXdataPtr = NULL;
+RegionRec PanoramiXScreenRegion = {{0, 0, 0, 0}, NULL};
static int PanoramiXNumDepths;
static DepthPtr PanoramiXDepths;
@@ -83,13 +83,13 @@ static int PanoramiXNumVisuals;
static VisualPtr PanoramiXVisuals;
/* We support at most 256 visuals */
-XID *PanoramiXVisualTable = NULL;
+_X_EXPORT XID *PanoramiXVisualTable = NULL;
-unsigned long XRC_DRAWABLE;
-unsigned long XRT_WINDOW;
-unsigned long XRT_PIXMAP;
-unsigned long XRT_GC;
-unsigned long XRT_COLORMAP;
+_X_EXPORT unsigned long XRC_DRAWABLE;
+_X_EXPORT unsigned long XRT_WINDOW;
+_X_EXPORT unsigned long XRT_PIXMAP;
+_X_EXPORT unsigned long XRT_GC;
+_X_EXPORT unsigned long XRT_COLORMAP;
/*
* Function prototypes
@@ -330,7 +330,7 @@ XineramaDestroyClip(GCPtr pGC)
-int
+_X_EXPORT int
XineramaDeleteResource(void * data, XID id)
{
free(data);
@@ -411,7 +411,7 @@ typedef struct _connect_callback_list {
static XineramaConnectionCallbackList *ConnectionCallbackList = NULL;
-Bool
+_X_EXPORT Bool
XineramaRegisterConnectionBlockCallback(void (*func)(void))
{
XineramaConnectionCallbackList *newlist;
@@ -1037,7 +1037,16 @@ ProcXineramaIsActive(ClientPtr client)
rep.type = X_Reply;
rep.length = 0;
rep.sequenceNumber = client->sequence;
+#if 1
+ {
+ /* The following hack fools clients into thinking that Xinerama
+ * is disabled even though it is not. */
+ extern Bool PanoramiXExtensionDisabledHack;
+ rep.state = !noPanoramiXExtension && !PanoramiXExtensionDisabledHack;
+ }
+#else
rep.state = !noPanoramiXExtension;
+#endif
if (client->swapped) {
swaps (&rep.sequenceNumber);
swapl (&rep.length);
diff --git a/nx-X11/programs/Xserver/Xext/saver.c b/nx-X11/programs/Xserver/Xext/saver.c
index 066dffed0..0b79a002b 100644
--- a/nx-X11/programs/Xserver/Xext/saver.c
+++ b/nx-X11/programs/Xserver/Xext/saver.c
@@ -51,7 +51,10 @@ in this Software without prior written authorization from the X Consortium.
#include "panoramiX.h"
#include "panoramiXsrv.h"
#endif
-
+#ifdef DPMSExtension
+#define DPMS_SERVER
+#include <nx-X11/extensions/dpms.h>
+#endif
#include <stdio.h>
@@ -68,12 +71,14 @@ static DISPATCH_PROC(ProcScreenSaverQueryVersion);
static DISPATCH_PROC(ProcScreenSaverSelectInput);
static DISPATCH_PROC(ProcScreenSaverSetAttributes);
static DISPATCH_PROC(ProcScreenSaverUnsetAttributes);
+static DISPATCH_PROC(ProcScreenSaverSuspend);
static DISPATCH_PROC(SProcScreenSaverDispatch);
static DISPATCH_PROC(SProcScreenSaverQueryInfo);
static DISPATCH_PROC(SProcScreenSaverQueryVersion);
static DISPATCH_PROC(SProcScreenSaverSelectInput);
static DISPATCH_PROC(SProcScreenSaverSetAttributes);
static DISPATCH_PROC(SProcScreenSaverUnsetAttributes);
+static DISPATCH_PROC(SProcScreenSaverSuspend);
static Bool ScreenSaverHandle (
ScreenPtr /* pScreen */,
@@ -110,6 +115,32 @@ static void ScreenSaverResetProc (
ExtensionEntry * /* extEntry */
);
+static RESTYPE SuspendType; /* resource type for suspension records */
+
+typedef struct _ScreenSaverSuspension *ScreenSaverSuspensionPtr;
+
+/* List of clients that are suspending the screensaver. */
+static ScreenSaverSuspensionPtr suspendingClients = NULL;
+
+/*
+ * clientResource is a resource ID that's added when the record is
+ * allocated, so the record is freed and the screensaver resumed when
+ * the client disconnects. count is the number of times the client has
+ * requested the screensaver be suspended.
+ */
+typedef struct _ScreenSaverSuspension
+{
+ ScreenSaverSuspensionPtr next;
+ ClientPtr pClient;
+ XID clientResource;
+ int count;
+} ScreenSaverSuspensionRec;
+
+static int ScreenSaverFreeSuspend(
+ pointer /*value */,
+ XID /* id */
+);
+
/*
* each screen has a list of clients requesting
* ScreenSaverNotify events. Each client has a resource
@@ -227,13 +258,15 @@ ScreenSaverExtensionInit(void)
AttrType = CreateNewResourceType(ScreenSaverFreeAttr);
EventType = CreateNewResourceType(ScreenSaverFreeEvents);
+ SuspendType = CreateNewResourceType(ScreenSaverFreeSuspend);
ScreenPrivateIndex = AllocateScreenPrivateIndex ();
+
for (i = 0; i < screenInfo.numScreens; i++)
{
pScreen = screenInfo.screens[i];
SetScreenPrivate (pScreen, NULL);
}
- if (AttrType && EventType && ScreenPrivateIndex != -1 &&
+ if (AttrType && EventType && SuspendType && ScreenPrivateIndex != -1 &&
(extEntry = AddExtension(ScreenSaverName, ScreenSaverNumberEvents, 0,
ProcScreenSaverDispatch, SProcScreenSaverDispatch,
ScreenSaverResetProc, StandardMinorOpcode)))
@@ -427,6 +460,45 @@ ScreenSaverFreeAttr (value, id)
return TRUE;
}
+static int
+ScreenSaverFreeSuspend (pointer value, XID id)
+{
+ ScreenSaverSuspensionPtr data = (ScreenSaverSuspensionPtr) value;
+ ScreenSaverSuspensionPtr *prev, this;
+
+ /* Unlink and free the suspension record for the client */
+ for (prev = &suspendingClients; (this = *prev); prev = &this->next)
+ {
+ if (this == data)
+ {
+ *prev = this->next;
+ free (this);
+ break;
+ }
+ }
+
+ /* Reenable the screensaver if this was the last client suspending it. */
+ if (screenSaverSuspended && suspendingClients == NULL)
+ {
+ screenSaverSuspended = FALSE;
+
+ /* The screensaver could be active, since suspending it (by design)
+ doesn't prevent it from being forceably activated */
+#ifdef DPMSExtension
+ if (screenIsSaved != SCREEN_SAVER_ON && DPMSPowerLevel == DPMSModeOn)
+#else
+ if (screenIsSaved != SCREEN_SAVER_ON)
+#endif
+ {
+ UpdateCurrentTimeIf();
+ lastDeviceEventTime = currentTime;
+ SetScreenSaverTimer();
+ }
+ }
+
+ return Success;
+}
+
static void
SendScreenSaverNotify (pScreen, state, forced)
ScreenPtr pScreen;
@@ -1286,12 +1358,73 @@ ProcScreenSaverUnsetAttributes (ClientPtr client)
return ScreenSaverUnsetAttributes(client);
}
+static int
+ProcScreenSaverSuspend (ClientPtr client)
+{
+ ScreenSaverSuspensionPtr *prev, this;
+
+ REQUEST(xScreenSaverSuspendReq);
+ REQUEST_SIZE_MATCH(xScreenSaverSuspendReq);
+
+ /* Check if this client is suspending the screensaver */
+ for (prev = &suspendingClients; (this = *prev); prev = &this->next)
+ if (this->pClient == client)
+ break;
+
+ if (this)
+ {
+ if (stuff->suspend == TRUE)
+ this->count++;
+ else if (--this->count == 0)
+ FreeResource (this->clientResource, RT_NONE);
+
+ return Success;
+ }
+
+ /* If we get to this point, this client isn't suspending the screensaver */
+ if (stuff->suspend == FALSE)
+ return Success;
+
+ /*
+ * Allocate a suspension record for the client, and stop the screensaver
+ * if it isn't already suspended by another client. We attach a resource ID
+ * to the record, so the screensaver will be reenabled and the record freed
+ * if the client disconnects without reenabling it first.
+ */
+ this = (ScreenSaverSuspensionPtr) malloc (sizeof (ScreenSaverSuspensionRec));
+
+ if (!this)
+ return BadAlloc;
+
+ memset(this, 0, sizeof (ScreenSaverSuspensionRec));
+ this->next = NULL;
+ this->pClient = client;
+ this->count = 1;
+ this->clientResource = FakeClientID (client->index);
+
+ if (!AddResource (this->clientResource, SuspendType, (pointer) this))
+ {
+ free (this);
+ return BadAlloc;
+ }
+
+ *prev = this;
+ if (!screenSaverSuspended)
+ {
+ screenSaverSuspended = TRUE;
+ FreeScreenSaverTimer();
+ }
+
+ return (client->noClientException);
+}
+
static DISPATCH_PROC((*NormalVector[])) = {
ProcScreenSaverQueryVersion,
ProcScreenSaverQueryInfo,
ProcScreenSaverSelectInput,
ProcScreenSaverSetAttributes,
ProcScreenSaverUnsetAttributes,
+ ProcScreenSaverSuspend,
};
#define NUM_REQUESTS ((sizeof NormalVector) / (sizeof NormalVector[0]))
@@ -1375,12 +1508,24 @@ SProcScreenSaverUnsetAttributes (client)
return ProcScreenSaverUnsetAttributes (client);
}
+static int
+SProcScreenSaverSuspend (ClientPtr client)
+{
+ REQUEST(xScreenSaverSuspendReq);
+
+ swaps(&stuff->length);
+ REQUEST_SIZE_MATCH(xScreenSaverSuspendReq);
+ swapl(&stuff->suspend);
+ return ProcScreenSaverSuspend (client);
+}
+
static DISPATCH_PROC((*SwappedVector[])) = {
SProcScreenSaverQueryVersion,
SProcScreenSaverQueryInfo,
SProcScreenSaverSelectInput,
SProcScreenSaverSetAttributes,
SProcScreenSaverUnsetAttributes,
+ SProcScreenSaverSuspend,
};
static int
diff --git a/nx-X11/programs/Xserver/Xext/sleepuntil.c b/nx-X11/programs/Xserver/Xext/sleepuntil.c
index 1934828d4..cc43815a7 100644
--- a/nx-X11/programs/Xserver/Xext/sleepuntil.c
+++ b/nx-X11/programs/Xserver/Xext/sleepuntil.c
@@ -78,7 +78,7 @@ static void SertafiedWakeupHandler(
void * /* LastSelectMask */
);
-int
+_X_EXPORT int
ClientSleepUntil (client, revive, notifyFunc, closure)
ClientPtr client;
TimeStamp *revive;
diff --git a/nx-X11/programs/Xserver/Xext/sync.c b/nx-X11/programs/Xserver/Xext/sync.c
index 7fa6145a6..e90e35db9 100644
--- a/nx-X11/programs/Xserver/Xext/sync.c
+++ b/nx-X11/programs/Xserver/Xext/sync.c
@@ -296,14 +296,18 @@ static void
SyncDeleteTriggerFromCounter(pTrigger)
SyncTrigger *pTrigger;
{
- SyncTriggerList *pCur, *pPrev = NULL;
+ SyncTriggerList *pCur;
+ SyncTriggerList *pPrev;
/* pCounter needs to be stored in pTrigger before calling here. */
if (!pTrigger->pCounter)
return;
- for (pCur = pTrigger->pCounter->pTriglist; pCur; pCur = pCur->next)
+ pPrev = NULL;
+ pCur = pTrigger->pCounter->pTriglist;
+
+ while (pCur)
{
if (pCur->pTrigger == pTrigger)
{
@@ -311,9 +315,13 @@ SyncDeleteTriggerFromCounter(pTrigger)
pPrev->next = pCur->next;
else
pTrigger->pCounter->pTriglist = pCur->next;
+
free(pCur);
break;
}
+
+ pPrev = pCur;
+ pCur = pCur->next;
}
if (IsSystemCounter(pTrigger->pCounter))
diff --git a/nx-X11/programs/Xserver/Xext/xres.c b/nx-X11/programs/Xserver/Xext/xres.c
index ceb9c65d4..03597ad95 100644
--- a/nx-X11/programs/Xserver/Xext/xres.c
+++ b/nx-X11/programs/Xserver/Xext/xres.c
@@ -6,6 +6,8 @@
#include <dix-config.h>
#endif
+#include <stdio.h>
+#include <string.h>
#include <nx-X11/X.h>
#include <nx-X11/Xproto.h>
#include "misc.h"
@@ -206,7 +208,7 @@ ProcXResQueryClientPixmapBytes (ClientPtr client)
rep.sequenceNumber = client->sequence;
rep.length = 0;
rep.bytes = bytes;
-#ifdef XSERVER64
+#ifdef _XSERVER64
rep.bytes_overflow = bytes >> 32;
#else
rep.bytes_overflow = 0;
diff --git a/nx-X11/programs/Xserver/Xext/xvmain.c b/nx-X11/programs/Xserver/Xext/xvmain.c
index 397f8dc81..c1492fdc6 100644
--- a/nx-X11/programs/Xserver/Xext/xvmain.c
+++ b/nx-X11/programs/Xserver/Xext/xvmain.c
@@ -253,7 +253,7 @@ CreateResourceTypes()
}
-int
+_X_EXPORT int
XvScreenInit(ScreenPtr pScreen)
{
XvScreenPtr pxvs;
@@ -333,13 +333,13 @@ XvResetProc(ExtensionEntry* extEntry)
{
}
-int
+_X_EXPORT int
XvGetScreenIndex()
{
return XvScreenIndex;
}
-unsigned long
+_X_EXPORT unsigned long
XvGetRTPort()
{
return XvRTPort;
diff --git a/nx-X11/programs/Xserver/dix/Imakefile b/nx-X11/programs/Xserver/dix/Imakefile
index 1024de965..ccdae3b82 100644
--- a/nx-X11/programs/Xserver/dix/Imakefile
+++ b/nx-X11/programs/Xserver/dix/Imakefile
@@ -132,7 +132,7 @@ NormalLibraryTarget(dix,$(OBJS))
LintLibraryTarget(dix,$(SRCS) $(XPSRC))
NormalLintTarget($(SRCS) $(XPSRC))
-SpecialCObjectRule(globals,$(ICONFIGFILES),$(SITE_DEFINES))
+SpecialCObjectRule(globals,$(ICONFIGFILES),$(SITE_DEFINES) $(EXT_DEFINES))
SpecialCObjectRule(main,$(ICONFIGFILES),$(VENDOR_DEFINES))
SpecialCObjectRule(pixmap,$(ICONFIGFILES),$(_NOOP_))
SpecialCObjectRule(privates,$(ICONFIGFILES),$(_NOOP_))
diff --git a/nx-X11/programs/Xserver/dix/globals.c b/nx-X11/programs/Xserver/dix/globals.c
index f9fa544ed..6f4774a5c 100644
--- a/nx-X11/programs/Xserver/dix/globals.c
+++ b/nx-X11/programs/Xserver/dix/globals.c
@@ -127,6 +127,10 @@ int defaultScreenSaverAllowExposures = DEFAULT_SCREEN_SAVER_EXPOSURES;
int logoScreenSaver = DEFAULT_LOGO_SCREEN_SAVER;
#endif
+#ifdef SCREENSAVER
+Bool screenSaverSuspended = FALSE;
+#endif
+
char *defaultFontPath = COMPILEDDEFAULTFONTPATH;
char *defaultTextFont = COMPILEDDEFAULTFONT;
char *defaultCursorFont = COMPILEDCURSORFONT;
diff --git a/nx-X11/programs/Xserver/dix/main.c b/nx-X11/programs/Xserver/dix/main.c
index 3f3c079e4..eb8f359a6 100644
--- a/nx-X11/programs/Xserver/dix/main.c
+++ b/nx-X11/programs/Xserver/dix/main.c
@@ -335,9 +335,6 @@ main(int argc, char *argv[], char *envp[])
InitRootWindow(screenInfo.screens[i]->root);
DefineInitialRootWindow(screenInfo.screens[0]->root);
SaveScreens(SCREEN_SAVER_FORCER, ScreenSaverReset);
-#ifdef DPMSExtension
- SetDPMSTimers();
-#endif
#ifdef PANORAMIX
if (!noPanoramiXExtension) {
@@ -387,9 +384,6 @@ main(int argc, char *argv[], char *envp[])
}
FreeFonts();
-#ifdef DPMSExtension
- FreeDPMSTimers();
-#endif
FreeAuditTimer();
ReleaseClientIds(serverClient);
diff --git a/nx-X11/programs/Xserver/include/globals.h b/nx-X11/programs/Xserver/include/globals.h
index 1c4d73e64..c43035cf0 100644
--- a/nx-X11/programs/Xserver/include/globals.h
+++ b/nx-X11/programs/Xserver/include/globals.h
@@ -11,6 +11,10 @@ extern CARD32 defaultScreenSaverInterval;
extern CARD32 ScreenSaverTime;
extern CARD32 ScreenSaverInterval;
+#ifdef SCREENSAVER
+extern Bool screenSaverSuspended;
+#endif
+
extern char *defaultFontPath;
extern int monitorResolution;
extern Bool loadableFonts;
diff --git a/nx-X11/programs/Xserver/os/WaitFor.c b/nx-X11/programs/Xserver/os/WaitFor.c
index 76e5da5f2..cb97039a7 100644
--- a/nx-X11/programs/Xserver/os/WaitFor.c
+++ b/nx-X11/programs/Xserver/os/WaitFor.c
@@ -701,26 +701,89 @@ TimerInit(void)
}
}
+#ifdef DPMSExtension
+
+#define DPMS_CHECK_MODE(mode,time)\
+ if (time > 0 && DPMSPowerLevel < mode && timeout >= time)\
+ DPMSSet(mode);
+
+#define DPMS_CHECK_TIMEOUT(time)\
+ if (time > 0 && (time - timeout) > 0)\
+ return time - timeout;
+
+static CARD32
+NextDPMSTimeout(INT32 timeout)
+{
+ /*
+ * Return the amount of time remaining until we should set
+ * the next power level. Fallthroughs are intentional.
+ */
+ switch (DPMSPowerLevel)
+ {
+ case DPMSModeOn:
+ DPMS_CHECK_TIMEOUT(DPMSStandbyTime)
+
+ case DPMSModeStandby:
+ DPMS_CHECK_TIMEOUT(DPMSSuspendTime)
+
+ case DPMSModeSuspend:
+ DPMS_CHECK_TIMEOUT(DPMSOffTime)
+
+ default: /* DPMSModeOff */
+ return 0;
+ }
+}
+#endif /* DPMSExtension */
+
static CARD32
ScreenSaverTimeoutExpire(OsTimerPtr timer,CARD32 now,void * arg)
{
- INT32 timeout = now - lastDeviceEventTime.milliseconds;
+ INT32 timeout = now - lastDeviceEventTime.milliseconds;
+ CARD32 nextTimeout = 0;
+
+#ifdef DPMSExtension
+ /*
+ * Check each mode lowest to highest, since a lower mode can
+ * have the same timeout as a higher one.
+ */
+ if (DPMSEnabled)
+ {
+ DPMS_CHECK_MODE(DPMSModeOff, DPMSOffTime)
+ DPMS_CHECK_MODE(DPMSModeSuspend, DPMSSuspendTime)
+ DPMS_CHECK_MODE(DPMSModeStandby, DPMSStandbyTime)
- if (timeout < ScreenSaverTime) {
- return ScreenSaverTime - timeout;
+ nextTimeout = NextDPMSTimeout(timeout);
+ }
+
+ /*
+ * Only do the screensaver checks if we're not in a DPMS
+ * power saving mode
+ */
+ if (DPMSPowerLevel != DPMSModeOn)
+ return nextTimeout;
+#endif /* DPMSExtension */
+
+ if (!ScreenSaverTime)
+ return nextTimeout;
+
+ if (timeout < ScreenSaverTime)
+ {
+ return nextTimeout > 0 ?
+ MIN(ScreenSaverTime - timeout, nextTimeout) :
+ ScreenSaverTime - timeout;
}
ResetOsBuffers(); /* not ideal, but better than nothing */
SaveScreens(SCREEN_SAVER_ON, ScreenSaverActive);
-#ifdef DPMSExtension
- if (ScreenSaverInterval > 0 && DPMSPowerLevel == DPMSModeOn)
-#else
if (ScreenSaverInterval > 0)
-#endif /* DPMSExtension */
- return ScreenSaverInterval;
+ {
+ nextTimeout = nextTimeout > 0 ?
+ MIN(ScreenSaverInterval, nextTimeout) :
+ ScreenSaverInterval;
+ }
- return 0;
+ return nextTimeout;
}
static OsTimerPtr ScreenSaverTimer = NULL;
@@ -737,93 +800,41 @@ FreeScreenSaverTimer(void)
void
SetScreenSaverTimer(void)
{
- if (ScreenSaverTime > 0) {
- ScreenSaverTimer = TimerSet(ScreenSaverTimer, 0, ScreenSaverTime,
- ScreenSaverTimeoutExpire, NULL);
- } else if (ScreenSaverTimer) {
- FreeScreenSaverTimer();
- }
-}
+ CARD32 timeout = 0;
#ifdef DPMSExtension
-
-static OsTimerPtr DPMSStandbyTimer = NULL;
-static OsTimerPtr DPMSSuspendTimer = NULL;
-static OsTimerPtr DPMSOffTimer = NULL;
-
-static CARD32
-DPMSStandbyTimerExpire(OsTimerPtr timer,CARD32 now,void * arg)
-{
- INT32 timeout = now - lastDeviceEventTime.milliseconds;
-
- if (timeout < DPMSStandbyTime) {
- return DPMSStandbyTime - timeout;
- }
- if (DPMSPowerLevel < DPMSModeStandby) {
- if (DPMSEnabled)
- DPMSSet(DPMSModeStandby);
- }
- return DPMSStandbyTime;
-}
-
-static CARD32
-DPMSSuspendTimerExpire(OsTimerPtr timer,CARD32 now,void * arg)
-{
- INT32 timeout = now - lastDeviceEventTime.milliseconds;
-
- if (timeout < DPMSSuspendTime) {
- return DPMSSuspendTime - timeout;
- }
- if (DPMSPowerLevel < DPMSModeSuspend) {
- if (DPMSEnabled)
- DPMSSet(DPMSModeSuspend);
- }
- return DPMSSuspendTime;
-}
-
-static CARD32
-DPMSOffTimerExpire(OsTimerPtr timer,CARD32 now,void * arg)
-{
- INT32 timeout = now - lastDeviceEventTime.milliseconds;
-
- if (timeout < DPMSOffTime) {
- return DPMSOffTime - timeout;
- }
- if (DPMSPowerLevel < DPMSModeOff) {
- if (DPMSEnabled)
- DPMSSet(DPMSModeOff);
+ if (DPMSEnabled)
+ {
+ /*
+ * A higher DPMS level has a timeout that's either less
+ * than or equal to that of a lower DPMS level.
+ */
+ if (DPMSStandbyTime > 0)
+ timeout = DPMSStandbyTime;
+
+ else if (DPMSSuspendTime > 0)
+ timeout = DPMSSuspendTime;
+
+ else if (DPMSOffTime > 0)
+ timeout = DPMSOffTime;
}
- return DPMSOffTime;
-}
+#endif
-void
-FreeDPMSTimers(void)
-{
- if (DPMSStandbyTimer) {
- TimerFree(DPMSStandbyTimer);
- DPMSStandbyTimer = NULL;
+ if (ScreenSaverTime > 0)
+ {
+ timeout = timeout > 0 ?
+ MIN(ScreenSaverTime, timeout) :
+ ScreenSaverTime;
}
- if (DPMSSuspendTimer) {
- TimerFree(DPMSSuspendTimer);
- DPMSSuspendTimer = NULL;
+#ifdef SCREENSAVER
+ if (timeout && !screenSaverSuspended) {
+#else
+ if (timeout) {
+#endif
+ ScreenSaverTimer = TimerSet(ScreenSaverTimer, 0, timeout,
+ ScreenSaverTimeoutExpire, NULL);
}
- if (DPMSOffTimer) {
- TimerFree(DPMSOffTimer);
- DPMSOffTimer = NULL;
+ else if (ScreenSaverTimer) {
+ FreeScreenSaverTimer();
}
}
-
-void
-SetDPMSTimers(void)
-{
- if (!DPMSEnabled)
- return;
-
- DPMSStandbyTimer = TimerSet(DPMSStandbyTimer, 0, DPMSStandbyTime,
- DPMSStandbyTimerExpire, NULL);
- DPMSSuspendTimer = TimerSet(DPMSSuspendTimer, 0, DPMSSuspendTime,
- DPMSSuspendTimerExpire, NULL);
- DPMSOffTimer = TimerSet(DPMSOffTimer, 0, DPMSOffTime,
- DPMSOffTimerExpire, NULL);
-}
-#endif