From ccbc9f87eb59497b23bd0424ee1ed20ad7c7db54 Mon Sep 17 00:00:00 2001 From: Zygo Blaxell Date: Mon, 2 Mar 2009 00:42:20 -0500 Subject: [PATCH] http://www.ibiblio.org/pub/historic-linux/ftp-archives/sunsite.unc.edu/Sep-29-1996/X11/xutils/screensavers/xscreensaver-1.26.tar.gz -rw-r--r-- 1 zblaxell zblaxell 148692 May 24 2002 xscreensaver-1.26.tar.gz e06b9602a89be6f08963e6a0f933b1edeae68eb4 xscreensaver-1.26.tar.gz --- README | 22 +- config.h | 33 ++- driver/Imakefile | 47 ++- driver/XScreenSaver.ad | 5 +- driver/demo.c | 2 +- driver/dialogs.c | 23 +- driver/dialogs.xd | 2 +- driver/lock.c | 181 +++++++++--- driver/stderr.c | 7 +- driver/subprocs.c | 12 +- driver/timers.c | 3 +- driver/windows.c | 14 +- driver/xscreensaver-command.c | 5 +- driver/xscreensaver-command.man | 2 +- driver/xscreensaver.c | 78 +++-- driver/xscreensaver.h | 6 +- driver/xscreensaver.man | 16 +- hacks/Imakefile | 13 +- hacks/attraction.c | 95 +++++- hacks/attraction.man | 46 ++- hacks/blitspin.c | 2 +- hacks/blitspin.man | 2 +- hacks/decayscreen.c | 3 +- hacks/flame.c | 21 +- hacks/flame.man | 2 +- hacks/greynetic.c | 4 +- hacks/greynetic.man | 2 +- hacks/halo.c | 70 +++-- hacks/halo.man | 11 +- hacks/helix.c | 8 +- hacks/helix.man | 2 +- hacks/hopalong.c | 4 +- hacks/hopalong.man | 2 +- hacks/hypercube.c | 4 +- hacks/hypercube.man | 2 +- hacks/imsmap.c | 4 +- hacks/imsmap.man | 2 +- hacks/lmorph.c | 501 ++++++++++++++++++++++++++++++++ hacks/lmorph.man | 54 ++++ hacks/maze.c | 12 +- hacks/noseguy.c | 2 +- hacks/noseguy.man | 2 +- hacks/noses/CVS/Entries | 16 +- hacks/pedal.c | 4 +- hacks/pyro.c | 2 +- hacks/pyro.man | 2 +- hacks/qix.c | 16 +- hacks/qix.man | 2 +- hacks/rocks.c | 9 +- hacks/rocks.man | 2 +- hacks/rorschach.c | 2 +- hacks/rorschach.man | 2 +- hacks/screenhack.c | 2 +- hacks/screenhack.h | 51 ++-- hacks/slidescreen.c | 3 +- hacks/slidescreen.man | 2 +- hacks/xlock.h | 30 +- hacks/xroger-hack.c | 2 +- hacks/xroger.man | 2 +- utils/Imakefile | 6 +- utils/fade.c | 2 +- utils/grabscreen.c | 2 +- utils/hsv.c | 2 +- utils/resources.c | 2 +- utils/usleep.c | 2 +- utils/version.h | 2 +- utils/visual.c | 3 +- utils/xroger.c | 2 +- utils/yarandom.c | 72 +++++ utils/yarandom.h | 19 ++ 70 files changed, 1312 insertions(+), 279 deletions(-) create mode 100644 hacks/lmorph.c create mode 100644 hacks/lmorph.man create mode 100644 utils/yarandom.c create mode 100644 utils/yarandom.h diff --git a/README b/README index 8470574b..55b1ae20 100644 --- a/README +++ b/README @@ -26,8 +26,7 @@ now be used as a screensaver without modification. The programs that are being run as screensavers don't need to have any special knowledge about what it means to be a screensaver. -The XIDLE or MIT-SCREEN-SAVER server extensions will be used if you have -them (win win.) +The XIDLE or MIT-SCREEN-SAVER server extensions will be used if you have them. Unfortunately, locking doesn't work if you don't have Motif. @@ -57,6 +56,7 @@ window, which are pointed at by the screensaver's default resource settings. things. I snarfed this code from xnlock. maze - This is the X maze demo modified to take a -root option so that it works with xscreensaver. + lmorph - morphing line drawings. All of these will pop up their own window unless given that -root option. See their man pages for more details. @@ -77,16 +77,20 @@ You can get all of these from the contrib directory on ftp.x.org. If you know of (or write) any other interesting programs that can be used as screensavers, please let me know! -This program should be updated to take advantage of the new R6 `screensaver' -server extension instead of XIdle. I didn't have time to do this before the -deadline for the R6 contrib tape, but by the time you read this, maybe it's -done - check a later release. +The latest version of xscreensaver is always ftpable from ftp.x.org. You can +also get it from my web page at http://www.netscape.com/people/jwz/. -The latest version of xscreensaver is on FTP.X.ORG. - - -- Jamie Zawinski + -- Jamie Zawinski +Changes since 1.25: Added `lmorph' hack. + Added viscosity and mouse-control to attraction. + Fixed possible bad color choices in qix and attraction. + Added ramp-mode to halo. + Added a new RNG, which is faster and more portable + than using the RNG in libc. + Made locking work on SCO. + Various other minor tweaks that I don't remember. Changes since 1.24: Made it capture the stdout/stderr of its subprocesses and present them on the screensaver window itself. Made demo mode work correctly with non-default visuals diff --git a/config.h b/config.h index 02ca5f4c..17517dc8 100644 --- a/config.h +++ b/config.h @@ -3,15 +3,6 @@ * This file is included by the various Imakefiles. */ -/* Uncomment the following line if you have the MIT-SCREEN-SAVER extension - * installed. This extension resides in .../contrib/extensions/screensaver/ - * on the X11R6 contrib tape. (Turning on this flag lets XScreenSaver work - * better with servers which support this extension; but it will still work - * with servers which do not suport this extension, so it's a good idea to - * compile in support for it if you can.) - */ -/* #define HAVE_SAVER_EXTENSION */ - /* Uncomment the following line if you have the XIDLE extension installed. * This extension resides in .../contrib/extensions/xidle/ on the X11R5 * contrib tape. (Turning on this flag lets XScreenSaver work better with @@ -21,6 +12,30 @@ */ /* #define HAVE_XIDLE_EXTENSION */ +/* Uncomment the following line if you have the MIT-SCREEN-SAVER extension + * installed. This extension resides in .../contrib/extensions/screensaver/ + * on the X11R6 contrib tape. + * + * This extension does basically the same thing that the XIDLE extension does, + * but there are two things wrong with it: first, because of the way the + * extension was designed, the `fade' option to XScreenSaver will be uglier: + * just before the screen fades out, there will be an unattractive flicker to + * black, because this extension blanks the screen *before* telling us that it + * is time to do so. Second, this extension is known to be buggy; on the + * systems I use, it works, but some people have reported X server crashes as + * a result of using it. XScreenSaver uses this extension rather + * conservatively, because when I tried to use any of its more complicated + * features, I could get it to crash the server at the drop of a hat. + * + * I wish someone would port the XIDLE extension to R6. Or I wish someone + * would make the MIT-SCREEN-SAVER extension not be such a piece of junk. + * + * Note that the SGI X server also has an extension called SCREEN_SAVER. + * That is a completely different extension, and XScreenSaver contains no + * support for it (though it probably wouldn't be hard.) + */ +/* #define HAVE_SAVER_EXTENSION */ + /* Uncomment the following line if you have the XPM library installed. * Some of the demos can make use of this if it is available. */ diff --git a/driver/Imakefile b/driver/Imakefile index 0caccaf3..5444939a 100644 --- a/driver/Imakefile +++ b/driver/Imakefile @@ -7,6 +7,7 @@ #include "../config.h" +/* #### If anyone ever finishes the Athena locking code, remove this. */ #if defined(NO_MOTIF) && !defined(NO_LOCKING) # define NO_LOCKING #endif @@ -64,26 +65,33 @@ DEFINES = SETUID_DEF XIDLE_DEF SAVER_DEF MOTIF_DEF LOCKING_DEF SHADOW_DEF R5ISMS SAVERLIBS = $(XMULIB) $(XTOOLLIB) $(EXTENSIONLIB) $(XLIB) -lm COMMLIBS = $(XLIB) -lm - UTIL_SRCS = $(UTILS)/resources.c $(UTILS)/fade.c $(UTILS)/usleep.c $(UTILS)/visual.c - UTIL_OBJS = $(UTILS)/resources.o $(UTILS)/fade.o $(UTILS)/usleep.o $(UTILS)/visual.o - DBOX_SRCS = dialogs.c demo.c lock.c - DBOX_OBJS = dialogs.o demo.o lock.o + UTIL_SRCS = $(UTILS)/resources.c $(UTILS)/fade.c $(UTILS)/visual.c $(UTILS)/usleep.c $(UTILS)/yarandom.c + UTIL_OBJS = $(UTILS)/resources.o $(UTILS)/fade.o $(UTILS)/visual.o $(UTILS)/usleep.o $(UTILS)/yarandom.o + DBOX_SRCS = dialogs.c demo.c + DBOX_OBJS = dialogs.o demo.o + LOCK_SRCS = lock.c + LOCK_OBJS = lock.o SAVERSRCS = xscreensaver.c timers.c subprocs.c windows.c stderr.c SAVEROBJS = xscreensaver.o timers.o subprocs.o windows.o stderr.o - SRCS1 = $(SAVERSRCS) MOTIF_SRC $(UTIL_SRCS) - OBJS1 = $(SAVEROBJS) MOTIF_OBJ $(UTIL_OBJS) + SRCS1 = $(SAVERSRCS) MOTIF_SRC $(LOCK_SRCS) $(UTIL_SRCS) + OBJS1 = $(SAVEROBJS) MOTIF_OBJ $(LOCK_OBJS) $(UTIL_OBJS) COMMSRCS = xscreensaver-command.c COMMOBJS = xscreensaver-command.o SRCS2 = $(COMMSRCS) OBJS2 = $(COMMOBJS) MEN = xscreensaver.man xscreensaver-command.man - TARFILES = README Imakefile $(SAVERSRCS) $(DBOX_SRCS) $(COMMSRCS) \ - xscreensaver.h XScreenSaver.ad dialogs.xd $(MEN) .gdbinit + TARFILES = README Imakefile $(SAVERSRCS) $(DBOX_SRCS) $(LOCK_SRCS) \ + $(COMMSRCS) xscreensaver.h XScreenSaver.ad dialogs.xd \ + $(MEN) .gdbinit #if defined(HPArchitecture) && !defined(NO_LOCKING) EXTRA_LIBRARIES = -lXhp11 /* for XHPDisableReset() */ #endif +#if defined(i386ScoArchitecture) + SCOLIBS = -lintl -lprot -lx -lcrypt_i +#endif + all:: xscreensaver xscreensaver-command echo_tarfiles: @@ -96,7 +104,7 @@ PROGRAMS = xscreensaver xscreensaver-command #define InstallProgram(p,d) InstallProgramWithFlags(p,d,$(INSTUIDFLAGS)) #endif -ComplexProgramTarget_1(xscreensaver,MOTIF_LIB $(SAVERLIBS),$(HP_NULL_STR)) +ComplexProgramTarget_1(xscreensaver,MOTIF_LIB $(SAVERLIBS),$(SCOLIBS) $(HP_NULL_STR)) #ifdef INSTALL_SETUID #undef InstallProgram @@ -121,3 +129,24 @@ XScreenSaver.ad.h: XScreenSaver.ad clean:: $(RM) XScreenSaver.ad.h + + +#if defined(SparcArchitecture) || defined(SGIArchitecture) +# undef UsePurify +# define UsePurify +#endif + +#ifdef UsePurify + PURIFY = purify + PURIFYOPTIONS = + +# undef PurifyProgramTarget +# define PurifyProgramTarget(program,deplist,linklist) @@\ +program.pure: deplist @@\ + RemoveTargetProgram($@) @@\ + $(CCENVSETUP) $(PURIFY) $(PURIFYOPTIONS) $(CC) \ + -o $@ $(LDOPTIONS) linklist $(EXTRA_LOAD_FLAGS) + +PurifyProgramTarget(xscreensaver,$(OBJS1),$(OBJS1) MOTIF_LIB $(SAVERLIBS)) + +#endif /* Purify */ diff --git a/driver/XScreenSaver.ad b/driver/XScreenSaver.ad index 0c3656ba..da72eff8 100644 --- a/driver/XScreenSaver.ad +++ b/driver/XScreenSaver.ad @@ -45,7 +45,8 @@ hypercube -root \n\ halo -root \n\ maze -root \n\ - flame -root \n + flame -root \n\ + lmorph -root \n ! Programs on this list are run only for monochrome screens. *monoPrograms: qix -root -linear -count 5 -size 200 -spread 30 \ @@ -102,7 +103,7 @@ *demoDialog.maxWidth: 600 *label1.labelString: XScreenSaver %s -*label2.labelString: Copyright © 1991-1995 by Jamie Zawinski +*label2.labelString: Copyright © 1991-1995 by Jamie Zawinski *demoList.visibleItemCount: 10 *demoList.automaticSelection: True *next.labelString: Run Next diff --git a/driver/demo.c b/driver/demo.c index 64bd58bc..b7823400 100644 --- a/driver/demo.c +++ b/driver/demo.c @@ -1,4 +1,4 @@ -/* xscreensaver, Copyright (c) 1993-1995 Jamie Zawinski +/* xscreensaver, Copyright (c) 1993-1995 Jamie Zawinski * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that diff --git a/driver/dialogs.c b/driver/dialogs.c index b4612b5d..a403c1b8 100644 --- a/driver/dialogs.c +++ b/driver/dialogs.c @@ -73,19 +73,13 @@ Widget restart; Widget spacer; +void create_passwd_dialog( parent ) Widget parent; { - Display *display = XtDisplay ( parent ); Widget children[8]; /* Children to manage */ Arg al[64]; /* Arg List */ register int ac = 0; /* Arg Count */ - char from_s [256]; /* For font list conversion */ - XrmValue from_value, to_value; /* ditto */ - int fg, bg; /* colour values for pixmaps */ - XmString *list_items; /* For list items */ - int list_item; /* Index for list_items */ - XmString xmstrings[15]; /* temporary storage for XmStrings */ Widget widget4; Widget widget7; @@ -216,19 +210,13 @@ Widget parent; +void create_resources_dialog( parent ) Widget parent; { - Display *display = XtDisplay ( parent ); Widget children[22]; /* Children to manage */ Arg al[64]; /* Arg List */ register int ac = 0; /* Arg Count */ - char from_s [256]; /* For font list conversion */ - XrmValue from_value, to_value; /* ditto */ - int fg, bg; /* colour values for pixmaps */ - XmString *list_items; /* For list items */ - int list_item; /* Index for list_items */ - XmString xmstrings[15]; /* temporary storage for XmStrings */ Widget widget12; Widget widget13; Widget widget14; @@ -593,18 +581,13 @@ Widget parent; +void create_demo_dialog( parent ) Widget parent; { - Display *display = XtDisplay ( parent ); Widget children[11]; /* Children to manage */ Arg al[64]; /* Arg List */ register int ac = 0; /* Arg Count */ - char from_s [256]; /* For font list conversion */ - XrmValue from_value, to_value; /* ditto */ - int fg, bg; /* colour values for pixmaps */ - XmString *list_items; /* For list items */ - int list_item; /* Index for list_items */ XmString xmstrings[15]; /* temporary storage for XmStrings */ diff --git a/driver/dialogs.xd b/driver/dialogs.xd index 03640b77..ad1f6da0 100644 --- a/driver/dialogs.xd +++ b/driver/dialogs.xd @@ -424,7 +424,7 @@ object 'label1' : XmLabel { object 'label2' : XmLabel { arguments { name = 'label2'; - XmNlabelString= 'Copyright © 1991-1994 by Jamie Zawinski '; + XmNlabelString= 'Copyright © 1991-1994 by Jamie Zawinski '; }; }; object 'text_area' : XmScrolledList { diff --git a/driver/lock.c b/driver/lock.c index 244eb0ba..e4ef9824 100644 --- a/driver/lock.c +++ b/driver/lock.c @@ -1,4 +1,4 @@ -/* xscreensaver, Copyright (c) 1993-1995 Jamie Zawinski +/* xscreensaver, Copyright (c) 1993-1995 Jamie Zawinski * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that @@ -9,6 +9,16 @@ * implied warranty. */ +/* #### If anyone ever finishes the Athena locking code, remove this. + But until then, locking requires Motif. + */ +#if defined(NO_MOTIF) && !defined(NO_LOCKING) +# define NO_LOCKING +#endif + + +#ifndef NO_LOCKING + #if __STDC__ #include #include @@ -24,24 +34,41 @@ #include +#include "xscreensaver.h" + +extern char *screensaver_version; +extern char *progname; +extern XtAppContext app; +extern Bool verbose_p; + +#ifdef SCO +/* SCO has some kind of goofy, nonstandard security crap. This stuff was + donated by one of their victims, I mean users, Didier Poirot . + */ +# include +# include +# include +#endif + #if !__STDC__ # define _NO_PROTO #endif -#include -#include -#include +#ifdef NO_MOTIF -#include "xscreensaver.h" +# include +# include +# include -#ifndef NO_LOCKING +#else /* Motif */ -Time passwd_timeout; +# include +# include +# include -extern char *screensaver_version; -extern char *progname; -extern XtAppContext app; -extern Bool verbose_p; +#endif /* Motif */ + +Time passwd_timeout; extern Widget passwd_dialog; extern Widget passwd_form; @@ -71,14 +98,26 @@ static char user_passwd [255]; # define GETPW getpwnam #endif +#ifdef SCO +# define PRPWTYPE struct pr_passwd * +# define GETPRPW getprpwnam +#endif + Bool lock_init () { Bool ok = True; char *u; PWTYPE p = GETPW ("root"); + +#ifdef SCO + PRPWTYPE prpwd = GETPRPW ("root"); + if (prpwd && *prpwd->ufld.fd_encrypt) + strcpy (root_passwd, prpwd->ufld.fd_encrypt); +#else /* !SCO */ if (p && p->PWSLOT && p->PWSLOT[0] != '*') strcpy (root_passwd, p->PWSLOT); +#endif /* !SCO */ else { fprintf (stderr, "%s: couldn't get root's password\n", progname); @@ -87,9 +126,14 @@ lock_init () /* It has been reported that getlogin() returns the wrong user id on some very old SGI systems... */ - u = getlogin (); + u = (char *) getlogin (); if (u) - p = GETPW (u); + { +#ifdef SCO + prpwd = GETPRPW (u); +#endif /* SCO */ + p = GETPW (u); + } else { /* getlogin() fails if not attached to a terminal; @@ -103,11 +147,16 @@ lock_init () #endif } +#ifdef SCO + if (prpwd && *prpwd->ufld.fd_encrypt) + strcpy (user_passwd, prpwd->ufld.fd_encrypt); +#else /* !SCO */ if (p && p->PWSLOT && /* p->PWSLOT[0] != '*' */ /* sensible */ (strlen (p->PWSLOT) > 4) /* solaris */ ) strcpy (user_passwd, p->PWSLOT); +#endif /* !SCO */ else { fprintf (stderr, "%s: couldn't get password of \"%s\"\n", progname, u); @@ -119,9 +168,11 @@ lock_init () -#if (XmVersion >= 1002) /* The `destroy' bug apears to be fixed as */ -# define DESTROY_WORKS /* of Motif 1.2.1, but the `verify-callback' */ -#endif /* bug is still present. */ +#if defined(NO_MOTIF) || (XmVersion >= 1002) + /* The `destroy' bug apears to be fixed as of Motif 1.2.1, but + the `verify-callback' bug is still present. */ +# define DESTROY_WORKS +#endif static void passwd_cancel_cb (button, client_data, call_data) @@ -147,7 +198,7 @@ passwd_done_cb (button, client_data, call_data) passwd_state = pw_fail; } -#ifdef VERIFY_CALLBACK_WORKS +#if !defined(NO_MOTIF) && defined(VERIFY_CALLBACK_WORKS) /* #### It looks to me like adding any modifyVerify callback causes #### Motif 1.1.4 to free the the TextF_Value() twice. I can't see @@ -214,6 +265,27 @@ CtrlM: done()\n\ static char translations[] = ":keypress()"; #endif +static void +text_field_set_string (widget, text, position) + Widget widget; + char *text; + int position; +{ +#ifdef NO_MOTIF + XawTextBlock block; + block.firstPos = 0; + block.length = strlen (text); + block.ptr = text; + block.format = 0; + XawTextReplace (widget, 0, -1, &block); + XawTextSetInsertionPoint (widget, position); +#else /* !NO_MOTIF */ + XmTextFieldSetString (widget, text); + XmTextFieldSetInsertionPosition (widget, position); +#endif /* !NO_MOTIF */ +} + + static void keypress (w, event, argv, argc) Widget w; @@ -239,8 +311,8 @@ keypress (w, event, argv, argc) s [++i] = 0; while (i--) s [i] = '*'; - XmTextFieldSetString (passwd_text, s); - XmTextFieldSetInsertionPosition (passwd_text, j + 1); + + text_field_set_string (passwd_text, s, j + 1); } static void @@ -259,8 +331,8 @@ backspace (w, event, argv, argc) s [i] = 0; while (i--) s [i] = '*'; - XmTextFieldSetString (passwd_text, s); - XmTextFieldSetInsertionPosition (passwd_text, j + 1); + + text_field_set_string (passwd_text, s, j + 1); } static void @@ -271,7 +343,7 @@ kill_line (w, event, argv, argc) Cardinal *argc; { memset (typed_passwd, 0, sizeof (typed_passwd)); - XmTextFieldSetString (passwd_text, ""); + text_field_set_string (passwd_text, "", 0); } static void @@ -284,7 +356,7 @@ done (w, event, argv, argc) passwd_done_cb (w, 0, 0); } -#endif /* !VERIFY_CALLBACK_WORKS */ +#endif /* !VERIFY_CALLBACK_WORKS || NO_MOTIF */ static void format_into_label (widget, string) @@ -293,22 +365,38 @@ format_into_label (widget, string) { char *label; char buf [255]; - XmString xm_label = 0; - XmString new_xm_label; Arg av[10]; int ac = 0; + +#ifdef NO_MOTIF + XtSetArg (av [ac], XtNlabel, &label); ac++; + XtGetValues (widget, av, ac); +#else /* Motif */ + XmString xm_label = 0; + XmString new_xm_label; XtSetArg (av [ac], XmNlabelString, &xm_label); ac++; XtGetValues (widget, av, ac); XmStringGetLtoR (xm_label, XmSTRING_DEFAULT_CHARSET, &label); - if (!strcmp (label, XtName (widget))) +#endif /* Motif */ + + if (!label || !strcmp (label, XtName (widget))) strcpy (buf, "ERROR: RESOURCES ARE NOT INSTALLED CORRECTLY"); else sprintf (buf, label, string); - new_xm_label = XmStringCreate (buf, XmSTRING_DEFAULT_CHARSET); + ac = 0; + +#ifdef NO_MOTIF + XtSetArg (av [ac], XtNlabel, buf); ac++; +#else /* Motif */ + new_xm_label = XmStringCreate (buf, XmSTRING_DEFAULT_CHARSET); XtSetArg (av [ac], XmNlabelString, new_xm_label); ac++; +#endif /* Motif */ + XtSetValues (widget, av, ac); +#ifndef NO_MOTIF XmStringFree (new_xm_label); +#endif XtFree (label); } @@ -339,8 +427,8 @@ roger (button, client_data, call_data) if (size > 40) size -= 30; x = (xgwa.width - size) / 2; y = (xgwa.height - size) / 2; - XtSetArg (av [ac], XmNforeground, &fg); ac++; - XtSetArg (av [ac], XmNbackground, &bg); ac++; + XtSetArg (av [ac], XtNforeground, &fg); ac++; + XtSetArg (av [ac], XtNbackground, &bg); ac++; XtGetValues (button, av, ac); /* if it's black on white, swap it cause it looks better (hack hack) */ if (fg == BlackPixelOfScreen (screen) && bg == WhitePixelOfScreen (screen)) @@ -355,6 +443,17 @@ roger (button, client_data, call_data) XFreeGC (dpy, erase_gc); } +#ifdef NO_MOTIF + +static void +make_passwd_dialog (parent) + Widget parent; +{ + abort (); /* #### */ +} + +#else /* Motif */ + static void make_passwd_dialog (parent) Widget parent; @@ -374,7 +473,7 @@ make_passwd_dialog (parent) XtOverrideTranslations (passwd_text, XtParseTranslationTable (translations)); #endif -#if (XmVersion >= 1002) +#if !defined(NO_MOTIF) && (XmVersion >= 1002) /* The focus stuff changed around; this didn't exist in 1.1.5. */ XtVaSetValues (passwd_form, XmNinitialFocus, passwd_text, 0); #endif @@ -387,6 +486,7 @@ make_passwd_dialog (parent) format_into_label (passwd_label1, screensaver_version); } +#endif /* Motif */ extern void idle_timer (); @@ -412,13 +512,13 @@ passwd_idle_timer (junk1, junk2) int ac = 0; XGCValues gcv; unsigned long fg, bg; - XtSetArg (av [ac], XmNheight, &d); ac++; + XtSetArg (av [ac], XtNheight, &d); ac++; XtGetValues (passwd_done, av, ac); ac = 0; - XtSetArg (av [ac], XmNwidth, &x); ac++; - XtSetArg (av [ac], XmNheight, &y); ac++; - XtSetArg (av [ac], XmNforeground, &fg); ac++; - XtSetArg (av [ac], XmNbackground, &bg); ac++; + XtSetArg (av [ac], XtNwidth, &x); ac++; + XtSetArg (av [ac], XtNheight, &y); ac++; + XtSetArg (av [ac], XtNforeground, &fg); ac++; + XtSetArg (av [ac], XtNbackground, &bg); ac++; XtGetValues (passwd_form, av, ac); x -= d; y -= d; @@ -455,7 +555,7 @@ pop_passwd_dialog (parent) int revert_to; typed_passwd [0] = 0; passwd_state = pw_read; - XmTextFieldSetString (passwd_text, ""); + text_field_set_string (passwd_text, "", 0); XGetInputFocus (dpy, &focus, &revert_to); #ifndef DESTROY_WORKS @@ -471,7 +571,7 @@ pop_passwd_dialog (parent) pop_up_dialog_box (passwd_dialog, passwd_form, 2); XtManageChild (passwd_form); -#if (XmVersion < 1002) +#if !defined(NO_MOTIF) && (XmVersion < 1002) /* The focus stuff changed around; this causes problems in 1.2.1 but is necessary in 1.1.5. */ XmProcessTraversal (passwd_text, XmTRAVERSE_CURRENT); @@ -512,11 +612,12 @@ pop_passwd_dialog (parent) case pw_cancel: lose = 0; break; default: abort (); } +#ifndef NO_MOTIF XmProcessTraversal (passwd_cancel, 0); /* turn off I-beam */ +#endif if (lose) { - XmTextFieldSetString (passwd_text, lose); - XmTextFieldSetInsertionPosition (passwd_text, strlen (lose) + 1); + text_field_set_string (passwd_text, lose, strlen (lose) + 1); passwd_idle_timer_tick = 1; id = XtAppAddTimeOut (app, 3000, passwd_idle_timer, 0); while (1) @@ -531,7 +632,7 @@ pop_passwd_dialog (parent) } } memset (typed_passwd, 0, sizeof (typed_passwd)); - XmTextFieldSetString (passwd_text, ""); + text_field_set_string (passwd_text, "", 0); XtSetKeyboardFocus (parent, None); #ifdef DESTROY_WORKS diff --git a/driver/stderr.c b/driver/stderr.c index 2d182487..7d5fc136 100644 --- a/driver/stderr.c +++ b/driver/stderr.c @@ -1,4 +1,4 @@ -/* xscreensaver, Copyright (c) 1991-1995 Jamie Zawinski +/* xscreensaver, Copyright (c) 1991-1995 Jamie Zawinski * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that @@ -159,7 +159,10 @@ stderr_popup_timer_fn (closure, id) static void -stderr_callback (XtPointer closure, int *fd, XtIntervalId *id) +stderr_callback (closure, fd, id) + XtPointer closure; + int *fd; + XtIntervalId *id; { char *s; int left; diff --git a/driver/subprocs.c b/driver/subprocs.c index ab969b13..689bbb01 100644 --- a/driver/subprocs.c +++ b/driver/subprocs.c @@ -1,4 +1,5 @@ -/* xscreensaver, Copyright (c) 1991-1993 Jamie Zawinski +/* xscreensaver, Copyright (c) 1991, 1992, 1993, 1995 + * Jamie Zawinski * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that @@ -80,14 +81,7 @@ extern int putenv (/* const char * */); /* getenv() is in stdlib.h... */ extern int kill (pid_t, int); /* signal() is in sys/signal.h... */ #endif -# ifndef random -# if defined(SVR4) || defined(SYSV) -# define random() rand() -# else /* !totally-losing-SYSV */ - extern long random(); /* rand() is in stdlib.h... */ -# endif /* !totally-losing-SYSV */ -# endif /* random defined */ - +#include "yarandom.h" #include "xscreensaver.h" /* this must be `sh', not whatever $SHELL happens to be. */ diff --git a/driver/timers.c b/driver/timers.c index ff367e4c..bb950d81 100644 --- a/driver/timers.c +++ b/driver/timers.c @@ -1,4 +1,4 @@ -/* xscreensaver, Copyright (c) 1991-1995 Jamie Zawinski +/* xscreensaver, Copyright (c) 1991-1995 Jamie Zawinski * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that @@ -141,6 +141,7 @@ BadWindow_ehandler (dpy, error) may have been destroyed <30 seconds after it was created. */ if (error->error_code == BadWindow || + error->error_code == BadMatch || error->error_code == BadDrawable) return 0; XmuPrintDefaultErrorMessage (dpy, error, stderr); diff --git a/driver/windows.c b/driver/windows.c index a9731b02..084bce73 100644 --- a/driver/windows.c +++ b/driver/windows.c @@ -1,4 +1,4 @@ -/* xscreensaver, Copyright (c) 1991-1995 Jamie Zawinski +/* xscreensaver, Copyright (c) 1991-1995 Jamie Zawinski * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that @@ -724,6 +724,12 @@ raise_window (inhibit_fade, between_hacks_p) XInstallColormap (dpy, cmap); } +#ifdef __hpux + /* Calls to XHPDisableReset and XHPEnableReset must be balanced, + or BadAccess errors occur. */ +static Bool hp_locked_p = False; +#endif /* __hpux */ + void blank_screen () { @@ -732,8 +738,9 @@ blank_screen () raise_window (False, False); grab_keyboard_and_mouse (); #ifdef __hpux - if (lock_p) + if (lock_p && !hp_locked_p) XHPDisableReset (dpy); /* turn off C-Sh-Reset */ + hp_locked_p = True; #endif } @@ -769,7 +776,8 @@ unblank_screen () ungrab_keyboard_and_mouse (); restore_real_vroot (); #ifdef __hpux - if (lock_p) + if (lock_p && hp_locked_p) XHPEnableReset (dpy); /* turn C-Sh-Reset back on */ + hp_locked_p = False; #endif } diff --git a/driver/xscreensaver-command.c b/driver/xscreensaver-command.c index 15e86063..d0aced94 100644 --- a/driver/xscreensaver-command.c +++ b/driver/xscreensaver-command.c @@ -1,4 +1,5 @@ -/* xscreensaver-command, Copyright (c) 1991-1995 Jamie Zawinski +/* xscreensaver-command, Copyright (c) 1991-1995 + * Jamie Zawinski * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that @@ -26,7 +27,7 @@ static char *screensaver_version; static char *usage = "usage: %s -\n\ \n\ This program provides external control of a running xscreensaver process.\n\ - Version %s, copyright (c) 1991-1994 Jamie Zawinski .\n\ + Version %s, copyright (c) 1991-1994 Jamie Zawinski .\n\ \n\ -demo Enter interactive demo mode.\n\ -deactivate Turns off the screensaver if it is on, as user input would.\n\ diff --git a/driver/xscreensaver-command.man b/driver/xscreensaver-command.man index b00acee9..06e88cbf 100644 --- a/driver/xscreensaver-command.man +++ b/driver/xscreensaver-command.man @@ -107,4 +107,4 @@ appear in supporting documentation. No representations are made about the suitability of this software for any purpose. It is provided "as is" without express or implied warranty. .SH AUTHOR -Jamie Zawinski , 13-aug-92. +Jamie Zawinski , 13-aug-92. diff --git a/driver/xscreensaver.c b/driver/xscreensaver.c index 451f953d..76f68c2e 100644 --- a/driver/xscreensaver.c +++ b/driver/xscreensaver.c @@ -1,4 +1,4 @@ -/* xscreensaver, Copyright (c) 1991-1995 Jamie Zawinski +/* xscreensaver, Copyright (c) 1991-1995 Jamie Zawinski * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that @@ -138,16 +138,9 @@ #include #endif /* HAVE_SAVER_EXTENSION */ +#include "yarandom.h" #include "xscreensaver.h" -#if defined(SVR4) || defined(SYSV) -# define srandom(i) srand((unsigned int)(i)) -#else -# ifndef __linux -extern void srandom P((int)); /* srand() is in stdlib.h... */ -# endif -#endif - extern char *get_string_resource P((char *, char *)); extern Bool get_boolean_resource P((char *, char *)); extern int get_integer_resource P((char *, char *)); @@ -237,9 +230,6 @@ static Atom XA_EXIT, XA_RESTART, XA_DEMO, XA_LOCK; #ifdef NO_MOTIF /* kludge */ Bool demo_mode_p = 0; Bool dbox_up_p = 0; -#ifndef NO_LOCKING -Time passwd_timeout = 0; -#endif #endif @@ -253,6 +243,7 @@ static XrmOptionDescRec options [] = { { "-timeout", ".timeout", XrmoptionSepArg, 0 }, { "-cycle", ".cycle", XrmoptionSepArg, 0 }, { "-idelay", ".initialDelay", XrmoptionSepArg, 0 }, + { "-nice", ".nice", XrmoptionSepArg, 0 }, { "-visual", ".visualID", XrmoptionSepArg, 0 }, { "-lock-timeout", ".lockTimeout", XrmoptionSepArg, 0 }, { "-install", ".installColormap", XrmoptionNoArg, "on" }, @@ -276,7 +267,7 @@ static void do_help P((void)) { printf ("\ -xscreensaver %s, copyright (c) 1991-1995 by Jamie Zawinski .\n\ +xscreensaver %s, copyright (c) 1991-1995 by Jamie Zawinski .\n\ The standard Xt command-line options are accepted; other options include:\n\ \n\ -timeout When the screensaver should activate.\n\ @@ -290,8 +281,8 @@ The standard Xt command-line options are accepted; other options include:\n\ -silent Don't.\n\ -xidle-extension Use the R5 XIdle server extension.\n\ -no-xidle-extension Don't.\n\ - -saver-extension Use the R6 MIT-SCREEN-SAVER server extension.\n\ - -no-saver-extension Don't.\n\ + -ss-extension Use the R6 MIT-SCREEN-SAVER server extension.\n\ + -no-ss-extension Don't.\n\ -lock Require a password before deactivating.\n\ -no-lock Don't.\n\ -lock-timeout Grace period before locking; default 0.\n\ @@ -312,7 +303,7 @@ more details.\n\n", #endif #if !defined(HAVE_XIDLE_EXTENSION) && !defined(HAVE_SAVER_EXTENSION) printf ("Support for the XIDLE and MIT-SCREEN-SAVER server extensions\ - was not\n\enabled at compile-time.\n"); + was not\nenabled at compile-time.\n"); #endif /* !HAVE_XIDLE_EXTENSION && !HAVE_SAVER_EXTENSION */ fflush (stdout); @@ -479,7 +470,7 @@ get_resources P((void)) /* don't set use_saver_extension unless it is explicitly specified */ if (get_string_resource ("saverExtension", "Boolean")) - use_xidle_extension = get_boolean_resource ("saverExtension", "Boolean"); + use_saver_extension = get_boolean_resource ("saverExtension", "Boolean"); else #ifdef HAVE_SAVER_EXTENSION /* pick a default */ use_saver_extension = True; @@ -660,6 +651,11 @@ initialize (argc, argv) nolock_reason = "not compiled with locking support"; #else locking_disabled_p = False; + +#ifdef SCO + set_auth_parameters(argc, argv); +#endif + if (! lock_init ()) /* before hack_uid() for proper permissions */ { locking_disabled_p = True; @@ -691,7 +687,7 @@ initialize (argc, argv) if (verbose_p) printf ("\ -%s %s, copyright (c) 1991-1995 by Jamie Zawinski .\n\ +%s %s, copyright (c) 1991-1995 by Jamie Zawinski .\n\ pid = %d.\n", progname, screensaver_version, getpid ()); ensure_no_screensaver_running (); @@ -820,7 +816,8 @@ main_loop () blank_screen (); spawn_screenhack (True); if (cycle) - cycle_id = XtAppAddTimeOut (app, cycle, (XtPointer)cycle_timer, 0); + cycle_id = XtAppAddTimeOut (app, cycle, + (XtTimerCallbackProc)cycle_timer, 0); #ifndef NO_LOCKING if (lock_p && lock_timeout == 0) @@ -828,7 +825,8 @@ main_loop () if (lock_p && !locked_p) /* locked_p might be true already because of ClientMessage */ lock_id = XtAppAddTimeOut (app,lock_timeout, - (XtPointer)activate_lock_timer,0); + (XtTimerCallbackProc) + activate_lock_timer,0); #endif PASSWD_INVALID: @@ -902,7 +900,7 @@ handle_clientmessage (event, until_idle_p) XEvent *event; Bool until_idle_p; { - Atom type; + Atom type = 0; if (event->xclient.message_type != XA_SCREENSAVER) { char *str; @@ -911,11 +909,13 @@ handle_clientmessage (event, until_idle_p) progname, (verbose_p ? "## " : ""), (str ? str : "(null)")); if (str) XFree (str); + return False; } if (event->xclient.format != 32) { fprintf (stderr, "%s: %sClientMessage of format %d received, not 32\n", progname, (verbose_p ? "## " : ""), event->xclient.format); + return False; } type = event->xclient.data.l[0]; if (type == XA_ACTIVATE) @@ -924,7 +924,15 @@ handle_clientmessage (event, until_idle_p) { if (verbose_p) printf ("%s: ACTIVATE ClientMessage received.\n", progname); - return True; + if (use_saver_extension) + { + XForceScreenSaver (dpy, ScreenSaverActive); + return False; + } + else + { + return True; + } } fprintf (stderr, "%s: %sClientMessage ACTIVATE received while already active.\n", @@ -936,7 +944,15 @@ handle_clientmessage (event, until_idle_p) { if (verbose_p) printf ("%s: DEACTIVATE ClientMessage received.\n", progname); - return True; + if (use_saver_extension) + { + XForceScreenSaver (dpy, ScreenSaverReset); + return False; + } + else + { + return True; + } } fprintf (stderr, "%s: %sClientMessage DEACTIVATE received while inactive.\n", @@ -1062,21 +1078,31 @@ handle_clientmessage (event, until_idle_p) } if (until_idle_p) - return True; + { + if (use_saver_extension) + { + XForceScreenSaver (dpy, ScreenSaverActive); + return False; + } + else + { + return True; + } + } } #endif } else { char *str; - str = XGetAtomName (dpy, type); + str = (type ? XGetAtomName(dpy, type) : 0); if (str) fprintf (stderr, "%s: %sunrecognised screensaver ClientMessage %s received\n", progname, (verbose_p ? "## " : ""), str); else fprintf (stderr, - "%s: %sunrecognised screensaver ClientMessage 0x%x received\n", + "%s: %sunrecognised screensaver ClientMessage 0x%x received\n", progname, (verbose_p ? "## " : ""), (unsigned int) event->xclient.data.l[0]); if (str) XFree (str); diff --git a/driver/xscreensaver.h b/driver/xscreensaver.h index 751ae0ce..ea792e2d 100644 --- a/driver/xscreensaver.h +++ b/driver/xscreensaver.h @@ -1,4 +1,4 @@ -/* xscreensaver, Copyright (c) 1993, 1995 Jamie Zawinski +/* xscreensaver, Copyright (c) 1993, 1995 Jamie Zawinski * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that @@ -27,9 +27,13 @@ #ifdef NO_MOTIF # define NO_DEMO_MODE + + /* #### If anyone ever finishes the Athena locking code, remove this. + Until then, Locking requires Motif. */ # ifndef NO_LOCKING # define NO_LOCKING # endif + #endif extern char *progname, *progclass; diff --git a/driver/xscreensaver.man b/driver/xscreensaver.man index 6d7c2f02..18bf571a 100644 --- a/driver/xscreensaver.man +++ b/driver/xscreensaver.man @@ -216,9 +216,10 @@ The background color used for the stdout/stderr text, if \fBcaptureStdout\fP or \fBcaptureStderr\fP are true. Default: Black. .TP 8 .B programs \fR(class \fBPrograms\fP) -The graphics hacks which \fIxscreensaver\fP runs when the user is idle. -The value of this resource is a string, one \fIsh\fP command per line. -Each line must contain exactly one command -- no semicolons. +The graphics hacks which \fIxscreensaver\fP runs when the user is idle, +in addition to those specified in colorPrograms or monoPrograms (as +appropriate.) The value of this resource is a string, one \fIsh\fP command +per line. Each line must contain exactly one command -- no semicolons. When the screensaver starts up, one of these is selected at random, and run. After the \fIcycle\fP period expires, it is killed, and another @@ -329,6 +330,13 @@ Simply add \fB"xscreensaver &"\fP to your \fI/usr/lib/X11/xdm/Xsetup\fP file. Because \fIxdm\fP grabs the keyboard, keypresses will not make the screensaver deactivate, but any mouse activity will. .PP +(If your system does not seem to be executing the \fIXsetup\fP file, you +may need to configure it to do so -- the traditional way to do this is +to make that file the value of the \fIDisplayManager*setup\fP resource +in the \fIxdm-config\fP file. See the man page for +.BR xdm (1) +for more details.) +.PP Users may want to add \fB"xscreensaver-command -restart"\fP to their startup scripts, so that the screensaver will be reinitialized with their private resource settings when they log in. @@ -534,7 +542,7 @@ permission notice appear in supporting documentation. No representations are made about the suitability of this software for any purpose. It is provided "as is" without express or implied warranty. .SH AUTHOR -Jamie Zawinski , 13-aug-92. +Jamie Zawinski , 13-aug-92. Please let me know if you find any bugs or make any improvements. Thanks to David Wojtowicz for implementing \fIlockTimeout\fP. diff --git a/hacks/Imakefile b/hacks/Imakefile index 1c68fa99..d2276c49 100644 --- a/hacks/Imakefile +++ b/hacks/Imakefile @@ -20,16 +20,16 @@ UTILS = ../utils INCLUDES = -I$(UTILS) DEFINES = R5ISMS XPMDEFS -EXTRA_LOAD_FLAGS= $(XMULIB) $(XTOOLLIB) XPMLIB $(EXTENSIONLIB) $(XLIB) -lm +LOCAL_LIBRARIES = $(XMULIB) $(XTOOLLIB) XPMLIB $(EXTENSIONLIB) $(XLIB) -lm HACKS = attraction.c greynetic.c helix.c hopalong.c xroger-hack.c \ noseguy.c pyro.c qix.c rocks.c rorschach.c blitspin.c \ imsmap.c slidescreen.c decayscreen.c maze.c hypercube.c \ - halo.c flame.c pedal.c + halo.c flame.c pedal.c lmorph.c MEN = attraction.man greynetic.man helix.man hopalong.man \ noseguy.man pyro.man xroger.man qix.man rocks.man \ rorschach.man blitspin.man imsmap.man slidescreen.man \ decayscreen.man maze.man hypercube.man halo.man flame.man \ - pedal.man + pedal.man lmorph.man TARFILES = README Imakefile screenhack.c $(HACKS) screenhack.h \ vroot.h xlock.h default.xbm $(MEN) .gdbinit noses/\* @@ -42,14 +42,16 @@ echo_tarfiles: all:: p @@\ p: deps screenhack.h ps.o $(DEPLIBS) @@\ RemoveTargetProgram($@) @@\ - $(CC) -o $@ $(LDOPTIONS) deps ps.o $(LDLIBS) $(EXTRA_LOAD_FLAGS) @@\ + $(CCENVSETUP) \ + $(CC) -o $@ $(LDOPTIONS) deps ps.o $(LOCAL_LIBRARIES) $(LDLIBS) @@\ @@\ InstallProgram(p,$(BINDIR)) @@\ InstallManPage(p,$(MANDIR)) @@\ clean:: @@\ $(RM) p -HOBJS=screenhack.o $(UTILS)/resources.o $(UTILS)/usleep.o $(UTILS)/visual.o +HOBJS=screenhack.o $(UTILS)/resources.o $(UTILS)/visual.o \ + $(UTILS)/usleep.o $(UTILS)/yarandom.o ScreenhackTarget (qix, qix, $(HOBJS) $(UTILS)/hsv.o) ScreenhackTarget (helix, helix, $(HOBJS) $(UTILS)/hsv.o) @@ -70,3 +72,4 @@ ScreenhackTarget (hypercube, hypercube, $(HOBJS)) ScreenhackTarget (halo, halo, $(HOBJS) $(UTILS)/hsv.o) ScreenhackTarget (flame, flame, $(HOBJS) $(UTILS)/hsv.o) ScreenhackTarget (pedal, pedal, $(HOBJS) $(UTILS)/hsv.o) +ScreenhackTarget (lmorph, lmorph, $(HOBJS)) diff --git a/hacks/attraction.c b/hacks/attraction.c index 7844154a..8e3f188f 100644 --- a/hacks/attraction.c +++ b/hacks/attraction.c @@ -1,4 +1,4 @@ -/* xscreensaver, Copyright (c) 1992 Jamie Zawinski +/* xscreensaver, Copyright (c) 1992, 1995 Jamie Zawinski * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that @@ -11,7 +11,8 @@ /* Simulation of a pair of quasi-gravitational fields, maybe sorta kinda a little like the strong and weak electromagnetic forces. Derived from - a Lispm screensaver by John Pezaris . + a Lispm screensaver by John Pezaris . Mouse control and + viscosity added by "Philip Edward Cutone, III" . John sez: @@ -32,15 +33,20 @@ The 1/r^2, -1/r^2, -10/r^2 thresholds proved not only robust but also interesting -- the orbs never collided and the threshold viscosity fixed the non-conservational problem. + + Philip sez: + > An even normal viscosity (rather than the thresholded version to + > bleed excess energy) is also not interesting. + + unless you make about 200 points.... set the viscosity to about .8 + and drag the mouse through it. it makes a nice wave which travels + through the field. */ -#include "screenhack.h" -#include "spline.h" #include #include -#if __STDC__ -#include /* for M_PI */ -#endif +#include "screenhack.h" +#include "spline.h" struct ball { float x, y; @@ -66,6 +72,11 @@ static int point_stack_size, point_stack_fp, pixel_stack_fp, pixel_stack_size; static unsigned long *pixel_stack; static unsigned int color_shift; +/*flip mods for mouse interaction*/ +static Bool mouse_p; +int mouse_x, mouse_y, mouse_mass, root_x, root_y; +static float viscosity; + static enum object_mode { ball_mode, line_mode, polygon_mode, spline_mode, spline_filled_mode, tail_mode @@ -122,6 +133,13 @@ init_balls (dpy, window) color_shift = get_integer_resource ("colorShift", "Integer"); if (color_shift >= 360) color_shift = 5; + /*flip mods for mouse interaction*/ + mouse_p = get_boolean_resource ("mouse", "Boolean"); + mouse_mass = get_integer_resource ("mouseSize", "Integer"); + mouse_mass = mouse_mass * mouse_mass *10; + + viscosity = get_float_resource ("viscosity", "Float"); + mode_str = get_string_resource ("mode", "Mode"); if (! mode_str) mode = ball_mode; else if (!strcmp (mode_str, "balls")) mode = ball_mode; @@ -272,6 +290,7 @@ compute_force (i, dx_ret, dy_ret) float *dx_ret, *dy_ret; { int j; + float x_dist, y_dist, dist, dist2; *dx_ret = 0; *dy_ret = 0; for (j = 0; j < npoints; j++) @@ -298,6 +317,28 @@ compute_force (i, dx_ret, dy_ret) *dy_ret += (frand (10.0) - 5.0); } } + + if (mouse_p) + { + x_dist = mouse_x - balls [i].x; + y_dist = mouse_y - balls [i].y; + dist2 = (x_dist * x_dist) + (y_dist * y_dist); + dist = sqrt (dist2); + + if (dist > 0.1) /* the balls are not overlapping */ + { + float new_acc = ((mouse_mass / dist2) * + ((dist < threshold) ? -1.0 : 1.0)); + float new_acc_dist = new_acc / dist; + *dx_ret += new_acc_dist * x_dist; + *dy_ret += new_acc_dist * y_dist; + } + else + { /* the balls are overlapping; move randomly */ + *dx_ret += (frand (10.0) - 5.0); + *dy_ret += (frand (10.0) - 5.0); + } + } } static void @@ -310,6 +351,15 @@ run_balls (dpy, window) static Colormap cmap; int i; + /*flip mods for mouse interaction*/ + Window root1, child1; + int mask; + if (mouse_p) + { + XQueryPointer(dpy, window, &root1, &child1, + &root_x, &root_y, &mouse_x, &mouse_y, &mask); + } + if (tick++ == 500) { XWindowAttributes xgwa; @@ -341,11 +391,20 @@ run_balls (dpy, window) balls[i].vx *= 0.9; balls[i].dx = 0; } + else if (viscosity != 1) + { + balls[i].vx *= viscosity; + } + if (balls[i].vy > 10) { balls[i].vy *= 0.9; balls[i].dy = 0; } + else if (viscosity != 1) + { + balls[i].vy *= viscosity; + } balls[i].x += balls[i].vx; balls[i].y += balls[i].vy; @@ -435,7 +494,7 @@ run_balls (dpy, window) abort (); if (!mono_p) { - XColor color2; + XColor color2, desired; color2 = balls [0].color; switch (cmode) { @@ -451,7 +510,18 @@ run_balls (dpy, window) abort (); } - if (!XAllocColor (dpy, cmap, &color2)) + desired = color2; + if (XAllocColor (dpy, cmap, &color2)) + { + /* XAllocColor returns the actual RGB that the hardware let us + allocate. Restore the requested values into the XColor struct + so that limited-resolution hardware doesn't cause cycle_hue to + get "stuck". */ + color2.red = desired.red; + color2.green = desired.green; + color2.blue = desired.blue; + } + else { color2 = balls [0].color; if (!XAllocColor (dpy, cmap, &balls [0].color)) @@ -569,6 +639,9 @@ char *defaults [] = { "*threshold: 100", "*delay: 10000", "*glow: false", + "*mouseSize: 10", + "*mouse: false", + "*viscosity: 1", "*orbit: false", "*colorShift: 3", "*segments: 100", @@ -588,6 +661,10 @@ XrmOptionDescRec options [] = { { "-vx", ".vx", XrmoptionSepArg, 0 }, { "-vy", ".vy", XrmoptionSepArg, 0 }, { "-vmult", ".vMult", XrmoptionSepArg, 0 }, + { "-mouse-size", ".mouseSize", XrmoptionSepArg, 0 }, + { "-mouse", ".mouse", XrmoptionNoArg, "true" }, + { "-nomouse", ".mouse", XrmoptionNoArg, "false" }, + { "-viscosity", ".viscosity", XrmoptionSepArg, 0 }, { "-glow", ".glow", XrmoptionNoArg, "true" }, { "-noglow", ".glow", XrmoptionNoArg, "false" }, { "-orbit", ".orbit", XrmoptionNoArg, "true" } diff --git a/hacks/attraction.man b/hacks/attraction.man index 334898ee..e3f94243 100644 --- a/hacks/attraction.man +++ b/hacks/attraction.man @@ -1,9 +1,22 @@ -.TH XScreenSaver 1 "22-mar-93" "X Version 11" +.de EX \"Begin example +.ne 5 +.if n .sp 1 +.if t .sp .5 +.nf +.in +.5i +.. +.de EE +.fi +.in -.5i +.if n .sp 1 +.if t .sp .5 +.. +.TH XScreenSaver 1 "14-Dec-95" "X Version 11" .SH NAME attraction - interactions of opposing forces .SH SYNOPSIS .B attraction -[\-display \fIhost:display.screen\fP] [\-foreground \fIcolor\fP] [\-background \fIcolor\fP] [\-window] [\-root] [\-mono] [\-install] [\-visual \fIvisual\fP] [\-points \fIint\fP] [\-threshold \fIint\fP] [\-mode balls | lines | polygons | splines | filled-splines | tails ] [\-color-mode cycle | random] [\-size \fIint\fP] [\-segments \fIint\fP] [\-delay \fIusecs\fP] [\-color-shift \fIdegrees\fP] [\-radius \fIint\fP] [\-vx \fIint\fP] [\-vy \fIint\fP] [\-glow] [\-noglow] [\-orbit] +[\-display \fIhost:display.screen\fP] [\-foreground \fIcolor\fP] [\-background \fIcolor\fP] [\-window] [\-root] [\-mono] [\-install] [\-visual \fIvisual\fP] [\-points \fIint\fP] [\-threshold \fIint\fP] [\-mode balls | lines | polygons | splines | filled-splines | tails ] [\-color-mode cycle | random] [\-size \fIint\fP] [\-segments \fIint\fP] [\-delay \fIusecs\fP] [\-color-shift \fIdegrees\fP] [\-radius \fIint\fP] [\-vx \fIint\fP] [\-vy \fIint\fP] [\-glow] [\-noglow] [\-orbit] [\-viscosity \fIfloat\fP] [\-mouse] [\-no-mouse] [\-mouse-size] .SH DESCRIPTION The \fIattraction\fP program has several visually different modes of operation, all of which are based on the interactions of a set of control @@ -115,6 +128,31 @@ to decay. In orbit mode, the initial velocity of the balls is multiplied by this; a number less than 1 will make the balls pull closer together, and a larger number will make them move apart. The default is 1, meaning stability. +.TP 8 +.B \-viscosity float +This sets the viscosity of the hypothetical fluid through which the control +points move; the default is 1, meaning no resistance. Values higher than 1 +aren't interesting; lower values cause less motion. + +One interesting thing to try is +.EX +attraction -viscosity 0.8 -points 75 \\ + -mouse -geometry =500x500 +.EE +Give it a few seconds to settle down into a stable clump, and then move +the mouse through it to make "waves". +.TP 8 +.B \-mouse +This will cause the mouse to be considered a control point; it will not be +drawn, but it will influence the other points, so you can wave the mouse +and influence the images being created. +.TP 8 +.B \-no-mouse +Turns off \fB\-mouse\fP. +.TP 8 +.B \-mouse-size integer +In \fB\-mouse\fP mode, this sets the mass of the mouse (analagously to the +\fB\-size\fP parameter.) .SH ENVIRONMENT .PP .TP 8 @@ -136,4 +174,6 @@ appear in supporting documentation. No representations are made about the suitability of this software for any purpose. It is provided "as is" without express or implied warranty. .SH AUTHOR -Jamie Zawinski , 13-aug-92. +Jamie Zawinski , 13-aug-92. + +Viscosity and mouse support by Philip Edward Cutone, III. diff --git a/hacks/blitspin.c b/hacks/blitspin.c index 10f49dd6..debdbaea 100644 --- a/hacks/blitspin.c +++ b/hacks/blitspin.c @@ -1,4 +1,4 @@ -/* xscreensaver, Copyright (c) 1992 Jamie Zawinski +/* xscreensaver, Copyright (c) 1992 Jamie Zawinski * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that diff --git a/hacks/blitspin.man b/hacks/blitspin.man index 4903faa7..4198883d 100644 --- a/hacks/blitspin.man +++ b/hacks/blitspin.man @@ -71,7 +71,7 @@ appear in supporting documentation. No representations are made about the suitability of this software for any purpose. It is provided "as is" without express or implied warranty. .SH AUTHOR -Jamie Zawinski , 17-aug-92. +Jamie Zawinski , 17-aug-92. Based on SmallTalk code which appeared in the August 1981 issue of Byte magazine. diff --git a/hacks/decayscreen.c b/hacks/decayscreen.c index 32f8167c..ce18a7ee 100644 --- a/hacks/decayscreen.c +++ b/hacks/decayscreen.c @@ -1,4 +1,5 @@ -/* xscreensaver, Copyright (c) 1992, 1993, 1994 Jamie Zawinski +/* xscreensaver, Copyright (c) 1992, 1993, 1994 + * Jamie Zawinski * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that diff --git a/hacks/flame.c b/hacks/flame.c index e010b9df..3f98e3e3 100644 --- a/hacks/flame.c +++ b/hacks/flame.c @@ -1,4 +1,4 @@ -/* xscreensaver, Copyright (c) 1993 Jamie Zawinski +/* xscreensaver, Copyright (c) 1993, 1995 Jamie Zawinski * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that @@ -48,8 +48,6 @@ #include "screenhack.h" -/*#include */ - #define POINT_BUFFER_SIZE 10 #define MAXLEV 4 @@ -248,6 +246,23 @@ flame (dpy, window) if (delay) usleep (delay); } + +#ifdef __hpux +/* I don't understand why this is necessary, but I'm told that this program + does nothing at all on HP-sUX without it. + */ +#undef random +#undef srandom +#include +int matherr(x) + register struct exception *x; +{ + if (x->type == PLOSS) return 1; + else return 0; +} +#endif /* __hpux */ + + char *progclass = "Flame"; diff --git a/hacks/flame.man b/hacks/flame.man index 67254f8e..e5326818 100644 --- a/hacks/flame.man +++ b/hacks/flame.man @@ -69,4 +69,4 @@ supporting documentation. Scott Graves , 06-Jun-91.n Ability to run standalone or with \fIxscreensaver\fP added by -Jamie Zawinski , 18-Oct-93. +Jamie Zawinski , 18-Oct-93. diff --git a/hacks/greynetic.c b/hacks/greynetic.c index dd9312ac..4dd3f172 100644 --- a/hacks/greynetic.c +++ b/hacks/greynetic.c @@ -1,4 +1,4 @@ -/* xscreensaver, Copyright (c) 1992 Jamie Zawinski +/* xscreensaver, Copyright (c) 1992, 1995 Jamie Zawinski * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that @@ -100,7 +100,7 @@ greynetic (dpy, window) gcv.stipple = pixmaps [random () % NBITS]; if (mono_p) { - if (random () % 1) + if (random () & 1) gcv.foreground = fg, gcv.background = bg; else gcv.foreground = bg, gcv.background = fg; diff --git a/hacks/greynetic.man b/hacks/greynetic.man index 2d187824..86381123 100644 --- a/hacks/greynetic.man +++ b/hacks/greynetic.man @@ -49,4 +49,4 @@ appear in supporting documentation. No representations are made about the suitability of this software for any purpose. It is provided "as is" without express or implied warranty. .SH AUTHOR -Jamie Zawinski , 13-aug-92. +Jamie Zawinski , 13-aug-92. diff --git a/hacks/halo.c b/hacks/halo.c index b8270ee8..d61e2ac3 100644 --- a/hacks/halo.c +++ b/hacks/halo.c @@ -1,4 +1,4 @@ -/* xscreensaver, Copyright (c) 1993 Jamie Zawinski +/* xscreensaver, Copyright (c) 1993, 1995 Jamie Zawinski * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that @@ -19,6 +19,7 @@ */ #include "screenhack.h" +#include struct circle { int x, y, radius; @@ -26,6 +27,11 @@ struct circle { int dx, dy; }; +static enum color_mode { + seuss_mode, ramp_mode, random_mode +} cmode; + + static struct circle *circles; static int count, global_count; static Pixmap pixmap, buffer; @@ -33,7 +39,6 @@ static int width, height, global_inc; static int delay; static unsigned long fg_pixel, bg_pixel; static XColor fgc, bgc; -static Bool xor_p; static GC draw_gc, erase_gc, copy_gc, merge_gc; static Bool anim_p; static Colormap cmap; @@ -77,16 +82,34 @@ init_circles (dpy, window) { XGCValues gcv; XWindowAttributes xgwa; + char *mode_str = 0; XGetWindowAttributes (dpy, window, &xgwa); cmap = xgwa.colormap; global_count = get_integer_resource ("count", "Integer"); if (global_count < 0) global_count = 0; global_inc = get_integer_resource ("increment", "Integer"); if (global_inc < 0) global_inc = 0; - xor_p = get_boolean_resource ("xor", "Boolean"); -/* if (mono_p) */ xor_p = True; anim_p = get_boolean_resource ("animate", "Boolean"); delay = get_integer_resource ("delay", "Integer"); + mode_str = get_string_resource ("colorMode", "ColorMode"); + if (! mode_str) cmode = random_mode; + else if (!strcmp (mode_str, "seuss")) cmode = seuss_mode; + else if (!strcmp (mode_str, "ramp")) cmode = ramp_mode; + else if (!strcmp (mode_str, "random")) cmode = random_mode; + else { + fprintf (stderr, + "%s: colorMode must be seuss, ramp, or random, not \"%s\"\n", + progname, mode_str); + exit (1); + } + + if (mono_p) cmode = seuss_mode; + if (cmode == random_mode) + cmode = ((random()&3) == 1) ? ramp_mode : seuss_mode; + + if (cmode == ramp_mode) + anim_p = False; /* This combo doesn't work right... */ + if (mono_p) { fg_pixel = get_pixel_resource ("foreground","Foreground", dpy, cmap); @@ -94,8 +117,15 @@ init_circles (dpy, window) } else { - hsv_to_rgb (0, 0.5, 1.0, &fgc.red, &fgc.green, &fgc.blue); - hsv_to_rgb (180, 1.0, 0.7, &bgc.red, &bgc.green, &bgc.blue); + int r = random() % 360; + int r2 = (random() % 180) + 45; + double fs, bs; + if (cmode == seuss_mode) + fs = 0.5, bs = 1.0; + else + fs = 1.0, bs = 0.1; + hsv_to_rgb (r, fs, 1.0, &fgc.red, &fgc.green, &fgc.blue); + hsv_to_rgb ((r+r2)%360, bs, 0.7, &bgc.red, &bgc.green, &bgc.blue); XAllocColor (dpy, cmap, &fgc); XAllocColor (dpy, cmap, &bgc); fg_pixel = fgc.pixel; @@ -110,7 +140,7 @@ init_circles (dpy, window) #endif pixmap = XCreatePixmap (dpy, window, width, height, 1); - if (xor_p) + if (cmode == seuss_mode) buffer = XCreatePixmap (dpy, window, width, height, 1); else buffer = 0; @@ -124,7 +154,7 @@ init_circles (dpy, window) gcv.background = bg_pixel; copy_gc = XCreateGC (dpy, window, GCForeground | GCBackground, &gcv); - if (xor_p) + if (cmode == seuss_mode) { gcv.foreground = 1; gcv.background = 0; @@ -183,10 +213,10 @@ run_circles (dpy, window) done = True; } if (radius > 0 && - (xor_p || circles [0].increment < 0)) + (cmode == seuss_mode || circles [0].increment < 0)) XFillArc (dpy, - (xor_p ? pixmap : window), - (xor_p ? draw_gc : merge_gc), + (cmode == seuss_mode ? pixmap : window), + (cmode == seuss_mode ? draw_gc : merge_gc), circles [i].x - radius, circles [i].y - radius, radius * 2, radius * 2, 0, 360*64); circles [i].radius += inc; @@ -223,12 +253,17 @@ run_circles (dpy, window) init_circles_1 (dpy, window); if (! mono_p) { + XColor d1, d2; cycle_hue (&fgc, 10); cycle_hue (&bgc, 10); XFreeColors (dpy, cmap, &fgc.pixel, 1, 0); XFreeColors (dpy, cmap, &bgc.pixel, 1, 0); + d1 = fgc; + d2 = bgc; XAllocColor (dpy, cmap, &fgc); XAllocColor (dpy, cmap, &bgc); + fgc.red = d1.red; fgc.green = d1.green; fgc.blue = d1.blue; + bgc.red = d2.red; bgc.green = d2.green; bgc.blue = d2.blue; XSetForeground (dpy, copy_gc, fgc.pixel); XSetBackground (dpy, copy_gc, bgc.pixel); } @@ -254,7 +289,7 @@ run_circles (dpy, window) if (buffer) XCopyPlane (dpy, pixmap, buffer, merge_gc, 0, 0, width, height, 0, 0, 1); - else if (!xor_p) + else if (cmode != seuss_mode) { static int ncolors = 0; static XColor *colors = 0; @@ -319,18 +354,17 @@ char *progclass = "Halo"; char *defaults [] = { "Halo.background: black", /* to placate SGI */ "Halo.foreground: white", -/* "*xor: false", */ - "*count: 0", - "*delay: 100000", + "*colorMode: random", + "*count: 0", + "*delay: 100000", 0 }; XrmOptionDescRec options [] = { { "-count", ".count", XrmoptionSepArg, 0 }, { "-delay", ".delay", XrmoptionSepArg, 0 }, - { "-animate", ".animate", XrmoptionNoArg, "True" } /* , - { "-xor", ".xor", XrmoptionNoArg, "True" }, - { "-no-xor", ".xor", XrmoptionNoArg, "False" } */ + { "-animate", ".animate", XrmoptionNoArg, "True" }, + { "-mode", ".colorMode", XrmoptionSepArg, 0 } }; int options_size = (sizeof (options) / sizeof (options[0])); diff --git a/hacks/halo.man b/hacks/halo.man index 270bc2ff..5239ab57 100644 --- a/hacks/halo.man +++ b/hacks/halo.man @@ -3,7 +3,7 @@ halo - draw circular patterns .SH SYNOPSIS .B halo -[\-display \fIhost:display.screen\fP] [\-foreground \fIcolor\fP] [\-background \fIcolor\fP] [\-window] [\-root] [\-mono] [\-install] [\-visual \fIvisual\fP] [\-count \fIint\fP] [\-delay \fIusecs\fP] [\-animate] +[\-display \fIhost:display.screen\fP] [\-foreground \fIcolor\fP] [\-background \fIcolor\fP] [\-window] [\-root] [\-mono] [\-install] [\-visual \fIvisual\fP] [\-count \fIint\fP] [\-delay \fIusecs\fP] [\-mode seuss | ramp | random ] [\-animate] .SH DESCRIPTION The \fIhalo\fP program draws cool patterns based on circles. .SH OPTIONS @@ -29,6 +29,13 @@ or the id number (decimal or hex) of a specific visual. .B \-count \fIinteger\fP How many circles to draw. Default 0, meaning random. .TP 8 +.B \-mode "seuss | ramp | random" +In \fIseuss\fP mode, alternating striped curves will be drawn. + +In \fIramp\fP mode, a color ramp will be drawn. + +\fIrandom\fP means pick the mode randomly. +.TP 8 .B \-delay \fImicroseconds\fP How much of a delay should be introduced between steps of the animation. Default 100000, or about 0.1 second. @@ -58,4 +65,4 @@ appear in supporting documentation. No representations are made about the suitability of this software for any purpose. It is provided "as is" without express or implied warranty. .SH AUTHOR -Jamie Zawinski , 6-jul-93. +Jamie Zawinski , 6-jul-93. diff --git a/hacks/helix.c b/hacks/helix.c index a6ce0aa1..84c4fd8c 100644 --- a/hacks/helix.c +++ b/hacks/helix.c @@ -1,4 +1,4 @@ -/* xscreensaver, Copyright (c) 1992 Jamie Zawinski +/* xscreensaver, Copyright (c) 1992, 1995 Jamie Zawinski * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that @@ -9,10 +9,8 @@ * implied warranty. */ +#include #include "screenhack.h" -#ifdef __STDC__ -#include /* for M_PI */ -#endif static double sins [360]; static double coss [360]; @@ -196,7 +194,7 @@ char *defaults [] = { 0 }; -XrmOptionDescRec options [] = { 0 }; +XrmOptionDescRec options [] = { { 0, } }; int options_size = 0; void diff --git a/hacks/helix.man b/hacks/helix.man index 9777f1df..76c7cfef 100644 --- a/hacks/helix.man +++ b/hacks/helix.man @@ -47,4 +47,4 @@ appear in supporting documentation. No representations are made about the suitability of this software for any purpose. It is provided "as is" without express or implied warranty. .SH AUTHOR -Jamie Zawinski , 13-aug-92. +Jamie Zawinski , 13-aug-92. diff --git a/hacks/hopalong.c b/hacks/hopalong.c index ef409f8f..2a91ecef 100644 --- a/hacks/hopalong.c +++ b/hacks/hopalong.c @@ -1,4 +1,4 @@ -/* xscreensaver, Copyright (c) 1992 Jamie Zawinski +/* xscreensaver, Copyright (c) 1992, 1995 Jamie Zawinski * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that @@ -52,8 +52,8 @@ * 23-Mar-88: Coded HOPALONG routines from Scientific American Sept. 86 p. 14. */ -#include "screenhack.h" #include +#include "screenhack.h" static GC gc; static int batchcount = 1000; diff --git a/hacks/hopalong.man b/hacks/hopalong.man index d30746b6..d812c7b3 100644 --- a/hacks/hopalong.man +++ b/hacks/hopalong.man @@ -66,4 +66,4 @@ supporting documentation. Patrick J. Naughton , 23-mar-88. Ability to run standalone or with \fIxscreensaver\fP added by -Jamie Zawinski , 13-aug-92. +Jamie Zawinski , 13-aug-92. diff --git a/hacks/hypercube.c b/hacks/hypercube.c index e2e71a6b..05574fb3 100644 --- a/hacks/hypercube.c +++ b/hacks/hypercube.c @@ -1,4 +1,4 @@ -/* xscreensaver, Copyright (c) 1992 Jamie Zawinski +/* xscreensaver, Copyright (c) 1992, 1995 Jamie Zawinski * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that @@ -12,8 +12,8 @@ * and Jamie Zawinski. */ -#include "screenhack.h" #include +#include "screenhack.h" static Display *dpy; static Window window; diff --git a/hacks/hypercube.man b/hacks/hypercube.man index 5efd02c0..daa66899 100644 --- a/hacks/hypercube.man +++ b/hacks/hypercube.man @@ -90,4 +90,4 @@ appear in supporting documentation. No representations are made about the suitability of this software for any purpose. It is provided "as is" without express or implied warranty. .SH AUTHOR -Jamie Zawinski , 6-dec-92. +Jamie Zawinski , 6-dec-92. diff --git a/hacks/imsmap.c b/hacks/imsmap.c index fc4f2ca1..7a619b94 100644 --- a/hacks/imsmap.c +++ b/hacks/imsmap.c @@ -49,8 +49,8 @@ initwin (dsp, win) enum mode_t this_mode; static Bool rv_p; static int ncolors = 0; - int shift; - double dshift; + int shift = 0; + double dshift = 0; XGCValues gcv; diff --git a/hacks/imsmap.man b/hacks/imsmap.man index 178b4c51..1badced3 100644 --- a/hacks/imsmap.man +++ b/hacks/imsmap.man @@ -60,4 +60,4 @@ stored in the RESOURCE_MANAGER property. .SH AUTHOR Juergen Nickelsen , 23-aug-92. -Hacked on by Jamie Zawinski , 24-aug-92. +Hacked on by Jamie Zawinski , 24-aug-92. diff --git a/hacks/lmorph.c b/hacks/lmorph.c new file mode 100644 index 00000000..9672f962 --- /dev/null +++ b/hacks/lmorph.c @@ -0,0 +1,501 @@ + +/************************************************************************** + * + * FILE lmorph.c + * MODULE OF xscreensaver + * + * DESCRIPTION Bilinear interpolation for morphing line shapes. + * + * WRITTEN BY Sverre H. Huseby Glenn T. Lines + * Maridalsvn. 122, leil 101 Frysjavn. 3, 5. etg. + * N-0461 Oslo N-0883 Oslo + * Norway Norway + * + * Phone: +47 22 71 99 08 Phone: +47 22 23 71 99 + * E-mail: sverrehu@ifi.uio.no E-mail: gtl@si.sintef.no + * + * The original idea, and the bilinear interpolation + * mathematics used, emerged in the head of the wise + * Glenn Terje Lines. + * + * MODIFICATIONS march 1995 + * * Converted from an MS-Windows program to X Window. + * + **************************************************************************/ + +#include +#include +#include +#include +#include "screenhack.h" + +/************************************************************************** + * * + * P R I V A T E D A T A * + * * + **************************************************************************/ + +/* Define MARGINS to make some space around the figure */ +#define MARGINS /**/ + +#define MAXFIGS 20 +#define TWO_PI (2.0 * M_PI) +#define RND(x) (random() % (x)) +static int + cFig = 0, /* Number of figure arrays. */ + cPoint, /* Number of points in each array. */ + nWork, /* Current work array number. */ + nFrom, /* Current from array number. */ + nTo; /* Current to array number. */ +static long + delay; /* usecs to wait between updates. */ +static XPoint + *aWork[2], /* Working arrays. */ + *a[MAXFIGS], /* The figure arrays. */ + *aTmp, /* Used as source when interrupting morph */ + *aPrev, /* Previous points displayed. */ + *aCurr, /* The current points displayed. */ + *aFrom, /* Figure converting from. */ + *aTo; /* Figure converting to. */ +static double + gam, + maxGamma = 1.0, + delta_gam; +static GC + gcDraw, gcClear; +static Display + *dpy; +static Window + window; + + + +/************************************************************************** + * * + * P U B L I C D A T A * + * * + **************************************************************************/ + +char *progclass = "LMorph"; + +char *defaults [] = { + "LMorph.background: black", + "LMorph.foreground: green", + "*points: 150", + "*steps: 0", + "*delay: 50000", + 0 +}; + +XrmOptionDescRec options [] = { + { "-points", ".points", XrmoptionSepArg, 0 }, + { "-steps", ".steps", XrmoptionSepArg, 0 }, + { "-delay", ".delay", XrmoptionSepArg, 0 }, +}; +int options_size = (sizeof (options) / sizeof (options[0])); + + + +/************************************************************************** + * * + * P R I V A T E F U N C T I O N S * + * * + **************************************************************************/ + +static void *xmalloc(size) + size_t size; +{ + void *ret; + + if ((ret = malloc(size)) == NULL) { + fprintf(stderr, "lmorph: out of memory\n"); + exit(1); + } + return ret; +} + + + +static double frnd() +{ + /* + * Hm. for some reason the second line (using RAND_MAX) didn't + * work on some machines, so I always use the first. + */ +#undef RAND_MAX +#ifndef RAND_MAX + return (double) (random() & 0x7FFF) / 0x7FFF; +#else + return ((double) random()) / RAND_MAX; +#endif +} + + + +static void initPointArrays() +{ + XWindowAttributes wa; + int q, w, + mx, my, /* Max screen coordinates. */ + mp, /* Max point number. */ + s, rx, ry, + marginx, marginy; + double scalex, scaley; + + XGetWindowAttributes(dpy, window, &wa); + mx = wa.width - 1; + my = wa.height - 1; + mp = cPoint - 1; + + aWork[0] = (XPoint *) xmalloc(cPoint * sizeof(XPoint)); + aWork[1] = (XPoint *) xmalloc(cPoint * sizeof(XPoint)); + aTmp = (XPoint *) xmalloc(cPoint * sizeof(XPoint)); + + + /* + * Figure 0 + */ + a[cFig] = (XPoint *) xmalloc(cPoint * sizeof(XPoint)); + s = cPoint / 4; + for (q = 0; q < s; q++) { + a[cFig][q].x = ((double) q / s) * mx; + a[cFig][q].y = 0; + a[cFig][s + q].x = mx; + a[cFig][s + q].y = ((double) q / s) * my; + a[cFig][2 * s + q].x = mx - ((double) q / s) * mx; + a[cFig][2 * s + q].y = my; + a[cFig][3 * s + q].x = 0; + a[cFig][3 * s + q].y = my - ((double) q / s) * my; + } + for (q = 4 * s; q < cPoint; q++) + a[cFig][q].x = a[cFig][q].y = 0; + a[cFig][mp].x = a[cFig][0].x; + a[cFig][mp].y = a[cFig][0].y; + ++cFig; + + /* + * Figure 1 + */ + a[cFig] = (XPoint *) xmalloc(cPoint * sizeof(XPoint)); + for (q = 0; q < cPoint; q++) { + a[cFig][q].x = ((double) q / cPoint) * mx; + a[cFig][q].y = (1.0 - sin(((double) q / mp) * TWO_PI)) * my / 2.0; + } + ++cFig; + + /* + * Figure 2 + */ + a[cFig] = (XPoint *) xmalloc(cPoint * sizeof(XPoint)); + rx = mx / 2; + ry = my / 2; + for (q = 0; q < cPoint; q++) { + a[cFig][q].x = mx / 2 + rx * sin(1 * TWO_PI * (double) q / mp); + a[cFig][q].y = my / 2 + ry * cos(3 * TWO_PI * (double) q / mp); + } + a[cFig][mp].x = a[cFig][0].x; + a[cFig][mp].y = a[cFig][0].y; + ++cFig; + + /* + * Figure 3 + */ + a[cFig] = (XPoint *) xmalloc(cPoint * sizeof(XPoint)); + rx = mx / 2; + ry = my / 2; + for (q = 0; q < cPoint; q++) { + a[cFig][q].x = mx / 2 + ry * sin(3 * TWO_PI * (double) q / mp); + a[cFig][q].y = my / 2 + ry * cos(1 * TWO_PI * (double) q / mp); + } + a[cFig][mp].x = a[cFig][0].x; + a[cFig][mp].y = a[cFig][0].y; + ++cFig; + + /* + * Figure 4 + */ + a[cFig] = (XPoint *) xmalloc(cPoint * sizeof(XPoint)); + rx = mx / 2; + ry = my / 2; + for (q = 0; q < cPoint; q++) { + a[cFig][q].x = mx / 2 + ry * (1 - 0.1 * frnd()) + * sin(TWO_PI * (double) q / mp); + a[cFig][q].y = my / 2 + ry * (1 - 0.1 * frnd()) + * cos(TWO_PI * (double) q / mp); + } + a[cFig][mp].x = a[cFig][0].x; + a[cFig][mp].y = a[cFig][0].y; + ++cFig; + + /* + * Figure 5 + */ + a[cFig] = (XPoint *) xmalloc(cPoint * sizeof(XPoint)); + rx = mx / 2; + ry = my / 2; + for (q = 0; q < cPoint; q++) { + a[cFig][q].x = mx / 2 + ry * (0.8 - 0.2 * sin(30 * TWO_PI * q / mp)) + * sin(TWO_PI * (double) q / mp); + a[cFig][q].y = my / 2 + ry * (0.8 - 0.2 * sin(30 * TWO_PI * q / mp)) + * cos(TWO_PI * (double) q / mp); + } + a[cFig][mp].x = a[cFig][0].x; + a[cFig][mp].y = a[cFig][0].y; + ++cFig; + + /* + * Figure 6 + */ + a[cFig] = (XPoint *) xmalloc(cPoint * sizeof(XPoint)); + rx = mx / 2; + ry = my / 2; + for (q = 0; q < cPoint; q++) { + a[cFig][q].x = mx / 2 + ry * sin(TWO_PI * (double) q / mp); + a[cFig][q].y = my / 2 + ry * cos(TWO_PI * (double) q / mp); + } + a[cFig][mp].x = a[cFig][0].x; + a[cFig][mp].y = a[cFig][0].y; + ++cFig; + + /* + * Figure 7 + */ + a[cFig] = (XPoint *) xmalloc(cPoint * sizeof(XPoint)); + rx = mx / 2; + ry = my / 2; + for (q = 0; q < cPoint; q++) { + a[cFig][q].x = mx / 2 + rx * cos(TWO_PI * (double) q / mp); + a[cFig][q].y = my / 2 + ry * sin(TWO_PI * (double) q / mp); + } + a[cFig][mp].x = a[cFig][0].x; + a[cFig][mp].y = a[cFig][0].y; + ++cFig; + + /* + * Figure 8 + */ + a[cFig] = (XPoint *) xmalloc(cPoint * sizeof(XPoint)); + for (q = 0; q < cPoint; q++) { + a[cFig][q].x = ((double) q / mp) * mx; + a[cFig][q].y = (1.0 - cos(((double) q / mp) * 3 * TWO_PI)) * my / 2.0; + } + ++cFig; + + /* + * Figure 9 + */ + a[cFig] = (XPoint *) xmalloc(cPoint * sizeof(XPoint)); + rx = mx / 2; + ry = my / 2; + for (q = 0; q < cPoint; q++) { + a[cFig][q].x = mx / 2 + rx * sin(2 * TWO_PI * (double) q / mp); + a[cFig][q].y = my / 2 + ry * cos(3 * TWO_PI * (double) q / mp); + } + a[cFig][mp].x = a[cFig][0].x; + a[cFig][mp].y = a[cFig][0].y; + ++cFig; + + /* + * Figure 10 + */ + a[cFig] = (XPoint *) xmalloc(cPoint * sizeof(XPoint)); + rx = mx / 2; + ry = my / 2; + for (q = 0; q < cPoint; q++) { + a[cFig][q].x = mx / 2 + ry * sin(5 * TWO_PI * (double) q / mp) + * ((double) q / mp); + a[cFig][q].y = my / 2 + ry * cos(5 * TWO_PI * (double) q / mp) + * ((double) q / mp); + } + ++cFig; + + /* + * Figure 11 + */ + a[cFig] = (XPoint *) xmalloc(cPoint * sizeof(XPoint)); + rx = mx / 2; + ry = my / 2; + for (q = 0; q < cPoint; q++) { + a[cFig][q].x = mx / 2 + ry * sin(6 * TWO_PI * (double) q / mp) + * ((double) q / mp); + a[cFig][q].y = my / 2 - ry * cos(6 * TWO_PI * (double) q / mp) + * ((double) q / mp); + } + ++cFig; + + /* + * Figure 12 + */ + a[cFig] = (XPoint *) xmalloc(cPoint * sizeof(XPoint)); + for (q = 0; q < cPoint; q++) { + a[cFig][q].x = ((double) q / mp) * mx; + a[cFig][q].y = (1.0 - sin(((double) q / mp) * 5 * TWO_PI)) * my / 2.0; + } + ++cFig; + +#ifdef MARGINS + /* + * Make some space around the figures. + */ + marginx = (mx + 1) / 10; + marginy = (my + 1) / 10; + scalex = (double) ((mx + 1) - 2.0 * marginx) / (mx + 1.0); + scaley = (double) ((my + 1) - 2.0 * marginy) / (my + 1.0); + for (q = 0; q < cFig; q++) + for (w = 0; w < cPoint; w++) { + a[q][w].x = marginx + a[q][w].x * scalex; + a[q][w].y = marginy + a[q][w].y * scaley; + } +#endif +} + + + +static void createPoints() +{ + int q; + XPoint *pa = aCurr, *pa1 = aFrom, *pa2 = aTo; + long lg, l1g; + + + lg = 8192L * gam, l1g = 8192L * (1.0 - gam); + for (q = 0; q < cPoint; q++) { + pa->x = (short) ((l1g * pa1->x + lg * pa2->x) / 8192L); + pa->y = (short) ((l1g * pa1->y + lg * pa2->y) / 8192L); + ++pa; + ++pa1; + ++pa2; + } +} + + +static void drawImage() +{ + register int q; + XPoint *old0, *old1, *new0, *new1; + + /* + * Problem: update the window without too much flickering. I do + * this by handling each linesegment separately. First remove a + * line, then draw the new line. The problem is that this leaves + * small black pixels on the figure. To fix this, I draw the + * entire figure using XDrawLines() afterwards. + */ + if (aPrev) { + old0 = aPrev; + old1 = aPrev + 1; + new0 = aCurr; + new1 = aCurr + 1; + for (q = cPoint - 1; q; q--) { + XDrawLine(dpy, window, gcClear, + old0->x, old0->y, old1->x, old1->y); + XDrawLine(dpy, window, gcDraw, + new0->x, new0->y, new1->x, new1->y); + ++old0; + ++old1; + ++new0; + ++new1; + } + } + XDrawLines(dpy, window, gcDraw, aCurr, cPoint, CoordModeOrigin); + XFlush(dpy); +} + +static void initLMorph() +{ + int steps; + XGCValues gcv; + XWindowAttributes wa; + Colormap cmap; + + cPoint = get_integer_resource("points", "Integer"); + steps = get_integer_resource("steps", "Integer"); + delay = get_integer_resource("delay", "Integer"); + + if (steps <= 0) + steps = (random() % 400) + 100; + + delta_gam = 1.0 / steps; + XGetWindowAttributes(dpy, window, &wa); + cmap = wa.colormap; + gcv.foreground = get_pixel_resource("foreground", "Foreground", dpy, cmap); + gcDraw = XCreateGC(dpy, window, GCForeground, &gcv); + XSetForeground(dpy, gcDraw, gcv.foreground); + gcv.foreground = get_pixel_resource("background", "Background", dpy, cmap); + gcClear = XCreateGC(dpy, window, GCForeground, &gcv); + XClearWindow(dpy, window); + + srandom(time(NULL)); + initPointArrays(); + aCurr = aWork[nWork = 0]; + aPrev = NULL; + gam = 2.0; + nTo = RND(cFig); +} + +static void animateLMorph() +{ + if (gam > maxGamma) { + gam = 0.0; + if (maxGamma == 1.0) { + nFrom = nTo; + aFrom = a[nFrom]; + } else { + memcpy(aTmp, aCurr, cPoint * sizeof(XPoint)); + aFrom = aTmp; + nFrom = -1; + } + do { + nTo = RND(cFig); + } while (nTo == nFrom); + aTo = a[nTo]; + if (RND(2)) { + /* + * Reverse the array to get more variation. + */ + int i1, i2; + XPoint p; + + for (i1 = 0, i2 = cPoint - 1; i1 < cPoint / 2; i1++, i2--) { + p = aTo[i1]; + aTo[i1] = aTo[i2]; + aTo[i2] = p; + } + } + /* + * It may be nice to interrupt the next run. + */ + if (RND(3) > 0) + maxGamma = 0.1 + 0.7 * (RND(1001) / 1000.0); + else + maxGamma = 1.0; + } + + createPoints(); + drawImage(); + aPrev = aCurr; + aCurr = aWork[nWork ^= 1]; + + gam += delta_gam; +} + + + +/************************************************************************** + * * + * P U B L I C F U N C T I O N S * + * * + **************************************************************************/ + +void screenhack(disp, win) + Display *disp; + Window win; +{ + dpy = disp; + window = win; + initLMorph(); + for (;;) { + animateLMorph(); + screenhack_usleep(delay); + } +} diff --git a/hacks/lmorph.man b/hacks/lmorph.man new file mode 100644 index 00000000..a631f24c --- /dev/null +++ b/hacks/lmorph.man @@ -0,0 +1,54 @@ +.TH LMORPH 1 "xscreensaver hack" +.SH NAME +lmorph \- morphing lines +.SH SYNOPSIS +.B lmorph +[\-display \fIhost:display.screen\fP] [\-foreground \fIcolor\fP] [\-background \fIcolor\fP] [\-window] [\-root] [\-mono] [\-install] [\-visual \fIvisual\fP] [\-points \fIint\fP] [\-steps \fIint\fP] [\-delay \fIusecs\fP] +.SH DESCRIPTION +The \fIlmorph\fP program morphs between simple linedrawings using bilinear +interpolation. +.SH OPTIONS +.I lmorph +accepts the following options: +.TP 8 +.B \-window +Draw on a newly-created window. This is the default. +.TP 8 +.B \-root +Draw on the root window. +.TP 8 +.B \-mono +If on a color display, pretend we're on a monochrome display. +.TP 8 +.B \-install +Install a private colormap for the window. +.TP 8 +.B \-visual \fIvisual\fP +Specify which visual to use. Legal values are the name of a visual class, +or the id number (decimal or hex) of a specific visual. +.TP 8 +.B \-points \fIinteger\fP +Number of points in each line drawing. Default is 150 points. +.TP 8 +.B \-steps \fIinteger\fP +Interpolation steps from one drawing to the next. Default is 0, which +means a random number between 100 and 500. +.TP 8 +.B \-delay \fImicroseconds\fP +How much of a delay should be introduced between steps of the animation. +Default 50000. +.SH ENVIRONMENT +.PP +.TP 8 +.B DISPLAY +to get the default host and display number. +.TP 8 +.B XENVIRONMENT +to get the name of a resource file that overrides the global resources +stored in the RESOURCE_MANAGER property. +.SH SEE ALSO +.BR X (1), +.BR xscreensaver (1) +.SH AUTHOR +Sverre H. Huseby and Glenn T. Lines , +built on top of the screen saver routines by Jamie Zawinski . diff --git a/hacks/maze.c b/hacks/maze.c index 5a77195c..6d73796e 100644 --- a/hacks/maze.c +++ b/hacks/maze.c @@ -1,7 +1,9 @@ /****************************************************************************** * [ maze ] ... * - * modified: [ 3-7-93 ] Jamie Zawinski + * modified: [ 8-11-95 ] Ed James + * added fill of dead-end box to solve_maze while loop. + * modified: [ 3-7-93 ] Jamie Zawinski * added the XRoger logo, cleaned up resources, made * grid size a parameter. * modified: [ 3-3-93 ] Jim Randell @@ -285,7 +287,7 @@ static void enter_square (); static void create_maze() /* create a maze layout given the intiialized maze */ { - register int i, newdoor; + register int i, newdoor = 0; do { move_list[sqnum].x = cur_sq_x; @@ -564,6 +566,10 @@ solve_maze() /* solve it with graphical feedback */ /* do it */ while (1) { if ( ++path[i].dir >= 4 ) { + XFillRectangle(dpy, win, cgc, + border_x + bw + grid_width * (int)(path[i].x), + border_y + bw + grid_height * (int)(path[i].y), + grid_width - (bw+bw), grid_height - (bw+bw)); i--; draw_solid_square( (int)(path[i].x), (int)(path[i].y), (int)(path[i].dir), cgc); @@ -613,7 +619,7 @@ enter_square(n) /* move into a neighboring square */ /* - * jmr additions for Jamie Zawinski's screensaver stuff, + * jmr additions for Jamie Zawinski's screensaver stuff, * note that the code above this has probably been hacked about in some * arbitrary way. */ diff --git a/hacks/noseguy.c b/hacks/noseguy.c index a39df178..3a6542c8 100644 --- a/hacks/noseguy.c +++ b/hacks/noseguy.c @@ -1,4 +1,4 @@ -/* xscreensaver, Copyright (c) 1992 Jamie Zawinski +/* xscreensaver, Copyright (c) 1992 Jamie Zawinski * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that diff --git a/hacks/noseguy.man b/hacks/noseguy.man index 7f7bedb7..fe18d8df 100644 --- a/hacks/noseguy.man +++ b/hacks/noseguy.man @@ -71,4 +71,4 @@ Copyright 1985, 1990 by Dan Heller . Dan Heller , 1985. Ability to run standalone or with \fIxscreensaver\fP added by -Jamie Zawinski , 13-aug-92. +Jamie Zawinski , 13-aug-92. diff --git a/hacks/noses/CVS/Entries b/hacks/noses/CVS/Entries index 7ca1c40a..7c60d8fc 100644 --- a/hacks/noses/CVS/Entries +++ b/hacks/noses/CVS/Entries @@ -1,8 +1,8 @@ -/nose.0.left/1.1/Mon Dec 19 04:30:41 1994 Thu Aug 25 15:04:28 1994// -/nose.0.right/1.1/Mon Dec 19 04:30:41 1994 Thu Aug 25 15:04:29 1994// -/nose.1.left/1.1/Mon Dec 19 04:30:41 1994 Thu Aug 25 15:04:30 1994// -/nose.1.right/1.1/Mon Dec 19 04:30:41 1994 Thu Aug 25 15:04:31 1994// -/nose.down/1.1/Mon Dec 19 04:30:41 1994 Thu Aug 25 15:04:32 1994// -/nose.front/1.1/Mon Dec 19 04:30:41 1994 Thu Aug 25 15:04:33 1994// -/nose.left.front/1.1/Mon Dec 19 04:30:41 1994 Thu Aug 25 15:04:34 1994// -/nose.right.front/1.1/Mon Dec 19 04:30:41 1994 Thu Aug 25 15:04:35 1994// +/nose.0.left/1.1/Fri Mar 17 18:30:19 1995 Thu Aug 25 15:04:28 1994// +/nose.0.right/1.1/Fri Mar 17 18:30:19 1995 Thu Aug 25 15:04:29 1994// +/nose.1.left/1.1/Fri Mar 17 18:30:20 1995 Thu Aug 25 15:04:30 1994// +/nose.1.right/1.1/Fri Mar 17 18:30:20 1995 Thu Aug 25 15:04:31 1994// +/nose.down/1.1/Fri Mar 17 18:30:20 1995 Thu Aug 25 15:04:32 1994// +/nose.front/1.1/Fri Mar 17 18:30:20 1995 Thu Aug 25 15:04:33 1994// +/nose.left.front/1.1/Fri Mar 17 18:30:20 1995 Thu Aug 25 15:04:34 1994// +/nose.right.front/1.1/Fri Mar 17 18:30:20 1995 Thu Aug 25 15:04:35 1994// diff --git a/hacks/pedal.c b/hacks/pedal.c index b39fef4f..8cde8d53 100644 --- a/hacks/pedal.c +++ b/hacks/pedal.c @@ -372,11 +372,11 @@ char *progclass = "Pedal"; * should be dark. */ char *defaults [] = { + "Pedal.background: black", /* to placate SGI */ + "Pedal.foreground: white", "*delay: 5", "*fadedelay: 200000", "*maxlines: 1000", - "*foreground: white", - "*background: black", 0 }; diff --git a/hacks/pyro.c b/hacks/pyro.c index f7df260b..996f7833 100644 --- a/hacks/pyro.c +++ b/hacks/pyro.c @@ -1,4 +1,4 @@ -/* xscreensaver, Copyright (c) 1992, 1994 Jamie Zawinski +/* xscreensaver, Copyright (c) 1992, 1994 Jamie Zawinski * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that diff --git a/hacks/pyro.man b/hacks/pyro.man index 5e83518a..8edb9669 100644 --- a/hacks/pyro.man +++ b/hacks/pyro.man @@ -57,4 +57,4 @@ appear in supporting documentation. No representations are made about the suitability of this software for any purpose. It is provided "as is" without express or implied warranty. .SH AUTHOR -Jamie Zawinski , 13-aug-92. +Jamie Zawinski , 13-aug-92. diff --git a/hacks/qix.c b/hacks/qix.c index e45c7955..c26e7367 100644 --- a/hacks/qix.c +++ b/hacks/qix.c @@ -1,4 +1,4 @@ -/* xscreensaver, Copyright (c) 1992 Jamie Zawinski +/* xscreensaver, Copyright (c) 1992, 1995 Jamie Zawinski * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that @@ -400,9 +400,21 @@ add_qline (dpy, window, cmap, qline, prev_qline, qix) if (!mono_p && !transparent_p) { + XColor desired; cycle_hue (&qline->color, color_shift); qline->color.flags = DoRed | DoGreen | DoBlue; - if (!XAllocColor (dpy, cmap, &qline->color)) + desired = qline->color; + if (XAllocColor (dpy, cmap, &qline->color)) + { + /* XAllocColor returns the actual RGB that the hardware let us + allocate. Restore the requested values into the XColor struct + so that limited-resolution hardware doesn't cause cycle_hue to + get "stuck". */ + qline->color.red = desired.red; + qline->color.green = desired.green; + qline->color.blue = desired.blue; + } + else { qline->color = prev_qline->color; if (!XAllocColor (dpy, cmap, &qline->color)) diff --git a/hacks/qix.man b/hacks/qix.man index c67221c0..816a55a3 100644 --- a/hacks/qix.man +++ b/hacks/qix.man @@ -111,4 +111,4 @@ appear in supporting documentation. No representations are made about the suitability of this software for any purpose. It is provided "as is" without express or implied warranty. .SH AUTHOR -Jamie Zawinski , 13-aug-92. +Jamie Zawinski , 13-aug-92. diff --git a/hacks/rocks.c b/hacks/rocks.c index 8cf49cf3..4e9e901e 100644 --- a/hacks/rocks.c +++ b/hacks/rocks.c @@ -1,4 +1,4 @@ -/* xscreensaver, Copyright (c) 1992 Jamie Zawinski +/* xscreensaver, Copyright (c) 1992, 1995 Jamie Zawinski * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that @@ -13,12 +13,9 @@ John Nguyen */ -#include "screenhack.h" #include #include -#if __STDC__ -#include /* for M_PI */ -#endif +#include "screenhack.h" #define MIN_DEPTH 2 /* rocks disappar when they get this close */ #define MAX_DEPTH 60 /* this is where rocks appear */ @@ -148,7 +145,7 @@ init_pixmaps (dpy, window) { int i; XGCValues gcv; - GC fg_gc = 0, bg_gc; + GC fg_gc = 0, bg_gc = 0; pixmaps [0] = pixmaps [1] = 0; for (i = MIN_DEPTH; i < MAX_WIDTH; i++) { diff --git a/hacks/rocks.man b/hacks/rocks.man index af45f894..22256d3e 100644 --- a/hacks/rocks.man +++ b/hacks/rocks.man @@ -68,4 +68,4 @@ express or implied warranty. .SH AUTHOR Based on Lisp Machine code copyright 1988 John Nguyen . -Ported to C and X by Jamie Zawinski , 13-aug-92. +Ported to C and X by Jamie Zawinski , 13-aug-92. diff --git a/hacks/rorschach.c b/hacks/rorschach.c index bb17ffc9..bea709cd 100644 --- a/hacks/rorschach.c +++ b/hacks/rorschach.c @@ -1,4 +1,4 @@ -/* xscreensaver, Copyright (c) 1992 Jamie Zawinski +/* xscreensaver, Copyright (c) 1992 Jamie Zawinski * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that diff --git a/hacks/rorschach.man b/hacks/rorschach.man index 1b0b2495..4619f0ff 100644 --- a/hacks/rorschach.man +++ b/hacks/rorschach.man @@ -61,4 +61,4 @@ appear in supporting documentation. No representations are made about the suitability of this software for any purpose. It is provided "as is" without express or implied warranty. .SH AUTHOR -Jamie Zawinski , 13-aug-92. +Jamie Zawinski , 13-aug-92. diff --git a/hacks/screenhack.c b/hacks/screenhack.c index 42615536..6c7a0300 100644 --- a/hacks/screenhack.c +++ b/hacks/screenhack.c @@ -1,4 +1,4 @@ -/* xscreensaver, Copyright (c) 1992, 1995 Jamie Zawinski +/* xscreensaver, Copyright (c) 1992, 1995 Jamie Zawinski * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that diff --git a/hacks/screenhack.h b/hacks/screenhack.h index fb3de4ce..9be43672 100644 --- a/hacks/screenhack.h +++ b/hacks/screenhack.h @@ -1,4 +1,4 @@ -/* xscreensaver, Copyright (c) 1992-1995 Jamie Zawinski +/* xscreensaver, Copyright (c) 1992-1995 Jamie Zawinski * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that @@ -57,6 +57,12 @@ #include #endif +#ifdef __hpux + /* Which of the ten billion standards does values.h belong to? + What systems always have it? */ +# include +#endif + #include #include #include @@ -70,26 +76,11 @@ extern XrmOptionDescRec options []; extern int options_size; extern char *defaults []; -#if __STDC__ -# if (defined(SVR4) || defined(SYSV)) && !defined(__sgi) -# ifndef random - extern int rand (void); -# define random() rand() -# endif -# ifndef srandom - extern void srand (unsigned int); -# define srandom(i) srand((unsigned int)(i)) -# endif -# else /* !totally-losing-SYSV */ -# ifndef random - extern long random (void); -# endif -# ifndef srandom - extern int srandom (unsigned int); -# endif -# endif /* !totally-losing-SYSV */ -#endif /* __STDC__ */ +/* Screw it, we'll just use our own RNG. See xscreensaver/utils/yarandom.c. */ +#include "yarandom.h" + +#undef P #if __STDC__ # define P(x)x #else @@ -126,11 +117,23 @@ extern Pixmap grab_screen_image P((Display *dpy, Window window, int root_p)); extern void copy_default_colormap_contents P((Display *dpy, Colormap to_cmap, Visual *to_visual)); +#if defined (__GNUC__) && (__GNUC__ >= 2) + /* Implement frand using GCC's statement-expression extension. */ + +# define frand(f) \ + ({ double tmp = (((double) random()) / \ + (((double) ((unsigned int)~0)) / ((double) (f+f)))); \ + tmp < 0 ? (-tmp) : tmp; }) + +#else /* not GCC2 - implement frand using a global variable.*/ + static double _frand_tmp_; -#define frand(f) \ - (_frand_tmp_ = (((double) random()) / \ - (((double) ((unsigned int)~0)) / ((double) (f+f)))), \ - _frand_tmp_ < 0 ? (-_frand_tmp_) : _frand_tmp_) +# define frand(f) \ + (_frand_tmp_ = (((double) random()) / \ + (((double) ((unsigned int)~0)) / ((double) (f+f)))), \ + _frand_tmp_ < 0 ? (-_frand_tmp_) : _frand_tmp_) + +#endif /* not GCC2 */ #undef P #endif /* _SCREENHACK_H_ */ diff --git a/hacks/slidescreen.c b/hacks/slidescreen.c index 52f0d975..6c8ccf71 100644 --- a/hacks/slidescreen.c +++ b/hacks/slidescreen.c @@ -1,4 +1,5 @@ -/* xscreensaver, Copyright (c) 1992, 1993, 1994 Jamie Zawinski +/* xscreensaver, Copyright (c) 1992, 1993, 1994 + * Jamie Zawinski * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that diff --git a/hacks/slidescreen.man b/hacks/slidescreen.man index 9dc86fc0..3d03dc50 100644 --- a/hacks/slidescreen.man +++ b/hacks/slidescreen.man @@ -65,4 +65,4 @@ appear in supporting documentation. No representations are made about the suitability of this software for any purpose. It is provided "as is" without express or implied warranty. .SH AUTHOR -Jamie Zawinski , 3-dec-92. +Jamie Zawinski , 3-dec-92. diff --git a/hacks/xlock.h b/hacks/xlock.h index a53a99a9..19e5fdab 100644 --- a/hacks/xlock.h +++ b/hacks/xlock.h @@ -5,6 +5,9 @@ ** for xlock 2.3 and xscreensaver 1.2, 28AUG92 ** ** +** Modified for xlockmore 3.0 by Anthony Thyssen +** on August 1995. +** ** To use, just copy the appropriate file from xlock, add a target ** for it in the Imakefile, and do the following: ** @@ -38,8 +41,13 @@ static Colormap cmap; static int batchcount; static unsigned int delay; +static unsigned int cycles; static double saturation; +#ifndef min +#define min(a,b) ((a)<(b)?(a):(b)) +#endif + typedef struct { GC gc; int npixels; @@ -75,7 +83,8 @@ My_XGetWindowAttributes (dpy, win, xgwa) bg_pixel = get_pixel_resource ("background", "Background", dpy, cmap); if (! mono_p) { for (npixels = 0; npixels < i; npixels++) { - hsv_to_rgb ((360*npixels)/i, saturation, 1.0, &color.red, &color.green, &color.blue); + hsv_to_rgb ((360*npixels)/i, saturation, 1.0, + &color.red, &color.green, &color.blue); if (! XAllocColor (dpy, cmap, &color)) break; pixels[npixels] = color.pixel; @@ -86,6 +95,9 @@ My_XGetWindowAttributes (dpy, win, xgwa) n = get_integer_resource ("count", "Integer"); if (n > 0) batchcount = n; + n = get_integer_resource ("cycles", "Integer"); + if (n >= 0) cycles = n; + gcv.foreground = fg_pixel; gcv.background = bg_pixel; gc = XCreateGC (dpy, win, GCForeground|GCBackground, &gcv); @@ -113,6 +125,8 @@ char *defaults[] = { "*foreground: white", "*ncolors: 64", "*delay: -1", + "*count: -1", + "*cycles: -1", 0 }; @@ -120,10 +134,11 @@ XrmOptionDescRec options[] = { {"-count", ".count", XrmoptionSepArg, 0}, {"-ncolors", ".ncolors", XrmoptionSepArg, 0}, {"-delay", ".delay", XrmoptionSepArg, 0}, + {"-cycles", ".cycles", XrmoptionSepArg, 0}, }; int options_size = (sizeof (options) / sizeof (options[0])); -#define PROGRAM(Y,Z,D,B,S) \ +#define PROGRAM(Y,Z,D,B,C,S) \ char *progclass = Y; \ \ void screenhack (dpy, window) \ @@ -132,15 +147,14 @@ void screenhack (dpy, window) \ { \ batchcount = B; \ delay = D; \ + cycles = C; \ saturation = S; \ dsp = dpy; \ \ + init##Z (window); \ while (1) { \ - init##Z (window); \ - for (;;) { \ - draw##Z (window); \ - XSync (dpy, True); \ - if (delay) usleep (delay); \ - } \ + draw##Z (window); \ + XSync (dpy, True); \ + if (delay) usleep (delay); \ } \ } diff --git a/hacks/xroger-hack.c b/hacks/xroger-hack.c index 72bd2d3c..615ade16 100644 --- a/hacks/xroger-hack.c +++ b/hacks/xroger-hack.c @@ -1,4 +1,4 @@ -/* xscreensaver, Copyright (c) 1991-1994 Jamie Zawinski +/* xscreensaver, Copyright (c) 1991-1994 Jamie Zawinski * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that diff --git a/hacks/xroger.man b/hacks/xroger.man index 2eeb2e66..799f5005 100644 --- a/hacks/xroger.man +++ b/hacks/xroger.man @@ -49,4 +49,4 @@ notice appear in supporting documentation. No representations are made about the suitability of fnord this software for any purpose. It is provided "as is" without express or fnord implied warranty. .SH AUTHOR -Jamie Zawinski , 13-aug-92. +Jamie Zawinski , 13-aug-92. diff --git a/utils/Imakefile b/utils/Imakefile index 25642827..5f61d60a 100644 --- a/utils/Imakefile +++ b/utils/Imakefile @@ -13,10 +13,10 @@ DEFINES = R5ISMS #endif SRCS = fade.c hsv.c resources.c spline.c usleep.c xroger.c \ - grabscreen.c visual.c + grabscreen.c visual.c yarandom.c OBJS = fade.o hsv.o resources.o spline.o usleep.o xroger.o \ - grabscreen.o visual.o - TARFILES = README Imakefile ad2c $(SRCS) spline.h version.h + grabscreen.o visual.o yarandom.o + TARFILES = README Imakefile ad2c $(SRCS) spline.h yarandom.h version.h all:: $(OBJS) diff --git a/utils/fade.c b/utils/fade.c index 16f815ce..40fe9ddd 100644 --- a/utils/fade.c +++ b/utils/fade.c @@ -1,4 +1,4 @@ -/* xscreensaver, Copyright (c) 1992 Jamie Zawinski +/* xscreensaver, Copyright (c) 1992 Jamie Zawinski * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that diff --git a/utils/grabscreen.c b/utils/grabscreen.c index 57e695fe..692e42e1 100644 --- a/utils/grabscreen.c +++ b/utils/grabscreen.c @@ -1,4 +1,4 @@ -/* xscreensaver, Copyright (c) 1992, 1993, 1994 Jamie Zawinski +/* xscreensaver, Copyright (c) 1992, 1993, 1994 Jamie Zawinski * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that diff --git a/utils/hsv.c b/utils/hsv.c index 2a88dffc..c5109120 100644 --- a/utils/hsv.c +++ b/utils/hsv.c @@ -1,4 +1,4 @@ -/* xscreensaver, Copyright (c) 1992 Jamie Zawinski +/* xscreensaver, Copyright (c) 1992 Jamie Zawinski * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that diff --git a/utils/resources.c b/utils/resources.c index 1e73abec..02c499b3 100644 --- a/utils/resources.c +++ b/utils/resources.c @@ -1,4 +1,4 @@ -/* xscreensaver, Copyright (c) 1992 Jamie Zawinski +/* xscreensaver, Copyright (c) 1992 Jamie Zawinski * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that diff --git a/utils/usleep.c b/utils/usleep.c index 2de351eb..30e7f152 100644 --- a/utils/usleep.c +++ b/utils/usleep.c @@ -1,4 +1,4 @@ -/* xscreensaver, Copyright (c) 1992 Jamie Zawinski +/* xscreensaver, Copyright (c) 1992 Jamie Zawinski * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that diff --git a/utils/version.h b/utils/version.h index f7d28871..a56e38a5 100644 --- a/utils/version.h +++ b/utils/version.h @@ -1,2 +1,2 @@ static char *screensaver_id = - "@(#)xscreensaver 1.25, by Jamie Zawinski (jwz@mcom.com)"; + "@(#)xscreensaver 1.26, by Jamie Zawinski (jwz@netscape.com)"; diff --git a/utils/visual.c b/utils/visual.c index 2737752d..cc8b5729 100644 --- a/utils/visual.c +++ b/utils/visual.c @@ -1,4 +1,5 @@ -/* xscreensaver, Copyright (c) 1993, 1994, 1995 Jamie Zawinski +/* xscreensaver, Copyright (c) 1993, 1994, 1995 + * Jamie Zawinski * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that diff --git a/utils/xroger.c b/utils/xroger.c index 01fd7d7f..039a97fc 100644 --- a/utils/xroger.c +++ b/utils/xroger.c @@ -1,4 +1,4 @@ -/* xscreensaver, Copyright (c) 1991-1993 Jamie Zawinski +/* xscreensaver, Copyright (c) 1991-1993 Jamie Zawinski * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that diff --git a/utils/yarandom.c b/utils/yarandom.c new file mode 100644 index 00000000..228b81ca --- /dev/null +++ b/utils/yarandom.c @@ -0,0 +1,72 @@ +/* ya_random -- Yet Another Random Number Generator. + + The unportable mess that is rand(), random(), drand48() and friends led me + to ask Phil Karlton what the Right Thing to Do was. + He responded with this. It is non-cryptographically secure, reasonably + random (more so than anything that is in any C library), and very fast. + + I don't understand how it works at all, but he says "look at Knuth, + Vol. 2 (original edition), page 26, Algorithm A. In this case n=55, + k=20 and m=2^32." + + So there you have it. + */ + +#include /* for getpid() */ +#include /* for gettimeofday() */ + + +/* The following 'random' numbers are taken from CRC, 18th Edition, page 622. + Each array element was taken from the corresponding line in the table, + except that a[0] was from line 100. 8s and 9s in the table were simply + skipped. The high order digit was taken mod 4. + */ +#define VectorSize 55 +static unsigned int a[VectorSize] = { + 035340171546, 010401501101, 022364657325, 024130436022, 002167303062, /* 5 */ + 037570375137, 037210607110, 016272055420, 023011770546, 017143426366, /* 10 */ + 014753657433, 021657231332, 023553406142, 004236526362, 010365611275, /* 14 */ + 007117336710, 011051276551, 002362132524, 001011540233, 012162531646, /* 20 */ + 007056762337, 006631245521, 014164542224, 032633236305, 023342700176, /* 25 */ + 002433062234, 015257225043, 026762051606, 000742573230, 005366042132, /* 30 */ + 012126416411, 000520471171, 000725646277, 020116577576, 025765742604, /* 35 */ + 007633473735, 015674255275, 017555634041, 006503154145, 021576344247, /* 40 */ + 014577627653, 002707523333, 034146376720, 030060227734, 013765414060, /* 45 */ + 036072251540, 007255221037, 024364674123, 006200353166, 010126373326, /* 50 */ + 015664104320, 016401041535, 016215305520, 033115351014, 017411670323 /* 55 */ +}; + +static int i1, i2; + +unsigned int ya_random() +{ + register int ret = a[i1] + a[i2]; + a[i1] = ret; + i1 = i1 >= VectorSize ? 0 : i1 + 1; + i2 = i2 >= VectorSize ? 0 : i2 + 1; + return ret; +} + +void ya_rand_init(seed) + register unsigned int seed; +{ + int i; + if (seed == 0) + { + struct timeval tp; + struct timezone tzp; + gettimeofday(&tp, &tzp); + /* ignore overflow */ + seed = (999*tp.tv_sec) + (1001*tp.tv_usec) + (1003 * getpid()); + } + + a[0] += seed; + for (i = 1; i < VectorSize; i++) + { + seed = a[i-1]*1001 + seed*999; + a[i] += seed; + } + + i1 = a[0] % VectorSize; + i2 = (i1 + 024) % VectorSize; +} diff --git a/utils/yarandom.h b/utils/yarandom.h new file mode 100644 index 00000000..53b22fd8 --- /dev/null +++ b/utils/yarandom.h @@ -0,0 +1,19 @@ +#undef random +#undef rand +#undef drand48 +#undef srandom +#undef srand +#undef srand48 + +#define random() ya_random() +#define srandom(i) ya_rand_init(0) + +#undef P +#if __STDC__ +# define P(x)x +#else +# define P(x)() +#endif + +extern unsigned int ya_random P((void)); +extern void ya_rand_init P((unsigned int)); -- 2.30.2