mikew@wyse.wyse.com (Mike Wexler) (09/23/88)
Submitted-by: toml%hpfctel@sde.hp.com (Tom LaStrange) Posting-number: Volume 1, Issue 48 Archive-name: twm/part03 #! /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 7)." # Contents: gram.y resize.c util.c # Wrapped by mikew@wyse on Thu Sep 22 16:21:22 1988 PATH=/bin:/usr/bin:/usr/ucb ; export PATH if test -f 'gram.y' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'gram.y'\" else echo shar: Extracting \"'gram.y'\" \(11423 characters\) sed "s/^X//" >'gram.y' <<'END_OF_FILE' 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.32 88/09/08 15:33:52 toml 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.32 88/09/08 15:33:52 toml 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 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 DEFAULT_FUNCTION 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 F_BEEP 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 NO_HILITE X%token <num> MENU_FONT ICON_FONT UNKNOWN_ICON ICONS ICON_DIRECTORY X%token <num> META SHIFT CONTROL WINDOW TITLE ICON ROOT FRAME 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 NO_TITLE_FOCUS FUNCTION F_FUNCTION X%token <num> BORDER_TILE_FOREGROUND BORDER_TILE_BACKGROUND 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 | NO_TITLE_FOCUS { if (FirstTime) TitleFocus = FALSE; } 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 | string full { AddFuncKey($1, cont, mods, X $2, Action); X Action = ""; X pull = NULL; X cont = 0; X mods = 0; 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_HILITE { list = NO_HILITE; } X win_list X | NO_HILITE { Highlight = FALSE; } 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 | FUNCTION string { root = GetRoot($2); } X function X | ICONS { list = ICONS; } X icon_list X | COLOR { color = COLOR; } X color_list X | MONOCHROME { color = MONOCHROME; } X color_list X | DEFAULT_FUNCTION action { DefaultFunction.func = $2; X if ($2 == F_MENU) X { X pull->prev = NULL; X DefaultFunction.menu = pull; X } X else X { X root = GetRoot(TWM_ROOT); X DefaultFunction.item = X AddToMenu(root,"x",Action,0,$2); X } X Action = ""; X pull = NULL; X } 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 | FRAME { cont = C_FRAME; } 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 | BORDER_TILE_FOREGROUND string { GetColor(color, X &BorderTileForeground, $2); } X | BORDER_TILE_BACKGROUND string { GetColor(color, X &BorderTileBackground, $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 Xfunction : LB function_entries RB X ; X Xfunction_entries: /* Empty */ X | function_entries function_entry X ; X Xfunction_entry : action { AddToMenu(root, "", Action, NULL, $1); X Action = ""; 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_BEEP { $$ = F_BEEP; } 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 | F_FUNCTION string { Action = $2; $$ = F_FUNCTION; } 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 END_OF_FILE if test 11423 -ne `wc -c <'gram.y'`; then echo shar: \"'gram.y'\" unpacked with wrong size! fi # end of 'gram.y' fi if test -f 'resize.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'resize.c'\" else echo shar: Extracting \"'resize.c'\" \(14937 characters\) sed "s/^X//" >'resize.c' <<'END_OF_FILE' 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: resize.c,v 1.17 88/09/06 12:10:04 toml Exp $ X * X * window resizing borrowed from the "wm" window manager X * X * 11-Dec-87 Thomas E. LaStrange File created X * X ***********************************************************************/ X X#ifndef lint Xstatic char RCSinfo[]= X"$Header: resize.c,v 1.17 88/09/06 12:10:04 toml Exp $"; X#endif X X#include <stdio.h> X#include "twm.h" X#include "util.h" X#include "resize.h" X#include "add_window.h" X#include "resize.bm" X#ifndef NOFOCUS X#include "focus.bm" X#else X#define focus_width 0 X#endif X X#define MINHEIGHT 32 X#define MINWIDTH 60 X Xstatic int dragx; /* all these variables are used */ Xstatic int dragy; /* in resize operations */ Xstatic int dragWidth; Xstatic int dragHeight; X Xstatic int origx; Xstatic int origy; Xstatic int origWidth; Xstatic int origHeight; X Xstatic int clampTop; Xstatic int clampBottom; Xstatic int clampLeft; Xstatic int clampRight; X Xstatic int last_width; Xstatic int last_height; X X/*********************************************************************** X * X * Procedure: X * StartResize - begin a window resize operation X * X * Inputs: X * ev - the event structure (button press) X * tmp_win - the TwmWindow pointer X * X *********************************************************************** X */ X Xvoid XStartResize(ev, tmp_win) XXEvent ev; XTwmWindow *tmp_win; X{ X Window junkRoot; X int junkbw, junkDepth; X X ResizeWindow = tmp_win->frame; X XGrabServer(dpy); X XGrabPointer(dpy, ev.xbutton.root, True, X ButtonReleaseMask, X GrabModeAsync, GrabModeSync, X Root, MoveCursor, CurrentTime); X X XGetGeometry(dpy, (Drawable) tmp_win->frame, &junkRoot, X &dragx, &dragy, &dragWidth, &dragHeight, &junkbw, X &junkDepth); X dragx += BorderWidth; X dragy += BorderWidth; X origx = dragx; X origy = dragy; X origWidth = dragWidth; X origHeight = dragHeight; X clampTop = clampBottom = clampLeft = clampRight = 0; X X XMoveWindow(dpy, SizeWindow, 0, 0); X XMapRaised(dpy, SizeWindow); X last_width = 0; X last_height = 0; X DisplaySize(tmp_win, origWidth, origHeight); X} X X/*********************************************************************** X * X * Procedure: X * AddStartResize - begin a window resize operation from AddWindow X * X * Inputs: X * tmp_win - the TwmWindow pointer X * X *********************************************************************** X */ X Xvoid XAddStartResize(tmp_win, x, y, w, h) XTwmWindow *tmp_win; Xint x, y, w, h; X{ X Window junkRoot; X int junkbw, junkDepth; X X XGrabServer(dpy); X XGrabPointer(dpy, Root, True, X ButtonReleaseMask, X GrabModeAsync, GrabModeSync, X Root, MoveCursor, CurrentTime); X X dragx = x + BorderWidth; X dragy = y + BorderWidth; X origx = dragx; X origy = dragy; X dragWidth = origWidth = w - 2 * BorderWidth; X dragHeight = origHeight = h - 2 * BorderWidth; X clampTop = clampBottom = clampLeft = clampRight = 0; X X XMoveWindow(dpy, SizeWindow, 0, InitialFontHeight + 4 + BW); X XMapRaised(dpy, SizeWindow); X last_width = 0; X last_height = 0; X DisplaySize(tmp_win, origWidth, origHeight); X} X X/*********************************************************************** X * X * Procedure: X * DoResize - move the rubberband around. This is called for X * each motion event when we are resizing X * X * Inputs: X * x_root - the X corrdinate in the root window X * y_root - the Y corrdinate in the root window X * tmp_win - the current twm window X * X *********************************************************************** X */ X Xvoid XDoResize(x_root, y_root, tmp_win) Xint x_root; Xint y_root; XTwmWindow *tmp_win; X{ X int action; X X action = 0; X X if (clampTop) { X int delta = y_root - dragy; X if (dragHeight - delta < MINHEIGHT) { X delta = dragHeight - MINHEIGHT; X clampTop = 0; X } X dragy += delta; X dragHeight -= delta; X action = 1; X } X else if (y_root <= dragy/* || X y_root == findRootInfo(root)->rooty*/) { X dragy = y_root; X dragHeight = origy + origHeight - X y_root; X clampBottom = 0; X clampTop = 1; X action = 1; X } X if (clampLeft) { X int delta = x_root - dragx; X if (dragWidth - delta < MINWIDTH) { X delta = dragWidth - MINWIDTH; X clampLeft = 0; X } X dragx += delta; X dragWidth -= delta; X action = 1; X } X else if (x_root <= dragx/* || X x_root == findRootInfo(root)->rootx*/) { X dragx = x_root; X dragWidth = origx + origWidth - X x_root; X clampRight = 0; X clampLeft = 1; X action = 1; X } X if (clampBottom) { X int delta = y_root - dragy - dragHeight; X if (dragHeight + delta < MINHEIGHT) { X delta = MINHEIGHT - dragHeight; X clampBottom = 0; X } X dragHeight += delta; X action = 1; X } X else if (y_root >= dragy + dragHeight - 1/* || X y_root == findRootInfo(root)->rooty X + findRootInfo(root)->rootheight - 1*/) { X dragy = origy; X dragHeight = 1 + y_root - dragy; X clampTop = 0; X clampBottom = 1; X action = 1; X } X if (clampRight) { X int delta = x_root - dragx - dragWidth; X if (dragWidth + delta < MINWIDTH) { X delta = MINWIDTH - dragWidth; X clampRight = 0; X } X dragWidth += delta; X action = 1; X } X else if (x_root >= dragx + dragWidth - 1/* || X x_root == findRootInfo(root)->rootx + X findRootInfo(root)->rootwidth - 1*/) { X dragx = origx; X dragWidth = 1 + x_root - origx; X clampLeft = 0; X clampRight = 1; X action = 1; X } X if (action) { X MoveOutline(Root, X dragx - BorderWidth, X dragy - BorderWidth, X dragWidth + 2 * BorderWidth, X dragHeight + 2 * BorderWidth); X } X X DisplaySize(tmp_win, dragWidth, dragHeight); X} X X/*********************************************************************** X * X * Procedure: X * DisplaySize - display the size in the dimensions window X * X * Inputs: X * tmp_win - the current twm window X * width - the width of the rubber band X * height - the height of the rubber band X * X *********************************************************************** X */ X Xvoid XDisplaySize(tmp_win, width, height) XTwmWindow *tmp_win; Xint width; Xint height; X{ X char str[100]; X int dwidth; X int dheight; X X if (last_width == width && last_height == height) X return; X X last_width = width; X last_height = height; X X dwidth = width; X dheight = height - tmp_win->title_height; X X if (tmp_win->hints.flags&PMinSize && tmp_win->hints.flags & PResizeInc) X { X dwidth -= tmp_win->hints.min_width; X dheight -= tmp_win->hints.min_height; X } X X if (tmp_win->hints.flags & PResizeInc) X { X dwidth /= tmp_win->hints.width_inc; X dheight /= tmp_win->hints.height_inc; X } X X sprintf(str, "%d x %d", dwidth, dheight); X X width = XTextWidth(SizeFont, str, strlen(str)) + 20; X strcat(str, " "); X XResizeWindow(dpy, SizeWindow, width, SizeFontHeight + 4); X XRaiseWindow(dpy, SizeWindow); X XDrawImageString(dpy, SizeWindow, SizeNormalGC, X 10, 2 + SizeFont->ascent, str, strlen(str)); X} X X/*********************************************************************** X * X * Procedure: X * EndResize - finish the resize operation X * X *********************************************************************** X */ X Xvoid XEndResize() X{ X TwmWindow *tmp_win; X Window w; X X#ifdef DEBUG X fprintf(stderr, "EndResize\n"); X#endif X X XUnmapWindow(dpy, SizeWindow); X MoveOutline(Root, 0, 0, 0, 0); X X XFindContext(dpy, ResizeWindow, TwmContext, &tmp_win); X X dragHeight = dragHeight - tmp_win->title_height; X X if (tmp_win->hints.flags&PMinSize && tmp_win->hints.flags & PResizeInc) X { X dragWidth -= tmp_win->hints.min_width; X dragHeight -= tmp_win->hints.min_height; X } X X if (tmp_win->hints.flags & PResizeInc) X { X dragWidth /= tmp_win->hints.width_inc; X dragHeight /= tmp_win->hints.height_inc; X X dragWidth *= tmp_win->hints.width_inc; X dragHeight *= tmp_win->hints.height_inc; X } X X if (tmp_win->hints.flags&PMinSize && tmp_win->hints.flags & PResizeInc) X { X dragWidth += tmp_win->hints.min_width; X dragHeight += tmp_win->hints.min_height; X } X X dragHeight = dragHeight + tmp_win->title_height; X X SetupWindow(tmp_win, X dragx - BorderWidth, X dragy - BorderWidth, X dragWidth, dragHeight); X X#ifdef SUN386 X /* This is a kludge to fix a problem in the Sun 386 server which X * causes windows to not be repainted after a resize operation. X */ X w = XCreateSimpleWindow(dpy, tmp_win->frame, X 0, 0, 9999, 9999, 0, Black, Black); X X XMapWindow(dpy, w); X XDestroyWindow(dpy, w); X XFlush(dpy); X#endif X X if (!NoRaiseResize) X XRaiseWindow(dpy, tmp_win->frame); X X ResizeWindow = NULL; X SetHints(tmp_win); X} X X/*********************************************************************** X * X * Procedure: X * AddEndResize - finish the resize operation for AddWindow X * X *********************************************************************** X */ X Xvoid XAddEndResize(tmp_win) XTwmWindow *tmp_win; X{ X X#ifdef DEBUG X fprintf(stderr, "AddEndResize\n"); X#endif X X XUnmapWindow(dpy, SizeWindow); X X dragHeight = dragHeight - tmp_win->title_height; X X if (tmp_win->hints.flags&PMinSize && tmp_win->hints.flags & PResizeInc) X { X dragWidth -= tmp_win->hints.min_width; X dragHeight -= tmp_win->hints.min_height; X } X X if (tmp_win->hints.flags & PResizeInc) X { X dragWidth /= tmp_win->hints.width_inc; X dragHeight /= tmp_win->hints.height_inc; X X dragWidth *= tmp_win->hints.width_inc; X dragHeight *= tmp_win->hints.height_inc; X } X X if (tmp_win->hints.flags&PMinSize && tmp_win->hints.flags & PResizeInc) X { X dragWidth += tmp_win->hints.min_width; X dragHeight += tmp_win->hints.min_height; X } X X AddingX = dragx; X AddingY = dragy; X AddingW = dragWidth + (2 * BorderWidth); X AddingH = dragHeight + tmp_win->title_height + (2 * BorderWidth); X} X X/*********************************************************************** X * X * Procedure: X * SetupWindow - set window sizes, this was called from either X * AddWindow, EndResize, or HandleConfigureNotify. X * X * Inputs: X * tmp_win - the TwmWindow pointer X * x - the x coordinate of the frame window X * y - the y coordinate of the frame window X * w - the width of the frame window X * h - the height of the frame window X * X * Special Considerations: X * This routine will check to make sure the window is not completely X * off the display, if it is, it'll bring some of it back on. X * X *********************************************************************** X */ X Xvoid XSetupWindow(tmp_win, x, y, w, h) XTwmWindow *tmp_win; Xint x, y, w, h; X{ X XWindowChanges xwc; X unsigned int xwcm; X int width; X X#ifdef DEBUG X fprintf(stderr, "SetupWindow: x=%d, y=%d, w=%d, h=%d\n", X x, y, w, h); X#endif X X if (x > MyDisplayWidth) X x = MyDisplayWidth - 64; X if (y > MyDisplayHeight) X y = MyDisplayHeight - 64; X X tmp_win->frame_x = x; X tmp_win->frame_y = y; X tmp_win->frame_width = w; X tmp_win->frame_height = h; X X XMoveResizeWindow(dpy, tmp_win->frame, x, y, w, h); X X xwcm = CWWidth; X xwc.width = w; X XConfigureWindow(dpy, tmp_win->title_w, xwcm, &xwc); X X tmp_win->attr.width = w; X tmp_win->attr.height = h - tmp_win->title_height; X X XMoveResizeWindow(dpy, tmp_win->w, 0, tmp_win->title_height, w, X h - tmp_win->title_height); X X xwcm = CWX; X xwc.x = w - resize_width - 1; X XConfigureWindow(dpy, tmp_win->resize_w, xwcm, &xwc); X X xwc.x = w - resize_width - focus_width - 3; X#ifndef NOFOCUS X XConfigureWindow(dpy, tmp_win->focus_w, xwcm, &xwc); X#endif X X width = w - TitleBarX - focus_width - resize_width - 5 - X tmp_win->name_width - 10; X X if (width <= 0) X { X xwc.x = MyDisplayWidth; X xwc.width = 1; X } X else X { X xwc.x = TitleBarX + tmp_win->name_width + 6; X xwc.width = width; X } X X xwcm = CWX | CWWidth; X XConfigureWindow(dpy, tmp_win->hilite_w, xwcm, &xwc); X} X X/*********************************************************************** X * X * Procedure: X * SetHints - set window hints so that if twm is killed the windows X * will start up in the same places they were at when twm was X * killed. X * X * Inputs: X * tmp_win - the TwmWindow pointer X * X *********************************************************************** X */ X Xvoid XSetHints(tmp_win) XTwmWindow *tmp_win; X{ X XWMHints wmhints; X XSizeHints hints; X int x, y, w, h; X X /* X wmhints = *(tmp_win->wmhints); X X if (tmp_win->icon) X wmhints.initial_state = IconicState; X else X wmhints.initial_state = NormalState; X X XGetGeometry(dpy, tmp_win->icon_w, &JunkRoot, &x, &y, &w, &h, X &JunkBW, &JunkDepth); X wmhints.icon_x = x; X wmhints.icon_y = y; X X wmhints.flags |= (StateHint | IconPositionHint); X XSetWMHints(dpy, tmp_win->w, &wmhints); X */ X X XGetGeometry(dpy, tmp_win->frame, &JunkRoot, &x, &y, &w, &h, X &JunkBW, &JunkDepth); X hints = tmp_win->hints; X hints.x = x; X hints.y = y + tmp_win->title_height; X hints.width = w; X hints.height = h - tmp_win->title_height; X X hints.flags |= (USPosition | USSize); X XSetNormalHints(dpy, tmp_win->w, &hints); X} END_OF_FILE if test 14937 -ne `wc -c <'resize.c'`; then echo shar: \"'resize.c'\" unpacked with wrong size! fi # end of 'resize.c' fi if test -f 'util.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'util.c'\" else echo shar: Extracting \"'util.c'\" \(12155 characters\) sed "s/^X//" >'util.c' <<'END_OF_FILE' 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: util.c,v 1.21 88/06/17 07:15:25 tlastran Exp $ X * X * utility routines for twm X * X * 28-Oct-87 Thomas E. LaStrange File created X * X ***********************************************************************/ X X#ifndef lint Xstatic char RCSinfo[]= X"$Header: util.c,v 1.21 88/06/17 07:15:25 tlastran Exp $"; X#endif X X#include <stdio.h> X#include "twm.h" X#include "util.h" X#include "gram.h" X X#define ZOOM_COUNT 8 /* number of outlines to draw while zooming */ X X/*********************************************************************** X * X * Procedure: X * MoveOutline - move a window outline X * X * Inputs: X * root - the window we are outlining X * x - upper left x coordinate X * y - upper left y coordinate X * width - the width of the rectangle X * height - the height of the rectangle X * X *********************************************************************** X */ X Xvoid XMoveOutline(root, x, y, width, height) X Window root; X int x, y, width, height; X{ X static int lastx = 0; X static int lasty = 0; X static int lastWidth = 0; X static int lastHeight = 0; X int xl, xr, yt, yb; X int xthird, ythird; X XSegment outline[16]; X XSegment *r = outline; X X if (x == lastx && y == lasty && width == lastWidth && height == lastHeight) X return; X X xthird = lastWidth/3; X ythird = lastHeight/3; X xl = lastx; X xr = lastx + lastWidth - 1; X yt = lasty; X yb = lasty + lastHeight - 1; X X if (lastWidth || lastHeight) X { X r->x1 = xl; X r->y1 = yt; X r->x2 = xr; X r++->y2 = yt; X X r->x1 = xl; X r->y1 = yb; X r->x2 = xr; X r++->y2 = yb; X X r->x1 = xl; X r->y1 = yt; X r->x2 = xl; X r++->y2 = yb; X X r->x1 = xr; X r->y1 = yt; X r->x2 = xr; X r++->y2 = yb; X X r->x1 = xl + xthird; X r->y1 = yt; X r->x2 = r->x1; X r++->y2 = yb; X X r->x1 = xl + (2 * xthird); X r->y1 = yt; X r->x2 = r->x1; X r++->y2 = yb; X X r->x1 = xl; X r->y1 = yt + ythird; X r->x2 = xr; X r->y2 = r->y1; X r++; X X r->x1 = xl; X r->y1 = yt + (2 * ythird); X r->x2 = xr; X r->y2 = r->y1; X r++; X } X X lastx = x; X lasty = y; X lastWidth = width; X lastHeight = height; X xthird = lastWidth/3; X ythird = lastHeight/3; X xl = lastx; X xr = lastx + lastWidth - 1; X yt = lasty; X yb = lasty + lastHeight - 1; X X if (lastWidth || lastHeight) X { X r->x1 = xl; X r->y1 = yt; X r->x2 = xr; X r++->y2 = yt; X X r->x1 = xl; X r->y1 = yb; X r->x2 = xr; X r++->y2 = yb; X X r->x1 = xl; X r->y1 = yt; X r->x2 = xl; X r++->y2 = yb; X X r->x1 = xr; X r->y1 = yt; X r->x2 = xr; X r++->y2 = yb; X X r->x1 = xl + xthird; X r->y1 = yt; X r->x2 = r->x1; X r++->y2 = yb; X X r->x1 = xl + (2 * xthird); X r->y1 = yt; X r->x2 = r->x1; X r++->y2 = yb; X X r->x1 = xl; X r->y1 = yt + ythird; X r->x2 = xr; X r->y2 = r->y1; X r++; X X r->x1 = xl; X r->y1 = yt + (2 * ythird); X r->x2 = xr; X r->y2 = r->y1; X r++; X } X if (r != outline) X { X XDrawSegments(dpy, root, DrawGC, outline, r - outline); X } X} X X/*********************************************************************** X * X * Procedure: X * Zoom - zoom in or out of an icon X * X * Inputs: X * wf - window to zoom from X * wt - window to zoom to X * X *********************************************************************** X */ X Xvoid XZoom(wf, wt) X{ X int fx, fy, fw, fh; X int tx, ty, tw, th; X int xl, yt, xr, yb; X int dx, dy, dw, dh; X int w, h, i; X XSegment outline[4]; X X if (!DoZoom) X return; X X XGetGeometry(dpy, wf, &JunkRoot, &fx, &fy, &fw, &fh, &JunkBW, &JunkDepth); X XGetGeometry(dpy, wt, &JunkRoot, &tx, &ty, &tw, &th, &JunkBW, &JunkDepth); X X dx = (tx - fx) / ZOOM_COUNT; X dy = (ty - fy) / ZOOM_COUNT; X dw = (tw - fw) / ZOOM_COUNT; X dh = (th - fh) / ZOOM_COUNT; X X xl = fx; X yt = fy; X xr = fx + fw; X yb = fy + fh; X w = fw; X h = fh; X X for (i = 0; i < ZOOM_COUNT; i++) X { X outline[0].x1 = xl; X outline[0].y1 = yt; X outline[0].x2 = xr; X outline[0].y2 = yt; X X outline[1].x1 = xr; X outline[1].y1 = yt; X outline[1].x2 = xr; X outline[1].y2 = yb; X X outline[2].x1 = xr; X outline[2].y1 = yb; X outline[2].x2 = xl; X outline[2].y2 = yb; X X outline[3].x1 = xl; X outline[3].y1 = yb; X outline[3].x2 = xl; X outline[3].y2 = yt; X X XDrawSegments(dpy, Root, DrawGC, outline, 4); X X w += dw; X h += dh; X xl += dx; X yt += dy; X xr = xl + w; X yb = yt + h; X } X X xl = fx; X yt = fy; X xr = fx + fw; X yb = fy + fh; X w = fw; X h = fh; X X for (i = 0; i < ZOOM_COUNT; i++) X { X outline[0].x1 = xl; X outline[0].y1 = yt; X outline[0].x2 = xr; X outline[0].y2 = yt; X X outline[1].x1 = xr; X outline[1].y1 = yt; X outline[1].x2 = xr; X outline[1].y2 = yb; X X outline[2].x1 = xr; X outline[2].y1 = yb; X outline[2].x2 = xl; X outline[2].y2 = yb; X X outline[3].x1 = xl; X outline[3].y1 = yb; X outline[3].x2 = xl; X outline[3].y2 = yt; X X XDrawSegments(dpy, Root, DrawGC, outline, 4); X X w += dw; X h += dh; X xl += dx; X yt += dy; X xr = xl + w; X yb = yt + h; X } X} X X/*********************************************************************** X * X * Procedure: X * MakeCenteredPixmap - make a pixmap centered in a space X * X * Returned Value: X * pid - the pixmap id X * X * Inputs: X * w - the window to associate the pixmap with X * gc - the graphics context to use X * width - the width of the pixmap to create X * height - the height of the pixmap to create X * data - pointer to the pixmap data X * pwidth - the width of the pixmap X * pheight - the height of the pixmap X * X *********************************************************************** X */ X XPixmap XMakeCenteredPixmap(w, gc, width, height, data, pwidth, pheight) X Drawable w; X GC gc; X int width, height; X short *data; X int pwidth, pheight; X{ X XImage ximage; X Pixmap pid; X int dx, dy; X X pid = XCreatePixmap(dpy, w, width, height, d_depth); X X ximage.height = pheight; X ximage.width = pwidth; X ximage.xoffset = 0; X ximage.format = XYBitmap; X ximage.data = (char *) data; X ximage.byte_order = LSBFirst; X ximage.bitmap_unit = 16; X ximage.bitmap_bit_order = LSBFirst; X ximage.bitmap_pad = 16; X ximage.bytes_per_line = (pwidth + 15) / 16 * 2; X ximage.depth = 1; X X dx = (width - pwidth) / 2; X dy = (height - pheight) / 2; X X XPutImage(dpy, pid, gc, &ximage, 0, 0, dx, dy, pwidth, pheight); X return (pid); X} X X/*********************************************************************** X * X * Procedure: X * MakePixmap - make a pixmap X * X * Returned Value: X * pid - the pixmap id X * X * Inputs: X * w - the window to associate the pixmap with X * gc - the graphics context to use X * data - pointer to the pixmap data X * width - the width of the pixmap X * height - the height of the pixmap X * X *********************************************************************** X */ X XPixmap XMakePixmap(w, gc, data, width, height) X Drawable w; X GC gc; X short *data; X int width, height; X{ X return MakeCenteredPixmap(w, gc, width, height, data, width, height); X} X X/*********************************************************************** X * X * Procedure: X * ExpandFilename - expand the tilde character to HOME X * if it is the first character of the filename X * X * Returned Value: X * a pointer to the new name X * X * Inputs: X * name - the filename to expand X * X *********************************************************************** X */ X Xchar * XExpandFilename(name) Xchar *name; X{ X char *newname; X X if (name[0] != '~') X return (name); X X newname = (char *)malloc(HomeLen + strlen(name) + 2); X sprintf(newname, "%s/%s", Home, &name[1]); X X return (newname); X} X X/*********************************************************************** X * X * Procedure: X * GetUnknownIcon - read in the bitmap file for the unknown icon X * X * Inputs: X * name - the filename to read X * X *********************************************************************** X */ X Xvoid XGetUnknownIcon(name) Xchar *name; X{ X UnknownPm = GetBitmap(name); X if (UnknownPm != NULL) X { X XGetGeometry(dpy, UnknownPm, &JunkRoot, &JunkX, &JunkY, X &UnknownWidth, &UnknownHeight, &JunkBW, &JunkDepth); X } X} X X/*********************************************************************** X * X * Procedure: X * GetBitmap - read in a bitmap file X * X * Returned Value: X * the pixmap associated with the bitmap X * X * Inputs: X * name - the filename to read X * X *********************************************************************** X */ X XPixmap XGetBitmap(name) Xchar *name; X{ X char *bigname; X int status, junk_hotx, junk_hoty; X Pixmap pm; X X if (name == NULL) X return (NULL); X X name = ExpandFilename(name); X bigname = name; X X status = XReadBitmapFile(dpy, Root, bigname, &JunkWidth, X &JunkHeight, &pm, &junk_hotx, &junk_hoty); X X if (status != BitmapSuccess && IconDirectory && name[0] != '/') X { X bigname = (char *)malloc(strlen(name) + strlen(IconDirectory) + 2); X sprintf(bigname, "%s/%s", IconDirectory, name); X status = XReadBitmapFile(dpy, Root, bigname, &JunkWidth, X &JunkHeight, &pm, &junk_hotx, &junk_hoty); X } X X if (status != BitmapSuccess && name[0] != '/') X { X bigname = (char *)malloc(strlen(name) + strlen(BITMAPS) + 2); X sprintf(bigname, "%s/%s", BITMAPS, name); X status = XReadBitmapFile(dpy, Root, bigname, &JunkWidth, X &JunkHeight, &pm, &junk_hotx, &junk_hoty); X } X X switch(status) X { X case BitmapSuccess: X break; X X case BitmapFileInvalid: X fprintf(stderr, ".twmrc: invalid bitmap file \"%s\"\n", bigname); X break; X X case BitmapNoMemory: X fprintf(stderr, ".twmrc: out of memory \"%s\"\n", bigname); X break; X X case BitmapOpenFailed: X fprintf(stderr, ".twmrc: failed to open bitmap file \"%s\"\n", X bigname); X break; X X default: X fprintf(stderr,".twmrc: bitmap error = 0x%x on file \"%s\"\n", X status, bigname); X break; X } X X if (status != BitmapSuccess) X return (NULL); X X return (pm); X} X Xint XGetColor(kind, what, name) Xint kind; Xint *what; Xchar *name; X{ X XColor color, junkcolor; X X if (!FirstTime) X return; X X if (Monochrome != kind) X return; X X if (!XParseColor(dpy, CMap, name, &color)) X { X fprintf(stderr, "twm: invalid color \"%s\"\n", name); X return; X } X X if (!XAllocColor(dpy, CMap, &color)) X { X fprintf(stderr, "twm: invalid color \"%s\"\n", name); X return; X } X X *what = color.pixel; X} END_OF_FILE if test 12155 -ne `wc -c <'util.c'`; then echo shar: \"'util.c'\" unpacked with wrong size! fi # end of 'util.c' fi echo shar: End of archive 3 \(of 7\). cp /dev/null ark3isdone MISSING="" for I in 1 2 3 4 5 6 7 ; do if test ! -f ark${I}isdone ; then MISSING="${MISSING} ${I}" fi done if test "${MISSING}" = "" ; then echo You have unpacked all 7 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 -- Mike Wexler(wyse!mikew) Phone: (408)433-1000 x1330