home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
unix
/
volume15
/
twm
/
part01
/
twm.c
< prev
Wrap
C/C++ Source or Header
|
1988-06-12
|
11KB
|
371 lines
/*****************************************************************************/
/** Copyright 1988 by Evans & Sutherland Computer Corporation, **/
/** Salt Lake City, Utah **/
/** **/
/** All Rights Reserved **/
/** **/
/** Permission to use, copy, modify, and distribute this software and **/
/** its documentation for any purpose and without fee is hereby **/
/** granted, provided that the above copyright notice appear in all **/
/** copies and that both that copyright notice and this permis- **/
/** sion notice appear in supporting documentation, and that the **/
/** name of Evans & Sutherland not be used in advertising or publi- **/
/** city pertaining to distribution of the software without specif- **/
/** ic, written prior permission. **/
/** **/
/** EVANS & SUTHERLAND DISCLAIMS ALL WARRANTIES WITH REGARD TO **/
/** THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILI- **/
/** TY AND FITNESS, IN NO EVENT SHALL EVANS & SUTHERLAND BE LIABLE **/
/** FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAM- **/
/** AGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, **/
/** WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS **/
/** ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PER- **/
/** FORMANCE OF THIS SOFTWARE. **/
/*****************************************************************************/
/***********************************************************************
*
* $Header: twm.c,v 1.23 88/04/15 07:09:30 tlastran Exp $
*
* twm - "Tom's Window Manager"
*
* 27-Oct-87 Thomas E. LaStrange File created
*
***********************************************************************/
#ifndef lint
static char RCSinfo[] =
"$Header: twm.c,v 1.23 88/04/15 07:09:30 tlastran Exp $";
#endif
#include <stdio.h>
#include <signal.h>
#include <fcntl.h>
#include "twm.h"
#include "add_window.h"
#include "gc.h"
#include "parse.h"
#include "version.h"
#include "menus.h"
#include "events.h"
#include "util.h"
#include "twm.bm"
TwmWindow TwmRoot; /* the head of the twm window list */
Display *dpy; /* which display are we talking to */
Window Root; /* the root window */
Window VersionWindow; /* the twm version window */
Window SizeWindow; /* the resize dimensions window */
Window ResizeWindow; /* the window we are resizing */
XFontStruct *TitleBarFont; /* title bar font structure */
XFontStruct *MenuFont; /* menu font structure */
XFontStruct *IconFont; /* icon font structure */
XFontStruct *SizeFont; /* resize font structure */
XFontStruct *VersionFont; /* version font structure */
char *TitleBarFontName = "8x13";/* default title bar font */
char *MenuFontName = "8x13"; /* default menu font */
char *IconFontName = "8x13"; /* default icon font */
char *SizeFontName = "fg-22"; /* default resize font */
char *VersionFontName = "8x13"; /* default version font */
int TitleBarFontHeight; /* height of title bar font */
int MenuFontHeight; /* height of menu font */
int IconFontHeight; /* height of icon font */
int SizeFontHeight; /* height of resize font */
int VersionFontHeight; /* height of version font */
Cursor ArrowCursor; /* title bar cursor */
Cursor ButtonCursor; /* title bar button cursor */
Cursor MoveCursor; /* move and resize cursor */
Cursor ClockCursor; /* wait a while cursor */
Cursor RightArrowCursor; /* menu cursor */
GC TitleNormalGC; /* GC for title bar */
GC MenuNormalGC; /* normal GC for menus */
GC MenuReverseGC; /* reverse video GC for menus */
GC MenuXorGC; /* XOR GC for menus */
GC IconNormalGC; /* GC for icons */
GC VersionNormalGC; /* GC for the version window */
GC SizeNormalGC; /* GC for the resize window */
GC DrawGC; /* GC to draw lines for move and resize */
XContext TwmContext; /* context for twm windows */
XContext MenuContext; /* context for all menu windows */
int BorderWidth = BW; /* border width of twm windows */
unsigned long Foreground; /* foreground color for all windows */
unsigned long Background; /* background color for all windows */
char Version[100]; /* place to build the version string */
Pixmap UnknownPm = NULL; /* the unknown icon pixmap */
int UnknownWidth = 0; /* width of the unknown icon */
int UnknownHeight = 0; /* height of the unknown icon */
int FirstTime = TRUE; /* first time we've read .twmrc */
int ReverseVideo = FALSE; /* flag to do reverse video */
int FocusRoot = TRUE; /* is the input focus on the root ? */
TwmWindow *Focus = NULL; /* the twm window that has focus */
int WarpCursor = FALSE; /* warp cursor on de-iconify ? */
int ParseError; /* error parsing the .twmrc file */
int TitleButton[MAX_BUTTONS + 1]; /* title button functions */
int TitleBarY; /* y coordinate to start text in the title */
int TitleBarX = TITLE_BAR_HEIGHT + 4; /* x coordinate ditto */
int MenuY; /* y coordiante for text in menus */
Window JunkRoot; /* junk window */
Window JunkChild; /* junk window */
int JunkX; /* junk variable */
int JunkY; /* junk variable */
int JunkWidth; /* junk variable */
int JunkHeight; /* junk variable */
int JunkDepth; /* junk variable */
int JunkBW; /* junk variable */
int JunkMask; /* junk variable */
/***********************************************************************
*
* Procedure:
* main - start of twm
*
***********************************************************************
*/
main(argc, argv)
int argc;
char *argv[];
{
Window root, parent, *children;
int nchildren, i;
int m, d, y;
char *display_name;
unsigned long valuemask; /* mask for create windows */
XSetWindowAttributes attributes; /* attributes for create windows */
display_name = NULL;
if (argc != 1 && argc != 3)
{
fprintf(stderr, "Usage: twm [-display display]\n");
exit(1);
}
if (argc == 3)
{
if (strncmp(argv[1], "-d", 2) == 0)
display_name = argv[2];
else
{
fprintf(stderr, "Usage: twm [-display display]\n");
exit(1);
}
}
signal(SIGINT, Done);
signal(SIGQUIT, Done);
signal(SIGHUP, Done);
signal(SIGTERM, Done);
TwmRoot.next = NULL;
TwmRoot.prev = NULL;
TwmRoot.w = NULL;
TwmRoot.title_w = NULL;
TwmRoot.iconify_w = NULL;
TwmRoot.resize_w = NULL;
if ((dpy = XOpenDisplay(display_name)) == NULL)
{
fprintf(stderr, "twm: can't open the display\n");
exit(1);
}
if (fcntl(ConnectionNumber(dpy), F_SETFD, 1) == -1)
{
fprintf(stderr, "twm: child cannot disinherit TCP fd\n");
exit(1);
}
Root = RootWindow(dpy, DefaultScreen(dpy));
XSetErrorHandler(Other);
XSelectInput(dpy, Root,
SubstructureRedirectMask |
ButtonPressMask | ButtonReleaseMask |
ExposureMask | ButtonMotionMask);
XSync(dpy, 0);
XSetErrorHandler(Error);
XSetInputFocus(dpy, Root, RevertToPointerRoot, CurrentTime);
TwmContext = XUniqueContext();
MenuContext = XUniqueContext();
/* define cursors */
ArrowCursor = XCreateFontCursor(dpy, XC_top_left_arrow);
MoveCursor = XCreateFontCursor(dpy, XC_fleur);
RightArrowCursor = XCreateFontCursor(dpy, XC_sb_right_arrow);
ButtonCursor = XCreateFontCursor(dpy, XC_center_ptr);
ClockCursor = XCreateFontCursor(dpy, XC_watch);
XGrabServer(dpy);
XSync(dpy, 0);
XQueryTree(dpy, Root, &root, &parent, &children, &nchildren);
ParseTwmrc(NULL);
FirstTime = FALSE;
CreateGCs();
for (i = 0; i < nchildren; i++)
{
if (MappedNotOverride(children[i]))
{
AddWindow(children[i]);
}
}
/* contruct the version string */
sprintf(Version, "%s", &Revision[1]);
Version[strlen(Version) - 1] = '\0';
sscanf(&Date[7], "%d/%d/%d", &y, &m, &d);
sprintf(Version, "%s Date: %d/%d/%d %s", Version, m, d, y, &Date[16]);
Version[strlen(Version) - 2] = '\0';
VersionWindow = XCreateSimpleWindow(dpy, Root,
0, 0,
twm_width + XTextWidth(VersionFont, Version, strlen(Version)) + 20,
VersionFontHeight + 4,
BW,
Foreground, Background);
valuemask = CWBackPixmap;
attributes.background_pixmap = MakePixmap(VersionWindow, TitleNormalGC,
twm_bits, twm_width, twm_height);
XCreateWindow(dpy, VersionWindow,
4, 1,
twm_width, twm_height,
0, DefaultDepth(dpy, 0), CopyFromParent, DefaultVisual(dpy, 0),
valuemask, &attributes);
XSelectInput(dpy, VersionWindow, ExposureMask);
XMapSubwindows(dpy, VersionWindow);
XMapWindow(dpy, VersionWindow);
SizeWindow = XCreateSimpleWindow(dpy, Root,
0, 0,
100,
SizeFontHeight + 4,
BW,
Foreground, Background);
XUngrabServer(dpy);
HandleEvents();
}
/***********************************************************************
*
* Procedure:
* Done - cleanup and exit twm
*
* Returned Value:
* none
*
* Inputs:
* none
*
* Outputs:
* none
*
* Special Considerations:
* none
*
***********************************************************************
*/
void
Done()
{
TwmWindow *tmp; /* temp twm window structure */
unsigned x, y;
XWindowChanges xwc; /* change window structure */
unsigned int xwcm; /* change window mask */
/* put a border back around all windows */
for (tmp = TwmRoot.next; tmp != NULL; tmp = tmp->next)
{
XGetGeometry(dpy, tmp->w, &JunkRoot, &x, &y, &JunkWidth, &JunkHeight,
&JunkBW, &JunkDepth);
xwcm = CWX | CWY | CWBorderWidth;
xwc.x = x - (2 * BorderWidth);
xwc.y = y - (2 * BorderWidth);
xwc.border_width = BorderWidth;
XConfigureWindow(dpy, tmp->w, xwcm, &xwc);
}
XSetInputFocus(dpy, Root, RevertToPointerRoot, CurrentTime);
XCloseDisplay(dpy);
exit(0);
}
/***********************************************************************
*
* Procedure:
* Error - X error handler. Print the error and exit.
*
* Inputs:
* dpy - the connection to the X server
* event - the error event structure
*
***********************************************************************
*/
void
Error(dpy, event)
Display *dpy;
XErrorEvent *event;
{
char buffer[BUFSIZ];
XGetErrorText(dpy, event->error_code, buffer, BUFSIZ);
(void) fprintf(stderr, "X Error: %s\n", buffer);
(void) fprintf(stderr, " Request Major code: %d\n", event->request_code);
(void) fprintf(stderr, " Request Minor code: %d\n", event->minor_code);
(void) fprintf(stderr, " ResourceId 0x%x\n", event->resourceid);
(void) fprintf(stderr, " Error Serial #%d\n", event->serial);
(void) fprintf(stderr, " Current Serial #%d\n", dpy->request);
Done();
}
/***********************************************************************
*
* Procedure:
* Other - error handler called if something else has set
* the attributes on the root window. Typically
* another window manager.
*
***********************************************************************
*/
void
Other(dpy, event)
Display *dpy;
XErrorEvent *event;
{
fprintf(stderr, "twm: Are you running another window manager?\n");
exit(1);
}