X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?p=xscreensaver;a=blobdiff_plain;f=driver%2Ftimers.c;h=160ad73d7c8e85b7d0d013b4ed75ba2765e7d13a;hp=a6a9486fb8fd312e8ec0a1d61663c79f8084e544;hb=ffd8c0873576a9e3065696a624dce6b766b77062;hpb=df7adbee81405e2849728a24b498ad2117784b1f diff --git a/driver/timers.c b/driver/timers.c index a6a9486f..160ad73d 100644 --- a/driver/timers.c +++ b/driver/timers.c @@ -1,6 +1,5 @@ /* timers.c --- detecting when the user is idle, and other timer-related tasks. - * xscreensaver, Copyright (c) 1991-1997, 1998 - * Jamie Zawinski + * xscreensaver, Copyright (c) 1991-2004 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 @@ -15,12 +14,12 @@ # include "config.h" #endif -/* #define DEBUG_TIMERS */ - #include #include #include #include +#include +#include #ifdef HAVE_XMU # ifndef VMS # include @@ -43,6 +42,10 @@ #include #endif /* HAVE_SGI_SAVER_EXTENSION */ +#ifdef HAVE_RANDR +#include +#endif /* HAVE_RANDR */ + #include "xscreensaver.h" #ifdef HAVE_PROC_INTERRUPTS @@ -73,21 +76,34 @@ idle_timer (XtPointer closure, XtIntervalId *id) fake_event.xany.display = si->dpy; fake_event.xany.window = 0; XPutBackEvent (si->dpy, &fake_event); + + /* If we are the timer that just went off, clear the pointer to the id. */ + if (id) + { + if (si->timer_id && *id != si->timer_id) + abort(); /* oops, scheduled timer twice?? */ + si->timer_id = 0; + } } -static void +void schedule_wakeup_event (saver_info *si, Time when, Bool verbose_p) { + if (si->timer_id) + { + if (verbose_p) + fprintf (stderr, "%s: idle_timer already running\n", blurb()); + return; + } + /* Wake up periodically to ask the server if we are idle. */ si->timer_id = XtAppAddTimeOut (si->app, when, idle_timer, (XtPointer) si); -#ifdef DEBUG_TIMERS if (verbose_p) fprintf (stderr, "%s: starting idle_timer (%ld, %ld)\n", blurb(), when, si->timer_id); -#endif /* DEBUG_TIMERS */ } @@ -99,6 +115,7 @@ notice_events (saver_info *si, Window window, Bool top_p) unsigned long events; Window root, parent, *kids; unsigned int nkids; + int screen_no; if (XtWindowToWidget (si->dpy, window)) /* If it's one of ours, don't mess up its event mask. */ @@ -109,6 +126,11 @@ notice_events (saver_info *si, Window window, Bool top_p) if (window == root) top_p = False; + /* Figure out which screen this window is on, for the diagnostics. */ + for (screen_no = 0; screen_no < si->nscreens; screen_no++) + if (root == RootWindowOfScreen (si->screens[screen_no].screen)) + break; + XGetWindowAttributes (si->dpy, window, &attrs); events = ((attrs.all_event_masks | attrs.do_not_propagate_mask) & KeyPressMask); @@ -125,14 +147,20 @@ notice_events (saver_info *si, Window window, Bool top_p) the mouse or touching the keyboard, we won't know that they've been active, and the screensaver will come on. That sucks, but I don't know how to get around it. + + Since X presents mouse wheels as clicks, this applies to those, too: + scrolling through a document using only the mouse wheel doesn't + count as activity... Fortunately, /proc/interrupts helps, on + systems that have it. Oh, if it's a PS/2 mouse, not serial or USB. + This sucks! */ XSelectInput (si->dpy, window, SubstructureNotifyMask | events); - if (top_p && p->verbose_p && (events & KeyPressMask)) + if (top_p && p->debug_p && (events & KeyPressMask)) { /* Only mention one window per tree (hack hack). */ - fprintf (stderr, "%s: selected KeyPress on 0x%lX\n", blurb(), - (unsigned long) window); + fprintf (stderr, "%s: %d: selected KeyPress on 0x%lX\n", + blurb(), screen_no, (unsigned long) window); top_p = False; } @@ -230,8 +258,6 @@ cycle_timer (XtPointer closure, XtIntervalId *id) else { maybe_reload_init_file (si); - if (p->verbose_p) - fprintf (stderr, "%s: changing graphics hacks.\n", blurb()); kill_screenhack (si); if (!si->throttled_p) @@ -245,14 +271,21 @@ cycle_timer (XtPointer closure, XtIntervalId *id) } } - si->cycle_id = XtAppAddTimeOut (si->app, how_long, cycle_timer, - (XtPointer) si); + if (how_long > 0) + { + si->cycle_id = XtAppAddTimeOut (si->app, how_long, cycle_timer, + (XtPointer) si); -#ifdef DEBUG_TIMERS - if (p->verbose_p) - fprintf (stderr, "%s: starting cycle_timer (%ld, %ld)\n", - blurb(), how_long, si->cycle_id); -#endif /* DEBUG_TIMERS */ + if (p->debug_p) + fprintf (stderr, "%s: starting cycle_timer (%ld, %ld)\n", + blurb(), how_long, si->cycle_id); + } + else + { + if (p->debug_p) + fprintf (stderr, "%s: not starting cycle_timer: how_long == %ld\n", + blurb(), (unsigned long) how_long); + } } @@ -270,7 +303,7 @@ activate_lock_timer (XtPointer closure, XtIntervalId *id) /* Call this when user activity (or "simulated" activity) has been noticed. */ -static void +void reset_timers (saver_info *si) { saver_preferences *p = &si->prefs; @@ -279,15 +312,14 @@ reset_timers (saver_info *si) if (si->timer_id) { -#ifdef DEBUG_TIMERS - if (p->verbose_p) + if (p->debug_p) 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 = 0; } - schedule_wakeup_event (si, p->timeout, p->verbose_p); /* sets si->timer_id */ + schedule_wakeup_event (si, p->timeout, p->debug_p); /* sets si->timer_id */ if (si->cycle_id) abort (); /* no cycle timer when inactive */ @@ -316,7 +348,13 @@ check_pointer_timer (XtPointer closure, XtIntervalId *id) */ abort (); - si->check_pointer_timer_id = + if (id && *id == si->check_pointer_timer_id) /* this is us - it's expired */ + si->check_pointer_timer_id = 0; + + if (si->check_pointer_timer_id) /* only queue one at a time */ + XtRemoveTimeOut (si->check_pointer_timer_id); + + si->check_pointer_timer_id = /* now re-queue */ XtAppAddTimeOut (si->app, p->pointer_timeout, check_pointer_timer, (XtPointer) si); @@ -327,8 +365,16 @@ check_pointer_timer (XtPointer closure, XtIntervalId *id) int root_x, root_y, x, y; unsigned int mask; - XQueryPointer (si->dpy, ssi->screensaver_window, &root, &child, - &root_x, &root_y, &x, &y, &mask); + if (!ssi->real_screen_p) continue; + + if (!XQueryPointer (si->dpy, ssi->screensaver_window, &root, &child, + &root_x, &root_y, &x, &y, &mask)) + { + /* If XQueryPointer() returns false, the mouse is not on this screen. + */ + root_x = -1; + root_y = -1; + } if (root_x == ssi->poll_mouse_last_root_x && root_y == ssi->poll_mouse_last_root_y && @@ -338,17 +384,38 @@ check_pointer_timer (XtPointer closure, XtIntervalId *id) active_p = True; -#ifdef DEBUG_TIMERS - if (p->verbose_p) - if (root_x == ssi->poll_mouse_last_root_x && - root_y == ssi->poll_mouse_last_root_y && - child == ssi->poll_mouse_last_child) - fprintf (stderr, "%s: modifiers changed at %s on screen %d.\n", - blurb(), timestring(), i); - else - fprintf (stderr, "%s: pointer moved at %s on screen %d.\n", - blurb(), timestring(), i); -#endif /* DEBUG_TIMERS */ + if (p->debug_p) + { + if (root_x == ssi->poll_mouse_last_root_x && + root_y == ssi->poll_mouse_last_root_y && + child == ssi->poll_mouse_last_child) + fprintf (stderr, "%s: %d: modifiers changed: 0x%04x -> 0x%04x.\n", + blurb(), i, ssi->poll_mouse_last_mask, mask); + else + { + fprintf (stderr, "%s: %d: pointer moved: ", blurb(), i); + if (ssi->poll_mouse_last_root_x == -1) + fprintf (stderr, "off screen"); + else + fprintf (stderr, "%d,%d", + ssi->poll_mouse_last_root_x, + ssi->poll_mouse_last_root_y); + fprintf (stderr, " -> "); + if (root_x == -1) + fprintf (stderr, "off screen."); + else + fprintf (stderr, "%d,%d", root_x, root_y); + if (ssi->poll_mouse_last_root_x == -1 || root_x == -1) + fprintf (stderr, ".\n"); + else +# undef ABS +# define ABS(x)((x)<0?-(x):(x)) + fprintf (stderr, " (%d,%d).\n", + ABS(ssi->poll_mouse_last_root_x - root_x), + ABS(ssi->poll_mouse_last_root_y - root_y)); +# undef ABS + } + } si->last_activity_screen = ssi; ssi->poll_mouse_last_root_x = root_x; @@ -362,11 +429,6 @@ check_pointer_timer (XtPointer closure, XtIntervalId *id) si->using_proc_interrupts && proc_interrupts_activity_p (si)) { -# ifdef DEBUG_TIMERS - if (p->verbose_p) - fprintf (stderr, "%s: /proc/interrupts activity at %s.\n", - blurb(), timestring()); -# endif /* DEBUG_TIMERS */ active_p = True; } #endif /* HAVE_PROC_INTERRUPTS */ @@ -403,17 +465,20 @@ check_for_clock_skew (saver_info *si) time_t now = time ((time_t *) 0); long shift = now - si->last_wall_clock_time; -#ifdef DEBUG_TIMERS - if (p->verbose_p) - fprintf (stderr, "%s: checking wall clock (%d).\n", blurb(), - (si->last_wall_clock_time == 0 ? 0 : shift)); -#endif /* DEBUG_TIMERS */ + if (p->debug_p) + { + int i = (si->last_wall_clock_time == 0 ? 0 : shift); + fprintf (stderr, + "%s: checking wall clock for hibernation (%d:%02d:%02d).\n", + blurb(), + (i / (60 * 60)), ((i / 60) % 60), (i % 60)); + } if (si->last_wall_clock_time != 0 && shift > (p->timeout / 1000)) { if (p->verbose_p) - fprintf (stderr, "%s: wall clock has jumped by %d:%02d:%02d!\n", + fprintf (stderr, "%s: wall clock has jumped by %ld:%02ld:%02ld!\n", blurb(), (shift / (60 * 60)), ((shift / 60) % 60), (shift % 60)); @@ -440,6 +505,63 @@ dispatch_event (saver_info *si, XEvent *event) } +static void +swallow_unlock_typeahead_events (saver_info *si, XEvent *e) +{ + XEvent event; + char buf [100]; + int i = 0; + + memset (buf, 0, sizeof(buf)); + + event = *e; + + do + { + if (event.xany.type == KeyPress) + { + char s[2]; + int size = XLookupString ((XKeyEvent *) &event, s, 1, 0, 0); + if (size != 1) continue; + switch (*s) + { + case '\010': case '\177': /* Backspace */ + if (i > 0) i--; + break; + case '\025': case '\030': /* Erase line */ + case '\012': case '\015': /* Enter */ + i = 0; + break; + case '\040': /* Space */ + if (i == 0) + break; /* ignore space at beginning of line */ + /* else, fall through */ + default: + buf [i++] = *s; + break; + } + } + + } while (i < sizeof(buf)-1 && + XCheckMaskEvent (si->dpy, KeyPressMask, &event)); + + buf[i] = 0; + + if (si->unlock_typeahead) + { + memset (si->unlock_typeahead, 0, strlen(si->unlock_typeahead)); + free (si->unlock_typeahead); + } + + if (i > 0) + si->unlock_typeahead = strdup (buf); + else + si->unlock_typeahead = 0; + + memset (buf, 0, sizeof(buf)); +} + + /* methods of detecting idleness: explicitly informed by SGI SCREEN_SAVER server event; @@ -497,11 +619,8 @@ sleep_until_idle (saver_info *si, Bool until_idle_p) { if (polling_for_idleness) /* This causes a no-op event to be delivered to us in a while, so that - we come back around through the event loop again. Use of this timer - is economical: for example, if the screensaver should come on in 5 - minutes, and the user has been idle for 2 minutes, then this - timeout will go off no sooner than 3 minutes from now. */ - schedule_wakeup_event (si, p->timeout, p->verbose_p); + we come back around through the event loop again. */ + schedule_wakeup_event (si, p->timeout, p->debug_p); if (polling_mouse_position) /* Check to see if the mouse has moved, and set up a repeating timer @@ -518,6 +637,15 @@ sleep_until_idle (saver_info *si, Bool until_idle_p) if (until_idle_p) { Time idle; + + /* We may be idle; check one last time to see if the mouse has + moved, just in case the idle-timer went off within the 5 second + window between mouse polling. If the mouse has moved, then + check_pointer_timer() will reset last_activity_time. + */ + if (polling_mouse_position) + check_pointer_timer ((XtPointer) si, 0); + #ifdef HAVE_XIDLE_EXTENSION if (si->using_xidle_extension) { @@ -581,9 +709,12 @@ sleep_until_idle (saver_info *si, Bool until_idle_p) { /* The event went off, but it turns out that the user has not yet been idle for long enough. So re-signal the event. - */ + Be economical: if we should blank after 5 minutes, and the + user has been idle for 2 minutes, then set this timer to + go off in 3 minutes. + */ if (polling_for_idleness) - schedule_wakeup_event (si, p->timeout - idle, p->verbose_p); + schedule_wakeup_event (si, p->timeout - idle, p->debug_p); } } break; @@ -599,11 +730,7 @@ sleep_until_idle (saver_info *si, Bool until_idle_p) if (scanning_all_windows) { Window w = event.xcreatewindow.window; -#ifdef DEBUG_TIMERS - start_notice_events_timer (si, w, p->verbose_p); -#else /* !DEBUG_TIMERS */ - start_notice_events_timer (si, w, False); -#endif /* !DEBUG_TIMERS */ + start_notice_events_timer (si, w, p->debug_p); } break; @@ -613,19 +740,62 @@ sleep_until_idle (saver_info *si, Bool until_idle_p) case ButtonRelease: case MotionNotify: -#ifdef DEBUG_TIMERS - if (p->verbose_p) + if (p->debug_p) { + Window root=0, window=0; + int x=-1, y=-1; + const char *type = 0; if (event.xany.type == MotionNotify) - fprintf (stderr,"%s: MotionNotify at %s\n",blurb(),timestring()); + { + type = "MotionNotify"; + root = event.xmotion.root; + window = event.xmotion.window; + x = event.xmotion.x_root; + y = event.xmotion.y_root; + } else if (event.xany.type == KeyPress) - fprintf (stderr, "%s: KeyPress seen on 0x%X at %s\n", blurb(), - (unsigned int) event.xkey.window, timestring ()); + { + type = "KeyPress"; + root = event.xkey.root; + window = event.xkey.window; + x = y = -1; + } else if (event.xany.type == ButtonPress) - fprintf (stderr, "%s: ButtonPress seen on 0x%X at %s\n", blurb(), - (unsigned int) event.xbutton.window, timestring ()); + { + type = "ButtonPress"; + root = event.xkey.root; + window = event.xkey.window; + x = event.xmotion.x_root; + y = event.xmotion.y_root; + } + + if (type) + { + int i; + for (i = 0; i < si->nscreens; i++) + if (root == RootWindowOfScreen (si->screens[i].screen)) + break; + fprintf (stderr,"%s: %d: %s on 0x%lx", + blurb(), i, type, (unsigned long) window); + + /* Be careful never to do this unless in -debug mode, as + this could expose characters from the unlock password. */ + if (p->debug_p && event.xany.type == KeyPress) + { + KeySym keysym; + char c = 0; + XLookupString (&event.xkey, &c, 1, &keysym, 0); + fprintf (stderr, " (%s%s)", + (event.xkey.send_event ? "synthetic " : ""), + XKeysymToString (keysym)); + } + + if (x == -1) + fprintf (stderr, "\n"); + else + fprintf (stderr, " at %d,%d.\n", x, y); + } } -#endif /* DEBUG_TIMERS */ /* If any widgets want to handle this event, let them. */ dispatch_event (si, &event); @@ -737,6 +907,45 @@ sleep_until_idle (saver_info *si, Bool until_idle_p) else #endif /* HAVE_SGI_SAVER_EXTENSION */ +#ifdef HAVE_RANDR + if (event.type == (si->randr_event_number + RRScreenChangeNotify)) + { + /* The Resize and Rotate extension sends an event when the + size, rotation, or refresh rate of the screen has changed. */ + + XRRScreenChangeNotifyEvent *xrr_event = + (XRRScreenChangeNotifyEvent *) &event; + /* XRRRootToScreen is in Xrandr.h 1.4, 2001/06/07 */ + int screen = XRRRootToScreen (si->dpy, xrr_event->window); + + if (p->verbose_p) + { + if (si->screens[screen].width == xrr_event->width && + si->screens[screen].height == xrr_event->height) + fprintf (stderr, + "%s: %d: no-op screen size change event (%dx%d)\n", + blurb(), screen, + xrr_event->width, xrr_event->height); + else + fprintf (stderr, + "%s: %d: screen size changed from %dx%d to %dx%d\n", + blurb(), screen, + si->screens[screen].width, + si->screens[screen].height, + xrr_event->width, xrr_event->height); + } + +# ifdef RRScreenChangeNotifyMask + /* Inform Xlib that it's ok to update its data structures. */ + XRRUpdateConfiguration (&event); /* Xrandr.h 1.9, 2002/09/29 */ +# endif /* RRScreenChangeNotifyMask */ + + /* Resize the existing xscreensaver windows and cached ssi data. */ + resize_screensaver_window (si); + } + else +#endif /* HAVE_RANDR */ + /* Just some random event. Let the Widgets handle it, if desired. */ dispatch_event (si, &event); } @@ -752,8 +961,13 @@ sleep_until_idle (saver_info *si, Bool until_idle_p) doesn't exhibit itself without an extension, because in that case, there's only one event generated by user activity, not two.) */ - XCheckMaskEvent (si->dpy, (KeyPressMask|ButtonPressMask|PointerMotionMask), - &event); + if (!until_idle_p && si->locked_p) + swallow_unlock_typeahead_events (si, &event); + else + while (XCheckMaskEvent (si->dpy, + (KeyPressMask|ButtonPressMask|PointerMotionMask), + &event)) + ; if (si->check_pointer_timer_id) @@ -884,8 +1098,8 @@ proc_interrupts_activity_p (saver_info *si) static char last_kbd_line[255] = { 0, }; static char last_ptr_line[255] = { 0, }; char new_line[sizeof(last_kbd_line)]; - Bool got_kbd = False, kbd_diff = False; - Bool got_ptr = False, ptr_diff = False; + Bool checked_kbd = False, kbd_changed = False; + Bool checked_ptr = False, ptr_changed = False; if (!f0) { @@ -936,27 +1150,48 @@ proc_interrupts_activity_p (saver_info *si) while (fgets (new_line, sizeof(new_line)-1, f1)) { - if (!got_kbd && strstr (new_line, "keyboard")) + if (strchr (new_line, ',')) + { + /* Ignore any line that has a comma on it: this is because + a setup like this: + + 12: 930935 XT-PIC usb-uhci, PS/2 Mouse + + is really bad news. It *looks* like we can note mouse + activity from that line, but really, that interrupt gets + fired any time any USB device has activity! So we have + to ignore any shared IRQs. + */ + } + else if (!checked_kbd && strstr (new_line, "keyboard")) { - kbd_diff = (*last_kbd_line && !!strcmp (new_line, last_kbd_line)); + kbd_changed = (*last_kbd_line && !!strcmp (new_line, last_kbd_line)); strcpy (last_kbd_line, new_line); - got_kbd = True; + checked_kbd = True; } - else if (!got_ptr && strstr (new_line, "PS/2 Mouse")) + else if (!checked_ptr && strstr (new_line, "PS/2 Mouse")) { - ptr_diff = (*last_ptr_line && !!strcmp (new_line, last_ptr_line)); + ptr_changed = (*last_ptr_line && !!strcmp (new_line, last_ptr_line)); strcpy (last_ptr_line, new_line); - got_ptr = True; + checked_ptr = True; } - if (got_kbd && got_ptr) + if (checked_kbd && checked_ptr) break; } - if (got_kbd || got_ptr) + if (checked_kbd || checked_ptr) { fclose (f1); - return (kbd_diff || ptr_diff); + + if (si->prefs.debug_p && (kbd_changed || ptr_changed)) + fprintf (stderr, "%s: /proc/interrupts activity: %s\n", + blurb(), + ((kbd_changed && ptr_changed) ? "mouse and kbd" : + kbd_changed ? "kbd" : + ptr_changed ? "mouse" : "ERR")); + + return (kbd_changed || ptr_changed); } @@ -1001,37 +1236,45 @@ static void watchdog_timer (XtPointer closure, XtIntervalId *id) { saver_info *si = (saver_info *) closure; + saver_preferences *p = &si->prefs; disable_builtin_screensaver (si, False); + /* If the DPMS settings on the server have changed, change them back to + what ~/.xscreensaver says they should be. */ + 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); + if (si->screen_blanked_p) { Bool running_p = screenhack_running_p (si); if (si->dbox_up_p) { -#ifdef DEBUG_TIMERS - if (si->prefs.verbose_p) + if (si->prefs.debug_p) fprintf (stderr, "%s: dialog box is up: not raising screen.\n", blurb()); -#endif /* DEBUG_TIMERS */ } else { -#ifdef DEBUG_TIMERS - if (si->prefs.verbose_p) + if (si->prefs.debug_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 (screenhack_running_p (si) && + !monitor_powered_on_p (si)) { if (si->prefs.verbose_p) fprintf (stderr, - "%s: server reports that monitor has powered down; " + "%s: X says monitor has powered down; " "killing running hacks.\n", blurb()); kill_screenhack (si); } @@ -1061,11 +1304,95 @@ reset_watchdog_timer (saver_info *si, Bool on_p) si->watchdog_id = XtAppAddTimeOut (si->app, p->watchdog_timeout, watchdog_timer, (XtPointer) si); -#ifdef DEBUG_TIMERS - if (p->verbose_p) + if (p->debug_p) fprintf (stderr, "%s: restarting watchdog_timer (%ld, %ld)\n", blurb(), p->watchdog_timeout, si->watchdog_id); -#endif /* DEBUG_TIMERS */ + } +} + +/* It's possible that a race condition could have led to the saver + window being unexpectedly still mapped. This can happen like so: + + - screen is blanked + - hack is launched + - that hack tries to grab a screen image (it does this by + first unmapping the saver window, then remapping it.) + - hack unmaps window + - hack waits + - user becomes active + - hack re-maps window (*) + - driver kills subprocess + - driver unmaps window (**) + + The race is that (*) might have been sent to the server before + the client process was killed, but, due to scheduling randomness, + might not have been received by the server until after (**). + In other words, (*) and (**) might happen out of order, meaning + the driver will unmap the window, and then after that, the + recently-dead client will re-map it. This leaves the user + locked out (it looks like a desktop, but it's not!) + + To avoid this: after un-blanking the screen, we launch a timer + that wakes up once a second for ten seconds, and makes damned + sure that the window is still unmapped. + */ + +void +de_race_timer (XtPointer closure, XtIntervalId *id) +{ + saver_info *si = (saver_info *) closure; + saver_preferences *p = &si->prefs; + int secs = 1; + + if (id == 0) /* if id is 0, this is the initialization call. */ + { + si->de_race_ticks = 10; + if (p->verbose_p) + fprintf (stderr, "%s: starting de-race timer (%d seconds.)\n", + blurb(), si->de_race_ticks); + } + else + { + int i; + XSync (si->dpy, False); + for (i = 0; i < si->nscreens; i++) + { + saver_screen_info *ssi = &si->screens[i]; + Window w = ssi->screensaver_window; + XWindowAttributes xgwa; + XGetWindowAttributes (si->dpy, w, &xgwa); + if (xgwa.map_state != IsUnmapped) + { + if (p->verbose_p) + fprintf (stderr, + "%s: %d: client race! emergency unmap 0x%lx.\n", + blurb(), i, (unsigned long) w); + XUnmapWindow (si->dpy, w); + } + else if (p->debug_p) + fprintf (stderr, "%s: %d: (de-race of 0x%lx is cool.)\n", + blurb(), i, (unsigned long) w); + } + XSync (si->dpy, False); + + si->de_race_ticks--; + } + + if (id && *id == si->de_race_id) + si->de_race_id = 0; + + if (si->de_race_id) abort(); + + if (si->de_race_ticks <= 0) + { + si->de_race_id = 0; + if (p->verbose_p) + fprintf (stderr, "%s: de-race completed.\n", blurb()); + } + else + { + si->de_race_id = XtAppAddTimeOut (si->app, secs * 1000, + de_race_timer, closure); } }