1 /* test-xdpms.c --- playing with the XDPMS extension.
2 * xscreensaver, Copyright (c) 1998 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
26 #include <X11/Xatom.h>
27 #include <X11/Intrinsic.h>
29 #include <X11/Xproto.h>
30 #include <X11/extensions/dpms.h>
31 #include <X11/extensions/dpmsstr.h>
33 extern Bool DPMSQueryExtension (Display *dpy, int *event_ret, int *error_ret);
34 extern Bool DPMSCapable (Display *dpy);
35 extern Status DPMSForceLevel (Display *dpy, CARD16 level);
36 extern Status DPMSInfo (Display *dpy, CARD16 *power_level, BOOL *state);
38 extern Status DPMSGetVersion (Display *dpy, int *major_ret, int *minor_ret);
39 extern Status DPMSSetTimeouts (Display *dpy,
40 CARD16 standby, CARD16 suspend, CARD16 off);
41 extern Bool DPMSGetTimeouts (Display *dpy,
42 CARD16 *standby, CARD16 *suspend, CARD16 *off);
43 extern Status DPMSEnable (Display *dpy);
44 extern Status DPMSDisable (Display *dpy);
48 char *progclass = "XScreenSaver";
54 time_t now = time ((time_t *) 0);
55 char *ct = (char *) ctime (&now);
56 int n = strlen(progname);
58 strncpy(buf, progname, n);
61 strncpy(buf+n, ct+11, 8);
62 strcpy(buf+n+9, ": ");
68 main (int argc, char **argv)
72 int event_number, error_number;
74 CARD16 standby, suspend, off;
79 Widget toplevel_shell = XtAppInitialize (&app, progclass, 0, 0,
80 &argc, argv, 0, 0, 0);
81 Display *dpy = XtDisplay (toplevel_shell);
82 XtGetApplicationNameAndClass (dpy, &progname, &progclass);
84 if (!DPMSQueryExtension(dpy, &event_number, &error_number))
86 fprintf(stderr, "%s: DPMSQueryExtension(dpy, ...) ==> False\n",
88 fprintf(stderr, "%s: server does not support the XDPMS extension.\n",
93 fprintf(stderr, "%s: DPMSQueryExtension(dpy, ...) ==> %d, %d\n", blurb(),
94 event_number, error_number);
96 if (!DPMSCapable(dpy))
98 fprintf(stderr, "%s: DPMSCapable(dpy) ==> False\n", blurb());
99 fprintf(stderr, "%s: server says hardware doesn't support DPMS.\n",
104 fprintf(stderr, "%s: DPMSCapable(dpy) ==> True\n", blurb());
106 if (!DPMSGetVersion(dpy, &major, &minor))
108 fprintf(stderr, "%s: DPMSGetVersion(dpy, ...) ==> False\n", blurb());
109 fprintf(stderr, "%s: server didn't report XDPMS version numbers?\n",
113 fprintf(stderr, "%s: DPMSGetVersion(dpy, ...) ==> %d, %d\n", blurb(),
116 if (!DPMSGetTimeouts(dpy, &standby, &suspend, &off))
118 fprintf(stderr, "%s: DPMSGetTimeouts(dpy, ...) ==> False\n", blurb());
119 fprintf(stderr, "%s: server didn't report DPMS timeouts?\n", blurb());
123 "%s: DPMSGetTimeouts(dpy, ...)\n"
124 "\t ==> standby = %d, suspend = %d, off = %d\n",
125 blurb(), standby, suspend, off);
129 if (!DPMSInfo(dpy, &state, &onoff))
131 fprintf(stderr, "%s: DPMSInfo(dpy, ...) ==> False\n", blurb());
132 fprintf(stderr, "%s: couldn't read DPMS state?\n", blurb());
138 fprintf(stderr, "%s: DPMSInfo(dpy, ...) ==> %s, %s\n", blurb(),
139 (state == DPMSModeOn ? "DPMSModeOn" :
140 state == DPMSModeStandby ? "DPMSModeStandby" :
141 state == DPMSModeSuspend ? "DPMSModeSuspend" :
142 state == DPMSModeOff ? "DPMSModeOff" : "???"),
143 (onoff == 1 ? "On" : onoff == 0 ? "Off" : "???"));
146 if (state == DPMSModeStandby ||
147 state == DPMSModeSuspend ||
148 state == DPMSModeOff)
151 fprintf(stderr, "%s: monitor is off; turning it on.\n", blurb());
152 st = DPMSForceLevel (dpy, DPMSModeOn);
153 fprintf (stderr, "%s: DPMSForceLevel (dpy, DPMSModeOn) ==> %s\n",
154 blurb(), (st ? "Ok" : "Error"));