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;
63 Bool bogus_p = (standby_secs == 0 || suspend_secs == 0 || off_secs == 0);
65 if (bogus_p) enabled_p = False;
67 if (! DPMSQueryExtension (dpy, &event, &error))
70 fprintf (stderr, "%s: XDPMS extension not supported.\n", blurb());
74 if (! DPMSCapable (dpy))
77 fprintf (stderr, "%s: DPMS not supported.\n", blurb());
81 if (! DPMSInfo (dpy, &o_power, &o_enabled))
84 fprintf (stderr, "%s: unable to get DPMS state.\n", blurb());
88 if (o_enabled != enabled_p)
90 if (! (enabled_p ? DPMSEnable (dpy) : DPMSDisable (dpy)))
93 fprintf (stderr, "%s: unable to set DPMS state.\n", blurb());
97 fprintf (stderr, "%s: turned DPMS %s.\n", blurb(),
98 enabled_p ? "on" : "off");
104 fprintf (stderr, "%s: not setting bogus DPMS timeouts: %d %d %d.\n",
105 blurb(), standby_secs, suspend_secs, off_secs);
109 if (!DPMSGetTimeouts (dpy, &o_standby, &o_suspend, &o_off))
112 fprintf (stderr, "%s: unable to get DPMS timeouts.\n", blurb());
116 if (o_standby != standby_secs ||
117 o_suspend != suspend_secs ||
120 if (!DPMSSetTimeouts (dpy, standby_secs, suspend_secs, off_secs))
123 fprintf (stderr, "%s: unable to set DPMS timeouts.\n", blurb());
127 fprintf (stderr, "%s: set DPMS timeouts: %d %d %d.\n", blurb(),
128 standby_secs, suspend_secs, off_secs);
131 # else /* !HAVE_DPMS_EXTENSION */
134 fprintf (stderr, "%s: DPMS support not compiled in.\n", blurb());
136 # endif /* HAVE_DPMS_EXTENSION */