--- xcompmgr.c 2005-02-01 16:41:12.000000000 -0700 +++ /home/lynx/Desktop/working/xcompmgr-1.1.1/xcompmgr.c 2005-02-16 13:37:02.000000000 -0700 @@ -28,6 +28,7 @@ */ +#include #include #include #include @@ -185,11 +186,14 @@ double fade_in_step = 0.028; double fade_out_step = 0.03; int fade_delta = 10; -int fade_time = 0; +time_t fade_time = 0; Bool fadeWindows = False; Bool excludeDockShadows = False; Bool fadeTrans = False; +/* Next screen update */ +static sig_atomic_t do_paint = 0; + Bool autoRedirect = False; /* For shadow precomputation */ @@ -197,13 +201,20 @@ unsigned char *shadowCorner = NULL; unsigned char *shadowTop = NULL; -int -get_time_in_milliseconds () +/* Time updated once per loop */ +static struct timeval g_tv; + +static void +update_global_time () { - struct timeval tv; + gettimeofday (&g_tv, NULL); +} - gettimeofday (&tv, NULL); - return tv.tv_sec * 1000 + tv.tv_usec / 1000; + +static time_t +get_time_in_milliseconds () +{ + return g_tv.tv_sec * 1000 + g_tv.tv_usec / 1000; } fade * @@ -304,22 +315,22 @@ int fade_timeout (void) { - int now; + time_t now; int delta; if (!fades) - return -1; + return 60000; now = get_time_in_milliseconds(); - delta = fade_time - now; - if (delta < 0) + if (now > fade_time) delta = 0; -/* printf ("timeout %d\n", delta); */ + else + delta = fade_time - now; return delta; } void run_fades (Display *dpy) { - int now = get_time_in_milliseconds(); + time_t now = get_time_in_milliseconds(); fade *f, *next; int steps; Bool need_dequeue; @@ -327,7 +338,7 @@ #if 0 printf ("run fades\n"); #endif - if (fade_time - now > 0) + if (fade_time > now) return; steps = 1 + (now - fade_time) / fade_delta; for (next = fades; f = next; ) @@ -373,7 +384,6 @@ } fade_time = now + fade_delta; } - static double gaussian (double r, double x, double y) { @@ -625,9 +635,7 @@ { XImage *shadowImage; Pixmap shadowPixmap; - Pixmap finalPixmap; Picture shadowPicture; - Picture finalPicture; GC gc; shadowImage = make_shadow (dpy, opacity, width, height); @@ -1595,7 +1603,6 @@ finish_destroy_win (Display *dpy, Window id, Bool gone) { win **prev, *w; - for (prev = &list; (w = *prev); prev = &w->next) if (w->id == id) { @@ -1835,6 +1842,32 @@ } } +static void +alarm_handler(int s) +{ + do_paint++; +} + +static void +set_timer() +{ + struct itimerval it; + struct sigaction act; + const long int usec = 16666; + + it.it_interval.tv_sec = 0; + it.it_interval.tv_usec = usec; + it.it_value.tv_sec = 0; + it.it_value.tv_usec = usec; + + act.sa_handler = &alarm_handler; + act.sa_flags = 0; + sigemptyset(&act.sa_mask); + + sigaction(SIGALRM, &act, NULL); + setitimer(ITIMER_REAL, &it, NULL); +} + void usage (char *program) { @@ -2040,19 +2073,19 @@ ufd.events = POLLIN; if (!autoRedirect) paint_all (dpy, None); + /* start itimer */ + set_timer(); for (;;) { + update_global_time(); /* dump_wins (); */ do { if (autoRedirect) XFlush (dpy); if (!QLength (dpy)) { - if (poll (&ufd, 1, fade_timeout()) == 0) - { - run_fades (dpy); - break; - } + if (poll (&ufd, 1, fade_timeout()) <= 0) + break; } XNextEvent (dpy, &ev); @@ -2162,14 +2195,20 @@ break; } } while (QLength (dpy)); - if (allDamage && !autoRedirect) - { - static int paint; - paint_all (dpy, allDamage); - paint++; - XSync (dpy, False); - allDamage = None; - clipChanged = False; + + if (do_paint > 0) { + update_global_time(); + + run_fades (dpy); + if (allDamage && !autoRedirect) + { + paint_all (dpy, allDamage); + XSync (dpy, False); + allDamage = None; + clipChanged = False; + } + + do_paint = 0; } } }