home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
x
/
volume14
/
tclock
/
part01
next >
Wrap
Internet Message Format
|
1991-08-27
|
41KB
Path: uunet!cs.utexas.edu!sun-barr!cronkite.Central.Sun.COM!exodus!austin.eds.com
From: mayoff@austin.eds.com (Rob Mayoff)
Newsgroups: comp.sources.x
Subject: v14i017: tclock -- transparent clock, Part01/01
Message-ID: <19139@exodus.Eng.Sun.COM>
Date: 28 Aug 91 01:31:42 GMT
Sender: news@exodus.Eng.Sun.COM
Lines: 1231
Approved: argv@sun.com
Submitted-by: mayoff@austin.eds.com (Rob Mayoff)
Posting-number: Volume 14, Issue 17
Archive-name: tclock/part01
+----------+
Moderator's note:
If you don't have the shape extension *built into your server*, then
this program won't work. Just because you may have -lXext doesn't
mean you have the shape extensions. If it doesn't work for you,
this program is just like a simple analog clock (that doesn't resize).
(also be sure to run xmkmf to make a new Makefile from the Imakefile.)
--dan
+----------+
An oft-asked question on comp.windows.x is "how do I make a transparent
window?" The program that follows, "tclock", uses the SHAPE extension
to display an analog clock with a "transparent" face.
#!/bin/sh
echo tclock/
mkdir tclock
echo tclock/Makefile
cat > tclock/Makefile << \END_OF_Makefile
# Makefile generated by imake - do not edit!
# $XConsortium: imake.c,v 1.51 89/12/12 12:37:30 jim Exp $
#
# The cpp used on this machine replaces all newlines and multiple tabs and
# spaces in a macro expansion with a single space. Imake tries to compensate
# for this, but is not always successful.
#
###########################################################################
# Makefile generated from "Imake.tmpl" and <Imakefile>
# $XConsortium: Imake.tmpl,v 1.77 89/12/18 17:01:37 jim Exp $
#
# Platform-specific parameters may be set in the appropriate .cf
# configuration files. Site-wide parameters may be set in the file
# site.def. Full rebuilds are recommended if any parameters are changed.
#
# If your C preprocessor doesn't define any unique symbols, you'll need
# to set BOOTSTRAPCFLAGS when rebuilding imake (usually when doing
# "make Makefile", "make Makefiles", or "make World").
#
# If you absolutely can't get imake to work, you'll need to set the
# variables at the top of each Makefile as well as the dependencies at the
# bottom (makedepend will do this automatically).
#
###########################################################################
# platform-specific configuration parameters - edit sun.cf to change
# platform: $XConsortium: sun.cf,v 1.38 89/12/23 16:10:10 jim Exp $
# operating system: SunOS 4.1.1
###########################################################################
# site-specific configuration parameters - edit site.def to change
# site: $XConsortium: site.def,v 1.21 89/12/06 11:46:50 jim Exp $
SHELL = /bin/sh
TOP = .
CURRENT_DIR = .
AR = ar cq
BOOTSTRAPCFLAGS =
CC = cc
COMPRESS = compress
CPP = /lib/cpp $(STD_CPP_DEFINES)
PREPROCESSCMD = cc -E $(STD_CPP_DEFINES)
INSTALL = install
LD = ld
LINT = lint
LINTLIBFLAG = -C
LINTOPTS = -axz
LN = ln -s
MAKE = make
MV = mv
CP = cp
RANLIB = ranlib
RANLIBINSTFLAGS =
RM = rm -f
STD_INCLUDES =
STD_CPP_DEFINES =
STD_DEFINES =
EXTRA_LOAD_FLAGS =
EXTRA_LIBRARIES =
TAGS = ctags
SHAREDCODEDEF = -DSHAREDCODE
SHLIBDEF = -DSUNSHLIB
PROTO_DEFINES =
INSTPGMFLAGS =
INSTBINFLAGS = -m 0755
INSTUIDFLAGS = -m 4755
INSTLIBFLAGS = -m 0664
INSTINCFLAGS = -m 0444
INSTMANFLAGS = -m 0444
INSTDATFLAGS = -m 0444
INSTKMEMFLAGS = -m 4755
DESTDIR =
TOP_INCLUDES = -I$(INCROOT)
CDEBUGFLAGS = -O
CCOPTIONS =
COMPATFLAGS =
ALLINCLUDES = $(STD_INCLUDES) $(TOP_INCLUDES) $(INCLUDES) $(EXTRA_INCLUDES)
ALLDEFINES = $(ALLINCLUDES) $(STD_DEFINES) $(PROTO_DEFINES) $(DEFINES) $(COMPATFLAGS)
CFLAGS = $(CDEBUGFLAGS) $(CCOPTIONS) $(ALLDEFINES)
LINTFLAGS = $(LINTOPTS) -DLINT $(ALLDEFINES)
LDLIBS = $(SYS_LIBRARIES) $(EXTRA_LIBRARIES)
LDOPTIONS = $(CDEBUGFLAGS) $(CCOPTIONS)
LDCOMBINEFLAGS = -X -r
MACROFILE = sun.cf
RM_CMD = $(RM) *.CKP *.ln *.BAK *.bak *.o core errs ,* *~ *.a .emacs_* tags TAGS make.log MakeOut
IMAKE_DEFINES =
IRULESRC = $(CONFIGDIR)
IMAKE_CMD = $(IMAKE) -DUseInstalled -I$(IRULESRC) $(IMAKE_DEFINES)
ICONFIGFILES = $(IRULESRC)/Imake.tmpl $(IRULESRC)/Imake.rules \
$(IRULESRC)/Project.tmpl $(IRULESRC)/site.def \
$(IRULESRC)/$(MACROFILE) $(EXTRA_ICONFIGFILES)
###########################################################################
# X Window System Build Parameters
# $XConsortium: Project.tmpl,v 1.63 89/12/18 16:46:44 jim Exp $
###########################################################################
# X Window System make variables; this need to be coordinated with rules
# $XConsortium: Project.tmpl,v 1.63 89/12/18 16:46:44 jim Exp $
PATHSEP = /
USRLIBDIR = $(DESTDIR)/usr/local/lib
BINDIR = $(DESTDIR)/usr/local/bin/X11
INCROOT = $(DESTDIR)/usr/local/include
BUILDINCROOT = $(TOP)
BUILDINCDIR = $(BUILDINCROOT)/X11
BUILDINCTOP = ..
INCDIR = $(INCROOT)/X11
ADMDIR = $(DESTDIR)/usr/local/adm
LIBDIR = $(USRLIBDIR)/X11
CONFIGDIR = $(LIBDIR)/config
LINTLIBDIR = $(USRLIBDIR)/lint
FONTDIR = $(LIBDIR)/fonts
XINITDIR = $(LIBDIR)/xinit
XDMDIR = $(LIBDIR)/xdm
AWMDIR = $(LIBDIR)/awm
TWMDIR = $(LIBDIR)/twm
GWMDIR = $(LIBDIR)/gwm
MANPATH = $(DESTDIR)/usr/local/man
MANSOURCEPATH = $(MANPATH)/man
MANDIR = $(MANSOURCEPATH)n
LIBMANDIR = $(MANSOURCEPATH)3
XAPPLOADDIR = $(LIBDIR)/app-defaults
SOXLIBREV = 4.2
SOXTREV = 4.0
SOXAWREV = 4.0
SOOLDXREV = 4.0
SOXMUREV = 4.0
SOXEXTREV = 4.0
FONTCFLAGS = -t
INSTAPPFLAGS = $(INSTDATFLAGS)
IMAKE = imake
DEPEND = makedepend
RGB = rgb
FONTC = bdftosnf
MKFONTDIR = mkfontdir
MKDIRHIER = /bin/sh $(BINDIR)/mkdirhier.sh
CONFIGSRC = $(TOP)/config
CLIENTSRC = $(TOP)/clients
DEMOSRC = $(TOP)/demos
LIBSRC = $(TOP)/lib
FONTSRC = $(TOP)/fonts
INCLUDESRC = $(TOP)/X11
SERVERSRC = $(TOP)/server
UTILSRC = $(TOP)/util
SCRIPTSRC = $(UTILSRC)/scripts
EXAMPLESRC = $(TOP)/examples
CONTRIBSRC = $(TOP)/../contrib
DOCSRC = $(TOP)/doc
RGBSRC = $(TOP)/rgb
DEPENDSRC = $(UTILSRC)/makedepend
IMAKESRC = $(CONFIGSRC)
XAUTHSRC = $(LIBSRC)/Xau
XLIBSRC = $(LIBSRC)/X
XMUSRC = $(LIBSRC)/Xmu
TOOLKITSRC = $(LIBSRC)/Xt
AWIDGETSRC = $(LIBSRC)/Xaw
OLDXLIBSRC = $(LIBSRC)/oldX
XDMCPLIBSRC = $(LIBSRC)/Xdmcp
BDFTOSNFSRC = $(FONTSRC)/bdftosnf
MKFONTDIRSRC = $(FONTSRC)/mkfontdir
EXTENSIONSRC = $(TOP)/extensions
DEPEXTENSIONLIB = $(USRLIBDIR)/libXext.a
EXTENSIONLIB = -lXext
DEPXLIB = $(DEPEXTENSIONLIB)
XLIB = $(EXTENSIONLIB) -lX11
DEPXAUTHLIB = $(USRLIBDIR)/libXau.a
XAUTHLIB = -lXau
DEPXMULIB =
XMULIB = -lXmu
DEPOLDXLIB =
OLDXLIB = -loldX
DEPXTOOLLIB =
XTOOLLIB = -lXt
DEPXAWLIB =
XAWLIB = -lXaw
LINTEXTENSIONLIB = $(USRLIBDIR)/llib-lXext.ln
LINTXLIB = $(USRLIBDIR)/llib-lX11.ln
LINTXMU = $(USRLIBDIR)/llib-lXmu.ln
LINTXTOOL = $(USRLIBDIR)/llib-lXt.ln
LINTXAW = $(USRLIBDIR)/llib-lXaw.ln
DEPLIBS = $(DEPXAWLIB) $(DEPXMULIB) $(DEPXTOOLLIB) $(DEPXLIB)
DEPLIBS1 = $(DEPLIBS)
DEPLIBS2 = $(DEPLIBS)
DEPLIBS3 = $(DEPLIBS)
###########################################################################
# Imake rules for building libraries, programs, scripts, and data files
# rules: $XConsortium: Imake.rules,v 1.67 89/12/18 17:14:15 jim Exp $
###########################################################################
# start of Imakefile
DEFINES = -DSHAPE -DMITSHM -DMULTIBUFFER -DMITMISC
SYS_LIBRARIES = -lm
LOCAL_LIBRARIES = $(XLIB)
SRCS = tclock.c
OBJS = tclock.o
PROGRAM = tclock
all:: tclock
tclock: $(OBJS) $(DEPLIBS)
$(RM) $@
$(CC) -o $@ $(OBJS) $(LDOPTIONS) $(LOCAL_LIBRARIES) $(LDLIBS) $(EXTRA_LOAD_FLAGS)
saber_tclock:
#load $(ALLDEFINES) $(SRCS) $(LOCAL_LIBRARIES) $(SYS_LIBRARIES) $(EXTRA_LIBRARIES)
osaber_tclock:
#load $(ALLDEFINES) $(OBJS) $(LOCAL_LIBRARIES) $(SYS_LIBRARIES) $(EXTRA_LIBRARIES)
install:: tclock
$(INSTALL) -c $(INSTPGMFLAGS) tclock $(BINDIR)
install.man:: tclock.man
$(INSTALL) -c $(INSTMANFLAGS) tclock.man $(MANDIR)/tclock.n
depend::
$(DEPEND) -s "# DO NOT DELETE" -- $(ALLDEFINES) -- $(SRCS)
lint:
$(LINT) $(LINTFLAGS) $(SRCS) $(LINTLIBS)
lint1:
$(LINT) $(LINTFLAGS) $(FILE) $(LINTLIBS)
clean::
$(RM) $(PROGRAM)
###########################################################################
# common rules for all Makefiles - do not edit
emptyrule::
clean::
$(RM_CMD) \#*
Makefile::
-@if [ -f Makefile ]; then \
echo " $(RM) Makefile.bak; $(MV) Makefile Makefile.bak"; \
$(RM) Makefile.bak; $(MV) Makefile Makefile.bak; \
else exit 0; fi
$(IMAKE_CMD) -DTOPDIR=$(TOP) -DCURDIR=$(CURRENT_DIR)
tags::
$(TAGS) -w *.[ch]
$(TAGS) -xw *.[ch] > TAGS
saber:
#load $(ALLDEFINES) $(SRCS)
osaber:
#load $(ALLDEFINES) $(OBJS)
###########################################################################
# empty rules for directories that do not have SUBDIRS - do not edit
install::
@echo "install in $(CURRENT_DIR) done"
install.man::
@echo "install.man in $(CURRENT_DIR) done"
Makefiles::
includes::
###########################################################################
# dependencies generated by makedepend
END_OF_Makefile
echo tclock/patchlevel.h
cat > tclock/patchlevel.h << \END_OF_patchlevel.h
Version 1.0, Patchlevel 0
END_OF_patchlevel.h
echo tclock/Imakefile
cat > tclock/Imakefile << \END_OF_Imakefile
DEFINES = ExtensionDefines
SYS_LIBRARIES = -lm
LOCAL_LIBRARIES = $(XLIB)
SRCS = tclock.c
OBJS = tclock.o
ComplexProgramTarget(tclock)
END_OF_Imakefile
echo tclock/tclock.c
cat > tclock/tclock.c << \END_OF_tclock.c
/*
* tclock.c Tclock creates a "transparent" clock for the X Window System
* using the shaped-window extension of X11R4.
*
* Copyright (C) 1991 Rob Mayoff.
*
* E-mail: mayoff@ccwf.cc.utexas.edu
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 1, or (at your option)
* any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <stdio.h>
#include <math.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xos.h>
#include <X11/Xresource.h>
#include <X11/extensions/shape.h>
#include <signal.h>
#include <errno.h>
#include "defaults.h"
#define HOURHAND 0
#define MINUTEHAND 1
#define SECONDHAND 2
#define NUMHANDS 3
#define NUMVERTICES 5
typedef struct
{
XPoint vertex[NUMVERTICES];
int offset[NUMVERTICES];
int radius[NUMVERTICES];
int position;
} Hand;
Display *display;
int screen_number;
Window rootWindow, mainWindow;
int ShapeEventNumber, ShapeErrorNumber;
long clock;
struct tm lastTimes, times;
Pixmap border, clip;
GC clearGC, drawGC;
double cos60[60], sin60[60];
Hand hand[NUMHANDS];
XArc tick[12];
XrmDatabase db;
int clockRadius;
int tickRadius;
int tickSize;
double scale;
char appName[200], appClass[200];
XSizeHints mainSize, savedHints;
char *
getOption(o)
char *o;
{
XrmValue value;
char *type, key[200], keyClass[200], *p;
/* Make the main key */
sprintf(key, "%s.%s", appName, o);
/* Make the class key */
sprintf(keyClass, "%s.%s", appClass, o);
for(p = keyClass; *p; p++)
if(*p == '.' && *(p+1))
*(p+1) = toupper(*(p+1));
if(XrmGetResource(db, key, keyClass, &type, &value))
return value.addr;
else
return 0;
}
void
initHand(h, s)
int h; /* Hand to initialize */
char *s; /* Name of hand */
{
char rn[1000]; /* Resource name */
static
char *vn[NUMVERTICES-1] = /* Names of vertices */
{ "tip", "right", "middle", "left" };
int i;
clockRadius = -1;
for(i = 0; i < NUMVERTICES-1; i++)
{
sprintf(rn, "%s.%s.radius", s, vn[i]);
hand[h].radius[i] = scale * atoi(getOption(rn)) + 0.5;
if(clockRadius < hand[h].radius[i])
clockRadius = hand[h].radius[i];
sprintf(rn, "%s.%s.offset", s, vn[i]);
hand[h].offset[i] = atoi(getOption(rn));
}
hand[h].radius[i] = hand[h].radius[0];
hand[h].offset[i] = hand[h].offset[0];
}
void
initMisc()
{
int i, j;
extern
double atof();
for(i=0; i<60; i++)
{
cos60[i] = cos((double)i * M_PI * 2.0 / 60);
sin60[i] = sin((double)i * M_PI * 2.0 / 60);
}
initHand(HOURHAND, "hour");
initHand(MINUTEHAND, "minute");
initHand(SECONDHAND, "second");
tickRadius = scale * atoi(getOption("tick.radius")) + 0.5;
tickSize = scale * atoi(getOption("tick.size")) + 0.5;
if((tickRadius + tickSize) > clockRadius)
clockRadius = tickRadius+tickSize;
for(i=0; i<12; i++)
{
j = (i + 9) % 12;
tick[i].x =
0.5 + (double)clockRadius + (double)cos60[j*5] * tickRadius - tickSize;
tick[i].y =
0.5 + (double)clockRadius + (double)sin60[j*5] * tickRadius - tickSize;
tick[i].width = tick[i].height = tickSize*2;
tick[i].angle1 = 0;
tick[i].angle2 = 360*64;
}
}
void drawHand(h, p)
int h; /* Hand number to draw */
int p; /* Position at which to draw it */
{
int i, j;
if(p != hand[h].position)
{
hand[h].position = p;
for(j = 0; j < NUMVERTICES - 1; j++)
{
i = (p + 45 + hand[h].offset[j]);
while(i >= 60) i-=60;
hand[h].vertex[j].x =
hand[h].radius[j] * cos60[i] + 0.5 + clockRadius;
hand[h].vertex[j].y =
hand[h].radius[j] * sin60[i] + 0.5 + clockRadius;
}
/* Close the polygon for XDrawLines (sigh) */
hand[h].vertex[j] = hand[h].vertex[0];
}
XFillPolygon(display, clip, drawGC, hand[h].vertex, NUMVERTICES-1,
Nonconvex, CoordModeOrigin);
XDrawLines(display, clip, clearGC, hand[h].vertex, NUMVERTICES,
CoordModeOrigin);
XFillPolygon(display, border, drawGC, hand[h].vertex, NUMVERTICES-1,
Nonconvex, CoordModeOrigin);
XDrawLines(display, border, drawGC, hand[h].vertex, NUMVERTICES,
CoordModeOrigin);
}
void
reshape()
{
XFillRectangle(display, border, clearGC, 0, 0,
clockRadius*2+1, clockRadius*2+1);
XFillRectangle(display, clip, clearGC, 0, 0,
clockRadius*2+1, clockRadius*2+1);
if(tickRadius > 0)
{
XFillArcs(display, clip, drawGC, tick, 12);
XDrawArcs(display, clip, clearGC, tick, 12);
XFillArcs(display, border, drawGC, tick, 12);
XDrawArcs(display, border, drawGC, tick, 12);
}
if(hand[SECONDHAND].radius[0])
drawHand(SECONDHAND, times.tm_sec);
if(hand[MINUTEHAND].radius[0])
drawHand(MINUTEHAND, times.tm_min);
if(hand[HOURHAND].radius[0])
drawHand(HOURHAND, times.tm_hour); /* Hour converted in sigalrm() */
XShapeCombineMask(display, mainWindow, ShapeBounding, 0, 0, border, ShapeSet);
XShapeCombineMask(display, mainWindow, ShapeClip, 0, 0, clip, ShapeSet);
XFlush(display, 1);
/* This call to XPending ensures that if the window gets closed, we die */
XPending(display);
}
XTextProperty *
strToTP(s)
char *s;
{
extern
char *malloc();
XTextProperty *tp = (XTextProperty *)malloc(sizeof *tp);
XStringListToTextProperty(&s, 1, tp);
return tp;
}
int
sigalrm()
{
clock = time(0);
times = *localtime(&clock);
times.tm_hour = times.tm_hour * 5 + times.tm_min / 12;
reshape();
}
unsigned long
getColor(c)
char *c;
{
XColor color;
if(!XParseColor(display, DefaultColormap(display, screen_number),
c, &color))
return 0;
XAllocColor(display, DefaultColormap(display, screen_number), &color);
return color.pixel;
}
void
usage(name)
char *name;
{
fprintf(stderr, "usage: %s [options]\n", name);
fprintf(stderr, "Options: (options followed by resource equivalents)\n");
fprintf(stderr, " -background .background Background color\n");
fprintf(stderr, " -bg .background ...\n");
fprintf(stderr, " -border .border Border color\n");
fprintf(stderr, " -borderWidth .borderWidth Border width\n");
fprintf(stderr, " -display .display X server name\n");
fprintf(stderr, " -geometry .geometry Clock location\n");
fprintf(stderr, " -scale .scale Scaling factor\n");
fprintf(stderr, " -tickradius .tick.radius Tick distance\n");
fprintf(stderr, " -ticksize .tick.size Tick size\n");
fprintf(stderr, " -width .borderWidth Border width\n");
fprintf(stderr, " -xrm other resources\n");
fprintf(stderr, "See defaults.h for other resources. A tick radius of\n");
fprintf(stderr, "zero will disable tick marks, for those who like a very\n");
fprintf(stderr, "abstract clock. The size part of the geometry strin\n");
fprintf(stderr, "is ignored - use -scale to adjust the clock size.\n");
fprintf(stderr, "\nTclock version 1.0, Copyright (C) 1991 Rob Mayoff.\n");
fprintf(stderr, "Tclock comes with ABSOLUTELY NO WARRANTY. This is free software, and\n");
fprintf(stderr, "you are welcome to redistribute it under certain conditions; see the file\n");
fprintf(stderr, "COPYING included with the distribution for details.\n");
}
void
makeAppName(r)
char *r;
{
char *p;
for(p = r+strlen(r); p >= r && *p != '/'; p--)
;
strcpy(appName, ++p);
strcpy(appClass, "Tclock");
}
void
main(ac, av)
int ac;
char **av;
{
XSetWindowAttributes mainAtts;
XWMHints mainWM;
XClassHint mainClass;
struct itimerval old, new;
int sigalrm();
XGCValues gcv;
XrmDatabase cmdDB;
extern
char *getenv();
char *displayName, fn[1000];
int parseReturn, rc;
XrmParseCommand(&db, option, numOptions, "tclock", &ac, av);
if(ac>1)
{
usage(av[0]);
exit(1);
}
makeAppName(av[0]);
displayName = getOption("display");
cmdDB = db;
if(!displayName)
displayName = getenv("DISPLAY");
if(!displayName)
displayName = ":0";
display = XOpenDisplay(displayName);
if(display == 0)
{
fprintf("Couldn't open display %s\n", displayName);
exit(-1);
}
screen_number = DefaultScreen(display);
rootWindow = RootWindow(display, screen_number);
if(!XShapeQueryExtension(display, &ShapeEventNumber, &ShapeErrorNumber))
exit(1);
db = XrmGetStringDatabase(tclockDefaults);
XrmMergeDatabases(XrmGetStringDatabase(XResourceManagerString(display), &db));
sprintf(fn, "%s/.Xdefaults", getenv("HOME"));
if(access(fn, R_OK) == 0)
XrmMergeDatabases(XrmGetFileDatabase(fn), &db);
if(getenv("XENVIRONMENT") && access(getenv("XENVIRONMENT")) == 0)
XrmMergeDatabases(XrmGetFileDatabase(getenv("XENVIRONMENT")), &db);
XrmMergeDatabases(cmdDB, &db);
scale = atof(getOption("scale"));
initMisc();
if(getOption("geometry"))
parseReturn = XParseGeometry(getOption("geometry"), &(mainSize.x),
&(mainSize.y), &(mainSize.width), &(mainSize.height));
else
parseReturn = NoValue;
mainSize.width = clockRadius*2+1;
mainSize.height = clockRadius*2+1;
mainSize.flags = 0;
if(parseReturn&(XValue|YValue))
{
mainSize.flags = USPosition;
if(parseReturn&XValue && parseReturn&XNegative)
mainSize.x =
DisplayWidth(display, screen_number) - mainSize.width + mainSize.x-1;
if(parseReturn&YValue && parseReturn&YNegative)
mainSize.y =
DisplayHeight(display, screen_number) - mainSize.height + mainSize.y-1;
}
mainAtts.border_pixel = getColor(getOption("border"));
mainAtts.background_pixel = getColor(getOption("background"));
mainAtts.save_under = 1;
mainAtts.event_mask = StructureNotifyMask|ButtonPressMask|ButtonReleaseMask;
mainAtts.do_not_propagate_mask = 0;
mainWindow = XCreateWindow(display, rootWindow,
mainSize.x, mainSize.y, mainSize.width, mainSize.height,
0, DefaultDepth(display, screen_number), InputOutput,
DefaultVisual(display, screen_number),
CWBorderPixel|CWBackPixel|CWSaveUnder|CWEventMask|CWDontPropagate,
&mainAtts);
savedHints = mainSize;
mainWM.flags = 0;
mainClass.res_name = mainClass.res_class = "xclock";
XSetWMProperties(display, mainWindow, strToTP("xclock"), strToTP("xclock"),
av, ac, &mainSize, &mainWM, &mainClass);
border = XCreatePixmap(display, mainWindow, clockRadius*2+1, clockRadius*2+1, 1);
clip = XCreatePixmap(display, mainWindow, clockRadius*2+1, clockRadius*2+1, 1);
gcv.function = GXclear;
gcv.join_style = JoinMiter;
gcv.line_width = atoi(getOption("borderWidth"));
clearGC = XCreateGC(display, border,
GCFunction|GCJoinStyle|GCLineWidth, &gcv);
gcv.function = GXset;
drawGC = XCreateGC(display, border,
GCFunction|GCJoinStyle|GCLineWidth, &gcv);
sigalrm();
XMapRaised(display, mainWindow);
XFlush(display);
signal(SIGALRM, sigalrm);
new.it_interval.tv_sec = 1;
new.it_value.tv_sec = 1;
new.it_interval.tv_usec = 0;
new.it_value.tv_usec = 0;
setitimer(ITIMER_REAL, &new, &old);
for(;;)
sigpause(0);
}
END_OF_tclock.c
echo tclock/defaults.h
cat > tclock/defaults.h << \END_OF_defaults.h
/*
* defaults.h This provides the defaults and the command line argument
* database for tclock.
*
* Copyright (C) 1991 Rob Mayoff.
*
* E-mail: mayoff@ccwf.cc.utexas.edu
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 1, or (at your option)
* any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
char *tclockDefaults =
"\
Tclock.Scale: 1\n\
Tclock.Border: white\n\
Tclock.Background: black\n\
Tclock.BorderWidth: 0\n\
\
Tclock.Hour.Tip.Radius: 60\n\
Tclock.Hour.Tip.Offset: 0\n\
Tclock.Hour.Right.Radius: 20\n\
Tclock.Hour.Right.Offset: 26\n\
Tclock.Hour.Middle.Radius: 10\n\
Tclock.Hour.Middle.Offset: 30\n\
Tclock.Hour.Left.Radius: 20\n\
Tclock.Hour.Left.Offset: 34\n\
\
Tclock.Minute.Tip.Radius: 100\n\
Tclock.Minute.Tip.Offset: 0\n\
Tclock.Minute.Right.Radius: 20\n\
Tclock.Minute.Right.Offset: 26\n\
Tclock.Minute.Middle.Radius: 10\n\
Tclock.Minute.Middle.Offset: 30\n\
Tclock.Minute.Left.Radius: 20\n\
Tclock.Minute.Left.Offset: 34\n\
\
Tclock.Second.Tip.Radius: 100\n\
Tclock.Second.Tip.Offset: 0\n\
Tclock.Second.Right.Radius: 3\n\
Tclock.Second.Right.Offset: 26\n\
Tclock.Second.Middle.Radius: 30\n\
Tclock.Second.Middle.Offset: 30\n\
Tclock.Second.Left.Radius: 3\n\
Tclock.Second.Left.Offset: 34\n\
\
Tclock.Tick.Radius: 95\n\
Tclock.Tick.Size: 4\n\
";
#define SEP XrmoptionSepArg
#define XRM XrmoptionResArg
XrmOptionDescRec option[] =
{
{ "-background", ".background", SEP, 0 },
{ "-bg", ".background", SEP, 0 },
{ "-border", ".border", SEP, 0 },
{ "-borderWidth", ".borderWidth", SEP, 0 },
{ "-display", ".display", SEP, 0 },
{ "-geometry", ".geometry", SEP, 0 },
{ "-scale", ".scale", SEP, 0 },
{ "-tickradius", ".tick.radius", SEP, 0 },
{ "-ticksize", ".tick.size", SEP, 0 },
{ "-width", ".borderWidth", SEP, 0 },
{ "-xrm", 0, XRM, 0 },
};
int numOptions = (sizeof option)/(sizeof(XrmOptionDescRec));
END_OF_defaults.h
echo tclock/COPYING
cat > tclock/COPYING << \END_OF_COPYING
GNU GENERAL PUBLIC LICENSE
Version 1, February 1989
Copyright (C) 1989 Free Software Foundation, Inc.
675 Mass Ave, Cambridge, MA 02139, USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The license agreements of most software companies try to keep users
at the mercy of those companies. By contrast, our General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. The
General Public License applies to the Free Software Foundation's
software and to any other program whose authors commit to using it.
You can use it for your programs, too.
When we speak of free software, we are referring to freedom, not
price. Specifically, the General Public License is designed to make
sure that you have the freedom to give away or sell copies of free
software, that you receive source code or can get it if you want it,
that you can change the software or use pieces of it in new free
programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of a such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must tell them their rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License Agreement applies to any program or other work which
contains a notice placed by the copyright holder saying it may be
distributed under the terms of this General Public License. The
"Program", below, refers to any such program or work, and a "work based
on the Program" means either the Program or any work containing the
Program or a portion of it, either verbatim or with modifications. Each
licensee is addressed as "you".
1. You may copy and distribute verbatim copies of the Program's source
code as you receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice and
disclaimer of warranty; keep intact all the notices that refer to this
General Public License and to the absence of any warranty; and give any
other recipients of the Program a copy of this General Public License
along with the Program. You may charge a fee for the physical act of
transferring a copy.
2. You may modify your copy or copies of the Program or any portion of
it, and copy and distribute such modifications under the terms of Paragraph
1 above, provided that you also do the following:
a) cause the modified files to carry prominent notices stating that
you changed the files and the date of any change; and
b) cause the whole of any work that you distribute or publish, that
in whole or in part contains the Program or any part thereof, either
with or without modifications, to be licensed at no charge to all
third parties under the terms of this General Public License (except
that you may choose to grant warranty protection to some or all
third parties, at your option).
c) If the modified program normally reads commands interactively when
run, you must cause it, when started running for such interactive use
in the simplest and most usual way, to print or display an
announcement including an appropriate copyright notice and a notice
that there is no warranty (or else, saying that you provide a
warranty) and that users may redistribute the program under these
conditions, and telling the user how to view a copy of this General
Public License.
d) You may charge a fee for the physical act of transferring a
copy, and you may at your option offer warranty protection in
exchange for a fee.
Mere aggregation of another independent work with the Program (or its
derivative) on a volume of a storage or distribution medium does not bring
the other work under the scope of these terms.
3. You may copy and distribute the Program (or a portion or derivative of
it, under Paragraph 2) in object code or executable form under the terms of
Paragraphs 1 and 2 above provided that you also do one of the following:
a) accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of
Paragraphs 1 and 2 above; or,
b) accompany it with a written offer, valid for at least three
years, to give any third party free (except for a nominal charge
for the cost of distribution) a complete machine-readable copy of the
corresponding source code, to be distributed under the terms of
Paragraphs 1 and 2 above; or,
c) accompany it with the information you received as to where the
corresponding source code may be obtained. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form alone.)
Source code for a work means the preferred form of the work for making
modifications to it. For an executable file, complete source code means
all the source code for all modules it contains; but, as a special
exception, it need not include source code for modules which are standard
libraries that accompany the operating system on which the executable
file runs, or for standard header files or definitions files that
accompany that operating system.
4. You may not copy, modify, sublicense, distribute or transfer the
Program except as expressly provided under this General Public License.
Any attempt otherwise to copy, modify, sublicense, distribute or transfer
the Program is void, and will automatically terminate your rights to use
the Program under this License. However, parties who have received
copies, or rights to use copies, from you under this General Public
License will not have their licenses terminated so long as such parties
remain in full compliance.
5. By copying, distributing or modifying the Program (or any work based
on the Program) you indicate your acceptance of this license to do so,
and all its terms and conditions.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the original
licensor to copy, distribute or modify the Program subject to these
terms and conditions. You may not impose any further restrictions on the
recipients' exercise of the rights granted herein.
7. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of the license which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
the license, you may choose any version ever published by the Free Software
Foundation.
8. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
Appendix: How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to humanity, the best way to achieve this is to make it
free software which everyone can redistribute and change under these
terms.
To do so, attach the following notices to the program. It is safest to
attach them to the start of each source file to most effectively convey
the exclusion of warranty; and each file should have at least the
"copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) 19yy <name of author>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 1, or (at your option)
any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) 19xx name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the
appropriate parts of the General Public License. Of course, the
commands you use may be called something other than `show w' and `show
c'; they could even be mouse-clicks or menu items--whatever suits your
program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the
program `Gnomovision' (a program to direct compilers to make passes
at assemblers) written by James Hacker.
<signature of Ty Coon>, 1 April 1989
Ty Coon, President of Vice
That's all there is to it!
END_OF_COPYING
echo tclock/tclock.man
cat > tclock/tclock.man << \END_OF_tclock.man
.TH TCLOCK 1 "Release 4" "X Version 11"
.SH NAME
tclock \- display time of day
.SH SYNOPSIS
.B tclock
[-option ...]
.SH DESCRIPTION
.I Tclock
displays an analog clock with a transparent face.
.SH OPTIONS
.TP 8
.B \-background \fIbackground-color\fB
specify the color of the interior of the clock
.TP 8
.B \-bg \fIbackground-color\fB
same as \-background
.TP 8
.B \-border \fIborder-color\fB
specify the color of the clock border
.TP 8
.B \-borderWidth \fIborder-width\fB
specify the thickness of the border \- this is used as the line-width
attribute of a graphics context, so a border width of zero still results
in a thin border. If you want \fIno\fP border at all, make the border
color the same as the background color.
.TP 8
.B \-display \fIdisplay-name\fB
specify the name of the display to use
.TP 8
.B \-geometry \fIclock-geometry\fB
specify the geometry of the clock. Note that the size specification of
this string will be ignored; see the \fI\-scale\fP option for changing
the size of the clock.
.TP 8
.B \-scale \fIclock-size\fB
specify the size of the clock as a scale of the normal size. For example,
\-scale 0.5 results in a clock half the size of the default (in width
and height - one-fourth the size in area), and \-scale 2.5 results in a
clock two and one-half times larger.
.TP 8
.B \-tickradius \fItick-distance\fB
specify the distance of each tick from the center of the clock. Specifying
zero results in no tick marks. Note that this is adjusted by the \-scale
option.
.TP 8
.B \-ticksize \fItick-size\fB
specify the radius of each tick mark. Note that this is adjusted by the
\-scale option; however, ticks do not seem to scale well, so if you regularly
start up the clock at a specific scaling amount, you may wish to fine-tune
this parameter for best results.
.TP 8
.B \-width \fIborder-width\fB
same as \-borderWidth
.TP 8
.B \-xrm \fImiscellaneous-resource\fB
specify a resource for which no command-line option exists. This is most
often used to disable the second hand by specifying \fI\-xrm
"Tclock.Second.Tip.Radius: 0".
.SH RESOURCES
.LP
The resources equivalent to command-line options are
.IP
Tclock.geometry
.br
Tclock.scale
.br
Tclock.border
.br
Tclock.background
.br
Tclock.borderWidth
.br
Tclock.tick.radius
.br
Tclock.tick.size
.LP
In addition, each hand of the clock is made up of four points. You may
specify the position of each of these four points for each hand. The hand
specifications are {hour, minute, second}, and the point specifications are
{tip, right, middle, left}. Each point has two resources:
.IP
Tclock.\fIhand\fP.\fIpoint\fP.radius
.br
Tclock.\fIhand\fP.\fIpoint\fP.offset
.LP
The radius specifies the distance in pixels of that points from the center
of the clock. The offset specifies the angle of that point as an offset in
minutes (sixtieths of a circle) from the "true" position of the hand.
Specifying a radius of zero for the tip of a hand disables that hand.
.LP
Note that after you have fine-tuned the shapes of the hands, you can simply
use the \-scale option (or the .scale resource) to get any size clock with
hands of that shape, without needing to adjust the radii of all those points.
.SH "SEE ALSO"
oclock(1), xclock(1)
.SH COPYRIGHT
Copyright (C) 1991 Rob Mayoff.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 1, or (at your option)
any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
.SH AUTHOR
Rob Mayoff (mayoff@ccwf.cc.utexas.edu)
END_OF_tclock.man
--
Dan Heller
O'Reilly && Associates Z-Code Software Comp-sources-x:
Senior Writer President comp-sources-x@uunet.uu.net
argv@ora.com argv@zipcode.com