~ubuntu-branches/ubuntu/karmic/xscreensaver/karmic

« back to all changes in this revision

Viewing changes to driver/dpms.c

  • Committer: Bazaar Package Importer
  • Author(s): Ralf Hildebrandt
  • Date: 2006-07-29 23:00:43 UTC
  • mfrom: (1.1.3 upstream)
  • mto: This revision was merged to the branch mainline in revision 15.
  • Revision ID: james.westby@ubuntu.com-20060729230043-3ergkicskbntet5n
Tags: 4.24-5
remove /usr/doc/xscreensaver link to finish /usr/doc ->
/usr/share/doc transition (closes: #380394)

Show diffs side-by-side

added added

removed removed

Lines of Context:
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>
3
3
 *
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.
11
11
 */
12
12
 
 
13
/* Display Power Management System (DPMS.)
 
14
 
 
15
   On XFree86 systems, "man xset" reports:
 
16
 
 
17
       -dpms    The -dpms option disables DPMS (Energy Star) features.
 
18
       +dpms    The +dpms option enables DPMS (Energy Star) features.
 
19
 
 
20
       dpms flags...
 
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
 
33
                particular mode.
 
34
 
 
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.)
 
41
 
 
42
   Some documentation:
 
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
 
45
 */
 
46
 
13
47
#ifdef HAVE_CONFIG_H
14
48
# include "config.h"
15
49
#endif
17
51
#include <stdio.h>
18
52
#include <X11/Xlib.h>
19
53
 
20
 
#ifdef HAVE_DPMS_EXTENSION
 
54
#ifdef HAVE_DPMS_EXTENSION   /* almost the whole file */
21
55
 
22
56
# include <X11/Xproto.h>
23
57
# include <X11/extensions/dpms.h>
25
59
 
26
60
  /* Why this crap is not in a header file somewhere, I have no idea.  Losers!
27
61
   */
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,
 
70
                                 CARD16 off);
 
71
  extern Bool   DPMSGetTimeouts (Display *, CARD16 *standby,
 
72
                                 CARD16 *suspend, CARD16 *off);
37
73
 
38
74
#endif /* HAVE_DPMS_EXTENSION */
39
75
 
48
84
 
49
85
#include "xscreensaver.h"
50
86
 
 
87
#ifdef HAVE_DPMS_EXTENSION
 
88
 
51
89
void
52
90
sync_server_dpms_settings (Display *dpy, Bool enabled_p,
53
91
                           int standby_secs, int suspend_secs, int off_secs,
54
92
                           Bool verbose_p)
55
93
{
56
 
# ifdef HAVE_DPMS_EXTENSION
57
 
 
58
94
  int event = 0, error = 0;
59
95
  BOOL o_enabled = False;
60
96
  CARD16 o_power = 0;
73
109
 
74
110
  if (bogus_p) enabled_p = False;
75
111
 
 
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.
 
114
   */
 
115
  if (standby_secs > 0xFFFF) standby_secs = 0xFFFF;
 
116
  if (suspend_secs > 0xFFFF) suspend_secs = 0xFFFF;
 
117
  if (off_secs     > 0xFFFF) off_secs     = 0xFFFF;
 
118
 
76
119
  if (! DPMSQueryExtension (dpy, &event, &error))
77
120
    {
78
121
      if (verbose_p)
136
179
        fprintf (stderr, "%s: set DPMS timeouts: %d %d %d.\n", blurb(),
137
180
                 standby_secs, suspend_secs, off_secs);
138
181
    }
139
 
 
140
 
# else  /* !HAVE_DPMS_EXTENSION */
141
 
 
 
182
}
 
183
 
 
184
Bool
 
185
monitor_powered_on_p (saver_info *si)
 
186
{
 
187
  Bool result;
 
188
  int event_number, error_number;
 
189
  BOOL onoff = False;
 
190
  CARD16 state;
 
191
 
 
192
  if (!DPMSQueryExtension(si->dpy, &event_number, &error_number))
 
193
    /* Server doesn't know -- assume the monitor is on. */
 
194
    result = True;
 
195
 
 
196
  else if (!DPMSCapable(si->dpy))
 
197
    /* Server says the monitor doesn't do power management -- so it's on. */
 
198
    result = True;
 
199
 
 
200
  else
 
201
    {
 
202
      DPMSInfo(si->dpy, &state, &onoff);
 
203
      if (!onoff)
 
204
        /* Server says DPMS is disabled -- so the monitor is on. */
 
205
        result = True;
 
206
      else
 
207
        switch (state) {
 
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? */
 
213
        }
 
214
    }
 
215
 
 
216
  return result;
 
217
}
 
218
 
 
219
void
 
220
monitor_power_on (saver_info *si)
 
221
{
 
222
  if (!monitor_powered_on_p (si))
 
223
    {
 
224
      DPMSForceLevel(si->dpy, DPMSModeOn);
 
225
      XSync(si->dpy, False);
 
226
      if (!monitor_powered_on_p (si))
 
227
        fprintf (stderr,
 
228
       "%s: DPMSForceLevel(dpy, DPMSModeOn) did not power the monitor on?\n",
 
229
                 blurb());
 
230
    }
 
231
}
 
232
 
 
233
#else  /* !HAVE_DPMS_EXTENSION */
 
234
 
 
235
void
 
236
sync_server_dpms_settings (Display *dpy, Bool enabled_p,
 
237
                           int standby_secs, int suspend_secs, int off_secs,
 
238
                           Bool verbose_p)
 
239
{
142
240
  if (verbose_p)
143
241
    fprintf (stderr, "%s: DPMS support not compiled in.\n", blurb());
144
 
 
145
 
# endif /* HAVE_DPMS_EXTENSION */
146
 
}
 
242
}
 
243
 
 
244
Bool
 
245
monitor_powered_on_p (saver_info *si) 
 
246
{
 
247
  return True; 
 
248
}
 
249
 
 
250
void
 
251
monitor_power_on (saver_info *si)
 
252
{
 
253
  return; 
 
254
}
 
255
 
 
256
#endif /* !HAVE_DPMS_EXTENSION */