X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?p=xscreensaver;a=blobdiff_plain;f=utils%2Ffade.c;h=d3f7ca3aa051ff1e808f7768b27957cfc66ab5df;hp=18e940680a1fb8d607118d66ac68e57058a12f23;hb=6b1c86cf395f59389e4ece4ea8f4bea2c332745b;hpb=bbd0773f2adde4927a6196361d4061e70bf48cd9 diff --git a/utils/fade.c b/utils/fade.c index 18e94068..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,9 +157,31 @@ 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 - simultaniously. We have to install multiple copies of the same set of + simultaneously. We have to install multiple copies of the same set of colors in order to fill up all the available slots in the hardware color lookup table, so we install an extra N colormaps per screen to make sure that all screens really go black. @@ -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); } }