http://ftp.x.org/contrib/applications/xscreensaver-3.20.tar.gz
[xscreensaver] / driver / xset.c
index 142acc325a35fba988530f1123fb1989647a2c85..6dabdb2d156f9f3942ed070abbce2358f23a64ca 100644 (file)
@@ -1,5 +1,5 @@
 /* xset.c --- interacting with server extensions and the builtin screensaver.
- * xscreensaver, Copyright (c) 1991-1998 Jamie Zawinski <jwz@netscape.com>
+ * xscreensaver, Copyright (c) 1991-1998 Jamie Zawinski <jwz@jwz.org>
  *
  * Permission to use, copy, modify, distribute, and sell this software and its
  * documentation for any purpose is hereby granted without fee, provided that
 
 #include "xscreensaver.h"
 
+#ifdef _VROOT_H_
+ERROR!  You must not include vroot.h in this file.
+#endif
+
 \f
 /* MIT SCREEN-SAVER server extension hackery.
  */
@@ -124,8 +128,8 @@ init_sgi_saver_extension (saver_info *si)
          fprintf (stderr,
        "%s: SGI SCREEN_SAVER extension exists, but can't be initialized;\n\
                perhaps some other screensaver program is already running?\n",
-                  progname);
-         p->use_sgi_saver_extension = False;
+                  blurb());
+         si->using_sgi_saver_extension = False;
          return;
        }
     }
@@ -133,13 +137,32 @@ init_sgi_saver_extension (saver_info *si)
 
 #endif /* HAVE_SGI_SAVER_EXTENSION */
 
+\f
+/* XIDLE server extension hackery.
+ */
+
+#ifdef HAVE_XIDLE_EXTENSION
+
+# include <X11/extensions/xidle.h>
+
+Bool
+query_xidle_extension (saver_info *si)
+{
+  int event_number;
+  int error_number;
+  return XidleQueryExtension (si->dpy, &event_number, &error_number);
+}
+
+#endif /* HAVE_XIDLE_EXTENSION */
+
+
 \f
 /* Figuring out what the appropriate XSetScreenSaver() parameters are
    (one wouldn't expect this to be rocket science.)
  */
 
 void
-disable_builtin_screensaver (saver_info *si, Bool turn_off_p)
+disable_builtin_screensaver (saver_info *si, Bool unblank_screen_p)
 {
   saver_preferences *p = &si->prefs;
   int current_server_timeout, current_server_interval;
@@ -169,24 +192,29 @@ disable_builtin_screensaver (saver_info *si, Bool turn_off_p)
   desired_server_interval = 0;
 
   /* I suspect (but am not sure) that DontAllowExposures might have
-     something to do with powering off the monitor as well. */
+     something to do with powering off the monitor as well, at least
+     on some systems that don't support XDPMS?  Who know... */
   desired_allow_exp = AllowExposures;
 
-#if defined(HAVE_MIT_SAVER_EXTENSION) || defined(HAVE_SGI_SAVER_EXTENSION)
-  if (p->use_mit_saver_extension || p->use_sgi_saver_extension)
+  if (si->using_mit_saver_extension || si->using_sgi_saver_extension)
     {
       desired_server_timeout = (p->timeout / 1000);
 
       /* The SGI extension won't give us events unless blanking is on.
         I think (unsure right now) that the MIT extension is the opposite. */
-      if (p->use_sgi_saver_extension)
+      if (si->using_sgi_saver_extension)
        desired_prefer_blank = PreferBlanking;
       else
        desired_prefer_blank = DontPreferBlanking;
     }
   else
-#endif /* HAVE_MIT_SAVER_EXTENSION || HAVE_SGI_SAVER_EXTENSION */
     {
+      /* When we're not using an extension, set the server-side timeout to 0,
+        so that the server never gets involved with screen blanking, and we
+        do it all ourselves.  (However, when we *are* using an extension,
+        we tell the server when to notify us, and rather than blanking the
+        screen, the server will send us an X event telling us to blank.)
+       */
       desired_server_timeout = 0;
     }
 
@@ -195,17 +223,19 @@ disable_builtin_screensaver (saver_info *si, Bool turn_off_p)
       desired_prefer_blank != current_prefer_blank ||
       desired_allow_exp != current_allow_exp)
     {
-      if (desired_server_timeout == 0)
-       printf ("%s%sisabling server builtin screensaver.\n\
-       You can re-enable it with \"xset s on\".\n",
-               (p->verbose_p ? "" : progname),
-               (p->verbose_p ? "\n\tD" : ": d"));
+      if (p->verbose_p && unblank_screen_p)
+        /* Used to print this all the time, but really, nobody cares.
+           Now only print it when verbose. */
+       fprintf (stderr,
+                "%s disabling server builtin screensaver.\n"
+                "%s: you can re-enable it with \"xset s on\".\n",
+                blurb(), blurb());
 
       if (p->verbose_p)
-       fprintf (stderr, "%s: (xset s %d %d %s %s)\n", progname,
+       fprintf (stderr, "%s: (xset s %d %d; xset s %s; xset s %s)\n", blurb(),
                 desired_server_timeout, desired_server_interval,
                 (desired_prefer_blank ? "blank" : "noblank"),
-                (desired_allow_exp ? "noexpose" : "expose"));
+                (desired_allow_exp ? "expose" : "noexpose"));
 
       XSetScreenSaver (si->dpy,
                       desired_server_timeout, desired_server_interval,
@@ -221,16 +251,16 @@ disable_builtin_screensaver (saver_info *si, Bool turn_off_p)
       {
        extension_initted = True;
 # ifdef HAVE_MIT_SAVER_EXTENSION
-       if (p->use_mit_saver_extension) init_mit_saver_extension(si);
+       if (si->using_mit_saver_extension) init_mit_saver_extension(si);
 # endif
 # ifdef HAVE_SGI_SAVER_EXTENSION
-       if (p->use_sgi_saver_extension) init_sgi_saver_extension(si);
+       if (si->using_sgi_saver_extension) init_sgi_saver_extension(si);
 # endif
       }
   }
 #endif /* HAVE_MIT_SAVER_EXTENSION || HAVE_SGI_SAVER_EXTENSION */
 
-  if (turn_off_p)
+  if (unblank_screen_p)
     /* Turn off the server builtin saver if it is now running. */
     XForceScreenSaver (si->dpy, ScreenSaverReset);
 }
@@ -264,6 +294,10 @@ disable_builtin_screensaver (saver_info *si, Bool turn_off_p)
    prototypes in any header file!  Thus, the prototypes here.  (The
    stuff in X11/extensions/dpms.h and X11/extensions/dpmsstr.h define
    the raw X protcol, they don't define the API to libXdpms.a.)
+
+   Some documentation:
+   Library:  ftp://ftp.x.org/pub/R6.4/xc/doc/specs/Xext/DPMSLib.ms
+   Protocol: ftp://ftp.x.org/pub/R6.4/xc/doc/specs/Xext/DPMS.ms
  */
 
 #ifdef HAVE_DPMS_EXTENSION
@@ -333,7 +367,7 @@ monitor_power_on (saver_info *si)
       if (!monitor_powered_on_p (si))
        fprintf (stderr,
        "%s: DPMSForceLevel(dpy, DPMSModeOn) did not power the monitor on?\n",
-                progname);
+                blurb());
     }
 }