jkh@ardent.UUCP (Jordan K. Hubbard) (06/06/88)
#! /bin/sh
# This is a shell archive. Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file". To overwrite existing
# files, type "sh file -c". You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g.. If this archive is complete, you
# will see the following message at the end:
# "End of archive 3 (of 8)."
# Contents: Gadget.c GridBox.c Iconify.c Icons.c Move.c NewIconify.c
# Wrapped by jkh@ardent on Sun Jun 5 18:56:29 1988
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'Gadget.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'Gadget.c'\"
else
echo shar: Extracting \"'Gadget.c'\" \(7997 characters\)
sed "s/^X//" >'Gadget.c' <<'END_OF_FILE'
X/*
X * Written February 29th, 1988.
X * By Jordan Hubbard, for Ardent Computer Corporation.
X *
X */
X#include "awm.h"
X#include "X11/Xutil.h"
X
extern XContext AwmContext;
X
AwmInfoPtr IsGadgetWin(w, gnum)
Window w;
int *gnum;
X{
X AwmInfoPtr awi;
X int i;
X
X Entry("IsGadgetWin")
X
X if (!XFindContext(dpy, w, AwmContext, &awi)) {
X Window *wp;
X
X if (!awi->gadgets)
X Leave((AwmInfoPtr)NULL)
X for (i = 0; i < NumGadgets; i++)
X if (awi->gadgets[i] == w) {
X if (gnum)
X *gnum = i;
X Leave(awi)
X }
X Leave((AwmInfoPtr)NULL)
X }
X}
X
Boolean FPutGadgets(w, mask, button, x, y)
Window w;
int mask, button, x, y;
X{
X Entry("FPutGadgets")
X
X if (w == RootWindow(dpy, scr))
X Leave(FALSE)
X PutGadgets(w);
X Leave(TRUE)
X}
X
X/*
X * This routine adds and gadgets onto title bar 'w' (though just
X * about any window would do, I suppose).
X */
int PutGadgets(w)
Window w;
X{
X int i, dir;
X int rx, lx, nx, ny;
X XWindowAttributes xwa;
X XSetWindowAttributes swa;
X unsigned long valuemask;
X GadgetDecl *gdec;
X AwmInfo *awi;
X char *cp;
X Boolean change = FALSE;
X Binding *bptr;
X Window tmp;
X
X Entry("PutGadgets")
X
X /* are there any gadgets declared? */
X if (NumGadgets < 1)
X Leave_void
X /* does this window have a title? */
X if (!(awi = IsTitled(w)))
X Leave_void
X else
X w = awi->title;
X /* if the window already has gadgets, this is a reshuffle */
X if (awi->gadgets)
X change = TRUE;
X else
X awi->gadgets = (Window *)malloc(sizeof(Window) * NumGadgets + 1);
X if (XGetWindowAttributes(dpy, w, &xwa) == BadWindow) {
X fprintf(stderr, "PutGadgets: Can't get attributes for title window %x\n",
X w);
X Leave_void
X }
X /* define some initial positioning information */
X dir = RightGadgetGravity;
X lx = 0;
X rx = xwa.width;
X valuemask = CWBackPixel | CWEventMask;
X swa.event_mask = (ButtonPressMask | ButtonReleaseMask | ExposureMask);
X for (i = 0; i < NumGadgets && Gadgets[i]; i++) {
X XGCValues gcv;
X
X gdec = Gadgets[i];
X
X /* Does gadget have its own gravity? */
X if (gdec->gravity != NoGadgetGravity)
X dir = gdec->gravity;
X ny = xwa.height - gdec->high;
X if (ny <= 0) {
X ny = 0;
X gdec->high = xwa.height;
X }
X else
X ny = (ny / 2) - 1;
X if (ny < 0)
X ny = 0;
X if (dir == LeftGadgetGravity) {
X nx = lx + gdec->offset;
X if (nx != 0 && nx == lx) /* not first time through, add pad */
X nx = lx + GadgetPad;
X if (nx < 0)
X nx = 0;
X lx = nx + gdec->wide;
X dir = RightGadgetGravity;
X }
X else { /* right gravity */
X nx = rx - gdec->wide - gdec->offset;
X if (!gdec->offset && rx != xwa.width)
X nx -= GadgetPad;
X if (nx > xwa.width)
X nx = xwa.width - gdec->wide - 1;
X rx = nx;
X dir = LeftGadgetGravity;
X }
X if (change == FALSE) {
X swa.background_pixel = gdec->backcolor;
X tmp = awi->gadgets[i] = XCreateWindow(dpy, w, nx, ny, gdec->wide,
X gdec->high, 1,
X xwa.depth, xwa.class,
X xwa.visual, valuemask, &swa);
X if (!tmp) {
X fprintf(stderr, "PutGadgets: Unable to create gadget window #%d\n",
X i);
X Leave_void
X }
X if (gdec->data) {
X Pixmap pix;
X
X pix = XCreatePixmapFromBitmapData(dpy, tmp, gdec->data,
X gdec->wide, gdec->high,
X gdec->forecolor, gdec->backcolor,
X xwa.depth);
X if (!pix) {
X fprintf(stderr, "PutGadgets: Unable to create pixmap for #%d\n",
X i);
X fprintf(stderr, "Using grey...\n");
X pix = GrayPixmap;
X }
X XSetWindowBackgroundPixmap(dpy, tmp, pix);
X XFreePixmap(dpy, pix);
X }
X XMapWindow(dpy, tmp);
X XSaveContext(dpy, tmp, AwmContext, awi);
X }
X else
X XMoveWindow(dpy, awi->gadgets[i], nx, ny);
X }
X if (change == FALSE) /* make sure the window array is null terminated */
X awi->gadgets[i] = (Window)NULL;
X Leave_void
X}
X
int FreeGadget(n)
int n;
X{
X Entry("FreeGadget")
X
X if (Gadgets[n]->data)
X XFree(Gadgets[n]->data);
X if (Gadgets[n]->name)
X free(Gadgets[n]->name);
X /* They tell me that this is not necessary for read-only cells. True?
X if (Gadgets[n]->forecolor)
X XFreeColors(dpy, DefaultColormap(dpy, scr),
X &(Gadgets[n]->forecolor), 1, AllPlanes);
X if (Gadgets[n]->backcolor)
X XFreeColors(dpy, DefaultColormap(dpy, scr),
X &(Gadgets[n]->backcolor), 1, AllPlanes);
X */ /* color free's commented out */
X}
X
int CheckGadgets()
X{
X int i, status = 0;
X
X Entry("CheckGadgets")
X
X for (i = 0; i < NumGadgets; i++)
X if (!Gadgets[i]) {
X fprintf(stderr, "awm: Gadget #%d is not declared!\n",
X i);
X fprintf(stderr, "All gadgets from 0 to %d must be declared.\n",
X NumGadgets - 1);
X status = 1;
X }
X Leave(status)
X}
X
Boolean ResetGadgets()
X{
X int i;
X
X Entry("ResetGadgets")
X
X for (i = 0; i < NumGadgets; i++) {
X FreeGadget(i);
X free(Gadgets[i]);
X Gadgets[i] = 0;
X }
X NumGadgets = 0;
X}
X
Boolean FDestroyGadgets(w, mask, button, x, y)
Window w;
int mask, button, x, y;
X{
X Entry("FDestroyGadgets")
X
X if (w == RootWindow(dpy, scr))
X Leave(FALSE)
X DestroyGadgets(w);
X Leave(TRUE)
X}
X
int DestroyGadgets(w)
Window w;
X{
X int i;
X AwmInfoPtr awi;
X
X Entry("DestroyGadgets")
X
X if (!(awi = IsTitled(w)))
X Leave_void
X if (!awi->gadgets)
X Leave_void
X for (i = 0; i < NumGadgets && Gadgets[i]; i++) {
X XDeleteContext(dpy, awi->gadgets[i], AwmContext);
X XDestroyWindow(dpy, awi->gadgets[i]);
X }
X free(awi->gadgets);
X awi->gadgets = 0;
X Leave_void
X}
X
int PaintGadgets(w)
Window w;
X{
X int i, y, x = 0;
X AwmInfoPtr awi;
X GadgetDecl *gdec;
X
X Entry("PaintGadgets")
X
X if (!(awi = IsTitled(w)))
X Leave_void
X if (!awi->gadgets)
X Leave_void
X for (i = 0; i < NumGadgets && Gadgets[i]; i++) {
X gdec = Gadgets[i];
X if (!gdec->data) {
X XGCValues gcv;
X
X gcv.font = gdec->fontInfo->fid;
X gcv.foreground = gdec->forecolor;
X gcv.background = gdec->backcolor;
X XChangeGC(dpy, awi->winGC, (GCFont | GCForeground | GCBackground),
X &gcv);
X y = (gdec->high + (gdec->fontInfo->max_bounds.ascent -
X gdec->fontInfo->max_bounds.descent)) / 2;
X x = 0;
X if (strlen(gdec->name) == 1) { /* it's a glyph (we think) */
X XFontStruct *real_font;
X XCharStruct char_info;
X int char_number, index, byte1, byte2;
X
X real_font = gdec->fontInfo;
X char_number = gdec->name[0];
X char_info = real_font->max_bounds;
X index = char_number;
X
X if (real_font->per_char) {
X if (!real_font->min_byte1 && !real_font->max_byte1) {
X if (char_number < real_font->min_char_or_byte2 ||
X char_number > real_font->max_char_or_byte2)
X index = real_font->default_char;
X index -= real_font->min_char_or_byte2;
X } else {
X byte2 = index & 0xff;
X byte1 = (index>>8) & 0xff;
X if (byte1 < real_font->min_byte1 ||
X byte1 > real_font->max_byte1 ||
X byte2 < real_font->min_char_or_byte2 ||
X byte2 > real_font->max_char_or_byte2) {
X byte2 = real_font->default_char & 0xff;
X byte1 = (real_font->default_char>>8)&0xff;
X }
X byte1 -= real_font->min_byte1;
X byte2 -= real_font->min_char_or_byte2;
X index = byte1 * (real_font->max_char_or_byte2 -
X real_font->min_char_or_byte2 + 1) +
X byte2;
X }
X char_info = real_font->per_char[index];
X }
X x = 0 - char_info.lbearing;
X y = char_info.ascent;
X }
X XDrawString(dpy, awi->gadgets[i], awi->winGC, x,
X y, gdec->name, strlen(gdec->name));
X }
X }
X Leave(0)
X}
END_OF_FILE
if test 7997 -ne `wc -c <'Gadget.c'`; then
echo shar: \"'Gadget.c'\" unpacked with wrong size!
fi
# end of 'Gadget.c'
fi
if test -f 'GridBox.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'GridBox.c'\"
else
echo shar: Extracting \"'GridBox.c'\" \(7071 characters\)
sed "s/^X//" >'GridBox.c' <<'END_OF_FILE'
X#ifndef lint
static char *rcsid_StoreGridBox_c = "$Header: GridBox.c,v 1.3 87/09/11 08:21:55 toddb Exp $";
X#endif lint
X
X#include "X11/copyright.h"
X
X/*
X * Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
X *
X * All Rights Reserved
X *
X * Permission to use, copy, modify, and distribute this software and its
X * documentation for any purpose and without fee is hereby granted,
X * provided that the above copyright notice appear in all copies and that
X * both that copyright notice and this permission notice appear in
X * supporting documentation, and that the name of Digital Equipment
X * Corporation not be used in advertising or publicity pertaining to
X * distribution of the software without specific, written prior permission.
X *
X *
X * DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
X * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
X * DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
X * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
X * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
X * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
X * SOFTWARE.
X */
X
X
X
X/*
X * MODIFICATION HISTORY
X *
X * 000 -- M. Gancarz, DEC Ultrix Engineering Group
X * 001 -- Loretta Guarino Reid, DEC Ultrix Engineering Group,
X Western Software Lab. Converted to X11.
X */
X
X#ifndef lint
static char *sccsid = "@(#)StoreGridBox.c 3.8 1/24/86";
X#endif
X
extern int Fheight;
X
X/*
X * StoreGridBox - This subroutine is used by the X Window Manager (xwm)
X * to store the vertices for the movement resize grid and box in a
X * vertex list.
X */
X
X#include "awm.h"
X
X/*
X * Store the vertices for the movement resize grid and box in a vertex list.
X */
int StoreGridBox(box, ulx, uly, lrx, lry)
register XSegment box[];
int ulx; /* Upper left X coordinate. */
int uly; /* Upper left Y coordinate. */
int lrx; /* Lower right X coordinate. */
int lry; /* Lower right Y coordinate. */
X{
X register int xthird, ythird;
X int x1third, y1third;
X int x2third, y2third;
X
X Entry("StoreGridBox")
X
X /*
X * Xor in.
X */
X box[0].x1 = ulx; box[0].y1 = uly;
X box[0].x2 = lrx; box[0].y2 = uly;
X
X box[1].x1 = lrx; box[1].y1 = uly;
X box[1].x2 = lrx; box[1].y2 = lry;
X
X box[2].x1 = lrx; box[2].y1 = lry;
X box[2].x2 = ulx; box[2].y2 = lry;
X
X box[3].x1 = ulx; box[3].y1 = lry;
X box[3].x2 = ulx; box[3].y2 = uly;
X
X
X /*
X * These are the X and Y calculations for the parts of the grid that
X * are dependent on the division by 3 calculations.
X */
X
X /*
X * Y dimension third.
X */
X ythird = (lry - uly) / 3;
X y1third = uly + ythird;
X y2third = y1third + ythird;
X
X /*
X * X dimension third.
X */
X xthird = (lrx - ulx) / 3;
X x1third = ulx + xthird;
X x2third = x1third + xthird;
X
X box[4].x1 = x1third; box[4].y1 = lry;
X box[4].x2 = x1third; box[4].y2 = uly;
X
X box[5].x1 = x2third; box[5].y1 = lry;
X box[5].x2 = x2third; box[5].y2 = uly;
X
X box[6].x1 = ulx; box[6].y1 = y1third;
X box[6].x2 = lrx; box[6].y2 = y1third;
X
X box[7].x1 = ulx; box[7].y1 = y2third;
X box[7].x2 = lrx; box[7].y2 = y2third;
X
X /*
X * Do not erase if we're freezing the screen.
X */
X if (Freeze)
X Leave(8)
X
X /*
X * From here on we're retracing the segments to clear the
X * grid using GXxor.
X */
X box[8].x1 = ulx; box[8].y1 = uly;
X box[8].x2 = lrx; box[8].y2 = uly;
X
X box[9].x1 = lrx; box[9].y1 = uly;
X box[9].x2 = lrx; box[9].y2 = lry;
X
X box[10].x1 = lrx; box[10].y1 = lry;
X box[10].x2 = ulx; box[10].y2 = lry;
X
X box[11].x1 = ulx; box[11].y1 = lry;
X box[11].x2 = ulx; box[11].y2 = uly;
X
X box[12].x1 = x1third; box[12].y1 = lry;
X box[12].x2 = x1third; box[12].y2 = uly;
X
X box[13].x1 = x2third; box[13].y1 = lry;
X box[13].x2 = x2third; box[13].y2 = uly;
X
X box[14].x1 = ulx; box[14].y1 = y1third;
X box[14].x2 = lrx; box[14].y2 = y1third;
X
X box[15].x1 = ulx; box[15].y1 = y2third;
X box[15].x2 = lrx; box[15].y2 = y2third;
X
X
X /*
X * Total number of segments is 16.
X */
X Leave(16)
X}
X
X/*
X * Store the vertices for the movement resize grid and box in a vertex list.
X * This is just like the routine above, but it adds a line for titled windows.
X */
X
extern int Fheight;
X
int StoreTitleGridBox(box, ulx, uly, lrx, lry)
register XSegment box[];
int ulx; /* Upper left X coordinate. */
int uly; /* Upper left Y coordinate. */
int lrx; /* Lower right X coordinate. */
int lry; /* Lower right Y coordinate. */
X{
X register int xthird, ythird;
X int x1third, y1third;
X int x2third, y2third;
X
X Entry("StoreTitleGridBox")
X
X /*
X * Xor in.
X */
X box[0].x1 = ulx; box[0].y1 = uly;
X box[0].x2 = lrx; box[0].y2 = uly;
X
X box[1].x1 = ulx; box[1].y1 = uly + Fheight + 2;
X box[1].x2 = lrx; box[1].y2 = uly + Fheight + 2;
X
X box[2].x1 = lrx; box[2].y1 = uly;
X box[2].x2 = lrx; box[2].y2 = lry;
X
X box[3].x1 = lrx; box[3].y1 = lry;
X box[3].x2 = ulx; box[3].y2 = lry;
X
X box[4].x1 = ulx; box[4].y1 = lry;
X box[4].x2 = ulx; box[4].y2 = uly;
X
X
X /*
X * These are the X and Y calculations for the parts of the grid that
X * are dependent on the division by 3 calculations.
X */
X
X /*
X * Y dimension third.
X */
X ythird = (lry - uly - Fheight - 2) / 3;
X y1third = uly + ythird + Fheight + 2;
X y2third = y1third + ythird;
X
X /*
X * X dimension third.
X */
X xthird = (lrx - ulx) / 3;
X x1third = ulx + xthird;
X x2third = x1third + xthird;
X
X box[5].x1 = x1third; box[5].y1 = lry;
X box[5].x2 = x1third; box[5].y2 = uly + Fheight + 3;
X
X box[6].x1 = x2third; box[6].y1 = lry;
X box[6].x2 = x2third; box[6].y2 = uly + Fheight + 3;
X
X box[7].x1 = ulx; box[7].y1 = y1third;
X box[7].x2 = lrx; box[7].y2 = y1third;
X
X box[8].x1 = ulx; box[8].y1 = y2third;
X box[8].x2 = lrx; box[8].y2 = y2third;
X
X /*
X * Do not erase if we're freezing the screen.
X */
X if (Freeze)
X Leave(9)
X
X /*
X * From here on we're retracing the segments to clear the
X * grid using GXxor.
X */
X box[9].x1 = ulx; box[9].y1 = uly;
X box[9].x2 = lrx; box[9].y2 = uly;
X
X box[10].x1 = ulx; box[10].y1 = uly + Fheight + 2;
X box[10].x2 = lrx; box[10].y2 = uly + Fheight + 2;
X
X box[11].x1 = lrx; box[11].y1 = uly;
X box[11].x2 = lrx; box[11].y2 = lry;
X
X box[12].x1 = lrx; box[12].y1 = lry;
X box[12].x2 = ulx; box[12].y2 = lry;
X
X box[13].x1 = ulx; box[13].y1 = lry;
X box[13].x2 = ulx; box[13].y2 = uly;
X
X box[14].x1 = x1third; box[14].y1 = lry;
X box[14].x2 = x1third; box[14].y2 = uly + Fheight + 3;
X
X box[15].x1 = x2third; box[15].y1 = lry;
X box[15].x2 = x2third; box[15].y2 = uly + Fheight + 3;
X
X box[16].x1 = ulx; box[16].y1 = y1third;
X box[16].x2 = lrx; box[16].y2 = y1third;
X
X box[17].x1 = ulx; box[17].y1 = y2third;
X box[17].x2 = lrx; box[17].y2 = y2third;
X
X
X /*
X * Total number of segments is 18.
X */
X Leave(18)
X}
END_OF_FILE
if test 7071 -ne `wc -c <'GridBox.c'`; then
echo shar: \"'GridBox.c'\" unpacked with wrong size!
fi
# end of 'GridBox.c'
fi
if test -f 'Iconify.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'Iconify.c'\"
else
echo shar: Extracting \"'Iconify.c'\" \(6147 characters\)
sed "s/^X//" >'Iconify.c' <<'END_OF_FILE'
X/* $Header: Iconify.c,v 1.1 87/09/11 08:21:28 toddb Exp $ */
X#include "X11/copyright.h"
X
X/*
X * Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
X *
X * All Rights Reserved
X *
X * Permission to use, copy, modify, and distribute this software and its
X * documentation for any purpose and without fee is hereby granted,
X * provided that the above copyright notice appear in all copies and that
X * both that copyright notice and this permission notice appear in
X * supporting documentation, and that the name of Digital Equipment
X * Corporation not be used in advertising or publicity pertaining to
X * distribution of the software without specific, written prior permission.
X *
X *
X * DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
X * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
X * DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
X * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
X * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
X * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
X * SOFTWARE.
X */
X
X
X
X/*
X * MODIFICATION HISTORY
X *
X * 000 -- M. Gancarz, DEC Ultrix Engineering Group
X * 001 -- R. Kittell, DEC Storage A/D May 20, 1986
X * Add optional warp of mouse to the upper right corner on de-iconify,
X * and to the icon center on iconify.
X * 002 -- Loretta Guarino Reid, DEC Ultrix Engineering Group,
X * Western Software Lab. Port to X11.
X * 003 -- Jordan Hubbard, Ardent Computer.
X * Many mods to cope with context manager, titled windows. Almost a total
X * rewrite.
X */
X
X#ifndef lint
static char *sccsid = "%W% %G%";
X#endif
X
X#include "awm.h"
X
Boolean Iconify(window, mask, button, x, y)
Window window; /* Event window. */
int mask; /* Button/key mask. */
int button; /* Button event detail. */
int x, y; /* Event mouse position. */
X{
X XWindowAttributes fromInfo; /* info on "from" window */
X XWindowAttributes toInfo; /* info on "to" window */
X int mse_x, mse_y; /* Mouse X and Y coordinates. */
X int sub_win_x, sub_win_y; /* relative Mouse coordinates. */
X int num_vectors; /* Number of vectors in zap buffer. */
X int mmask; /* Mouse state */
X Window root; /* Mouse root window. */
X Window from, to; /* from -> to windows */
X Window sub_win; /* Mouse position sub-window. */
X XSegment zap[MAX_ZAP_VECTORS]; /* Zap effect vertex buffer. */
X Boolean dozap; /* local Zap */
X AwmInfoPtr awi;
X
X Entry("Iconify")
X
X /*
X * Do not try to iconify the root window.
X */
X if (window == RootWindow(dpy, scr))
X Leave(FALSE)
X /*
X * The original idea of zap lines has one flaw. If a window wants
X * to be created iconic, it should just appear that way without any
X * fuss. CheckMap() calls us with (win, 0, 0, 0, 0) when this is the
X * case, so we can special case this to turn off Zap temporarily.
X * Since we don't want to mess with the global "Zap", we use
X * "dozap" instead.
X */
X dozap = (mask || button || x || y) ? Zap : FALSE;
X /*
X * Clear the vector buffer.
X */
X if (dozap)
X bzero(zap, sizeof(zap));
X
X /*
X * Get the mouse cursor position in case we must put a new
X * icon there.
X */
X XQueryPointer(dpy, RootWindow(dpy, scr), &root, &sub_win,
X &mse_x, &mse_y, &sub_win_x, &sub_win_y, &mmask);
X
X
X /*
X * Figure out which direction we're going in (icon->window or vica-versa)
X */
X awi = GetAwmInfo(window);
X if (awi->state == ICON) {
X from = awi->icon;
X to = (awi->frame) ? awi->frame : awi->client;
X if (awi->placed == FALSE)
X PlaceWindow(to);
X }
X else if (awi->state == WINDOW) {
X from = (awi->frame) ? awi->frame : awi->client;
X to = (awi->icon) ? awi->icon : MakeIcon(window, mse_x, mse_y, TRUE);
X }
X else {
X printf("Iconify: Window %x has unknown state '%x'\n",
X awi->client, awi->state);
X Leave(FALSE)
X }
X status = XGetWindowAttributes(dpy, from, &fromInfo);
X if (status == FAILURE)
X Leave(FALSE)
X status = XGetWindowAttributes(dpy, to, &toInfo);
X if (status == FAILURE)
X Leave(FALSE)
X
X /*
X * Store the zap vector buffer.
X */
X if (dozap) {
X num_vectors =
X StoreZap(zap,
X fromInfo.x - 1,
X fromInfo.y - 1,
X fromInfo.x + fromInfo.width +
X (fromInfo.border_width << 1),
X fromInfo.y + fromInfo.height +
X (fromInfo.border_width << 1),
X toInfo.x - 1,
X toInfo.y - 1,
X toInfo.x + toInfo.width +
X (toInfo.border_width << 1),
X toInfo.y + toInfo.height +
X (toInfo.border_width << 1));
X }
X if (awi->state == ICON) {
X if (!awi->frame)
X XRemoveFromSaveSet(dpy, awi->client);
X awi->state = WINDOW;
X }
X else if (awi->state == WINDOW) {
X XAddToSaveSet(dpy, awi->client);
X awi->state = ICON;
X }
X else
X fprintf(stderr, "Window state for window %x got munged!\n",
X awi->client);
X /*
X * Map the target.
X */
X XMapRaised(dpy, to);
X if (dozap) {
X /*
X * Draw the zap lines.
X */
X DrawZap();
X }
X /*
X * Unmap the "from" window.
X */
X XUnmapWindow(dpy, from);
X XFlush(dpy);
X /*
X * Optionally warp the mouse to the upper right corner of the
X * window.
X */
X if (WarpOnDeIconify && awi->state == WINDOW) {
X int y;
X
X y = (toInfo.height >= 10) ? 10 : toInfo.height / 2;
X if (awi->frame) { /* compensate for title */
X XWindowAttributes xwa;
X XGetWindowAttributes(dpy, awi->title, &xwa);
X y += xwa.height + 2;
X }
X status = XWarpPointer (dpy, None, to,
X 0, 0, 0, 0,
X toInfo.width >= 7 ?
X toInfo.width - 7 : toInfo.width / 2,
X y);
X }
X
X if (WarpOnIconify && awi->state == ICON)
X status = XWarpPointer (dpy, None, to,
X 0, 0, 0, 0,
X toInfo.width / 2, toInfo.height / 2);
X Leave(TRUE)
X}
END_OF_FILE
if test 6147 -ne `wc -c <'Iconify.c'`; then
echo shar: \"'Iconify.c'\" unpacked with wrong size!
fi
# end of 'Iconify.c'
fi
if test -f 'Icons.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'Icons.c'\"
else
echo shar: Extracting \"'Icons.c'\" \(9559 characters\)
sed "s/^X//" >'Icons.c' <<'END_OF_FILE'
X/* $Header: Icons.c,v 1.4 87/09/09 12:00:29 swick Exp $ */
X#include "X11/copyright.h"
X
X/*
X * Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
X *
X * All Rights Reserved
X *
X * Permission to use, copy, modify, and distribute this software and its
X * documentation for any purpose and without fee is hereby granted,
X * provided that the above copyright notice appear in all copies and that
X * both that copyright notice and this permission notice appear in
X * supporting documentation, and that the name of Digital Equipment
X * Corporation not be used in advertising or publicity pertaining to
X * distribution of the software without specific, written prior permission.
X *
X *
X * DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
X * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
X * DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
X * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
X * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
X * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
X * SOFTWARE.
X */
X
X
X
X/*
X * MODIFICATION HISTORY
X *
X * 000 -- L. Guarino Reid, DEC Ultrix Engineering Group
X */
X
X#ifndef lint
static char *sccsid = "%W% %G%";
X#endif
X
X#include "awm.h"
X#include "X11/Xutil.h"
X
extern XContext AwmContext;
X
X/* the client should pass us a bitmap (single-plane pixmap with background=0
X * and foreground = 1). It is our responsibility to convert it to a pixmap
X * of the appropriate depth for a window tile and also color it with the
X * appropriate background and foreground pixels.
X *
X * we'll use the (global) IconGC for the fore/background pixels.
X */
X
static Pixmap MakePixmapFromBitmap( bitmap, clipmask, width_return, height_return )
Pixmap bitmap, clipmask;
unsigned int *width_return, *height_return;
X{
X Pixmap tile;
X Window junkW;
X int junk, width, height;
X GC iGC;
X XGCValues gcv;
X
X Entry("MakePixmapFromBitmap")
X
X if (!XGetGeometry( dpy, bitmap, &junkW, &junk, &junk,
X &width, &height, &junk, &junk )) {
X Warning( "client passed invalid pixmap for icon." );
X Leave( NULL )
X }
X tile = XCreatePixmap( dpy, RootWindow(dpy, scr), width, height,
X DefaultDepth(dpy, scr) );
X if (clipmask)
X XSetClipMask(dpy, IconGC, clipmask);
X gcv.foreground = ITextForeground;
X gcv.background = ITextBackground;
X iGC = XCreateGC(dpy, RootWindow(dpy, scr), (GCForeground | GCBackground),
X &gcv);
X XCopyPlane( dpy, bitmap, tile, iGC, 0, 0, width, height, 0, 0, 1 );
X XFreeGC(dpy, iGC);
X if (width_return)
X *width_return = width;
X if (height_return)
X *height_return = height;
X Leave(tile)
X}
X
char *GetIconName(window)
Window window;
X{
X char *name;
X Status status;
X long len, after;
X Atom a_type;
X int a_form;
X
X Entry("GetIconName")
X
X status = XGetWindowProperty(dpy, window, XA_WM_ICON_NAME, 0, 256,
X False, XA_STRING, &a_type, &a_form, &len, &after,
X &name);
X
X if (status != Success) {
X status = XGetWindowProperty(dpy, window, XA_WM_NAME, 0, NAME_LEN,
X False, XA_STRING, &a_type, &a_form, &len,
X &after, &name);
X if (status != Success)
X Leave((char *)NULL)
X }
X if (a_form == 0) /* we have no bananas */
X Leave((char *)NULL)
X if (a_form != 8) {
X Warning("Window has icon_name in wrong format");
X if (name)
X free(name);
X Leave((char *)NULL)
X }
X if (len > NAME_LEN) {
X Warning("Window has icon_name greater than maximum length");
X len = NAME_LEN;
X }
X if (!len)
X Leave((char *)NULL)
X name[len] = 0;
X Leave(name)
X}
X
Boolean IsIcon(icon, win)
Window icon;
Window *win;
X{
X AwmInfoPtr awi;
X
X Entry("IsIcon")
X
X if (win)
X *win = 0;
X awi = GetAwmInfo(icon);
X if (!awi)
X Leave(FALSE)
X if (awi->icon == icon) {
X if (win)
X *win = awi->client;
X Leave(TRUE)
X }
X else if (awi->client == icon || awi->frame == icon) {
X if (win)
X *win = awi->icon;
X Leave(FALSE)
X }
X Leave(FALSE)
X}
X
RemoveIcon(window)
Window window;
X{
X AwmInfoPtr awi;
X
X Entry("RemoveIcon")
X
X if ((awi = GetAwmInfo(window)) != NULL) {
X XDeleteContext(dpy, awi->icon, AwmContext);
X if (awi->own) {
X XDestroyWindow(dpy, awi->icon);
X if (awi->iconPixmap != IBackPixmap)
X XFreePixmap(dpy, awi->iconPixmap);
X }
X awi->icon = 0;
X awi->state = WINDOW;
X }
X Leave_void
X}
X
GetDefaultSize(window, icon_w, icon_h)
Window window;
int *icon_w, *icon_h;
X{
X char *name; /* Event window name. */
X
X Entry("GetDefaultSize")
X
X /*
X * Determine the size of the icon window.
X */
X name = GetIconName(window);
X *icon_h = IFontInfo->ascent + IFontInfo->descent;
X if (name) {
X *icon_w = XTextWidth(IFontInfo, name, strlen(name));
X if (*icon_w == 0)
X *icon_w = *icon_h;
X }
X else
X *icon_w = *icon_h;
X Leave_void
X}
X
Window MakeIcon(window, x, y, mousePositioned)
Window window; /* associated window. */
int x, y; /* Event mouse position. */
Boolean mousePositioned;
X{
X Window icon; /* icon window. */
X int icon_x, icon_y; /* Icon U. L. X and Y coordinates. */
X int icon_w, icon_h; /* Icon width and height. */
X int icon_bdr; /* Icon border width. */
X int mask; /* Icon event mask */
X int depth; /* for XGetGeometry */
X XSetWindowAttributes iconValues; /* for icon window creation */
X unsigned long iconValues_mask; /* for above */
X XWMHints *wmhints; /* see if icon position provided */
X XWMHints *XGetWMHints();
X Pixmap clip = 0;
X Window AddIcon();
X
X Entry("MakeIcon")
X
X iconValues.background_pixmap = IBackPixmap;
X mask = (ExposureMask | StructureNotifyMask | KeyPressMask);
X /*
X * Process window manager hints.
X */
X if (wmhints = XGetWMHints(dpy, window)) {
X if (wmhints->flags & IconWindowHint)
X Leave(AddIcon(window, wmhints->icon_window, FALSE,
X (StructureNotifyMask), (Pixmap)NULL))
X else if (wmhints->flags & IconPixmapHint) {
X if (wmhints->flags & IconMaskHint)
X clip = wmhints->icon_mask;
X iconValues.background_pixmap =
X MakePixmapFromBitmap(wmhints->icon_pixmap, clip,
X &icon_w, &icon_h );
X if (iconValues.background_pixmap)
X mask = (StructureNotifyMask);
X else {
X iconValues.background_pixmap = IBackPixmap;
X wmhints->flags &= ~IconPixmapHint;
X GetDefaultSize(window, &icon_w, &icon_h);
X }
X }
X else GetDefaultSize(window, &icon_w, &icon_h);
X }
X else GetDefaultSize(window, &icon_w, &icon_h);
X
X /*
X * Fix up sizes by padding.
X */
X if (!wmhints || !(wmhints->flags & (IconPixmapHint|IconWindowHint))) {
X icon_w += (HIconPad << 1);
X icon_h += (VIconPad << 1);
X }
X
X /*
X * Set the icon border attributes.
X */
X if (!wmhints || !(wmhints->flags & IconWindowHint)) {
X icon_bdr = IBorderWidth;
X iconValues.border_pixel = IBorder;
X }
X
X if (wmhints && (wmhints->flags & IconPositionHint)) {
X icon_x = wmhints->icon_x;
X icon_y = wmhints->icon_y;
X } else {
X if (mousePositioned) {
X /*
X * Determine the coordinates of the icon window;
X * normalize so that we don't lose the icon off the
X * edge of the screen.
X */
X icon_x = x - (icon_w >> 1) + 1;
X if (icon_x < 0) icon_x = 0;
X icon_y = y - (icon_h >> 1) + 1;
X if (icon_y < 0) icon_y = 0;
X if ((icon_x - 1 + icon_w + (icon_bdr << 1)) > ScreenWidth) {
X icon_x = ScreenWidth - icon_w - (icon_bdr << 1) + 1;
X }
X if ((icon_y - 1 + icon_h + (icon_bdr << 1)) > ScreenHeight) {
X icon_y = ScreenHeight - icon_h - (icon_bdr << 1) + 1;
X }
X }
X else {
X icon_x = x + (icon_w >> 1);
X icon_y = y + (icon_y >> 1);
X }
X
X }
X
X /*
X * Create the icon window.
X */
X iconValues_mask = CWBorderPixel | CWBackPixmap;
X /*
X * Here we assume that if they want save unders, they'll also want
X * backing store on the icons. Perhaps a dangerous assumption, but
X * one we have to make at this point.
X */
X if (SaveUnder) {
X iconValues.backing_store = WhenMapped;
X iconValues_mask |= CWBackingStore;
X }
X Leave(AddIcon(window,
X XCreateWindow(
X dpy, RootWindow(dpy, scr),
X icon_x, icon_y,
X icon_w, icon_h,
X icon_bdr, 0, CopyFromParent, CopyFromParent,
X iconValues_mask, &iconValues),
X TRUE, mask, iconValues.background_pixmap))
X
X}
X
Window AddIcon(window, icon, own, mask, background)
Window window, icon;
Boolean own;
int mask;
Pixmap background;
X{
X Binding *bptr;
X AwmInfoPtr awi;
X
X Entry("AddIcon")
X
X if (icon == NULL)
X Leave(NULL)
X /*
X * Use the text cursor whenever the mouse is in the icon window.
X */
X XDefineCursor(dpy, icon, TextCursor);
X
X /*
X * Select "key pressed", "window exposure" and "unmap window"
X * events for the icon window.
X */
X XSelectInput(dpy, icon, mask);
X /*
X * Handle any registered grabs for the icon window.
X */
X for (bptr = Blist; bptr; bptr = bptr->next)
X if (bptr->context & ICON)
X Grab(bptr->mask, icon);
X awi = GetAwmInfo(window);
X awi->icon = icon;
X awi->own = own;
X awi->iconPixmap = background;
X XSaveContext(dpy, icon, AwmContext, awi);
X Leave(icon)
X}
END_OF_FILE
if test 9559 -ne `wc -c <'Icons.c'`; then
echo shar: \"'Icons.c'\" unpacked with wrong size!
fi
# end of 'Icons.c'
fi
if test -f 'Move.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'Move.c'\"
else
echo shar: Extracting \"'Move.c'\" \(7893 characters\)
sed "s/^X//" >'Move.c' <<'END_OF_FILE'
X#ifndef lint
X static char *rcsid_Move_c = "$Header: Move.c,v 1.8 87/08/25 11:24:56 swick Exp $";
X#endif lint
X
X#include "X11/copyright.h"
X
X/*
X * Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
X *
X * All Rights Reserved
X *
X * Permission to use, copy, modify, and distribute this software and its
X * documentation for any purpose and without fee is hereby granted,
X * provided that the above copyright notice appear in all copies and that
X * both that copyright notice and this permission notice appear in
X * supporting documentation, and that the name of Digital Equipment
X * Corporation not be used in advertising or publicity pertaining to
X * distribution of the software without specific, written prior permission.
X *
X *
X * DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
X * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
X * DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
X * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
X * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
X * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
X * SOFTWARE.
X */
X
X/*
X * MODIFICATION HISTORY
X *
X * 000 -- M. Gancarz, DEC Ultrix Engineering Group
X * 001 -- Loretta Guarino Reid, DEC Ultrix Engineering Group,
X * Western Software Lab. Port to X11
X */
X
X#ifndef lint
static char *sccsid = "@(#)Move.c 3.8 1/24/86";
X#endif
X
X#include "awm.h"
X
Boolean Move(window, mask, button, x, y)
Window window; /* Event window. */
int mask; /* Button/key mask. */
int button; /* Button event detail. */
int x, y; /* Event mouse position. */
X{
X register int prev_x; /* Previous event window X location. */
X register int prev_y; /* Previous event window Y location. */
X XWindowAttributes window_info; /* Event window information. */
X int cur_x; /* Current event window X location. */
X int cur_y; /* Current event window Y location. */
X int root_x; /* Root window X location. */
X int root_y; /* Root window Y location. */
X int ulx, uly; /* Event window upper left X and Y. */
X int lrx, lry; /* Event window lower right X and Y. */
X int init_ulx, init_uly; /* Init window upper left X and Y. */
X int init_lrx, init_lry; /* Init window lower right X and Y. */
X int num_vectors; /* Number of vectors in box. */
X int ptrmask; /* state of ptr when queried */
X Window sub_window; /* Query mouse event sub-window. */
X Window root; /* Query mouse event root. */
X AwmInfoPtr awi;
X XEvent button_event; /* Button event packet. */
X XSegment box[MAX_BOX_VECTORS]; /* Box vertex buffer. */
X XSegment zap[MAX_ZAP_VECTORS]; /* Zap effect verted buffer. */
X int (*storegrid_func)(); /* Function to use for grid */
X int (*storebox_func)(); /* Function to use for box */
X
X Entry("Move")
X
X /*
X * Do not try to move the root window.
X */
X if (window == RootWindow(dpy, scr))
X Leave(FALSE)
X
X /*
X * Change the cursor.
X */
X grab_pointer();
X /*
X * Clear the vector buffers.
X */
X bzero(box, sizeof(box));
X if (Zap)
X bzero(zap, sizeof(zap));
X
X /*
X * Gather info on the event window.
X */
X awi = GetAwmInfo(window);
X if (!awi)
X Leave(FALSE)
X status = XGetWindowAttributes(dpy, window, &window_info);
X if (status == FAILURE)
X Leave(FALSE)
X
X if (awi->title && !IsIcon(window, NULL)) {
X storegrid_func = StoreTitleGridBox;
X storebox_func = StoreTitleBox;
X }
X else {
X storegrid_func = StoreGridBox;
X storebox_func = StoreBox;
X }
X /*
X * Initialize movement variables.
X */
X init_ulx = ulx = window_info.x;
X init_uly = uly = window_info.y;
X init_lrx = lrx = window_info.x + window_info.width +
X (window_info.border_width << 1) - 1;
X init_lry = lry = window_info.y + window_info.height +
X (window_info.border_width << 1) - 1;
X
X /*
X * Store the box.
X */
X if (Grid)
X num_vectors = (*storegrid_func)(box, ulx, uly, lrx, lry);
X else
X num_vectors = (*storebox_func)(box, ulx, uly, lrx, lry);
X
X /*
X * Initialize the previous location variables.
X */
X prev_x = x;
X prev_y = y;
X
X /*
X * Freeze the server, if requested by the user.
X * This results in a solid box instead of a flickering one.
X */
X if (Freeze)
X XGrabServer(dpy);
X Snatched = True;
X /*
X * Process any pending exposure events before drawing the box.
X */
X while (QLength(dpy) > 0) {
X XPeekEvent(dpy, &button_event);
X if (((XAnyEvent *)&button_event)->window == RootWindow(dpy, scr))
X break;
X GetButton(&button_event);
X }
X
X /*
X * Now draw the box.
X */
X
X DrawBox();
X Frozen = window;
X
X /*
X * Main loop.
X */
X while (TRUE) {
X
X /*
X * Check to see if we have a change in mouse button status.
X * This is how we get out of this "while" loop.
X */
X if (XPending(dpy) && !ProcessRequests(box, num_vectors) &&
X GetButton(&button_event)) {
X /*
X * Process the pending events, this sequence is the only
X * way out of the loop and the routine.
X */
X
X if ((button_event.type != ButtonPress) &&
X (button_event.type != ButtonRelease)) {
X continue; /* spurious menu event... */
X }
X
X /*
X * If we froze the server, then erase the last lines drawn.
X */
X if (Freeze) {
X DrawBox();
X Frozen = (Window)0;
X XUngrabServer(dpy);
X }
X
X if ((button_event.type == ButtonRelease) &&
X (((XButtonReleasedEvent *)&button_event)->button == button)) {
X
X /*
X * The button was released, so move the window.
X */
X
X if (Zap) {
X num_vectors = StoreZap(zap,
X init_ulx, init_uly,
X init_lrx, init_lry,
X ulx, uly,
X lrx, lry);
X DrawZap();
X DrawZap();
X }
X#ifdef titan /* 5x4 alignment */
X ulx += (ulx % 5);
X uly += (uly % 4);
X#endif /* titan */
X if (Wall) {
X if (ulx < 0)
X ulx = 0;
X if (ulx > (ScreenWidth - window_info.width))
X ulx = (ScreenWidth - window_info.width);
X if (uly < 0)
X uly = 0;
X if (uly > (ScreenHeight - window_info.height))
X uly = (ScreenHeight - window_info.height);
X }
X XMoveWindow(dpy, window, ulx, uly);
X Snatched = False;
X ungrab_pointer();
X Leave(TRUE)
X }
X else {
X /*
X * Some other button event occured, this aborts the
X * current operation.
X */
X
X ResetCursor(button);
X Snatched = False;
X ungrab_pointer();
X Leave(TRUE)
X }
X }
X
X /*
X * Take care of all the little things that have changed.
X */
X XQueryPointer(dpy,
X RootWindow(dpy, scr), &root, &sub_window,
X &root_x, &root_y, &cur_x, &cur_y, &ptrmask);
X if ((cur_x != prev_x) || (cur_y != prev_y)) {
X
X /*
X * If we've frozen the server, then erase the old box first!
X */
X if (Freeze)
X DrawBox();
X
X /*
X * Box position has changed.
X */
X ulx += cur_x - prev_x;
X uly += cur_y - prev_y;
X lrx += cur_x - prev_x;
X lry += cur_y - prev_y;
X
X /*
X * Box needs to be restored.
X */
X if (Grid)
X num_vectors = (*storegrid_func)(box, ulx, uly, lrx, lry);
X else
X num_vectors = (*storebox_func)(box, ulx, uly, lrx, lry);
X
X
X /*
X * Draw the new box.
X */
X if (Freeze)
X DrawBox();
X }
X
X /*
X * Save old box position.
X */
X prev_x = cur_x;
X prev_y = cur_y;
X
X /*
X * If server is not frozen, then draw the "flicker" box.
X */
X if (!Freeze) {
X DrawBox();
X DrawBox();
X }
X }
X}
END_OF_FILE
if test 7893 -ne `wc -c <'Move.c'`; then
echo shar: \"'Move.c'\" unpacked with wrong size!
fi
# end of 'Move.c'
fi
if test -f 'NewIconify.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'NewIconify.c'\"
else
echo shar: Extracting \"'NewIconify.c'\" \(10332 characters\)
sed "s/^X//" >'NewIconify.c' <<'END_OF_FILE'
X#include "X11/copyright.h"
X
X/*
X * Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
X *
X * All Rights Reserved
X *
X * Permission to use, copy, modify, and distribute this software and its
X * documentation for any purpose and without fee is hereby granted,
X * provided that the above copyright notice appear in all copies and that
X * both that copyright notice and this permission notice appear in
X * supporting documentation, and that the name of Digital Equipment
X * Corporation not be used in advertising or publicity pertaining to
X * distribution of the software without specific, written prior permission.
X *
X *
X * DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
X * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
X * DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
X * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
X * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
X * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
X * SOFTWARE.
X */
X
X/*
X * MODIFICATION HISTORY
X *
X * 000 -- M. Gancarz, DEC Ultrix Engineering Group
X * 001 -- Loretta Guarino Reid, DEC Ultrix Engineering Group,
X * Western Software Lab. Port to X11.
X */
X
X#ifndef lint
static char *sccsid = "%W% %G%";
X#endif
X
X#include "awm.h"
X
Boolean NewIconify(window, mask, button, x, y)
Window window; /* Event window. */
int mask; /* Button/key mask. */
int button; /* Button event detail. */
int x, y; /* Event mouse position. */
X{
X XWindowAttributes fromInfo; /* from window info. */
X XWindowAttributes toInfo; /* to window info. */
X Window from, to;
X char *name; /* Event window name. */
X int mse_x, mse_y; /* Mouse X and Y coordinates. */
X int new_x, new_y; /* To U. L. X and Y coordinates. */
X int new_w, new_h; /* To width and height. */
X int bdw; /* border width */
X int prev_x; /* Previous event window X location. */
X int prev_y; /* Previous event window Y location. */
X int cur_x; /* Current event window X location. */
X int cur_y; /* Current event window Y location. */
X int root_x; /* Root window X location. */
X int root_y; /* Root window Y location. */
X int ulx, uly; /* Event window upper left X and Y. */
X int lrx, lry; /* Event window lower right X and Y. */
X int init_ulx, init_uly; /* Init window upper left X and Y. */
X int init_lrx, init_lry; /* Init window lower right X and Y. */
X int num_vectors; /* Number of vectors in box. */
X int status; /* Routine call return status. */
X int ptrmask; /* pointer query state. */
X Window root; /* Mouse root window. */
X Window icon; /* Icon window. */
X Window sub_win; /* Mouse position sub-window. */
X XEvent button_event; /* Button event packet. */
X XSegment box[MAX_BOX_VECTORS]; /* Box vertex buffer. */
X XSegment zap[MAX_ZAP_VECTORS]; /* Zap effect vertex buffer. */
X int (*storegrid_func)(); /* Function to use for grid */
X int (*storebox_func)(); /* Function to use for box */
X Boolean iconifying; /* Are we iconifying? */
X AwmInfoPtr awi;
X
X Entry("NewIconify")
X
X /*
X * Do not lower or iconify the root window.
X */
X if (window == RootWindow(dpy, scr))
X Leave(FALSE)
X
X /*
X * Change the cursor to the icon cursor.
X */
X grab_pointer();
X
X /*
X * Clear the vector buffers.
X */
X bzero(box, sizeof(box));
X if (Zap)
X bzero(zap, sizeof(zap));
X
X /*
X * Get info on the event window.
X */
X awi = GetAwmInfo(window);
X if (!awi)
X Leave(FALSE)
X /*
X * Are we iconifying or de-iconifying?
X */
X if (awi->state == ICON) {
X from = awi->icon;
X to = (awi->frame) ? awi->frame : awi->client;
X }
X else if (awi->state == WINDOW) {
X from = (awi->frame) ? awi->frame : awi->client;
X to = (awi->icon) ? awi->icon : MakeIcon(window, x, y, FALSE);
X }
X else {
X fprintf(stderr, "NewIconify: Window %x has unknown state '%x'\n",
X awi->client, awi->state);
X Leave(FALSE)
X }
X status = XGetWindowAttributes(dpy, from, &fromInfo);
X if (status == FAILURE)
X Leave(FALSE)
X
X status = XGetWindowAttributes(dpy, to, &toInfo);
X if (status == FAILURE)
X Leave(FALSE)
X
X /*
X * Initialize the movement variables.
X */
X init_ulx = ulx = x - (toInfo.width >> 1) - toInfo.border_width;
X init_uly = uly = y - (toInfo.height >> 1) - toInfo.border_width;
X init_lrx = lrx = x + (toInfo.width >> 1) + toInfo.border_width - 1;
X init_lry = lry = y + (toInfo.height >> 1) + toInfo.border_width - 1;
X prev_x = x;
X prev_y = y;
X
X if (awi->frame && awi->state == ICON) {
X storegrid_func = StoreTitleGridBox;
X storebox_func = StoreTitleBox;
X }
X else {
X storegrid_func = StoreGridBox;
X storebox_func = StoreBox;
X }
X
X /*
X * Store the box.
X */
X if (Grid)
X num_vectors = storegrid_func(box, ulx, uly, lrx, lry);
X else
X num_vectors = storebox_func(box, ulx, uly, lrx, lry);
X
X /*
X * Freeze the server, if requested by the user.
X * This results in a solid box instead of a flickering one.
X */
X if (Freeze)
X XGrabServer(dpy);
X
X /*
X * Process any outstanding events before drawing the box.
X */
X while (QLength(dpy) > 0) {
X XPeekEvent(dpy, &button_event);
X if (((XAnyEvent *)&button_event)->window == RootWindow(dpy, scr))
X break;
X GetButton(&button_event);
X }
X
X /*
X * Draw the box.
X */
X DrawBox();
X if (Freeze)
X Frozen = window;
X
X /*
X * We spin our wheels here looking for mouse movement or a change
X * in the status of the buttons.
X */
X Snatched = TRUE;
X while (TRUE) {
X
X /*
X * Check to see if we have a change in mouse button status.
X * This is how we get out of this "while" loop.
X */
X if (XPending(dpy) && !ProcessRequests(box, num_vectors) &&
X GetButton(&button_event)) {
X /*
X * Process the pending events, this sequence is the only
X * way out of the loop and the routine.
X */
X
X if ((button_event.type != ButtonPress) &&
X (button_event.type != ButtonRelease)) {
X continue; /* spurious menu event... */
X }
X
X /*
X * If we froze the server, then erase the last lines drawn.
X */
X if (Freeze) {
X DrawBox();
X Frozen = (Window)0;
X XUngrabServer(dpy);
X }
X
X /*
X * Save the mouse cursor location.
X */
X if (button_event.type == ButtonPress ||
X button_event.type == ButtonRelease) {
X mse_x = ((XButtonEvent *)&button_event)->x;
X mse_y = ((XButtonEvent *)&button_event)->y;
X break;
X }
X }
X else {
X /*
X * Continue to track the mouse until we get a change
X * in button status.
X */
X XQueryPointer(dpy, RootWindow(dpy, scr),
X &root, &sub_win, &root_x, &root_y, &cur_x,
X &cur_y, &ptrmask);
X
X /*
X * If the mouse has moved, then make sure the box follows it.
X */
X if ((cur_x != prev_x) || (cur_y != prev_y)) {
X
X /*
X * If we've frozen the server, then erase the old box first!
X */
X if (Freeze)
X DrawBox();
X
X /*
X * Set the new box position.
X */
X ulx += cur_x - prev_x;
X uly += cur_y - prev_y;
X lrx += cur_x - prev_x;
X lry += cur_y - prev_y;
X
X /*
X * Calculate the vectors for the new box.
X */
X
X if (Grid)
X num_vectors = storegrid_func(box, ulx, uly, lrx,
X lry);
X else
X num_vectors = storebox_func(box, ulx, uly, lrx, lry);
X
X /*
X * Draw the new box.
X */
X if (Freeze)
X DrawBox();
X }
X
X /*
X * Save the old box position.
X */
X prev_x = cur_x;
X prev_y = cur_y;
X
X /*
X * If server is not frozen, then draw the "flicker" box.
X */
X if (!Freeze) {
X DrawBox();
X DrawBox();
X }
X }
X }
X Snatched = FALSE;
X /*
X * If the button is not a button release of the same button pressed,
X * then abort the operation.
X */
X if ((button_event.type != ButtonRelease) ||
X (((XButtonReleasedEvent *)&button_event)->button != button)) {
X ResetCursor(button);
X ungrab_pointer();
X Leave(TRUE)
X }
X
X /*
X * If we are here we have committed to iconifying/deiconifying.
X */
X
X /*
X * Determine the coordinates of the icon or window;
X * normalize the window or icon coordinates if the user so desires.
X */
X new_w = toInfo.width;
X new_h = toInfo.height;
X bdw = toInfo.border_width;
X new_x = mse_x - (new_w >> 1) - bdw;
X new_y = mse_y - (new_h >> 1) - bdw;
X if ((NIcon && awi->state == WINDOW) || (NWindow && awi->state == ICON)) {
X if (new_x < 0) new_x = 0;
X if (new_y < 0) new_y = 0;
X if ((new_x - 1 + new_w + (bdw << 1)) > ScreenWidth) {
X new_x = ScreenWidth - new_w - (bdw << 1) + 1;
X }
X if ((new_y - 1 + new_h + (bdw << 1)) > ScreenHeight) {
X new_y = ScreenHeight - new_h - (bdw << 1) + 1;
X }
X }
X if (awi->state == ICON) {
X awi->state = WINDOW;
X awi->placed = TRUE;
X if (!awi->title)
X XRemoveFromSaveSet(dpy, awi->client);
X }
X else if (awi->state == WINDOW) {
X awi->state = ICON;
X XAddToSaveSet(dpy, awi->client);
X }
X else
X fprintf(stderr, "NewIconify: Window state got trashed!\n");
X
X /*
X * Move the window into place.
X */
X XMoveWindow(dpy, to, new_x, new_y);
X
X /*
X * Map the icon window.
X */
X XMapRaised(dpy, to);
X if (Zap) {
X num_vectors = StoreZap(zap,
X fromInfo.x,
X fromInfo.y,
X fromInfo.x + fromInfo.width
X + (fromInfo.border_width << 1),
X fromInfo.y + fromInfo.height
X + (fromInfo.border_width << 1),
X ulx, uly, lrx, lry);
X DrawZap();
X DrawZap();
X }
X /*
X * Unmap the event window.
X */
X XUnmapWindow(dpy, from);
X XFlush(dpy);
X ungrab_pointer();
X Leave(TRUE)
X}
END_OF_FILE
if test 10332 -ne `wc -c <'NewIconify.c'`; then
echo shar: \"'NewIconify.c'\" unpacked with wrong size!
fi
# end of 'NewIconify.c'
fi
echo shar: End of archive 3 \(of 8\).
cp /dev/null ark3isdone
MISSING=""
for I in 1 2 3 4 5 6 7 8 ; do
if test ! -f ark${I}isdone ; then
MISSING="${MISSING} ${I}"
fi
done
if test "${MISSING}" = "" ; then
echo You have unpacked all 8 archives.
rm -f ark[1-9]isdone
else
echo You still need to unpack the following archives:
echo " " ${MISSING}
fi
## End of shell archive.
exit 0