+
+
+/* This timer goes off every few minutes, whether the user is idle or not,
+ to try and clean up anything that has gone wrong.
+
+ It calls disable_builtin_screensaver() so that if xset has been used,
+ or some other program (like xlock) has messed with the XSetScreenSaver()
+ settings, they will be set back to sensible values (if a server extension
+ is in use, messing with xlock can cause xscreensaver to never get a wakeup
+ event, and could cause monitor power-saving to occur, and all manner of
+ heinousness.)
+
+ If the screen is currently blanked, it raises the window, in case some
+ other window has been mapped on top of it.
+
+ If the screen is currently blanked, and there is no hack running, it
+ clears the window, in case there is an error message printed on it (we
+ don't want the error message to burn in.)
+ */
+
+static void
+watchdog_timer (XtPointer closure, XtIntervalId *id)
+{
+ saver_info *si = (saver_info *) closure;
+
+ disable_builtin_screensaver (si, False);
+
+ if (si->screen_blanked_p)
+ {
+ Bool running_p = screenhack_running_p(si);
+
+#ifdef DEBUG_TIMERS
+ if (si->prefs.verbose_p)
+ fprintf (stderr, "%s: watchdog timer raising %sscreen.\n",
+ blurb(), (running_p ? "" : "and clearing "));
+#endif /* DEBUG_TIMERS */
+
+ raise_window (si, True, True, running_p);
+
+ if (!monitor_powered_on_p (si))
+ {
+ if (si->prefs.verbose_p)
+ fprintf (stderr,
+ "%s: server reports that monitor has powered down; "
+ "killing running hacks.\n", blurb());
+ kill_screenhack (si);
+ }
+ }
+}
+
+
+void
+reset_watchdog_timer (saver_info *si, Bool on_p)
+{
+ saver_preferences *p = &si->prefs;
+
+ if (si->watchdog_id)
+ {
+ XtRemoveTimeOut (si->watchdog_id);
+ si->watchdog_id = 0;
+ }
+
+ if (on_p && p->watchdog_timeout)
+ {
+ si->watchdog_id = XtAppAddTimeOut (si->app, p->watchdog_timeout,
+ watchdog_timer, (XtPointer) si);
+
+#ifdef DEBUG_TIMERS
+ if (p->verbose_p)
+ fprintf (stderr, "%s: restarting watchdog_timer (%ld, %ld)\n",
+ blurb(), p->watchdog_timeout, si->watchdog_id);
+#endif /* DEBUG_TIMERS */
+
+ }
+}