-/* xscreensaver, Copyright (c) 1992, 1993, 1994 Jamie Zawinski <jwz@mcom.com>
+/* xscreensaver, Copyright (c) 1992, 1993, 1994, 1996, 1997
+ * Jamie Zawinski <jwz@netscape.com>
*
* Permission to use, copy, modify, distribute, and sell this software and its
* documentation for any purpose is hereby granted without fee, provided that
static int grid_w, grid_h;
static int delay, delay2;
static GC gc;
+int max_width, max_height;
static void
-init_slide (dpy, window)
- Display *dpy;
- Window window;
+init_slide (Display *dpy, Window window)
{
int i;
XGCValues gcv;
XWindowAttributes xgwa;
int border;
- int root_p;
unsigned long fg;
- Pixmap pixmap;
Drawable d;
Colormap cmap;
Visual *visual;
XGetWindowAttributes (dpy, window, &xgwa);
cmap = xgwa.colormap;
visual = xgwa.visual;
-
- copy_default_colormap_contents (dpy, cmap, visual);
+ max_width = xgwa.width;
+ max_height = xgwa.height;
delay = get_integer_resource ("delay", "Integer");
delay2 = get_integer_resource ("delay2", "Integer");
grid_size = get_integer_resource ("gridSize", "Integer");
pix_inc = get_integer_resource ("pixelIncrement", "Integer");
border = get_integer_resource ("internalBorderWidth", "InternalBorderWidth");
- fg = get_pixel_resource ("background", "Background", dpy,
- /* Pixels always come out of default map. */
- XDefaultColormapOfScreen (xgwa.screen));
- root_p = get_boolean_resource ("root", "Boolean");
+ fg = get_pixel_resource ("background", "Background", dpy, cmap);
+
+ grab_screen_image (xgwa.screen, window);
+
+
+ /* Total kludge -- if grab_screen_image() installed a new colormap, assume
+ that pixel 0 is the one we should use. This further assumes that the
+ pixel is black, which overrides the user's -background setting, alas.
+ */
+ XGetWindowAttributes (dpy, window, &xgwa);
+ if (cmap != xgwa.colormap) fg = 0;
+
if (delay < 0) delay = 0;
if (delay2 < 0) delay2 = 0;
gc = XCreateGC (dpy, window, GCForeground |GCFunction | GCSubwindowMode,
&gcv);
- pixmap = grab_screen_image (dpy, window, root_p);
-
XGetWindowAttributes (dpy, window, &xgwa);
bitmap_w = xgwa.width;
bitmap_h = xgwa.height;
xoff = (bitmap_w - (grid_w * grid_size)) / 2;
yoff = (bitmap_h - (grid_h * grid_size)) / 2;
- d = (pixmap ? pixmap : window);
+ d = window;
if (border)
{
- int i;
for (i = 0; i <= bitmap_w; i += grid_size)
XFillRectangle (dpy, d, gc, xoff+i-border/2, yoff, border, bitmap_h);
for (i = 0; i <= bitmap_h; i += grid_size)
XFillRectangle (dpy, d, gc, 0, bitmap_h - yoff, bitmap_w, yoff);
}
- if (pixmap) XClearWindow (dpy, window);
XSync (dpy, True);
if (delay2) usleep (delay2 * 2);
for (i = 0; i < grid_size; i += pix_inc)
}
static void
-slide1 (dpy, window)
- Display *dpy;
- Window window;
+slide1 (Display *dpy, Window window)
{
/* this code is a total kludge, but who cares, it works... */
int i, x, y, ix, iy, dx, dy, dir, w, h, size, inc;
inc = pix_inc;
for (i = 0; i < grid_size; i += inc)
{
+ int fx, fy, tox, toy;
if (inc + i > grid_size)
inc = grid_size - i;
- XCopyArea (dpy, window, window, gc, x, y, grid_size * w, grid_size * h,
- x - dx * inc, y - dy * inc);
+ tox = x - dx * inc;
+ toy = y - dy * inc;
+
+ fx = (x < 0 ? 0 : x > max_width ? max_width : x);
+ fy = (y < 0 ? 0 : y > max_height ? max_height : y);
+ tox = (tox < 0 ? 0 : tox > max_width ? max_width : tox);
+ toy = (toy < 0 ? 0 : toy > max_height ? max_height : toy);
+
+ XCopyArea (dpy, window, window, gc,
+ fx, fy,
+ grid_size * w, grid_size * h,
+ tox, toy);
+
x -= dx * inc;
y -= dy * inc;
switch (dir)
char *progclass = "SlidePuzzle";
char *defaults [] = {
- "SlidePuzzle.mappedWhenManaged:false",
- "SlidePuzzle.dontClearWindow: true",
- "*background: black",
+ "*dontClearRoot: True",
+
+#ifdef __sgi /* really, HAVE_READ_DISPLAY_EXTENSION */
+ "*visualID: Best",
+#endif
+
+ "*background: Black",
"*gridSize: 70",
"*pixelIncrement: 10",
"*internalBorderWidth: 1",
{ "-increment", ".pixelIncrement", XrmoptionSepArg, 0 },
{ "-delay", ".delay", XrmoptionSepArg, 0 },
{ "-delay2", ".delay2", XrmoptionSepArg, 0 },
+ { 0, 0, 0, 0 }
};
-int options_size = (sizeof (options) / sizeof (options[0]));
-
void
-screenhack (dpy, window)
- Display *dpy;
- Window window;
+screenhack (Display *dpy, Window window)
{
init_slide (dpy, window);
while (1)