By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,617 Members | 1,896 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,617 IT Pros & Developers. It's quick & easy.

ERROR: storage size of 'tzp' isn't known

P: n/a
System:
Redhat 7.2 [Alpha]
Kernel-2.6.11.8
GCC-3.4.3
CCC-6.5.9
Binutils-2.15
Make-3.80
GTK/GLIB-2.6.7

For some reason my Linux box is suddenly having issues trying to read ;

'/usr/include/time.h'
'/usr/include/sys/time.h'

This is a problem that has just recently cropped up and hasn't always been
an issue. I first noticed it after upgrading to GTK-2.6.0, I don't know if
thats the problem but that was when I first noticed it. Now whenever I
attempt to compile programs, which about the only way to upgrade/install
software on an Alpha nowadays, I receive the error 'error: storage size of
'tzp' isn't known'. I get this with programs which are GTK intensive such as
Gaim/Xchat/Xscreensavers but apparently don't see it with other programs
such as Apache/Pureftpd/Openssl/etc.

Does anyone happen to have an idea on how to fix this problem? I've tried to
narrow things down by using strace/lsof while building but have turned up
nothing. I've updated SED/ MAKE/ BINUTILS/ AUTOMAKE/ LIBTOOL/ AUTOCONF/ 'you
name it'...

16K /usr/include/time.h
[root@jericho utils]# cat /usr/include/time.h
/* Copyright (C) 1991-1999, 2000, 2001, 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.

The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */

/*
* ISO C99 Standard: 7.23 Date and time <time.h>
*/

#ifndef _TIME_H

#if (! defined __need_time_t && !defined __need_clock_t && \
! defined __need_timespec)
# define _TIME_H 1
# include <features.h>

__BEGIN_DECLS

#endif

#ifdef _TIME_H
/* Get size_t and NULL from <stddef.h>. */
# define __need_size_t
# define __need_NULL
# include <stddef.h>

/* This defines CLOCKS_PER_SEC, which is the number of processor clock
ticks per second. */
# include <bits/time.h>

/* This is the obsolete POSIX.1-1988 name for the same constant. */
# if !defined __STRICT_ANSI__ && !defined __USE_XOPEN2K
# ifndef CLK_TCK
# define CLK_TCK CLOCKS_PER_SEC
# endif
# endif

#endif /* <time.h> included. */

#if !defined __clock_t_defined && (defined _TIME_H || defined
__need_clock_t)
# define __clock_t_defined 1

# include <bits/types.h>

__BEGIN_NAMESPACE_STD
/* Returned by `clock'. */
typedef __clock_t clock_t;
__END_NAMESPACE_STD
#if defined __USE_XOPEN || defined __USE_POSIX || defined __USE_MISC
__USING_NAMESPACE_STD(clock_t)
#endif

#endif /* clock_t not defined and <time.h> or need clock_t. */
#undef __need_clock_t

#if !defined __time_t_defined && (defined _TIME_H || defined __need_time_t)
# define __time_t_defined 1

# include <bits/types.h>

__BEGIN_NAMESPACE_STD
/* Returned by `time'. */
typedef __time_t time_t;
__END_NAMESPACE_STD
#if defined __USE_POSIX || defined __USE_MISC || defined __USE_SVID
__USING_NAMESPACE_STD(time_t)
#endif

#endif /* time_t not defined and <time.h> or need time_t. */
#undef __need_time_t

#if !defined __clockid_t_defined && \
((defined _TIME_H && defined __USE_POSIX199309) || defined
__need_clockid_t)
# define __clockid_t_defined 1

# include <bits/types.h>

/* Clock ID used in clock and timer functions. */
typedef __clockid_t clockid_t;

#endif /* clockid_t not defined and <time.h> or need clockid_t. */
#undef __clockid_time_t

#if !defined __timer_t_defined && \
((defined _TIME_H && defined __USE_POSIX199309) || defined
__need_timer_t)
# define __timer_t_defined 1

# include <bits/types.h>

/* Timer ID returned by `timer_create'. */
typedef __timer_t timer_t;

#endif /* timer_t not defined and <time.h> or need timer_t. */
#undef __need_timer_t
#if !defined __timespec_defined && \
((defined _TIME_H && \
(defined __USE_POSIX199309 || defined __USE_MISC)) || \
defined __need_timespec)
# define __timespec_defined 1

/* POSIX.1b structure for a time value. This is like a `struct timeval' but
has nanoseconds instead of microseconds. */
struct timespec
{
__time_t tv_sec; /* Seconds. */
long int tv_nsec; /* Nanoseconds. */
};

#endif /* timespec not defined and <time.h> or need timespec. */
#undef __need_timespec
#ifdef _TIME_H
__BEGIN_NAMESPACE_STD
/* Used by other time functions. */
struct tm
{
int tm_sec; /* Seconds. [0-60] (1 leap second) */
int tm_min; /* Minutes. [0-59] */
int tm_hour; /* Hours. [0-23] */
int tm_mday; /* Day. [1-31] */
int tm_mon; /* Month. [0-11] */
int tm_year; /* Year - 1900. */
int tm_wday; /* Day of week. [0-6] */
int tm_yday; /* Days in year.[0-365] */
int tm_isdst; /* DST. [-1/0/1]*/

#ifdef __USE_BSD
long int tm_gmtoff; /* Seconds east of UTC. */
__const char *tm_zone; /* Timezone abbreviation. */
#else
long int __tm_gmtoff; /* Seconds east of UTC. */
__const char *__tm_zone; /* Timezone abbreviation. */
#endif
};
__END_NAMESPACE_STD
#if defined __USE_XOPEN || defined __USE_POSIX || defined __USE_MISC
__USING_NAMESPACE_STD(tm)
#endif
#ifdef __USE_POSIX199309
/* POSIX.1b structure for timer start values and intervals. */
struct itimerspec
{
struct timespec it_interval;
struct timespec it_value;
};

/* We can use a simple forward declaration. */
struct sigevent;

#endif /* POSIX.1b */

#ifdef __USE_XOPEN2K
# ifndef __pid_t_defined
typedef __pid_t pid_t;
# define __pid_t_defined
# endif
#endif
__BEGIN_NAMESPACE_STD
/* Time used by the program so far (user time + system time).
The result / CLOCKS_PER_SECOND is program time in seconds. */
extern clock_t clock (void) __THROW;

/* Return the current time and put it in *TIMER if TIMER is not NULL. */
extern time_t time (time_t *__timer) __THROW;

/* Return the difference between TIME1 and TIME0. */
extern double difftime (time_t __time1, time_t __time0)
__THROW __attribute__ ((__const__));

/* Return the `time_t' representation of TP and normalize TP. */
extern time_t mktime (struct tm *__tp) __THROW;
/* Format TP into S according to FORMAT.
Write no more than MAXSIZE characters and return the number
of characters written, or 0 if it would exceed MAXSIZE. */
extern size_t strftime (char *__restrict __s, size_t __maxsize,
__const char *__restrict __format,
__const struct tm *__restrict __tp) __THROW;
__END_NAMESPACE_STD

# ifdef __USE_XOPEN
/* Parse S according to FORMAT and store binary time information in TP.
The return value is a pointer to the first unparsed character in S. */
extern char *strptime (__const char *__restrict __s,
__const char *__restrict __fmt, struct tm *__tp)
__THROW;
# endif

# ifdef __USE_GNU
/* Similar to the two functions above but take the information from
the provided locale and not the global locale. */
# include <xlocale.h>

extern size_t strftime_l (char *__restrict __s, size_t __maxsize,
__const char *__restrict __format,
__const struct tm *__restrict __tp,
__locale_t __loc) __THROW;

extern char *strptime_l (__const char *__restrict __s,
__const char *__restrict __fmt, struct tm *__tp,
__locale_t __loc) __THROW;
# endif
__BEGIN_NAMESPACE_STD
/* Return the `struct tm' representation of *TIMER
in Universal Coordinated Time (aka Greenwich Mean Time). */
extern struct tm *gmtime (__const time_t *__timer) __THROW;

/* Return the `struct tm' representation
of *TIMER in the local timezone. */
extern struct tm *localtime (__const time_t *__timer) __THROW;
__END_NAMESPACE_STD

# if defined __USE_POSIX || defined __USE_MISC
/* Return the `struct tm' representation of *TIMER in UTC,
using *TP to store the result. */
extern struct tm *gmtime_r (__const time_t *__restrict __timer,
struct tm *__restrict __tp) __THROW;

/* Return the `struct tm' representation of *TIMER in local time,
using *TP to store the result. */
extern struct tm *localtime_r (__const time_t *__restrict __timer,
struct tm *__restrict __tp) __THROW;
# endif /* POSIX or misc */

__BEGIN_NAMESPACE_STD
/* Return a string of the form "Day Mon dd hh:mm:ss yyyy\n"
that is the representation of TP in this format. */
extern char *asctime (__const struct tm *__tp) __THROW;

/* Equivalent to `asctime (localtime (timer))'. */
extern char *ctime (__const time_t *__timer) __THROW;
__END_NAMESPACE_STD

# if defined __USE_POSIX || defined __USE_MISC
/* Reentrant versions of the above functions. */

/* Return in BUF a string of the form "Day Mon dd hh:mm:ss yyyy\n"
that is the representation of TP in this format. */
extern char *asctime_r (__const struct tm *__restrict __tp,
char *__restrict __buf) __THROW;

/* Equivalent to `asctime_r (localtime_r (timer, *TMP*), buf)'. */
extern char *ctime_r (__const time_t *__restrict __timer,
char *__restrict __buf) __THROW;
# endif /* POSIX or misc */
/* Defined in localtime.c. */
extern char *__tzname[2]; /* Current timezone names. */
extern int __daylight; /* If daylight-saving time is ever in use.
*/
extern long int __timezone; /* Seconds west of UTC. */
# ifdef __USE_POSIX
/* Same as above. */
extern char *tzname[2];

/* Set time conversion information from the TZ environment variable.
If TZ is not defined, a locale-dependent default is used. */
extern void tzset (void) __THROW;
# endif

# if defined __USE_SVID || defined __USE_XOPEN
extern int daylight;
extern long int timezone;
# endif

# ifdef __USE_SVID
/* Set the system time to *WHEN.
This call is restricted to the superuser. */
extern int stime (__const time_t *__when) __THROW;
# endif
/* Nonzero if YEAR is a leap year (every 4 years,
except every 100th isn't, and every 400th is). */
# define __isleap(year) \
((year) % 4 == 0 && ((year) % 100 != 0 || (year) % 400 == 0))
# ifdef __USE_MISC
/* Miscellaneous functions many Unices inherited from the public domain
localtime package. These are included only for compatibility. */

/* Like `mktime', but for TP represents Universal Time, not local time. */
extern time_t timegm (struct tm *__tp) __THROW;

/* Another name for `mktime'. */
extern time_t timelocal (struct tm *__tp) __THROW;

/* Return the number of days in YEAR. */
extern int dysize (int __year) __THROW __attribute__ ((__const__));
# endif
# ifdef __USE_POSIX199309
/* Pause execution for a number of nanoseconds. */
extern int nanosleep (__const struct timespec *__requested_time,
struct timespec *__remaining) __THROW;
/* Get resolution of clock CLOCK_ID. */
extern int clock_getres (clockid_t __clock_id, struct timespec *__res)
__THROW;

/* Get current value of clock CLOCK_ID and store it in TP. */
extern int clock_gettime (clockid_t __clock_id, struct timespec *__tp)
__THROW;

/* Set clock CLOCK_ID to value TP. */
extern int clock_settime (clockid_t __clock_id, __const struct timespec
*__tp)
__THROW;

# ifdef __USE_XOPEN2K
/* High-resolution sleep with the specified clock. */
extern int clock_nanosleep (clockid_t __clock_id, int __flags,
__const struct timespec *__req,
struct timespec *__rem) __THROW;

/* Return clock ID for CPU-time clock. */
extern int clock_getcpuclockid (pid_t __pid, clockid_t *__clock_id) __THROW;
# endif
/* Create new per-process timer using CLOCK_ID. */
extern int timer_create (clockid_t __clock_id,
struct sigevent *__restrict __evp,
timer_t *__restrict __timerid) __THROW;

/* Delete timer TIMERID. */
extern int timer_delete (timer_t __timerid) __THROW;

/* Set timer TIMERID to VALUE, returning old value in OVLAUE. */
extern int timer_settime (timer_t __timerid, int __flags,
__const struct itimerspec *__restrict __value,
struct itimerspec *__restrict __ovalue) __THROW;

/* Get current value of timer TIMERID and store it in VLAUE. */
extern int timer_gettime (timer_t __timerid, struct itimerspec *__value)
__THROW;

/* Get expiration overrun for timer TIMERID. */
extern int timer_getoverrun (timer_t __timerid) __THROW;
# endif
# ifdef __USE_XOPEN_EXTENDED
/* Set to one of the following values to indicate an error.
1 the DATEMSK environment variable is null or undefined,
2 the template file cannot be opened for reading,
3 failed to get file status information,
4 the template file is not a regular file,
5 an error is encountered while reading the template file,
6 memory allication failed (not enough memory available),
7 there is no line in the template that matches the input,
8 invalid input specification Example: February 31 or a time is
specified that can not be represented in a time_t (representing
the time in seconds since 00:00:00 UTC, January 1, 1970) */
extern int getdate_err;

/* Parse the given string as a date specification and return a value
representing the value. The templates from the file identified by
the environment variable DATEMSK are used. In case of an error
`getdate_err' is set. */
extern struct tm *getdate (__const char *__string) __THROW;
# endif

# ifdef __USE_GNU
/* Since `getdate' is not reentrant because of the use of `getdate_err'
and the static buffer to return the result in, we provide a thread-safe
variant. The functionality is the same. The result is returned in
the buffer pointed to by RESBUFP and in case of an error the return
value is != 0 with the same values as given above for `getdate_err'. */
extern int getdate_r (__const char *__restrict __string,
struct tm *__restrict __resbufp) __THROW;
# endif

__END_DECLS

#endif /* <time.h> included. */

#endif /* <time.h> not already included. */
Nov 14 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
[root@jericho utils]# cat fade.c
/* xscreensaver, Copyright (c) 1992-2003 Jamie Zawinski <jw*@jwz.org>
*
* Permission to use, copy, modify, distribute, and sell this software and
its
* documentation for any purpose is hereby granted without fee, provided
that
* the above copyright notice appear in all copies and that both that
* copyright notice and this permission notice appear in supporting
* documentation. No representations are made about the suitability of this
* software for any purpose. It is provided "as is" without express or
* implied warranty.
*/

#include "utils.h"

#include <sys/time.h> /* for gettimeofday() */
#include <time.h>

#ifdef VMS
# include "vms-gtod.h"
#endif /* VMS */

#include "visual.h"
#include "usleep.h"
#include "fade.h"

Colormap
copy_colormap (Screen *screen, Visual *visual,
Colormap cmap, Colormap into_cmap)
{
int i;
Display *dpy = DisplayOfScreen (screen);
Window window = RootWindowOfScreen (screen);
int ncolors = CellsOfScreen (screen);
XColor *colors = 0;

/* If this is a colormap on a mono visual, or one with insanely many
color cells, bug out. */
if (ncolors <= 2 || ncolors > 4096)
return 0;
/* If this is a non-writable visual, bug out. */
if (!has_writable_cells (screen, visual))
return 0;

if (! into_cmap)
into_cmap = XCreateColormap (dpy, window, visual, AllocAll);
if (! cmap)
cmap = DefaultColormapOfScreen (screen);

colors = (XColor *) calloc(sizeof(XColor), ncolors);
for (i = 0; i < ncolors; i++)
colors [i].pixel = i;
XQueryColors (dpy, cmap, colors, ncolors);
XStoreColors (dpy, into_cmap, colors, ncolors);
free (colors);
return into_cmap;
}
void
blacken_colormap (Screen *screen, Colormap cmap)
{
Display *dpy = DisplayOfScreen (screen);
int ncolors = CellsOfScreen (screen);
XColor *colors;
int i;
if (ncolors > 4096)
return;
colors = (XColor *) calloc(sizeof(XColor), ncolors);
for (i = 0; i < ncolors; i++)
colors[i].pixel = i;
XStoreColors (dpy, cmap, colors, ncolors);
free (colors);
}

static void fade_screens_1 (Display *dpy, Colormap *cmaps,
Window *black_windows, int nwindows,
int seconds, int ticks,
Bool out_p, Bool clear_windows);

#ifdef HAVE_SGI_VC_EXTENSION
static int sgi_gamma_fade (Display *dpy,
Window *black_windows, int nwindows,
int seconds, int ticks,
Bool out_p, Bool clear_windows);
#endif /* HAVE_SGI_VC_EXTENSION */

#ifdef HAVE_XF86VMODE_GAMMA
static int xf86_gamma_fade (Display *dpy,
Window *black_windows, int nwindows,
int seconds, int ticks,
Bool out_p, Bool clear_windows);
#endif /* HAVE_XF86VMODE_GAMMA */
void
fade_screens (Display *dpy, Colormap *cmaps,
Window *black_windows, int nwindows,
int seconds, int ticks,
Bool out_p, Bool clear_windows)
{
int oseconds = seconds;
Bool was_in_p = !out_p;

/* When we're asked to fade in, first fade out, then fade in.
That way all the transitions are smooth -- from what's on the
screen, to black, to the desktop.
*/
if (was_in_p)
{
clear_windows = True;
out_p = True;
seconds /= 3;
if (seconds == 0)
seconds = 1;
}

AGAIN:

/* #### printf("\n\nfade_screens %d %d %d\n", seconds, ticks, out_p); */

#ifdef HAVE_SGI_VC_EXTENSION
/* First try to do it by fading the gamma in an SGI-specific way... */
if (0 == sgi_gamma_fade(dpy, black_windows, nwindows,
seconds, ticks, out_p,
clear_windows))
;
else
#endif /* HAVE_SGI_VC_EXTENSION */

#ifdef HAVE_XF86VMODE_GAMMA
/* Then try to do it by fading the gamma in an XFree86-specific way... */
if (0 == xf86_gamma_fade(dpy, black_windows, nwindows,
seconds, ticks, out_p,
clear_windows))
;
else
#endif /* HAVE_XF86VMODE_GAMMA */

/* Else, do it the old-fashioned way, which (somewhat) loses if
there are TrueColor windows visible. */
fade_screens_1 (dpy, cmaps, black_windows, nwindows,
seconds, ticks,
out_p, clear_windows);

/* If we were supposed to be fading in, do so now (we just faded out,
so now fade back in.)
*/
if (was_in_p)
{
was_in_p = False;
out_p = False;
seconds = oseconds * 2 / 3;
if (seconds == 0)
seconds = 1;
goto AGAIN;
}
}
/* 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
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.

I'm told that this trick also works with XInside's AcceleratedX when
using
the Matrox Millennium card (which also allows multiple PseudoColor and
TrueColor visuals to co-exist and display properly at the same time.)

This trick works ok on the 24-bit Indy video hardware, but doesn't work
at
all on the O2 24-bit hardware. I guess the higher-end hardware is too
"good" for this to work (dammit.) So... I figured out the "right" way to
do this on SGIs, which is to ramp the monitor's gamma down to 0. That's
what is implemented in sgi_gamma_fade(), so we use that if we can.
*/
static void
fade_screens_1 (Display *dpy, Colormap *cmaps,
Window *black_windows, int nwindows,
int seconds, int ticks,
Bool out_p, Bool clear_windows)
{
int i, j, k;
int steps = seconds * ticks;
long usecs_per_step = (long)(seconds * 1000000) / (long)steps;
XEvent dummy_event;
int cmaps_per_screen = 5;
int nscreens = ScreenCount(dpy);
int ncmaps = nscreens * cmaps_per_screen;
Colormap *fade_cmaps = 0;
Bool installed = False;
int total_ncolors;
XColor *orig_colors, *current_colors, *screen_colors, *orig_screen_colors;
struct timeval then, now;
#ifdef GETTIMEOFDAY_TWO_ARGS
struct timezone tzp;
#endif

total_ncolors = 0;
for (i = 0; i < nscreens; i++)
total_ncolors += CellsOfScreen (ScreenOfDisplay(dpy, i));

orig_colors = (XColor *) calloc(sizeof(XColor), total_ncolors);
current_colors = (XColor *) calloc(sizeof(XColor), total_ncolors);

/* Get the contents of the colormap we are fading from or to. */
screen_colors = orig_colors;
for (i = 0; i < nscreens; i++)
{
int ncolors = CellsOfScreen (ScreenOfDisplay (dpy, i));
Colormap cmap = (cmaps ? cmaps[i] : 0);
if (!cmap) cmap = DefaultColormap(dpy, i);

for (j = 0; j < ncolors; j++)
screen_colors[j].pixel = j;
XQueryColors (dpy, cmap, screen_colors, ncolors);

screen_colors += ncolors;
}

memcpy (current_colors, orig_colors, total_ncolors * sizeof (XColor));
/* Make the writable colormaps (we keep these around and reuse them.) */
if (!fade_cmaps)
{
fade_cmaps = (Colormap *) calloc(sizeof(Colormap), ncmaps);
for (i = 0; i < nscreens; i++)
{
Visual *v = DefaultVisual(dpy, i);
Screen *s = ScreenOfDisplay(dpy, i);
if (has_writable_cells (s, v))
for (j = 0; j < cmaps_per_screen; j++)
fade_cmaps[(i * cmaps_per_screen) + j] =
XCreateColormap (dpy, RootWindowOfScreen (s), v, AllocAll);
}
}

#ifdef GETTIMEOFDAY_TWO_ARGS
gettimeofday(&then, &tzp);
#else
gettimeofday(&then);
#endif

/* Iterate by steps of the animation... */
for (i = (out_p ? steps : 0);
(out_p ? i > 0 : i < steps);
(out_p ? i-- : i++))
{

/* For each screen, compute the current value of each color...
*/
orig_screen_colors = orig_colors;
screen_colors = current_colors;
for (j = 0; j < nscreens; j++)
{
int ncolors = CellsOfScreen (ScreenOfDisplay (dpy, j));
for (k = 0; k < ncolors; k++)
{
/* This doesn't take into account the relative luminance of
the
RGB components (0.299, 0.587, and 0.114 at gamma 2.2) but
the difference is imperceptible for this application... */
screen_colors[k].red = orig_screen_colors[k].red * i /
steps;
screen_colors[k].green = orig_screen_colors[k].green * i /
steps;
screen_colors[k].blue = orig_screen_colors[k].blue * i /
steps;
}
screen_colors += ncolors;
orig_screen_colors += ncolors;
}

/* Put the colors into the maps...
*/
screen_colors = current_colors;
for (j = 0; j < nscreens; j++)
{
int ncolors = CellsOfScreen (ScreenOfDisplay (dpy, j));
for (k = 0; k < cmaps_per_screen; k++)
{
Colormap c = fade_cmaps[j * cmaps_per_screen + k];
if (c)
XStoreColors (dpy, c, screen_colors, ncolors);
}
screen_colors += ncolors;
}

/* Put the maps on the screens, and then take the windows off the
screen.
(only need to do this the first time through the loop.)
*/
if (!installed)
{
for (j = 0; j < ncmaps; j++)
if (fade_cmaps[j])
XInstallColormap (dpy, fade_cmaps[j]);
installed = True;

if (black_windows && !out_p)
for (j = 0; j < nwindows; j++)
if (black_windows[j])
{
XUnmapWindow (dpy, black_windows[j]);
XClearWindow (dpy, black_windows[j]);
}
}

XSync (dpy, False);

/* If there is user activity, bug out. (Bug out on keypresses or
mouse presses, but not motion, and not release events. Bugging
out on motion made the unfade hack be totally useless, I think.)

We put the event back so that the calling code can notice it too.
It would be better to not remove it at all, but that's harder
because Xlib has such a non-design for this kind of crap, and
in this application it doesn't matter if the events end up out
of order, so in the grand unix tradition we say "fuck it" and
do something that mostly works for the time being.
*/
if (XCheckMaskEvent (dpy, (KeyPressMask|ButtonPressMask),
&dummy_event))
{
XPutBackEvent (dpy, &dummy_event);
goto DONE;
}

#ifdef GETTIMEOFDAY_TWO_ARGS
gettimeofday(&now, &tzp);
#else
gettimeofday(&now);
#endif

/* 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);
}
}

DONE:

if (orig_colors) free (orig_colors);
if (current_colors) free (current_colors);

/* If we've been given windows to raise after blackout, raise them before
releasing the colormaps.
*/
if (out_p && black_windows)
{
for (i = 0; i < nwindows; i++)
{
if (clear_windows)
XClearWindow (dpy, black_windows[i]);
XMapRaised (dpy, black_windows[i]);
}
XSync(dpy, False);
}

/* Now put the target maps back.
If we're fading out, use the given cmap (or the default cmap, if none.)
If we're fading in, always use the default cmap.
*/
for (i = 0; i < nscreens; i++)
{
Colormap cmap = (cmaps ? cmaps[i] : 0);
if (!cmap || !out_p)
cmap = DefaultColormap(dpy, i);
XInstallColormap (dpy, cmap);
}

/* The fade (in or out) is complete, so we don't need the black maps on
stage any more.
*/
for (i = 0; i < ncmaps; i++)
if (fade_cmaps[i])
{
XUninstallColormap(dpy, fade_cmaps[i]);
XFreeColormap(dpy, fade_cmaps[i]);
fade_cmaps[i] = 0;
}
free(fade_cmaps);
fade_cmaps = 0;
}


/* SGI Gamma fading */

#ifdef HAVE_SGI_VC_EXTENSION

# include <X11/extensions/XSGIvc.h>

struct screen_sgi_gamma_info {
int gamma_map; /* ??? always using 0 */
int nred, ngreen, nblue;
unsigned short *red1, *green1, *blue1;
unsigned short *red2, *green2, *blue2;
int gamma_size;
int gamma_precision;
Bool alpha_p;
};
static void sgi_whack_gamma(Display *dpy, int screen,
struct screen_sgi_gamma_info *info, float
ratio);

static int
sgi_gamma_fade (Display *dpy,
Window *black_windows, int nwindows,
int seconds, int ticks,
Bool out_p, Bool clear_windows)
{
int steps = seconds * ticks;
long usecs_per_step = (long)(seconds * 1000000) / (long)steps;
XEvent dummy_event;
int nscreens = ScreenCount(dpy);
struct timeval then, now;
#ifdef GETTIMEOFDAY_TWO_ARGS
struct timezone tzp;
#endif
int i, screen;
int status = -1;
struct screen_sgi_gamma_info *info = (struct screen_sgi_gamma_info *)
calloc(nscreens, sizeof(*info));

/* Get the current gamma maps for all screens.
Bug out and return -1 if we can't get them for some screen.
*/
for (screen = 0; screen < nscreens; screen++)
{
if (!XSGIvcQueryGammaMap(dpy, screen, info[screen].gamma_map,
&info[screen].gamma_size,
&info[screen].gamma_precision,
&info[screen].alpha_p))
goto FAIL;

if (!XSGIvcQueryGammaColors(dpy, screen, info[screen].gamma_map,
XSGIVC_COMPONENT_RED,
&info[screen].nred, &info[screen].red1))
goto FAIL;
if (! XSGIvcQueryGammaColors(dpy, screen, info[screen].gamma_map,
XSGIVC_COMPONENT_GREEN,
&info[screen].ngreen,
&info[screen].green1))
goto FAIL;
if (!XSGIvcQueryGammaColors(dpy, screen, info[screen].gamma_map,
XSGIVC_COMPONENT_BLUE,
&info[screen].nblue, &info[screen].blue1))
goto FAIL;

if (info[screen].gamma_precision == 8) /* Scale it up to 16 bits.
*/
{
int j;
for(j = 0; j < info[screen].nred; j++)
info[screen].red1[j] =
((info[screen].red1[j] << 8) | info[screen].red1[j]);
for(j = 0; j < info[screen].ngreen; j++)
info[screen].green1[j] =
((info[screen].green1[j] << 8) | info[screen].green1[j]);
for(j = 0; j < info[screen].nblue; j++)
info[screen].blue1[j] =
((info[screen].blue1[j] << 8) | info[screen].blue1[j]);
}

info[screen].red2 = (unsigned short *)
malloc(sizeof(*info[screen].red2) * (info[screen].nred+1));
info[screen].green2 = (unsigned short *)
malloc(sizeof(*info[screen].green2) * (info[screen].ngreen+1));
info[screen].blue2 = (unsigned short *)
malloc(sizeof(*info[screen].blue2) * (info[screen].nblue+1));
}

#ifdef GETTIMEOFDAY_TWO_ARGS
gettimeofday(&then, &tzp);
#else
gettimeofday(&then);
#endif

/* If we're fading in (from black), then first crank the gamma all the
way down to 0, then take the windows off the screen.
*/
if (!out_p)
{
for (screen = 0; screen < nscreens; screen++)
sgi_whack_gamma(dpy, screen, &info[screen], 0.0);

for (screen = 0; screen < nwindows; screen++)
if (black_windows && black_windows[screen])
{
XUnmapWindow (dpy, black_windows[screen]);
XClearWindow (dpy, black_windows[screen]);
XSync(dpy, False);
}
}

/* Iterate by steps of the animation... */
for (i = (out_p ? steps : 0);
(out_p ? i > 0 : i < steps);
(out_p ? i-- : i++))
{
for (screen = 0; screen < nscreens; screen++)
{
sgi_whack_gamma(dpy, screen, &info[screen],
(((float)i) / ((float)steps)));

/* If there is user activity, bug out. (Bug out on keypresses or
mouse presses, but not motion, and not release events. Bugging
out on motion made the unfade hack be totally useless, I
think.)

We put the event back so that the calling code can notice it
too.
It would be better to not remove it at all, but that's harder
because Xlib has such a non-design for this kind of crap, and
in this application it doesn't matter if the events end up out
of order, so in the grand unix tradition we say "fuck it" and
do something that mostly works for the time being.
*/
if (XCheckMaskEvent (dpy, (KeyPressMask|ButtonPressMask),
&dummy_event))
{
XPutBackEvent (dpy, &dummy_event);
goto DONE;
}

#ifdef GETTIMEOFDAY_TWO_ARGS
gettimeofday(&now, &tzp);
#else
gettimeofday(&now);
#endif

/* 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);
}
}
}
DONE:

if (out_p && black_windows)
{
for (screen = 0; screen < nwindows; screen++)
{
if (clear_windows)
XClearWindow (dpy, black_windows[screen]);
XMapRaised (dpy, black_windows[screen]);
}
XSync(dpy, False);
}

/* I can't explain this; without this delay, we get a flicker.
I suppose there's some lossage with stale bits being in the
hardware frame buffer or something, and this delay gives it
time to flush out. This sucks! */
usleep(100000); /* 1/10th second */

for (screen = 0; screen < nscreens; screen++)
sgi_whack_gamma(dpy, screen, &info[screen], 1.0);
XSync(dpy, False);

status = 0;

FAIL:
for (screen = 0; screen < nscreens; screen++)
{
if (info[screen].red1) free (info[screen].red1);
if (info[screen].green1) free (info[screen].green1);
if (info[screen].blue1) free (info[screen].blue1);
if (info[screen].red2) free (info[screen].red2);
if (info[screen].green2) free (info[screen].green2);
if (info[screen].blue2) free (info[screen].blue2);
}
free(info);

return status;
}

static void
sgi_whack_gamma(Display *dpy, int screen, struct screen_sgi_gamma_info
*info,
float ratio)
{
int k;

if (ratio < 0) ratio = 0;
if (ratio > 1) ratio = 1;
for (k = 0; k < info->gamma_size; k++)
{
info->red2[k] = info->red1[k] * ratio;
info->green2[k] = info->green1[k] * ratio;
info->blue2[k] = info->blue1[k] * ratio;
}

XSGIvcStoreGammaColors16(dpy, screen, info->gamma_map, info->nred,
XSGIVC_MComponentRed, info->red2);
XSGIvcStoreGammaColors16(dpy, screen, info->gamma_map, info->ngreen,
XSGIVC_MComponentGreen, info->green2);
XSGIvcStoreGammaColors16(dpy, screen, info->gamma_map, info->nblue,
XSGIVC_MComponentBlue, info->blue2);
XSync(dpy, False);
}

#endif /* HAVE_SGI_VC_EXTENSION */


/* XFree86 4.x+ Gamma fading */

#ifdef HAVE_XF86VMODE_GAMMA

#include <X11/extensions/xf86vmode.h>

typedef struct {
XF86VidModeGamma vmg;
int size;
unsigned short *r, *g, *b;
} xf86_gamma_info;

static int xf86_check_gamma_extension (Display *dpy);
static Bool xf86_whack_gamma (Display *dpy, int screen,
xf86_gamma_info *ginfo, float ratio);

static int
xf86_gamma_fade (Display *dpy,
Window *black_windows, int nwindows,
int seconds, int ticks,
Bool out_p, Bool clear_windows)
{
int steps = seconds * ticks;
long usecs_per_step = (long)(seconds * 1000000) / (long)steps;
XEvent dummy_event;
int nscreens = ScreenCount(dpy);
struct timeval then, now;
#ifdef GETTIMEOFDAY_TWO_ARGS
struct timezone tzp;
#endif
int i, screen;
int status = -1;
xf86_gamma_info *info = 0;

static int ext_ok = -1;

/* Only probe the extension once: the answer isn't going to change. */
if (ext_ok == -1)
ext_ok = xf86_check_gamma_extension (dpy);

/* If this server doesn't have the gamma extension, bug out. */
if (ext_ok == 0)
goto FAIL;

# ifndef HAVE_XF86VMODE_GAMMA_RAMP
if (ext_ok == 2) ext_ok = 1; /* server is newer than client! */
# endif

info = (xf86_gamma_info *) calloc(nscreens, sizeof(*info));

/* Get the current gamma maps for all screens.
Bug out and return -1 if we can't get them for some screen.
*/
for (screen = 0; screen < nscreens; screen++)
{
if (ext_ok == 1) /* only have gamma parameter, not ramps. */
{
if (!XF86VidModeGetGamma(dpy, screen, &info[screen].vmg))
goto FAIL;
}
# ifdef HAVE_XF86VMODE_GAMMA_RAMP
else if (ext_ok == 2) /* have ramps */
{
if (!XF86VidModeGetGammaRampSize(dpy, screen, &info[screen].size))
goto FAIL;
if (info[screen].size <= 0)
goto FAIL;

info[screen].r = (unsigned short *)
calloc(info[screen].size, sizeof(unsigned short));
info[screen].g = (unsigned short *)
calloc(info[screen].size, sizeof(unsigned short));
info[screen].b = (unsigned short *)
calloc(info[screen].size, sizeof(unsigned short));

if (!(info[screen].r && info[screen].g && info[screen].b))
goto FAIL;

if (!XF86VidModeGetGammaRamp(dpy, screen, info[screen].size,
info[screen].r,
info[screen].g,
info[screen].b))
goto FAIL;
}
# endif /* HAVE_XF86VMODE_GAMMA_RAMP */
else
abort();
}

#ifdef GETTIMEOFDAY_TWO_ARGS
gettimeofday(&then, &tzp);
#else
gettimeofday(&then);
#endif

/* If we're fading in (from black), then first crank the gamma all the
way down to 0, then take the windows off the screen.
*/
if (!out_p)
{
for (screen = 0; screen < nscreens; screen++)
xf86_whack_gamma(dpy, screen, &info[screen], 0.0);
for (screen = 0; screen < nwindows; screen++)
if (black_windows && black_windows[screen])
{
XUnmapWindow (dpy, black_windows[screen]);
XClearWindow (dpy, black_windows[screen]);
XSync(dpy, False);
}
}

/* Iterate by steps of the animation... */
for (i = (out_p ? steps : 0);
(out_p ? i > 0 : i < steps);
(out_p ? i-- : i++))
{
for (screen = 0; screen < nscreens; screen++)
{
xf86_whack_gamma(dpy, screen, &info[screen],
(((float)i) / ((float)steps)));

/* If there is user activity, bug out. (Bug out on keypresses or
mouse presses, but not motion, and not release events. Bugging
out on motion made the unfade hack be totally useless, I
think.)

We put the event back so that the calling code can notice it
too.
It would be better to not remove it at all, but that's harder
because Xlib has such a non-design for this kind of crap, and
in this application it doesn't matter if the events end up out
of order, so in the grand unix tradition we say "fuck it" and
do something that mostly works for the time being.
*/
if (XCheckMaskEvent (dpy, (KeyPressMask|ButtonPressMask),
&dummy_event))
{
XPutBackEvent (dpy, &dummy_event);
goto DONE;
}

#ifdef GETTIMEOFDAY_TWO_ARGS
gettimeofday(&now, &tzp);
#else
gettimeofday(&now);
#endif

/* 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);
}
}
}
DONE:

if (out_p && black_windows)
{
for (screen = 0; screen < nwindows; screen++)
{
if (clear_windows)
XClearWindow (dpy, black_windows[screen]);
XMapRaised (dpy, black_windows[screen]);
}
XSync(dpy, False);
}

/* I can't explain this; without this delay, we get a flicker.
I suppose there's some lossage with stale bits being in the
hardware frame buffer or something, and this delay gives it
time to flush out. This sucks! */
usleep(100000); /* 1/10th second */

for (screen = 0; screen < nscreens; screen++)
xf86_whack_gamma(dpy, screen, &info[screen], 1.0);
XSync(dpy, False);

status = 0;

FAIL:
if (info)
{
for (screen = 0; screen < nscreens; screen++)
{
if (info[screen].r) free(info[screen].r);
if (info[screen].g) free(info[screen].g);
if (info[screen].b) free(info[screen].b);
}
free(info);
}

return status;
}
/* This bullshit is needed because the VidMode extension doesn't work
on remote displays -- but if the remote display has the extension
at all, XF86VidModeQueryExtension returns true, and then
XF86VidModeQueryVersion dies with an X error. Thank you XFree,
may I have another.
*/

static Bool error_handler_hit_p = False;

static int
ignore_all_errors_ehandler (Display *dpy, XErrorEvent *error)
{
error_handler_hit_p = True;
return 0;
}

static Bool
safe_XF86VidModeQueryVersion (Display *dpy, int *majP, int *minP)
{
Bool result;
XErrorHandler old_handler;
XSync (dpy, False);
error_handler_hit_p = False;
old_handler = XSetErrorHandler (ignore_all_errors_ehandler);

result = XF86VidModeQueryVersion (dpy, majP, minP);

XSync (dpy, False);
XSetErrorHandler (old_handler);
XSync (dpy, False);

return (error_handler_hit_p
? False
: result);
}

/* VidModeExtension version 2.0 or better is needed to do gamma.
2.0 added gamma values; 2.1 added gamma ramps.
*/
# define XF86_VIDMODE_GAMMA_MIN_MAJOR 2
# define XF86_VIDMODE_GAMMA_MIN_MINOR 0
# define XF86_VIDMODE_GAMMA_RAMP_MIN_MAJOR 2
# define XF86_VIDMODE_GAMMA_RAMP_MIN_MINOR 1

/* Returns 0 if gamma fading not available; 1 if only gamma value setting
is available; 2 if gamma ramps are available.
*/
static int
xf86_check_gamma_extension (Display *dpy)
{
int event, error, major, minor;

if (!XF86VidModeQueryExtension (dpy, &event, &error))
return 0; /* display doesn't have the extension. */

if (!safe_XF86VidModeQueryVersion (dpy, &major, &minor))
return 0; /* unable to get version number? */

if (major < XF86_VIDMODE_GAMMA_MIN_MAJOR ||
(major == XF86_VIDMODE_GAMMA_MIN_MAJOR &&
minor < XF86_VIDMODE_GAMMA_MIN_MINOR))
return 0; /* extension is too old for gamma. */

if (major < XF86_VIDMODE_GAMMA_RAMP_MIN_MAJOR ||
(major == XF86_VIDMODE_GAMMA_RAMP_MIN_MAJOR &&
minor < XF86_VIDMODE_GAMMA_RAMP_MIN_MINOR))
return 1; /* extension is too old for gamma ramps. */

/* Copacetic */
return 2;
}
/* XFree doesn't let you set gamma to a value smaller than this.
Apparently they didn't anticipate the trick I'm doing here...
*/
#define XF86_MIN_GAMMA 0.1
static Bool
xf86_whack_gamma(Display *dpy, int screen, xf86_gamma_info *info,
float ratio)
{
Bool status;

if (ratio < 0) ratio = 0;
if (ratio > 1) ratio = 1;

if (info->size == 0) /* we only have a gamma number, not a ramp. */
{
XF86VidModeGamma g2;

g2.red = info->vmg.red * ratio;
g2.green = info->vmg.green * ratio;
g2.blue = info->vmg.blue * ratio;

# ifdef XF86_MIN_GAMMA
if (g2.red < XF86_MIN_GAMMA) g2.red = XF86_MIN_GAMMA;
if (g2.green < XF86_MIN_GAMMA) g2.green = XF86_MIN_GAMMA;
if (g2.blue < XF86_MIN_GAMMA) g2.blue = XF86_MIN_GAMMA;
# endif

status = XF86VidModeSetGamma (dpy, screen, &g2);
}
else
{
# ifdef HAVE_XF86VMODE_GAMMA_RAMP

unsigned short *r, *g, *b;
int i;
r = (unsigned short *) malloc(info->size * sizeof(unsigned short));
g = (unsigned short *) malloc(info->size * sizeof(unsigned short));
b = (unsigned short *) malloc(info->size * sizeof(unsigned short));

for (i = 0; i < info->size; i++)
{
r[i] = info->r[i] * ratio;
g[i] = info->g[i] * ratio;
b[i] = info->b[i] * ratio;
}

status = XF86VidModeSetGammaRamp(dpy, screen, info->size, r, g, b);

free (r);
free (g);
free (b);

# else /* !HAVE_XF86VMODE_GAMMA_RAMP */
abort();
# endif /* !HAVE_XF86VMODE_GAMMA_RAMP */
}

XSync(dpy, False);
return status;
}

#endif /* HAVE_XF86VMODE_GAMMA */
Nov 14 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.