X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?p=xscreensaver;a=blobdiff_plain;f=utils%2Ffade.c;h=d3f7ca3aa051ff1e808f7768b27957cfc66ab5df;hp=a45ae4807daa6ab02c9e075366ea2ffff60931e9;hb=6b1c86cf395f59389e4ece4ea8f4bea2c332745b;hpb=488f2fa8fbdbc77e91a70da2962d73af49e6cace diff --git a/utils/fade.c b/utils/fade.c index a45ae480..d3f7ca3a 100644 --- a/utils/fade.c +++ b/utils/fade.c @@ -1,4 +1,4 @@ -/* xscreensaver, Copyright (c) 1992-2003 Jamie Zawinski +/* xscreensaver, Copyright (c) 1992-2008 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 @@ -157,6 +157,28 @@ fade_screens (Display *dpy, Colormap *cmaps, } +static void +sleep_from (struct timeval *now, struct timeval *then, long usecs_per_step) +{ + /* If several seconds have passed, the machine must have been asleep + or thrashing or something. Don't sleep in that case, to avoid + overflowing and sleeping for an unconscionably long time. This + function should only be sleeping for very short periods. + */ + if (now->tv_sec - then->tv_sec < 5) + { + long diff = (((now->tv_sec - then->tv_sec) * 1000000) + + now->tv_usec - then->tv_usec); + if (usecs_per_step > diff) + usleep (usecs_per_step - diff); + } + + then->tv_sec = now->tv_sec; + then->tv_usec = now->tv_usec; +} + + + /* The business with `cmaps_per_screen' is to fake out the SGI 8-bit video hardware, which is capable of installing multiple (4) colormaps simultaneously. We have to install multiple copies of the same set of @@ -329,14 +351,7 @@ fade_screens_1 (Display *dpy, Colormap *cmaps, /* If we haven't already used up our alotted time, sleep to avoid changing the colormap too fast. */ - { - long diff = (((now.tv_sec - then.tv_sec) * 1000000) + - now.tv_usec - then.tv_usec); - then.tv_sec = now.tv_sec; - then.tv_usec = now.tv_usec; - if (usecs_per_step > diff) - usleep (usecs_per_step - diff); - } + sleep_from (&now, &then, usecs_per_step); } DONE: @@ -530,14 +545,7 @@ sgi_gamma_fade (Display *dpy, /* If we haven't already used up our alotted time, sleep to avoid changing the colormap too fast. */ - { - long diff = (((now.tv_sec - then.tv_sec) * 1000000) + - now.tv_usec - then.tv_usec); - then.tv_sec = now.tv_sec; - then.tv_usec = now.tv_usec; - if (usecs_per_step > diff) - usleep (usecs_per_step - diff); - } + sleep_from (&now, &then, usecs_per_step); } } @@ -757,14 +765,7 @@ xf86_gamma_fade (Display *dpy, /* If we haven't already used up our alotted time, sleep to avoid changing the colormap too fast. */ - { - long diff = (((now.tv_sec - then.tv_sec) * 1000000) + - now.tv_usec - then.tv_usec); - then.tv_sec = now.tv_sec; - then.tv_usec = now.tv_usec; - if (usecs_per_step > diff) - usleep (usecs_per_step - diff); - } + sleep_from (&now, &then, usecs_per_step); } }