+
+ if (!system_has_proc_interrupts_p)
+ {
+ si->using_proc_interrupts = False;
+ if (p->verbose_p && piwhy)
+ fprintf (stderr, "%s: not using /proc/interrupts: %s.\n", blurb(),
+ piwhy);
+ }
+ else if (p->verbose_p)
+ {
+ if (si->using_proc_interrupts)
+ fprintf (stderr,
+ "%s: consulting /proc/interrupts for keyboard activity.\n",
+ blurb());
+ else
+ fprintf (stderr,
+ "%s: not consulting /proc/interrupts for keyboard activity.\n",
+ blurb());
+ }
+}
+
+
+#ifdef DEBUG_MULTISCREEN
+static void
+debug_multiscreen_timer (XtPointer closure, XtIntervalId *id)
+{
+ saver_info *si = (saver_info *) closure;
+ saver_preferences *p = &si->prefs;
+ if (update_screen_layout (si))
+ {
+ if (p->verbose_p)
+ {
+ fprintf (stderr, "%s: new layout:\n", blurb());
+ describe_monitor_layout (si);
+ }
+ resize_screensaver_window (si);
+ }
+ XtAppAddTimeOut (si->app, 1000*4, debug_multiscreen_timer, (XtPointer) si);
+}
+#endif /* DEBUG_MULTISCREEN */
+
+
+/* For the case where we aren't using an server extensions, select user events
+ on all the existing windows, and launch timers to select events on
+ newly-created windows as well.
+
+ If a server extension is being used, this does nothing.
+ */
+static void
+select_events (saver_info *si)
+{
+ saver_preferences *p = &si->prefs;
+ int i;
+
+ if (si->using_xidle_extension ||
+ si->using_mit_saver_extension ||
+ si->using_sgi_saver_extension)
+ return;
+
+ if (p->initial_delay)
+ {
+ if (p->verbose_p)
+ {
+ fprintf (stderr, "%s: waiting for %d second%s...", blurb(),
+ (int) p->initial_delay/1000,
+ (p->initial_delay == 1000 ? "" : "s"));
+ fflush (stderr);
+ fflush (stdout);
+ }
+ usleep (p->initial_delay);
+ if (p->verbose_p)
+ fprintf (stderr, " done.\n");
+ }
+
+ if (p->verbose_p)
+ {
+ fprintf (stderr, "%s: selecting events on extant windows...", blurb());
+ fflush (stderr);
+ fflush (stdout);
+ }
+
+ /* Select events on the root windows of every screen. This also selects
+ for window creation events, so that new subwindows will be noticed.
+ */
+ for (i = 0; i < si->nscreens; i++)
+ {
+ saver_screen_info *ssi = &si->screens[i];
+ if (ssi->real_screen_p)
+ start_notice_events_timer (si,
+ RootWindowOfScreen (si->screens[i].screen), False);
+ }
+
+ if (p->verbose_p)
+ fprintf (stderr, " done.\n");
+
+# ifdef DEBUG_MULTISCREEN
+ if (p->debug_p) debug_multiscreen_timer ((XtPointer) si, 0);
+# endif
+}
+
+
+void
+maybe_reload_init_file (saver_info *si)
+{
+ saver_preferences *p = &si->prefs;
+ if (init_file_changed_p (p))
+ {
+ if (p->verbose_p)
+ fprintf (stderr, "%s: file \"%s\" has changed, reloading.\n",
+ blurb(), init_file_name());
+
+ load_init_file (si->dpy, p);
+
+ /* If a server extension is in use, and p->timeout has changed,
+ we need to inform the server of the new timeout. */
+ disable_builtin_screensaver (si, False);
+
+ /* If the DPMS settings in the init file have changed,
+ change the settings on the server to match. */
+ sync_server_dpms_settings (si->dpy,
+ (p->dpms_enabled_p &&
+ p->mode != DONT_BLANK),
+ p->dpms_standby / 1000,
+ p->dpms_suspend / 1000,
+ p->dpms_off / 1000,
+ False);
+ }
+}
+
+
+/* Loop forever:
+
+ - wait until the user is idle;
+ - blank the screen;
+ - wait until the user is active;
+ - unblank the screen;
+ - repeat.
+
+ */
+static void
+main_loop (saver_info *si)
+{
+ saver_preferences *p = &si->prefs;
+ Bool ok_to_unblank;
+ int i;
+
+ while (1)
+ {
+ Bool was_locked = False;
+
+ if (p->verbose_p)
+ fprintf (stderr, "%s: awaiting idleness.\n", blurb());
+
+ check_for_leaks ("unblanked A");
+ sleep_until_idle (si, True);
+ check_for_leaks ("unblanked B");
+
+ if (p->verbose_p)
+ {
+ if (si->demoing_p)
+ fprintf (stderr, "%s: demoing %d at %s.\n", blurb(),
+ si->selection_mode, timestring());
+ else
+ fprintf (stderr, "%s: blanking screen at %s.\n", blurb(),
+ timestring());
+ }
+
+ maybe_reload_init_file (si);
+
+ if (p->mode == DONT_BLANK)
+ {
+ if (p->verbose_p)
+ fprintf (stderr, "%s: idle with blanking disabled at %s.\n",
+ blurb(), timestring());
+
+ /* Go around the loop and wait for the next bout of idleness,
+ or for the init file to change, or for a remote command to
+ come in, or something.
+
+ But, if locked_p is true, go ahead. This can only happen
+ if we're in "disabled" mode but a "lock" clientmessage came
+ in: in that case, we should go ahead and blank/lock the screen.
+ */
+ if (!si->locked_p)
+ continue;
+ }
+
+ /* Since we're about to blank the screen, kill the de-race timer,
+ if any. It might still be running if we have unblanked and then
+ re-blanked in a short period (e.g., when using the "next" button
+ in xscreensaver-demo.)
+ */
+ if (si->de_race_id)
+ {
+ if (p->verbose_p)
+ fprintf (stderr, "%s: stopping de-race timer (%d remaining.)\n",
+ blurb(), si->de_race_ticks);
+ XtRemoveTimeOut (si->de_race_id);
+ si->de_race_id = 0;
+ }
+
+
+ /* Now, try to blank.
+ */
+
+ if (! blank_screen (si))
+ {
+ /* We were unable to grab either the keyboard or mouse.
+ This means we did not (and must not) blank the screen.
+ If we were to blank the screen while some other program
+ is holding both the mouse and keyboard grabbed, then
+ we would never be able to un-blank it! We would never
+ see any events, and the display would be wedged.
+
+ So, just go around the loop again and wait for the
+ next bout of idleness. (If the user remains idle, we
+ will next try to blank the screen again in no more than
+ 60 seconds.)
+ */
+ Time retry = 60 * 1000;
+ if (p->timeout < retry)
+ retry = p->timeout;
+
+ if (p->debug_p)
+ {
+ fprintf (stderr,
+ "%s: DEBUG MODE: unable to grab -- BLANKING ANYWAY.\n",
+ blurb());
+ }
+ else
+ {
+ fprintf (stderr,
+ "%s: unable to grab keyboard or mouse! Blanking aborted.\n",
+ blurb());
+
+ schedule_wakeup_event (si, retry, p->debug_p);
+ continue;
+ }
+ }
+
+ for (i = 0; i < si->nscreens; i++)
+ kill_screenhack (&si->screens[i]);
+
+ raise_window (si, True, True, False);
+ if (si->throttled_p)
+ fprintf (stderr, "%s: not launching hack (throttled.)\n", blurb());
+ else
+ for (i = 0; i < si->nscreens; i++)
+ spawn_screenhack (&si->screens[i]);
+
+ /* Don't start the cycle timer in demo mode. */
+ if (!si->demoing_p && p->cycle)
+ si->cycle_id = XtAppAddTimeOut (si->app,
+ (si->selection_mode
+ /* see comment in cycle_timer() */
+ ? 1000 * 60 * 60
+ : p->cycle),
+ cycle_timer,
+ (XtPointer) si);
+
+