1
1
/* dpms.c --- syncing the X Display Power Management values
2
* xscreensaver, Copyright (c) 2001 Jamie Zawinski <jwz@jwz.org>
2
* xscreensaver, Copyright (c) 2001, 2005 Jamie Zawinski <jwz@jwz.org>
4
4
* Permission to use, copy, modify, distribute, and sell this software and its
5
5
* documentation for any purpose is hereby granted without fee, provided that
10
10
* implied warranty.
13
/* Display Power Management System (DPMS.)
15
On XFree86 systems, "man xset" reports:
17
-dpms The -dpms option disables DPMS (Energy Star) features.
18
+dpms The +dpms option enables DPMS (Energy Star) features.
21
The dpms option allows the DPMS (Energy Star)
22
parameters to be set. The option can take up to three
23
numerical values, or the `force' flag followed by a
24
DPMS state. The `force' flags forces the server to
25
immediately switch to the DPMS state specified. The
26
DPMS state can be one of `standby', `suspend', or
27
`off'. When numerical values are given, they set the
28
inactivity period before the three modes are activated.
29
The first value given is for the `standby' mode, the
30
second is for the `suspend' mode, and the third is for
31
the `off' mode. Setting these values implicitly
32
enables the DPMS features. A value of zero disables a
35
However, note that the implementation is more than a little bogus,
36
in that there is code in /usr/X11R6/lib/libXdpms.a to implement all
37
the usual server-extension-querying utilities -- but there are no
38
prototypes in any header file! Thus, the prototypes here. (The
39
stuff in X11/extensions/dpms.h and X11/extensions/dpmsstr.h define
40
the raw X protcol, they don't define the API to libXdpms.a.)
43
Library: ftp://ftp.x.org/pub/R6.4/xc/doc/specs/Xext/DPMSLib.ms
44
Protocol: ftp://ftp.x.org/pub/R6.4/xc/doc/specs/Xext/DPMS.ms
13
47
#ifdef HAVE_CONFIG_H
14
48
# include "config.h"
26
60
/* Why this crap is not in a header file somewhere, I have no idea. Losers!
28
extern Bool DPMSQueryExtension (Display *dpy, int *event_ret, int *err_ret);
29
extern Bool DPMSCapable (Display *dpy);
30
extern Status DPMSInfo (Display *dpy, CARD16 *power_level, BOOL *state);
31
extern Status DPMSSetTimeouts (Display *dpy,
32
CARD16 standby, CARD16 suspend, CARD16 off);
33
extern Bool DPMSGetTimeouts (Display *dpy,
34
CARD16 *standby, CARD16 *suspend, CARD16 *off);
62
extern Bool DPMSQueryExtension (Display *, int *event_ret, int *err_ret);
63
extern Status DPMSGetVersion (Display *, int *major_ret, int *minor_ret);
64
extern Bool DPMSCapable (Display *);
65
extern Status DPMSInfo (Display *, CARD16 *power_level, BOOL *state);
35
66
extern Status DPMSEnable (Display *dpy);
36
67
extern Status DPMSDisable (Display *dpy);
68
extern Status DPMSForceLevel (Display *, CARD16 level);
69
extern Status DPMSSetTimeouts (Display *, CARD16 standby, CARD16 suspend,
71
extern Bool DPMSGetTimeouts (Display *, CARD16 *standby,
72
CARD16 *suspend, CARD16 *off);
38
74
#endif /* HAVE_DPMS_EXTENSION */
49
85
#include "xscreensaver.h"
87
#ifdef HAVE_DPMS_EXTENSION
52
90
sync_server_dpms_settings (Display *dpy, Bool enabled_p,
53
91
int standby_secs, int suspend_secs, int off_secs,
56
# ifdef HAVE_DPMS_EXTENSION
58
94
int event = 0, error = 0;
59
95
BOOL o_enabled = False;
60
96
CARD16 o_power = 0;
74
110
if (bogus_p) enabled_p = False;
112
/* X protocol sends these values in a CARD16, so truncate them to 16 bits.
113
This means that the maximum timeout is 18:12:15.
115
if (standby_secs > 0xFFFF) standby_secs = 0xFFFF;
116
if (suspend_secs > 0xFFFF) suspend_secs = 0xFFFF;
117
if (off_secs > 0xFFFF) off_secs = 0xFFFF;
76
119
if (! DPMSQueryExtension (dpy, &event, &error))
136
179
fprintf (stderr, "%s: set DPMS timeouts: %d %d %d.\n", blurb(),
137
180
standby_secs, suspend_secs, off_secs);
140
# else /* !HAVE_DPMS_EXTENSION */
185
monitor_powered_on_p (saver_info *si)
188
int event_number, error_number;
192
if (!DPMSQueryExtension(si->dpy, &event_number, &error_number))
193
/* Server doesn't know -- assume the monitor is on. */
196
else if (!DPMSCapable(si->dpy))
197
/* Server says the monitor doesn't do power management -- so it's on. */
202
DPMSInfo(si->dpy, &state, &onoff);
204
/* Server says DPMS is disabled -- so the monitor is on. */
208
case DPMSModeOn: result = True; break; /* really on */
209
case DPMSModeStandby: result = False; break; /* kinda off */
210
case DPMSModeSuspend: result = False; break; /* pretty off */
211
case DPMSModeOff: result = False; break; /* really off */
212
default: result = True; break; /* protocol error? */
220
monitor_power_on (saver_info *si)
222
if (!monitor_powered_on_p (si))
224
DPMSForceLevel(si->dpy, DPMSModeOn);
225
XSync(si->dpy, False);
226
if (!monitor_powered_on_p (si))
228
"%s: DPMSForceLevel(dpy, DPMSModeOn) did not power the monitor on?\n",
233
#else /* !HAVE_DPMS_EXTENSION */
236
sync_server_dpms_settings (Display *dpy, Bool enabled_p,
237
int standby_secs, int suspend_secs, int off_secs,
143
241
fprintf (stderr, "%s: DPMS support not compiled in.\n", blurb());
145
# endif /* HAVE_DPMS_EXTENSION */
245
monitor_powered_on_p (saver_info *si)
251
monitor_power_on (saver_info *si)
256
#endif /* !HAVE_DPMS_EXTENSION */