-/* xscreensaver, Copyright (c) 1992 Jamie Zawinski <jwz@netscape.com>
+/* xscreensaver, Copyright (c) 1992, 1996, 1997, 1998
+ * Jamie Zawinski <jwz@jwz.org>
*
* Permission to use, copy, modify, distribute, and sell this software and its
* documentation for any purpose is hereby granted without fee, provided that
#include "screenhack.h"
#include <stdio.h>
-#if __STDC__
extern FILE *popen (const char *, const char *);
extern int pclose (FILE *);
-#endif
-
-#define Pixel unsigned long
#define font_height(font) (font->ascent + font->descent)
#define FONT_NAME "-*-times-*-*-*-*-18-*-*-*-*-*-*-*"
static Window window;
static int Width, Height;
static GC fg_gc, bg_gc, text_fg_gc, text_bg_gc;
-static char *words, *get_words();
+static char *words;
+static char *get_words (void);
static int x, y;
static XFontStruct *font;
static char *def_words = "I'm out running around.";
-static void init_images(), walk(), talk();
-static int think();
-static unsigned long interval, look();
-static Pixmap left0, left1, right0, right1;
+static void walk (int dir);
+static void talk (int erase);
+static void talk_1 (void);
+static int think (void);
+static unsigned long interval;
+static unsigned long look (void);
+static Pixmap left1, left2, right1, right2;
static Pixmap left_front, right_front, front, down;
static char *program, *orig_program, *filename, *text;
#define GET_PASSWD 2
static int state; /* indicates states: walking or getting passwd */
-static void (*next_fn) ();
-
-#include "noses/nose.0.left"
-#include "noses/nose.1.left"
-#include "noses/nose.0.right"
-#include "noses/nose.1.right"
-#include "noses/nose.left.front"
-#include "noses/nose.right.front"
-#include "noses/nose.front"
-#include "noses/nose.down"
+static void (*next_fn) (void);
+
+#ifdef HAVE_XPM
+# include <X11/xpm.h>
+
+# include "images/noseguy/nose-f1.xpm"
+# include "images/noseguy/nose-f2.xpm"
+# include "images/noseguy/nose-f3.xpm"
+# include "images/noseguy/nose-f4.xpm"
+# include "images/noseguy/nose-l1.xpm"
+# include "images/noseguy/nose-l2.xpm"
+# include "images/noseguy/nose-r1.xpm"
+# include "images/noseguy/nose-r2.xpm"
+#else
+# include "images/noseguy/nose-f1.xbm"
+# include "images/noseguy/nose-f2.xbm"
+# include "images/noseguy/nose-f3.xbm"
+# include "images/noseguy/nose-f4.xbm"
+# include "images/noseguy/nose-l1.xbm"
+# include "images/noseguy/nose-l2.xbm"
+# include "images/noseguy/nose-r1.xbm"
+# include "images/noseguy/nose-r2.xbm"
+#endif
static void
-init_images ()
+init_images (void)
{
static Pixmap *images[] = {
- &left0, &left1, &right0, &right1,
+ &left1, &left2, &right1, &right2,
&left_front, &right_front, &front, &down
};
+ int i;
+#ifdef HAVE_XPM
+ static char **bits[] = {
+ nose_l1_xpm, nose_l2_xpm, nose_r1_xpm, nose_r2_xpm,
+ nose_f2_xpm, nose_f3_xpm, nose_f1_xpm, nose_f4_xpm
+ };
+ for (i = 0; i < sizeof (images) / sizeof(*images); i++)
+ {
+ XWindowAttributes xgwa;
+ XpmAttributes xpmattrs;
+ Pixmap pixmap = 0;
+ int result;
+ xpmattrs.valuemask = 0;
+
+ XGetWindowAttributes (dpy, window, &xgwa);
+
+# ifdef XpmCloseness
+ xpmattrs.valuemask |= XpmCloseness;
+ xpmattrs.closeness = 40000;
+# endif
+# ifdef XpmVisual
+ xpmattrs.valuemask |= XpmVisual;
+ xpmattrs.visual = xgwa.visual;
+# endif
+# ifdef XpmDepth
+ xpmattrs.valuemask |= XpmDepth;
+ xpmattrs.depth = xgwa.depth;
+# endif
+# ifdef XpmColormap
+ xpmattrs.valuemask |= XpmColormap;
+ xpmattrs.colormap = xgwa.colormap;
+# endif
+
+ result = XpmCreatePixmapFromData(dpy, window, bits[i],
+ &pixmap, 0 /* mask */, &xpmattrs);
+ if (!pixmap || (result != XpmSuccess && result != XpmColorError))
+ {
+ fprintf (stderr, "%s: Can't load nose images\n", progname);
+ exit (1);
+ }
+ *images[i] = pixmap;
+ }
+#else
static unsigned char *bits[] = {
- nose_0_left_bits, nose_1_left_bits, nose_0_right_bits,
- nose_1_right_bits, nose_left_front_bits, nose_right_front_bits,
- nose_front_bits, nose_down_bits
+ nose_l1_bits, nose_l2_bits, nose_r1_bits, nose_r2_bits,
+ nose_f2_bits, nose_f3_bits, nose_f1_bits, nose_f4_bits
};
- int i;
- for (i = 0; i < sizeof (images) / sizeof (images[0]); i++)
+ for (i = 0; i < sizeof (images) / sizeof(*images); i++)
if (!(*images[i] =
XCreatePixmapFromBitmapData(dpy, window,
(char *) bits[i], 64, 64, 1, 0, 1)))
{
- fprintf (stderr, "%s: Can't load nose images", progname);
+ fprintf (stderr, "%s: Can't load nose images\n", progname);
exit (1);
}
+#endif
}
#define LEFT 001
#define Y_INCR 2
static void
-move()
+move (void)
{
static int length,
dir;
next_fn = move;
}
+#ifdef HAVE_XPM
+# define COPY(dpy,frame,window,gc,x,y,w,h,x2,y2) \
+ XCopyArea (dpy,frame,window,gc,x,y,w,h,x2,y2)
+#else
+# define COPY(dpy,frame,window,gc,x,y,w,h,x2,y2) \
+ XCopyPlane(dpy,frame,window,gc,x,y,w,h,x2,y2,1L)
+#endif
+
static void
-walk(dir)
- register int dir;
+walk(int dir)
{
register int incr = 0;
static int lastdir;
if (dir & LEFT)
{
incr = X_INCR;
- frame = (up < 0) ? left0 : left1;
+ frame = (up < 0) ? left1 : left2;
}
else
{
incr = -X_INCR;
- frame = (up < 0) ? right0 : right1;
+ frame = (up < 0) ? right1 : right2;
}
if ((lastdir == FRONT || lastdir == DOWN) && dir & UP)
{
* workaround silly bug that leaves screen dust when guy is
* facing forward or down and moves up-left/right.
*/
- XCopyPlane(dpy, frame, window, fg_gc, 0, 0, 64, 64, x, y, 1L);
+ COPY(dpy, frame, window, fg_gc, 0, 0, 64, 64, x, y);
XFlush(dpy);
}
/* note that maybe neither UP nor DOWN is set! */
}
/* Explicit up/down movement only (no left/right) */
else if (dir == UP)
- XCopyPlane(dpy, front, window, fg_gc,
- 0, 0, 64, 64, x, y -= Y_INCR, 1L);
+ COPY(dpy, front, window, fg_gc, 0, 0, 64, 64, x, y -= Y_INCR);
else if (dir == DOWN)
- XCopyPlane(dpy, down, window, fg_gc,
- 0, 0, 64, 64, x, y += Y_INCR, 1L);
+ COPY(dpy, down, window, fg_gc, 0, 0, 64, 64, x, y += Y_INCR);
else if (dir == FRONT && frame != front)
{
if (up > 0)
frame = right_front;
else
frame = front;
- XCopyPlane(dpy, frame, window, fg_gc, 0, 0, 64, 64, x, y, 1L);
+ COPY(dpy, frame, window, fg_gc, 0, 0, 64, 64, x, y);
}
if (dir & LEFT)
while (--incr >= 0)
{
- XCopyPlane(dpy, frame, window, fg_gc,
- 0, 0, 64, 64, --x, y + up, 1L);
+ COPY(dpy, frame, window, fg_gc, 0, 0, 64, 64, --x, y + up);
XFlush(dpy);
}
else if (dir & RIGHT)
while (++incr <= 0)
{
- XCopyPlane(dpy, frame, window, fg_gc,
- 0, 0, 64, 64, ++x, y + up, 1L);
+ COPY(dpy, frame, window, fg_gc, 0, 0, 64, 64, ++x, y + up);
XFlush(dpy);
}
lastdir = dir;
}
static int
-think()
+think (void)
{
if (random() & 1)
walk(FRONT);
if (random() & 1)
{
if (getwordsfrom == FROM_PROGRAM)
- words = get_words(0, (char **) 0);
+ words = get_words();
return 1;
}
return 0;
#define MAXLINES 40
static void
-talk(force_erase)
- int force_erase;
+talk(int force_erase)
{
int width = 0,
height,
walk(FRONT);
p = strcpy(buf, words);
- if (!(p2 = index(p, '\n')) || !p2[1])
+ if (!(p2 = strchr(p, '\n')) || !p2[1])
{
total = strlen (words);
strcpy (args[0], words);
break;
}
p = p2 + 1;
- if (!(p2 = index(p, '\n')))
+ if (!(p2 = strchr(p, '\n')))
break;
}
height++;
}
interval = (total / 15) * 1000;
if (interval < 2000) interval = 2000;
- next_fn = talk;
+ next_fn = talk_1;
}
+static void talk_1 (void)
+{
+ talk(0);
+}
+
+
static unsigned long
-look()
+look (void)
{
if (random() % 3)
{
- XCopyPlane(dpy, (random() & 1) ? down : front, window, fg_gc,
- 0, 0, 64, 64, x, y, 1L);
+ COPY(dpy, (random() & 1) ? down : front, window, fg_gc,
+ 0, 0, 64, 64, x, y);
return 1000L;
}
if (!(random() % 5))
return 0;
if (random() % 3)
{
- XCopyPlane(dpy, (random() & 1) ? left_front : right_front,
- window, fg_gc, 0, 0, 64, 64, x, y, 1L);
+ COPY(dpy, (random() & 1) ? left_front : right_front,
+ window, fg_gc, 0, 0, 64, 64, x, y);
return 1000L;
}
if (!(random() % 5))
return 0;
- XCopyPlane(dpy, (random() & 1) ? left0 : right0, window, fg_gc,
- 0, 0, 64, 64, x, y, 1L);
+ COPY(dpy, (random() & 1) ? left1 : right1, window, fg_gc,
+ 0, 0, 64, 64, x, y);
return 1000L;
}
static void
-init_words()
+init_words (void)
{
char *mode = get_string_resource ("mode", "Mode");
static int first_time = 1;
static char *
-get_words()
+get_words (void)
{
FILE *pp;
static char buf[BUFSIZ];
switch (getwordsfrom)
{
case FROM_PROGRAM:
+#ifndef VMS
if ((pp = popen(program, "r")))
{
while (fgets(p, sizeof(buf) - strlen(buf), pp))
p = def_words;
}
break;
+#endif /* VMS */
case FROM_FILE:
if ((pp = fopen(filename, "r")))
{
char *progclass = "Noseguy";
char *defaults [] = {
- "Noseguy.background: black", /* to placate SGI */
- "Noseguy.foreground: white",
+ ".background: black",
+ ".foreground: gray80",
+#ifndef VMS
"*mode: program",
- "*program: fortune -s",
+#else
+ "*mode: string",
+#endif
+ "*program: " ZIPPY_PROGRAM,
"noseguy.font: -*-new century schoolbook-*-r-*-*-*-180-*-*-*-*-*-*",
0
};
{ "-filename", ".filename", XrmoptionSepArg, 0 },
{ "-font", ".font", XrmoptionSepArg, 0 },
{ "-text-foreground", ".textForeground", XrmoptionSepArg, 0 },
- { "-text-background", ".textBackground", XrmoptionSepArg, 0 }
+ { "-text-background", ".textBackground", XrmoptionSepArg, 0 },
+ { 0, 0, 0, 0 }
};
-int options_size = (sizeof (options) / sizeof (options[0]));
static void
-noseguy_init (d, w)
- Display *d;
- Window w;
+noseguy_init (Display *d, Window w)
{
- Pixel fg, bg, text_fg, text_bg;
+ unsigned long fg, bg, text_fg, text_bg;
XWindowAttributes xgwa;
Colormap cmap;
char *fontname = get_string_resource ("font", "Font");
}
void
-screenhack (d, w)
- Display *d;
- Window w;
+screenhack (Display *d, Window w)
{
noseguy_init (d, w);
next_fn = move;
while (1)
{
- next_fn (0);
+ next_fn();
XSync (dpy, True);
usleep (interval * 1000);
}