mikew@wyse.wyse.com (Mike Wexler) (08/10/88)
Submitted-by: jkh@ardent (Jordan Hubbard) Posting-number: Volume 0, Issue 9 Archive-name: awm/part08 #! /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 8 (of 13)." # Contents: awm/Titlebar.c awm/awm.h # Wrapped by mikew@wyse on Mon Aug 8 12:01:46 1988 PATH=/bin:/usr/bin:/usr/ucb ; export PATH if test -f awm/Titlebar.c -a "${1}" != "-c" ; then echo shar: Will not over-write existing file \"awm/Titlebar.c\" else echo shar: Extracting \"awm/Titlebar.c\" \(18459 characters\) sed "s/^X//" >awm/Titlebar.c <<'END_OF_awm/Titlebar.c' X#ident "%W% %G%" X X X X#ifndef lint Xstatic char *rcsid_TitleBar_c = "$Header: TitleBar.c,v 1.4 88/07/24 01:26:00 jkh Exp $"; X#endif lint X X#include "X11/copyright.h" X/* X * X * Copyright 1987, 1988 by Ardent Computer Corporation, Sunnyvale, Ca. X * X * Copyright 1987 by Jordan Hubbard. X * X * X * All Rights Reserved X * X * Permission to use, copy, modify, and distribute this software and its X * documentation for any purpose and without fee is hereby granted, X * provided that the above copyright notice appear in all copies and that X * both that copyright notice and this permission notice appear in X * supporting documentation, and that the name of Ardent Computer X * Corporation or Jordan Hubbard not be used in advertising or publicity X * pertaining to distribution of the software without specific, written X * prior permission. X * X */ X X/* X * MODIFICATION HISTORY X * X * 002 -- Jordan Hubbard, U.C. Berkeley. X Title bar support routines. X * 1.2 -- Fairly major restructuring to uncouple title bars and X * border contexts. X * 1.3 -- Handling of colors revamped significantly to deal with X * different colormaps. X */ X X#include "awm.h" X#include "X11/Xutil.h" X#include "X11/cursorfont.h" X Xint TB_wide, TB_high, TBB_wide, TBB_high, BC_wide, BC_high; Xint BCB_wide, BCB_high; X Xextern XContext AwmContext; X X#define BLANK_WIDE 16 X#define BLANK_HIGH 16 Xstatic char blank_bits[] = { X 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, X 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, X 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; X Xstatic Boolean Title_res, Frame_res; X Xvoid Init_Titles() X{ X TFontInfo = GetFontRes("title.font", DEF_TITLE_FONT); X TFontBoldInfo = GetFontRes("title.boldFont", NULL); X TBackPixmapData = GetPixmapDataRes("title.pixmap", &TB_wide, &TB_high); X TBoldPixmapData = GetPixmapDataRes("title.boldPixmap", &TBB_wide, X &TBB_high); X TForeground = GetStringRes("title.foreground", Foreground); X TBackground = GetStringRes("title.background", Background); X TTextForeground = GetStringRes("title.text.foreground", TForeground); X TTextBackground = GetStringRes("title.text.background", TBackground); X X TCursor = GetIntRes("title.cursor", DEF_TITLE_CURSOR); X X TitleHeight = GetIntRes("title.height", 0); X TitlePad = GetIntRes("title.pad", DEF_TITLE_PAD); X NameOffset = GetIntRes("windowName.offset", 0); X titleHeight = TFontInfo->max_bounds.ascent + X TFontInfo->max_bounds.descent + (TitlePad * 2); X /* we've specified a bold pixmap, but no back pixmap. Use blank. */ X if (TBoldPixmapData && !TBackPixmapData) { X TBackPixmapData = blank_bits; X TB_wide = BLANK_WIDE; X TB_high = BLANK_HIGH; X } X if (TFontBoldInfo) { X int foo; X X foo = TFontBoldInfo->max_bounds.ascent + X TFontBoldInfo->max_bounds.descent + (TitlePad * 2); X if (foo > titleHeight) X titleHeight = foo; X } X if (titleHeight < gadgetHeight) X titleHeight = gadgetHeight; X if (TitleHeight) /* Specified height overrides derived height */ X titleHeight = TitleHeight; X TitleCursor = XCreateFontCursor(dpy, TCursor); X if (!TitleCursor) X Error("Init_Titles: Can't get title cursor #%d!\n", TCursor); X /* Gadgets can't exist without titles, so we'll init them here */ X GadgetPad = GetIntRes("gadget.pad", DEF_GADGET_PAD); X GadgetBorder = GetIntRes("gadget.border", DEF_GADGET_BORDER); X X Title_res = TRUE; X} X Xvoid Init_Frames() X{ X int t_wide, t_high, junk; X register char *cp; X X Entry("Init_Frames") X X BForeground = GetStringRes("borderContext.foreground", Foreground); X BBackground = GetStringRes("borderContext.background", Background); X X BCursor = GetIntRes("borderContext.cursor", DEF_BCONTEXT_CURSOR); X X BBackPixmapData = GetPixmapDataRes("borderContext.pixmap", &BC_wide, X &BC_high); X BBoldPixmapData = GetPixmapDataRes("borderContext.boldPixmap", &BCB_wide, X &BCB_high); X /* we've specified a bold BC pixmap, but no back pixmap. Use blank. */ X if (BBoldPixmapData && !BBackPixmapData) { X BBackPixmapData = blank_bits; X BC_wide = BLANK_WIDE; X BC_high = BLANK_HIGH; X } X FrameCursor = XCreateFontCursor(dpy, BCursor); X if (!FrameCursor) X Error("Init_Frames: Can't get border cursor #%d!\n", BCursor); X Frame_res = TRUE; X Leave_void X} X Xchar *GetTitleName(w) XWindow w; X{ X char *cp = 0, *tmp; X X Entry("GetTitleName") X X if (!XFetchName(dpy, w, &cp) || !cp) X cp = "Untitled Window"; X tmp = (char *)malloc(strlen(cp) + 3); X X /* X * We add a space on both ends for asthetic effect X * (only apparent if we're using inverse video). X */ X tmp[0] = ' '; X strcpy(tmp + 1, cp); X strcat(tmp, " "); X free(cp); X Leave(tmp) X} X X/* X * Reparent window 'w' into a frame, making the frame the right X * size to hold any other window related decorations that may be X * added later. If window 'w' already has a frame, then it resizes X * it if necessary. X */ XWindow Reparent(w) XWindow w; X{ X Window foster; X XWindowAttributes xwa; X XSetWindowAttributes swa; X XWMHints *wm_hints; X XSizeHints sz_hints; X XClassHint class_hints; X AwmInfoPtr awi; X char *icon_name; X int bch, bcv, x, y, bw, width, height; X int clnt_x, clnt_y; X unsigned long valuemask; X Boolean decorated = FALSE; X Colormap cmap; X Pixel bfore, bback; X X Entry("Reparent") X X awi = GetAwmInfo(w); X if (!awi) { X fprintf(stderr, "Reparent: Window %x isn't registered!\n", w); X Leave((Window)NULL) X } X if (awi->frame && (awi->state & ST_DECORATED)) X Leave((Window)NULL) X X if (!Frame_res) X Init_Frames(); X X if (awi->attrs & AT_TITLE && !Title_res) X Init_Titles(); X X if (!awi->frame) X XGetWindowAttributes(dpy, awi->client, &xwa); X else X XGetWindowAttributes(dpy, awi->frame, &xwa); X valuemask = CWEventMask | CWBorderPixel | CWBackPixel | CWColormap; X swa.event_mask = (SubstructureRedirectMask | SubstructureNotifyMask); X bw = xwa.border_width; X x = xwa.x; X y = xwa.y; X height = xwa.height; X width = xwa.width; X cmap = xwa.colormap; X bfore = GetPixel(BForeground, cmap); X bback = GetPixel(BBackground, cmap); X clnt_y = clnt_x = 0; X if (awi->attrs & AT_BORDER) { X XSetWindowAttributes cswa; X X swa.event_mask |= (ButtonPressMask | ButtonReleaseMask); X bcv = BContext + 1; X bch = bcv * 2; X X cswa.do_not_propagate_mask = X (ButtonPressMask | ButtonReleaseMask); X XChangeWindowAttributes(dpy, awi->client, CWDontPropagate, &cswa); X } X else X bch = bcv = 0; X if (FrameFocus) X swa.event_mask |= (LeaveWindowMask | EnterWindowMask); X if (awi->attrs & AT_BORDER) { X swa.background_pixel = bfore; X swa.border_pixel = bback; X decorated = TRUE; X } X else if (awi->attrs & AT_TITLE) { X swa.background_pixel = GetPixel(TBackground, cmap); X swa.border_pixel = GetPixel(TForeground, cmap); X } X else { X swa.background_pixel = GetPixel(Background, cmap); X swa.border_pixel = GetPixel(Foreground, cmap); X } X swa.colormap = cmap; X if (PushDown == FALSE) { X if (awi->attrs & AT_TITLE) X y -= (titleHeight + 2); X else if (awi->attrs & AT_BORDER) X y -= BContext; X } X /* calculate size for frame */ X if (awi->attrs & AT_TITLE) X height += titleHeight + 2; X if (awi->attrs & AT_BORDER) { X if (!(awi->attrs & AT_TITLE)) X height += (bcv * 2); X else X height += bcv; X width += bch; X } X if (awi->attrs & AT_TITLE) X clnt_y = titleHeight + 2; X X if (awi->attrs & AT_BORDER) { X if (!(awi->attrs & AT_TITLE)) X clnt_y = BContext; X clnt_x = BContext; X } X X if (!awi->frame) { X foster = XCreateWindow(dpy, RootWindow(dpy, scr), x, y, width, X height, (bw ? bw : 1), xwa.depth, xwa.class, X xwa.visual, valuemask, &swa); X if (!foster) X Error("Reparent: Can't create foster parent!"); X X if (awi->attrs & AT_BORDER) X XDefineCursor(dpy, foster, FrameCursor); X X XAddToSaveSet(dpy, awi->client); X XSetWindowBorderWidth(dpy, awi->client, X ((awi->attrs & AT_BORDER) ? 1 : 0)); X XReparentWindow(dpy, awi->client, foster, clnt_x, clnt_y); X XMapWindow(dpy, awi->client); X XSync(dpy, FALSE); X X if (BBackPixmapData) { /* we have a border context tile */ X awi->BC_back = GetPixmapFromCache(foster, X BBackPixmapData, X BC_wide, BC_high, X bfore, bback, X xwa.depth); X if (!awi->BC_back) X Error("Reparent: Can't get pixmap for border context."); X else X XSetWindowBackgroundPixmap(dpy, foster, awi->BC_back); X } X if (BBoldPixmapData) { /* we have a bold border context tile */ X awi->BC_bold = GetPixmapFromCache(foster, X BBoldPixmapData, X BCB_wide, BCB_high, X bfore, bback, X xwa.depth); X if (!awi->BC_bold) X Error("Reparent: Can't get bold pixmap for border context."); X } X awi->frame = foster; X awi->border_width = bw; X awi->name = GetTitleName(awi->client); X X /* Make titlebar "frame" inherit characteristics of victim */ X XStoreName(dpy, foster, awi->name); X if (XGetIconName(dpy, w, &icon_name)) { X XSetIconName(dpy, foster, icon_name); X free(icon_name); X } X if (wm_hints = XGetWMHints(dpy, awi->client)) { X XSetWMHints(dpy, foster, wm_hints); X XFree(wm_hints); X } X XGetNormalHints(dpy, awi->client, &sz_hints); X XSetNormalHints(dpy, foster, &sz_hints); X XGetZoomHints(dpy, awi->client, &sz_hints); X XSetZoomHints(dpy, foster, &sz_hints); X class_hints.res_name = class_hints.res_class = (char *)NULL; X if (XGetClassHint(dpy, awi->client, &class_hints) == Success) X XSetClassHint(dpy, foster, &class_hints); X X XSaveContext(dpy, foster, AwmContext, awi); X } X else { X XMoveResizeWindow(dpy, awi->frame, xwa.x, xwa.y, width, height); X XMoveWindow(dpy, awi->client, clnt_x, clnt_y); X if (awi->attrs & AT_BORDER) X decorated = TRUE; X foster = awi->frame; X } X if (decorated) X awi->state |= ST_DECORATED; X Leave(foster) X} X Xvoid AddTitle(w) XWindow w; X{ X int bch, bcv; X Window title; X AwmInfoPtr awi; X unsigned long valuemask; X XWindowAttributes xwa; X XSetWindowAttributes swa; X XWindowChanges wc; X Pixel tfore, tback; X X Entry("AddTitle") X X awi = GetAwmInfo(w); X X if (!awi) { X fprintf(stderr, "AddTitle: Window %x is not registered!\n", w); X Leave_void X } X if (!awi->frame) X Leave_void X if (awi->title) X Leave_void X if (!(awi->attrs & AT_TITLE)) X Leave_void X X XGetWindowAttributes(dpy, awi->client, &xwa); X swa.event_mask = (ExposureMask | ButtonPressMask | ButtonReleaseMask); X swa.colormap = xwa.colormap; X tfore = GetPixel(TForeground, xwa.colormap); X tback = GetPixel(TBackground, xwa.colormap); X swa.background_pixel = tback; X swa.border_pixel = tfore; X valuemask = (CWEventMask | CWColormap | CWBackPixel | CWBorderPixel); X if (awi->attrs & AT_BORDER) X bch = (BContext * 2) + 2; X else X bch = 0; X title = XCreateWindow(dpy, awi->frame, 0, 0, (xwa.width - 2) + bch, X titleHeight, X 1, xwa.depth, xwa.class, xwa.visual, X valuemask, &swa); X if (!title) X Error("AddTitle: Can't create title bar!"); X if (TBackPixmapData) { X awi->back = GetPixmapFromCache(title, TBackPixmapData, X TB_wide, TB_high, X tfore, tback, X xwa.depth); X if (!awi->back) X Error("AddTitle: Can't create pixmap for title background"); X else X XSetWindowBackgroundPixmap(dpy, title, awi->back); X } X if (TBoldPixmapData) { X awi->bold = GetPixmapFromCache(title, TBoldPixmapData, X TBB_wide, TBB_high, X tfore, tback, X xwa.depth); X if (!awi->bold) X Error("AddTitle: Can't create pixmap for bold background"); X } X wc.sibling = awi->client; X wc.stack_mode = Above; X XConfigureWindow(dpy, title, CWSibling|CWStackMode, &wc); X XDefineCursor(dpy, title, TitleCursor); X XSelectInput(dpy, title, (ExposureMask | ButtonPressMask | X ButtonReleaseMask)); X XMapWindow(dpy, title); X awi->title = title; X awi->state |= ST_DECORATED; X XSaveContext(dpy, title, AwmContext, awi); X} X XBoolean FNoDecorate(w, mask, button, x, y) XWindow w; Xint mask, button, x, y; X{ X Entry("FNoDecorate") X X if (w == RootWindow(dpy, scr)) X Leave(FALSE) X NoDecorate(w, FALSE); X Leave(TRUE) X} X Xvoid NoDecorate(w, destroy) XWindow w; XBoolean destroy; X{ X XWindowAttributes xwa; X AwmInfoPtr awi; X X Entry("NoDecorate") X X awi = GetAwmInfo(w); X if (!awi || !awi->frame) X Leave_void X X if (!(awi->state & ST_DECORATED)) X Leave_void X if (awi->gadgets) X DestroyGadgets(w); X if (awi->title) { X XDeleteContext(dpy, awi->title, AwmContext); X if (awi->back) X FreePixmapFromCache(awi->back); X if (awi->bold) X FreePixmapFromCache(awi->bold); X XDestroyWindow(dpy, awi->title); X awi->title = awi->back = awi->bold = (Drawable)NULL; X } X if (destroy) { X XDeleteContext(dpy, awi->frame, AwmContext); X if (awi->BC_back) X FreePixmapFromCache(awi->BC_back); X if (awi->BC_bold) X FreePixmapFromCache(awi->BC_bold); X free(awi->name); X awi->name = (char *)NULL; X XDestroyWindow(dpy, awi->frame); X awi->frame = awi->BC_back = awi->BC_bold = (Drawable)NULL; X } X else { X XGetWindowAttributes(dpy, awi->client, &xwa); X XResizeWindow(dpy, awi->frame, xwa.width, xwa.height); X XMoveWindow(dpy, awi->client, 0, 0); X awi->state ^= ST_DECORATED; X } X XSync(dpy, FALSE); X Leave_void X} X XBoolean FDecorate(window, mask, button, x, y) XWindow window; Xint mask; Xint button; Xint x, y; X{ X Window fr; X X Entry("FDecorate") X X if (window == RootWindow(dpy, scr)) X Leave(FALSE) X fr = Decorate(window); X if (fr) X XMapWindow(dpy, fr); X XSync(dpy, FALSE); X Leave(FALSE) X} X XWindow Decorate(w) XWindow w; X{ X Window ret; X AwmInfoPtr awi; X X Entry("Decorate") X X ret = Reparent(w); X if (ret) { X AddTitle(ret); X PutGadgets(ret); X } X Leave(ret) X} X Xvoid PaintTitle(w, reversed) XWindow w; XBoolean reversed; X{ X static GC gc, rgc; X int x, y, ijunk; X XWindowAttributes xwa; X Window junk, chld; X XFontStruct *f_info; X AwmInfoPtr awi; X XGCValues gcv; X Colormap cmap; X X Entry("PaintTitle") X X if (!(awi = IsTitled(w))) X Leave_void X XGetWindowAttributes(dpy, awi->title, &xwa); X cmap = xwa.colormap; X if (reversed && TFontBoldInfo) X f_info = TFontBoldInfo; X else X f_info = TFontInfo; X gcv.font = f_info->fid; X gcv.foreground = (reversed && !TFontBoldInfo) ? X GetPixel(TTextBackground, cmap) : GetPixel(TTextForeground, cmap); X gcv.background = (reversed && !TFontBoldInfo) ? X GetPixel(TTextForeground, cmap) : GetPixel(TTextBackground, cmap); X XChangeGC(dpy, awi->winGC, (GCFont | GCForeground | GCBackground), &gcv); X XClearWindow(dpy, awi->title); X if (ShowName) { /* print window names? */ X int textlen; X X textlen = XTextWidth(f_info, awi->name, strlen(awi->name)); X X if (!NameOffset) X x = (xwa.width - textlen) / 2; X else { X if (NameOffset < 0) X x = (xwa.width - textlen) + NameOffset; X else X x = NameOffset; X if (x + textlen > xwa.width) X x = (xwa.width - textlen) + 1; X } X y = (xwa.height + f_info->max_bounds.ascent - X f_info->max_bounds.descent) / 2; X X XDrawImageString(dpy, awi->title, awi->winGC, x, y, awi->name, X strlen(awi->name)); X } X Leave_void X} X XAwmInfoPtr IsTitled(w) XWindow w; X{ X AwmInfoPtr tmp; X X Entry("IsTitled") X X if (tmp = GetAwmInfo(w)) X if (tmp->title) X Leave(tmp) X Leave((AwmInfoPtr)NULL) X} X X/* X * These routines deal with a sort of "pixmap cache" that is needed X * to minimize the number of pixmaps created by awm. Awm operates on the X * assumption that the user may have an arbitrary number of windows at X * arbitrary depths. Since awm likes to create resources at the same X * depth as the client window, some sort of mechanism is needed to insure X * that as few are created as possible. X */ X Xstruct _resInfo { X struct _resInfo *next; X Drawable res; X char *res_data; X Pixel res_fore, res_back; X int res_depth; X int ref_count; X} *CacheHead; X Xstruct _resInfo *allocResNode() X{ X struct _resInfo *ptr; X X Entry("allocResNode") X X ptr = (struct _resInfo *)malloc(sizeof(struct _resInfo)); X if (!ptr) X fprintf(stderr, "allocResNode: Out of memory!\n"); X Leave(ptr) X} X X/* X * Look for pixmap in cache and returns it or allocate new pixmap, X * store it in cache and return it. X */ XDrawable GetPixmapFromCache(d, data, wide, high, fore, back, depth) XDrawable d; Xchar *data; Xint wide, high; XPixel fore, back; Xint depth; X{ X struct _resInfo *cptr, *iptr; X X cptr = iptr = CacheHead; X while (cptr) { X if (cptr->res_depth > depth) X break; X if (cptr->res_depth == depth) { X if (cptr->res_data > data) X break; X else if (cptr->res_data == data) { X if (cptr->res_fore == fore && cptr->res_back == back) { X cptr->ref_count++; X Leave(cptr->res) X } X } X } X iptr = cptr; X cptr = cptr->next; X } X /* fell through, create another resource */ X if (!iptr || cptr == CacheHead) /* need to initialize list */ X CacheHead = iptr = allocResNode(); X else { X iptr->next = allocResNode(); X iptr = iptr->next; X } X iptr->next = cptr; X iptr->res_depth = depth; X iptr->res_data = data; X iptr->res_fore = fore; X iptr->res_back = back; X iptr->res = XCreatePixmapFromBitmapData(dpy, d, data, wide, high, X fore, back, depth); X iptr->ref_count = 1; X Leave(iptr->res) X} X X/* X * Free pixmap (and associated cache cell) if no longer needed. X */ Xvoid FreePixmapFromCache(pix) XPixmap pix; X{ X struct _resInfo *ptr, *tmp; X X ptr = tmp = CacheHead; X while (ptr) { X if (ptr->res == pix) X break; X tmp = ptr; X ptr = ptr->next; X } X if (!ptr) X Leave_void X if (--ptr->ref_count == 0) { /* last ref */ X if (ptr == CacheHead) X CacheHead = CacheHead->next; X else X tmp->next = ptr->next; X XFreePixmap(dpy, ptr->res); X free(ptr); X } X} END_OF_awm/Titlebar.c if test 18459 -ne `wc -c <awm/Titlebar.c`; then echo shar: \"awm/Titlebar.c\" unpacked with wrong size! fi # end of overwriting check fi if test -f awm/awm.h -a "${1}" != "-c" ; then echo shar: Will not over-write existing file \"awm/awm.h\" else echo shar: Extracting \"awm/awm.h\" \(21364 characters\) sed "s/^X//" >awm/awm.h <<'END_OF_awm/awm.h' X#ident "%W% %G%" X X X X#ifndef lint Xstatic char *rcsid_awm_h = "$Header: awm.h,v 1.2 88/07/23 17:26:00 jkh Exp $"; X#endif lint X X#include "X11/copyright.h" X/* X * X * Copyright 1987, 1988 by Ardent Computer Corporation, Sunnyvale, Ca. X * X * Copyright 1987 by Jordan Hubbard. X * X * X * All Rights Reserved X * X * Permission to use, copy, modify, and distribute this software and its X * documentation for any purpose and without fee is hereby granted, X * provided that the above copyright notice appear in all copies and that X * both that copyright notice and this permission notice appear in X * supporting documentation, and that the name of Ardent Computer X * Corporation or Jordan Hubbard not be used in advertising or publicity X * pertaining to distribution of the software without specific, written X * prior permission. X * X */ X X/* X * Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts. X * X * All Rights Reserved X * X * Permission to use, copy, modify, and distribute this software and its X * documentation for any purpose and without fee is hereby granted, X * provided that the above copyright notice appear in all copies and that X * both that copyright notice and this permission notice appear in X * supporting documentation, and that the name of Digital Equipment X * Corporation not be used in advertising or publicity pertaining to X * distribution of the software without specific, written prior permission. X * X * X * DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING X * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL X * DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR X * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, X * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, X * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS X * SOFTWARE. X */ X X X X/* X * MODIFICATION HISTORY X * X * 000 -- M. Gancarz, DEC Ultrix Engineering Group X * 001 -- R. Kittell, DEC Storage A/D May 19, 1986 X * Added global vars for warp options. X * 002 -- Loretta Guarino Reid, DEC Ultrix Engineering Group, X * Western Software Lab, Port to X11 X * 003 -- Jordan Hubbard, Ardent Computer X * Many additional declarations for awm. X */ X X#include <errno.h> X#include <stdio.h> X#include <strings.h> X#include "X11/Xlib.h" X#include "X11/Intrinsic.h" X#include "X11/Xatom.h" X#include "menus/rtlmenu.h" X#include "support.h" X X#define MIN(x, y) ((x) <= (y) ? (x) : (y)) X#define MAX(x, y) ((x) >= (y) ? (x) : (y)) X#define VOLUME_PERCENTAGE(x) ((x)*14) X#define ModMask 0xFF X#define ButtonMask(b) (((b)==Button1) ? Button1Mask : \ X (((b)==Button2) ? Button2Mask : Button3Mask)) X X#define DEF_DELTA 1 X#define DEF_FUNC GXcopy X#define DEF_ICON_BORDER_WIDTH 2 X#define DEF_ICON_PAD 4 X#define DEF_POP_BORDER_WIDTH 2 X#define DEF_POP_PAD 4 X#define DEF_MENU_BORDER_WIDTH 2 X#define DEF_MENU_PAD 4 X#define DEF_GADGET_PAD 3 X#define DEF_GADGET_BORDER 1 X#define DEF_TITLE_PAD 2 X#define DEF_VOLUME 4 X#define DEF_PUSH 5 X#define DEF_BCONTEXT_WIDTH 0 X#define DEF_RAISE_DELAY 100 /* milliseconds */ X#define DEF_MAX_COLORS 0 /* 0 means take as many as we can */ X#ifndef DEF_BCONTEXT_CURSOR X#define DEF_BCONTEXT_CURSOR XC_plus X#endif DEF_BCONTEXT_CURSOR X#ifndef DEF_TITLE_CURSOR X#define DEF_TITLE_CURSOR XC_left_ptr X#endif DEF_TITLE_CURSOR X#ifndef NAME X#define NAME "awm" X#endif NAME X#ifndef CLASS X#define CLASS "Wm" X#endif CLASS X#ifndef DEF_FONT X#define DEF_FONT "fixed" X#endif DEF_FONT X#ifndef DEF_TITLE_FONT X#define DEF_TITLE_FONT "vtsingle" X#endif DEF_TITLE_FONT X#ifndef DEF_ICON_FONT X#define DEF_ICON_FONT "8x13" X#endif DEF_ICON_FONT X#ifndef DEF_POPUP_FONT X#define DEF_POPUP_FONT "9x15" X#endif DEF_POPUP_FONT X#ifndef DEF_GADGET_FONT X#define DEF_GADGET_FONT "fixed" X#endif DEF_GADGET_FONT X#ifndef DEF_MENU_FONT X#define DEF_MENU_FONT "8x13" X#endif DEF_MENU_FONT X#ifndef DEF_BOLD_FONT X#define DEF_BOLD_FONT "8x13bold" X#endif DEF_BOLD_FONT X#define DEF_MENU_DELTA 20 X X#define INIT_PTEXT {'0', '0', '0', 'x', '0', '0', '0'} X X#ifndef TEMPFILE X#define TEMPFILE "/tmp/awm.XXXXXX" X#endif TEMPFILE X X#define CURSOR_WIDTH 16 X#define CURSOR_HEIGHT 16 X X#define MAX_ZAP_VECTORS 8 X#define MAX_BOX_VECTORS 20 X X#define DRAW_WIDTH 0 /* use fastest hardware draw */ X#define DRAW_VALUE 0xfd X#define DRAW_FUNC GXxor X#define DRAW_PLANES 1 X X#define NOCOLOR -1 X X/* X * The first BITS_USED bits of the mask are used to define the most generic X * types. All other bits are free for storing peripheral information. X * For now, we use the extra bits to specify which gadget(s) are bound X * to an action. MAX_GADGETS depends on BITS_USED to determine the maximum X * number of gadgets possible. If you add a new context type, be sure to X * increment BITS_USED. X */ X#define ROOT 0x1 X#define WINDOW 0x2 X#define ICON 0x4 X#define TITLE 0x8 X#define BORDER 0x10 X#define GADGET 0x20 X X#define BITS_USED 6 X X/* Window states */ X#define ST_WINDOW 0x1 X#define ST_ICON 0x2 X#define ST_PLACED 0x4 X#define ST_DECORATED 0x8 X X/* Window attributes */ X#define AT_NONE 0x0 X#define AT_TITLE 0x1 X#define AT_GADGETS 0x2 X#define AT_RAISE 0x4 X#define AT_BORDER 0x8 X#define AT_INPUT 0x10 X X/* X * Gadgets aren't the sort of embellishments that one uses in quantitity X * (unless one is designing a truly odd interface), so we keep the information X * in an array instead of using the usual linked list. MAX_GADGETS is a derived X * macro (see BITS_USED) that is used to determine the size of the X * Array. X * X */ X#define MAX_GADGETS ((sizeof(int) * 8) - BITS_USED) X X#ifndef FAILURE X#define FAILURE 0 X#endif FAILURE X X#define NAME_LEN 256 /* Maximum length string names */ X#define EVENTMASK (ButtonPressMask | ButtonReleaseMask) X X X#define DrawBox() XDrawSegments(dpy, RootWindow(dpy, scr),DrawGC,box,num_vectors) X#define DrawZap() XDrawSegments(dpy, RootWindow(dpy, scr),DrawGC,zap,num_vectors) X X#define gray_width 16 X#define gray_height 16 Xextern char gray_bits[]; X X#define solid_width 16 X#define solid_height 16 Xextern char solid_bits[]; X X/* X * All one needs to know about an awm managed window.. (so far...) X */ Xtypedef struct _awminfo { X Window title, client, frame, icon; /* Associated windows */ X Window *gadgets; /* associated gadgets */ X char *name; /* The formatted window name */ X Boolean own; /* Do we own the icon window? */ X Pixmap back, bold, iconPixmap; /* background, bold and icon pix */ X Pixmap BC_back, BC_bold; /* BC back and bold pixmaps */ X unsigned int border_width; /* original border width */ X int state; /* The state of the window */ X int attrs; /* Window "attributes" */ X GC winGC; /* GC at proper depth for window */ X} AwmInfo, *AwmInfoPtr; X X/* X * This whole section has changed substantially. Basically, since all the X * variables have vanished into the resource manager, the keyword table X * only needs to keep track of function pointers, boolean pointers and X * "special" keywords like menu and gagdet. Since some things are still X * modifiable from menus (only booleans, currently, though this will change), X * we keep these in the keyword table even though X * they're no longer directly modifable from the .awmrc X */ X X/* X * Keyword table entry. X */ Xtypedef struct _keyword { X char *name; X int type; X Boolean *bptr; X Boolean (*fptr)(); X} Keyword; X X/* X * Keyword table type entry. X */ X#define IsFunction 1 X#define IsMenuMap 2 X#define IsMenu 3 X#define IsDownFunction 4 X#define IsParser 5 X#define IsQuitFunction 6 X#define IsGadget 7 X#define IsBoolean 8 X#define IsAction 9 X X/* X * Button/key binding type. X */ Xtypedef struct _binding { X struct _binding *next; X int context; X int mask; X int button; X Boolean (*func)(); X char *menuname; X RTLMenu menu; X} Binding; X X/* X * Key expression type. X */ Xtypedef struct _keyexpr { X char *name; X int mask; X} KeyExpr; X X/* X * Context expression type. X */ Xtypedef struct _contexpr { X char *name; X int mask; X} ContExpr; X X/* X * Button modifier type. X */ Xtypedef struct _buttonmodifier { X char *name; X int mask; X} ButtonModifier; X X/* X * Gravity expression type. X */ Xtypedef struct _gravityexpr { X char *name; X int mask; X} GravityExpr; X X/* X * Button modifier mask definitions. X * bits 13 and 14 unused in key masks, according to X.h X * steal bit 15, since we don't use AnyModifier X */ X X#define DeltaMotion (1<<13) X#define ButtonUp (1<<14) X#define ButtonDown AnyModifier X#define ButtonMods DeltaMotion+ButtonUp+ButtonDown X X/* X * Button and mask redefinitions, for X11 X */ X#define LeftMask Button1Mask X#define MiddleMask Button2Mask X#define RightMask Button3Mask X#define LeftButton Button1 X#define MiddleButton Button2 X#define RightButton Button3 X X/* X * Declaration specific information for gadgets. This defines only gadget X * types, not the actual gadgets. The pixmap member is only used if a pixmap X * is being displayed. Gravity and offset are purely optional. X */ X X#define NoGadgetGravity 0 X#define LeftGadgetGravity 1 X#define RightGadgetGravity 2 X#define CenterGadgetGravity 3 X Xtypedef struct _gadgetdecl { /* Declaration (type) information */ X unsigned char *name; /* Either text label or pixmap file name */ X unsigned char *data; /* If pixmap file, this is the data from it */ X char *forecolor; /* foreground color for pixmap */ X char *backcolor; /* background color for pixmap */ X XFontStruct *fontInfo; /* font for text */ X int high, wide; /* width and height of pixmap or text */ X int gravity; /* stick to the left or right? */ X int offset; /* offset from previous item */ X} GadgetDecl; X X/* X * MenuInfo data type. X */ Xtypedef struct _menuinfo { X char *name; /* Name of this menu. */ X char *pixmapname; /* Name of label pixmap (opt) */ X RTLMenu menu; /* RTL menu handle for destroy */ X struct _actionline *line; /* Linked list of menu items. */ X} MenuInfo; X X/* X * Action Line data type. X */ Xtypedef struct _actionline { X struct _actionline *next; /* Pointer to next line. */ X char *name; /* Name of this line. */ X char *pixmapname; /* Name of the backing pixmap (opt) */ X int type; /* IsShellCommand, IsText, IsTextNL... */ X RTLMenuItem item; /* RTL item handle */ X char *text; /* Text string to be acted upon. */ X Boolean (*func)(); /* Window manager function to be invoked. */ X} ActionLine; X X/* X * ActionLine->type definitions. X */ X#define IsShellCommand 1 X#define IsText 2 X#define IsTextNL 3 X#define IsUwmFunction 4 X#define IsMenuFunction 5 X#define IsImmFunction 6 /* Immediate (context-less) function. */ X#define IsVar 7 /* we're setting a boolean variable */ X X/* X * Menu Link data type. Used by the parser when creating a linked list X * of menus. X */ Xtypedef struct _menulink { X struct _menulink *next; /* Pointer to next MenuLink. */ X struct _menuinfo *menu; /* Pointer to the menu in this link. */ X} MenuLink; X X/* X * External variable definitions. X */ Xextern int errno; Xextern Window Pop; /* Pop-up dimension display window. */ Xextern Window Frozen; /* Contains window id of "gridded" window. */ Xextern XFontStruct *IFontInfo; /* Icon text font information. */ Xextern XFontStruct *PFontInfo; /* Pop-up text font information. */ Xextern XFontStruct *TFontInfo; /* Title text font information. */ Xextern XFontStruct *TFontBoldInfo;/* Title text (bold) font information. */ Xextern XFontStruct *GFontInfo; /* Gadget box text font */ Xextern XFontStruct *MFontInfo; /* Menu font */ Xextern XFontStruct *MBoldFontInfo;/* Menu bold font */ Xextern Pixmap GrayPixmap; /* Gray pixmap. */ Xextern Pixmap SolidPixmap; Xextern Pixmap IBackPixmap; /* Icon window background pixmap. */ Xextern char *BForeground; /* Border Context (pixmap) foreground pixel */ Xextern char *BBackground; /* Border Context (pixmap) background pixel */ Xextern char *WBorder; /* Window border pixel */ Xextern char *TTextForeground; /* Title text foreground pixel */ Xextern char *TTextBackground; /* Title text background pixel */ Xextern char *TForeground; /* Title (pixmap) foreground pixel */ Xextern char *TBackground; /* Title (pixmap) background pixel */ Xextern char *Foreground; /* default forground color (text) */ Xextern char *Background; /* default background color (text) */ Xextern Pixel IBorder; /* Icon window border pixel. */ Xextern Pixel ITextForeground; /* Icon window text forground color. */ Xextern Pixel ITextBackground; /* Icon window text background color. */ Xextern Pixel IForeground; /* Icon pixmap foreground color */ Xextern Pixel IBackground; /* Icon pixmap background color */ Xextern Pixel PForeground; /* Pop-up window forground color. */ Xextern Pixel PBackground; /* Pop-up window background color. */ Xextern Pixel PBorder; /* Pop-Up Window border pixel. */ Xextern Pixel ForeColor; /* default foreground color */ Xextern Pixel BackColor; /* default background color */ Xextern Pixel MBorder; /* Menu border color */ Xextern Pixel MForeground; /* Menu foreground color */ Xextern Pixel MBackground; /* Menu background color */ Xextern Cursor ArrowCrossCursor; /* Arrow cross cursor. */ Xextern Cursor TextCursor; /* Text cursor used in icon windows. */ Xextern Cursor IconCursor; /* Icon Cursor. */ Xextern Cursor LeftButtonCursor; /* Left button main cursor. */ Xextern Cursor MiddleButtonCursor;/* Middle button main cursor. */ Xextern Cursor RightButtonCursor;/* Right button main cursor. */ Xextern Cursor TargetCursor; /* Target (select-a-window) cursor. */ Xextern Cursor TitleCursor; /* Title bar cursor */ Xextern Cursor FrameCursor; /* Frame cursor */ Xextern int GadgetBorder; /* Width of gadget borders */ Xextern int ScreenWidth; /* Display screen width. */ Xextern int ScreenHeight; /* Display screen height. */ Xextern int TitleHeight; /* Height in pixels of title bar(s) */ Xextern int titleHeight; /* Derived height of title bar(s) */ Xextern int gadgetHeight; /* Height of highest gadget */ Xextern int NameOffset; /* Offset for window name */ Xextern int IBorderWidth; /* Icon window border width. */ Xextern int PWidth; /* Pop-up window width (including borders). */ Xextern int PHeight; /* Pop-up window height (including borders). */ Xextern int PBorderWidth; /* Pop-up window border width. */ Xextern int PPadding; /* Pop-up window padding. */ Xextern int Delay; /* Delay between clicks of double click. */ Xextern int Delta; /* Mouse movement slop. */ Xextern int HIconPad; /* Icon horizontal padding. */ Xextern int VIconPad; /* Icon vertical padding. */ Xextern int Pushval; /* Number of pixels to push window by. */ Xextern int BContext; /* Width of border context area in pixels */ Xextern int RaiseDelay; /* Delay in milliseconds before autoraising windows */ Xextern int Volume; /* Audible alarm volume. */ Xextern int NumGadgets; /* Number of gadgets used */ Xextern int GadgetPad; /* Padding between gadgets */ Xextern int TitlePad; /* Title text padding */ Xextern int status; /* Routine return status. */ Xextern int Maxfd; /* Maximum file descriptors for select(2). */ Xextern int MPad; /* menu padding */ Xextern int MDelta; /* Menu subitem delta */ Xextern int MBorderWidth; /* Menu border width */ Xextern int MItemBorder; /* Menu item border width */ Xextern int BCursor; /* Border context cursor */ Xextern int TCursor; /* Title context cursor */ Xextern MenuLink *Menus; /* Linked list of menus. */ Xextern GC IconGC; /* graphics context for icon */ Xextern GC PopGC; /* graphics context for pop */ Xextern GC DrawGC; /* graphics context for zap */ X Xextern Boolean Autoraise; /* Raise window on input focus? */ Xextern Boolean Autoselect; /* Warp mouse to default menu selection? */ Xextern Boolean Borders; /* Display border context areas? */ Xextern Boolean ConstrainResize; /* Don't resize until pointer leaves window */ Xextern Boolean Freeze; /* Freeze server during move/resize? */ Xextern Boolean Grid; /* Should the m/r box contain a 9 seg. grid. */ Xextern Boolean Hilite; /* Should we highlight titles on focus? */ Xextern Boolean BorderHilite; /* Should we highlight borders on focus? */ Xextern Boolean FrameFocus; /* Should frame be considered part of window */ Xextern Boolean ShowName; /* Display names in title bars */ Xextern Boolean NWindow; /* Normalize windows? */ Xextern Boolean NIcon; /* Normalize icons? */ Xextern Boolean RootResizeBox; /* Should resize box obscure window? */ Xextern Boolean InstallColormap; /* Install colormap for clients? */ Xextern Boolean Push; /* Relative=TRUE, Absolute=FALSE. */ Xextern Boolean ResizeRelative; /* Relative=TRUE, Absolute=FALSE. */ Xextern Boolean Reverse; /* Reverse video? */ Xextern Boolean SaveUnder; /* Save unders? */ Xextern Boolean Snatched; /* We're in the middle of an no-highlight/raise op */ Xextern Boolean Titles; /* Title bars on windows? */ Xextern Boolean PushDown; /* Down=TRUE, Up=FALSE */ Xextern Boolean UseGadgets; /* Gadget boxes in title bars? */ Xextern Boolean Wall; /* Don't allow windows past edges of screen */ Xextern Boolean WarpOnRaise; /* Warp to upper right corner on raise. */ Xextern Boolean WarpOnIconify; /* Warp to icon center on iconify. */ Xextern Boolean WarpOnDeIconify; /* Warp to upper right corner on de-iconify. */ Xextern Boolean Zap; /* Should the the zap effect be used. */ Xextern Boolean FocusSetByUser; /* True if f.focus called */ Xextern Boolean FocusSetByWM; /* True if awm set the focus */ X Xextern char PText[]; /* Pop-up window dummy text. */ Xextern int PTextSize; /* Pop-up window dummy text size. */ X Xextern int Lineno; /* Line count for parser. */ Xextern Boolean Startup_File_Error; /* Startup file error flag. */ Xextern char Startup_File[]; /* Startup file name. */ Xextern char *IFontName; /* Icon font name. */ Xextern char *PFontName; /* Pop-up font name. */ Xextern char *TFontName; /* Title font name. */ Xextern char *GFontName; /* Gadget font name */ Xextern char *TFontBoldName; /* Bold Title font name. */ Xextern char *TBackPixmapName; /* Title pixmap file */ Xextern char *TBoldPixmapName; /* Title (highlighted) pixmap file */ Xextern char *TBackPixmapData; /* Bitmap data file title background */ Xextern char *TBoldPixmapData; /* ditto, except highlighted */ Xextern char *BBackPixmapData; /* Border Context area background pixmap data */ Xextern char *BBoldPixmapData; /* Border Context bold pixmap data */ Xextern char *awmPath; /* Pathlist for pixmap files */ Xextern char **Argv; /* Pointer to command line parameters. */ Xextern char **Environ; /* Pointer to environment. */ X Xextern char *DefaultBindings[]; /* Default bindings string array. */ Xextern Keyword KeywordTable[]; /* Keyword lookup table. */ Xextern Binding *Blist; /* Button/key bindings list. */ Xextern KeyExpr KeyExprTbl[]; /* Key expression table. */ Xextern ContExpr ContExprTbl[]; /* Context expression table. */ Xextern ButtonModifier ButtModTbl[];/* Button modifier table. */ Xextern GravityExpr GravityExprTbl[]; /* Gravity expression table. */ X Xextern GadgetDecl **Gadgets; /* Gadgets declared. See gram.y */ Xextern int scr; Xextern Display *dpy; /* Display info pointer. */ X X#ifdef PROFIL Xint ptrap(); X#endif X X/* X * External routine typing. X */ Xextern Boolean Beep(); Xextern Boolean CircleDown(); Xextern Boolean CircleUp(); Xextern Boolean Continue(); Xextern Boolean Focus(); Xextern Boolean UnFocus(); Xextern Boolean GetButton(); Xextern Boolean Iconify(); Xextern Boolean Lower(); Xextern Boolean DoMenu(); Xextern Boolean DoAction(); Xextern Boolean Move(); Xextern Boolean MoveOpaque(); Xextern Boolean Neaten(); Xextern Boolean NewIconify(); Xextern Boolean Pause(); Xextern Boolean ShoveDown(); Xextern Boolean ShoveLeft(); Xextern Boolean ShoveRight(); Xextern Boolean ShoveUp(); Xextern Boolean Quit(); Xextern Boolean Raise(); Xextern Boolean Redraw(); Xextern Boolean Refresh(); Xextern Boolean ResetBindings(); Xextern Boolean ResetMenus(); Xextern Boolean ResetGadgets(); Xextern Boolean Resize(); Xextern Boolean Restart(); Xextern Boolean FDecorate(); Xextern Boolean FNoDecorate(); Xextern Boolean DestroyClient(); Xextern Boolean GetBoolRes(); Xextern Boolean ConfigureWindow(); Xextern int StoreCursors(); Xextern int StoreBox(); Xextern int StoreTitleBox(); Xextern int StoreGridBox(); Xextern int StoreTitleGridBox(); Xextern int StoreZap(); Xextern int Error(); Xextern int XError(); Xextern int CreateMenus(); Xextern int GetIntRes(); Xextern Window Reparent(), Decorate(); Xextern unsigned char *expand_metachars(); Xextern char *stash(); Xextern char *GetIconName(); Xextern char *expand_from_path(); Xextern char *GetStringRes(); Xextern char *GetPixmapDataRes(); Xextern Pixmap GetPixmapRes(); Xextern Pixel GetColorRes(); Xextern Pixel GetPixel(); Xextern XFontStruct *GetFontRes(); Xextern Drawable GetPixmapFromCache(); Xextern AwmInfoPtr GetAwmInfo(); Xextern AwmInfoPtr RegisterWindow(); Xextern AwmInfoPtr IsTitled(); Xextern AwmInfoPtr IsGadgetWin(); X Xextern void Init_Titles(), Init_Frames(); Xextern void NoDecorate(); Xextern void PaintTitle(); Xextern void SetBorderPixmaps(); Xextern void FreePixmapFromCache(); X X#ifdef NEATEN X#define DEFAULT_ABS_MIN 64 X#define SEPARATION 2 X#define DEF_PRIMARY_PLACEMENT "Top" X#define DEF_SECONDARY_PLACEMENT "Left" X Xextern int AbsMinWidth; Xextern int AbsMinHeight; Xextern Boolean RetainSize; Xextern Boolean KeepOpen; Xextern Boolean Fill; Xextern Boolean UsePriorities; Xextern Boolean FixTopOfStack; Xextern char *PrimaryIconPlacement; Xextern char *SecondaryIconPlacement; X#endif NEATEN END_OF_awm/awm.h if test 21364 -ne `wc -c <awm/awm.h`; then echo shar: \"awm/awm.h\" unpacked with wrong size! fi # end of overwriting check fi echo shar: End of archive 8 \(of 13\). cp /dev/null ark8isdone MISSING="" for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 ; do if test ! -f ark${I}isdone ; then MISSING="${MISSING} ${I}" fi done if test "${MISSING}" = "" ; then echo You have unpacked all 13 archives. rm -f ark[1-9]isdone ark[1-9][0-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