"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "driver/dpms.c" between
xscreensaver-6.00.tar.gz and xscreensaver-6.01.tar.gz

About: XScreenSaver is a large collection of screen savers and also the framework for blanking and locking the screen.

dpms.c  (xscreensaver-6.00):dpms.c  (xscreensaver-6.01)
skipping to change at line 23 skipping to change at line 23
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
# include "config.h" # include "config.h"
#endif #endif
#include <stdio.h> #include <stdio.h>
#include <X11/Xlib.h> #include <X11/Xlib.h>
#include <X11/Intrinsic.h> #include <X11/Intrinsic.h>
#include "xscreensaver.h" #include "xscreensaver.h"
/* Disable the X11 built-in screen saver. This is not directly related
to DPMS, but it does need to be prevented from fighting with us.
*/
static void
disable_builtin_saver (Display *dpy)
{
int otimeout = -1;
int ointerval = -1;
int oblanking = -1;
int oexposures = -1;
XGetScreenSaver (dpy, &otimeout, &ointerval, &oblanking, &oexposures);
if (otimeout == 0 && ointerval == 0 && oblanking == 0 && oexposures == 0)
{
if (verbose_p > 1)
fprintf (stderr, "%s: builtin saver already disabled\n", blurb());
}
else
{
if (verbose_p)
fprintf (stderr, "%s: disabling server's builtin saver\n", blurb());
XSetScreenSaver (dpy, 0, 0, 0, 0);
XForceScreenSaver (dpy, ScreenSaverReset);
}
}
#ifndef HAVE_DPMS_EXTENSION /* almost the whole file */ #ifndef HAVE_DPMS_EXTENSION /* almost the whole file */
void void
sync_server_dpms_settings (Display *dpy, struct saver_preferences *p) sync_server_dpms_settings (Display *dpy, struct saver_preferences *p)
{ {
disable_builtin_saver (dpy);
if (p->verbose_p) if (p->verbose_p)
fprintf (stderr, "%s: DPMS not supported at compile time\n", blurb()); fprintf (stderr, "%s: DPMS not supported at compile time\n", blurb());
} }
Bool monitor_powered_on_p (Display *dpy) { return True; } Bool monitor_powered_on_p (Display *dpy)
void monitor_power_on (saver_info *si, Bool on_p) { return; } {
if (verbose_p > 1)
fprintf (stderr,
"%s: DPMS disabled at compile time, assuming monitor on\n",
blurb());
return True;
}
void monitor_power_on (saver_info *si, Bool on_p)
{
if (verbose_p > 1)
fprintf (stderr,
"%s: DPMS disabled at compile time, not turning monitor %s\n",
blurb(), (on ? "on" : "off"));
return;
}
#else /* HAVE_DPMS_EXTENSION -- whole file */ #else /* HAVE_DPMS_EXTENSION -- whole file */
# include <X11/Xproto.h> # include <X11/Xproto.h>
# include <X11/extensions/dpms.h> # include <X11/extensions/dpms.h>
static Bool error_handler_hit_p = False; static Bool error_handler_hit_p = False;
static int static int
ignore_all_errors_ehandler (Display *dpy, XErrorEvent *error) ignore_all_errors_ehandler (Display *dpy, XErrorEvent *error)
skipping to change at line 69 skipping to change at line 110
Bool dpms_quickoff_p = p->dpms_quickoff_p; Bool dpms_quickoff_p = p->dpms_quickoff_p;
int standby_secs = p->dpms_standby / 1000; int standby_secs = p->dpms_standby / 1000;
int suspend_secs = p->dpms_suspend / 1000; int suspend_secs = p->dpms_suspend / 1000;
int off_secs = p->dpms_off / 1000; int off_secs = p->dpms_off / 1000;
Bool verbose_p = p->verbose_p; Bool verbose_p = p->verbose_p;
static Bool warned_p = False; static Bool warned_p = False;
/* If the monitor is currently powered off, defer any changes until /* If the monitor is currently powered off, defer any changes until
we are next called while it is powered on. */ we are next called while it is powered on. */
if (! monitor_powered_on_p (dpy)) if (! monitor_powered_on_p (dpy))
return; {
if (verbose_p > 1)
fprintf (stderr, "%s: DPMS: monitor off, skipping sync\n", blurb());
return;
}
/* Why did I do this? It makes DPMS never happen. disable_builtin_saver (dpy);
XSetScreenSaver (dpy, 0, 0, 0, 0);
XForceScreenSaver (dpy, ScreenSaverReset);
*/
if (dpms_quickoff_p && !off_secs) if (dpms_quickoff_p && !off_secs)
{ {
/* To do this, we might need to temporarily re-enable DPMS first. */ /* To do this, we might need to temporarily re-enable DPMS first. */
off_secs = 0xFFFF; off_secs = 0xFFFF;
} }
if (standby_secs == 0 && suspend_secs == 0 && off_secs == 0) if (standby_secs == 0 && suspend_secs == 0 && off_secs == 0)
/* all zero implies "DPMS disabled" */ /* all zero implies "DPMS disabled" */
enabled_p = False; enabled_p = False;
skipping to change at line 103 skipping to change at line 145
/* X protocol sends these values in a CARD16, so truncate them to 16 bits. /* X protocol sends these values in a CARD16, so truncate them to 16 bits.
This means that the maximum timeout is 18:12:15. This means that the maximum timeout is 18:12:15.
*/ */
if (standby_secs > 0xFFFF) standby_secs = 0xFFFF; if (standby_secs > 0xFFFF) standby_secs = 0xFFFF;
if (suspend_secs > 0xFFFF) suspend_secs = 0xFFFF; if (suspend_secs > 0xFFFF) suspend_secs = 0xFFFF;
if (off_secs > 0xFFFF) off_secs = 0xFFFF; if (off_secs > 0xFFFF) off_secs = 0xFFFF;
if (! DPMSQueryExtension (dpy, &event, &error)) if (! DPMSQueryExtension (dpy, &event, &error))
{ {
if (verbose_p && !warned_p) if (verbose_p > 1 || (verbose_p && !warned_p))
fprintf (stderr, "%s: XDPMS extension not supported\n", blurb()); fprintf (stderr, "%s: XDPMS extension not supported\n", blurb());
warned_p = True; warned_p = True;
return; return;
} }
if (! DPMSCapable (dpy)) if (! DPMSCapable (dpy))
{ {
if (verbose_p && !warned_p) if (verbose_p > 1 || (verbose_p && !warned_p))
fprintf (stderr, "%s: DPMS not supported\n", blurb()); fprintf (stderr, "%s: DPMS not supported\n", blurb());
warned_p = True; warned_p = True;
return; return;
} }
if (! DPMSInfo (dpy, &o_power, &o_enabled)) if (! DPMSInfo (dpy, &o_power, &o_enabled))
{ {
if (verbose_p && !warned_p) if (verbose_p > 1 || (verbose_p && !warned_p))
fprintf (stderr, "%s: unable to get DPMS state\n", blurb()); fprintf (stderr, "%s: unable to get DPMS state\n", blurb());
warned_p = True; warned_p = True;
return; return;
} }
if (o_enabled != enabled_p) if (o_enabled != enabled_p)
{ {
if (! (enabled_p ? DPMSEnable (dpy) : DPMSDisable (dpy))) if (! (enabled_p ? DPMSEnable (dpy) : DPMSDisable (dpy)))
{ {
if (verbose_p && !warned_p) if (verbose_p && !warned_p)
skipping to change at line 168 skipping to change at line 210
if (!DPMSSetTimeouts (dpy, standby_secs, suspend_secs, off_secs)) if (!DPMSSetTimeouts (dpy, standby_secs, suspend_secs, off_secs))
{ {
if (verbose_p) if (verbose_p)
fprintf (stderr, "%s: unable to set DPMS timeouts\n", blurb()); fprintf (stderr, "%s: unable to set DPMS timeouts\n", blurb());
return; return;
} }
else if (verbose_p) else if (verbose_p)
fprintf (stderr, "%s: set DPMS timeouts: %d %d %d\n", blurb(), fprintf (stderr, "%s: set DPMS timeouts: %d %d %d\n", blurb(),
standby_secs, suspend_secs, off_secs); standby_secs, suspend_secs, off_secs);
} }
else if (verbose_p > 1)
fprintf (stderr, "%s: DPMS timeouts already %d %d %d\n", blurb(),
o_standby, o_suspend, o_off);
} }
Bool Bool
monitor_powered_on_p (Display *dpy) monitor_powered_on_p (Display *dpy)
{ {
Bool result; Bool result;
int event_number, error_number; int event_number, error_number;
BOOL onoff = False; BOOL onoff = False;
CARD16 state; CARD16 state;
if (!DPMSQueryExtension(dpy, &event_number, &error_number)) if (!DPMSQueryExtension(dpy, &event_number, &error_number))
/* Server doesn't know -- assume the monitor is on. */ {
result = True; /* Server doesn't know -- assume the monitor is on. */
if (verbose_p > 1)
fprintf (stderr, "%s: DPMSQueryExtension failed, assuming monitor on\n",
blurb());
result = True;
}
else if (!DPMSCapable(dpy)) else if (!DPMSCapable(dpy))
/* Server says the monitor doesn't do power management -- so it's on. */ {
result = True; /* Server says the monitor doesn't do power management -- so it's on. */
if (verbose_p > 1)
fprintf (stderr, "%s: DPMSCapable false; assuming monitor on\n",
blurb());
result = True;
}
else else
{ {
DPMSInfo(dpy, &state, &onoff); DPMSInfo(dpy, &state, &onoff);
if (!onoff) if (!onoff)
/* Server says DPMS is disabled -- so the monitor is on. */ {
result = True; /* Server says DPMS is disabled -- so the monitor is on. */
if (verbose_p > 1)
fprintf (stderr, "%s: DPMSInfo disabled; assuming monitor on\n",
blurb());
result = True;
}
else else
switch (state) { switch (state) {
case DPMSModeOn: result = True; break; /* really on */ case DPMSModeOn: result = True; break; /* really on */
case DPMSModeStandby: result = False; break; /* kinda off */ case DPMSModeStandby: result = False; break; /* kinda off */
case DPMSModeSuspend: result = False; break; /* pretty off */ case DPMSModeSuspend: result = False; break; /* pretty off */
case DPMSModeOff: result = False; break; /* really off */ case DPMSModeOff: result = False; break; /* really off */
default: result = True; break; /* protocol error? */ default: result = True; break; /* protocol error? */
} }
if (verbose_p > 1)
fprintf (stderr, "%s: DPMSInfo = %s %s\n", blurb(),
(state == DPMSModeOn ? "DPMSModeOn" :
state == DPMSModeStandby ? "DPMSModeStandby" :
state == DPMSModeSuspend ? "DPMSModeSuspend" :
state == DPMSModeOff ? "DPMSModeOff" : "???"),
(result ? "True" : "False"));
} }
return result; return result;
} }
void void
monitor_power_on (saver_info *si, Bool on_p) monitor_power_on (saver_info *si, Bool on_p)
{ {
Bool verbose_p = si->prefs.verbose_p;
if ((!!on_p) != monitor_powered_on_p (si->dpy)) if ((!!on_p) != monitor_powered_on_p (si->dpy))
{ {
XErrorHandler old_handler; XErrorHandler old_handler;
int event_number, error_number; int event_number, error_number;
static Bool warned_p = False; static Bool warned_p = False;
if (!DPMSQueryExtension(si->dpy, &event_number, &error_number) || if (!DPMSQueryExtension(si->dpy, &event_number, &error_number) ||
!DPMSCapable(si->dpy)) !DPMSCapable(si->dpy))
{ {
if (si->prefs.verbose_p && !warned_p) if (verbose_p > 1 || (verbose_p && !warned_p))
fprintf (stderr, fprintf (stderr,
"%s: unable to power %s monitor: no DPMS extension\n", "%s: unable to power %s monitor: no DPMS extension\n",
blurb(), (on_p ? "on" : "off")); blurb(), (on_p ? "on" : "off"));
warned_p = True; warned_p = True;
return; return;
} }
/* The manual for DPMSForceLevel() says that it throws BadMatch if /* The manual for DPMSForceLevel() says that it throws BadMatch if
"DPMS is disabled on the specified display." "DPMS is disabled on the specified display."
skipping to change at line 244 skipping to change at line 312
*/ */
XSync (si->dpy, False); XSync (si->dpy, False);
error_handler_hit_p = False; error_handler_hit_p = False;
old_handler = XSetErrorHandler (ignore_all_errors_ehandler); old_handler = XSetErrorHandler (ignore_all_errors_ehandler);
XSync (si->dpy, False); XSync (si->dpy, False);
DPMSForceLevel(si->dpy, (on_p ? DPMSModeOn : DPMSModeOff)); DPMSForceLevel(si->dpy, (on_p ? DPMSModeOn : DPMSModeOff));
XSync (si->dpy, False); XSync (si->dpy, False);
XSetErrorHandler (old_handler); XSetErrorHandler (old_handler);
/* Ignore error_handler_hit_p, just probe monitor instead */ /* Ignore error_handler_hit_p, just probe monitor instead */
if (verbose_p > 1 && error_handler_hit_p)
fprintf (stderr, "%s: DPMSForceLevel got an X11 error\n", blurb());
if ((!!on_p) != monitor_powered_on_p (si->dpy)) /* double-check */ if ((!!on_p) != monitor_powered_on_p (si->dpy)) /* double-check */
fprintf (stderr, fprintf (stderr,
"%s: DPMSForceLevel(dpy, %s) did not change monitor power state\n", "%s: DPMSForceLevel(dpy, %s) did not change monitor power state\n",
blurb(), blurb(),
(on_p ? "DPMSModeOn" : "DPMSModeOff")); (on_p ? "DPMSModeOn" : "DPMSModeOff"));
} }
else if (verbose_p > 1)
fprintf (stderr, "%s: monitor is already %s\n", blurb(),
on_p ? "on" : "off");
} }
#endif /* HAVE_DPMS_EXTENSION -- whole file */ #endif /* HAVE_DPMS_EXTENSION -- whole file */
 End of changes. 17 change blocks. 
17 lines changed or deleted 91 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)