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
27 #include <X11/Xatom.h>
28 #include <X11/Intrinsic.h>
30 #include <X11/Xproto.h>
31 #include <X11/extensions/dpms.h>
32 #include <X11/extensions/dpmsstr.h>
34 extern Bool DPMSQueryExtension (Display *dpy, int *event_ret, int *error_ret);
35 extern Bool DPMSCapable (Display *dpy);
36 extern Status DPMSForceLevel (Display *dpy, CARD16 level);
37 extern Status DPMSInfo (Display *dpy, CARD16 *power_level, BOOL *state);
39 extern Status DPMSGetVersion (Display *dpy, int *major_ret, int *minor_ret);
40 extern Status DPMSSetTimeouts (Display *dpy,
41 CARD16 standby, CARD16 suspend, CARD16 off);
42 extern Bool DPMSGetTimeouts (Display *dpy,
43 CARD16 *standby, CARD16 *suspend, CARD16 *off);
44 extern Status DPMSEnable (Display *dpy);
45 extern Status DPMSDisable (Display *dpy);
49 char *progclass = "XScreenSaver";
55 time_t now = time ((time_t *) 0);
56 char *ct = (char *) ctime (&now);
57 int n = strlen(progname);
59 strncpy(buf, progname, n);
62 strncpy(buf+n, ct+11, 8);
63 strcpy(buf+n+9, ": ");
69 main (int argc, char **argv)
73 int event_number, error_number;
75 CARD16 standby, suspend, off;
80 Widget toplevel_shell = XtAppInitialize (&app, progclass, 0, 0,
81 &argc, argv, 0, 0, 0);
82 Display *dpy = XtDisplay (toplevel_shell);
83 XtGetApplicationNameAndClass (dpy, &progname, &progclass);
85 if (!DPMSQueryExtension(dpy, &event_number, &error_number))
87 fprintf(stderr, "%s: DPMSQueryExtension(dpy, ...) ==> False\n",
89 fprintf(stderr, "%s: server does not support the XDPMS extension.\n",
94 fprintf(stderr, "%s: DPMSQueryExtension(dpy, ...) ==> %d, %d\n", blurb(),
95 event_number, error_number);
97 if (!DPMSCapable(dpy))
99 fprintf(stderr, "%s: DPMSCapable(dpy) ==> False\n", blurb());
100 fprintf(stderr, "%s: server says hardware doesn't support DPMS.\n",
105 fprintf(stderr, "%s: DPMSCapable(dpy) ==> True\n", blurb());
107 if (!DPMSGetVersion(dpy, &major, &minor))
109 fprintf(stderr, "%s: DPMSGetVersion(dpy, ...) ==> False\n", blurb());
110 fprintf(stderr, "%s: server didn't report XDPMS version numbers?\n",
114 fprintf(stderr, "%s: DPMSGetVersion(dpy, ...) ==> %d, %d\n", blurb(),
117 if (!DPMSGetTimeouts(dpy, &standby, &suspend, &off))
119 fprintf(stderr, "%s: DPMSGetTimeouts(dpy, ...) ==> False\n", blurb());
120 fprintf(stderr, "%s: server didn't report DPMS timeouts?\n", blurb());
124 "%s: DPMSGetTimeouts(dpy, ...)\n"
125 "\t ==> standby = %d, suspend = %d, off = %d\n",
126 blurb(), standby, suspend, off);
130 if (!DPMSInfo(dpy, &state, &onoff))
132 fprintf(stderr, "%s: DPMSInfo(dpy, ...) ==> False\n", blurb());
133 fprintf(stderr, "%s: couldn't read DPMS state?\n", blurb());
139 fprintf(stderr, "%s: DPMSInfo(dpy, ...) ==> %s, %s\n", blurb(),
140 (state == DPMSModeOn ? "DPMSModeOn" :
141 state == DPMSModeStandby ? "DPMSModeStandby" :
142 state == DPMSModeSuspend ? "DPMSModeSuspend" :
143 state == DPMSModeOff ? "DPMSModeOff" : "???"),
144 (onoff == 1 ? "On" : onoff == 0 ? "Off" : "???"));
147 if (state == DPMSModeStandby ||
148 state == DPMSModeSuspend ||
149 state == DPMSModeOff)
152 fprintf(stderr, "%s: monitor is off; turning it on.\n", blurb());
153 st = DPMSForceLevel (dpy, DPMSModeOn);
154 fprintf (stderr, "%s: DPMSForceLevel (dpy, DPMSModeOn) ==> %s\n",
155 blurb(), (st ? "Ok" : "Error"));