Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

v23i003: xsquclock - Keep on clocking, A Square CLock for X, Part01/01

1 view
Skip to first unread message

Jens Dengler

unread,
Mar 13, 1995, 3:49:39 PM3/13/95
to
Submitted-by: je...@cs.tu-berlin.de (Jens Dengler)
Posting-number: Volume 23, Issue 3
Archive-name: xsquclock/part01
Environment: X11, clock

From the README:

Because with the first post I get mail from a long time unseen colleague,
I'm back to post another program, which I've written even a looonger time
ago as one of my first experiences with X/11, testing the way colors go.
In fact, the program has worked first on an Atari ST with color monitor
but I hope there are no remnants of GEMDOS left... 8-)

Nobody knows what will follow now: Another clock.

And: THIS TIME IT'S ONLY FOR COLOR DISPLAYS with min. 6 bit depth. Sorry.

Also its useful to have many different colors within the colormap. This
clock uses the colors from color number 16 up of the number of colors in
the colormap. This is because of the fact that most window managers
are using up to the first 16 colors for themself and therefore defining
sometimes very boring colors to them.

To this clock everybody told me that they don't understand it, but it is
really simple. The only confusing thing might be that the "seconds" are
not displayed although a random one of the inner upper layer squares changes
randomly its color within every "update" cycle.

#! /bin/sh
# This is a shell archive. Remove anything before this line, then feed it
# into a shell via "sh file" or similar. To overwrite existing files,
# type "sh file -c".
# Contents: xsquclock/Imakefile xsquclock/Makefile xsquclock/README
# xsquclock/patchlevel.h xsquclock/xsquclock.c
# xsquclock/xsquclock.man
# Wrapped by chris@ftp on Mon Mar 13 14:37:58 1995
PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin:$PATH ; export PATH
echo If this archive is complete, you will see the following message:
echo ' "shar: End of archive 1 (of 1)."'
if test -f 'xsquclock/Imakefile' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'xsquclock/Imakefile'\"
else
echo shar: Extracting \"'xsquclock/Imakefile'\" \(146 characters\)
sed "s/^X//" >'xsquclock/Imakefile' <<'END_OF_FILE'
XINCLUDES = -I$(TOP)
XLOCAL_LIBRARIES = $(XLIB)
XDEPLIBS =
XLDLIBS =
X
XSRCS = xsquclock.c
XOBJS = xsquclock.o
X
XComplexProgramTarget(xsquclock)
END_OF_FILE
if test 146 -ne `wc -c <'xsquclock/Imakefile'`; then
echo shar: \"'xsquclock/Imakefile'\" unpacked with wrong size!
fi
# end of 'xsquclock/Imakefile'
fi
if test -f 'xsquclock/Makefile' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'xsquclock/Makefile'\"
else
echo shar: Extracting \"'xsquclock/Makefile'\" \(103 characters\)
sed "s/^X//" >'xsquclock/Makefile' <<'END_OF_FILE'
Xxsquclock: xsquclock.c
X cc -o xsquclock xsquclock.c -lX11
X
Xclean:
X /bin/rm xsquclock.o core xsquclock
END_OF_FILE
if test 103 -ne `wc -c <'xsquclock/Makefile'`; then
echo shar: \"'xsquclock/Makefile'\" unpacked with wrong size!
fi
# end of 'xsquclock/Makefile'
fi
if test -f 'xsquclock/README' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'xsquclock/README'\"
else
echo shar: Extracting \"'xsquclock/README'\" \(10016 characters\)
sed "s/^X//" >'xsquclock/README' <<'END_OF_FILE'
X
XBecause with the first post I get mail from a long time unseen colleague,
XI'm back to post another program, which I've written even a looonger time
Xago as one of my first experiences with X/11, testing the way colors go.
XIn fact, the program has worked first on an Atari ST with color monitor
Xbut I hope there are no remnants of GEMDOS left... 8-)
X
XNobody knows what will follow now: Another clock.
X
XAnd: THIS TIME IT'S ONLY FOR COLOR DISPLAYS with min. 6 bit depth. Sorry.
X
XAlso its useful to have many different colors within the colormap. This
Xclock uses the colors from color number 16 up of the number of colors in
Xthe colormap. This is because of the fact that most window managers
Xare using up to the first 16 colors for themself and therefore defining
Xsometimes very boring colors to them.
X
XTo this clock everybody told me that they don't understand it, but it is
Xreally simple. The only confusing thing might be that the "seconds" are
Xnot displayed although a random one of the inner upper layer squares changes
Xrandomly its color within every "update" cycle.
X
XIf you have a color display with only one black or white color within
Xthe first 16 colors and the other colors are different from white or
Xblack, it is obvious how the minutes and hours of the clock works.
XHere is a little ASCII art to illustrate the lower layer of the clock,
Xit has 16x16 squares:
X
X _______________________________________________________________
X|52 |53 |54 |55 |56 |57 |58 |59 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
X|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
X|51 | | | | | | | | | | | | | | | 8 |
X|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
X|50 | | | | | | | | | | | | | | | 9 |
X|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
X|49 | | | | | | | | | | | | | | |10 |
X|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
X|48 | | | | | | | | | | | | | | |11 |
X|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
X|47 | | | | | | | | | | | | | | |12 |
X|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
X|46 | | | | | | | | | | | | | | |13 |
X|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
X|45 | | | | | | | | | | | | | | |14 |
X|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
X|44 | | | | | | | | | | | | | | |15 |
X|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
X|43 | | | | | | | | | | | | | | |16 |
X|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
X|42 | | | | | | | | | | | | | | |17 |
X|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
X|41 | | | | | | | | | | | | | | |18 |
X|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
X|40 | | | | | | | | | | | | | | |19 |
X|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
X|39 | | | | | | | | | | | | | | |20 |
X|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
X|38 | | | | | | | | | | | | | | |21 |
X|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
X|37 |36 |35 |34 |33 |32 |31 |30 |29 |28 |27 |26 |25 |24 |23 |22 |
X|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
X
XOn this lower layer the minutes are displayed, using the fact that
X16x16 squares have 60 outer squares. The square that should be the
Xonly black (or white when -rv was passed) one is the one which shows
Xthe current minute along to the upper numbering scheme. If you have
Xmany black colors in your palette it should help to click on the
Xclock and look which square stays black.
X
XThe following scheme shows the upper layer above the lower layer:
X
X _______________________________________________________________
X| _|_ | _|_ | _|_ | _|_ | _|_ | _|_ | _|_ | _|_ |
X|_| |_|_| 11|_|_| 11|_|_| 12|_|_| 12|_|_| 1|_|_| 1|_|_| |_|
X| |___| | |___| | |___| | |___| | |___| | |___| | |___| | |___| |
X|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
X| _|_ | _|_ | _|_ | _|_ | _|_ | _|_ | _|_ | _|_ |
X|_| 10|_|_| |_|_| |_|_| |_|_| |_|_| |_|_| |_|_| 2|_|
X| |___| | |___| | |___| | |___| | |___| | |___| | |___| | |___| |
X|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
X| _|_ | _|_ | _|_ | _|_ | _|_ | _|_ | _|_ | _|_ |
X|_| 10|_|_| |_|_| |_|_| |_|_| |_|_| |_|_| |_|_| 2|_|
X| |___| | |___| | |___| | |___| | |___| | |___| | |___| | |___| |
X|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
X| _|_ | _|_ | _|_ | _|_ | _|_ | _|_ | _|_ | _|_ |
X|_| 9|_|_| |_|_| |_|_| |_|_| |_|_| |_|_| |_|_| 3|_|
X| |___| | |___| | |___| | |___| | |___| | |___| | |___| | |___| |
X|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
X| _|_ | _|_ | _|_ | _|_ | _|_ | _|_ | _|_ | _|_ |
X|_| 9|_|_| |_|_| |_|_| |_|_| |_|_| |_|_| |_|_| 3|_|
X| |___| | |___| | |___| | |___| | |___| | |___| | |___| | |___| |
X|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
X| _|_ | _|_ | _|_ | _|_ | _|_ | _|_ | _|_ | _|_ |
X|_| 8|_|_| |_|_| |_|_| |_|_| |_|_| |_|_| |_|_| 4|_|
X| |___| | |___| | |___| | |___| | |___| | |___| | |___| | |___| |
X|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
X| _|_ | _|_ | _|_ | _|_ | _|_ | _|_ | _|_ | _|_ |
X|_| 8|_|_| |_|_| |_|_| |_|_| |_|_| |_|_| |_|_| 4|_|
X| |___| | |___| | |___| | |___| | |___| | |___| | |___| | |___| |
X|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
X| _|_ | _|_ | _|_ | _|_ | _|_ | _|_ | _|_ | _|_ |
X|_| |_|_| 7|_|_| 7|_|_| 6|_|_| 6|_|_| 5|_|_| 5|_|_| |_|
X| |___| | |___| | |___| | |___| | |___| | |___| | |___| | |___| |
X|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
X
XOn a specific hour the two squares with the correspondent number should
Xbe black. Test: what time shows the following squclock? (# = black)
X
X _______________________________________________________________
X| _|_ | _|_ | _|_ | _|_ | _|_ | _|_ | _|_ | _|_ |
X|_| |_|_|###|_|_|###|_|_| |_|_| |_|_| |_|_| |_|_| |_|
X| |___| | |###| | |###| | |___| | |___| | |___| | |___| | |___| |
X|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
X| _|_ | _|_ | _|_ | _|_ | _|_ | _|_ | _|_ | _|_ |
X|_| |_|_| |_|_| |_|_| |_|_| |_|_| |_|_| |_|_| |_|
X| |___| | |___| | |___| | |___| | |___| | |___| | |___| | |___| |
X|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
X| _|_ | _|_ | _|_ | _|_ | _|_ | _|_ | _|_ | _|_ |
X|_| |_|_| |_|_| |_|_| |_|_| |_|_| |_|_| |_|_| |_|
X| |___| | |___| | |___| | |___| | |___| | |___| | |___| | |___| |
X|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
X| _|_ | _|_ | _|_ | _|_ | _|_ | _|_ | _|_ | _|_ |
X|_| |_|_| |_|_| |_|_| |_|_| |_|_| |_|_| |_|_| |_|
X| |___| | |___| | |___| | |___| | |___| | |___| | |___| | |___| |
X|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
X| _|_ | _|_ | _|_ | _|_ | _|_ | _|_ | _|_ | _|_ |
X|_| |_|_| |_|_| |_|_| |_|_| |_|_| |_|_| |_|_| |_|
X| |___| | |___| | |___| | |___| | |___| | |___| | |___| | |___| |
X|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
X| _|_ | _|_ | _|_ | _|_ | _|_ | _|_ | _|_ | _|_ |
X|_| |_|_| |_|_| |_|_| |_|_| |_|_| |_|_| |_|_| |_|
X| |___| | |___| | |___| | |___| | |___| | |___| | |___| | |___| |
X|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
X| _|_ | _|_ | _|_ | _|_ | _|_ | _|_ | _|_ | _|_ |
X|_| |_|_| |_|_| |_|_| |_|_| |_|_| |_|_| |_|_| |_|
X| |___| | |___| | |___| | |___| | |___| | |___| | |___| | |___| |
X|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|
X| _|_ | _|_ | _|_ | _|_ | _|_ | _|_ | _|_ | _|_ |
X|_| |_|_| |_|_| |_|_| |_|_| |_|_| |_|_| |_|_| |_|
X| |___| | |___| | |___| | |___| | |___| | |___| | |___| | |___|#|
X|___|___|___|___|___|___|___|___|___|___|___|___|___|___|___|###|
X
X
X
XCorrect answer: 11:22 am or pm.
X
XThe one who still don't understand the clock should remain by
Xenjoying the colors and reading the time from the title bar or the
Xicon name.
X
XPlease notice also that the clock has a simple mechanism to terminate
Xit: simply give it the keyboard focus and give it a KeyPress event should
Xkill xsquclock with a -1 return value (its the same behaviour as in xbclock).
XAlso the clock wants to stay in square shape, so if you resize it it will
Xuse the next smaller square size to display unless the window manager wont
Xlet it. (In that case it could be that xsquclock is trying to get its
Xsquare shape 4E4. I have only noticed this behaviour once back in the 80ties
Xon an old odd version of the hpwm for X11/R3.)
X
XFor everyone who want to try to compile this:
X
XYES, IT'S K&R-C! And it's bad K&R-C, I know. It's even bad X/11. 8-)
X ---
X
XBut the clock is original... I've never seen it before and I think
XI have invented it by myself.
X
XBecause an Imakefile is obligate for a distribution, I've included
Xit. The Makefile is a very short one similar to the line that should
Xwork universally. I'm using this one instead of the locally made by
Xxmkmf because the Makefile made by xmkmf is bigger than this README!
XOn other systems to make this clock you have to have a K&R-C-Compiler
Xand you have to make a Makefile first (unless you like to try
X"gcc -o xsquclock xsquclock.c -lX11"), I recommend xmkmf in a proper
Xmade X distribution, so first type
X
Xxmkmf
X
Xand then
X
Xmake
X
Xshould work. Enjoy!
END_OF_FILE
if test 10016 -ne `wc -c <'xsquclock/README'`; then
echo shar: \"'xsquclock/README'\" unpacked with wrong size!
fi
# end of 'xsquclock/README'
fi
if test -f 'xsquclock/patchlevel.h' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'xsquclock/patchlevel.h'\"
else
echo shar: Extracting \"'xsquclock/patchlevel.h'\" \(0 characters\)
sed "s/^X//" >'xsquclock/patchlevel.h' <<'END_OF_FILE'
END_OF_FILE
if test 0 -ne `wc -c <'xsquclock/patchlevel.h'`; then
echo shar: \"'xsquclock/patchlevel.h'\" unpacked with wrong size!
fi
# end of 'xsquclock/patchlevel.h'
fi
if test -f 'xsquclock/xsquclock.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'xsquclock/xsquclock.c'\"
else
echo shar: Extracting \"'xsquclock/xsquclock.c'\" \(12638 characters\)
sed "s/^X//" >'xsquclock/xsquclock.c' <<'END_OF_FILE'
X/*****************************************************************************
X * *
X * xsquclock.c: C-Programm Hauptmodul (X-Applikation) *
X * *
X * author: jd *
X * version: 110790 fuer cc auf hp 9000/300 WS *
X * modified: 080894 *
X * last time modified: 110894 *
X * *
X *****************************************************************************
X * *
X * $Header: xsquclock.c,v 1.1 1994/08/11 13:38:35 jensd Exp jensd $ *
X * *
X * Copyright (C) 1990, 1994 by Jens Dengler *
X * *
X * Permission to use, copy, modify, and distribute this software and its *
X * documentation for any purpose and without fee is hereby granted, provided *
X * that the above copyright notice appear in all copies and that both that *
X * copyright notice and this permission notice appear in supporting *
X * documentation. This software is provided "as is" without express or *
X * implied warranty. *
X * *
X *****************************************************************************/
X
X
X/*** X-Konstanten, Strukturen und Variablen ***/
X
X#include <ctype.h>
X#include <stdio.h>
X#include <time.h>
X#include <X11/X.h>
X#include <signal.h>
X#include <X11/Xlib.h>
X#include <X11/Xutil.h>
X
X#define forever while(1)
X#define MIN(a,b)((a < b)? a : b )
X#define COLOROFFSET 16
X#define NO_WINDOW -1
X#define FALSE 0
X#define TRUE -1
X
XDisplay *mydisplay;
XWindow mywindow;
XGC mygc;
XXGCValues GCset;
XXEvent myevent;
XXSizeHints myhint;
Xint myscreen;
Xunsigned long myforeground,mybackground;
X
X/*** Eigene Konstanten, Strukturen und globale Variablen ***/
X
Xint delta = 10, mindelta = 6, bitsperRGB, intervall;
Xchar **globav;
Xint globac;
Xunsigned long Xccolors;
X
X/*** Hilfsroutinen ***/
X
X/*****************************************************************************/
Xint choose(n)
X/*****************************************************************************/
Xint n;
X{ return(rand() % n);
X}
X
Xmdraw(m)
Xregister int m;
X{ register int i,j,k;
X int x,y;
X
X k = (m == 0)? 59 : m-1;
X while (k != (m+1) % 60)
X { if (k < 8 || k > 51)
X { j = 0;
X if (k < 8) i = k + 8;
X else i = k - 52;
X }
X else if (k < 23)
X { i = 15; j = k - 7;
X }
X else if (k < 38)
X { j = 15; i = 37 - k;
X }
X else
X { i = 0; j = 52 - k;
X }
X if (k == m) GCset.foreground = myforeground;
X else GCset.foreground = choose(Xccolors-COLOROFFSET)+COLOROFFSET;
X XChangeGC(mydisplay,mygc,GCForeground,&GCset);
X x = i*delta; y = j*delta;
X XFillRectangle(mydisplay,mywindow,mygc,x,y,delta,delta);
X j >>= 1;
X i >>= 1;
X GCset.foreground = choose(Xccolors-COLOROFFSET)+COLOROFFSET;
X XChangeGC(mydisplay,mygc,GCForeground,&GCset);
X x = (delta >> 1)+i*(delta << 1);
X y = (delta >> 1)+j*(delta << 1);
X XFillRectangle(mydisplay,mywindow,mygc,x,y,delta,delta);
X k = ((k+1) % 60);
X }
X /* Zusaetzlich einmal ein Kaestchen umfaerben */
X i = choose(6)+1; j = choose(6)+1;
X GCset.foreground = choose(Xccolors-COLOROFFSET)+COLOROFFSET;
X XChangeGC(mydisplay,mygc,GCForeground,&GCset);
X x = (delta >> 1)+i*(delta << 1);
X y = (delta >> 1)+j*(delta << 1);
X XFillRectangle(mydisplay,mywindow,mygc,x,y,delta,delta);
X}
X
X/******************************************************************************/
Xhdraw(h)
X/******************************************************************************/
Xint h;
X{ int i,j,k,l,m,n;
X int x,y;
X
X h++; /* TZ != MEZ -> MESZ !? */
X h %= 12; k = h;
X for (n = 0; n < 2; n++)
X { if (k < 2 || k > 10)
X { j = m = 0;
X if (k < 2) i = (k << 1)+3;
X else i = 1;
X l = i+1;
X }
X else if (k < 5)
X { i = l = 7; j = ((k - 2) << 1)+1; m = j+1;
X }
X else if (k < 8)
X { j = m = 7; i = 5 - ((k - 5) << 1); l = i+1;
X }
X else
X { i = l = 0; j = 5 - ((k - 8) << 1); m = j+1;
X }
X if (k == (h+1) % 12) GCset.foreground = myforeground;
X else GCset.foreground = choose(Xccolors-COLOROFFSET)+COLOROFFSET;
X XChangeGC(mydisplay,mygc,GCForeground,&GCset);
X x = (delta >> 1)+i*(delta << 1);
X y = (delta >> 1)+j*(delta << 1);
X XFillRectangle(mydisplay,mywindow,mygc,x,y,delta,delta);
X if (k == (h+1) % 12) GCset.foreground = myforeground;
X else GCset.foreground = choose(Xccolors-COLOROFFSET)+COLOROFFSET;
X XChangeGC(mydisplay,mygc,GCForeground,&GCset);
X x = (delta >> 1)+l*(delta << 1);
X y = (delta >> 1)+m*(delta << 1);
X XFillRectangle(mydisplay,mywindow,mygc,x,y,delta,delta);
X k = ((k+1) % 12);
X }
X}
X
X/******************************************************************************/
Xiniclocking()
X/******************************************************************************/
X{ register int i,j;
X long tim;
X
X signal(SIGALRM,SIG_IGN); /* Hier wird viel gemalt, deshalb abschotten! */
X tim = time((long *) 0) % 3600;
X srand((unsigned) tim);
X for (i = 0; i < 16; i++)
X for (j = 0; j < 16; j++)
X { GCset.foreground = choose(Xccolors-COLOROFFSET)+COLOROFFSET;
X XChangeGC(mydisplay,mygc,GCForeground,&GCset);
X XFillRectangle(mydisplay,mywindow,mygc,i*delta,j*delta,delta,delta);
X }
X for (i = 0; i < 8; i++)
X for (j = 0; j < 8; j++)
X { GCset.foreground = choose(Xccolors-COLOROFFSET)+COLOROFFSET;
X XChangeGC(mydisplay,mygc,GCForeground,&GCset);
X XFillRectangle(mydisplay,mywindow,mygc,(delta >> 1)+(i*delta << 1),
X (delta >> 1)+(j*delta << 1),delta,delta);
X }
X tim = time((long *) 0);
X mdraw((int) (tim / 60) % 60);
X hdraw((int) (tim / 3600) % 24);
X XFlush(mydisplay);
X}
X
X/******************************************************************************/
Xclocking()
X/* ist eine trap-Routine, jeweils einmal pro Intervall aktiviert. Restauriert
X am Ende das signal auf sich selbst.
X*/
X/******************************************************************************/
X{ char wholetxt[48],subtxt[32];
X int i,j;
X long tim;
X
X signal(SIGALRM,SIG_IGN); /* Waehrend des Zeichnens kein weiteres Signal */
X tim = time((long *) 0);
X strcpy(wholetxt,ctime(&tim));
X wholetxt[strlen(wholetxt)-1] = '\0';
X XStoreName(mydisplay,mywindow,wholetxt);
X strcpy(subtxt,&wholetxt[11]);
X subtxt[5] = '\0';
X XSetIconName(mydisplay,mywindow,subtxt);
X if (tim % 60 == 0 || intervall != 1)
X { mdraw((tim / 60) % 60);
X /* Die Stunde muss jede Minute nachgezeichnet werden, da ansonsten beim
X Durchgang des Minutenzeigers durch den Stundenzeiger der Stundenzeiger
X verschwindet!
X */
X hdraw((tim / 3600) % 24);
X }
X GCset.foreground = choose(Xccolors-COLOROFFSET)+COLOROFFSET;
X i = choose(6)+1; j = choose(6)+1;
X XChangeGC(mydisplay,mygc,GCForeground,&GCset);
X XFillRectangle(mydisplay,mywindow,mygc,(delta >> 1)+(i*delta << 1),
X (delta >> 1)+(j*delta << 1),delta,delta);
X XFlush(mydisplay);
X signal(SIGALRM,clocking);
X alarm(intervall);
X}
X
X/*** Hauptprogramm ***/
X
X/******************************************************************************/
Xmain(ac,av)
X/******************************************************************************/
Xint ac; char **av;
X{ int done,reverse,borderlen,verbose;
X char defgeometry[80],displayname[80],globstr[80];
X unsigned int oldw,oldh;
X Window rootofroot;
X XWindowAttributes wind;
X Visual *visual;
X
X globav = av; globac = ac;
X strcpy(displayname,"");
X while (--ac > 0)
X if (!strcmp(*++av,"-display") && ac > 0)
X { ac--; strcpy(displayname,*++av);
X }
X
X av = globav; ac = globac;
X mydisplay = XOpenDisplay(displayname);
X if (!mydisplay)
X { fprintf(stderr,"xsquclock: Cannot open display: %s\n",displayname); exit(1);
X }
X myscreen = DefaultScreen(mydisplay);
X
X verbose = FALSE; borderlen = 1; intervall = 1;
X XGetWindowAttributes(mydisplay,XRootWindow(mydisplay,myscreen),&wind);
X oldh = myhint.height = oldw = myhint.width = (delta << 4);
X myhint.x = wind.x + (wind.width - myhint.width) / 2;
X myhint.y = wind.y + (wind.height - myhint.height) / 2;
X sprintf(defgeometry,"%dx%d+%d+%d",myhint.width,myhint.height,myhint.x,myhint.y);
X while (--ac > 0)
X { ++av;
X if (!strcmp(*av,"-update") && ac > 0)
X { ac--; intervall = atoi(*++av);
X }
X else if (!strcmp(*av,"-bw") && ac > 0)
X { ac--; borderlen = atoi(*++av);
X }
X else if (!strcmp(*av,"-geometry") && ac > 0)
X { ac--; strcpy(globstr,*++av);
X XGeometry(mydisplay,myscreen,globstr,defgeometry,borderlen,
X 1,1,0,0,&myhint.x,&myhint.y,&myhint.width,&myhint.height);
X delta = MIN(myhint.height,myhint.width) >> 4;
X myhint.height = myhint.width = (delta << 4);
X }
X else if (!strcmp(*av,"-verbose")) verbose = TRUE;
X else if (!strcmp(*av,"-rv")) reverse = TRUE;
X }
X visual = XDefaultVisual(mydisplay,myscreen);
X XSync(mydisplay,1);
X Xccolors = visual->map_entries;
X if (Xccolors < 64)
X { fprintf(stderr,"To less colors for display\n");
X exit(2);
X }
X else if (verbose)
X fprintf(stderr,"Display shall provide %ld colors\n",Xccolors);
X if (visual->class == GrayScale)
X { fprintf(stderr,"But only in grey steps, bye!\n");
X exit(3);
X }
X else if (visual->class == TrueColor)
X { fprintf(stderr,"Colormap not changeable.\n");
X }
X bitsperRGB = visual->bits_per_rgb;
X if (verbose) fprintf(stderr,"Colordepth is %d bits\n",bitsperRGB);
X if (!reverse)
X { mybackground = WhitePixel(mydisplay,myscreen);
X myforeground = BlackPixel(mydisplay,myscreen);
X if (verbose) fprintf(stderr,"Hands should be black.\n");
X }
X else
X { mybackground = BlackPixel(mydisplay,myscreen);
X myforeground = WhitePixel(mydisplay,myscreen);
X if (verbose) fprintf(stderr,"Hands should be white.\n");
X }
X mywindow = XCreateSimpleWindow(mydisplay,DefaultRootWindow(mydisplay),
X myhint.x,myhint.y,myhint.width,myhint.height,
X borderlen,myforeground,mybackground);
X myhint.flags = PPosition | PSize;
X XSetStandardProperties(mydisplay,mywindow,"squclock","Squclock",None,globav,globac,&myhint);
X mygc = XCreateGC(mydisplay,mywindow,0,0);
X
X XSelectInput(mydisplay,mywindow,ExposureMask|ButtonPressMask|KeyPressMask);
X
X XMapRaised(mydisplay,mywindow); /* Jetzt wird das Fenster angezeigt */
X iniclocking();
X rootofroot = DefaultRootWindow(mydisplay);
X for (done = 0; done == 0; )
X { clocking();
X XNextEvent(mydisplay,&myevent);
X switch(myevent.type)
X { case Expose:
X if (myevent.xexpose.count) break;
X XGetGeometry(mydisplay,mywindow,&rootofroot,
X &wind.x,&wind.y,&wind.width,&wind.height,
X &wind.border_width,&wind.depth);
X if (oldw == wind.width || oldh == wind.height)
X { iniclocking(); break;
X }
X oldw = MIN(wind.width,wind.height);
X oldw -= oldw % 32;
X delta = oldw >> 4;
X if (delta < mindelta)
X { delta = mindelta; oldw = delta << 4;
X }
X wind.width = wind.height = oldh = oldw;
X XResizeWindow(mydisplay,mywindow,oldw,oldh);
X sprintf(globstr,"%dx%d+%d+%d",oldw,oldh,wind.x,wind.y);
X if (verbose) fprintf(stderr,"Geometry: %s\n",globstr);
X XGeometry(mydisplay,myscreen,globstr,defgeometry,borderlen,
X 1,1,0,0,&wind.x,&wind.y,&wind.width,&wind.height);
X iniclocking();
X break;
X case ButtonPress:
X iniclocking();
X break;
X case KeyPress:
X goto bye;
X }
X }
X bye:
X XFreeGC(mydisplay,mygc);
X XDestroyWindow(mydisplay,mywindow);
X XCloseDisplay(mydisplay);
X exit(-1);
X}
END_OF_FILE
if test 12638 -ne `wc -c <'xsquclock/xsquclock.c'`; then
echo shar: \"'xsquclock/xsquclock.c'\" unpacked with wrong size!
fi
# end of 'xsquclock/xsquclock.c'
fi
if test -f 'xsquclock/xsquclock.man' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'xsquclock/xsquclock.man'\"
else
echo shar: Extracting \"'xsquclock/xsquclock.man'\" \(2622 characters\)
sed "s/^X//" >'xsquclock/xsquclock.man' <<'END_OF_FILE'
X.TH XSQUCLOCK 1 "Aug. 6th, 1994" "X Version 11"
X.SH NAME
Xxsquclock - square clock for X color displays
X.SH SYNOPSIS
X.B xsquclock
X[\fItoolkitoptions\fP] [options]
X.SH DESCRIPTION
XThe
X.I xsquclock
Xprogram displays the time in a semi analogous form with colored squares.
XIn the 28 outer upper layer squares the hour is displayed with two full black
Xsquares. In the 60 outer lower layer squares the minute is displayed whith
Xone black square. The 36 inner upper layer squares change their color
Xrandomly at every update tick. The program also
Xgenerates the digital time string as the application title and icon title,
Xformed by
X.I ctime\fP.
XThe time is continuously updated at a frequency which may be specified by
Xthe user.
X.I xsquclock
Xterminates if it gets a KeyPress event.
X.SH OPTIONS
X.I xsquclock
Xaccepts most of the standard X Toolkit command line options along with the
Xadditional options listed below:
X.TP 8
X.B \-update \fIseconds\fP
XThis option specifies the frequency in seconds at which \fIxsquclock\fP
Xshould update its display. If the clock is obscured and then exposed,
Xit will be updated immediately. It'll also be updated if the clock
Xwindow is clicked at. The default update frequency is 1 second.
X.TP 8
X.B \-verbose
XThis option tolds \fIxsquclock\fP to print some information, for instance
Xits new geometry if window size was changed.
X.PP
XThe following standard X Toolkit command line arguments are commonly used with
X.I xsquclock:
X.TP 8
X.B \-bw \fInumber\fP
XThis option specifies the width in pixels of the border surrounding the window.
X.TP 8
X.B \-rv
XThis option indicates that reverse video should be simulated by swapping
Xthe foreground and background colors. If the reverse video option is on,
Xthe hours and minutes are displayed with white squares rather than with
Xblack squares.
X.TP 8
X.B \-geometry \fIgeometry\fP
XThis option specifies the preferred size and position of the clock window.
X.TP 8
X.B \-display \fIhost\fP:\fIdisplay\fP
XThis option specifies the X server to contact.
X.SH X DEFAULTS
XThis program don't uses any X Toolkit widget.
X.SH ENVIRONMENT
XPlease note that
X.I xsquclock
Xis only useful on color displays. Also it is neccessary to have many
Xcolors that are obviously different to black or white to have a
Xgood chance to recognize the time correctly.
X.SH "SEE ALSO"
XX(1), time(3C)
X.SH KNOWN BUGS
X.I xsquclock
Xbelieves the system clock, uses \fItime\fP to determine the clock layout,
Xand uses \fIctime\fP to generate window title and icon title. So it is
Xpossible that window title and clock are showing different times!
X.SH UNKNOWN BUGS
XCountless.
X.SH AUTHOR
XJens Dengler (TUB)
X
END_OF_FILE
if test 2622 -ne `wc -c <'xsquclock/xsquclock.man'`; then
echo shar: \"'xsquclock/xsquclock.man'\" unpacked with wrong size!
fi
# end of 'xsquclock/xsquclock.man'
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 must unpack the following archives:
echo " " ${MISSING}
fi
exit 0
exit 0 # Just in case...
--
// ch...@Sterling.COM | Send comp.sources.x submissions to:
\X/ Amiga: The only way to fly! | sour...@sterling.com
GCS d++(--) h++ s++:+ g+++(?) p? au(*)(0) a w+ v-(*) C++ US+++ P+ L+ 3 N++ K
!W M V-- -po+ Y+ t+ 5++ j- r+ G+ v b+++ D- b-- e+ u+ h- f+ r+++ !n y+++

0 new messages