X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=driver%2Ftimers.c;h=aba6d5a3f0d421973fa1b3ef198ae9ce6bb0d13d;hb=2a991a811de4c7b22f812682b267b616a809fd9a;hp=92aa4b939e59deba9fa6328eb7d20f9bf932812b;hpb=f3e0240915ed9f9b3a61781f5c7002d587563fe0;p=xscreensaver diff --git a/driver/timers.c b/driver/timers.c index 92aa4b93..aba6d5a3 100644 --- a/driver/timers.c +++ b/driver/timers.c @@ -1,5 +1,6 @@ /* timers.c --- detecting when the user is idle, and other timer-related tasks. - * xscreensaver, Copyright (c) 1991-1997 Jamie Zawinski + * xscreensaver, Copyright (c) 1991-1997, 1998 + * Jamie Zawinski * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that @@ -105,8 +106,8 @@ notice_events (saver_info *si, Window window, Bool top_p) 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; } @@ -183,13 +184,15 @@ cycle_timer (XtPointer closure, XtIntervalId *id) 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); } @@ -198,9 +201,9 @@ cycle_timer (XtPointer closure, XtIntervalId *id) #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 */ } @@ -211,7 +214,7 @@ activate_lock_timer (XtPointer closure, XtIntervalId *id) 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 @@ -235,19 +238,20 @@ reset_timers (saver_info *si) #ifdef DEBUG_TIMERS if (p->verbose_p) - printf ("%s: killing idle_timer (%ld, %ld)\n", - progname, p->timeout, si->timer_id); -#endif + fprintf (stderr, "%s: killing idle_timer (%ld, %ld)\n", + blurb(), p->timeout, si->timer_id); +#endif /* DEBUG_TIMERS */ + 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); } @@ -267,6 +271,7 @@ check_pointer_timer (XtPointer closure, XtIntervalId *id) if (p->use_xidle_extension || p->use_mit_saver_extension || p->use_sgi_saver_extension) + /* If an extension is in use, we should not be polling the mouse. */ abort (); si->check_pointer_timer_id = @@ -296,12 +301,12 @@ check_pointer_timer (XtPointer closure, XtIntervalId *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; @@ -315,6 +320,20 @@ check_pointer_timer (XtPointer closure, XtIntervalId *id) } +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) { @@ -328,11 +347,12 @@ sleep_until_idle (saver_info *si, Bool until_idle_p) /* 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 && @@ -356,8 +376,8 @@ sleep_until_idle (saver_info *si, Bool until_idle_p) { 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 @@ -395,8 +415,8 @@ sleep_until_idle (saver_info *si, Bool until_idle_p) 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 */ } } @@ -415,10 +435,11 @@ sleep_until_idle (saver_info *si, Bool until_idle_p) 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; @@ -433,12 +454,19 @@ sleep_until_idle (saver_info *si, Bool until_idle_p) 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 */ + + /* If any widgets want to handle this event, let them. */ + dispatch_event (si, &event); /* We got a user event */ if (!until_idle_p) @@ -458,8 +486,8 @@ sleep_until_idle (saver_info *si, Bool until_idle_p) { # ifdef DEBUG_TIMERS if (p->verbose_p) - printf ("%s: ScreenSaverOn event received at %s\n", - progname, timestring ()); + fprintf (stderr, "%s: ScreenSaverOn event received at %s\n", + blurb(), timestring ()); # endif /* DEBUG_TIMERS */ /* Get the "real" server window(s) out of the way as soon @@ -479,7 +507,7 @@ sleep_until_idle (saver_info *si, Bool until_idle_p) # ifdef DEBUG_TIMERS fprintf (stderr, "%s: ScreenSaverOn event wasn't of type External!\n", - progname); + blurb()); # endif /* DEBUG_TIMERS */ } @@ -490,16 +518,17 @@ sleep_until_idle (saver_info *si, Bool until_idle_p) { # ifdef DEBUG_TIMERS if (p->verbose_p) - printf ("%s: ScreenSaverOff event received at %s\n", - progname, timestring ()); + fprintf (stderr, "%s: ScreenSaverOff event received at %s\n", + blurb(), timestring ()); # endif /* DEBUG_TIMERS */ 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 ()); + fprintf (stderr, + "%s: unknown MIT-SCREEN-SAVER event received at %s\n", + blurb(), timestring ()); # endif /* DEBUG_TIMERS */ } else @@ -512,8 +541,8 @@ sleep_until_idle (saver_info *si, Bool until_idle_p) { # ifdef DEBUG_TIMERS if (p->verbose_p) - printf ("%s: ScreenSaverStart event received at %s\n", - progname, timestring ()); + fprintf (stderr, "%s: ScreenSaverStart event received at %s\n", + blurb(), timestring ()); # endif /* DEBUG_TIMERS */ if (until_idle_p) @@ -524,8 +553,8 @@ sleep_until_idle (saver_info *si, Bool until_idle_p) { # ifdef DEBUG_TIMERS if (p->verbose_p) - printf ("%s: ScreenSaverEnd event received at %s\n", - progname, timestring ()); + fprintf (stderr, "%s: ScreenSaverEnd event received at %s\n", + blurb(), timestring ()); # endif /* DEBUG_TIMERS */ if (!until_idle_p) goto DONE; @@ -533,7 +562,7 @@ sleep_until_idle (saver_info *si, Bool until_idle_p) else #endif /* HAVE_SGI_SAVER_EXTENSION */ - XtDispatchEvent (&event); + dispatch_event (si, &event); } } DONE: @@ -562,7 +591,7 @@ sleep_until_idle (saver_info *si, Bool until_idle_p) 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; @@ -597,12 +626,23 @@ watchdog_timer (XtPointer closure, XtIntervalId *id) if (si->screen_blanked_p) { Bool running_p = screenhack_running_p(si); + #ifdef DEBUG_TIMERS if (si->prefs.verbose_p) - printf ("%s: watchdog timer raising %sscreen.\n", - progname, (running_p ? "" : "and clearing ")); -#endif + 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); + } } } } @@ -626,8 +666,9 @@ reset_watchdog_timer (saver_info *si, Bool on_p) #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 */ + } }