v02i049: a colorful kaleidoscopic display, version 2, Part01/01

Mike Wexler mikew at wyse.wyse.com
Fri Dec 23 03:24:20 AEST 1988


Submitted-by: natham at hp-pcs.hp.com (Nathan Meyers)
Posting-number: Volume 2, Issue 49
Archive-name: kaleid2/part01

#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of archive 1 (of 1)."
# Contents:  README AUTHOR Makefile kaleid.1 kaleid.c kalicon.h
#   patchlevel.h
# Wrapped by mikew at wyse on Thu Dec 22 09:21:51 1988
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'README' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'README'\"
else
echo shar: Extracting \"'README'\" \(501 characters\)
sed "s/^X//" >'README' <<'END_OF_FILE'
XKaleid produces a colorful kaleidoscope display in an X11 window -- it
Xwas ported from an MS-DOS program written for the EGA/VGA display.
X
XFor connoisseurs of window managers, this program does two interesting
Xthings: 1) it creates and maintains a window icon, and 2) it observes
Xwindow manager sizing hints for its window icon.
X
XTo make on bsd systems:
X
X	make
X
XTo make on systems of SYSV descent (such as hp-ux):
X
X	make SYSV
X
X---------------------
XNathan Meyers
XHewlett-Packard
Xnathanm at hp-pcd.hp.com
END_OF_FILE
if test 501 -ne `wc -c <'README'`; then
    echo shar: \"'README'\" unpacked with wrong size!
fi
# end of 'README'
fi
if test -f 'AUTHOR' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'AUTHOR'\"
else
echo shar: Extracting \"'AUTHOR'\" \(369 characters\)
sed "s/^X//" >'AUTHOR' <<'END_OF_FILE'
XThis X11 implementation is based on a public-domain kaleidoscope program
Xby Judson D. McClendon of Sun Valley Systems (Birmingham, AL).
XPermission granted to author to port to X11 and publish.
X
XX11 kaleid program by Nathan Meyers of Hewlett-Packard (internet mail
Xaddress nathanm at hp-pcd.hp.com).  Permission granted to freely copy and
Xdistribute on a non-profit basis.
END_OF_FILE
if test 369 -ne `wc -c <'AUTHOR'`; then
    echo shar: \"'AUTHOR'\" unpacked with wrong size!
fi
# end of 'AUTHOR'
fi
if test -f 'Makefile' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'Makefile'\"
else
echo shar: Extracting \"'Makefile'\" \(214 characters\)
sed "s/^X//" >'Makefile' <<'END_OF_FILE'
XCFLAGS=-O -I/global/include
XLDFLAGS=-L/global/lib
X
Xkaleid:	kaleid.o
X	cc kaleid.o $(CFLAGS) $(LDFLAGS) -o kaleid -lX11
X
Xkaleid.o:	kaleid.c kalicon.h
X	cc -c $(CFLAGS) kaleid.c
X
XSYSV:
X	@make "CFLAGS=$(CFLAGS) -DSYSV"
END_OF_FILE
if test 214 -ne `wc -c <'Makefile'`; then
    echo shar: \"'Makefile'\" unpacked with wrong size!
fi
# end of 'Makefile'
fi
if test -f 'kaleid.1' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'kaleid.1'\"
else
echo shar: Extracting \"'kaleid.1'\" \(4591 characters\)
sed "s/^X//" >'kaleid.1' <<'END_OF_FILE'
X.TH KALEID 1
X.PD
X.ad b
X.SH NAME
Xkaleid \- X11 Kaleidoscope Display
X.SH SYNOPSIS
X.TP \w'\fBkaleid\fR 'u
X\fBkaleid\fR
X[\|\fB-display\fR displayname\|] [\|\fB-bg\fR background\|]
X[\|\fB-bd\fR border\|] [\|\fB-bw\fR borderwidth\|]
X[\|\fB-geometry\fR geometry\|] [\|\fB-delay\fR msec\|]
X[\|\fB-icondelay\fR msec\|] [\|\fB-iconic\fR\|] [\|\fB-mono\fR\|]
X[\|\fB-mult\fR number\|] [\|\fB-r\fR\|] [\|\fB-randomcolor\fR\|]
X.SH HP-UX COMPATIBILITY
X.TP 10
XOrigin:
XUser Contributed
X.SH DESCRIPTION
X.I Kaleid
Xis an X11 port of Judson McClendon's EGA/VGA Kaleidoscope program from
Xthe PC community.  \fIKaleid\fR runs a colorful kaleidoscope display in
Xan X11 window.  The 16-color palette is chosen to approximate the
Xdefault palette found on EGA and VGA displays.
X.PP
XWith window managers that support icon windows (such as \fIuwm\fR), the
X\fIkaleid\fR icon is a small kaleidoscope window that runs a slow
Xkaleidoscope display (see \fB-icondelay\fR option, below).
X.PP
XOptions:
X.TP .5i
X.B -display
XSpecify display on which to run; defaults to contents of DISPLAY
Xenvironment variable.
X.TP
X.B -bg
XSpecify background color; defaults to black.
X.TP
X.B -bd
XSpecify border color; defaults to white.
X.TP
X.B -bw
XSpecify border width in pixels; defaults to 2.
X.TP
X.B -geometry
XSpecify window geometry; defaults to =300x300+0+0.
X.TP
X.B -delay
XSpecify a delay (in msec) to be performed between drawing each set of
Xlines \(em can be used to avoid swamping the X11 server.  Defaults to 10
X(100 when \fB-r\fR option, below, is used).
X.TP
X.B -icondelay
XSpecify the delay to be used when drawing to the \fIkaleid\fR icon.
XDefaults to 100 msec.
X.TP
X.B -iconic
XCause \fIkaleid\fR to come up in the iconic state.
X.TP
X.B -mono
XForce \fIkaleid\fR to run in monochrome mode (default behavior on
Xa monochrome display).
X.TP
X.B -mult
XRun specified number of \fIkaleid\fR windows.  Each window is a
Xtop-level window with an associated icon.  See the note on WINDOW
XMANAGER INTERACTIONS (below) for details on where the multiple windows
Xget mapped.
X.TP
X.B -r
XRun \fIkaleid\fR in the root window.  This option causes \fIkaleid\fR
Xto ignore all options irrelevant to running in the root window.
X.TP
X.B -randomcolor
XInstead of the standard palette, use a randomly-generated palette that
Xis randomly changed at times during \fIkaleid\fR's execution.  This
Xoption causes kaleid to allocate read/write color cells instead of
Xread-only color cells, and will not work on a display whose default
Xvisual type is StaticColor, StaticGray, or TrueColor.
X.SH NOTE
XSpecifying a delay (icondelay) value of 0 will cause kaleid to draw into
Xits window (icon) at top speed, bogging down your server and, if
X\fIkaleid\fR is run remotely, your network.  The default delay value
Xwas chosen to work well on a fast CPU with a fast X server -- it is
Xprobably too low for many systems.
X.PP
XIf \fIkaleid\fR and the server are running on the same CPU, running
X\fIkaleid\fR with a higher nice (nice(1)) value will usually produce
Xgood results without 1) swamping the server, and 2) requiring you to
Ximpose an unpleasantly long delay.
X.SH AUTHORSHIP
XThere have been many different kaleidoscope programs for many different
Xflavors of computers and PCs over the years.  This program was modified
Xfrom the public-domain kaleidoscope program for IBM PCs by Judson D.
XMcClendon (Sun Valley Systems, 329 37th Court N.E., Birmingham, AL,
X35215, CompuServe address [74415,1003]).  The port to X11 was performed
Xby Nathan Meyers of Hewlett-Packard (nathanm at hp-pcd.hp.com).
X.SH WINDOW MANAGER INTERACTIONS
XSome window managers do not appear to cope very well with window icons,
Xresulting in strange icon behavior.  \fIUwm\fR does not suffer from this
Xproblem, although problems can occur when changing window managers (to
Xor from \fIuwm\fR) during execution of \fIkaleid\fR.
X.PP
XOn window managers that support window icons and that specify icon
Xsizing hints, \fIkaleid\fR will respect the icon sizing hints, creating
Xthe largest permissible icon.  Without icon sizing hints, the default
Xicon size is 64x64.
X.PP
X\fIKaleid\fR maps all of its top-level windows to =+0+0 unless
Xoverridden by a geometry string, and all of its icon windows to =+0+0.
XWhere the windows and icons actually \fIend up\fR is a function of how
Xyour window manager handles placement of windows and icons.  \fIUwm\fR,
Xfor example, will request manual window placement for each top-level
Xwindow if a geometry string is not specified, but will leave all icons
Xmapped at =+0+0.  Conversely, with window managers that maintain
Xgalleries or grids of icons, multiple \fIkaleid\fR icons can be
Xspectacular.
END_OF_FILE
if test 4591 -ne `wc -c <'kaleid.1'`; then
    echo shar: \"'kaleid.1'\" unpacked with wrong size!
fi
# end of 'kaleid.1'
fi
if test -f 'kaleid.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'kaleid.c'\"
else
echo shar: Extracting \"'kaleid.c'\" \(20946 characters\)
sed "s/^X//" >'kaleid.c' <<'END_OF_FILE'
X#include <stdio.h>
X#include <X11/X.h>
X#include <X11/Xlib.h>
X#include <X11/Xutil.h>
X#include <X11/Xos.h>
X#include <signal.h>
X#include "kalicon.h"
X
X/*
X  KALEIDOSCOPE (X11 Version)
X
X  Original EGA/VGA version (for IBM PCs and compatibles) by:
X    Judson D. McClendon
X    Sun Valley Systems
X    329 37th Court N.E.
X    Birmingham, AL 35215
X    Compuserve: [74415,1003]
X
X  Ported to X11 by Nathan Meyers, nathanm at hp-pcd.hp.com.
X*/
X
Xchar *progname;
X
X
X/* Approximation of CGA/EGA/VGA colors -- (out of standard order) */
Xunsigned long colors[][3] = { { 0x0000, 0x0000, 0x0000 },    /* black */
X			      { 0xffff, 0xffff, 0xffff },    /* bright white */
X			      { 0x0000, 0x0000, 0xaaaa },    /* blue */
X			      { 0x0000, 0xaaaa, 0x0000 },    /* green */
X			      { 0x0000, 0xaaaa, 0xaaaa },    /* cyan */
X			      { 0xaaaa, 0x0000, 0x0000 },    /* red */
X			      { 0xaaaa, 0x0000, 0xaaaa },    /* magenta */
X			      { 0xaaaa, 0x5555, 0x0000 },    /* brown */
X			      { 0xaaaa, 0xaaaa, 0xaaaa },    /* white  */
X			      { 0x5555, 0x5555, 0x5555 },    /* dark grey */
X			      { 0x5555, 0x5555, 0xffff },    /* light blue */
X			      { 0x5555, 0xffff, 0x5555 },    /* light green */
X			      { 0x5555, 0xffff, 0xffff },    /* light cyan */
X			      { 0xffff, 0x5555, 0x5555 },    /* light red */
X			      { 0xffff, 0x5555, 0xffff },    /* light magenta */
X			      { 0xffff, 0xffff, 0x5555 } };  /* yellow */
X
X#define NCOLORS 16
X
Xstatic char *what = "@(#)kaleid.c $Revision: 1.60 $";
X
XDisplay *display;
Xint screen;
X
Xvoid refreshrootquit()
X{
X  XClearWindow(display,RootWindow(display,screen));
X  XSync(display,0);
X  exit(0);
X}
X
Xint nwindows=1, nvisible=0;
Xint *visible;
XWindow *window;
Xint *CX, *CY, *M;
Xint *X1, *Y1, *X2, *Y2, *XV1, *YV1, *XV2, *YV2, *HC;
Xint *XA, *YA, *XB, *YB, *XC, *YC, *XD, *YD;
Xstruct timeval *schedule, *intervals;
Xint numcolors;
Xint dynamic_colors=0;
Xunsigned long palette[NCOLORS];
Xlong rndm();
X
Xmain(argc,argv)
Xint argc;
Xchar *argv[];
X{
X  unsigned long bgcolor, bdcolor;
X  int bwidth = 2;
X  int i;
X  XSizeHints size_hints;
X  XIconSize icon_size_hints, *icon_size_list;
X  int numsizes, currsize;
X  XWMHints wm_hints;
X  char *displayname = NULL, *background = NULL, *border = NULL;
X  char *geomstring = NULL;
X  GC color_gcs[NCOLORS];
X  XColor screen_in_out, visual_def_return, exact_def_return;
X  int o_argc = argc;
X  char **o_argv = argv;
X  XEvent event;
X  long time();
X  int doroot = 0;
X  int delayvalue = -1, icondelay=100;
X  int iconic=0;
X  int monochrome=0;
X  char *basename, *strrchr();
X
X  progname = argv[0];
X
X  if ((basename=strrchr(progname,'/'))!=NULL) basename++;
X  else basename=progname;
X
X  while (--argc>0) {
X    char *option = (*++argv);
X    if (!strcmp(option,"-display")) {
X      if (--argc==0) usage();
X      displayname = (*++argv);
X    }
X    else if (strchr(option,':')) {
X      displayname = option;
X    }
X    else if (!strcmp(option,"-bg")) {
X      if (--argc==0) usage();
X      background = (*++argv);
X    }
X    else if (!strcmp(option,"-bd")) {
X      if (--argc==0) usage();
X      border = (*++argv);
X    }
X    else if (!strcmp(option,"-bw")) {
X      if (--argc==0) usage();
X      bwidth = atoi(*++argv);
X      if (bwidth<0) bwidth = 0;
X    }
X    else if (!strcmp(option,"-delay")) {
X      if (--argc==0) usage();
X      delayvalue = atoi(*++argv);
X      if (delayvalue<0) delayvalue = 0;
X    }
X    else if (!strcmp(option,"-icondelay")) {
X      if (--argc==0) usage();
X      icondelay = atoi(*++argv);
X      if (icondelay<0) icondelay = 0;
X    }
X    else if (!strcmp(option,"-iconic")) {
X      iconic = 1;
X    }
X    else if (!strcmp(option,"-geometry")) {
X      if (--argc==0) usage();
X      geomstring = (*++argv);
X    }
X    else if (*option=='=') {
X      geomstring = option;
X    }
X    else if (!strcmp(option,"-mono")) {
X      monochrome=1;
X    }
X    else if (!strcmp(option,"-mult")) {
X      if (--argc==0) usage();
X      nwindows = atoi(*++argv);
X      if (nwindows<1) nwindows = 1;
X    }
X    else if (!strcmp(option,"-r")) {
X      doroot = 1;
X    }
X    else if (!strcmp(option,"-root")) {
X      doroot = 1;
X    }
X    else if (!strcmp(option,"-randomcolor")) {
X      dynamic_colors = 1;
X    }
X    else usage();
X  }
X
X  if (delayvalue == -1) delayvalue = doroot ? 100 : 10;
X
X  display = XOpenDisplay(displayname);
X  if (display==NULL) {
X    (void)fprintf(stderr,
X	          (displayname==NULL) ?
X	          "%s: Failed to open display.\n" :
X	          "%s: Failed to open display %s.\n",
X	          progname,displayname);
X    exit(1);
X  }
X  screen = DefaultScreen(display);
X
X  if (background == NULL ||
X      XAllocNamedColor(display,
X		       DefaultColormap(display,screen),
X		       background,
X		       &visual_def_return,
X		       &exact_def_return)==False)
X    bgcolor = BlackPixel(display,screen);
X  else bgcolor = exact_def_return.pixel;
X
X  if (border==NULL ||
X      XAllocNamedColor(display,
X		       DefaultColormap(display,screen),
X		       border,
X		       &visual_def_return,
X		       &exact_def_return)==False)
X   bdcolor = WhitePixel(display,screen);
X  else bdcolor = exact_def_return.pixel;
X
X  if (!monochrome && DisplayCells(display,screen) > 2) {
X    if (dynamic_colors) {
X      for (numcolors=NCOLORS; numcolors>=2; numcolors--) {
X	if (XAllocColorCells(display,DefaultColormap(display,screen),
X			     0, (unsigned long *)NULL, 0,
X			     palette, (unsigned int)numcolors) == True) {
X	  randomize_colors();
X	  break;
X	}
X      }
X      if (numcolors < 2) fatalerror("Cannot allocate R/W color cells",NULL);
X    }
X    else {
X      for (numcolors=0; numcolors<NCOLORS; numcolors++) {
X        screen_in_out.flags = DoRed | DoGreen | DoBlue;
X        screen_in_out.red = colors[numcolors][0];
X        screen_in_out.green = colors[numcolors][1];
X        screen_in_out.blue = colors[numcolors][2];
X        if (XAllocColor(display, DefaultColormap(display,screen),
X		        &screen_in_out)==False) {
X	  if (numcolors < 2) fatalerror("Cannot allocate colors",NULL);
X	  break;
X        }
X        palette[numcolors] = screen_in_out.pixel;
X      }
X    }
X  }
X  else {
X    numcolors=2;
X    palette[0] = WhitePixel(display,screen);
X    palette[1] = BlackPixel(display,screen);
X  }
X
X  size_hints.x = 0;
X  size_hints.y = 0;
X  size_hints.width = 300;
X  size_hints.height = 300;
X
X  size_hints.flags = PPosition | PSize;
X  if (geomstring!=NULL) {
X    int result;
X    result = XParseGeometry(geomstring,&size_hints.x,&size_hints.y,
X		            &size_hints.width,&size_hints.height);
X    if (result & XNegative)
X      size_hints.x += DisplayWidth(display,screen)
X		    - size_hints.width
X		    - bwidth*2;
X    if (result & YNegative)
X      size_hints.y += DisplayHeight(display,screen)
X		    - size_hints.height
X		    - bwidth*2;
X    if (result & XValue || result & YValue) {
X      size_hints.flags |= USPosition;
X      size_hints.flags &= ~PPosition;
X    }
X    if (result & WidthValue || result & HeightValue) {
X      size_hints.flags |= USSize;
X      size_hints.flags &= ~PSize;
X    }
X  }
X
X  if (doroot) {
X    char *calloc();
X    if (!allocate_arrays(1)) {
X      (void)fprintf(stderr,"%s: malloc() failure\n",progname);
X      exit(1);
X    }
X    intervals[0].tv_sec = delayvalue/1000;
X    intervals[0].tv_usec = (delayvalue % 1000) * 1000;
X    window[0] = RootWindow(display,screen);
X  }
X  else {
X    Pixmap bitmapicon;
X    char *calloc();
X
X    if (!allocate_arrays((unsigned)(2*nwindows))) {
X      (void)fprintf(stderr,"%s: malloc() failure\n",progname);
X      exit(1);
X    }
X
X    for (i=0; i<nwindows; i++)
X      window[i] = XCreateSimpleWindow(display,RootWindow(display,screen),
X				        size_hints.x,size_hints.y,
X				        size_hints.width,size_hints.height,
X				        bwidth,bdcolor,bgcolor);
X
X    icon_size_hints.max_width=64;
X    icon_size_hints.max_height=64;
X    currsize=0;
X    if (XGetIconSizes(display,RootWindow(display,screen),
X		      &icon_size_list,&numsizes)) {
X      for (i=1; i<numsizes; i++) {	/* Look for largest icon size */
X	if (icon_size_list[i].max_width >= icon_size_list[currsize].max_width &&
X	    icon_size_list[i].max_height >= icon_size_list[currsize].max_height)
X	  currsize=i;
X      }
X      if (icon_size_list[currsize].max_width <= 0 ||
X	  icon_size_list[currsize].max_height <= 0 ) {
X	XFree(icon_size_list);
X        icon_size_list = &icon_size_hints;
X      }
X    }
X    else
X      icon_size_list = &icon_size_hints;
X
X    for (i=0; i<nwindows; i++) {
X      window[i+nwindows] = XCreateSimpleWindow(display,
X					  RootWindow(display,screen), 0,0,
X				          icon_size_list[currsize].max_width,
X				          icon_size_list[currsize].max_height,
X				          2,BlackPixel(display,screen),
X				          WhitePixel(display,screen));
X
X      CX[i+nwindows] = icon_size_list[currsize].max_width >> 1;
X      CY[i+nwindows] = icon_size_list[currsize].max_height >> 1;
X      M[i+nwindows] = (CX[i+nwindows]>CY[i+nwindows]) ?
X			 CX[i+nwindows] :
X			 CY[i+nwindows];
X      M[i+nwindows] = M[i+nwindows] ? M[i+nwindows] : 1;
X    }
X
X    if (icon_size_list != &icon_size_hints) XFree(icon_size_list);
X
X    for (i=0; i<nwindows; i++)
X      XSetStandardProperties(display,window[i],"Kaleidoscope",basename,
X			     None,o_argv,o_argc,&size_hints);
X
X    /* Create bitmap icon for wm's that don't support window icons */
X    bitmapicon=XCreateBitmapFromData(display,RootWindow(display,screen),
X				     icon_bits, icon_width, icon_height);
X
X    /* Use window icon for window managers that support one */
X    wm_hints.icon_pixmap = bitmapicon;
X    wm_hints.flags = IconPixmapHint | IconWindowHint;
X
X    if (iconic) {
X      wm_hints.initial_state = IconicState;
X      wm_hints.flags |= StateHint;
X    }
X
X    for (i=0; i<nwindows; i++) {
X      wm_hints.icon_window = window[i+nwindows];
X      XSetWMHints(display,window[i],&wm_hints);
X      XSelectInput(display,window[i],
X	StructureNotifyMask|VisibilityChangeMask);
X      XSelectInput(display,window[i+nwindows],
X	StructureNotifyMask|VisibilityChangeMask);
X      XMapWindow(display,window[i]);
X
X      intervals[i].tv_sec = delayvalue/1000;
X      intervals[i].tv_usec = (delayvalue % 1000) * 1000;
X      intervals[i+nwindows].tv_sec = icondelay/1000;
X      intervals[i+nwindows].tv_usec = (icondelay % 1000) * 1000;
X
X      CX[i] = size_hints.width/2;
X      CY[i] = size_hints.height/2;
X      M[i] = (CX[i]>CY[i]) ? CX[i] : CY[i];
X      M[i] = M[i] ? M[i] : 1;
X    }
X
X  }
X
X  for (i = 0; i<numcolors; i++) {
X    XGCValues values;
X    values.foreground = palette[i];
X    color_gcs[i] = XCreateGC(display,window[0],GCForeground,&values);
X  }
X
X  nwindows <<= 1;
X  if (doroot) {
X    nwindows=1;
X    nvisible=1;
X    visible[0]=1;
X  }
X
X  srand48(time((long *)NULL));
X
X  for (;;) {
X    int winno;
X    for (winno=0; winno<nwindows; winno++) if (visible[winno]) break;
X    if (doroot) {
X      int dontcare;
X      Window wdontcare;
X      struct sigvec vec;
X      XGetGeometry(display,RootWindow(display,screen),&wdontcare,&dontcare,
X		   &dontcare, &CX[0], &CY[0], &dontcare, &dontcare);
X      CX[0] >>= 1;
X      CY[0] >>= 1;
X      M[0] = (CX[0]>CY[0]) ? CX[0] : CY[0];
X      M[0] = M[0] ? M[0] : 1;
X      vec.sv_handler = refreshrootquit;
X      vec.sv_mask = 0x0;
X      vec.sv_flags = 0;
X      (void)sigvec(SIGINT, &vec, (struct sigvec *)NULL);
X      (void)sigvec(SIGQUIT, &vec, (struct sigvec *)NULL);
X      (void)sigvec(SIGTERM, &vec, (struct sigvec *)NULL);
X    }
X    while (nvisible) {
X      if (!rndm(50L)) {
X        X1[winno] = rndm((long)M[winno]) + 1;
X        X2[winno] = rndm((long)M[winno]) + 1;
X        Y1[winno] = rndm((long)X1[winno]);
X        Y2[winno] = rndm((long)X2[winno]);
X      }
X      if (!rndm(10L)) {
X        XV1[winno] = rndm(7L)-3;
X        XV2[winno] = rndm(7L)-3;
X        YV1[winno] = rndm(7L)-3;
X        YV2[winno] = rndm(7L)-3;
X        HC[winno] = rndm((long)numcolors);
X      }
X      if (CX[winno]<CY[winno]) {
X        XA[winno] = (long)X1[winno]*(long)CX[winno]/(long)CY[winno];
X        YA[winno] = (long)Y1[winno]*(long)CX[winno]/(long)CY[winno];
X        XB[winno] = X1[winno];
X        YB[winno] = Y1[winno];
X        XC[winno] = (long)X2[winno]*(long)CX[winno]/(long)CY[winno];
X        YC[winno] = (long)Y2[winno]*(long)CX[winno]/(long)CY[winno];
X        XD[winno] = X2[winno];
X        YD[winno] = Y2[winno];
X      }
X      else {
X        XA[winno] = X1[winno];
X        YA[winno] = Y1[winno];
X        XB[winno] = (long)X1[winno]*(long)CY[winno]/(long)CX[winno];
X        YB[winno] = (long)Y1[winno]*(long)CY[winno]/(long)CX[winno];
X        XC[winno] = X2[winno];
X        YC[winno] = Y2[winno];
X        XD[winno] = (long)X2[winno]*(long)CY[winno]/(long)CX[winno];
X        YD[winno] = (long)Y2[winno]*(long)CY[winno]/(long)CX[winno];
X      }
X      XDrawLine(display,window[winno],color_gcs[HC[winno]],
X                CX[winno]+XA[winno],
X                CY[winno]-YB[winno],
X                CX[winno]+XC[winno],
X                CY[winno]-YD[winno]);
X      XDrawLine(display,window[winno],color_gcs[HC[winno]],
X                CX[winno]-YA[winno],
X                CY[winno]+XB[winno],
X                CX[winno]-YC[winno],
X                CY[winno]+XD[winno]);
X      XDrawLine(display,window[winno],color_gcs[HC[winno]],
X                CX[winno]-XA[winno],
X                CY[winno]-YB[winno],
X                CX[winno]-XC[winno],
X                CY[winno]-YD[winno]);
X      XDrawLine(display,window[winno],color_gcs[HC[winno]],
X                CX[winno]-YA[winno],
X                CY[winno]-XB[winno],
X                CX[winno]-YC[winno],
X                CY[winno]-XD[winno]);
X      XDrawLine(display,window[winno],color_gcs[HC[winno]],
X                CX[winno]-XA[winno],
X                CY[winno]+YB[winno],
X                CX[winno]-XC[winno],
X                CY[winno]+YD[winno]);
X      XDrawLine(display,window[winno],color_gcs[HC[winno]],
X                CX[winno]+YA[winno],
X                CY[winno]-XB[winno],
X                CX[winno]+YC[winno],
X                CY[winno]-XD[winno]);
X      XDrawLine(display,window[winno],color_gcs[HC[winno]],
X                CX[winno]+XA[winno],
X                CY[winno]+YB[winno],
X                CX[winno]+XC[winno],
X                CY[winno]+YD[winno]);
X      XDrawLine(display,window[winno],color_gcs[HC[winno]],
X                CX[winno]+YA[winno],
X                CY[winno]+XB[winno],
X                CX[winno]+YC[winno],
X                CY[winno]+XD[winno]);
X      XFlush(display);
X      X1[winno]= (X1[winno] + XV1[winno]) % M[winno];
X      Y1[winno]= (Y1[winno] + YV1[winno]) % M[winno];
X      X2[winno]= (X2[winno] + XV2[winno]) % M[winno];
X      Y2[winno]= (Y2[winno] + YV2[winno]) % M[winno];
X      if (!rndm(500L)) XClearWindow(display,window[winno]);
X      if (dynamic_colors && !rndm((long)(800/numcolors))) randomize_color();
X      winno=scheduler();
X      if (XCheckMaskEvent(display,~0L,&event)==True) handle_event(&event);
X    }
X    XNextEvent(display,&event);
X    handle_event(&event);
X  }
X}
X
Xrandomize_color()
X{
X  int i;
X  XColor color;
X  color.pixel = palette[rndm((long)numcolors)];
X  color.red = rndm(65535L);
X  color.green = rndm(65535L);
X  color.blue = rndm(65535L);
X  color.flags = DoRed|DoGreen|DoBlue;
X  XStoreColor(display, DefaultColormap(display,screen), &color);
X}
X
Xrandomize_colors()
X{
X  int i;
X  XColor color[NCOLORS];
X  for (i=0; i<numcolors; i++) {
X    color[i].pixel = palette[i];
X    color[i].red = rndm(65535L);
X    color[i].green = rndm(65535L);
X    color[i].blue = rndm(65535L);
X    color[i].flags = DoRed|DoGreen|DoBlue;
X  }
X  XStoreColors(display, DefaultColormap(display,screen), color, numcolors);
X}
X
Xhandle_event(event)
XXEvent *event;
X{
X  int i;
X  if (event->type==ConfigureNotify) {
X    for (i=0; i<nwindows; i++) {
X      if (event->xconfigure.window==window[i]) {
X        if (CX[i] != event->xconfigure.width/2 ||
X            CY[i] != event->xconfigure.height/2)
X	  XClearWindow(display,event->xconfigure.window);
X        CX[i] = event->xconfigure.width/2;
X        CY[i] = event->xconfigure.height/2;
X        M[i] = (CX[i]>CY[i]) ? CX[i] : CY[i];
X        M[i] = M[i] ? M[i] : 1;
X        break;
X      }
X    }
X  }
X  else if (event->type==MapNotify) {
X    for (i=0; i<nwindows; i++) {
X      if (event->xmap.window==window[i]) {
X        X1[i] = rndm((long)M[i]) + 1;
X        X2[i] = rndm((long)M[i]) + 1;
X        Y1[i] = rndm((long)X1[i]);
X        Y2[i] = rndm((long)X2[i]);
X        XV1[i] = rndm(7L)-3;
X        XV2[i] = rndm(7L)-3;
X        YV1[i] = rndm(7L)-3;
X        YV2[i] = rndm(7L)-3;
X        HC[i] = rndm((long)numcolors);
X        break;
X      }
X    }
X  }
X  else if (event->type==VisibilityNotify) {
X    for (i=0; i<nwindows; i++) {
X      if (event->xvisibility.window==window[i]) {
X	if (visible[i] &&
X	    event->xvisibility.state == VisibilityFullyObscured) {
X          visible[i]=0;
X          nvisible--;
X	}
X	else if (!visible[i] &&
X		 event->xvisibility.state != VisibilityFullyObscured) {
X          visible[i]=1;
X          nvisible++;
X	}
X        break;
X      }
X    }
X  }
X}
X
Xusage()
X{
X  int i;
X  (void)fprintf(stderr,"Usage: %s [-display <displayname>] [-bg <background>]",
X	  progname);
X  (void)fprintf(stderr," [-bd <border>]\n");
X  for (i = 0; i<(strlen(progname)+8); i++) (void)putc(' ',stderr);
X  (void)fprintf(stderr,"[-bw <borderwidth>] [-geometry <geometry>]");
X  (void)fprintf(stderr," [-delay <msec>]\n");
X  for (i = 0; i<(strlen(progname)+8); i++) (void)putc(' ',stderr);
X  (void)fprintf(stderr,"[-icondelay <msec>] [-iconic] [-mono]");
X  (void)fprintf(stderr," [-mult <number>] -r\n");
X  for (i = 0; i<(strlen(progname)+8); i++) (void)putc(' ',stderr);
X  (void)fprintf(stderr,"[-randomcolor]\n");
X  exit(1);
X}
X
Xfatalerror(s1,s2)
Xchar *s1,*s2;
X{
X  (void)fprintf(stderr,"%s: ",progname);
X  (void)fprintf(stderr,s1,s2);
X  (void)putc('\n',stderr);
X  exit(1);
X}
X
Xlong rndm(maxval)
Xlong maxval;
X{
X  long lrand48();
X  return ((lrand48() >> 15) * maxval) >> 16;
X}
X
Xallocate_arrays(nwin)
Xunsigned nwin;
X{
X  char *calloc();
X  if ((window=(Window *)calloc(nwin,sizeof(Window))) == NULL) return 0;
X  if ((CX=(int *)calloc(nwin,sizeof(int))) == NULL) return 0;
X  if ((CY=(int *)calloc(nwin,sizeof(int))) == NULL) return 0;
X  if ((M=(int *)calloc(nwin,sizeof(int))) == NULL) return 0;
X  if ((visible=(int *)calloc(nwin,sizeof(int))) == NULL) return 0;
X  if ((X1=(int *)calloc(nwin,sizeof(int))) == NULL) return 0;
X  if ((Y1=(int *)calloc(nwin,sizeof(int))) == NULL) return 0;
X  if ((X2=(int *)calloc(nwin,sizeof(int))) == NULL) return 0;
X  if ((Y2=(int *)calloc(nwin,sizeof(int))) == NULL) return 0;
X  if ((XV1=(int *)calloc(nwin,sizeof(int))) == NULL) return 0;
X  if ((YV1=(int *)calloc(nwin,sizeof(int))) == NULL) return 0;
X  if ((XV2=(int *)calloc(nwin,sizeof(int))) == NULL) return 0;
X  if ((YV2=(int *)calloc(nwin,sizeof(int))) == NULL) return 0;
X  if ((HC=(int *)calloc(nwin,sizeof(int))) == NULL) return 0;
X  if ((XA=(int *)calloc(nwin,sizeof(int))) == NULL) return 0;
X  if ((YA=(int *)calloc(nwin,sizeof(int))) == NULL) return 0;
X  if ((XB=(int *)calloc(nwin,sizeof(int))) == NULL) return 0;
X  if ((YB=(int *)calloc(nwin,sizeof(int))) == NULL) return 0;
X  if ((XC=(int *)calloc(nwin,sizeof(int))) == NULL) return 0;
X  if ((YC=(int *)calloc(nwin,sizeof(int))) == NULL) return 0;
X  if ((XD=(int *)calloc(nwin,sizeof(int))) == NULL) return 0;
X  if ((YD=(int *)calloc(nwin,sizeof(int))) == NULL) return 0;
X  if ((schedule=(struct timeval *)calloc(nwin,sizeof(struct timeval))) == NULL)
X    return 0;
X  if ((intervals=(struct timeval *)calloc(nwin,sizeof(struct timeval))) == NULL)
X    return 0;
X  return 1;
X}
X
Xint scheduler()
X{
X  struct timeval currtime, *nextalarm, *alarmindex;
X  struct timezone tzp;
X  int i;
X
X  /* Get current time */
X  (void)gettimeofday(&currtime, &tzp);
X
X  /* Find earliest alarm due */
X  alarmindex = nextalarm = schedule;
X  for (i=1; i<nwindows; i++) {
X    if (visible[++alarmindex - schedule] &&
X	( alarmindex->tv_sec < nextalarm->tv_sec ||
X          alarmindex->tv_sec == nextalarm->tv_sec &&
X          alarmindex->tv_usec < nextalarm->tv_usec ))
X      nextalarm = alarmindex;
X  }
X
X  /* If the next alarm is not past due, sleep until it comes due */
X  if (currtime.tv_sec < nextalarm->tv_sec ||
X      currtime.tv_sec == nextalarm->tv_sec &&
X      currtime.tv_usec < nextalarm->tv_usec) {
X    struct timeval timeout;
X    int fd=ConnectionNumber(display), readfds;
X
X    timeout.tv_sec = 0;
X    timeout.tv_usec = 0;
X    timeout.tv_sec = nextalarm->tv_sec - currtime.tv_sec;
X    timeout.tv_usec = nextalarm->tv_usec - currtime.tv_usec;
X    if (timeout.tv_usec < 0) {
X      timeout.tv_sec -= 1L;
X      timeout.tv_usec += 1000000L;
X    }
X
X    readfds = 1<<fd;
X    (void)select(fd+1, &readfds, NULL, NULL, &timeout);
X
X    /* Recompute current time */
X    (void)gettimeofday(&currtime, &tzp);
X
X  }
X
X  /* Set next alarm to current time + interval */
X  nextalarm->tv_sec = currtime.tv_sec + intervals[nextalarm-schedule].tv_sec;
X  nextalarm->tv_usec = currtime.tv_usec + intervals[nextalarm-schedule].tv_usec;
X  if (nextalarm->tv_usec >= 1000000) {
X    nextalarm->tv_sec += 1;
X    nextalarm->tv_usec -= 1000000;
X  }
X
X  /* Return index of next alarm */
X  return nextalarm-schedule;
X}
END_OF_FILE
if test 20946 -ne `wc -c <'kaleid.c'`; then
    echo shar: \"'kaleid.c'\" unpacked with wrong size!
fi
# end of 'kaleid.c'
fi
if test -f 'kalicon.h' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'kalicon.h'\"
else
echo shar: Extracting \"'kalicon.h'\" \(3360 characters\)
sed "s/^X//" >'kalicon.h' <<'END_OF_FILE'
X/* Kaleidoscope icon -- for window managers that do not support window
X   icons. */
X
X#define icon_width 64
X#define icon_height 64
Xstatic char icon_bits[] = {
X   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
X   0xff, 0xff, 0xff, 0xff, 0xff, 0xfd, 0xff, 0xff, 0xff, 0xff, 0x7f, 0xff,
X   0xff, 0xf3, 0xff, 0xbb, 0xbb, 0xff, 0x9f, 0xff, 0xff, 0xcf, 0xff, 0x77,
X   0xdd, 0xff, 0xe7, 0xff, 0xff, 0x33, 0xff, 0x6f, 0xed, 0xff, 0x99, 0xff,
X   0xff, 0xcf, 0xfc, 0xeb, 0xae, 0x7f, 0xe6, 0xff, 0xff, 0x3f, 0xf3, 0x57,
X   0xd4, 0x9f, 0xf9, 0xff, 0xff, 0xcf, 0xc8, 0x37, 0xd9, 0x27, 0xe6, 0xff,
X   0xfb, 0x3f, 0x27, 0x2b, 0xa9, 0xc9, 0xf9, 0xbf, 0xd7, 0xff, 0x9c, 0x94,
X   0x52, 0x72, 0xfe, 0xd7, 0xd7, 0xbf, 0x73, 0x90, 0x12, 0x9c, 0xf9, 0xd7,
X   0xaf, 0x7e, 0xce, 0x03, 0x81, 0x67, 0xfe, 0xea, 0xaf, 0xfe, 0x39, 0x07,
X   0x81, 0x99, 0xff, 0xea, 0x5f, 0xf5, 0xe6, 0x00, 0x00, 0xe6, 0x5e, 0xf5,
X   0x5f, 0xed, 0x99, 0x03, 0x80, 0x39, 0x5f, 0xf5, 0xbf, 0xaa, 0x67, 0x06,
X   0x41, 0xce, 0xab, 0xfa, 0xbf, 0x5a, 0x9b, 0x11, 0x88, 0xb3, 0xad, 0xfa,
X   0x7f, 0x56, 0x65, 0x02, 0x81, 0x4c, 0xd5, 0xfc, 0x7f, 0xb5, 0x9a, 0x01,
X   0x00, 0xb3, 0x56, 0xfd, 0xff, 0xac, 0x6a, 0x20, 0x08, 0xac, 0x6a, 0xfe,
X   0xff, 0x6a, 0x95, 0x08, 0x01, 0x52, 0xab, 0xfe, 0xff, 0x59, 0x55, 0x22,
X   0x81, 0x54, 0x35, 0xff, 0xff, 0xd5, 0xaa, 0x28, 0x08, 0xaa, 0x55, 0xff,
X   0xff, 0xb3, 0x0a, 0x98, 0x32, 0xa0, 0x9a, 0xff, 0xff, 0xb3, 0x45, 0x64,
X   0x4c, 0xc4, 0x9a, 0xff, 0xb7, 0x25, 0x01, 0x4a, 0xa4, 0x00, 0x41, 0xdb,
X   0x6f, 0x02, 0x00, 0x05, 0x41, 0x0b, 0x80, 0xec, 0x9f, 0x0d, 0x02, 0x21,
X   0x08, 0x01, 0x60, 0xf3, 0x7f, 0x03, 0x90, 0x12, 0x91, 0x96, 0x80, 0xfd,
X   0xf7, 0x00, 0x00, 0xc6, 0xc7, 0x00, 0x00, 0xde, 0x4f, 0x0c, 0x00, 0xc1,
X   0x07, 0x01, 0x60, 0xe4, 0xbf, 0x33, 0x65, 0xe8, 0x2f, 0x4c, 0x99, 0xf9,
X   0x4f, 0x0c, 0x00, 0xc1, 0x07, 0x01, 0x60, 0xe4, 0xf7, 0x00, 0x00, 0xc6,
X   0xc7, 0x00, 0x00, 0xde, 0x7f, 0x03, 0x90, 0x12, 0x91, 0x96, 0x80, 0xfd,
X   0x9f, 0x0d, 0x02, 0x21, 0x08, 0x01, 0x60, 0xf3, 0x6f, 0x02, 0x00, 0x05,
X   0x41, 0x0b, 0x80, 0xec, 0xb7, 0x25, 0x01, 0x4a, 0xa4, 0x00, 0x41, 0xdb,
X   0xff, 0xb3, 0x45, 0x64, 0x4c, 0xc4, 0x9a, 0xff, 0xff, 0xb3, 0x0a, 0x98,
X   0x32, 0xa0, 0x9a, 0xff, 0xff, 0xd5, 0xaa, 0x28, 0x08, 0xaa, 0x55, 0xff,
X   0xff, 0x59, 0x55, 0x22, 0x81, 0x54, 0x35, 0xff, 0xff, 0x6a, 0x95, 0x08,
X   0x01, 0x52, 0xab, 0xfe, 0xff, 0xac, 0x6a, 0x20, 0x08, 0xac, 0x6a, 0xfe,
X   0x7f, 0xb5, 0x9a, 0x01, 0x00, 0xb3, 0x56, 0xfd, 0x7f, 0x56, 0x65, 0x02,
X   0x81, 0x4c, 0xd5, 0xfc, 0xbf, 0x5a, 0x9b, 0x11, 0x88, 0xb3, 0xad, 0xfa,
X   0xbf, 0xaa, 0x67, 0x06, 0x41, 0xce, 0xab, 0xfa, 0x5f, 0xed, 0x99, 0x03,
X   0x80, 0x39, 0x5f, 0xf5, 0x5f, 0xf5, 0xe6, 0x00, 0x00, 0xe6, 0x5e, 0xf5,
X   0xaf, 0xfe, 0x39, 0x07, 0x81, 0x99, 0xff, 0xea, 0xaf, 0x7e, 0xce, 0x03,
X   0x81, 0x67, 0xfe, 0xea, 0xd7, 0xbf, 0x73, 0x90, 0x12, 0x9c, 0xf9, 0xd7,
X   0xd7, 0xff, 0x9c, 0x94, 0x52, 0x72, 0xfe, 0xd7, 0xfb, 0x3f, 0x27, 0x2b,
X   0xa9, 0xc9, 0xf9, 0xbf, 0xff, 0xcf, 0xc8, 0x37, 0xd9, 0x27, 0xe6, 0xff,
X   0xff, 0x3f, 0xf3, 0x57, 0xd4, 0x9f, 0xf9, 0xff, 0xff, 0xcf, 0xfc, 0xeb,
X   0xae, 0x7f, 0xe6, 0xff, 0xff, 0x33, 0xff, 0x6f, 0xed, 0xff, 0x99, 0xff,
X   0xff, 0xcf, 0xff, 0x77, 0xdd, 0xff, 0xe7, 0xff, 0xff, 0xf3, 0xff, 0xbb,
X   0xbb, 0xff, 0x9f, 0xff, 0xff, 0xfd, 0xff, 0xff, 0xff, 0xff, 0x7f, 0xff,
X   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
END_OF_FILE
if test 3360 -ne `wc -c <'kalicon.h'`; then
    echo shar: \"'kalicon.h'\" unpacked with wrong size!
fi
# end of 'kalicon.h'
fi
if test -f 'patchlevel.h' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'patchlevel.h'\"
else
echo shar: Extracting \"'patchlevel.h'\" \(21 characters\)
sed "s/^X//" >'patchlevel.h' <<'END_OF_FILE'
X#define PATCHLEVEL 2
END_OF_FILE
if test 21 -ne `wc -c <'patchlevel.h'`; then
    echo shar: \"'patchlevel.h'\" unpacked with wrong size!
fi
# end of 'patchlevel.h'
fi
echo shar: End of archive 1 \(of 1\).
cp /dev/null ark1isdone
MISSING=""
for I in 1 ; do
    if test ! -f ark${I}isdone ; then
	MISSING="${MISSING} ${I}"
    fi
done
if test "${MISSING}" = "" ; then
    echo You have the archive.
    rm -f ark[1-9]isdone
else
    echo You still need to unpack the following archives:
    echo "        " ${MISSING}
fi
##  End of shell archive.
exit 0
-- 
Mike Wexler(wyse!mikew)    Phone: (408)433-1000 x1330
Moderator of comp.sources.x



More information about the Comp.sources.x mailing list