/* timers.c --- detecting when the user is idle, and other timer-related tasks.
- * xscreensaver, Copyright (c) 1991-1997 Jamie Zawinski <jwz@netscape.com>
+ * xscreensaver, Copyright (c) 1991-1997, 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
if (top_p && p->verbose_p && (events & KeyPressMask))
{
/* Only mention one window per tree (hack hack). */
- printf ("%s: selected KeyPress on 0x%lX\n", progname,
- (unsigned long) window);
+ fprintf (stderr, "%s: selected KeyPress on 0x%lX\n", blurb(),
+ (unsigned long) window);
top_p = False;
}
if (si->dbox_up_p)
{
if (p->verbose_p)
- printf ("%s: dbox up; delaying hack change.\n", progname);
+ fprintf (stderr, "%s: dialog box up; delaying hack change.\n",
+ blurb());
how_long = 30000; /* 30 secs */
}
else
{
+ maybe_reload_init_file (si);
if (p->verbose_p)
- printf ("%s: changing graphics hacks.\n", progname);
+ fprintf (stderr, "%s: changing graphics hacks.\n", blurb());
kill_screenhack (si);
spawn_screenhack (si, False);
}
#ifdef DEBUG_TIMERS
if (p->verbose_p)
- printf ("%s: starting cycle_timer (%ld, %ld)\n",
- progname, how_long, si->cycle_id);
-#endif
+ fprintf (stderr, "%s: starting cycle_timer (%ld, %ld)\n",
+ blurb(), how_long, si->cycle_id);
+#endif /* DEBUG_TIMERS */
}
saver_preferences *p = &si->prefs;
if (p->verbose_p)
- printf ("%s: timed out; activating lock\n", progname);
+ fprintf (stderr, "%s: timed out; activating lock\n", blurb());
si->locked_p = True;
#ifdef HAVE_XHPDISABLERESET
reset_timers (saver_info *si)
{
saver_preferences *p = &si->prefs;
- if (p->use_mit_saver_extension || p->use_sgi_saver_extension)
+ if (si->using_mit_saver_extension || si->using_sgi_saver_extension)
return;
#ifdef DEBUG_TIMERS
if (p->verbose_p)
- printf ("%s: killing idle_timer (%ld, %ld)\n",
- progname, p->timeout, si->timer_id);
-#endif
- XtRemoveTimeOut (si->timer_id);
+ fprintf (stderr, "%s: killing idle_timer (%ld, %ld)\n",
+ blurb(), p->timeout, si->timer_id);
+#endif /* DEBUG_TIMERS */
+
+ if (si->timer_id)
+ XtRemoveTimeOut (si->timer_id);
si->timer_id = XtAppAddTimeOut (si->app, p->timeout, idle_timer,
(XtPointer) si);
- if (si->cycle_id) abort ();
+ if (si->cycle_id) abort (); /* no cycle timer when inactive */
#ifdef DEBUG_TIMERS
if (p->verbose_p)
- printf ("%s: restarting idle_timer (%ld, %ld)\n",
- progname, p->timeout, si->timer_id);
-#endif
+ fprintf (stderr, "%s: restarting idle_timer (%ld, %ld)\n",
+ blurb(), p->timeout, si->timer_id);
+#endif /* DEBUG_TIMERS */
si->last_activity_time = time ((time_t *) 0);
}
saver_preferences *p = &si->prefs;
Bool active_p = False;
- if (p->use_xidle_extension ||
- p->use_mit_saver_extension ||
- p->use_sgi_saver_extension)
+ if (si->using_xidle_extension ||
+ si->using_mit_saver_extension ||
+ si->using_sgi_saver_extension)
+ /* If an extension is in use, we should not be polling the mouse. */
abort ();
si->check_pointer_timer_id =
if (root_x == ssi->poll_mouse_last_root_x &&
root_y == ssi->poll_mouse_last_root_y &&
child == ssi->poll_mouse_last_child)
- printf ("%s: modifiers changed at %s on screen %d.\n",
- progname, timestring(), i);
+ fprintf (stderr, "%s: modifiers changed at %s on screen %d.\n",
+ blurb(), timestring(), i);
else
- printf ("%s: pointer moved at %s on screen %d.\n",
- progname, timestring(), i);
-#endif
+ fprintf (stderr, "%s: pointer moved at %s on screen %d.\n",
+ blurb(), timestring(), i);
+#endif /* DEBUG_TIMERS */
si->last_activity_screen = ssi;
ssi->poll_mouse_last_root_x = root_x;
}
+static void
+dispatch_event (saver_info *si, XEvent *event)
+{
+ /* If this is for the splash dialog, pass it along.
+ Note that the password dialog is handled with its own event loop,
+ so events for that window will never come through here.
+ */
+ if (si->splash_dialog && event->xany.window == si->splash_dialog)
+ handle_splash_event (si, event);
+
+ XtDispatchEvent (event);
+}
+
+
void
sleep_until_idle (saver_info *si, Bool until_idle_p)
{
if (until_idle_p)
{
- if (!p->use_mit_saver_extension && !p->use_sgi_saver_extension)
+ if (!si->using_mit_saver_extension && !si->using_sgi_saver_extension)
{
/* Wake up periodically to ask the server if we are idle. */
si->timer_id = XtAppAddTimeOut (si->app, p->timeout, idle_timer,
(XtPointer) si);
+
#ifdef DEBUG_TIMERS
if (p->verbose_p)
- printf ("%s: starting idle_timer (%ld, %ld)\n",
- progname, p->timeout, si->timer_id);
-#endif
+ fprintf (stderr, "%s: starting idle_timer (%ld, %ld)\n",
+ blurb(), p->timeout, si->timer_id);
+#endif /* DEBUG_TIMERS */
}
- if (!p->use_xidle_extension &&
- !p->use_mit_saver_extension &&
- !p->use_sgi_saver_extension)
+ if (!si->using_xidle_extension &&
+ !si->using_mit_saver_extension &&
+ !si->using_sgi_saver_extension)
/* start polling the mouse position */
check_pointer_timer ((XtPointer) si, 0);
}
{
Time idle;
#ifdef HAVE_XIDLE_EXTENSION
- if (p->use_xidle_extension)
+ if (si->using_xidle_extension)
{
if (! XGetIdleTime (si->dpy, &idle))
{
- fprintf (stderr, "%s: XGetIdleTime() failed.\n", progname);
- saver_exit (si, 1);
+ fprintf (stderr, "%s: XGetIdleTime() failed.\n", blurb());
+ saver_exit (si, 1, 0);
}
}
else
#endif /* HAVE_XIDLE_EXTENSION */
#ifdef HAVE_MIT_SAVER_EXTENSION
- if (p->use_mit_saver_extension)
+ if (si->using_mit_saver_extension)
{
/* We don't need to do anything in this case - the synthetic
event isn't necessary, as we get sent specific events
else
#endif /* HAVE_MIT_SAVER_EXTENSION */
#ifdef HAVE_SGI_SAVER_EXTENSION
- if (p->use_sgi_saver_extension)
+ if (si->using_sgi_saver_extension)
{
/* We don't need to do anything in this case - the synthetic
event isn't necessary, as we get sent specific events
if (idle >= p->timeout)
goto DONE;
- else if (!p->use_mit_saver_extension &&
- !p->use_sgi_saver_extension)
+ else if (!si->using_mit_saver_extension &&
+ !si->using_sgi_saver_extension)
{
si->timer_id = XtAppAddTimeOut (si->app, p->timeout - idle,
idle_timer, (XtPointer) si);
#ifdef DEBUG_TIMERS
if (p->verbose_p)
- printf ("%s: starting idle_timer (%ld, %ld)\n",
- progname, p->timeout - idle, si->timer_id);
+ fprintf (stderr, "%s: starting idle_timer (%ld, %ld)\n",
+ blurb(), p->timeout - idle, si->timer_id);
#endif /* DEBUG_TIMERS */
}
}
break;
case CreateNotify:
- if (!p->use_xidle_extension &&
- !p->use_mit_saver_extension &&
- !p->use_sgi_saver_extension)
+ if (!si->using_xidle_extension &&
+ !si->using_mit_saver_extension &&
+ !si->using_sgi_saver_extension)
{
start_notice_events_timer (si, event.xcreatewindow.window);
#ifdef DEBUG_TIMERS
if (p->verbose_p)
- printf ("%s: starting notice_events_timer for 0x%X (%lu)\n",
- progname,
- (unsigned int) event.xcreatewindow.window,
- p->notice_events_timeout);
+ fprintf (stderr,
+ "%s: starting notice_events_timer for 0x%X (%lu)\n",
+ blurb(),
+ (unsigned int) event.xcreatewindow.window,
+ p->notice_events_timeout);
#endif /* DEBUG_TIMERS */
}
break;
if (p->verbose_p)
{
if (event.xany.type == MotionNotify)
- printf ("%s: MotionNotify at %s\n", progname, timestring ());
+ fprintf (stderr, "%s: MotionNotify at %s\n",
+ blurb(), timestring ());
else if (event.xany.type == KeyPress)
- printf ("%s: KeyPress seen on 0x%X at %s\n", progname,
- (unsigned int) event.xkey.window, timestring ());
+ fprintf (stderr, "%s: KeyPress seen on 0x%X at %s\n", blurb(),
+ (unsigned int) event.xkey.window, timestring ());
+ else if (event.xany.type == ButtonPress)
+ fprintf (stderr, "%s: ButtonPress seen on 0x%X at %s\n", blurb(),
+ (unsigned int) event.xbutton.window, timestring ());
}
-#endif
+#endif /* DEBUG_TIMERS */
- /* We got a user event */
+ /* If any widgets want to handle this event, let them. */
+ dispatch_event (si, &event);
+
+ /* We got a user event.
+ If we're waiting for the user to become active, this is it.
+ If we're waiting until the user becomes idle, reset the timers
+ (since now we have longer to wait.)
+ */
if (!until_idle_p)
- goto DONE;
+ {
+ if (si->demoing_p &&
+ (event.xany.type == MotionNotify ||
+ event.xany.type == KeyRelease))
+ /* When we're demoing a single hack, mouse motion doesn't
+ cause deactivation. Only clicks and keypresses do. */
+ ;
+ else
+ /* If we're not demoing, then any activity causes deactivation.
+ */
+ goto DONE;
+ }
else
reset_timers (si);
+
break;
default:
(XScreenSaverNotifyEvent *) &event;
if (sevent->state == ScreenSaverOn)
{
-# ifdef DEBUG_TIMERS
+ int i = 0;
if (p->verbose_p)
- printf ("%s: ScreenSaverOn event received at %s\n",
- progname, timestring ());
-# endif /* DEBUG_TIMERS */
+ fprintf (stderr, "%s: MIT ScreenSaverOn event received.\n",
+ blurb());
/* Get the "real" server window(s) out of the way as soon
as possible. */
- int i = 0;
for (i = 0; i < si->nscreens; i++)
{
saver_screen_info *ssi = &si->screens[i];
if (sevent->kind != ScreenSaverExternal)
{
-# ifdef DEBUG_TIMERS
fprintf (stderr,
"%s: ScreenSaverOn event wasn't of type External!\n",
- progname);
-# endif /* DEBUG_TIMERS */
+ blurb());
}
if (until_idle_p)
}
else if (sevent->state == ScreenSaverOff)
{
-# ifdef DEBUG_TIMERS
if (p->verbose_p)
- printf ("%s: ScreenSaverOff event received at %s\n",
- progname, timestring ());
-# endif /* DEBUG_TIMERS */
+ fprintf (stderr, "%s: MIT ScreenSaverOff event received.\n",
+ blurb());
if (!until_idle_p)
goto DONE;
}
-# ifdef DEBUG_TIMERS
- else if (p->verbose_p)
- printf ("%s: unknown MIT-SCREEN-SAVER event received at %s\n",
- progname, timestring ());
-# endif /* DEBUG_TIMERS */
+ else
+ fprintf (stderr,
+ "%s: unknown MIT-SCREEN-SAVER event %d received!\n",
+ blurb(), sevent->state);
}
else
#ifdef HAVE_SGI_SAVER_EXTENSION
if (event.type == (si->sgi_saver_ext_event_number + ScreenSaverStart))
{
-# ifdef DEBUG_TIMERS
if (p->verbose_p)
- printf ("%s: ScreenSaverStart event received at %s\n",
- progname, timestring ());
-# endif /* DEBUG_TIMERS */
+ fprintf (stderr, "%s: SGI ScreenSaverStart event received.\n",
+ blurb());
if (until_idle_p)
goto DONE;
else if (event.type == (si->sgi_saver_ext_event_number +
ScreenSaverEnd))
{
-# ifdef DEBUG_TIMERS
if (p->verbose_p)
- printf ("%s: ScreenSaverEnd event received at %s\n",
- progname, timestring ());
-# endif /* DEBUG_TIMERS */
+ fprintf (stderr, "%s: SGI ScreenSaverEnd event received.\n",
+ blurb());
if (!until_idle_p)
goto DONE;
}
else
#endif /* HAVE_SGI_SAVER_EXTENSION */
- XtDispatchEvent (&event);
+ dispatch_event (si, &event);
}
}
DONE:
si->timer_id = 0;
}
- if (until_idle_p && si->cycle_id)
+ if (until_idle_p && si->cycle_id) /* no cycle timer when inactive */
abort ();
return;
watchdog_timer (XtPointer closure, XtIntervalId *id)
{
saver_info *si = (saver_info *) closure;
- if (!si->demo_mode_p)
+
+ disable_builtin_screensaver (si, False);
+
+ if (si->screen_blanked_p)
{
- disable_builtin_screensaver (si, False);
- if (si->screen_blanked_p)
- {
- Bool running_p = screenhack_running_p(si);
+ 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)
- printf ("%s: watchdog timer raising %sscreen.\n",
- progname, (running_p ? "" : "and clearing "));
-#endif
- raise_window (si, True, True, running_p);
+ fprintf (stderr,
+ "%s: server reports that monitor has powered down; "
+ "killing running hacks.\n", blurb());
+ kill_screenhack (si);
}
}
}
#ifdef DEBUG_TIMERS
if (p->verbose_p)
- printf ("%s: restarting watchdog_timer (%ld, %ld)\n",
- progname, p->watchdog_timeout, si->watchdog_id);
-#endif
+ fprintf (stderr, "%s: restarting watchdog_timer (%ld, %ld)\n",
+ blurb(), p->watchdog_timeout, si->watchdog_id);
+#endif /* DEBUG_TIMERS */
+
}
}