[comp.windows.x] twm 3.0, part 2 of 5

tlastran@esunix.UUCP (Tom LaStrange) (06/04/88)

#! /bin/sh
# This is a shell archive, meaning:
# 1.  Remove everything above the #! /bin/sh line.
# 2.  Save the resulting test in a file
# 3.  Execute the file with /bin/sh (not csh) to create the files:
#
#gram.y
#mytitle.c
#add_window.c
#gc.c
#twm.c
#
# Created by tlastran (Tom LaStrange) on Fri Jun  3 11:32:30 MDT 1988
#
if test -f 'gram.y'
then
    echo shar: will not over-write existing file "gram.y"
else
echo extracting "gram.y"
sed 's/^X//' >gram.y <<'SHAR_EOF'
X/*****************************************************************************/
X/**       Copyright 1988 by Evans & Sutherland Computer Corporation,        **/
X/**                          Salt Lake City, Utah                           **/
X/**                                                                         **/
X/**                           All Rights Reserved                           **/
X/**                                                                         **/
X/**    Permission to use, copy, modify, and distribute this software and    **/
X/**    its documentation  for  any  purpose  and  without  fee is hereby    **/
X/**    granted, provided that the above copyright notice appear  in  all    **/
X/**    copies and that both  that  copyright  notice  and  this  permis-    **/
X/**    sion  notice appear in supporting  documentation,  and  that  the    **/
X/**    name  of Evans & Sutherland  not be used in advertising or publi-    **/
X/**    city pertaining to distribution  of the software without  specif-    **/
X/**    ic, written prior permission.                                        **/
X/**                                                                         **/
X/**    EVANS  & SUTHERLAND  DISCLAIMS  ALL  WARRANTIES  WITH  REGARD  TO    **/
X/**    THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILI-    **/
X/**    TY AND FITNESS, IN NO EVENT SHALL EVANS &  SUTHERLAND  BE  LIABLE    **/
X/**    FOR  ANY  SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY  DAM-    **/
X/**    AGES  WHATSOEVER RESULTING FROM  LOSS OF USE,  DATA  OR  PROFITS,    **/
X/**    WHETHER   IN  AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS    **/
X/**    ACTION, ARISING OUT OF OR IN  CONNECTION  WITH  THE  USE  OR PER-    **/
X/**    FORMANCE OF THIS SOFTWARE.                                           **/
X/*****************************************************************************/
X
X/***********************************************************************
X *
X * $Header: gram.y,v 1.26 88/06/03 10:45:44 tlastran Exp $
X *
X * .twmrc command grammer
X *
X * 07-Jan-86 Thomas E. LaStrange	File created
X *
X ***********************************************************************/
X
X%{
Xstatic char RCSinfo[]=
X"$Header: gram.y,v 1.26 88/06/03 10:45:44 tlastran Exp $";
X
X#include <stdio.h>
X#include "twm.h"
X#include "menus.h"
X#include "list.h"
X#include "util.h"
X
Xstatic char *Action = "";
Xstatic MenuRoot	*root,
X		*pull = NULL;
X
XMenuRoot *GetRoot();
X
Xstatic char *ptr;
Xstatic int Button;
Xstatic int list;
Xstatic int mods = 0, cont = 0;
Xstatic int color;
X
Xextern int yylineno;
X%}
X
X%union
X{
X    int num;
X    char *ptr;
X};
X
X%token <num> LB RB MENUS MENU BUTTON TBUTTON
X%token <num> F_MENU F_UNFOCUS F_REFRESH F_FILE F_TWMRC F_CIRCLEUP F_QUIT
X%token <num> F_NOP F_TITLE F_VERSION F_EXEC F_CUT F_CIRCLEDOWN F_SOURCE
X%token <num> F_CUTFILE F_MOVE F_ICONIFY F_FOCUS F_RESIZE F_RAISE F_LOWER
X%token <num> F_DESTROY F_WINREFRESH DONT_MOVE_OFF ZOOM
X%token <num> WARPCURSOR NUMBER BORDERWIDTH TITLE_FONT REVERSE_VIDEO
X%token <num> RESIZE_FONT NO_TITLE AUTO_RAISE FORCE_ICON
X%token <num> MENU_FONT ICON_FONT UNKNOWN_ICON ICONS ICON_DIRECTORY
X%token <num> META SHIFT CONTROL WINDOW TITLE ICON ROOT
X%token <num> COLON EQUALS BORDER_COLOR TITLE_FOREGROUND TITLE_BACKGROUND
X%token <num> MENU_FOREGROUND MENU_BACKGROUND MENU_SHADOW_COLOR
X%token <num> MENU_TITLE_FOREGROUND MENU_TITLE_BACKGROUND
X%token <num> ICON_FOREGROUND ICON_BACKGROUND ICON_BORDER_COLOR
X%token <num> NO_RAISE_ON_MOVE NO_RAISE_ON_DEICONIFY NO_RAISE_ON_RESIZE
X%token <num> COLOR MONOCHROME
X%token <ptr> STRING
X
X%type <ptr> string
X%type <num> action button number tbutton full
X
X%start twmrc 
X
X%%
Xtwmrc		: stmts
X		;
X
Xstmts		: /* Empty */
X		| stmts stmt
X		;
X
Xstmt		: error
X		| FORCE_ICON		{ if (FirstTime) ForceIcon = TRUE; }
X		| REVERSE_VIDEO		{ if (FirstTime) ReverseVideo = TRUE; }
X		| ICON_FONT string	{ if (FirstTime) IconFontName = $2; }
X		| RESIZE_FONT string	{ if (FirstTime) SizeFontName = $2; }
X		| MENU_FONT string	{ if (FirstTime) MenuFontName = $2; }
X		| TITLE_FONT string	{ if (FirstTime) TitleBarFontName=$2; }
X		| UNKNOWN_ICON string	{ if (FirstTime) GetUnknownIcon($2); }
X		| ICON_DIRECTORY string	{ if (FirstTime)
X					    IconDirectory = ExpandFilename($2);
X					}
X		| WARPCURSOR		{ if (FirstTime) WarpCursor = TRUE; }
X		| NO_RAISE_ON_MOVE	{ if (FirstTime) NoRaiseMove = TRUE; }
X		| NO_RAISE_ON_RESIZE	{ if (FirstTime) NoRaiseResize = TRUE; }
X		| NO_RAISE_ON_DEICONIFY	{ if (FirstTime) NoRaiseDeicon = TRUE; }
X		| DONT_MOVE_OFF		{ if (FirstTime) DontMoveOff = TRUE; }
X		| ZOOM			{ if (FirstTime) DoZoom = TRUE; }
X		| BORDERWIDTH number	{ if (FirstTime) BorderWidth = $2; }
X		| button string		{ root = GetRoot($2);
X					  Mouse[$1][C_ROOT][0].func = F_MENU;
X					  Mouse[$1][C_ROOT][0].menu = root;
X					}
X		| button action		{ Mouse[$1][C_ROOT][0].func = $2;
X					  if ($2 == F_MENU)
X					  {
X					    pull->prev = NULL;
X					    Mouse[$1][C_ROOT][0].menu = pull;
X					  }
X					  else
X					  {
X					    root = GetRoot(TWM_ROOT);
X					    Mouse[$1][C_ROOT][0].item = 
X					    AddToMenu(root,"x",Action,0,$2);
X					  }
X					  Action = "";
X					  pull = NULL;
X					}
X		| button full		{ Mouse[$1][cont][mods].func = $2;
X					  if ($2 == F_MENU)
X					  {
X					    pull->prev = NULL;
X					    Mouse[$1][cont][mods].menu = pull;
X					  }
X					  else
X					  {
X					    root = GetRoot(TWM_ROOT);
X					    Mouse[$1][cont][mods].item = 
X					    AddToMenu(root,"x",Action,0,$2);
X					  }
X					  Action = "";
X					  pull = NULL;
X					  cont = 0;
X					  mods = 0;
X					}
X		| tbutton action	{ Mouse[$1][C_TITLE][0].func = $2;
X					  Mouse[$1][C_ICON][0].func = $2;
X					  if ($2 == F_MENU)
X					  {
X					    pull->prev = NULL;
X					    Mouse[$1][C_TITLE][0].menu = pull;
X					    Mouse[$1][C_ICON][0].menu = pull;
X					  }
X					  else
X					  {
X					    root = GetRoot(TWM_ROOT);
X					    Mouse[$1][C_TITLE][0].item = 
X					    AddToMenu(root,"x",Action,0,$2);
X					    Mouse[$1][C_ICON][0].item =
X						Mouse[$1][C_TITLE][0].item;
X					  }
X					  Action = "";
X					  pull = NULL;
X					}
X		| NO_TITLE		{ list = NO_TITLE; }
X		  win_list
X		| AUTO_RAISE		{ list = AUTO_RAISE; }
X		  win_list
X		| MENU string		{ root = GetRoot($2); }
X		  menu
X		| ICONS 		{ list = ICONS; }
X		  icon_list
X		| COLOR 		{ color = COLOR; }
X		  color_list
X		| MONOCHROME 		{ color = MONOCHROME; }
X		  color_list
X		;
X
X
Xfull		: EQUALS keys COLON context COLON action  { $$ = $6; }
X		;
X
Xkeys		: /* Empty */
X		| keys key
X		;
X
Xkey		: META			{ mods |= Mod1Mask; }
X		| SHIFT			{ mods |= ShiftMask; }
X		| CONTROL		{ mods |= ControlMask; }
X		;
X
Xcontext		: WINDOW		{ cont = C_WINDOW; }
X		| TITLE			{ cont = C_TITLE; }
X		| ICON			{ cont = C_ICON; }
X		| ROOT			{ cont = C_ROOT; }
X		;
X
Xcolor_list	: LB color_entries RB
X		;
X
Xcolor_entries	: /* Empty */
X		| color_entries color_entry
X		;
X
Xcolor_entry	: BORDER_COLOR string	{ GetColor(color, &BorderColor, $2); }
X		| TITLE_FOREGROUND string { GetColor(color,
X						&TitleForeground, $2); }
X		| TITLE_BACKGROUND string { GetColor(color,
X						&TitleBackground, $2); }
X		| MENU_FOREGROUND string { GetColor(color,
X						&MenuForeground, $2); }
X		| MENU_BACKGROUND string { GetColor(color,
X						&MenuBackground, $2); }
X		| MENU_TITLE_FOREGROUND string { GetColor(color,
X						    &MenuTitleForeground, $2); }
X		| MENU_TITLE_BACKGROUND string { GetColor(color,
X						    &MenuTitleBackground, $2); }
X		| MENU_SHADOW_COLOR string { GetColor(color,
X						    &MenuShadowColor, $2); }
X		| ICON_FOREGROUND string { GetColor(color,
X						&IconForeground, $2); }
X		| ICON_BACKGROUND string { GetColor(color,
X						&IconBackground, $2); }
X		| ICON_BORDER_COLOR string { GetColor(color,
X						&IconBorderColor, $2); }
X
Xwin_list	: LB win_entries RB
X		;
X
Xwin_entries	: /* Empty */
X		| win_entries win_entry
X		;
X
Xwin_entry	: string		{ if (FirstTime) AddToList(list, $1, 0); }
X		;
X
Xicon_list	: LB icon_entries RB
X		;
X
Xicon_entries	: /* Empty */
X		| icon_entries icon_entry
X		;
X
Xicon_entry	: string string		{   if (FirstTime)
X					    { 
X						Pixmap pm;
X						
X						pm = GetBitmap($2);
X						if (pm != NULL)
X						    AddToList(list, $1, pm);
X					    }
X					}
X		;
X
Xmenu		: LB menu_entries RB
X		;
X
Xmenu_entries	: /* Empty */
X		| menu_entries menu_entry
X		;
X
Xmenu_entry	: string action		{ AddToMenu(root, $1, Action, pull, $2);
X					  Action = "";
X					  pull = NULL;
X					}
X		;
X
Xaction		: F_NOP			{ $$ = F_NOP; }
X		| F_QUIT		{ $$ = F_QUIT; }
X		| F_FOCUS		{ $$ = F_FOCUS; }
X		| F_REFRESH		{ $$ = F_REFRESH; }
X		| F_WINREFRESH		{ $$ = F_WINREFRESH; }
X		| F_SOURCE string	{ Action = $2; $$ = F_TWMRC; }
X		| F_MOVE		{ $$ = F_MOVE; }
X		| F_ICONIFY		{ $$ = F_ICONIFY; }
X		| F_UNFOCUS		{ $$ = F_UNFOCUS; }
X		| F_RESIZE		{ $$ = F_RESIZE; }
X		| F_RAISE		{ $$ = F_RAISE; }
X		| F_LOWER		{ $$ = F_LOWER; }
X		| F_DESTROY		{ $$ = F_DESTROY; }
X		| F_TWMRC		{ $$ = F_TWMRC; }
X		| F_VERSION		{ $$ = F_VERSION; }
X		| F_TITLE		{ $$ = F_TITLE; }
X		| F_CIRCLEUP		{ $$ = F_CIRCLEUP; }
X		| F_CIRCLEDOWN		{ $$ = F_CIRCLEDOWN; }
X		| F_CUTFILE		{ $$ = F_CUTFILE; }
X		| F_MENU string		{ pull = GetRoot($2);
X					  pull->prev = root;
X					  $$ = F_MENU;
X					}
X		| F_FILE string		{ Action = $2; $$ = F_FILE; }
X		| F_EXEC string		{ Action = $2; $$ = F_EXEC; }
X		| F_CUT string		{ Action = $2; $$ = F_CUT; }
X		;
X
Xbutton		: BUTTON		{ $$ = $1;
X					  if ($1 == 0)
X						yyerror();
X
X					  if ($1 > MAX_BUTTONS)
X					  {
X						$$ = 0;
X						yyerror();
X					  }
X					}
X		;
Xtbutton		: TBUTTON		{ $$ = $1;
X					  if ($1 == 0)
X						yyerror();
X
X					  if ($1 > MAX_BUTTONS)
X					  {
X						$$ = 0;
X						yyerror();
X					  }
X					}
X		;
X
Xstring		: STRING		{ ptr = (char *)malloc(strlen($1)+1);
X					  strcpy(ptr, $1);
X					  RemoveDQuote(ptr);
X					  $$ = ptr;
X					}
Xnumber		: NUMBER		{ $$ = $1; }
X		;
X
X%%
Xyyerror(s) char *s;
X{
X    fprintf(stderr, "twm: syntax error, line %d\n", yylineno);
X    ParseError = 1;
X}
XRemoveDQuote(str)
Xchar *str;
X{
X    strcpy(str, &str[1]);
X    str[strlen(str)-1] = '\0';
X}
X
XMenuRoot *
XGetRoot(name)
Xchar *name;
X{
X    MenuRoot *tmp;
X
X    tmp = FindMenuRoot(name);
X    if (tmp == NULL)
X	tmp = NewMenuRoot(name);
X
X    return tmp;
X}
X
SHAR_EOF
if test 10093 -ne "`wc -c < gram.y`"
then
    echo shar: error transmitting "gram.y" '(should have been 10093 characters)'
fi
fi
if test -f 'mytitle.c'
then
    echo shar: will not over-write existing file "mytitle.c"
else
echo extracting "mytitle.c"
sed 's/^X//' >mytitle.c <<'SHAR_EOF'
X#include <stdio.h>
X
Xmain()
X{
X    char	*wd, *home, *term, dir[200], host[100];
X    int		i, len;
X
X    if ((wd = (char *)getwd(dir)) == NULL)
X	exit(0);
X
X    term = (char *)getenv("TERM");
X    if (strncmp(term, "xterm", 5))
X	exit(0);
X
X    home = (char *)getenv("HOME");
X    gethostname(host,100);
X
X    len = strlen(home);
X    for (i = 0; i < len; i++)
X    {
X	if (home[i] != wd[i])
X	    break;
X    }
X
X    if (i == len)
X	printf("\033]2;%s: ~%s\007", host,&wd[i]);
X    else
X	printf("\033]2;%s: %s\007", host,wd);
X
X    printf("\033]1;%s\007", host);
X
X    exit(0);
X}
SHAR_EOF
if test 558 -ne "`wc -c < mytitle.c`"
then
    echo shar: error transmitting "mytitle.c" '(should have been 558 characters)'
fi
fi
if test -f 'add_window.c'
then
    echo shar: will not over-write existing file "add_window.c"
else
echo extracting "add_window.c"
sed 's/^X//' >add_window.c <<'SHAR_EOF'
X/*****************************************************************************/
X/**       Copyright 1988 by Evans & Sutherland Computer Corporation,        **/
X/**                          Salt Lake City, Utah                           **/
X/**                                                                         **/
X/**                           All Rights Reserved                           **/
X/**                                                                         **/
X/**    Permission to use, copy, modify, and distribute this software and    **/
X/**    its documentation  for  any  purpose  and  without  fee is hereby    **/
X/**    granted, provided that the above copyright notice appear  in  all    **/
X/**    copies and that both  that  copyright  notice  and  this  permis-    **/
X/**    sion  notice appear in supporting  documentation,  and  that  the    **/
X/**    name  of Evans & Sutherland  not be used in advertising or publi-    **/
X/**    city pertaining to distribution  of the software without  specif-    **/
X/**    ic, written prior permission.                                        **/
X/**                                                                         **/
X/**    EVANS  & SUTHERLAND  DISCLAIMS  ALL  WARRANTIES  WITH  REGARD  TO    **/
X/**    THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILI-    **/
X/**    TY AND FITNESS, IN NO EVENT SHALL EVANS &  SUTHERLAND  BE  LIABLE    **/
X/**    FOR  ANY  SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY  DAM-    **/
X/**    AGES  WHATSOEVER RESULTING FROM  LOSS OF USE,  DATA  OR  PROFITS,    **/
X/**    WHETHER   IN  AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS    **/
X/**    ACTION, ARISING OUT OF OR IN  CONNECTION  WITH  THE  USE  OR PER-    **/
X/**    FORMANCE OF THIS SOFTWARE.                                           **/
X/*****************************************************************************/
X
X/**********************************************************************
X *
X * $Header: add_window.c,v 1.25 88/06/03 10:18:55 tlastran Exp $
X *
X * Add a new window, put the titlbar and other stuff around
X * the window
X *
X * 31-Mar-88 Tom LaStrange        Initial Version.
X *
X **********************************************************************/
X
X#ifndef lint
Xstatic char RCSinfo[]=
X"$Header: add_window.c,v 1.25 88/06/03 10:18:55 tlastran Exp $";
X#endif lint
X
X#include <stdio.h>
X#include "twm.h"
X#include <X11/Xatom.h>
X#include "add_window.h"
X#include "util.h"
X#include "resize.h"
X#include "gram.h"
X#include "list.h"
X#include "events.h"
X#include "menus.h"
X
X#include "iconify.bm"
X#include "resize.bm"
X#ifndef NOFOCUS
X#include "focus.bm"
X#else
X#define focus_width 0
X#endif
X#include "hilite.bm"
X
Xint AddingWindow = 0;		/* adding window count */
Xint AddingX;
Xint AddingY;
Xint AddingW;
Xint AddingH;
X
Xchar NoName[] = "No Name"; /* name if no name is specified */
X
X/***********************************************************************
X *
X *  Procedure:
X *	AddWindow - add a new window to the twm list
X *
X *  Returned Value:
X *	(TwmWindow *) - pointer to the TwmWindow structure
X *
X *  Inputs:
X *	w	- the window id of the window to add
X *
X ***********************************************************************
X */
X
XTwmWindow *
XAddWindow(w)
XWindow w;
X{
X    TwmWindow *tmp_win;			/* new twm window structure */
X    char *prop;
X    unsigned long valuemask;		/* mask for create windows */
X    XSetWindowAttributes attributes;	/* attributes for create windows */
X    XSetWindowAttributes grav_attr;	/* gravity attributes to set */
X    int width, len;			/* tmp variable */
X    int junk1, junk2, junk3;
X    int x;
X    Pixmap pm;			/* tmp pixmap variable */
X    XWindowChanges xwc;		/* change window structure */
X    unsigned int xwcm;		/* change window mask */
X    int dont_know;		/* don't know where to put the window */
X    XColor blob, cret;
X
X#ifdef DEBUG
X    fprintf(stderr, "AddWindow: w = 0x%x\n", w);
X#endif
X
X    /* allocate space for the twm window */
X    tmp_win = (TwmWindow *)malloc(sizeof(TwmWindow));
X    tmp_win->w = w;
X
X    XSelectInput(dpy, tmp_win->w, PropertyChangeMask);
X    XGetWindowAttributes(dpy, tmp_win->w, &tmp_win->attr);
X    XFetchName(dpy, tmp_win->w, &tmp_win->name);
X    tmp_win->class = NoClass;
X    XGetClassHint(dpy, tmp_win->w, &tmp_win->class);
X
X#ifdef DEBUG
X    fprintf(stderr, "  name = \"%s\"\n", tmp_win->name);
X#endif
X    tmp_win->wmhints = XGetWMHints(dpy, tmp_win->w);
X    if (XGetNormalHints(dpy, tmp_win->w, &tmp_win->hints) == 0)
X	tmp_win->hints.flags = 0;
X
X    if (strncmp("xterm", tmp_win->class.res_name, 5) == 0 ||
X    	strncmp("xterm", tmp_win->class.res_class, 5) == 0)
X	tmp_win->xterm = TRUE;
X    else
X	tmp_win->xterm = FALSE;
X
X    dont_know = TRUE;
X    if (tmp_win->hints.flags & PPosition)
X    {
X#ifdef DEBUG
X	fprintf(stderr, "  program specified hints\n");
X#endif
X	tmp_win->attr.x = tmp_win->hints.x;
X	tmp_win->attr.y = tmp_win->hints.y;
X	tmp_win->attr.width = tmp_win->hints.width;
X	tmp_win->attr.height = tmp_win->hints.height;
X    }
X    if (tmp_win->hints.flags & USPosition)
X    {
X#ifdef DEBUG
X	fprintf(stderr, "  user specified hints\n");
X#endif
X	dont_know = FALSE;
X	tmp_win->attr.x = tmp_win->hints.x;
X	tmp_win->attr.y = tmp_win->hints.y;
X	tmp_win->attr.width = tmp_win->hints.width;
X	tmp_win->attr.height = tmp_win->hints.height;
X    }
X
X    if (tmp_win->name == NULL)
X	tmp_win->name = NoName;
X    if (tmp_win->class.res_name == NULL)
X    	tmp_win->class.res_name = NoName;
X    if (tmp_win->class.res_class == NULL)
X    	tmp_win->class.res_class = NoName;
X
X    tmp_win->full_name = tmp_win->name;
X
X    if (strncmp("xterm_", tmp_win->name, 6) == 0)
X	tmp_win->name = &tmp_win->name[6];
X
X    tmp_win->auto_raise = (short)LookInList(AUTO_RAISE, tmp_win->full_name, 
X     &tmp_win->class);
X    if (LookInList(NO_TITLE, tmp_win->full_name, &tmp_win->class))
X	tmp_win->title_height = 0;
X    else
X	tmp_win->title_height = TITLE_BAR_HEIGHT + BorderWidth;
X
X    if (HandlingEvents && dont_know)
X    {
X	if (!(tmp_win->wmhints && tmp_win->wmhints->flags & StateHint &&
X	    tmp_win->wmhints->initial_state == IconicState) &&
X	   (tmp_win->xterm || (tmp_win->attr.x == 0 && tmp_win->attr.y == 0)))
X	{
X	    width = XTextWidth(InitialFont, tmp_win->name,
X		strlen(tmp_win->name)) + 20;
X	    XResizeWindow(dpy, InitialWindow, width, InitialFontHeight + 4);
X	    XMapRaised(dpy, InitialWindow);
X	    XDrawImageString(dpy, InitialWindow, InitialNormalGC,
X		10, 2 + InitialFont->ascent,
X		tmp_win->name, strlen(tmp_win->name));
X
X	    AddingW = tmp_win->attr.width;
X	    AddingH = tmp_win->attr.height;
X	    AddingWindow += 1;
X
X	    XGrabPointer(dpy, Root, True,
X		0,
X		GrabModeAsync, GrabModeSync,
X		Root, UpperLeftCursor, CurrentTime);
X
X	    AddingW = tmp_win->attr.width + 2 * BorderWidth;
X	    AddingH = tmp_win->attr.height + tmp_win->title_height +
X		2 * BorderWidth;
X
X	    while (TRUE)
X	    {
X		XQueryPointer(dpy, Root, &JunkRoot, &JunkChild,
X		    &JunkX, &JunkY, &AddingX, &AddingY, &JunkMask);
X
X		MoveOutline(Root, AddingX, AddingY, AddingW, AddingH);
X
X		if (JunkMask & (Button1Mask | Button2Mask | Button3Mask))
X		    break;
X	    }
X
X	    if (JunkMask & Button2Mask)
X	    {
X		XWarpPointer(dpy, None, Root, 0, 0, 0, 0,
X		    AddingX + AddingW/2, AddingY + AddingH/2);
X		AddStartResize(tmp_win, AddingX, AddingY, AddingW, AddingH);
X
X		while (TRUE)
X		{
X		    int lastx, lasty;
X
X		    XQueryPointer(dpy, Root, &JunkRoot, &JunkChild,
X			&JunkX, &JunkY, &AddingX, &AddingY, &JunkMask);
X
X		    if (lastx != AddingX || lasty != AddingY)
X		    {
X			DoResize(AddingX, AddingY, tmp_win);
X
X			lastx = AddingX;
X			lasty = AddingY;
X		    }
X
X		    if (!(JunkMask & Button2Mask))
X		    {
X			AddEndResize(tmp_win);
X			break;
X		    }
X		}
X	    }
X
X	    MoveOutline(Root, 0, 0, 0, 0);
X	    XUnmapWindow(dpy, InitialWindow);
X
X	    tmp_win->attr.x = AddingX;
X	    tmp_win->attr.y = AddingY + tmp_win->title_height;
X	    tmp_win->attr.width = AddingW - 2 * BorderWidth;
X	    tmp_win->attr.height = AddingH - tmp_win->title_height -
X		(2 * BorderWidth);
X	}
X    }
X
X    if (tmp_win->attr.y < tmp_win->title_height)
X	tmp_win->attr.y = tmp_win->title_height;
X
X    xwcm = CWX | CWY | CWWidth | CWHeight | CWBorderWidth;
X
X#ifdef DEBUG
X	fprintf(stderr, "  position window  %d, %d  %dx%d\n", 
X	    tmp_win->attr.x,
X	    tmp_win->attr.y,
X	    tmp_win->attr.width,
X	    tmp_win->attr.height);
X#endif
X    xwc.x = tmp_win->attr.x + tmp_win->attr.border_width;
X    xwc.y = tmp_win->attr.y + tmp_win->attr.border_width;
X    xwc.width = tmp_win->attr.width;
X    xwc.height = tmp_win->attr.height;
X    xwc.border_width = 0;
X
X    XConfigureWindow(dpy, tmp_win->w, xwcm, &xwc);
X
X    tmp_win->name_width = XTextWidth(TitleBarFont, tmp_win->name,
X	strlen(tmp_win->name));
X
X    if (XGetWindowProperty(dpy, tmp_win->w, XA_WM_ICON_NAME, 0, 200, False,
X	AnyPropertyType, &junk1, &junk2, &junk3, &len, &tmp_win->icon_name))
X	tmp_win->icon_name = tmp_win->name;
X
X    if (tmp_win->icon_name == NULL)
X	tmp_win->icon_name = tmp_win->name;
X
X    tmp_win->iconified = FALSE;
X    tmp_win->icon = FALSE;
X
X    /* add the window into the twm list */
X    tmp_win->next = TwmRoot.next;
X    if (TwmRoot.next != NULL)
X	TwmRoot.next->prev = tmp_win;
X    tmp_win->prev = &TwmRoot;
X    TwmRoot.next = tmp_win;
X
X    /* create windows */
X
X    tmp_win->frame_x = tmp_win->attr.x;
X    tmp_win->frame_y = tmp_win->attr.y - tmp_win->title_height;
X
X    tmp_win->frame = XCreateSimpleWindow(dpy, Root,
X	tmp_win->frame_x,
X	tmp_win->frame_y,
X	tmp_win->attr.width,
X	tmp_win->attr.height + tmp_win->title_height,
X	BorderWidth,
X	BorderColor, TitleBackground);
X
X    /*
X    XSetWindowBorderPixmap(dpy, tmp_win->frame, GrayTile);
X    */
X    
X    tmp_win->title_w = XCreateSimpleWindow(dpy, tmp_win->frame,
X	-BorderWidth, -BorderWidth,
X	tmp_win->attr.width, TITLE_BAR_HEIGHT,
X	BorderWidth,
X	BorderColor, TitleBackground);
X
X    /*
X    XSetWindowBorderPixmap(dpy, tmp_win->title_w, GrayTile);
X    */
X
X    /* the three buttons have the pixmap as the background of the
X     * window, that way I don't have to worry about repainting them
X     * on expose events.
X     */
X
X    valuemask = CWEventMask | CWBackPixmap;
X    attributes.event_mask = ButtonPressMask | ButtonReleaseMask;
X    attributes.background_pixmap = MakePixmap(tmp_win->title_w, TitleNormalGC,
X	iconify_bits, iconify_width, iconify_height);
X
X    tmp_win->iconify_w = XCreateWindow(dpy, tmp_win->title_w,
X	TITLE_BAR_SPACE, TITLE_BAR_SPACE,
X	iconify_width, iconify_height,
X	0, DefaultDepth(dpy, 0), CopyFromParent, DefaultVisual(dpy,0),
X	valuemask, &attributes);
X
X#ifndef NOFOCUS
X    attributes.background_pixmap = MakePixmap(tmp_win->title_w, TitleNormalGC,
X	focus_bits, focus_width, focus_height);
X
X    tmp_win->focus_w = XCreateWindow(dpy, tmp_win->title_w,
X	tmp_win->attr.width - resize_width -3 - focus_width, TITLE_BAR_SPACE,
X	iconify_width, iconify_height,
X	0, DefaultDepth(dpy, 0), CopyFromParent, DefaultVisual(dpy,0),
X	valuemask, &attributes);
X#endif
X
X    attributes.background_pixmap = MakePixmap(tmp_win->title_w, TitleNormalGC,
X	resize_bits, resize_width, resize_height);
X
X    tmp_win->resize_w = XCreateWindow(dpy, tmp_win->title_w,
X	tmp_win->attr.width - resize_width - 1,
X	TITLE_BAR_SPACE,
X	resize_width, resize_height,
X	0, DefaultDepth(dpy, 0), CopyFromParent, DefaultVisual(dpy,0),
X	valuemask, &attributes);
X	
X    valuemask = CWBackPixmap;
X    attributes.background_pixmap = MakePixmap(tmp_win->title_w, TitleNormalGC,
X	hilite_bits, hilite_width, hilite_height);
X
X    tmp_win->hilite_w = XCreateWindow(dpy, tmp_win->title_w,
X	TitleBarX, 1,
X	10, hilite_height,
X	0, DefaultDepth(dpy, 0), CopyFromParent, DefaultVisual(dpy,0),
X	valuemask, &attributes);
X	
X    XDefineCursor(dpy, tmp_win->title_w, ArrowCursor);
X    XDefineCursor(dpy, tmp_win->iconify_w, ButtonCursor);
X#ifndef NOFOCUS
X    XDefineCursor(dpy, tmp_win->focus_w, ButtonCursor);
X#endif
X    XDefineCursor(dpy, tmp_win->resize_w, ButtonCursor);
X
X    XSelectInput(dpy, tmp_win->w, StructureNotifyMask | PropertyChangeMask);
X    XSelectInput(dpy, tmp_win->frame,
X	ButtonPressMask | ButtonReleaseMask |
X	EnterWindowMask | LeaveWindowMask);
X
X    XSelectInput(dpy, tmp_win->title_w, 
X	ButtonPressMask | ButtonReleaseMask | ExposureMask);
X
X    grav_attr.win_gravity = NorthWestGravity;
X    grav_attr.bit_gravity = ForgetGravity;
X    XChangeWindowAttributes(dpy, tmp_win->w, 
X	CWBitGravity | CWWinGravity, &grav_attr);
X    XChangeWindowAttributes(dpy, tmp_win->frame, 
X	CWBitGravity | CWWinGravity, &grav_attr);
X
X    XAddToSaveSet(dpy, tmp_win->w);
X    XReparentWindow(dpy, tmp_win->w, tmp_win->frame, 0, tmp_win->title_height);
X
X    SetupWindow(tmp_win,
X	tmp_win->frame_x,
X	tmp_win->frame_y,
X	tmp_win->attr.width,
X	tmp_win->attr.height + tmp_win->title_height);
X
X    pm = NULL;
X    tmp_win->forced = FALSE;
X
X    /* now go through the steps to get an icon window,  if ForceIcon is 
X     * set, then no matter what else is defined, the bitmap from the
X     * .twmrc file is used
X     */
X    if (ForceIcon)
X    {
X	Pixmap bm;
X	XImage *image;
X	unsigned mask;
X
X        bm = (Pixmap)LookInList(ICONS, tmp_win->full_name, &tmp_win->class);
X	if (bm != NULL)
X	{
X	    XGetGeometry(dpy, bm, &JunkRoot, &JunkX, &JunkY,
X		&tmp_win->icon_width, &tmp_win->icon_height,
X		&JunkBW, &JunkDepth);
X
X	    /*
X	    mask = IconForeground ^ IconBackground;
X	    image = XGetImage(dpy, bm, 0, 0, tmp_win->icon_width,
X		tmp_win->icon_height, AllPlanes, XYPixmap);
X	    */
X
X	    pm = XCreatePixmap(dpy, Root, tmp_win->icon_width,
X		tmp_win->icon_height, DefaultDepth(dpy, 0));
X
X	    /* the copy plane works on color ! */
X	    XCopyPlane(dpy, bm, pm, IconNormalGC,
X		0,0, tmp_win->icon_width, tmp_win->icon_height, 0, 0, 1 );
X
X	    /*
X	    this code works on a monochrome system
X
X	    XPutImage(dpy, pm, IconNormalGC,
X		image, 0, 0, 0, 0, tmp_win->icon_width, tmp_win->icon_height);
X	    */
X	    tmp_win->forced = TRUE;
X	}
X    }
X
X    /* if the pixmap is still NULL, we didn't get one from the above code,
X     * that could mean that ForceIcon was not set, or that the window
X     * was not in the Icons list, now check the WM hints for an icon
X     */
X    if (pm == NULL && tmp_win->wmhints &&
X	tmp_win->wmhints->flags & IconPixmapHint)
X    {
X    
X	XGetGeometry(dpy,   tmp_win->wmhints->icon_pixmap,
X             &JunkRoot, &JunkX, &JunkY,
X	     &tmp_win->icon_width, &tmp_win->icon_height, &JunkBW, &JunkDepth);
X
X	pm = XCreatePixmap(dpy, Root, tmp_win->icon_width, tmp_win->icon_height,
X	    DefaultDepth(dpy, 0));
X
X	XCopyPlane(dpy, tmp_win->wmhints->icon_pixmap, pm, IconNormalGC,
X	    0,0, tmp_win->icon_width, tmp_win->icon_height, 0, 0, 1 );
X    }
X
X    /* if we still haven't got an icon, let's look in the Icon list 
X     * if ForceIcon is not set
X     */
X    if (pm == NULL && !ForceIcon)
X    {
X	Pixmap bm;
X	XImage *image;
X	unsigned mask;
X
X        bm = (Pixmap)LookInList(ICONS, tmp_win->full_name, &tmp_win->class);
X	if (bm != NULL)
X	{
X	    XGetGeometry(dpy, bm, &JunkRoot, &JunkX, &JunkY,
X		&tmp_win->icon_width, &tmp_win->icon_height,
X		&JunkBW, &JunkDepth);
X
X	    /*
X	    mask = IconForeground ^ IconBackground;
X	    image = XGetImage(dpy, bm, 0, 0, tmp_win->icon_width,
X		tmp_win->icon_height, AllPlanes, XYPixmap);
X	    */
X
X	    pm = XCreatePixmap(dpy, Root, tmp_win->icon_width,
X		tmp_win->icon_height, DefaultDepth(dpy, 0));
X
X	    /* the copy plane works on color ! */
X	    XCopyPlane(dpy, bm, pm, IconNormalGC,
X		0,0, tmp_win->icon_width, tmp_win->icon_height, 0, 0, 1 );
X
X	    /*
X	    this code works on a monochrome system
X
X	    XPutImage(dpy, pm, IconNormalGC,
X		image, 0, 0, 0, 0, tmp_win->icon_width, tmp_win->icon_height);
X	    */
X	}
X    }
X
X    /* if we still don't have an icon, assign the UnknownIcon */
X
X    if (pm == NULL && UnknownPm != NULL)
X    {
X	XImage *image;
X	unsigned mask;
X
X	tmp_win->icon_width = UnknownWidth;
X	tmp_win->icon_height = UnknownHeight;
X	mask = IconForeground ^ IconBackground;
X	image = XGetImage(dpy, UnknownPm, 0, 0, tmp_win->icon_width,
X	    tmp_win->icon_height, AllPlanes, XYPixmap);
X
X	pm = XCreatePixmap(dpy, Root, tmp_win->icon_width,
X	    tmp_win->icon_height, DefaultDepth(dpy, 0));
X
X	/* the copy plane works on color ! */
X	XCopyPlane(dpy, UnknownPm, pm, IconNormalGC,
X	    0,0, tmp_win->icon_width, tmp_win->icon_height, 0, 0, 1 );
X
X	/*
X	this code works on a monochrome system
X
X	XPutImage(dpy, pm, IconNormalGC,
X	    image, 0, 0, 0, 0, tmp_win->icon_width, tmp_win->icon_height);
X	*/
X    }
X
X    if (pm == NULL)
X    {
X	tmp_win->icon_height = 0;
X	tmp_win->icon_width = 0;
X	valuemask = 0;
X    }
X    else
X    {
X	valuemask = CWBackPixmap;
X	attributes.background_pixmap = pm;
X    }
X
X    tmp_win->icon_w_width = XTextWidth(IconFont,
X	tmp_win->icon_name, strlen(tmp_win->icon_name));
X
X    tmp_win->icon_w_width += 6;
X    if (tmp_win->icon_w_width < tmp_win->icon_width)
X    {
X	tmp_win->icon_x = (tmp_win->icon_width - tmp_win->icon_w_width)/2;
X	tmp_win->icon_x += 3;
X	tmp_win->icon_w_width = tmp_win->icon_width;
X    }
X    else
X    {
X	tmp_win->icon_x = 3;
X    }
X    tmp_win->icon_y = tmp_win->icon_height + IconFontHeight;
X
X    if (tmp_win->wmhints && tmp_win->wmhints->flags & IconWindowHint)
X    {
X	tmp_win->icon_w = tmp_win->wmhints->icon_window;
X    }
X    else
X    {
X	tmp_win->icon_w = XCreateSimpleWindow(dpy, Root,
X	    0,0,
X	    tmp_win->icon_w_width,
X	    tmp_win->icon_height + IconFontHeight + 4,
X	    2, IconBorderColor, IconBackground);
X    }
X
X    XSelectInput(dpy, tmp_win->icon_w,
X	ButtonPressMask | ButtonReleaseMask | ExposureMask);
X
X    tmp_win->icon_bm_w = NULL;
X    if (pm != NULL)
X    {
X	if (tmp_win->icon_w_width == tmp_win->icon_width)
X	    x = 0;
X	else
X	    x = (tmp_win->icon_w_width - tmp_win->icon_width)/2;
X
X	tmp_win->icon_bm_w = XCreateWindow(dpy, tmp_win->icon_w,
X	    x, 0, tmp_win->icon_width, tmp_win->icon_height,
X	    0, DefaultDepth(dpy, 0), CopyFromParent,
X	    DefaultVisual(dpy,0),
X	    valuemask, &attributes);
X    }
X
X    XDefineCursor(dpy, tmp_win->icon_w, ArrowCursor);
X
X    GrabButtons(tmp_win);
X
X    XSaveContext(dpy, tmp_win->w, TwmContext, tmp_win);
X    XSaveContext(dpy, tmp_win->frame, TwmContext, tmp_win);
X    XSaveContext(dpy, tmp_win->title_w, TwmContext, tmp_win);
X    XSaveContext(dpy, tmp_win->iconify_w, TwmContext, tmp_win);
X    XSaveContext(dpy, tmp_win->resize_w, TwmContext, tmp_win);
X    XSaveContext(dpy, tmp_win->icon_w, TwmContext, tmp_win);
X#ifndef NOFOCUS
X    XSaveContext(dpy, tmp_win->focus_w, TwmContext, tmp_win);
X#endif
X    XSaveContext(dpy, tmp_win->hilite_w, TwmContext, tmp_win);
X
X    SetHints(tmp_win);
X
X    return (tmp_win);
X}
X
X/***********************************************************************
X *
X *  Procedure:
X *	MappedNotOverride - checks to see if we should really
X *		put a twm frame on the window
X *
X *  Returned Value:
X *	TRUE	- go ahead and frame the window
X *	FALSE	- don't frame the window
X *
X *  Inputs:
X *	w	- the window to check
X *
X ***********************************************************************
X */
X
Xint
XMappedNotOverride(w)
X    Window w;
X{
X    XWindowAttributes wa;
X
X    XGetWindowAttributes(dpy, w, &wa);
X    return ((wa.map_state != IsUnmapped) && (wa.override_redirect != True));
X}
X
X/***********************************************************************
X *
X *  Procedure:
X *	GrabButtons - grab needed buttons for the window
X *
X *  Inputs:
X *	tmp_win - the twm window structure to use
X *
X ***********************************************************************
X */
X
Xvoid
XGrabButtons(tmp_win)
XTwmWindow *tmp_win;
X{
X    int i, j;
X
X    for (i = 0; i < MAX_BUTTONS+1; i++)
X    {
X	for (j = 0; j < MOD_SIZE; j++)
X	{
X	    if (Mouse[i][C_WINDOW][j].func != NULL)
X	    {
X		XGrabButton(dpy, i, j, tmp_win->w,
X		    True, ButtonPressMask | ButtonReleaseMask,
X		    GrabModeAsync, GrabModeAsync, None, ArrowCursor);
X	    }
X	}
X    }
X}
X
X/***********************************************************************
X *
X *  Procedure:
X *	UngrabButtons - ungrab buttons for windows
X *
X *  Inputs:
X *	tmp_win - the twm window structure to use
X *
X ***********************************************************************
X */
X
Xvoid
XUngrabButtons(tmp_win)
XTwmWindow *tmp_win;
X{
X    int i;
X
X    for (i = 0; i < MAX_BUTTONS+1; i++)
X    {
X	XUngrabButton(dpy, i, AnyModifier, tmp_win->w);
X    }
X}
SHAR_EOF
if test 20102 -ne "`wc -c < add_window.c`"
then
    echo shar: error transmitting "add_window.c" '(should have been 20102 characters)'
fi
fi
if test -f 'gc.c'
then
    echo shar: will not over-write existing file "gc.c"
else
echo extracting "gc.c"
sed 's/^X//' >gc.c <<'SHAR_EOF'
X/*****************************************************************************/
X/**       Copyright 1988 by Evans & Sutherland Computer Corporation,        **/
X/**                          Salt Lake City, Utah                           **/
X/**                                                                         **/
X/**                           All Rights Reserved                           **/
X/**                                                                         **/
X/**    Permission to use, copy, modify, and distribute this software and    **/
X/**    its documentation  for  any  purpose  and  without  fee is hereby    **/
X/**    granted, provided that the above copyright notice appear  in  all    **/
X/**    copies and that both  that  copyright  notice  and  this  permis-    **/
X/**    sion  notice appear in supporting  documentation,  and  that  the    **/
X/**    name  of Evans & Sutherland  not be used in advertising or publi-    **/
X/**    city pertaining to distribution  of the software without  specif-    **/
X/**    ic, written prior permission.                                        **/
X/**                                                                         **/
X/**    EVANS  & SUTHERLAND  DISCLAIMS  ALL  WARRANTIES  WITH  REGARD  TO    **/
X/**    THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILI-    **/
X/**    TY AND FITNESS, IN NO EVENT SHALL EVANS &  SUTHERLAND  BE  LIABLE    **/
X/**    FOR  ANY  SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY  DAM-    **/
X/**    AGES  WHATSOEVER RESULTING FROM  LOSS OF USE,  DATA  OR  PROFITS,    **/
X/**    WHETHER   IN  AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS    **/
X/**    ACTION, ARISING OUT OF OR IN  CONNECTION  WITH  THE  USE  OR PER-    **/
X/**    FORMANCE OF THIS SOFTWARE.                                           **/
X/*****************************************************************************/
X
X/**********************************************************************
X *
X * $Header: gc.c,v 1.8 88/06/03 10:31:55 tlastran Exp $
X *
X * Open the fonts and create the GCs
X *
X * 31-Mar-88 Tom LaStrange        Initial Version.
X *
X **********************************************************************/
X
X#ifndef lint
Xstatic char RCSinfo[]=
X"$Header: gc.c,v 1.8 88/06/03 10:31:55 tlastran Exp $";
X#endif lint
X
X#include <stdio.h>
X#include "twm.h"
X
X/***********************************************************************
X *
X *  Procedure:
X *	CreateGCs - open fonts and create all the needed GC's.  I only
X *		    want to do this once, hence the first_time flag.
X *
X ***********************************************************************
X */
X
Xvoid
XCreateGCs()
X{
X    static int first_time = TRUE;
X    XGCValues	    gcv;
X    unsigned long   gcm, mask;
X
X    if (!first_time)
X	return;
X
X    first_time = FALSE;
X
X    /* open fonts */
X
X    TitleBarFont = XLoadQueryFont(dpy, TitleBarFontName);
X    TitleBarFontHeight = TitleBarFont->ascent + TitleBarFont->descent;
X    TitleBarY = (TITLE_BAR_FONT_HEIGHT - TitleBarFontHeight)/2 +
X	TitleBarFont->ascent;
X
X    MenuFont = XLoadQueryFont(dpy, MenuFontName);
X    MenuFontHeight = MenuFont->ascent + MenuFont->descent;
X    MenuY = MenuFont->ascent + 1;
X
X    IconFont = XLoadQueryFont(dpy, IconFontName);
X    IconFontHeight = IconFont->ascent + IconFont->descent;
X
X    VersionFont = XLoadQueryFont(dpy, VersionFontName);
X    VersionFontHeight = VersionFont->ascent + VersionFont->descent;
X
X    SizeFont = XLoadQueryFont(dpy, SizeFontName);
X    SizeFontHeight = SizeFont->ascent + SizeFont->descent;
X
X    InitialFont = XLoadQueryFont(dpy, InitialFontName);
X    InitialFontHeight = InitialFont->ascent + InitialFont->descent;
X
X    /* create GC's */
X
X    if (ReverseVideo)
X    {
X	Background = Black;
X	Foreground = White;
X    }
X    else
X    {
X	Foreground = Black;
X	Background = White;
X    }
X
X    mask = Foreground ^ Background;
X
X    gcm = 0;
X    gcm |= GCFont;	    gcv.font = TitleBarFont->fid;
X    gcm |= GCPlaneMask;	    gcv.plane_mask = AllPlanes;
X    gcm |= GCForeground;    gcv.foreground = TitleForeground;
X    gcm |= GCBackground;    gcv.background = TitleBackground;
X
X    TitleNormalGC = XCreateGC(dpy, Root, gcm, &gcv);
X
X    gcm = 0;
X    gcm |= GCFont;	    gcv.font = MenuFont->fid;
X    gcm |= GCPlaneMask;	    gcv.plane_mask = AllPlanes;
X    gcm |= GCForeground;    gcv.foreground = MenuForeground;
X    gcm |= GCBackground;    gcv.background = MenuBackground;
X
X    MenuNormalGC = XCreateGC(dpy, Root, gcm, &gcv);
X
X    gcv.foreground = MenuBackground;
X    gcv.background = MenuForeground;
X
X    MenuReverseGC = XCreateGC(dpy, Root, gcm, &gcv);
X
X    mask = MenuForeground ^ MenuBackground;
X
X    gcm = 0;
X    gcm |= GCFunction;	    gcv.function = GXxor;
X    gcm |= GCFont;	    gcv.font = MenuFont->fid;
X    gcm |= GCPlaneMask;	    gcv.plane_mask = mask;
X    gcm |= GCForeground;    gcv.foreground = mask;
X    gcm |= GCBackground;    gcv.background = MenuBackground;
X
X    MenuXorGC = XCreateGC(dpy, Root, gcm, &gcv);
X
X    gcm = 0;
X    gcm |= GCFont;	    gcv.font = MenuFont->fid;
X    gcm |= GCPlaneMask;	    gcv.plane_mask = AllPlanes;
X    gcm |= GCForeground;    gcv.foreground = MenuTitleForeground;
X    gcm |= GCBackground;    gcv.background = MenuTitleBackground;
X
X    MenuTitleGC = XCreateGC(dpy, Root, gcm, &gcv);
X
X    mask = Foreground ^ Background;
X    gcm = 0;
X    gcm |= GCFunction;	    gcv.function = GXxor;
X    gcm |= GCLineWidth;	    gcv.line_width = 0;
X    gcm |= GCForeground;    gcv.foreground = mask;
X    gcm |= GCPlaneMask;	    gcv.plane_mask = mask;
X    gcm |= GCSubwindowMode; gcv.subwindow_mode = IncludeInferiors;
X
X    DrawGC = XCreateGC(dpy, Root, gcm, &gcv);
X
X    gcm = 0;
X    gcm |= GCFont;	    gcv.font = IconFont->fid;
X    gcm |= GCPlaneMask;	    gcv.plane_mask = AllPlanes;
X    gcm |= GCForeground;    gcv.foreground = IconForeground;
X    gcm |= GCBackground;    gcv.background = IconBackground;
X
X    IconNormalGC = XCreateGC(dpy, Root, gcm, &gcv);
X
X    mask = Foreground ^ Background;
X    gcm = 0;
X    gcm |= GCFont;	    gcv.font = VersionFont->fid;
X    gcm |= GCPlaneMask;	    gcv.plane_mask = mask;
X    gcm |= GCForeground;    gcv.foreground = Foreground;
X    gcm |= GCBackground;    gcv.background = Background;
X
X    VersionNormalGC = XCreateGC(dpy, Root, gcm, &gcv);
X
X    gcm = 0;
X    gcm |= GCFont;	    gcv.font = SizeFont->fid;
X    gcm |= GCPlaneMask;	    gcv.plane_mask = mask;
X    gcm |= GCForeground;    gcv.foreground = Foreground;
X    gcm |= GCBackground;    gcv.background = Background;
X
X    SizeNormalGC = XCreateGC(dpy, Root, gcm, &gcv);
X
X    gcm = 0;
X    gcm |= GCFont;	    gcv.font = InitialFont->fid;
X    gcm |= GCPlaneMask;	    gcv.plane_mask = mask;
X    gcm |= GCForeground;    gcv.foreground = Foreground;
X    gcm |= GCBackground;    gcv.background = Background;
X
X    InitialNormalGC = XCreateGC(dpy, Root, gcm, &gcv);
X}
SHAR_EOF
if test 6824 -ne "`wc -c < gc.c`"
then
    echo shar: error transmitting "gc.c" '(should have been 6824 characters)'
fi
fi
if test -f 'twm.c'
then
    echo shar: will not over-write existing file "twm.c"
else
echo extracting "twm.c"
sed 's/^X//' >twm.c <<'SHAR_EOF'
X/*****************************************************************************/
X/**       Copyright 1988 by Evans & Sutherland Computer Corporation,        **/
X/**                          Salt Lake City, Utah                           **/
X/**                                                                         **/
X/**                           All Rights Reserved                           **/
X/**                                                                         **/
X/**    Permission to use, copy, modify, and distribute this software and    **/
X/**    its documentation  for  any  purpose  and  without  fee is hereby    **/
X/**    granted, provided that the above copyright notice appear  in  all    **/
X/**    copies and that both  that  copyright  notice  and  this  permis-    **/
X/**    sion  notice appear in supporting  documentation,  and  that  the    **/
X/**    name  of Evans & Sutherland  not be used in advertising or publi-    **/
X/**    city pertaining to distribution  of the software without  specif-    **/
X/**    ic, written prior permission.                                        **/
X/**                                                                         **/
X/**    EVANS  & SUTHERLAND  DISCLAIMS  ALL  WARRANTIES  WITH  REGARD  TO    **/
X/**    THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILI-    **/
X/**    TY AND FITNESS, IN NO EVENT SHALL EVANS &  SUTHERLAND  BE  LIABLE    **/
X/**    FOR  ANY  SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY  DAM-    **/
X/**    AGES  WHATSOEVER RESULTING FROM  LOSS OF USE,  DATA  OR  PROFITS,    **/
X/**    WHETHER   IN  AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS    **/
X/**    ACTION, ARISING OUT OF OR IN  CONNECTION  WITH  THE  USE  OR PER-    **/
X/**    FORMANCE OF THIS SOFTWARE.                                           **/
X/*****************************************************************************/
X
X/***********************************************************************
X *
X * $Header: twm.c,v 1.38 88/06/03 10:45:37 tlastran Exp $
X *
X * twm - "Tom's Window Manager"
X *
X * 27-Oct-87 Thomas E. LaStrange	File created
X *
X ***********************************************************************/
X
X#ifndef lint
Xstatic char RCSinfo[] =
X"$Header: twm.c,v 1.38 88/06/03 10:45:37 tlastran Exp $";
X#endif
X
X#include <stdio.h>
X#include <signal.h>
X#include <fcntl.h>
X#include "twm.h"
X#include "add_window.h"
X#include "gc.h"
X#include "parse.h"
X#include "version.h"
X#include "menus.h"
X#include "events.h"
X#include "util.h"
X#include "gram.h"
X
X#include "twm.bm"
X#include "gray.bm"
X
XTwmWindow TwmRoot;		/* the head of the twm window list */
X
XDisplay *dpy;			/* which display are we talking to */
Xint screen;			/* the default screen */
X
XWindow Root;			/* the root window */
XWindow VersionWindow;		/* the twm version window */
XWindow SizeWindow;		/* the resize dimensions window */
XWindow ResizeWindow;		/* the window we are resizing */
XWindow InitialWindow;		/* the window name we are creating */
XColormap CMap;			/* default color map */
X
XXFontStruct *TitleBarFont;	/* title bar font structure */
XXFontStruct *MenuFont;		/* menu font structure */
XXFontStruct *IconFont;		/* icon font structure */
XXFontStruct *SizeFont;		/* resize font structure */
XXFontStruct *VersionFont;	/* version font structure */
XXFontStruct *InitialFont;	/* window creation font structure */
X
Xchar *TitleBarFontName = "8x13";/* default title bar font */
Xchar *MenuFontName = "8x13";	/* default menu font */
Xchar *IconFontName = "8x13";	/* default icon font */
Xchar *SizeFontName = "fg-22";	/* default resize font */
Xchar *VersionFontName = "8x13";	/* default version font */
Xchar *InitialFontName = "9x15";	/* default window creation font */
Xchar *IconDirectory = NULL;	/* icon directory to search */
X
Xint TitleBarFontHeight;		/* height of title bar font */
Xint MenuFontHeight;		/* height of menu font */
Xint IconFontHeight;		/* height of icon font */
Xint SizeFontHeight;		/* height of resize font */
Xint VersionFontHeight;		/* height of version font */
Xint InitialFontHeight;		/* height of window creation font */
X
Xint BorderColor;		/* color of window borders */
Xint TitleForeground;		/* foreground color of titlebar */
Xint TitleBackground;		/* background color of titlebar */
Xint MenuForeground;		/* menu foreground color */
Xint MenuBackground;		/* menu background color */
Xint MenuTitleForeground;	/* menu title foreground color */
Xint MenuTitleBackground;	/* menu title background color */
Xint MenuShadowColor;		/* menu shadow color */
Xint IconForeground;		/* icon foreground color */
Xint IconBackground;		/* icon background color */
Xint IconBorderColor;		/* icon border color */
X
XCursor ArrowCursor;		/* title bar cursor */
XCursor ButtonCursor;		/* title bar button cursor */
XCursor MoveCursor;		/* move and resize cursor */
XCursor ClockCursor;		/* wait a while cursor */
XCursor RightArrowCursor;	/* menu cursor */
XCursor UpperLeftCursor;		/* upper Left corner cursor */
XCursor DotCursor;		/* dot cursor for f.move, etc. from menus */
XCursor SkullCursor;		/* skull and cross bones, f.destroy */
X
XGC TitleNormalGC;		/* GC for title bar */
XGC MenuNormalGC;		/* normal GC for menus */
XGC MenuReverseGC;		/* reverse video GC for menus */
XGC MenuXorGC;			/* XOR GC for menus */
XGC MenuTitleGC;			/* normal GC for menu titles */
XGC IconNormalGC;		/* GC for icons */
XGC VersionNormalGC;		/* GC for the version window */
XGC SizeNormalGC;		/* GC for the resize window */
XGC InitialNormalGC;		/* GC for the initial creation window */
XGC DrawGC;			/* GC to draw lines for move and resize */
X
XXClassHint NoClass;		/* for applications with no class */
X
XXContext TwmContext;		/* context for twm windows */
XXContext MenuContext;		/* context for all menu windows */
X
Xint BorderWidth = BW;		/* border width of twm windows */
Xunsigned long Foreground;	/* foreground color of twm windows */
Xunsigned long Background;	/* background color of twm windows */
Xunsigned long Black;
Xunsigned long White;
XPixmap GrayTile;
X
Xchar Version[100];		/* place to build the version string */
XPixmap UnknownPm = NULL;	/* the unknown icon pixmap */
Xint UnknownWidth = 0;		/* width of the unknown icon */
Xint UnknownHeight = 0;		/* height of the unknown icon */
Xint FirstTime = TRUE;		/* first time we've read .twmrc */
Xint ReverseVideo = FALSE;	/* flag to do reverse video */
Xint FocusRoot = TRUE;		/* is the input focus on the root ? */
XTwmWindow *Focus = NULL;	/* the twm window that has focus */
Xint WarpCursor = FALSE;		/* warp cursor on de-iconify ? */
Xint ForceIcon = FALSE;		/* force the icon to the user specified */
Xint NoRaiseMove = FALSE;	/* don't raise window following move */
Xint NoRaiseResize = FALSE;	/* don't raise window following resize */
Xint NoRaiseDeicon = FALSE;	/* don't raise window on deiconify */
Xint DontMoveOff = FALSE;	/* don't allow windows to be moved off */
Xint DoZoom = FALSE;		/* zoom in and out of icons */
Xint Monochrome = COLOR;		/* is the display monochrome ? */
Xchar *Home;			/* the HOME environment variable */
Xint HomeLen;			/* length of Home */
Xint ParseError;			/* error parsing the .twmrc file */
Xint MyDisplayWidth;		/* my copy of DisplayWidth(dpy, screen) */
Xint MyDisplayHeight;		/* my copy of DisplayHeight(dpy, screen) */
X
Xint TitleBarY;			/* y coordinate to start text in the title */
Xint TitleBarX = TITLE_BAR_HEIGHT + 4;	/* x coordinate ditto */
Xint MenuY;			/* y coordiante for text in menus */
Xint HandlingEvents = FALSE;	/* are we handling events yet? */
X
XWindow JunkRoot;		/* junk window */
XWindow JunkChild;		/* junk window */
Xint JunkX;			/* junk variable */
Xint JunkY;			/* junk variable */
Xint JunkWidth;			/* junk variable */
Xint JunkHeight;			/* junk variable */
Xint JunkDepth;			/* junk variable */
Xint JunkBW;			/* junk variable */
Xint JunkMask;			/* junk variable */
X
X/***********************************************************************
X *
X *  Procedure:
X *	main - start of twm
X *
X ***********************************************************************
X */
X
Xmain(argc, argv)
X    int argc;
X    char *argv[];
X{
X    Window root, parent, *children;
X    int nchildren, i;
X    int m, d, y;
X    char *display_name;
X    unsigned long valuemask;	/* mask for create windows */
X    XSetWindowAttributes attributes;	/* attributes for create windows */
X
X    display_name = NULL;
X
X    if (argc != 1 && argc != 3)
X    {
X	fprintf(stderr, "Usage: twm [-display display]\n");
X	exit(1);
X    }
X
X    if (argc == 3)
X    {
X	if (strncmp(argv[1], "-d", 2) == 0)
X	    display_name = argv[2];
X	else
X	{
X	    fprintf(stderr, "Usage: twm [-display display]\n");
X	    exit(1);
X	}
X    }
X
X    signal(SIGINT, Done);
X    signal(SIGQUIT, Done);
X    signal(SIGHUP, Done);
X    signal(SIGTERM, Done);
X
X    Home = (char *)getenv("HOME");
X    if (Home == NULL)
X	Home = "./";
X
X    HomeLen = strlen(Home);
X
X    NoClass.res_name = NoName;
X    NoClass.res_class = NoName;
X
X    TwmRoot.next = NULL;
X    TwmRoot.prev = NULL;
X    TwmRoot.w = NULL;
X    TwmRoot.title_w = NULL;
X    TwmRoot.iconify_w = NULL;
X    TwmRoot.resize_w = NULL;
X
X    if ((dpy = XOpenDisplay(display_name)) == NULL)
X    {
X	fprintf(stderr, "twm: can't open the display\n");
X	exit(1);
X    }
X
X
X    if (fcntl(ConnectionNumber(dpy), F_SETFD, 1) == -1)
X    {
X	fprintf(stderr, "twm: child cannot disinherit TCP fd\n");
X	exit(1);
X    }
X
X    screen = DefaultScreen(dpy);
X    Root = RootWindow(dpy, screen);
X    CMap = DefaultColormap(dpy, screen);
X    MyDisplayWidth = DisplayWidth(dpy, screen);
X    MyDisplayHeight = DisplayHeight(dpy, screen);
X
X    XSetErrorHandler(Other);
X    XSelectInput(dpy, Root,
X	SubstructureRedirectMask |
X	ButtonPressMask | ButtonReleaseMask | ExposureMask);
X    XSync(dpy, 0);
X
X    XSetErrorHandler(Error);
X    XSetInputFocus(dpy, Root, RevertToPointerRoot, CurrentTime);
X
X    TwmContext = XUniqueContext();
X    MenuContext = XUniqueContext();
X
X    /* define cursors */
X
X    ArrowCursor = XCreateFontCursor(dpy, XC_top_left_arrow);
X    MoveCursor = XCreateFontCursor(dpy, XC_fleur);
X    RightArrowCursor = XCreateFontCursor(dpy, XC_sb_right_arrow);
X    ButtonCursor = XCreateFontCursor(dpy, XC_center_ptr);
X    ClockCursor = XCreateFontCursor(dpy, XC_watch);
X    UpperLeftCursor = XCreateFontCursor(dpy, XC_top_left_corner);
X    DotCursor = XCreateFontCursor(dpy, XC_dot);
X    SkullCursor = XCreateFontCursor(dpy, XC_pirate);
X
X    XGrabServer(dpy);
X    XSync(dpy, 0);
X    XQueryTree(dpy, Root, &root, &parent, &children, &nchildren);
X
X    /* setup default colors */
X
X    Black = BlackPixel(dpy, screen);
X    White = WhitePixel(dpy, screen);
X
X    BorderColor = Black;
X    TitleForeground = Black;
X    TitleBackground = White;
X    MenuForeground = Black;
X    MenuBackground = White;
X    MenuTitleForeground = Black;
X    MenuTitleBackground = White;
X    MenuShadowColor = Black;
X    IconForeground = Black;
X    IconBackground = White;
X    IconBorderColor = Black;
X
X    if (DefaultDepth(dpy, screen) == 1)
X	Monochrome = MONOCHROME;
X
X    ParseTwmrc(NULL);
X    FirstTime = FALSE;
X    CreateGCs();
X
X    GrayTile = MakePixmap(Root, TitleNormalGC, gray_bits, 
X     gray_width, gray_height);
X
X    for (i = 0; i < nchildren; i++)
X    {
X	if (MappedNotOverride(children[i]))
X	{
X	    AddWindow(children[i]);
X	}
X    }
X
X    InitialWindow = XCreateSimpleWindow(dpy, Root,
X	0, 0, 5, InitialFontHeight + 4, BW, Foreground, Background);
X
X    /* contruct the version string */
X    sprintf(Version, "%s", &Revision[1]);
X    Version[strlen(Version) - 1] = '\0';
X    sscanf(&Date[7], "%d/%d/%d", &y, &m, &d);
X    sprintf(Version, "%s  Date: %d/%d/%d %s", Version, m, d, y, &Date[16]);
X    Version[strlen(Version) - 2] = '\0';
X
X    VersionWindow = XCreateSimpleWindow(dpy, Root,
X	0, 0,
X	twm_width + XTextWidth(VersionFont, Version, strlen(Version)) + 20,
X	VersionFontHeight + 4,
X	BW,
X	Foreground, Background);
X
X    valuemask = CWBackPixmap;
X    attributes.background_pixmap = MakePixmap(VersionWindow, VersionNormalGC,
X	twm_bits, twm_width, twm_height);
X
X    XCreateWindow(dpy, VersionWindow,
X	4, 1,
X	twm_width, twm_height,
X	0, DefaultDepth(dpy, 0), CopyFromParent, DefaultVisual(dpy, 0),
X	valuemask, &attributes);
X
X    XSelectInput(dpy, VersionWindow, ExposureMask);
X    XMapSubwindows(dpy, VersionWindow);
X    XMapWindow(dpy, VersionWindow);
X
X    SizeWindow = XCreateSimpleWindow(dpy, Root,
X	0, 0,
X	100,
X	SizeFontHeight + 4,
X	BW,
X	Foreground, Background);
X
X
X    XUngrabServer(dpy);
X
X    HandlingEvents = TRUE;
X    InitEvents();
X    HandleEvents();
X}
X
X/***********************************************************************
X *
X *  Procedure:
X *	Done - cleanup and exit twm
X *
X *  Returned Value:
X *	none
X *
X *  Inputs:
X *	none
X *
X *  Outputs:
X *	none
X *
X *  Special Considerations:
X *	none
X *
X ***********************************************************************
X */
X
Xvoid
XDone()
X{
X    TwmWindow *tmp;			/* temp twm window structure */
X    unsigned x, y;
X    XWindowChanges xwc;		/* change window structure */
X    unsigned int xwcm;		/* change window mask */
X
X    /* put a border back around all windows */
X
X    for (tmp = TwmRoot.next; tmp != NULL; tmp = tmp->next)
X    {
X	XGetGeometry(dpy, tmp->w, &JunkRoot, &x, &y, &JunkWidth, &JunkHeight,
X	    &JunkBW, &JunkDepth);
X
X	xwcm = CWX | CWY | CWBorderWidth;
X
X	xwc.x = x - (2 * BorderWidth);
X	xwc.y = y - (2 * BorderWidth);
X	xwc.border_width = BorderWidth;
X
X	XConfigureWindow(dpy, tmp->w, xwcm, &xwc);
X    }
X
X    XSetInputFocus(dpy, Root, RevertToPointerRoot, CurrentTime);
X    XCloseDisplay(dpy);
X    exit(0);
X}
X
X/***********************************************************************
X *
X *  Procedure:
X *	Error - X error handler.  If we got here it is probably,
X *		because the client window went away and we haven't 
X *		got the DestroyNotify yet.
X *
X *  Inputs:
X *	dpy	- the connection to the X server
X *	event	- the error event structure
X *
X ***********************************************************************
X */
X
Xvoid
XError(dpy, event)
XDisplay *dpy;
XXErrorEvent *event;
X{
X    TwmWindow *tmp;			/* temp twm window structure */
X    char buffer[BUFSIZ];
X
X    /* Look for the window in the list, if it's there, remove it
X     * from the list, and continue on, else ignore the error.
X     * This is assumes that twm makes no errors. HaHa
X     */
X    for (tmp = TwmRoot.next; tmp != NULL; tmp = tmp->next)
X    {
X	if (tmp->w == event->resourceid)
X	{
X	    if (tmp == Focus)
X	    {
X		FocusOnRoot();
X	    }
X	    XDeleteContext(dpy, tmp->w, TwmContext);
X	    XDeleteContext(dpy, tmp->frame, TwmContext);
X	    XDeleteContext(dpy, tmp->title_w, TwmContext);
X	    XDeleteContext(dpy, tmp->iconify_w, TwmContext);
X	    XDeleteContext(dpy, tmp->resize_w, TwmContext);
X	    XDeleteContext(dpy, tmp->icon_w, TwmContext);
X#ifndef NOFOCUS
X	    XDeleteContext(dpy, tmp->focus_w, TwmContext);
X#endif
X	    XDeleteContext(dpy, tmp->hilite_w, TwmContext);
X
X	    XDestroyWindow(dpy, tmp->frame);
X	    XDestroyWindow(dpy, tmp->icon_w);
X	    tmp->prev->next = tmp->next;
X	    if (tmp->next != NULL)
X		tmp->next->prev = tmp->prev;
X
X	    free((char *)tmp);
X	    return;
X	}
X    }
X
X    return;
X
X    /*
X    XGetErrorText(dpy, event->error_code, buffer, BUFSIZ);
X    (void) fprintf(stderr, "X Error: %s\n", buffer);
X    (void) fprintf(stderr, "  Request Major code: %d\n", event->request_code);
X    (void) fprintf(stderr, "  Request Minor code: %d\n", event->minor_code);
X    (void) fprintf(stderr, "  ResourceId 0x%x\n", event->resourceid);
X    (void) fprintf(stderr, "  Error Serial #%d\n", event->serial);
X    (void) fprintf(stderr, "  Current Serial #%d\n", dpy->request);
X
X    Done();
X    */
X}
X
X/***********************************************************************
X *
X *  Procedure:
X *	Other - error handler called if something else has set 
X *		the attributes on the root window.  Typically
X *		another window manager.
X *
X ***********************************************************************
X */
X
Xvoid
XOther(dpy, event)
XDisplay *dpy;
XXErrorEvent *event;
X{
X    fprintf(stderr, "twm: Are you running another window manager?\n");
X    exit(1);
X}
SHAR_EOF
if test 15921 -ne "`wc -c < twm.c`"
then
    echo shar: error transmitting "twm.c" '(should have been 15921 characters)'
fi
fi
# end of shell archive
exit 0