http://x.cybermirror.org/R5contrib/xscreensaver-1.21.tar.Z
[xscreensaver] / driver / xscreensaver.c
index 54aee1dc459486747a4935639decd77523b42728..eb0bd64e0b850ec264e40ee8385a5e7bf3f2c1a3 100644 (file)
  *   it if the description above sounds just too flaky to live.  It is, but
  *   those are your choices.
  *
+ *   A third idle-detection option could be implement (but is not): when running
+ *   on the console display ($DISPLAY is `localhost`:0) and we're on a machine
+ *   where /dev/tty and /dev/mouse have reasonable last-modification times, we
+ *   could just stat those.  But the incremental benefit of implementing this
+ *   is really small, so forget I said anything.
+ *
  *   Debugging hints:
  *     - Have a second terminal handy.
  *     - Be careful where you set your breakpoints, you don't want this to
@@ -176,7 +182,9 @@ Time lock_timeout;
 
 extern Time timeout;
 extern Time cycle;
+#ifndef NO_LOCKING
 extern Time passwd_timeout;
+#endif
 extern Time pointer_timeout;
 extern Time notice_events_timeout;
 extern XtIntervalId lock_id, cycle_id;
@@ -196,6 +204,7 @@ extern Bool fade_p, unfade_p;
 extern int fade_seconds, fade_ticks;
 extern Bool install_cmap_p;
 extern Bool locking_disabled_p;
+extern char *nolock_reason;
 extern Bool demo_mode_p;
 extern Bool dbox_up_p;
 extern int next_mode_p;
@@ -212,8 +221,10 @@ static Atom XA_EXIT, XA_RESTART, XA_DEMO, XA_LOCK;
 #ifdef NO_MOTIF /* kludge */
 Bool demo_mode_p = 0;
 Bool dbox_up_p = 0;
+#ifndef NO_LOCKING
 Time passwd_timeout = 0;
 #endif
+#endif
 
 \f
 #ifdef NO_DEMO_MODE
@@ -226,7 +237,7 @@ static XrmOptionDescRec options [] = {
   { "-timeout",                ".timeout",     XrmoptionSepArg, 0 },
   { "-idelay",         ".initialDelay",XrmoptionSepArg, 0 },
   { "-cycle",          ".cycle",       XrmoptionSepArg, 0 },
-  { "-visual",         ".visual",      XrmoptionSepArg, 0 },
+  { "-visual",         ".visualID",    XrmoptionSepArg, 0 },
   { "-lock-timeout",   ".lockTimeout", XrmoptionSepArg, 0 },
   { "-verbose",                ".verbose",     XrmoptionNoArg, "on" },
   { "-silent",         ".verbose",     XrmoptionNoArg, "off" },
@@ -378,7 +389,8 @@ get_screenhacks ()
 static void
 get_resources ()
 {
-  visual         = get_visual_resource (dpy, "visual", "Visual");
+  /* Note: we can't use the resource ".visual" because Xt is SO FUCKED. */
+  visual         = get_visual_resource (dpy, "visualID", "VisualID");
   timeout         = 1000 * get_minutes_resource ("timeout", "Time");
   cycle           = 1000 * get_minutes_resource ("cycle",   "Time");
   lock_timeout   = 1000 * get_minutes_resource ("lockTimeout", "Time");
@@ -392,13 +404,15 @@ get_resources ()
   fade_ticks     = get_integer_resource ("fadeTicks", "Integer");
   shell           = get_string_resource ("bourneShell", "BourneShell");
   initial_delay   = get_seconds_resource ("initialDelay", "Time");
-  passwd_timeout  = 1000 * get_seconds_resource ("passwdTimeout", "Time");
   pointer_timeout = 1000 * get_seconds_resource ("pointerPollTime", "Time");
   notice_events_timeout = 1000 * get_seconds_resource ("windowCreationTimeout",
                                                       "Time");
+#ifndef NO_LOCKING
+  passwd_timeout  = 1000 * get_seconds_resource ("passwdTimeout", "Time");
+  if (passwd_timeout == 0) passwd_timeout = 30000;
+#endif
   if (timeout < 10000) timeout = 10000;
   if (cycle < 2000) cycle = 2000;
-  if (passwd_timeout == 0) passwd_timeout = 30000;
   if (pointer_timeout == 0) pointer_timeout = 5000;
   if (notice_events_timeout == 0) notice_events_timeout = 10000;
   if (fade_seconds == 0 || fade_ticks == 0) fade_p = False;
@@ -411,6 +425,7 @@ get_resources ()
 
 #ifdef NO_LOCKING
   locking_disabled_p = True;
+  nolock_reason = "not compiled with locking support";
   if (lock_p)
     {
       lock_p = False;
@@ -420,8 +435,8 @@ get_resources ()
 #else  /* ! NO_LOCKING */
   if (lock_p && locking_disabled_p)
     {
-      fprintf (stderr, "%s: %slocking is disabled.\n", progname,
-              (verbose_p ? "## " : ""));
+      fprintf (stderr, "%s: %slocking is disabled (%s).\n", progname,
+              (verbose_p ? "## " : ""), nolock_reason);
       lock_p = False;
     }
 #endif /* ! NO_LOCKING */
@@ -531,10 +546,14 @@ initialize (argc, argv)
 
 #ifdef NO_LOCKING
   locking_disabled_p = True;
+  nolock_reason = "not compiled with locking support";
 #else
   locking_disabled_p = False;
   if (! lock_init ())  /* before hack_uid() for proper permissions */
-    locking_disabled_p = True;
+    {
+      locking_disabled_p = True;
+      nolock_reason = "error getting password";
+    }
 #endif
 
   hack_uid ();
@@ -557,8 +576,14 @@ initialize (argc, argv)
   }
   save_argv (argc, argv);
   initialize_connection (argc, argv);
+  ensure_no_screensaver_running ();
 
+  if (verbose_p)
+    printf ("\
+%s %s, copyright (c) 1991-1993 by Jamie Zawinski <jwz@lucid.com>.\n\
+ pid = %d.\n", progname, screensaver_version, getpid ());
   ensure_no_screensaver_running ();
+
   demo_mode_p = initial_demo_mode_p;
   screensaver_window = 0;
   cursor = 0;
@@ -567,6 +592,7 @@ initialize (argc, argv)
   cycle_id = 0;
   lock_id = 0;
   locked_p = False;
+
   if (use_xidle)
     {
 #ifdef HAVE_XIDLE
@@ -587,11 +613,6 @@ initialize (argc, argv)
 
   init_sigchld ();
 
-  if (verbose_p)
-    printf ("\
-%s %s, copyright (c) 1991-1993 by Jamie Zawinski <jwz@lucid.com>.\n\
- pid = %d.\n", progname, screensaver_version, getpid ());
-
   disable_builtin_screensaver ();
 
   if (initial_demo_mode_p)