1 /* dpms.c --- syncing the X Display Power Management values
2 * xscreensaver, Copyright (c) 2001 Jamie Zawinski <jwz@jwz.org>
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that
7 * copyright notice and this permission notice appear in supporting
8 * documentation. No representations are made about the suitability of this
9 * software for any purpose. It is provided "as is" without express or
20 #ifdef HAVE_DPMS_EXTENSION
22 # include <X11/Xproto.h>
23 # include <X11/extensions/dpms.h>
24 # include <X11/extensions/dpmsstr.h>
26 /* 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);
35 extern Status DPMSEnable (Display *dpy);
36 extern Status DPMSDisable (Display *dpy);
38 #endif /* HAVE_DPMS_EXTENSION */
41 /* This file doesn't need the Xt headers, so stub these types out... */
43 #define XtAppContext void*
44 #define XrmDatabase void*
45 #define XtIntervalId void*
46 #define XtPointer void*
49 #include "xscreensaver.h"
52 sync_server_dpms_settings (Display *dpy, Bool enabled_p,
53 int standby_secs, int suspend_secs, int off_secs,
56 # ifdef HAVE_DPMS_EXTENSION
58 int event = 0, error = 0;
59 BOOL o_enabled = False;
61 CARD16 o_standby = 0, o_suspend = 0, o_off = 0;
64 if (standby_secs == 0 && suspend_secs == 0 && off_secs == 0)
65 /* all zero implies "DPMS disabled" */
68 else if ((standby_secs != 0 && standby_secs < 10) ||
69 (suspend_secs != 0 && suspend_secs < 10) ||
70 (off_secs != 0 && off_secs < 10))
71 /* any negative, or any positive-and-less-than-10-seconds, is crazy. */
74 if (bogus_p) enabled_p = False;
76 if (! DPMSQueryExtension (dpy, &event, &error))
79 fprintf (stderr, "%s: XDPMS extension not supported.\n", blurb());
83 if (! DPMSCapable (dpy))
86 fprintf (stderr, "%s: DPMS not supported.\n", blurb());
90 if (! DPMSInfo (dpy, &o_power, &o_enabled))
93 fprintf (stderr, "%s: unable to get DPMS state.\n", blurb());
97 if (o_enabled != enabled_p)
99 if (! (enabled_p ? DPMSEnable (dpy) : DPMSDisable (dpy)))
102 fprintf (stderr, "%s: unable to set DPMS state.\n", blurb());
106 fprintf (stderr, "%s: turned DPMS %s.\n", blurb(),
107 enabled_p ? "on" : "off");
113 fprintf (stderr, "%s: not setting bogus DPMS timeouts: %d %d %d.\n",
114 blurb(), standby_secs, suspend_secs, off_secs);
118 if (!DPMSGetTimeouts (dpy, &o_standby, &o_suspend, &o_off))
121 fprintf (stderr, "%s: unable to get DPMS timeouts.\n", blurb());
125 if (o_standby != standby_secs ||
126 o_suspend != suspend_secs ||
129 if (!DPMSSetTimeouts (dpy, standby_secs, suspend_secs, off_secs))
132 fprintf (stderr, "%s: unable to set DPMS timeouts.\n", blurb());
136 fprintf (stderr, "%s: set DPMS timeouts: %d %d %d.\n", blurb(),
137 standby_secs, suspend_secs, off_secs);
140 # else /* !HAVE_DPMS_EXTENSION */
143 fprintf (stderr, "%s: DPMS support not compiled in.\n", blurb());
145 # endif /* HAVE_DPMS_EXTENSION */